Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
cpython/Include/cpython/dictobject.h at main · python/cpython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Uh oh!
There was an error while loading.
Please reload this page
.
python
/
cpython
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
35.4k
Star
76.9k
Code
Issues
5k+
Pull requests
2.6k
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
main
Breadcrumbs
cpython
/
Include
/
cpython
/
dictobject.h
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
108 lines (86 loc) · 3.84 KB
main
Breadcrumbs
cpython
/
Include
/
cpython
/
dictobject.h
Copy path
Top
File metadata and controls
Code
Blame
108 lines (86 loc) · 3.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef
Py_CPYTHON_DICTOBJECT_H
# error
"this header file must not be included directly"
#endif
typedef
struct
_dictkeysobject
PyDictKeysObject
;
typedef
struct
_dictvalues
PyDictValues
;
/* The ma_values pointer is NULL for a combined table
* or points to an array of PyObject* for a split table
*/
typedef
struct
{
PyObject_HEAD
/* Number of items in the dictionary */
Py_ssize_t
ma_used
;
/* This is a private field for CPython's internal use.
* Bits 0-7 are for dict watchers.
* Bits 8-11 are for the watched mutation counter (used by tier2 optimization)
* Bits 12-31 are currently unused
* Bits 32-63 are a unique id in the free threading build (used for per-thread refcounting)
*/
uint64_t
_ma_watcher_tag
;
PyDictKeysObject
*
ma_keys
;
/* If ma_values is NULL, the table is "combined": keys and values
are stored in ma_keys.
If ma_values is not NULL, the table is split:
keys are stored in ma_keys and values are stored in ma_values */
PyDictValues
*
ma_values
;
}
PyDictObject
;
// frozendict
PyAPI_DATA
(
PyTypeObject
)
PyFrozenDict_Type
;
#define
PyFrozenDict_Check
(
op
) PyObject_TypeCheck((op), &PyFrozenDict_Type)
#define
PyFrozenDict_CheckExact
(
op
) Py_IS_TYPE((op), &PyFrozenDict_Type)
#define
PyAnyDict_CheckExact
(
ob
) \
(PyDict_CheckExact(ob) || PyFrozenDict_CheckExact(ob))
#define
PyAnyDict_Check
(
ob
) \
(PyDict_Check(ob) || PyFrozenDict_Check(ob))
PyAPI_FUNC
(
PyObject
*
)
_PyDict_GetItem_KnownHash
(
PyObject
*
mp
,
PyObject
*
key
,
Py_hash_t
hash
);
// PyDict_GetItemStringRef() can be used instead
Py_DEPRECATED
(
3.14
)
PyAPI_FUNC
(
PyObject
*
)
_PyDict_GetItemStringWithError
(
PyObject
*
,
const
char
*
);
PyAPI_FUNC
(
PyObject
*
)
PyDict_SetDefault
(
PyObject
*
mp
,
PyObject
*
key
,
PyObject
*
defaultobj
);
/* Get the number of items of a dictionary. */
static
inline
Py_ssize_t
PyDict_GET_SIZE
(
PyObject
*
op
) {
PyDictObject
*
mp
;
assert
(
PyAnyDict_Check
(
op
));
mp
=
_Py_CAST
(
PyDictObject
*
,
op
);
#ifdef
Py_GIL_DISABLED
return
_Py_atomic_load_ssize_relaxed
(
&
mp
->
ma_used
);
#else
return
mp
->
ma_used
;
#endif
}
#define
PyDict_GET_SIZE
(
op
) PyDict_GET_SIZE(_PyObject_CAST(op))
PyAPI_FUNC
(
int
)
PyDict_ContainsString
(
PyObject
*
mp
,
const
char
*
key
);
PyAPI_FUNC
(
PyObject
*
)
_PyDict_NewPresized
(
Py_ssize_t
minused
);
PyAPI_FUNC
(
int
)
PyDict_Pop
(
PyObject
*
dict
,
PyObject
*
key
,
PyObject
*
*
result
);
PyAPI_FUNC
(
int
)
PyDict_PopString
(
PyObject
*
dict
,
const
char
*
key
,
PyObject
*
*
result
);
// Use PyDict_Pop() instead
Py_DEPRECATED
(
3.14
)
PyAPI_FUNC
(
PyObject
*
)
_PyDict_Pop
(
PyObject
*
dict
,
PyObject
*
key
,
PyObject
*
default_value
);
/* Dictionary watchers */
#define
PY_FOREACH_DICT_EVENT
(
V
) \
V(ADDED) \
V(MODIFIED) \
V(DELETED) \
V(CLONED) \
V(CLEARED) \
V(DEALLOCATED)
typedef
enum
{
#define
PY_DEF_EVENT(EVENT) PyDict_EVENT_##EVENT,
PY_FOREACH_DICT_EVENT
(
PY_DEF_EVENT
)
#undef
PY_DEF_EVENT
}
PyDict_WatchEvent
;
// Callback to be invoked when a watched dict is cleared, dealloced, or modified.
// In clear/dealloc case, key and new_value will be NULL. Otherwise, new_value will be the
// new value for key, NULL if key is being deleted.
typedef
int
(
*
PyDict_WatchCallback
)(
PyDict_WatchEvent
event
,
PyObject
*
dict
,
PyObject
*
key
,
PyObject
*
new_value
);
// Register/unregister a dict-watcher callback
PyAPI_FUNC
(
int
)
PyDict_AddWatcher
(
PyDict_WatchCallback
callback
);
PyAPI_FUNC
(
int
)
PyDict_ClearWatcher
(
int
watcher_id
);
// Mark given dictionary as "watched" (callback will be called if it is modified)
PyAPI_FUNC
(
int
)
PyDict_Watch
(
int
watcher_id
,
PyObject
*
dict
);
PyAPI_FUNC
(
int
)
PyDict_Unwatch
(
int
watcher_id
,
PyObject
*
dict
);
// Create a frozendict. Create an empty dictionary if iterable is NULL.
PyAPI_FUNC
(
PyObject
*
)
PyFrozenDict_New
(
PyObject
*
iterable
);
You can’t perform that action at this time.