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 ...@@ -155,7 +155,23 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject
value = type; value = type;
type = (PyObject*) Py_TYPE(value); type = (PyObject*) Py_TYPE(value);
} else if (PyExceptionClass_Check(type)) { } 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) // 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; PyObject *args;
if (!value) if (!value)
args = PyTuple_New(0); args = PyTuple_New(0);
...@@ -166,7 +182,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject ...@@ -166,7 +182,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject
args = PyTuple_Pack(1, value); args = PyTuple_Pack(1, value);
if (!args) if (!args)
goto bad; goto bad;
owned_instance = PyEval_CallObject(type, args); owned_instance = PyObject_Call(type, args, NULL);
Py_DECREF(args); Py_DECREF(args);
if (!owned_instance) if (!owned_instance)
goto bad; goto bad;
...@@ -178,6 +194,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject ...@@ -178,6 +194,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject
type, Py_TYPE(value)); type, Py_TYPE(value));
goto bad; goto bad;
} }
}
} else { } else {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"raise: exception class must be a subclass of BaseException"); "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