Commit 60eb977a authored by Stefan Behnel's avatar Stefan Behnel

fix 'raise type, instance' in Py3 by preventing it from trying to re-instantiate the instance

parent 7e59e591
......@@ -155,7 +155,23 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject
value = type;
type = (PyObject*) Py_TYPE(value);
} else if (PyExceptionClass_Check(type)) {
// make sure value is an exception instance of type
PyObject *instance_class = NULL;
if (value && PyExceptionInstance_Check(value)) {
instance_class = (PyObject*) Py_TYPE(value);
if (instance_class != type) {
if (PyObject_IsSubclass(instance_class, type)) {
// believe the instance
type = instance_class;
} else {
instance_class = NULL;
}
}
}
if (!instance_class) {
// instantiate the type now (we don't know when and how it will be caught)
// assuming that 'value' is an argument to the type's constructor
// not using PyErr_NormalizeException() to avoid ref-counting problems
PyObject *args;
if (!value)
args = PyTuple_New(0);
......@@ -166,7 +182,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject
args = PyTuple_Pack(1, value);
if (!args)
goto bad;
owned_instance = PyEval_CallObject(type, args);
owned_instance = PyObject_Call(type, args, NULL);
Py_DECREF(args);
if (!owned_instance)
goto bad;
......@@ -178,6 +194,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject
type, Py_TYPE(value));
goto bad;
}
}
} else {
PyErr_SetString(PyExc_TypeError,
"raise: exception class must be a subclass of BaseException");
......
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