Skip to content

Commit 98f9ddd

Browse files
author
fdrake
committed
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
sense now that extension types can support __init__ directly rather than requiring function constructors. git-svn-id: http://svn.python.org/projects/python/trunk@28239 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 5f2635a commit 98f9ddd

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

Python/modsupport.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,24 @@ Py_InitModule4(char *name, PyMethodDef *methods, char *doc,
5656
if ((m = PyImport_AddModule(name)) == NULL)
5757
return NULL;
5858
d = PyModule_GetDict(m);
59-
for (ml = methods; ml->ml_name != NULL; ml++) {
60-
if ((ml->ml_flags & METH_CLASS) ||
61-
(ml->ml_flags & METH_STATIC)) {
62-
PyErr_SetString(PyExc_ValueError,
63-
"module functions cannot set"
64-
" METH_CLASS or METH_STATIC");
65-
return NULL;
66-
}
67-
v = PyCFunction_New(ml, passthrough);
68-
if (v == NULL)
69-
return NULL;
70-
if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
59+
if (methods != NULL) {
60+
for (ml = methods; ml->ml_name != NULL; ml++) {
61+
if ((ml->ml_flags & METH_CLASS) ||
62+
(ml->ml_flags & METH_STATIC)) {
63+
PyErr_SetString(PyExc_ValueError,
64+
"module functions cannot set"
65+
" METH_CLASS or METH_STATIC");
66+
return NULL;
67+
}
68+
v = PyCFunction_New(ml, passthrough);
69+
if (v == NULL)
70+
return NULL;
71+
if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
72+
Py_DECREF(v);
73+
return NULL;
74+
}
7175
Py_DECREF(v);
72-
return NULL;
7376
}
74-
Py_DECREF(v);
7577
}
7678
if (doc != NULL) {
7779
v = PyString_FromString(doc);

0 commit comments

Comments
 (0)