summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-08-22 18:17:25 (GMT)
committerGitHub <noreply@github.com>2023-08-22 18:17:25 (GMT)
commit615f6e946db6d7eae66b8de9a75a6c58a84516a6 (patch)
treed94d9365566defdedf9f2cf0deffa8f53b6ae587 /Modules
parent0cb0c238d520a8718e313b52cffc356a5a7561bf (diff)
downloadcpython-615f6e946db6d7eae66b8de9a75a6c58a84516a6.zip
cpython-615f6e946db6d7eae66b8de9a75a6c58a84516a6.tar.gz
cpython-615f6e946db6d7eae66b8de9a75a6c58a84516a6.tar.bz2
gh-106320: Remove _PyDict_GetItemStringWithError() function (#108313)
Remove private _PyDict_GetItemStringWithError() function of the public C API: the new PyDict_GetItemStringRef() can be used instead. * Move private _PyDict_GetItemStringWithError() to the internal C API. * _testcapi get_code_extra_index() uses PyDict_GetItemStringRef(). Avoid using private functions in _testcapi which tests the public C API.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testcapi/code.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Modules/_testcapi/code.c b/Modules/_testcapi/code.c
index cadaf5e..691dd5f 100644
--- a/Modules/_testcapi/code.c
+++ b/Modules/_testcapi/code.c
@@ -9,12 +9,12 @@ get_code_extra_index(PyInterpreterState* interp) {
PyObject *interp_dict = PyInterpreterState_GetDict(interp); // borrowed
assert(interp_dict); // real users would handle missing dict... somehow
- PyObject *index_obj = _PyDict_GetItemStringWithError(interp_dict, key); // borrowed
+ PyObject *index_obj;
+ if (PyDict_GetItemStringRef(interp_dict, key, &index_obj) < 0) {
+ goto finally;
+ }
Py_ssize_t index = 0;
if (!index_obj) {
- if (PyErr_Occurred()) {
- goto finally;
- }
index = PyUnstable_Eval_RequestCodeExtraIndex(NULL);
if (index < 0 || PyErr_Occurred()) {
goto finally;
@@ -31,6 +31,7 @@ get_code_extra_index(PyInterpreterState* interp) {
}
else {
index = PyLong_AsSsize_t(index_obj);
+ Py_DECREF(index_obj);
if (index == -1 && PyErr_Occurred()) {
goto finally;
}