]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38631: Replace tp_new_wrapper() fatal error with SystemError (GH-18262)
authorVictor Stinner <vstinner@python.org>
Thu, 30 Jan 2020 08:02:49 +0000 (09:02 +0100)
committerGitHub <noreply@github.com>
Thu, 30 Jan 2020 08:02:49 +0000 (09:02 +0100)
tp_new_wrapper() now raises a SystemError if called with non-type
self, rather than calling Py_FatalError() which cannot be catched.

Objects/typeobject.c

index b095e2921dcf26eb51118d3c748f9e1a44701246..8422a3c5a38c46c6834029df2e04504dcfb325ec 100644 (file)
@@ -6042,8 +6042,12 @@ tp_new_wrapper(PyObject *self, PyObject *args, PyObject *kwds)
     PyTypeObject *type, *subtype, *staticbase;
     PyObject *arg0, *res;
 
-    if (self == NULL || !PyType_Check(self))
-        Py_FatalError("__new__() called with non-type 'self'");
+    if (self == NULL || !PyType_Check(self)) {
+        PyErr_Format(PyExc_SystemError,
+                     "__new__() called with non-type 'self'");
+        return NULL;
+    }
+
     type = (PyTypeObject *)self;
     if (!PyTuple_Check(args) || PyTuple_GET_SIZE(args) < 1) {
         PyErr_Format(PyExc_TypeError,