tag:blogger.com,1999:blog-3465761147722302880.post6194551975160973619..comments2007-07-23T09:25:31.287-07:00Comments on The Audacity to Code: __traits and PydKirkhttp://www.blogger.com/profile/04406863919785076582noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-3465761147722302880.post-2162896751960530492007-07-23T09:25:00.000-07:002007-07-23T09:25:00.000-07:00Hi and thank you for PyD !I'm experiencing problem...Hi and thank you for PyD !<BR/><BR/>I'm experiencing problems whith the garbage collector when I try to use PyD<BR/>under Linux with the GDC compiler<BR/>gdc (GCC) 4.1.1 20060524 ( (gdc 0.22, using dmd 1.004)).<BR/><BR/>I obtained the simplest example by modifying the rawexample of the pyd source. Here is the D code:<BR/><BR/>// A module written to the raw Python/C API.<BR/><BR/>module rawexample;<BR/>import python;<BR/>import std.gc;<BR/><BR/>extern(C)<BR/>PyObject* myCollect(PyObject* self, PyObject* args) {<BR/> fullCollect();<BR/> Py_INCREF(Py_None);<BR/> return Py_None;<BR/>}<BR/><BR/>PyMethodDef[] rawexample_methods = [<BR/> {"myCollect", &myCollect, METH_VARARGS, ""},<BR/> {null, null, 0, null}<BR/>];<BR/><BR/>extern(C)<BR/>export void initrawexample() {<BR/> PyObject* m = Py_InitModule("rawexample", rawexample_methods.ptr);<BR/>}<BR/><BR/>So I define a single function myCollect which only calls fullCollect(). I compile this into a shared library, using the following setup file:<BR/><BR/>from celerid.support import setup, Extension<BR/><BR/>projName = 'rawexample'<BR/><BR/>setup(<BR/> name=projName,<BR/> version='0.1',<BR/> ext_modules=[<BR/> Extension(projName, ['rawexample.d', ],<BR/> extra_compile_args = [ <BR/> ],<BR/> raw_only=True)<BR/> ],<BR/>)<BR/><BR/>then I run the following test.py file<BR/><BR/>import os.path, sys<BR/>import distutils.util<BR/><BR/># Append the directory in which the binaries were placed to Python's sys.path,<BR/># then import the D DLL.<BR/>libDir = os.path.join('build', 'lib.%s-%s' % (<BR/> distutils.util.get_platform(),<BR/> '.'.join(str(v) for v in sys.version_info[:2])<BR/>))<BR/>sys.path.append(os.path.abspath(libDir))<BR/>import rawexample<BR/><BR/>rawexample.myCollect()<BR/>rawexample.myCollect()<BR/>print "test.py: done"<BR/><BR/>This results in nothing printed and a segmentation fault. If I call myCollect only once, the message "test.py: done" is printed but then there is still a segmentation fault.<BR/><BR/>Note that I designed this example after some mysterious crashes of a larger program which didn't call directely "fullCollect", but I suspected the gc because the program failed only after a large number of iterations...<BR/><BR/>If you have an idea about how to fix this, please let me know !<BR/><BR/> EricREricRhttp://www.blogger.com/profile/08945577077175812657noreply@blogger.com