-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-116437: Use new C API PyDict_Pop() to simplify the code #116438
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 all commits
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 |
---|---|---|
|
@@ -17556,11 +17556,11 @@ posixmodule_exec(PyObject *m) | |
return -1; | ||
} | ||
|
||
if (PyDict_DelItemString(dct, "pwritev") == -1) { | ||
PyErr_Clear(); | ||
if (PyDict_PopString(dct, "pwritev", NULL) < 0) { | ||
return -1; | ||
} | ||
if (PyDict_DelItemString(dct, "preadv") == -1) { | ||
PyErr_Clear(); | ||
if (PyDict_PopString(dct, "preadv", NULL) < 0) { | ||
return -1; | ||
Comment on lines
-17559
to
+17563
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. This is slightly different behavior, isn't it? Before, we tried removing each item and ignored all errors. Now we fail at the first error. Is that okay? (Maybe @ronaldoussoren has some thoughts on this?) Was this intentional? (The same applies to the changes in Modules/timemodule.c.) 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. Not ignoring errors is always a good thing. |
||
} | ||
} | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1077,20 +1077,20 @@ def visitModule(self, mod): | |
if (!name) { | ||
goto cleanup; | ||
} | ||
PyObject *value = PyDict_GetItemWithError(remaining_dict, name); | ||
PyObject *value; | ||
int rc = PyDict_Pop(remaining_dict, name, &value); | ||
Py_DECREF(name); | ||
if (rc < 0) { | ||
goto cleanup; | ||
} | ||
if (!value) { | ||
if (PyErr_Occurred()) { | ||
goto cleanup; | ||
} | ||
break; | ||
} | ||
if (PyList_Append(positional_args, value) < 0) { | ||
rc = PyList_Append(positional_args, value); | ||
Py_DECREF(value); | ||
if (rc < 0) { | ||
goto cleanup; | ||
} | ||
if (PyDict_DelItem(remaining_dict, name) < 0) { | ||
goto cleanup; | ||
} | ||
Py_DECREF(name); | ||
Comment on lines
+1081
to
-1093
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. Good catch about fixing the decrefs. |
||
} | ||
PyObject *args_tuple = PyList_AsTuple(positional_args); | ||
if (!args_tuple) { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took me a minute to make sense of your changes in this file, but now I get it. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. I blocked here for 5 minutes :-D