Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-45711: use exc_value instead of exc_type to determine if exc_info is valid. Add more assertions.#29627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
iritkatriel merged 7 commits into python:main from iritkatriel:bpo-45711-remove-exc_type_fieldNov 25, 2021
Uh oh!
There was an error while loading. Please reload this page.
Merged
bpo-45711: use exc_value instead of exc_type to determine if exc_info is valid. Add more assertions. #29627
Changes from all commits
Commits
Show all changes
7 commits Select commit Hold shift + click to select a range
9275583 bpo-45711: make decisions based on exc_value instead of exc_type. Str…
iritkatriel fbff4f6 put assertion definition under Py_DEBUG to remove Address sanitizer w…
iritkatriel bc889bc Merge remote-tracking branch 'upstream/main' into bpo-45711-remove-ex…
iritkatriel 3c451a1 err_info->exc_value ==> exc_value
iritkatriel 277c509 Simplified _PyErr_GetExcInfo. Moved assertion in _PyErr_GetTopmostExc…
iritkatriel 437cebb exc2 --> typ2
iritkatriel de67ed6 exc --> typ
iritkatriel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -79,11 +79,16 @@ _PyErr_StackItem * | ||
| _PyErr_GetTopmostException(PyThreadState *tstate) | ||
| { | ||
| _PyErr_StackItem *exc_info = tstate->exc_info; | ||
| while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && | ||
| assert(exc_info); | ||
| while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) && | ||
| exc_info->previous_item != NULL) | ||
| { | ||
| assert(exc_info->exc_type == NULL || exc_info->exc_type == Py_None); | ||
| exc_info = exc_info->previous_item; | ||
| } | ||
| assert(exc_info->previous_item == NULL || | ||
| (exc_info->exc_type != NULL && exc_info->exc_type != Py_None)); | ||
| return exc_info; | ||
| } | ||
| @@ -471,10 +476,20 @@ _PyErr_GetExcInfo(PyThreadState *tstate, | ||
| PyObject **p_type, PyObject **p_value, PyObject **p_traceback) | ||
| { | ||
| _PyErr_StackItem *exc_info = _PyErr_GetTopmostException(tstate); | ||
| *p_type = exc_info->exc_type; | ||
| *p_value = exc_info->exc_value; | ||
| *p_traceback = exc_info->exc_traceback; | ||
gvanrossum marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| if (*p_value == NULL || *p_value == Py_None){ | ||
| assert(exc_info->exc_type == NULL || exc_info->exc_type == Py_None); | ||
| *p_type = Py_None; | ||
| } | ||
| else{ | ||
| assert(PyExceptionInstance_Check(*p_value)); | ||
| assert(exc_info->exc_type == PyExceptionInstance_Class(*p_value)); | ||
| *p_type = PyExceptionInstance_Class(*p_value); | ||
| } | ||
| Py_XINCREF(*p_type); | ||
| Py_XINCREF(*p_value); | ||
| Py_XINCREF(*p_traceback); | ||
| @@ -507,42 +522,66 @@ PyErr_SetExcInfo(PyObject *p_type, PyObject *p_value, PyObject *p_traceback) | ||
| Py_XDECREF(oldtraceback); | ||
| } | ||
| PyObject* | ||
| _PyErr_StackItemToExcInfoTuple(_PyErr_StackItem *err_info) | ||
| { | ||
| PyObject *exc_value = err_info->exc_value; | ||
| if (exc_value == NULL){ | ||
| exc_value = Py_None; | ||
| } | ||
| assert(exc_value == Py_None || PyExceptionInstance_Check(exc_value)); | ||
| PyObject *exc_type = PyExceptionInstance_Check(exc_value) ? | ||
| PyExceptionInstance_Class(exc_value) : | ||
| Py_None; | ||
| return Py_BuildValue( | ||
| "(OOO)", | ||
| exc_type, | ||
| exc_value, | ||
| err_info->exc_traceback != NULL ? | ||
| err_info->exc_traceback : Py_None); | ||
| } | ||
| /* Like PyErr_Restore(), but if an exception is already set, | ||
| set the context associated with it. | ||
| The caller is responsible for ensuring that this call won't create | ||
| any cycles in the exception context chain. */ | ||
| void | ||
| _PyErr_ChainExceptions(PyObject *exc, PyObject *val, PyObject *tb) | ||
| _PyErr_ChainExceptions(PyObject *typ, PyObject *val, PyObject *tb) | ||
| { | ||
| if (exc == NULL) | ||
| if (typ == NULL) | ||
| return; | ||
| PyThreadState *tstate = _PyThreadState_GET(); | ||
| if (!PyExceptionClass_Check(exc)){ | ||
| if (!PyExceptionClass_Check(typ)){ | ||
| _PyErr_Format(tstate, PyExc_SystemError, | ||
| "_PyErr_ChainExceptions: " | ||
| "exception %R is not a BaseException subclass", | ||
| exc); | ||
| typ); | ||
| return; | ||
| } | ||
| if (_PyErr_Occurred(tstate)){ | ||
| PyObject *exc2, *val2, *tb2; | ||
| _PyErr_Fetch(tstate, &exc2, &val2, &tb2); | ||
| _PyErr_NormalizeException(tstate, &exc, &val, &tb); | ||
| PyObject *typ2, *val2, *tb2; | ||
| _PyErr_Fetch(tstate, &typ2, &val2, &tb2); | ||
| _PyErr_NormalizeException(tstate, &typ, &val, &tb); | ||
| if (tb != NULL){ | ||
| PyException_SetTraceback(val, tb); | ||
| Py_DECREF(tb); | ||
| } | ||
| Py_DECREF(exc); | ||
| _PyErr_NormalizeException(tstate, &exc2, &val2, &tb2); | ||
| Py_DECREF(typ); | ||
| _PyErr_NormalizeException(tstate, &typ2, &val2, &tb2); | ||
| PyException_SetContext(val2, val); | ||
| _PyErr_Restore(tstate, exc2, val2, tb2); | ||
| _PyErr_Restore(tstate, typ2, val2, tb2); | ||
| } | ||
| else{ | ||
| _PyErr_Restore(tstate, exc, val, tb); | ||
| _PyErr_Restore(tstate, typ, val, tb); | ||
| } | ||
| } | ||
| @@ -567,7 +606,11 @@ _PyErr_ChainStackItem(_PyErr_StackItem *exc_info) | ||
| } else{ | ||
| exc_info_given = 1; | ||
| } | ||
| if (exc_info->exc_type == NULL || exc_info->exc_type == Py_None){ | ||
| assert( (exc_info->exc_type == NULL || exc_info->exc_type == Py_None) == | ||
| (exc_info->exc_value == NULL || exc_info->exc_value == Py_None) ); | ||
| if (exc_info->exc_value == NULL || exc_info->exc_value == Py_None){ | ||
| return; | ||
| } | ||
| @@ -579,21 +622,32 @@ _PyErr_ChainStackItem(_PyErr_StackItem *exc_info) | ||
| tstate->exc_info = exc_info; | ||
| } | ||
| PyObject *exc, *val, *tb; | ||
| _PyErr_Fetch(tstate, &exc, &val, &tb); | ||
| PyObject *typ, *val, *tb; | ||
| _PyErr_Fetch(tstate, &typ, &val, &tb); | ||
| PyObject *exc2, *val2, *tb2; | ||
| exc2 = exc_info->exc_type; | ||
| PyObject *typ2, *val2, *tb2; | ||
| typ2 = exc_info->exc_type; | ||
| val2 = exc_info->exc_value; | ||
| tb2 = exc_info->exc_traceback; | ||
| _PyErr_NormalizeException(tstate, &exc2, &val2, &tb2); | ||
| #ifdef Py_DEBUG | ||
| PyObject *typ2_before = typ2; | ||
| PyObject *val2_before = val2; | ||
| PyObject *tb2_before = tb2; | ||
| #endif | ||
| _PyErr_NormalizeException(tstate, &typ2, &val2, &tb2); | ||
| #ifdef Py_DEBUG | ||
| /* exc_info should already be normalized */ | ||
| assert(typ2 == typ2_before); | ||
| assert(val2 == val2_before); | ||
| assert(tb2 == tb2_before); | ||
| #endif | ||
| if (tb2 != NULL){ | ||
| PyException_SetTraceback(val2, tb2); | ||
| } | ||
| /* _PyErr_SetObject sets the context from PyThreadState. */ | ||
| _PyErr_SetObject(tstate, exc, val); | ||
| Py_DECREF(exc); // since _PyErr_Occurred was true | ||
| _PyErr_SetObject(tstate, typ, val); | ||
| Py_DECREF(typ); // since _PyErr_Occurred was true | ||
| Py_XDECREF(val); | ||
| Py_XDECREF(tb); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.