Commit 233cc598 authored by Fred Drake's avatar Fred Drake

Py_InitModule4(): Accept NULL for the 'methods' argument. This makes

sense now that extension types can support __init__ directly rather
than requiring function constructors.
parent 92bb6e7b
...@@ -56,22 +56,24 @@ Py_InitModule4(char *name, PyMethodDef *methods, char *doc, ...@@ -56,22 +56,24 @@ Py_InitModule4(char *name, PyMethodDef *methods, char *doc,
if ((m = PyImport_AddModule(name)) == NULL) if ((m = PyImport_AddModule(name)) == NULL)
return NULL; return NULL;
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
for (ml = methods; ml->ml_name != NULL; ml++) { if (methods != NULL) {
if ((ml->ml_flags & METH_CLASS) || for (ml = methods; ml->ml_name != NULL; ml++) {
(ml->ml_flags & METH_STATIC)) { if ((ml->ml_flags & METH_CLASS) ||
PyErr_SetString(PyExc_ValueError, (ml->ml_flags & METH_STATIC)) {
"module functions cannot set" PyErr_SetString(PyExc_ValueError,
" METH_CLASS or METH_STATIC"); "module functions cannot set"
return NULL; " METH_CLASS or METH_STATIC");
} return NULL;
v = PyCFunction_New(ml, passthrough); }
if (v == NULL) v = PyCFunction_New(ml, passthrough);
return NULL; if (v == NULL)
if (PyDict_SetItemString(d, ml->ml_name, v) != 0) { return NULL;
if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
Py_DECREF(v);
return NULL;
}
Py_DECREF(v); Py_DECREF(v);
return NULL;
} }
Py_DECREF(v);
} }
if (doc != NULL) { if (doc != NULL) {
v = PyString_FromString(doc); v = PyString_FromString(doc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment