i build a.so library for python program but different position to call NimMain() , program results are different too.
a.nim
proc test(name : cstring,address: cstring) : int {. exportc,dynlib,cdecl .} =
var k = newSeq[string]()
k.add($name)
k.add($address)
echo len(k),k
if len($name) > 255:
return 200
return len($name)
build cmd: nim c --app:lib -d:release --stackTrace:off --noMain a
OS: ubuntu 16.04
a.py
#coding: utf8
from ctypes import *
P = CDLL("./liba.so")
P.test.argtypes = [c_char_p,c_char_p]
P.test.restype = c_int
#P.NimMain() #Position 1
b.py
#coding: utf8
from a import P
if __name__=="__main__":
# P.NimMain() #Position 2
A="Jerry TOM"
for x in xrange(4096):
print "===>",x
print P.test("Hello",A*(x+1)),x
Run
b.py
uncomment Position 1: sometime SIGSEGV: Illegal storage access. (Attempt to read from nil?)
uncomment Position 2: It's OK..
debug mode:
nim --lineDir:on --debuginfo c --debugger:native --stackTrace:off --app:lib --noMain a
gdb /usr/bin/python2
r b.py
......
bt
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff63ee8cf in copyStringRC1 (src0=0x7ffff5f67040) at /home/program/nim/lib/system/sysstr.nim:109
109 result.len = src.len
(gdb) bt
#0 0x00007ffff63ee8cf in copyStringRC1 (src0=0x7ffff5f67040) at /home/program/nim/lib/system/sysstr.nim:109
#1 0x00007ffff63fb525 in test (name0=0x7ffff7e94fb4 "Hello",
address0=0xa5a5e4 "Jerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJerry TOMJe"...) at /home/david/1/a.nim:5
#2 0x00007ffff6617e40 in ffi_call_unix64 () from /usr/lib/x86_64-linux-gnu/libffi.so.6
looks like, NimMain no work and GC work ?
thanks
Hi,
if you try set at the start of a.nim
GC_disable()
?