On Nov 26, 5:27 am, k3xji <[EMAIL PROTECTED]> wrote:
> 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,

This works fine for me:

static PyObject *
methA(PyObject *self, PyObject *args) {
    int a;

    PyArg_ParseTuple( args, "i", &a );
    printf( "%i\n", a );

    Py_INCREF(Py_None);

    return Py_None;
}

Did you want capital-I for 'unsigned int'?
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to