How can you pass a char * to nim, ive been trying for a while but i keep 
getting segfault.

if i use:
    
    
    proc read_csv(fpx: cstring): void {.exportc.} =
        let fp: string = cast[string](fpx)
        var s = newFileStream(fp, fmRead)
        if s == nil:
            echo "file not found"
            return
    

then there's a segfault at newFileStream

if i use
    
    
    proc read_csv(fp: string): void {.exportc.} =
        var s = newFileStream(fp, fmRead)
        if s == nil:
            echo "file not found"
            return
    

then the first 15 chars get truncated, but i still also get a segfault at 
newFileStream

i tried calling the function from c with read_csv("/path/to/csv");

if i run the nim file instead of compiling to c it works.

Also i found out that if i hardcode the value i get a segfault here 
STRING_LITERAL(TM_xgSOGG8fvQlwPH9bPyp9bbTg_6, "path_here", 36);

thx 

Reply via email to