c-extension crashes unexpected

Markus Wintermann garz at tmft.net
Fri Apr 22 10:37:11 EDT 2005


hello,

i try to write an extension which calls an api.
however,
i haven´t written very much till now, 
but i`ve already managed to make a mistake.

because when i try to call my function,
python 2.4 dies with an errorwindow.

i believe that has something todo with reference counts and memory
allocation but i can´t find my mistake.

here´s the code:

/* Wrapper-Funktion für apiJob() */
static PyObject* wrap_apiJob(PyObject* self, PyObject* args) {

	char* ecu = (char *) PyMem_Malloc(APIMAXNAME);
	char* job = (char *) PyMem_Malloc(APIMAXNAME);
	char* para = (char *) PyMem_Malloc(APIMAXPARA);
	PyObject *resultlist;
	unsigned short i,j,setcount,resultcount;

	if (!PyArg_ParseTuple(args, "ss|s", &ecu, &job, &para))  { return 0;}

	if (!apiInit()) return Py_BuildValue("s", apiErrorText());

	apiJob(ecu, job, para, "");

	while (apiState()==APIBUSY);

	if (apiState()==APIERROR) {
		return Py_BuildValue("s", apiErrorText());
	}

	if (!apiResultSets(&setcount)) return Py_BuildValue("s",
apiErrorText());

	for (i=0;i<setcount+1;i++) {
		PyList_SetItem(resultlist, i, Py_BuildValue("i",i));

	}

	resultlist =  PyList_New(setcount+1);


	PyMem_Free(ecu);
	PyMem_Free(job);
	PyMem_Free(para);

	return Py_BuildValue("N",resultlist);
}

-----------
there is nothing wrong with the apicalls.
when i comment them out it dies too.



More information about the Python-list mailing list