2 Jul
2010
2 Jul
'10
6:37 a.m.
Paul Grunau paul@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.