Python C/API simple debugging

k3xji sumerc at gmail.com
Wed Nov 26 06:27:04 EST 2008


Hi all,

I am new to Python C API and finding it difficult to debug C
extensions. So, basically I want to see the value of an integer value
during the C API. Here is the code:

#define LAST_MIX_VAL 0xDEADBEEF

static PyObject *
chash(PyObject *self, PyObject *args)
{
    unsigned int key,result; //treat key like an usinged int.
	unsigned char a,b,c,d;

	key = result = 0;
    if (!PyArg_ParseTuple(args, "i", &key))
        return NULL;

	printf("Key:%i\n",Py_BuildValue("i", key));
	.
.

So, I just want to see the contents of local variable key. If I call
printf(..) without Py_BuildValue(), the interpreter shuts down, because
(I am assuming) printf is allocating some value in heap that is not in
the interpreter's heap itself which is causing the corruption.

This way it works, but this time I cannot see correct key content.

So, questions are:
- What I am doing wrong here?
- What is the preffered approach for these kind simple-debugging
issue? I searched C/API ref but cannot see any help on that?

Thanks,



More information about the Python-list mailing list