]> granicus.if.org Git - python/commitdiff
Repair COMError. Since exceptions are new style classes now, setting
authorThomas Heller <theller@ctypes.org>
Fri, 13 Jul 2007 13:59:39 +0000 (13:59 +0000)
committerThomas Heller <theller@ctypes.org>
Fri, 13 Jul 2007 13:59:39 +0000 (13:59 +0000)
the methods and docstring after the type creation does not work, they
must be in the dictionary before creating the type.

Modules/_ctypes/_ctypes.c

index 34b6829a9c24f82ae946771ecb0686ead9ffb687..8eeb865647a35170e2769e53fef50f8907a90983 100644 (file)
@@ -4520,11 +4520,6 @@ create_comerror(void)
        PyObject *s;
        int status;
 
-       ComError = PyErr_NewException("_ctypes.COMError",
-                                     NULL,
-                                     dict);
-       if (ComError == NULL)
-               return -1;
        while (methods->ml_name) {
                /* get a wrapper for the built-in function */
                PyObject *func = PyCFunction_New(methods, NULL);
@@ -4539,13 +4534,24 @@ create_comerror(void)
                Py_DECREF(meth);
                ++methods;
        }
-       Py_INCREF(ComError);
+
        s = PyString_FromString(comerror_doc);
        if (s == NULL)
                return -1;
        status = PyDict_SetItemString(dict, "__doc__", s);
        Py_DECREF(s);
-       return status;
+       if (status == -1) {
+               Py_DECREF(dict);
+               return -1;
+       }
+
+       ComError = PyErr_NewException("_ctypes.COMError",
+                                     NULL,
+                                     dict);
+       if (ComError == NULL)
+               return -1;
+
+       return 0;
 }
 
 #endif