sora
sora
MModular
Created by Ryan on 11/1/2024 in #questions
How Unsafe/Safe is this code?
Don't you need some sort of index to size mapping for this to work?
5 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Could you share your GitHub handle so I can give you credit in the description?
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
I actually already made a PR for it: https://github.com/modularml/mojo/pull/3698
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Except StringRef is an unsafe type mainly meant for C++ interop which you probably should avoid using, people are trying to replace them with string slice in the stdlib
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
FYI, Mojo stdlib is apache 2 with LLVM exceptions, so if you are allowed to contribute to most libs for Rust, you should be fine.
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Not at all, it's just people haven't implemented it yet. You could add that to the stdlib if you are interested.
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Ah, Mojo does "prevent" you from returning the Span unless you manually rebind the lifetime parameter
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
What do you mean by local lt?
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
You can in fact avoid alloc, using InlineArray would be equivalent.
from memory import UnsafePointer, stack_allocation
from utils import StringSlice

fn main():
p = stack_allocation[9, DType.uint8]()

# fill
s = String("123456789")
for i in range(9):
p[i] = s.as_bytes()[i]
#

s = StringSlice[MutableAnyOrigin](unsafe_from_utf8_ptr=p, len=9)
from memory import UnsafePointer, stack_allocation
from utils import StringSlice

fn main():
p = stack_allocation[9, DType.uint8]()

# fill
s = String("123456789")
for i in range(9):
p[i] = s.as_bytes()[i]
#

s = StringSlice[MutableAnyOrigin](unsafe_from_utf8_ptr=p, len=9)
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
This is more the idiom
l = String._buffer_type(...) # == List[Byte, hint_trivial_type=True]
String(impl=l)
l = String._buffer_type(...) # == List[Byte, hint_trivial_type=True]
String(impl=l)
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
I'm not sure since inline array is allocated on the stack
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Yea, UnsafePointer[Byte].alloc, or String._buffer_type(capacity=...)
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Implicit conversion itself is not a bug. Accidentally making String constructable from UnsafePointer[Byte] is.
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
If you are also not happy with implicit conversions, be very loud here.
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
I think i know the problem, buf got freed too earily @Michael Kowalski was right, plus you are trying to free stack memory
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Nothing to do with the constructor per se. Mojo finds the overload where each argument undergoes at most one implicit conversion.
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
Could you include the whole program?
52 replies
MModular
Created by aurelian on 10/20/2024 in #questions
why does this String init work without len?
I think you are correct and that's horrible, we should fix it
52 replies
MModular
Created by Martin Dudek on 10/18/2024 in #questions
List of references in Mojo
from memory import Arc

fn main():
l1 = Arc(List(1, 2))
l2 = Arc(List(3, 4))
l3 = List(l1, l2)
l3[0][][0] = 10
print(l1[].__str__())
from memory import Arc

fn main():
l1 = Arc(List(1, 2))
l2 = Arc(List(3, 4))
l3 = List(l1, l2)
l3[0][][0] = 10
print(l1[].__str__())
8 replies
MModular
Created by franchesoni on 10/17/2024 in #questions
print breaks code
12 replies