cpython: 0c65a2089f00 (original) (raw)
Mercurial > cpython
changeset 102847:0c65a2089f00
Add _PyErr_CreateException() Issue #27809: Helper function optimized to create an exception: use fastcall whenever possible. [#27809]
Victor Stinner victor.stinner@gmail.com | |
---|---|
date | Mon, 22 Aug 2016 23:59:08 +0200 |
parents | 5587d0dfab4c |
children | c53c532de995 |
files | Python/errors.c |
diffstat | 1 files changed, 30 insertions(+), 31 deletions(-)[+] [-] Python/errors.c 61 |
line wrap: on
line diff
--- a/Python/errors.c +++ b/Python/errors.c @@ -52,6 +52,20 @@ PyErr_Restore(PyObject *type, PyObject Py_XDECREF(oldtraceback); } +static PyObject +_PyErr_CreateException(PyObject *exception, PyObject *value) +{
- if (value == NULL || value == Py_None) {
return _PyObject_CallNoArg(exception);[](#l1.11)
- }
- else if (PyTuple_Check(value)) {
return PyObject_Call(exception, value, NULL);[](#l1.14)
- }
- else {
return _PyObject_CallArg1(exception, value);[](#l1.17)
- }
+} + void PyErr_SetObject(PyObject *exception, PyObject *value) { @@ -66,6 +80,7 @@ PyErr_SetObject(PyObject *exception, PyO exception); return; } + Py_XINCREF(value); exc_value = tstate->exc_value; if (exc_value != NULL && exc_value != Py_None) { @@ -73,28 +88,21 @@ PyErr_SetObject(PyObject exception, PyO Py_INCREF(exc_value); if (value == NULL || !PyExceptionInstance_Check(value)) { / We must normalize the value right now */
PyObject *args, *fixed_value;[](#l1.36)
PyObject *fixed_value;[](#l1.37)
/* Issue #23571: PyEval_CallObject() must not be called with an[](#l1.39)
/* Issue #23571: functions must not be called with an[](#l1.40) exception set */[](#l1.41) PyErr_Clear();[](#l1.42)
if (value == NULL || value == Py_None)[](#l1.44)
args = PyTuple_New(0);[](#l1.45)
else if (PyTuple_Check(value)) {[](#l1.46)
Py_INCREF(value);[](#l1.47)
args = value;[](#l1.48)
fixed_value = _PyErr_CreateException(exception, value);[](#l1.49)
Py_XDECREF(value);[](#l1.50)
if (fixed_value == NULL) {[](#l1.51)
return;[](#l1.52) }[](#l1.53)
else[](#l1.54)
args = PyTuple_Pack(1, value);[](#l1.55)
fixed_value = args ?[](#l1.56)
PyEval_CallObject(exception, args) : NULL;[](#l1.57)
Py_XDECREF(args);[](#l1.58)
Py_XDECREF(value);[](#l1.59)
if (fixed_value == NULL)[](#l1.60)
return;[](#l1.61)
+ value = fixed_value; } + /* Avoid reference cycles through the context chain. This is O(chain length) but context chains are usually very short. Sensitive readers may try @@ -110,7 +118,8 @@ PyErr_SetObject(PyObject *exception, PyO o = context; } PyException_SetContext(value, exc_value);
} else {[](#l1.73)
}[](#l1.74)
} @@ -258,25 +267,15 @@ PyErr_NormalizeException(PyObject **exc, class. */ if (!inclass || !is_subclass) {else {[](#l1.75) Py_DECREF(exc_value);[](#l1.76) }[](#l1.77)
PyObject *args, *res;[](#l1.83)
PyObject *fixed_value;[](#l1.84)
if (value == Py_None)[](#l1.86)
args = PyTuple_New(0);[](#l1.87)
else if (PyTuple_Check(value)) {[](#l1.88)
Py_INCREF(value);[](#l1.89)
args = value;[](#l1.90)
fixed_value = _PyErr_CreateException(type, value);[](#l1.91)
if (fixed_value == NULL) {[](#l1.92)
goto finally;[](#l1.93) }[](#l1.94)
else[](#l1.95)
args = PyTuple_Pack(1, value);[](#l1.96)
if (args == NULL)[](#l1.98)
goto finally;[](#l1.99)
res = PyEval_CallObject(type, args);[](#l1.100)
Py_DECREF(args);[](#l1.101)
if (res == NULL)[](#l1.102)
goto finally;[](#l1.103) Py_DECREF(value);[](#l1.104)
value = res;[](#l1.105)
value = fixed_value;[](#l1.106) }[](#l1.107) /* if the class of the instance doesn't exactly match the[](#l1.108) class of the type, believe the instance[](#l1.109)