-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem() #11112
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
Changes from 1 commit
6b79d33
b2f44b7
41f2ec3
15046cb
bce5923
fe7a98f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1899,12 +1899,7 @@ match_getslice_by_index(MatchObject* self, Py_ssize_t index, PyObject* def) | |
| void* ptr; | ||
| Py_ssize_t i, j; | ||
|
|
||
| if (index < 0 || index >= self->groups) { | ||
| /* raise IndexError if we were given a bad group number */ | ||
| PyErr_SetString( | ||
| PyExc_IndexError, | ||
| "no such group" | ||
| ); | ||
| if (index < 0) { | ||
|
||
| return NULL; | ||
| } | ||
|
|
||
|
|
@@ -1940,16 +1935,24 @@ match_getindex(MatchObject* self, PyObject* index) | |
| return 0; | ||
|
|
||
| if (PyIndex_Check(index)) { | ||
| return PyNumber_AsSsize_t(index, NULL); | ||
| i = PyNumber_AsSsize_t(index, NULL); | ||
| } | ||
| else { | ||
| i = -1; | ||
|
|
||
| i = -1; | ||
|
|
||
| if (self->pattern->groupindex) { | ||
| index = PyDict_GetItem(self->pattern->groupindex, index); | ||
| if (index && PyLong_Check(index)) { | ||
| i = PyLong_AsSsize_t(index); | ||
| if (self->pattern->groupindex) { | ||
| index = PyDict_GetItemWithError(self->pattern->groupindex, index); | ||
| if (index && PyLong_Check(index)) { | ||
| i = PyLong_AsSsize_t(index); | ||
| } | ||
| } | ||
| } | ||
| if (i < 0 || i >= self->groups) { | ||
| /* raise IndexError if we were given a bad group number */ | ||
| if (!PyErr_Occurred()) { | ||
| PyErr_SetString(PyExc_IndexError, "no such group"); | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
| return i; | ||
|
|
@@ -2114,11 +2117,7 @@ _sre_SRE_Match_start_impl(MatchObject *self, PyObject *group) | |
| { | ||
| Py_ssize_t index = match_getindex(self, group); | ||
|
|
||
| if (index < 0 || index >= self->groups) { | ||
| PyErr_SetString( | ||
| PyExc_IndexError, | ||
| "no such group" | ||
| ); | ||
| if (index < 0) { | ||
| return -1; | ||
| } | ||
|
|
||
|
|
@@ -2141,11 +2140,7 @@ _sre_SRE_Match_end_impl(MatchObject *self, PyObject *group) | |
| { | ||
| Py_ssize_t index = match_getindex(self, group); | ||
|
|
||
| if (index < 0 || index >= self->groups) { | ||
| PyErr_SetString( | ||
| PyExc_IndexError, | ||
| "no such group" | ||
| ); | ||
| if (index < 0) { | ||
| return -1; | ||
| } | ||
|
|
||
|
|
@@ -2195,11 +2190,7 @@ _sre_SRE_Match_span_impl(MatchObject *self, PyObject *group) | |
| { | ||
| Py_ssize_t index = match_getindex(self, group); | ||
|
|
||
| if (index < 0 || index >= self->groups) { | ||
| PyErr_SetString( | ||
| PyExc_IndexError, | ||
| "no such group" | ||
| ); | ||
| if (index < 0) { | ||
| return NULL; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,10 +226,13 @@ string_intern(xmlparseobject *self, const char* str) | |
| return result; | ||
| if (!self->intern) | ||
| return result; | ||
| value = PyDict_GetItem(self->intern, result); | ||
| value = PyDict_GetItemWithError(self->intern, result); | ||
| if (!value) { | ||
| if (PyDict_SetItem(self->intern, result, result) == 0) | ||
| if (!PyErr_Occurred() && | ||
| PyDict_SetItem(self->intern, result, result) == 0) | ||
| { | ||
| return result; | ||
| } | ||
| else { | ||
| Py_DECREF(result); | ||
| return NULL; | ||
|
|
@@ -1604,13 +1607,18 @@ static int init_handler_descrs(void) | |
| hi->getset.set = (setter)xmlparse_handler_setter; | ||
| hi->getset.closure = &handler_info[i]; | ||
|
|
||
| PyObject *descr; | ||
| if (PyDict_GetItemString(Xmlparsetype.tp_dict, hi->name)) | ||
| continue; | ||
| descr = PyDescr_NewGetSet(&Xmlparsetype, &hi->getset); | ||
|
|
||
| PyObject *descr = PyDescr_NewGetSet(&Xmlparsetype, &hi->getset); | ||
| if (descr == NULL) | ||
| return -1; | ||
|
|
||
| if (PyDict_GetItemWithError(Xmlparsetype.tp_dict, PyDescr_NAME(descr))) { | ||
| Py_DECREF(descr); | ||
| continue; | ||
| } | ||
| else if (PyErr_Occurred()) { | ||
| Py_DECREF(descr); | ||
| return -1; | ||
| } | ||
| if (PyDict_SetItem(Xmlparsetype.tp_dict, PyDescr_NAME(descr), descr) < 0) { | ||
| Py_DECREF(descr); | ||
| return -1; | ||
|
|
@@ -1682,8 +1690,8 @@ MODULE_INITFUNC(void) | |
| Py_DECREF(m); | ||
| return NULL; | ||
| } | ||
| errors_module = PyDict_GetItem(d, errmod_name); | ||
| if (errors_module == NULL) { | ||
| errors_module = PyDict_GetItemWithError(d, errmod_name); | ||
| if (errors_module == NULL && !PyErr_Occurred()) { | ||
ericsnowcurrently marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| errors_module = PyModule_New(MODULE_NAME ".errors"); | ||
| if (errors_module != NULL) { | ||
| _PyImport_SetModule(errmod_name, errors_module); | ||
|
|
@@ -1692,7 +1700,7 @@ MODULE_INITFUNC(void) | |
| } | ||
| } | ||
| Py_DECREF(errmod_name); | ||
| model_module = PyDict_GetItem(d, modelmod_name); | ||
| model_module = PyDict_GetItemWithError(d, modelmod_name); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't the error need to be returned or cleared?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is returned below, at line 1713.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The model_module gets reset on line 1705, so the error from the first attempt may remain uncleared or swallowed
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 1705 is executed only no error was raised at this line. Error handling in this function (as well as in many other module initialization functions) is pretty poor. Results of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then shouldn't line 1704 have
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already added. |
||
| if (model_module == NULL) { | ||
| model_module = PyModule_New(MODULE_NAME ".model"); | ||
| if (model_module != NULL) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.