bpo-35134: Create Include/cpython/dictobject.h (GH-10732) · python/cpython@ffedd9a (original) (raw)

`@@ -4,7 +4,6 @@

`

4

4

`extern "C" {

`

5

5

`#endif

`

6

6

``

7

``

-

8

7

`/* Dictionary object type -- mapping from hashable object to object */

`

9

8

``

10

9

`/* The distribution includes a separate file, Objects/dictnotes.txt,

`

`@@ -13,119 +12,26 @@ extern "C" {

`

13

12

` tuning dictionaries, and several ideas for possible optimizations.

`

14

13

`*/

`

15

14

``

16

``

`-

#ifndef Py_LIMITED_API

`

17

``

-

18

``

`-

typedef struct _dictkeysobject PyDictKeysObject;

`

19

``

-

20

``

`-

/* The ma_values pointer is NULL for a combined table

`

21

``

`-

`

22

``

`-

*/

`

23

``

`-

typedef struct {

`

24

``

`-

PyObject_HEAD

`

25

``

-

26

``

`-

/* Number of items in the dictionary */

`

27

``

`-

Py_ssize_t ma_used;

`

28

``

-

29

``

`-

/* Dictionary version: globally unique, value change each time

`

30

``

`-

the dictionary is modified */

`

31

``

`-

uint64_t ma_version_tag;

`

32

``

-

33

``

`-

PyDictKeysObject *ma_keys;

`

34

``

-

35

``

`-

/* If ma_values is NULL, the table is "combined": keys and values

`

36

``

`-

are stored in ma_keys.

`

37

``

-

38

``

`-

If ma_values is not NULL, the table is splitted:

`

39

``

`-

keys are stored in ma_keys and values are stored in ma_values */

`

40

``

`-

PyObject **ma_values;

`

41

``

`-

} PyDictObject;

`

42

``

-

43

``

`-

typedef struct {

`

44

``

`-

PyObject_HEAD

`

45

``

`-

PyDictObject *dv_dict;

`

46

``

`-

} _PyDictViewObject;

`

47

``

-

48

``

`-

#endif /* Py_LIMITED_API */

`

49

``

-

50

15

`PyAPI_DATA(PyTypeObject) PyDict_Type;

`

51

``

`-

PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;

`

52

``

`-

PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;

`

53

``

`-

PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;

`

54

``

`-

PyAPI_DATA(PyTypeObject) PyDictRevIterKey_Type;

`

55

``

`-

PyAPI_DATA(PyTypeObject) PyDictRevIterItem_Type;

`

56

``

`-

PyAPI_DATA(PyTypeObject) PyDictRevIterValue_Type;

`

57

``

`-

PyAPI_DATA(PyTypeObject) PyDictKeys_Type;

`

58

``

`-

PyAPI_DATA(PyTypeObject) PyDictItems_Type;

`

59

``

`-

PyAPI_DATA(PyTypeObject) PyDictValues_Type;

`

60

16

``

61

17

`#define PyDict_Check(op) \

`

62

18

` PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_DICT_SUBCLASS)

`

63

19

`#define PyDict_CheckExact(op) (Py_TYPE(op) == &PyDict_Type)

`

64

``

`-

#define PyDictKeys_Check(op) PyObject_TypeCheck(op, &PyDictKeys_Type)

`

65

``

`-

#define PyDictItems_Check(op) PyObject_TypeCheck(op, &PyDictItems_Type)

`

66

``

`-

#define PyDictValues_Check(op) PyObject_TypeCheck(op, &PyDictValues_Type)

`

67

``

`-

/* This excludes Values, since they are not sets. */

`

68

``

`-

define PyDictViewSet_Check(op) \

`

69

``

`-

(PyDictKeys_Check(op) || PyDictItems_Check(op))

`

70

``

-

71

20

``

72

21

`PyAPI_FUNC(PyObject *) PyDict_New(void);

`

73

22

`PyAPI_FUNC(PyObject *) PyDict_GetItem(PyObject *mp, PyObject *key);

`

74

``

`-

#ifndef Py_LIMITED_API

`

75

``

`-

PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,

`

76

``

`-

Py_hash_t hash);

`

77

``

`-

#endif

`

78

23

