8000 gh-106320: Remove _PyDict_GetItemStringWithError() function (#108313) · python/cpython@615f6e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 615f6e9

Browse files
authored
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.
1 parent 0cb0c23 commit 615f6e9

File tree

8 files changed

+12
-6
lines changed

8 files changed

+12
-6
lines changed

Include/cpython/dictobject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
3636
Py_hash_t hash);
3737
PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,
3838
_Py_Identifier *key);
39-
PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *);
4039
PyAPI_FUNC(PyObject *) PyDict_SetDefault(
4140
PyObject *mp, PyObject *key, PyObject *defaultobj);
4241
PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key,

Include/internal/pycore_dict.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern "C" {
1313

1414
// Unsafe flavor of PyDict_GetItemWithError(): no error checking
1515
extern PyObject* _PyDict_GetItemWithError(PyObject *dp, PyObject *key);
16+
extern PyObject* _PyDict_GetItemStringWithError(PyObject *, const char *);
1617

1718
extern int _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
1819

Modules/_testcapi/code.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ get_code_extra_index(PyInterpreterState* interp) {
99
PyObject *interp_dict = PyInterpreterState_GetDict(interp); // borrowed
1010
assert(interp_dict); // real users would handle missing dict... somehow
1111

12-
PyObject *index_obj = _PyDict_GetItemStringWithError(interp_dict, key); // borrowed
12+
PyObject *index_obj;
13+
if (PyDict_GetItemStringRef(interp_dict, key, &index_obj) < 0) {
14+
goto finally;
15+
}
1316
Py_ssize_t index = 0;
1417
if (!index_obj) {
15-
if (PyErr_Occurred()) {
16-
goto finally;
17-
}
1818
index = PyUnstable_Eval_RequestCodeExtraIndex(NULL);
1919
if (index < 0 || PyErr_Occurred()) {
2020
goto finally;
@@ -31,6 +31,7 @@ get_code_extra_index(PyInterpreterState* interp) {
3131
}
3232
else {
3333
index = PyLong_AsSsize_t(index_obj);
34+
Py_DECREF(index_obj);
3435
if (index == -1 && PyErr_Occurred()) {
3536
goto finally;
3637
}

Objects/structseq.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include "Python.h"
11+
#include "pycore_dict.h" // _PyDict_GetItemStringWithError()
1112
#include "pycore_tuple.h" // _PyTuple_FromArray()
1213
#include "pycore_object.h" // _PyObject_GC_TRACK()
1314

Python/codecs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Copyright (c) Corporation for National Research Initiatives.
1010

1111
#include "Python.h"
1212
#include "pycore_call.h" // _PyObject_CallNoArgs()
13+
#include "pycore_dict.h" // _PyDict_GetItemStringWithError()
1314
#include "pycore_interp.h" // PyInterpreterState.codec_search_path
1415
#include "pycore_pyerrors.h" // _PyErr_FormatNote()
1516
#include "pycore_pystate.h" // _PyInterpreterState_GET()

Python/import.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Module definition and import implementation */
22

33
#include "Python.h"
4-
4+
#include "pycore_dict.h" // _PyDict_GetItemStringWithError()
55
#include "pycore_hashtable.h" // _Py_hashtable_new_full()
66
#include "pycore_import.h" // _PyImport_BootstrapImp()
77
#include "pycore_initconfig.h" // _PyStatus_OK()
@@ -15,6 +15,7 @@
1515
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1616
#include "pycore_sysmodule.h" // _PySys_Audit()
1717
#include "pycore_weakref.h" // _PyWeakref_GET_REF()
18+
1819
#include "marshal.h" // PyMarshal_ReadObjectFromString()
1920
#include "importdl.h" // _PyImport_DynLoadFiletab
2021
#include "pydtrace.h" // PyDTrace_IMPORT_FIND_LOAD_START_ENABLED()

Python/initconfig.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "pycore_dict.h" // _PyDict_GetItemStringWithError()
23
#include "pycore_fileutils.h" // _Py_HasFileSystemDefaultEncodeErrors
34
#include "pycore_getopt.h" // _PyOS_GetOpt()
45
#include "pycore_initconfig.h" // _PyStatus_OK()

Python/pythonrun.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "pycore_ast.h" // PyAST_mod2obj
1616
#include "pycore_ceval.h" // _Py_EnterRecursiveCall
1717
#include "pycore_compile.h" // _PyAST_Compile()
18+
#include "pycore_dict.h" // _PyDict_GetItemStringWithError()
1819
#include "pycore_interp.h" // PyInterpreterState.importlib
1920
#include "pycore_object.h" // _PyDebug_PrintTotalRefs()
2021
#include "pycore_parser.h" // _PyParser_ASTFromString()

0 commit comments

Comments
 (0)
0