Python C/API simple debugging

k3xji sumerc at gmail.com
Wed Nov 26 06:39:30 EST 2008


On Nov 26, 1:34 pm, Stefan Behnel <stefan... at behnel.de> wrote:
> k3xji wrote:
> > 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));
> >    .
> > .
> > [...]
> > - What is the preffered approach for these kind simple-debugging
> > issue?
>
> If you want to simplify this kind of debugging as well as the general code
> writing itself, consider using Cython.
>
> http://cython.org/
>
> Apart from that, I'd use gdb for debugging these things. It does have a
> learning curve, but in change gives you a lot more than just "print-debugging".
>
> Stefan

OK.

How to use gdb? I am compiling the extension to a "pyd" file and
importing it right now. So, I assume we need to, somehow load the
extension dynamically for debugging? But how?

Thanks



More information about the Python-list mailing list