[issue40704] PyIter_Check fails when compiling in the Limited API

Maxwell Bernstein report at bugs.python.org
Wed May 20 18:13:33 EDT 2020


Maxwell Bernstein <tekk.nolagi at gmail.com> added the comment:

See for example the following C program:

```
#define Py_LIMITED_API

#include "Python.h"

int main() {
  Py_Initialize();
  PyObject* foo;
  PyIter_Check(foo);
}
```

when compiled (gcc test.c `pkg-config --cflags python3`) produces:

```
In file included from /usr/include/python3.6m/Python.h:135:0,
                 from test.c:3:
test.c: In function ‘main’:
/usr/include/python3.6m/abstract.h:712:20: error: dereferencing pointer to incomplete type ‘struct _typeobject’
     ((obj)->ob_type->tp_iternext != NULL && \
                    ^
test.c:8:3: note: in expansion of macro ‘PyIter_Check’
   PyIter_Check(foo);
   ^~~~~~~~~~~~
/usr/include/python3.6m/abstract.h:713:38: error: ‘_PyObject_NextNotImplemented’ undeclared (first use in this function); did you mean ‘PyObject_HashNotImplemented’?
      (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented)
                                      ^
test.c:8:3: note: in expansion of macro ‘PyIter_Check’
   PyIter_Check(foo);
   ^~~~~~~~~~~~
/usr/include/python3.6m/abstract.h:713:38: note: each undeclared identifier is reported only once for each function it appears in
      (obj)->ob_type->tp_iternext != &_PyObject_NextNotImplemented)
                                      ^
test.c:8:3: note: in expansion of macro ‘PyIter_Check’
   PyIter_Check(foo);
   ^~~~~~~~~~~~
```

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40704>
_______________________________________


More information about the Python-bugs-list mailing list