Python 2.2.1 DLL extension causes "abnormal program termination"

Fredrik Lundh fredrik at pythonware.com
Thu Sep 1 16:47:55 CEST 2005


Hugh wrote:

> Apologies if this has already been answered in here and I can't find
> it, but can anyone help with this problem?
> I hope the example code and comments state clearly enough what is
> happening, but if not, please ask me for further information.
> Thank in advance for any help.

> #   static PyObject* dummy(PyObject* self, PyObject* args)
> #   {
> #   return Py_None;
> #   }

C functions must return an "owned" reference.  or in other words, since
Py_None is an existing object, you need to increment the reference count
before returning it:

    Py_INCREF(Py_None);
    return Py_None;

or, better, but only works in recent Pythons:

    Py_RETURN_NONE;

for more on reference counting and object ownership, see:

    http://docs.python.org/ext/refcounts.html

</F> 






More information about the Python-list mailing list