[capi-sig] intermittent failure of threading

Hrvoje Niksic hniksic at xemacs.org
Fri Jul 2 08:37:07 CEST 2010

Paul Grunau <paul at anilabsys.com> writes:

>       char *b;
>       PyArg_ParseTuple( pArgs, "s", &b );
>       mod = PyImport_ImportModule(b);
>       if( mod == NULL )
>       {
>             printf("Could not import %s\n",b);
>             return Py_None;
>       }
>       modsetFlag = TRUE;
>       return Py_None;

Python functions are expected to return a new reference, so you should
Py_INCREF None (or any other returned Python object) before returning
it.  This applies to both setmodname and setprocname.

>             pres = PyObject_CallFunction(attr,NULL);
>             if( pres == NULL )printf("CallFunction failed!\n");

PyObject_CallFunction returns a new reference, so you should Py_DECREF
pres in the case when it is not NULL and you no longer need it.

Also, posting a complete code sample in C, that we can build and test
ourselves, might help debugging the specific problem you are having,
which may or may not be related to the above reference-counting errors.

More information about the capi-sig mailing list