Search code examples
pythoncpython-extensions

PyArg_Parse returning frame object instead of PyLongObject


I'm writing a Python Module using the C extension API and am trying to pass a long variable from Python into the C function and then from that get the raw PyLongObject used to represent this variable.

I'm using the PyArg_Parse function to parse the variable into a raw C Pointer. I'm expecting the PyObject returned to be of type PyLongObject, however whenever I inspect the value of the typename for the parsed object its always of type 'frame'? What am I missing?

static PyObject* test(PyObject *self, PyObject *args)
{
    PyObject *num;

    if(!PyArg_Parse(args, "0", &num))
    {
        //ERROR YO
    }

    printf("\n%s\n", num->ob_type->tp_name);

    Py_RETURN_NONE;
}

Solution

  • It looks as if you are passing an invalid argument format specification (never saw a 0 (zero) there). As a result, you get an exception which you don't deal with, but treat the return-value in "num" as if it was a successful value. On top of that, you are using a deprecated function to parse the arguments.