J
Joe Ardent
Hello,
I'm running into a very odd problem here with a Python module (written
in C). The following code works fine when built against and loaded
into Python 2.4, but fails when built against and loaded into Python
2.5.1:
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-
if (!func) {
Py_XDECREF(klass);
return NULL;
}
printf( "We get here\n" );
func = PyMethod_New(func, NULL, klass);
printf( "We don't get here\n" );
# .......
}
}
The output of 'python2.5 -c "import mymod"' is:
"""
We get here
python2: Modules/gcmodule.c:276: visit_decref: Assertion `gc-
"""
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 (this module has a bunch of C++ classes that get turned into
python classes).
Does anyone have any tips for debugging this? I'd really like to know
what exactly is being decref'd. This has been driving me crazy for a
while. Thanks in advance for any insights or tips!
I'm running into a very odd problem here with a Python module (written
in C). The following code works fine when built against and loaded
into Python 2.4, but fails when built against and loaded into Python
2.5.1:
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-
PyObject *func = IlmPyClass_NewFunction(def);ml_name );
if (!func) {
Py_XDECREF(klass);
return NULL;
}
printf( "We get here\n" );
func = PyMethod_New(func, NULL, klass);
printf( "We don't get here\n" );
# .......
}
}
The output of 'python2.5 -c "import mymod"' is:
"""
We get here
python2: Modules/gcmodule.c:276: visit_decref: Assertion `gc-
Abortgc.gc_refs != 0' failed.
"""
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 (this module has a bunch of C++ classes that get turned into
python classes).
Does anyone have any tips for debugging this? I'd really like to know
what exactly is being decref'd. This has been driving me crazy for a
while. Thanks in advance for any insights or tips!