Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyArg_ParseTuple default argument

If I have the following function and the optional argument myobj is not passed, does myobj remain NULL or is it set to Py_None?

static PyObject * myfunc(PyObject * self, PyObject * args) {
    PyObject * myobj = NULL;
    if (!PyArg_ParseTuple(args, "|O", &myobj)) {
        return NULL;
    }
    // ...
}

According Parsing arguments and building values,

| Indicates that the remaining arguments in the Python argument list are optional. The C variables corresponding to optional arguments should be initialized to their default value — when an optional argument is not specified, PyArg_ParseTuple() does not touch the contents of the corresponding C variable(s).

Does this apply to PyObject *s? It's obviously a pointer that exists in C so one could say it's a C variable, but it's a pointer to a python object so one could also say it does not count as a C variable.

like image 343
Uyghur Lives Matter Avatar asked Apr 11 '12 19:04

Uyghur Lives Matter


1 Answers

It will remain NULL. And of course a pointer to a struct is a C object.

like image 62
ThiefMaster Avatar answered Oct 11 '22 17:10

ThiefMaster