Skip to content

Commit 87cc9b1

Browse files
vstinnerasvetlov
authored andcommitted
bpo-45316: Move private PyDict functions to internal C API (GH-31577)
Move the following private unexported functions to the internal C API headers: * _PyDictKeys_GetVersionForCurrentState() * _PyDictKeys_StringLookup() * _PyDict_FromKeys() * _PyDict_GetItemHint() * _PyDict_KeysSize() * _PyDict_LoadGlobal() * _PyDict_NewKeysForClass() * _PyDict_Pop_KnownHash() * _PyDict_SetItem_Take2() * _PyObjectDict_SetItem() * _PyObject_MakeDictFromInstanceAttributes() * _Py_dict_lookup()
1 parent 992d9e7 commit 87cc9b1

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

Include/cpython/dictobject.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ PyAPI_FUNC(int) _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key,
4242
Py_hash_t hash);
4343
PyAPI_FUNC(int) _PyDict_DelItemIf(PyObject *mp, PyObject *key,
4444
int (*predicate)(PyObject *value));
45-
PyDictKeysObject *_PyDict_NewKeysForClass(void);
4645
PyAPI_FUNC(int) _PyDict_Next(
4746
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
4847

@@ -53,11 +52,8 @@ PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, _Py_Identifier *);
5352
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
5453
PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
5554
PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
56-
Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys);
5755
PyAPI_FUNC(Py_ssize_t) _PyDict_SizeOf(PyDictObject *);
5856
PyAPI_FUNC(PyObject *) _PyDict_Pop(PyObject *, PyObject *, PyObject *);
59-
PyObject *_PyDict_Pop_KnownHash(PyObject *, PyObject *, Py_hash_t, PyObject *);
60-
PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
6157
#define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL)
6258

6359
/* Like PyDict_Merge, but override can be 0, 1 or 2. If override is 0,
@@ -71,10 +67,6 @@ PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, _Py_Identifier *key, PyObject *i
7167
PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, _Py_Identifier *key);
7268
PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out);
7369

74-
int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);
75-
PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
76-
Py_ssize_t _PyDict_GetItemHint(PyDictObject *, PyObject *, Py_ssize_t, PyObject **);
77-
7870
/* _PyDictView */
7971

8072
typedef struct {
@@ -84,9 +76,3 @@ typedef struct {
8476

8577
PyAPI_FUNC(PyObject *) _PyDictView_New(PyObject *, PyTypeObject *);
8678
PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other);
87-
88-
/* Gets a version number unique to the current state of the keys of dict, if possible.
89-
* Returns the version number, or zero if it was not possible to get a version number. */
90-
uint32_t _PyDictKeys_GetVersionForCurrentState(PyDictKeysObject *dictkeys);
91-
92-
Py_ssize_t _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyObject *key);

Include/internal/pycore_dict.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,29 @@ typedef struct {
4343
PyObject *me_value; /* This field is only meaningful for combined tables */
4444
} PyDictKeyEntry;
4545

46+
extern PyDictKeysObject *_PyDict_NewKeysForClass(void);
47+
extern PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
48+
49+
/* Gets a version number unique to the current state of the keys of dict, if possible.
50+
* Returns the version number, or zero if it was not possible to get a version number. */
51+
extern uint32_t _PyDictKeys_GetVersionForCurrentState(PyDictKeysObject *dictkeys);
52+
53+
extern Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys);
54+
4655
/* _Py_dict_lookup() returns index of entry which can be used like DK_ENTRIES(dk)[index].
4756
* -1 when no entry found, -3 when compare raises error.
4857
*/
49-
Py_ssize_t _Py_dict_lookup(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr);
58+
extern Py_ssize_t _Py_dict_lookup(PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject **value_addr);
59+
60+
extern Py_ssize_t _PyDict_GetItemHint(PyDictObject *, PyObject *, Py_ssize_t, PyObject **);
61+
extern Py_ssize_t _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyObject *key);
62+
extern PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
5063

5164
/* Consumes references to key and value */
52-
int _PyDict_SetItem_Take2(PyDictObject *op, PyObject *key, PyObject *value);
65+
extern int _PyDict_SetItem_Take2(PyDictObject *op, PyObject *key, PyObject *value);
66+
extern int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);
67+
68+
extern PyObject *_PyDict_Pop_KnownHash(PyObject *, PyObject *, Py_hash_t, PyObject *);
5369

5470
#define DKIX_EMPTY (-1)
5571
#define DKIX_DUMMY (-2) /* Used internally */
@@ -138,7 +154,7 @@ extern uint64_t _pydict_global_version;
138154

139155
#define DICT_NEXT_VERSION() (++_pydict_global_version)
140156

141-
PyObject *_PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values);
157+
extern PyObject *_PyObject_MakeDictFromInstanceAttributes(PyObject *obj, PyDictValues *values);
142158

143159
static inline void
144160
_PyDictValues_AddToInsertionOrder(PyDictValues *values, Py_ssize_t ix)

0 commit comments

Comments
 (0)