| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4e30ed3 commit b0be6b3
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -342,9 +342,6 @@ def g(): | |||
| 342 | 342 | try: | |
| 343 | 343 | yield | |
| 344 | 344 | except Exception: | |
| 345 | - # Without the `gi_exc_state.exc_type != Py_None` in | ||
| 346 | - # _gen_throw(), this line was causing a crash ("Segmentation | ||
| 347 | - # fault (core dumped)") on e.g. Fedora 32. | ||
| 348 | 345 | raise RuntimeError | |
| 349 | 346 | ||
| 350 | 347 | gen = g() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -304,22 +304,33 @@ static PyGetSetDef BaseException_getset[] = { | |||
| 304 | 304 | }; | |
| 305 | 305 | ||
| 306 | 306 | ||
| 307 | + static inline PyBaseExceptionObject* | ||
| 308 | + _PyBaseExceptionObject_cast(PyObject *exc) | ||
| 309 | + { | ||
| 310 | + assert(PyExceptionInstance_Check(exc)); | ||
| 311 | + return (PyBaseExceptionObject *)exc; | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + | ||
| 307 | 315 | PyObject * | |
| 308 | - PyException_GetTraceback(PyObject *self) { | ||
| 309 | - PyBaseExceptionObject *base_self = (PyBaseExceptionObject *)self; | ||
| 316 | + PyException_GetTraceback(PyObject *self) | ||
| 317 | + { | ||
| 318 | + PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self); | ||
| 310 | 319 | Py_XINCREF(base_self->traceback); | |
| 311 | 320 | return base_self->traceback; | |
| 312 | 321 | } | |
| 313 | 322 | ||
| 314 | 323 | ||
| 315 | 324 | int | |
| 316 | - PyException_SetTraceback(PyObject *self, PyObject *tb) { | ||
| 317 | - return BaseException_set_tb((PyBaseExceptionObject *)self, tb, NULL); | ||
| 325 | + PyException_SetTraceback(PyObject *self, PyObject *tb) | ||
| 326 | + { | ||
| 327 | + return BaseException_set_tb(_PyBaseExceptionObject_cast(self), tb, NULL); | ||
| 318 | 328 | } | |
| 319 | 329 | ||
| 320 | 330 | PyObject * | |
| 321 | - PyException_GetCause(PyObject *self) { | ||
| 322 | - PyObject *cause = ((PyBaseExceptionObject *)self)->cause; | ||
| 331 | + PyException_GetCause(PyObject *self) | ||
| 332 | + { | ||
| 333 | + PyObject *cause = _PyBaseExceptionObject_cast(self)->cause; | ||
| 323 | 334 | Py_XINCREF(cause); | |
| 324 | 335 | return cause; | |
| 325 | 336 | } | |
@@ -328,13 +339,15 @@ PyException_GetCause(PyObject *self) { | |||
| 328 | 339 | void | |
| 329 | 340 | PyException_SetCause(PyObject *self, PyObject *cause) | |
| 330 | 341 | { | |
| 331 | - ((PyBaseExceptionObject *)self)->suppress_context = 1; | ||
| 332 | - Py_XSETREF(((PyBaseExceptionObject *)self)->cause, cause); | ||
| 342 | + PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self); | ||
| 343 | + base_self->suppress_context = 1; | ||
| 344 | + Py_XSETREF(base_self->cause, cause); | ||
| 333 | 345 | } | |
| 334 | 346 | ||
| 335 | 347 | PyObject * | |
| 336 | - PyException_GetContext(PyObject *self) { | ||
| 337 | - PyObject *context = ((PyBaseExceptionObject *)self)->context; | ||
| 348 | + PyException_GetContext(PyObject *self) | ||
| 349 | + { | ||
| 350 | + PyObject *context = _PyBaseExceptionObject_cast(self)->context; | ||
| 338 | 351 | Py_XINCREF(context); | |
| 339 | 352 | return context; | |
| 340 | 353 | } | |
@@ -343,14 +356,15 @@ PyException_GetContext(PyObject *self) { | |||
| 343 | 356 | void | |
| 344 | 357 | PyException_SetContext(PyObject *self, PyObject *context) | |
| 345 | 358 | { | |
| 346 | - Py_XSETREF(((PyBaseExceptionObject *)self)->context, context); | ||
| 359 | + Py_XSETREF(_PyBaseExceptionObject_cast(self)->context, context); | ||
| 347 | 360 | } | |
| 348 | 361 | ||
| 349 | 362 | #undef PyExceptionClass_Name | |
| 350 | 363 | ||
| 351 | 364 | const char * | |
| 352 | 365 | PyExceptionClass_Name(PyObject *ob) | |
| 353 | 366 | { | |
| 367 | + assert(PyExceptionClass_Check(ob)); | ||
| 354 | 368 | return ((PyTypeObject*)ob)->tp_name; | |
| 355 | 369 | } | |
| 356 | 370 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -512,15 +512,15 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, | |||
| 512 | 512 | } | |
| 513 | 513 | ||
| 514 | 514 | PyErr_Restore(typ, val, tb); | |
| 515 | - /* XXX It seems like we shouldn't have to check not equal to Py_None | ||
| 516 | - here because exc_type should only ever be a class. But not including | ||
| 517 | - this check was causing crashes on certain tests e.g. on Fedora. */ | ||
| 518 | - if (gen->gi_exc_state.exc_type && gen->gi_exc_state.exc_type != Py_None) { | ||
| 519 | - Py_INCREF(gen->gi_exc_state.exc_type); | ||
| 520 | - Py_XINCREF(gen->gi_exc_state.exc_value); | ||
| 521 | - Py_XINCREF(gen->gi_exc_state.exc_traceback); | ||
| 522 | - _PyErr_ChainExceptions(gen->gi_exc_state.exc_type, | ||
| 523 | - gen->gi_exc_state.exc_value, gen->gi_exc_state.exc_traceback); | ||
| 515 | + | ||
| 516 | + _PyErr_StackItem *gi_exc_state = &gen->gi_exc_state; | ||
| 517 | + if (gi_exc_state->exc_type != NULL && gi_exc_state->exc_type != Py_None) { | ||
| 518 | + Py_INCREF(gi_exc_state->exc_type); | ||
| 519 | + Py_XINCREF(gi_exc_state->exc_value); | ||
| 520 | + Py_XINCREF(gi_exc_state->exc_traceback); | ||
| 521 | + _PyErr_ChainExceptions(gi_exc_state->exc_type, | ||
| 522 | + gi_exc_state->exc_value, | ||
| 523 | + gi_exc_state->exc_traceback); | ||
| 524 | 524 | } | |
| 525 | 525 | return gen_send_ex(gen, Py_None, 1, 0); | |
| 526 | 526 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,7 +107,8 @@ _PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value) | |||
| 107 | 107 | if (exception != NULL && | |
| 108 | 108 | !PyExceptionClass_Check(exception)) { | |
| 109 | 109 | _PyErr_Format(tstate, PyExc_SystemError, | |
| 110 | - "exception %R not a BaseException subclass", | ||
| 110 | + "_PyErr_SetObject: " | ||
| 111 | + "exception %R is not a BaseException subclass", | ||
| 111 | 112 | exception); | |
| 112 | 113 | return; | |
| 113 | 114 | } | |
@@ -484,6 +485,15 @@ _PyErr_ChainExceptions(PyObject *exc, PyObject *val, PyObject *tb) | |||
| 484 | 485 | return; | |
| 485 | 486 | ||
| 486 | 487 | PyThreadState *tstate = _PyThreadState_GET(); | |
| 488 | + | ||
| 489 | + if (!PyExceptionClass_Check(exc)) { | ||
| 490 | + _PyErr_Format(tstate, PyExc_SystemError, | ||
| 491 | + "_PyErr_ChainExceptions: " | ||
| 492 | + "exception %R is not a BaseException subclass", | ||
| 493 | + exc); | ||
| 494 | + return; | ||
| 495 | + } | ||
| 496 | + | ||
| 487 | 497 | if (_PyErr_Occurred(tstate)) { | |
| 488 | 498 | PyObject *exc2, *val2, *tb2; | |
| 489 | 499 | _PyErr_Fetch(tstate, &exc2, &val2, &tb2); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments