Skip to content

Commit c4246a9

Browse files
committed
Fallback to iterative copy of a container with limited API
1 parent 074b9b2 commit c4246a9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pybindgen/container.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,12 @@ def _generate_container_constructor(self, code_sink):
549549
code_sink.writeln(r'''
550550
int %(CONTAINER_CONVERTER_FUNC_NAME)s(PyObject *arg, %(CTYPE)s *container)
551551
{
552+
#ifndef Py_LIMITED_API
552553
if (PyObject_IsInstance(arg, (PyObject*) &%(PYTYPESTRUCT)s)) {
553554
*container = *((%(PYSTRUCT)s*)arg)->obj;
554-
} else if (PyList_Check(arg)) {
555+
} else
556+
#endif
557+
if (PyList_Check(arg)) {
555558
container->clear();
556559
Py_ssize_t size = PyList_Size(arg);
557560
for (Py_ssize_t i = 0; i < size; i++) {
@@ -581,9 +584,12 @@ def _generate_container_constructor(self, code_sink):
581584
code_sink.writeln(r'''
582585
int %(CONTAINER_CONVERTER_FUNC_NAME)s(PyObject *arg, %(CTYPE)s *container)
583586
{
587+
#ifndef Py_LIMITED_API
584588
if (PyObject_IsInstance(arg, (PyObject*) &%(PYTYPESTRUCT)s)) {
585589
*container = *((%(PYSTRUCT)s*)arg)->obj;
586-
} else if (PyList_Check(arg)) {
590+
} else
591+
#endif
592+
if (PyList_Check(arg)) {
587593
container->clear();
588594
Py_ssize_t size = PyList_Size(arg);
589595
for (Py_ssize_t i = 0; i < size; i++) {

0 commit comments

Comments
 (0)