| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d06c201 commit aa64c46
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,6 +91,7 @@ PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *); | |||
| 91 | 91 | PyAPI_FUNC(int) PyErr_GivenExceptionMatches(PyObject *, PyObject *); | |
| 92 | 92 | PyAPI_FUNC(int) PyErr_ExceptionMatches(PyObject *); | |
| 93 | 93 | PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**); | |
| 94 | + PyAPI_FUNC(void) _PyErr_ReplaceException(PyObject *, PyObject *, PyObject *); | ||
| 94 | 95 | ||
| 95 | 96 | /* */ | |
| 96 | 97 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -529,14 +529,8 @@ io_open(PyObject *self, PyObject *args, PyObject *kwds) | |||
| 529 | 529 | PyObject *exc, *val, *tb, *close_result; | |
| 530 | 530 | PyErr_Fetch(&exc, &val, &tb); | |
| 531 | 531 | close_result = PyObject_CallMethod(result, "close", NULL); | |
| 532 | - if (close_result != NULL) { | ||
| 533 | - Py_DECREF(close_result); | ||
| 534 | - PyErr_Restore(exc, val, tb); | ||
| 535 | - } else { | ||
| 536 | - Py_XDECREF(exc); | ||
| 537 | - Py_XDECREF(val); | ||
| 538 | - Py_XDECREF(tb); | ||
| 539 | - } | ||
| 532 | + _PyErr_ReplaceException(exc, val, tb); | ||
| 533 | + Py_XDECREF(close_result); | ||
| 540 | 534 | Py_DECREF(result); | |
| 541 | 535 | } | |
| 542 | 536 | Py_XDECREF(modeobj); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -483,15 +483,8 @@ buffered_close(buffered *self, PyObject *args) | |||
| 483 | 483 | res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_close, NULL); | |
| 484 | 484 | ||
| 485 | 485 | if (exc != NULL) { | |
| 486 | - if (res != NULL) { | ||
| 487 | - Py_CLEAR(res); | ||
| 488 | - PyErr_Restore(exc, val, tb); | ||
| 489 | - } | ||
| 490 | - else { | ||
| 491 | - Py_DECREF(exc); | ||
| 492 | - Py_XDECREF(val); | ||
| 493 | - Py_XDECREF(tb); | ||
| 494 | - } | ||
| 486 | + _PyErr_ReplaceException(exc, val, tb); | ||
| 487 | + Py_CLEAR(res); | ||
| 495 | 488 | } | |
| 496 | 489 | ||
| 497 | 490 | end: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2480,15 +2480,8 @@ textiowrapper_close(textio *self, PyObject *args) | |||
| 2480 | 2480 | ||
| 2481 | 2481 | res = PyObject_CallMethod(self->buffer, "close", NULL); | |
| 2482 | 2482 | if (exc != NULL) { | |
| 2483 | - if (res != NULL) { | ||
| 2484 | - Py_CLEAR(res); | ||
| 2485 | - PyErr_Restore(exc, val, tb); | ||
| 2486 | - } | ||
| 2487 | - else { | ||
| 2488 | - Py_DECREF(exc); | ||
| 2489 | - Py_XDECREF(val); | ||
| 2490 | - Py_XDECREF(tb); | ||
| 2491 | - } | ||
| 2483 | + _PyErr_ReplaceException(exc, val, tb); | ||
| 2484 | + Py_CLEAR(res); | ||
| 2492 | 2485 | } | |
| 2493 | 2486 | return res; | |
| 2494 | 2487 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -263,6 +263,26 @@ PyErr_Clear(void) | |||
| 263 | 263 | PyErr_Restore(NULL, NULL, NULL); | |
| 264 | 264 | } | |
| 265 | 265 | ||
| 266 | + /* Restore previously fetched exception if an exception is not set, | ||
| 267 | + otherwise drop previously fetched exception. | ||
| 268 | + Like _PyErr_ChainExceptions() in Python 3, but doesn't set the context. | ||
| 269 | + */ | ||
| 270 | + void | ||
| 271 | + _PyErr_ReplaceException(PyObject *exc, PyObject *val, PyObject *tb) | ||
| 272 | + { | ||
| 273 | + if (exc == NULL) | ||
| 274 | + return; | ||
| 275 | + | ||
| 276 | + if (PyErr_Occurred()) { | ||
| 277 | + Py_DECREF(exc); | ||
| 278 | + Py_XDECREF(val); | ||
| 279 | + Py_XDECREF(tb); | ||
| 280 | + } | ||
| 281 | + else { | ||
| 282 | + PyErr_Restore(exc, val, tb); | ||
| 283 | + } | ||
| 284 | + } | ||
| 285 | + | ||
| 266 | 286 | /* Convenience functions to set a type error exception and return 0 */ | |
| 267 | 287 | ||
| 268 | 288 | int | |
| Back | FazBrowse Home | New Git URL |
0 commit comments