Python C API (PyObject_CallMethod clear object)

Gabriel Genellina gagsl-py2 at
Mon Jan 26 03:25:46 CET 2009

En Sun, 25 Jan 2009 23:46:01 -0200, <googler.1.webmaster at>  

> I have a problm with deallocating stuff. I call a function with this
> command:
> PyObject *rvalue = PyObject_CallMethod(obj, "execute","",NULL);
> if(rvalue==NULL)
>     PyErr_Print();
> else
>     Py_DECREF(rvalue);
> Can it be, that something is missing here? Imagine I allocate an
> object of a type:
> t = MyImage()
> ,;- syntax_error 129=)/%  #is a syntax error
> How you see I would get a syntaxerror, but an object of the type
> MyImage() is created. But its deallocated when Py_Finalize() is
> called. What can I do to deallocate this object after
> PyObject_CallMethod returns NULL, too? I debug it, so if rvalue!=NULL
> the object is deallocated, but what can I do if rvalue==NULL=

A syntax error is detected *before* the code runs -- so the object isn't  
created at all.

Gabriel Genellina

More information about the Python-list mailing list