problem with Py_BuildValue
Cédric Lucantis
omer at no-log.org
Sun Jun 15 12:20:48 EDT 2008
> Thank you. At least I can exclude another few error sources, now.
>
>
>> I see nothing wrong with your code so I'd say it is somewhere else (did
>> you snip any code between the end of the loop and the return?).
>No. (Apart from freeing allocated memory.)
I'm pretty sure we'll find something interesting here :)
> > and if it doesn't help trace the content of your list
> > after each iteration to see when the bad things happen (you can check the
> > reference count of an object with obj->ob_refcnt).
>
> Seems ok. What I did to check this was placing this after building the
> list:
>
> for (i=0; i < limit; i++) {
> dummy = PyList_GetItem(python_return_value, i);
> printf("%f\n", PyFloat_AsDouble(dummy));
> Py_CLEAR(dummy);
> }
PyList_GetItem returns a borrowed reference so you shoud _not_ unref it (this
explains the refcnt -1 I think)
Here's the code producing your message (from Objects/object.c in the python
sources) :
/* Implementation of PyObject_Print with recursion checking */
static int
internal_print(PyObject *op, FILE *fp, int flags, int nesting)
{
<snip>
if (op->ob_refcnt <= 0)
/* XXX(twouters) cast refcount to long until %zd is
universally available */
fprintf(fp, "<refcnt %ld at %p>", (long)op->ob_refcnt, op);
}
<snip>
}
I don't really understand its purpose, but it confirms that it's a ref count
problem. Maybe the full source of your function could help ?
--
Cédric Lucantis
More information about the Python-list
mailing list