Hello,
I have a Python module here that takes a bunch of C++ classes, and turns them into Python classes. When built against and loaded into Python 2.4, everything is fine. But when built against and loaded into Python 2.5, I get an assert violation from Python's gc module. Here is the code that is failing:
klass = PyClass_New(bases, classDict, className);
if (klass && methods) {
/* add methods to class */
for (def = methods; def->ml_name != NULL; def++) {
printf( "IlmPyClass: %d, def = %s\n", __LINE__, def->ml_name);
PyObject *func = IlmPyClass_NewFunction(def);
if (!func) {
Py_XDECREF(klass);
return NULL;
}
printf( "We get here\n" );
func = PyMethod_New(func, NULL, klass); //this line fails
printf( "We don't get here\n" );
# .......
}
}
The output of 'python2.5 -c "import mymod"' is:
""" [.... snip a bunch of "we get here, we don't get here" etc. as things fail to fail...] IlmPyClass: 197, def = __init__ We get here python2: Modules/gcmodule.c:276: visit_decref: Assertion `gc->gc.gc_refs != 0' failed.
Abort """
The obvious things, such as Py_INCREFing klass or func, do not work.
What's extra strange, in addition to this code working fine in an earlier python version, is that this code works fine for most of the classes that are instantiated.
What I really want to do, though, is see what exactly is being decref'd. Does anyone have any tips for doing this? I've already tried using a debug build of Python; it doesn't seem to provide that type of ref tracing. Thanks in advance for any tips or insights.
-- Joe Ardent