Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-105375: Improve error handling in _Unpickler_SetInputStream()#105667
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
f1f1a0a620a98709e678b2d6a7b5666bd74078149be30aa91ab8606aba9ceb0b6a8a17File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Prevent exceptions from possibly being overwritten in case of multiplefailures.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1678,25 +1678,40 @@ _Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file) | ||
| { | ||
| /* Optional file methods */ | ||
| if (_PyObject_LookupAttr(file, &_Py_ID(peek), &self->peek) < 0) { | ||
| goto error; | ||
| } | ||
| if (_PyObject_LookupAttr(file, &_Py_ID(readinto), &self->readinto) < 0) { | ||
| goto error; | ||
| } | ||
| int no_read_attr = 0; | ||
| if (_PyObject_LookupAttr(file, &_Py_ID(read), &self->read) < 0) { | ||
| if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { | ||
erlend-aasland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| goto error; | ||
| } | ||
| PyErr_Clear(); | ||
erlend-aasland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| no_read_attr = 1; | ||
| } | ||
| int no_readline_attr = 0; | ||
| if (_PyObject_LookupAttr(file, &_Py_ID(readline), &self->readline) < 0) { | ||
| if (!PyErr_ExceptionMatches(PyExc_AttributeError)) { | ||
| goto error; | ||
| } | ||
| PyErr_Clear(); | ||
erlend-aasland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| no_readline_attr = 1; | ||
| } | ||
| if (no_read_attr || no_readline_attr) { | ||
erlend-aasland marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| PyErr_SetString(PyExc_TypeError, | ||
| "file must have 'read' and 'readline' attributes"); | ||
| goto error; | ||
| } | ||
| return 0; | ||
| error: | ||
| Py_CLEAR(self->read); | ||
| Py_CLEAR(self->readinto); | ||
| Py_CLEAR(self->readline); | ||
| Py_CLEAR(self->peek); | ||
| return -1; | ||
| } | ||
| /* Returns -1 (with an exception set) on failure, 0 on success. This may | ||