An unexpected visit_decref assertion fail (code works under python 2.4, doesn't under 2.5)

Joe Ardent ardent at gmail.com
Sat Apr 25 03:36:53 CEST 2009


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-
>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);
            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-
>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 (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!

--
Joe Ardent



More information about the Python-list mailing list