-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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 2 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 |
---|---|---|
|
@@ -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.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -452,7 +452,7 @@ _PyRun_SimpleFileObject(FILE *fp, PyObject *filename, int closeit, | |
v = run_pyc_file(pyc_fp, dict, dict, flags); | ||
} else { | ||
/* When running from stdin, leave __main__.__loader__ alone */ | ||
if (PyUnicode_CompareWithASCIIString(filename, "<stdin>") != 0 && | ||
if ((!PyUnicode_Check(filename) || !PyUnicode_EqualToUTF8(filename, "<stdin>")) && | ||
set_main_loader(dict, filename, "SourceFileLoader") < 0) { | ||
fprintf(stderr, "python: failed to set __main__.__loader__\n"); | ||
ret = -1; | ||
|
@@ -472,11 +472,11 @@ _PyRun_SimpleFileObject(FILE *fp, PyObject *filename, int closeit, | |
|
||
done: | ||
if (set_file_name) { | ||
if (PyDict_DelItemString(dict, "__file__")) { | ||
PyErr_Clear(); | ||
if (PyDict_PopString(dict, "__file__", NULL) < 0) { | ||
PyErr_Print(); | ||
} | ||
if (PyDict_DelItemString(dict, "__cached__")) { | ||
PyErr_Clear(); | ||
if (PyDict_PopString(dict, "__cached__", NULL) < 0) { | ||
PyErr_Print(); | ||
} | ||
Comment on lines
-475
to
480
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. Nice. Using |
||
} | ||
Py_XDECREF(main_module); | ||
|
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