Calling a nim compiled lib from python eventually fails:
Tested on latest nim dev and python2.7 and python3.4
import times
# file : blah.nim
# compile : nim c --app:lib blah.nim
proc pDays*(pDate:cstring,pdays:cint):cstring {. exportc, dynlib .} =
let aDate = $pDate
let days = int(pdays)
var myinterval = initInterval()
var tifo = parse(aDate,"yyyy-MM-dd")
myinterval.days = days
var rtp = tifo + myinterval
var rxs = rtp.format("yyyy-MM-dd")
result = cstring(rxs)
This is called like so from python:
from ctypes import *
libblah = CDLL("/data4/NimStuff/libblah.so") # change path as required
libblah.pDays.argtypes = [c_char_p,c_int]
libblah.pDays.restype = c_char_p
datex = '2012-01-31'
for x in range(0,100):
print (x," --> ",libblah.pDays(datex,x))
# after 77 ok loops it fails
#72 --> 2012-04-12
#73 --> 2012-04-13
#74 --> 2012-04-14
#75 --> 2012-04-15
#76 --> 2012-04-16
#77 --> 2012-04-17
#Traceback (most recent call last)
#blah.nim(15) pDays
#times.nim(755) format
#gc.nim(579) growObj
#gc.nim(530) growObj
#SIGSEGV: Illegal storage access. (Attempt to read from nil?)
#78 -->
What do I need to do differently ?
Thanks.
On further reflection this appears to be a too eager GC at work
after compiling the lib with
nim c --app:lib --gc:boehm blah
the error goes away ...
Maybe should be mentioned in the docs , if --gc:boehm is the
better choice for lib compilation.