Frank Saez
Frank Saez
MModular
Created by Frank Saez on 8/15/2024 in #community-showcase
LibCurl
1 replies
MModular
Created by Frank Saez on 7/31/2024 in #community-showcase
HaldClut
Hi, I've created a (small) HaldClut library. https://github.com/f-saez/haldclut-mojo
2 replies
MModular
Created by Frank Saez on 7/25/2024 in #community-showcase
boxblur
Hi, I've created a boxblur filter. In itself, it's more a demo or a tutorial than a useful piece of code. I've just wanted to put that code alone for toying with before using it elsewhere. https://github.com/f-saez/box_blur_mojo Nothing fancy but it may be useful for a beginner (convolution + a bit of SIMD + multi-threading)
1 replies
MModular
Created by Frank Saez on 7/9/2024 in #community-showcase
Blend2D
Hi, The FFI for Blend2D, a 2D vector graphics engine. https://github.com/f-saez/blend2d-mojo
1 replies
MModular
Created by Frank Saez on 7/1/2024 in #community-showcase
ZSTD
Hi, https://github.com/f-saez/zstd-mojo Same thing as LZ4 but with ZSTD.
1 replies
MModular
Created by Frank Saez on 6/30/2024 in #community-showcase
LZ4
Hi, https://github.com/f-saez/lz4-mojo Basic FFI of LZ4, meaning just block compress/decompress ... for now.
1 replies
MModular
Created by Frank Saez on 6/28/2024 in #community-showcase
LibJpeg
Hi, https://github.com/f-saez/libjpeg-mojo My little take on LibJpeg and FFI. It's just a toy right now, but it may grow in the future
1 replies
MModular
Created by Frank Saez on 6/14/2024 in #questions
About lifetimes
Hi, I'm playing with FFI and I need to know how to manage correctly some lifetimes. Let's take an example :
alias external_func = fn(UnsafePointer[JpegErrorMgr]) -> UInt

@value
struct Stuff:
var pointer : UnsafePointer[UInt8]
var ... # many other fields

fn main():
var thing = ffi.DLHandle("liblambda.so", ffi.RTLD.NOW)
if thing.__bool__():
var bytes = List[UInt8]()
with open("file", "rb") as f:
bytes = f.read_bytes()

var my_struct = Stuff()
my_struct.pointer = bytes.unsafe_ptr()
var result = thing.get_function[external_func]("external_func")(my_struct.unsafe_ptr())
# others call to external_func but no other use of my_struct
...
alias external_func = fn(UnsafePointer[JpegErrorMgr]) -> UInt

@value
struct Stuff:
var pointer : UnsafePointer[UInt8]
var ... # many other fields

fn main():
var thing = ffi.DLHandle("liblambda.so", ffi.RTLD.NOW)
if thing.__bool__():
var bytes = List[UInt8]()
with open("file", "rb") as f:
bytes = f.read_bytes()

var my_struct = Stuff()
my_struct.pointer = bytes.unsafe_ptr()
var result = thing.get_function[external_func]("external_func")(my_struct.unsafe_ptr())
# others call to external_func but no other use of my_struct
...
If I understand correctly, for Mojo, the life of bytes stops as soon as my_struct is not used and in this case, it's just after the first call to "external_func". Trouble is external_func will need bytes to be alive for a longer time but Mojo can't know that and external_func will starts to act funny because the values of bytes may have changed So, my question is : how to manage this kind of lifetime ? an easy answer is to do some useless stuff with my_struct at the end of the block or encapsulate some parts in a function (it's what I do now), but a cleaner way to do that must exists. I've also try to use DTypePointer but I have only be able to use them with basic types like a bunch of bytes but not structured data I must have misunderstood something.
2 replies
MModular
Created by Frank Saez on 6/12/2024 in #questions
FFI
Hi, I'm working on FFI and I've got two small questions : 1 - what is the equivalent of size_t in Mojo ? 2 - Dynamic linking is easy but I haven't found a way to proceed with a static library (.a file). Is there a clean and official way to do that ? Thanks.
16 replies
MModular
Created by Frank Saez on 6/5/2024 in #questions
Question about iterating a list of strings
Hi, I've got a background in Rust (10 years) and in Python (1 year) and I try to learn Mojo. I've try this :
fn main():
try:
var stuff = String("dddd\nffff\njjjj\nkkkk").split("\n")
for x in stuff:
print(x)
except:
print("failed")
fn main():
try:
var stuff = String("dddd\nffff\njjjj\nkkkk").split("\n")
for x in stuff:
print(x)
except:
print("failed")
and got this obscure error message :
/source/prog.mojo:7:12: error: no matching function in call to 'print'
print(x)
~~~~~^~~
/source/prog.mojo:1:1: note: candidate not viable: expected at most 0 positional arguments, got 1
fn main():
^
/source/prog.mojo:1:1: note: candidate not viable: callee expects 2 parameters, but 0 were specified
fn main():
^
/source/prog.mojo:7:13: note: failed to infer parameter 'T', argument type 'Reference[String, 1, stuff, 0]' does not conform to trait 'Stringable'
print(x)
^
mojo: error: failed to parse the provided Mojo source module
/source/prog.mojo:7:12: error: no matching function in call to 'print'
print(x)
~~~~~^~~
/source/prog.mojo:1:1: note: candidate not viable: expected at most 0 positional arguments, got 1
fn main():
^
/source/prog.mojo:1:1: note: candidate not viable: callee expects 2 parameters, but 0 were specified
fn main():
^
/source/prog.mojo:7:13: note: failed to infer parameter 'T', argument type 'Reference[String, 1, stuff, 0]' does not conform to trait 'Stringable'
print(x)
^
mojo: error: failed to parse the provided Mojo source module
but if I use indexes, it works :
for x in range(0, len(stuff)):
print(stuff[x])
for x in range(0, len(stuff)):
print(stuff[x])
I seem to have a hard time with the most basic things 🙂 What have I misunderstood ? Thanks
14 replies