`PyAPI_FUNC(PyObject *) PyDict_GetItemWithError(PyObject *mp, PyObject *key);

`

79

``

`-

#ifndef Py_LIMITED_API

`

80

``

`-

PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp,

`

81

``

`-

struct _Py_Identifier *key);

`

82

``

`-

PyAPI_FUNC(PyObject *) PyDict_SetDefault(

`

83

``

`-

PyObject *mp, PyObject *key, PyObject *defaultobj);

`

84

``

`-

#endif

`

85

24

`PyAPI_FUNC(int) PyDict_SetItem(PyObject *mp, PyObject *key, PyObject *item);

`

86

``

`-

#ifndef Py_LIMITED_API

`

87

``

`-

PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key,

`

88

``

`-

PyObject *item, Py_hash_t hash);

`

89

``

`-

#endif

`

90

25

`PyAPI_FUNC(int) PyDict_DelItem(PyObject *mp, PyObject *key);

`

91

``

`-

#ifndef Py_LIMITED_API

`

92

``

`-

PyAPI_FUNC(int) _PyDict_DelItem_KnownHash(PyObject *mp, PyObject *key,

`

93

``

`-

Py_hash_t hash);

`

94

``

`-

PyAPI_FUNC(int) _PyDict_DelItemIf(PyObject *mp, PyObject *key,

`

95

``

`-

int (*predicate)(PyObject *value));

`

96

``

`-

#endif

`

97

26

`PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);

`

98

27

`PyAPI_FUNC(int) PyDict_Next(

`

99

28

`PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);

`

100

``

`-

#ifndef Py_LIMITED_API

`

101

``

`-

PyDictKeysObject *_PyDict_NewKeysForClass(void);

`

102

``

`-

PyAPI_FUNC(PyObject *) PyObject_GenericGetDict(PyObject *, void *);

`

103

``

`-

PyAPI_FUNC(int) _PyDict_Next(

`

104

``

`-

PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);

`

105

``

`-

PyObject *_PyDictView_New(PyObject *, PyTypeObject *);

`

106

``

`-

#endif

`

107

29

`PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);

`

108

30

`PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);

`

109

31

`PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);

`

110

32

`PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp);

`

111

33

`PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp);

`

112

34

`PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key);

`

113

``

`-

#ifndef Py_LIMITED_API

`

114

``

`-

/* Get the number of items of a dictionary. */

`

115

``

`-

#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used)

`

116

``

`-

PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash);

`

117

``

`-

PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);

`

118

``

`-

PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);

`

119

``

`-

PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);

`

120

``

`-

Py_ssize_t _PyDict_KeysSize(PyDictKeysObject *keys);

`

121

``

`-

PyAPI_FUNC(Py_ssize_t) _PyDict_SizeOf(PyDictObject *);

`

122

``

`-

PyAPI_FUNC(PyObject *) _PyDict_Pop(PyObject *, PyObject *, PyObject *);

`

123

``

`-

PyObject *_PyDict_Pop_KnownHash(PyObject *, PyObject *, Py_hash_t, PyObject *);

`

124

``

`-

PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);

`

125

``

`-

#define _PyDict_HasSplitTable(d) ((d)->ma_values != NULL)

`

126

``

-

127

``

`-

PyAPI_FUNC(int) PyDict_ClearFreeList(void);

`

128

``

`-

#endif

`

129

35

``

130

36

`/* PyDict_Update(mp, other) is equivalent to PyDict_Merge(mp, other, 1). */

`

131

37

`PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other);

`

`@@ -136,44 +42,50 @@ PyAPI_FUNC(int) PyDict_Update(PyObject *mp, PyObject *other);

`

136

42

` dict.update(other) is equivalent to PyDict_Merge(dict, other, 1).

`

137

43

`*/

`

138

44

`PyAPI_FUNC(int) PyDict_Merge(PyObject *mp,

`

139

``

`-

PyObject *other,

`

140

``

`-

int override);

`

141

``

-

142

``

`-

#ifndef Py_LIMITED_API

`

143

``

`-

/* Like PyDict_Merge, but override can be 0, 1 or 2. If override is 0,

`

144

``

`-

the first occurrence of a key wins, if override is 1, the last occurrence

`

145

``

