assertion error

Tim Peters tim.peters at gmail.com
Thu Jul 22 13:03:56 EDT 2004


[benevilent at optusnet.com.au]
> I'm getting an assertion error as a result of embedding python.
>
> "Modules/gcmodule.c:231: visit_decref: Assertion `gc->gc.gc_refs != 0'
> failed."
> 
> I only get this assertion error with Python compiled with debugging
> flags, rathen than the standard library which comes with Debian.

C asserts are only active in a debug build, so that's not surprising.

> Using gdb I know on what type the object is, which is involved in the
> assertion. It is a subclass of a built-in type which I have defined.

Did you write this subclass in C or in Python?

> This subclass has variables which can cause instances of the subclass to
> participate in circular references (the built-in type I have defined
> itself has no member variables). Removing the circular references seems
> to avoid the error.
> 
> I was under the impression that python can detect circular references,
> and that this should not be a problem.

Circular references aren't a problem.  As the comment on that assert says,

    assert(gc->gc.gc_refs != 0); /* else refcount was too small */

If you wrote your subclass in C, it's almost certainly a missing
Py_INCREF (or excess Py_DECREF) in your C code:  there are more
pointers to the object than the object's refcount believes exist.  Or
it's possible that you wrote a tp_traverse implementation that visits
a single containee more than once (but that's rare).

If you wrote your subclass in Python, then it's probably a
not-reported-before bug in Python, and you should open a bug report
(including a minimal test case).



More information about the Python-list mailing list