]> granicus.if.org Git - python/commitdiff
Py_InitModule4(): Accept NULL for the 'methods' argument. This makes
authorFred Drake <fdrake@acm.org>
Wed, 14 Aug 2002 20:57:56 +0000 (20:57 +0000)
committerFred Drake <fdrake@acm.org>
Wed, 14 Aug 2002 20:57:56 +0000 (20:57 +0000)
sense now that extension types can support __init__ directly rather
than requiring function constructors.

Python/modsupport.c

index 1f8ef07d17139ac60c86865d9c8d1879899270e8..98b0341330187858078beb473fb5d59ebf3d08ae 100644 (file)
@@ -56,22 +56,24 @@ Py_InitModule4(char *name, PyMethodDef *methods, char *doc,
        if ((m = PyImport_AddModule(name)) == NULL)
                return NULL;
        d = PyModule_GetDict(m);
-       for (ml = methods; ml->ml_name != NULL; ml++) {
-               if ((ml->ml_flags & METH_CLASS) ||
-                   (ml->ml_flags & METH_STATIC)) {
-                       PyErr_SetString(PyExc_ValueError,
-                                       "module functions cannot set"
-                                       " METH_CLASS or METH_STATIC");
-                       return NULL;
-               }
-               v = PyCFunction_New(ml, passthrough);
-               if (v == NULL)
-                       return NULL;
-               if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
+       if (methods != NULL) {
+               for (ml = methods; ml->ml_name != NULL; ml++) {
+                       if ((ml->ml_flags & METH_CLASS) ||
+                           (ml->ml_flags & METH_STATIC)) {
+                               PyErr_SetString(PyExc_ValueError,
+                                               "module functions cannot set"
+                                               " METH_CLASS or METH_STATIC");
+                               return NULL;
+                       }
+                       v = PyCFunction_New(ml, passthrough);
+                       if (v == NULL)
+                               return NULL;
+                       if (PyDict_SetItemString(d, ml->ml_name, v) != 0) {
+                               Py_DECREF(v);
+                               return NULL;
+                       }
                        Py_DECREF(v);
-                       return NULL;
                }
-               Py_DECREF(v);
        }
        if (doc != NULL) {
                v = PyString_FromString(doc);