0

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;
}

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah! Thank you! What it turned out to be was me misreading the documentation of O (object) [PyObject *] to be a 0 and not a O. By properly handling my errors instead of being lazy I realised this, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.