`-

of a key wins, if override is 2, a KeyError with conflicting key as

`

146

``

`-

argument is raised.

`

147

``

`-

*/

`

148

``

`-

PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override);

`

149

``

`-

PyAPI_FUNC(PyObject ) _PyDictView_Intersect(PyObject self, PyObject *other);

`

150

``

`-

#endif

`

``

45

`+

PyObject *other,

`

``

46

`+

int override);

`

151

47

``

152

48

`/* PyDict_MergeFromSeq2 updates/merges from an iterable object producing

`

153

49

` iterable objects of length 2. If override is true, the last occurrence

`

154

50

` of a key wins, else the first. The Python dict constructor dict(seq2)

`

155

51

` is equivalent to dict={}; PyDict_MergeFromSeq(dict, seq2, 1).

`

156

52

`*/

`

157

53

`PyAPI_FUNC(int) PyDict_MergeFromSeq2(PyObject *d,

`

158

``

`-

PyObject *seq2,

`

159

``

`-

int override);

`

``

54

`+

PyObject *seq2,

`

``

55

`+

int override);

`

160

56

``

161

57

`PyAPI_FUNC(PyObject *) PyDict_GetItemString(PyObject *dp, const char *key);

`

162

``

`-

#ifndef Py_LIMITED_API

`

163

``

`-

PyAPI_FUNC(PyObject *) _PyDict_GetItemId(PyObject *dp, struct _Py_Identifier *key);

`

164

``

`-

#endif /* !Py_LIMITED_API */

`

165

58

`PyAPI_FUNC(int) PyDict_SetItemString(PyObject *dp, const char *key, PyObject *item);

`

166

``

`-

#ifndef Py_LIMITED_API

`

167

``

`-

PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item);

`

168

``

`-

#endif /* !Py_LIMITED_API */

`

169

59

`PyAPI_FUNC(int) PyDict_DelItemString(PyObject *dp, const char *key);

`

170

60

``

171

``

`-

#ifndef Py_LIMITED_API

`

172

``

`-

PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key);

`

173

``

`-

PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out);

`

``

61

`+

/* Dictionary (keys, values, items) views */

`

``

62

+

``

63

`+

PyAPI_DATA(PyTypeObject) PyDictKeys_Type;

`

``

64

`+

PyAPI_DATA(PyTypeObject) PyDictValues_Type;

`

``

65

`+

PyAPI_DATA(PyTypeObject) PyDictItems_Type;

`

``

66

+

``

67

`+

#define PyDictKeys_Check(op) PyObject_TypeCheck(op, &PyDictKeys_Type)

`

``

68

`+

#define PyDictValues_Check(op) PyObject_TypeCheck(op, &PyDictValues_Type)

`

``

69

`+

#define PyDictItems_Check(op) PyObject_TypeCheck(op, &PyDictItems_Type)

`

``

70

`+

/* This excludes Values, since they are not sets. */

`

``

71

`+

define PyDictViewSet_Check(op) \

`

``

72

`+

(PyDictKeys_Check(op) || PyDictItems_Check(op))

`

``

73

+

``

74

`+

/* Dictionary (key, value, items) iterators */

`

174

75

``

175

``

`-

int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value);

`

176

``

`-

PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);

`

``

76

`+

PyAPI_DATA(PyTypeObject) PyDictIterKey_Type;

`

``

77

`+

PyAPI_DATA(PyTypeObject) PyDictIterValue_Type;

`

``

78

`+

PyAPI_DATA(PyTypeObject) PyDictIterItem_Type;

`

``

79

+

``

80

`+

PyAPI_DATA(PyTypeObject) PyDictRevIterKey_Type;

`

``

81

`+

PyAPI_DATA(PyTypeObject) PyDictRevIterItem_Type;

`

``

82

`+

PyAPI_DATA(PyTypeObject) PyDictRevIterValue_Type;

`

``

83

+

``

84

+

``

85

`+

#ifndef Py_LIMITED_API

`

``

86

`+

define Py_CPYTHON_DICTOBJECT_H

`

``

87

`+

include "cpython/dictobject.h"

`

``

88

`+

undef Py_CPYTHON_DICTOBJECT_H

`

177

89

`#endif

`

178

90

``

179

91

`#ifdef __cplusplus

`