diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.cxx b/dtool/src/interrogate/interfaceMakerPythonNative.cxx index 2e089b09d8..ca6c6d5ca7 100755 --- a/dtool/src/interrogate/interfaceMakerPythonNative.cxx +++ b/dtool/src/interrogate/interfaceMakerPythonNative.cxx @@ -507,9 +507,9 @@ get_slotted_function_def(Object *obj, Function *func, SlottedFunctionDef &def) { return true; } - if (method_name == "next") { + if (method_name == "next" || method_name == "__next__") { def._answer_location = "tp_iternext"; - def._wrapper_type = WT_no_params; + def._wrapper_type = WT_iter_next; return true; } } @@ -1700,6 +1700,29 @@ write_module_class(ostream &out, Object *obj) { } break; + case WT_iter_next: + // PyObject *func(PyObject *self) + // However, returns NULL instead of None + { + Function *func = rfi->first; + out << "//////////////////\n"; + out << "// A wrapper function to satisfy Python's internal calling conventions.\n"; + out << "// " << ClassName << " ..." << rfi->second._answer_location << " = " << methodNameFromCppName(func, export_class_name, false) << "\n"; + out << "//////////////////\n"; + out << "static PyObject *" << func->_name << methodNameFromCppName(func, export_class_name, false) << "(PyObject *self) {\n"; + out << " PyObject *args = Py_BuildValue(\"()\");\n"; + out << " PyObject *result = " << func->_name << "(self, args, NULL);\n"; + out << " Py_DECREF(args);\n"; + out << " if (result == Py_None) {\n"; + out << " Py_DECREF(Py_None);\n"; + out << " return NULL;\n"; + out << " } else {\n"; + out << " return result;\n"; + out << " }\n"; + out << "}\n\n"; + } + break; + case WT_none: break; } diff --git a/dtool/src/interrogate/interfaceMakerPythonNative.h b/dtool/src/interrogate/interfaceMakerPythonNative.h index 32ddd65af7..3bcb9d3b04 100755 --- a/dtool/src/interrogate/interfaceMakerPythonNative.h +++ b/dtool/src/interrogate/interfaceMakerPythonNative.h @@ -76,6 +76,7 @@ private: WT_inquiry, WT_getbuffer, WT_releasebuffer, + WT_iter_next, }; class SlottedFunctionDef {