Skip to content

Commit 1f5f06e

Browse files
committed
gh-106320: Remove private _PyDict C API
Move private _PyDict functions to the internal C API (pycore_dict.h): * _PyDict_Contains_KnownHash() * _PyDict_DebugMallocStats() * _PyDict_DelItemIf() * _PyDict_GetItemWithError() * _PyDict_HasOnlyStringKeys() * _PyDict_MaybeUntrack() * _PyDict_MergeEx() No longer export these functions.
1 parent 0a9b339 commit 1f5f06e

File tree

9 files changed

+33
-17
lines changed

9 files changed

+33
-17
lines changed

Diff for: Include/cpython/dictobject.h

+2-13
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ typedef struct {
3434

3535
PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
3636
Py_hash_t hash);
37-
PyAPI_FUNC(PyObject *) _PyDict_GetItemWithError(PyObject *dp, PyObject *key);
3837
PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,
3938
_Py_Identifier *key);
4039
PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *);
@@ -44,8 +43,7 @@ PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key,
4443
PyObject *item, Py_hash_t hash);
4544
PyAPI_FUNC(int) _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key,
4645
Py_hash_t hash);
47-
PyAPI_FUNC(int) _PyDict_DelItemIf(PyObject *mp, PyObject *key,
48-
int (*predicate)(PyObject *value));
46+
4947
PyAPI_FUNC(int) _PyDict_Next(
5048
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
5149

@@ -58,25 +56,16 @@ static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
5856
}
5957
#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
6058

61-
PyAPI_FUNC(int) _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
6259
PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, _Py_Identifier *);
60+
6361
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
64-
PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
65-
PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
6662
PyAPI_FUNC(Py_ssize_t) _PyDict_SizeOf(PyDictObject *);
6763
PyAPI_FUNC(PyObject *) _PyDict_Pop(PyObject *, PyObject *, PyObject *);
6864
#define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL)
6965

70-
/* Like PyDict_Merge, but override can be 0, 1 or 2. If override is 0,
71-
the first occurrence of a key wins, if override is 1, the last occurrence
72-
of a key wins, if override is 2, a KeyError with conflicting key as
73-
argument is raised.
74-
*/
75-
PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
7666
PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, _Py_Identifier *key, PyObject *item);
7767

7868
PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, _Py_Identifier *key);
79-
PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out);
8069

8170
/* _PyDictView */
8271

Diff for: Include/internal/pycore_dict.h

+20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ extern "C" {
1212
#include "pycore_dict_state.h"
1313
#include "pycore_runtime.h" // _PyRuntime
1414

15+
// Unsafe flavor of PyDict_GetItemWithError(): no error checking
16+
extern PyObject* _PyDict_GetItemWithError(PyObject *dp, PyObject *key);
17+
18+
extern int _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
19+
20+
extern int _PyDict_DelItemIf(PyObject *mp, PyObject *key,
21+
int (*predicate)(PyObject *value));
22+
23+
extern int _PyDict_HasOnlyStringKeys(PyObject *mp);
24+
25+
extern void _PyDict_MaybeUntrack(PyObject *mp);
26+
27+
/* Like PyDict_Merge, but override can be 0, 1 or 2. If override is 0,
28+
the first occurrence of a key wins, if override is 1, the last occurrence
29+
of a key wins, if override is 2, a KeyError with conflicting key as
30+
argument is raised.
31+
*/
32+
extern int _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);
33+
34+
extern void _PyDict_DebugMallocStats(FILE *out);
1535

1636
/* runtime lifecycle */
1737

Diff for: Modules/_weakref.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "pycore_dict.h" // _PyDict_DelItemIf()
23
#include "pycore_object.h" // _PyObject_GET_WEAKREFS_LISTPTR
34
#include "pycore_weakref.h" // _PyWeakref_IS_DEAD()
45

Diff for: Modules/gcmodule.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
#include "Python.h"
2727
#include "pycore_context.h"
28+
#include "pycore_dict.h" // _PyDict_MaybeUntrack()
2829
#include "pycore_initconfig.h"
29-
#include "pycore_interp.h" // PyInterpreterState.gc
30+
#include "pycore_interp.h" // PyInterpreterState.gc
3031
#include "pycore_object.h"
3132
#include "pycore_pyerrors.h"
32-
#include "pycore_pystate.h" // _PyThreadState_GET()
33-
#include "pycore_weakref.h" // _PyWeakref_ClearRef()
33+
#include "pycore_pystate.h" // _PyThreadState_GET()
34+
#include "pycore_weakref.h" // _PyWeakref_ClearRef()
3435
#include "pydtrace.h"
3536

3637
typedef struct _gc_runtime_state GCState;

Diff for: Objects/setobject.c

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333

3434
#include "Python.h"
35+
#include "pycore_dict.h" // _PyDict_Contains_KnownHash()
3536
#include "pycore_modsupport.h" // _PyArg_NoKwnames()
3637
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
3738
#include "pycore_setobject.h" // _PySet_NextEntry() definition

Diff for: Python/_warnings.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Python.h"
2+
#include "pycore_dict.h" // _PyDict_GetItemWithError()
23
#include "pycore_frame.h"
34
#include "pycore_initconfig.h"
45
#include "pycore_interp.h" // PyInterpreterState.warnings

Diff for: Python/bltinmodule.c

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "pycore_call.h" // _PyObject_CallNoArgs()
77
#include "pycore_ceval.h" // _PyEval_Vector()
88
#include "pycore_compile.h" // _PyAST_Compile()
9+
#include "pycore_dict.h" // _PyDict_GetItemWithError()
910
#include "pycore_long.h" // _PyLong_CompactValue
1011
#include "pycore_modsupport.h" // _PyArg_NoKwnames()
1112
#include "pycore_object.h" // _Py_AddToAllObjects()

Diff for: Python/getargs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
/* New getargs implementation */
33

44
#include "Python.h"
5-
#include "pycore_tuple.h" // _PyTuple_ITEMS()
5+
#include "pycore_dict.h" // _PyDict_HasOnlyStringKeys()
66
#include "pycore_pylifecycle.h" // _PyArg_Fini
7+
#include "pycore_tuple.h" // _PyTuple_ITEMS()
78

89
#include <ctype.h>
910
#include <float.h>

Diff for: Python/sysmodule.c

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Data members:
1717
#include "Python.h"
1818
#include "pycore_call.h" // _PyObject_CallNoArgs()
1919
#include "pycore_ceval.h" // _PyEval_SetAsyncGenFinalizer()
20+
#include "pycore_dict.h" // _PyDict_GetItemWithError()
2021
#include "pycore_frame.h" // _PyInterpreterFrame
2122
#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
2223
#include "pycore_long.h" // _PY_LONG_MAX_STR_DIGITS_THRESHOLD

0 commit comments

Comments
 (0)