reference count

J jstier at cs.uvic.ca
Thu Sep 29 01:15:56 CEST 2005


Hi,


I have a problem with the reference count after an error occurs
in a script which I execute as follows..

PyObject* lDict = PyDict_New();
PyDict_SetItemString(lDict, "item", (PyObject*)iItem->mPyObject);
PyObject* lResult = PyEval_EvalCode(mCode, ScnGlobal::sDictionary,
lDict);
if (! lResult)
{
    PyErr_Print();
}
else
{
    Py_DECREF(lResult);
}
Py_DECREF(lDict);


The script within the mCode object only contains the following line,
which generates an error.

print aasas


The problem is that after PyEval_EvalCode returns the reference count
for lDict is one larger than before. Py_DECREF(lDict) does
therefore not delete the Dictionary, which causes me problems. Is
Python keeping an exception around. I assume that I have to do some
more cleanup ??


Cheers
Jochen




More information about the Python-list mailing list