Hi all,

I'm trying to create a Ruby extension in Nim, so I've built a Nim dynamic 
library (.so) that exports a number of functions, which I'm then accessing 
using Ruby's [FFI](https://github.com/ffi/ffi) module. What I've found, is that 
I can easily use functions that return ints or floats, but cannot use functions 
that return strings or arrays. To illustrate:
    
    
    ## utils.nim
    
    proc test_int(): int {.cdecl, exportc} =
      let res: int = 1
      return res
    
    proc test_string(): string {.cdecl, exportc} =
      let res: string = "result"
      return res
    
    proc test_arr(): array[3, int] {.cdecl, exportc} =
      let list = [3,4,5]
      return list
    

I build this file with: 
    
    
    $> nim c --cc:gcc --d:release --threads:on --app:lib utils.nim
    

Which is successful, and I can verify that my functions have been exported with 
    
    
    $> nm -D libutils.so
    

I can then call _test_int_ from my Ruby code and have the integer returned but 
when I call _test_string_ or _test_arr_, I get the following error:

> SIGSEGV: Illegal storage access. (Attempt to read from nil?)

I've used the Ruby FFI before to call C-written libraries that return arrays or 
char* without any problem, so I don't think the problem is on that side. Any 
ideas on what I'm doing wrong would be greatly appreciated.

PS: I'm using Nim 0.17.0 (2017-05-17) [Linux: amd64]

Reply via email to