> So now, using cstring instead of string means the test_string function works 
> smoothly!

Can you show the example? I was not aware that Nim can create cstrings for FFI 
access out of the box.

> but still keep getting random numbers.

Well, your example can not work. Returning the addr should not make it much 
better I guess.

Your list is allocated somewhere -- on the stack or on the heap garbage 
collected. In both cases is it not valid any more after return of that proc. I 
gave some suggestions for solution in my previous post.

Of course all what I say has no solid foundations -- only Araq known exactly 
what the compiler will do, as the compiler and Araq are always free to try to 
guess what the user really intents and to try to give him what he may wants 

Do you also consider freeing the returned memory somehow? Another approch may 
be to allocate the needed memory in the Ruby world and pass a pointer to that 
memory to Nim, where Nim can fill in the data. 

Reply via email to