Coverage Report

Created: 2025-11-16 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython3/Include/cpython/dictobject.h
Line
Count
Source
1
#ifndef Py_CPYTHON_DICTOBJECT_H
2
#  error "this header file must not be included directly"
3
#endif
4
5
typedef struct _dictkeysobject PyDictKeysObject;
6
typedef struct _dictvalues PyDictValues;
7
8
/* The ma_values pointer is NULL for a combined table
9
 * or points to an array of PyObject* for a split table
10
 */
11
typedef struct {
12
    PyObject_HEAD
13
14
    /* Number of items in the dictionary */
15
    Py_ssize_t ma_used;
16
17
    /* This is a private field for CPython's internal use.
18
     * Bits 0-7 are for dict watchers.
19
     * Bits 8-11 are for the watched mutation counter (used by tier2 optimization)
20
     * Bits 12-31 are currently unused
21
     * Bits 32-63 are a unique id in the free threading build (used for per-thread refcounting)
22
     */
23
    uint64_t _ma_watcher_tag;
24
25
    PyDictKeysObject *ma_keys;
26
27
    /* If ma_values is NULL, the table is "combined": keys and values
28
       are stored in ma_keys.
29
30
       If ma_values is not NULL, the table is split:
31
       keys are stored in ma_keys and values are stored in ma_values */
32
    PyDictValues *ma_values;
33
} PyDictObject;
34
35
PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key,
36
                                                 Py_hash_t hash);
37
// PyDict_GetItemStringRef() can be used instead
38
Py_DEPRECATED(3.14) PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *);
39
PyAPI_FUNC(PyObject *) PyDict_SetDefault(
40
    PyObject *mp, PyObject *key, PyObject *defaultobj);
41
42
// Inserts `key` with a value `default_value`, if `key` is not already present
43
// in the dictionary.  If `result` is not NULL, then the value associated
44
// with `key` is returned in `*result` (either the existing value, or the now
45
// inserted `default_value`).
46
// Returns:
47
//   -1 on error
48
//    0 if `key` was not present and `default_value` was inserted
49
//    1 if `key` was present and `default_value` was not inserted
50
PyAPI_FUNC(int) PyDict_SetDefaultRef(PyObject *mp, PyObject *key, PyObject *default_value, PyObject **result);
51
52
/* Get the number of items of a dictionary. */
53
1.27M
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
1.27M
    PyDictObject *mp;
55
1.27M
    assert(PyDict_Check(op));
56
1.27M
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
1.27M
    return mp->ma_used;
61
1.27M
#endif
62
1.27M
}
Unexecuted instantiation: exceptions.c:PyDict_GET_SIZE
Unexecuted instantiation: genericaliasobject.c:PyDict_GET_SIZE
listobject.c:PyDict_GET_SIZE
Line
Count
Source
53
231k
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
231k
    PyDictObject *mp;
55
231k
    assert(PyDict_Check(op));
56
231k
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
231k
    return mp->ma_used;
61
231k
#endif
62
231k
}
Unexecuted instantiation: longobject.c:PyDict_GET_SIZE
Unexecuted instantiation: dictobject.c:PyDict_GET_SIZE
Unexecuted instantiation: moduleobject.c:PyDict_GET_SIZE
Unexecuted instantiation: object.c:PyDict_GET_SIZE
Unexecuted instantiation: obmalloc.c:PyDict_GET_SIZE
Unexecuted instantiation: picklebufobject.c:PyDict_GET_SIZE
Unexecuted instantiation: rangeobject.c:PyDict_GET_SIZE
setobject.c:PyDict_GET_SIZE
Line
Count
Source
53
20.7k
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
20.7k
    PyDictObject *mp;
55
20.7k
    assert(PyDict_Check(op));
56
20.7k
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
20.7k
    return mp->ma_used;
61
20.7k
#endif
62
20.7k
}
Unexecuted instantiation: sliceobject.c:PyDict_GET_SIZE
Unexecuted instantiation: structseq.c:PyDict_GET_SIZE
Unexecuted instantiation: templateobject.c:PyDict_GET_SIZE
Unexecuted instantiation: tupleobject.c:PyDict_GET_SIZE
typeobject.c:PyDict_GET_SIZE
Line
Count
Source
53
269
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
269
    PyDictObject *mp;
55
269
    assert(PyDict_Check(op));
56
269
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
269
    return mp->ma_used;
61
269
#endif
62
269
}
Unexecuted instantiation: typevarobject.c:PyDict_GET_SIZE
Unexecuted instantiation: unicode_formatter.c:PyDict_GET_SIZE
Unexecuted instantiation: unicode_writer.c:PyDict_GET_SIZE
Unexecuted instantiation: unicodectype.c:PyDict_GET_SIZE
Unexecuted instantiation: unicodeobject.c:PyDict_GET_SIZE
Unexecuted instantiation: unionobject.c:PyDict_GET_SIZE
Unexecuted instantiation: weakrefobject.c:PyDict_GET_SIZE
Unexecuted instantiation: _warnings.c:PyDict_GET_SIZE
Unexecuted instantiation: bltinmodule.c:PyDict_GET_SIZE
ceval.c:PyDict_GET_SIZE
Line
Count
Source
53
363
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
363
    PyDictObject *mp;
55
363
    assert(PyDict_Check(op));
56
363
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
363
    return mp->ma_used;
61
363
#endif
62
363
}
Unexecuted instantiation: codecs.c:PyDict_GET_SIZE
Unexecuted instantiation: codegen.c:PyDict_GET_SIZE
compile.c:PyDict_GET_SIZE
Line
Count
Source
53
466k
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
466k
    PyDictObject *mp;
55
466k
    assert(PyDict_Check(op));
56
466k
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
466k
    return mp->ma_used;
61
466k
#endif
62
466k
}
Unexecuted instantiation: context.c:PyDict_GET_SIZE
Unexecuted instantiation: errors.c:PyDict_GET_SIZE
flowgraph.c:PyDict_GET_SIZE
Line
Count
Source
53
476k
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
476k
    PyDictObject *mp;
55
476k
    assert(PyDict_Check(op));
56
476k
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
476k
    return mp->ma_used;
61
476k
#endif
62
476k
}
Unexecuted instantiation: frame.c:PyDict_GET_SIZE
Unexecuted instantiation: future.c:PyDict_GET_SIZE
Unexecuted instantiation: gc.c:PyDict_GET_SIZE
Unexecuted instantiation: gc_gil.c:PyDict_GET_SIZE
getargs.c:PyDict_GET_SIZE
Line
Count
Source
53
491
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
491
    PyDictObject *mp;
55
491
    assert(PyDict_Check(op));
56
491
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
491
    return mp->ma_used;
61
491
#endif
62
491
}
Unexecuted instantiation: ceval_gil.c:PyDict_GET_SIZE
Unexecuted instantiation: hamt.c:PyDict_GET_SIZE
Unexecuted instantiation: hashtable.c:PyDict_GET_SIZE
Unexecuted instantiation: import.c:PyDict_GET_SIZE
Unexecuted instantiation: importdl.c:PyDict_GET_SIZE
Unexecuted instantiation: initconfig.c:PyDict_GET_SIZE
Unexecuted instantiation: instrumentation.c:PyDict_GET_SIZE
Unexecuted instantiation: instruction_sequence.c:PyDict_GET_SIZE
Unexecuted instantiation: intrinsics.c:PyDict_GET_SIZE
Unexecuted instantiation: legacy_tracing.c:PyDict_GET_SIZE
Unexecuted instantiation: lock.c:PyDict_GET_SIZE
Unexecuted instantiation: marshal.c:PyDict_GET_SIZE
Unexecuted instantiation: modsupport.c:PyDict_GET_SIZE
Unexecuted instantiation: mysnprintf.c:PyDict_GET_SIZE
Unexecuted instantiation: parking_lot.c:PyDict_GET_SIZE
Unexecuted instantiation: preconfig.c:PyDict_GET_SIZE
Unexecuted instantiation: pyarena.c:PyDict_GET_SIZE
Unexecuted instantiation: pyctype.c:PyDict_GET_SIZE
Unexecuted instantiation: pyhash.c:PyDict_GET_SIZE
Unexecuted instantiation: pylifecycle.c:PyDict_GET_SIZE
Unexecuted instantiation: pystate.c:PyDict_GET_SIZE
Unexecuted instantiation: pythonrun.c:PyDict_GET_SIZE
Unexecuted instantiation: pytime.c:PyDict_GET_SIZE
Unexecuted instantiation: qsbr.c:PyDict_GET_SIZE
Unexecuted instantiation: bootstrap_hash.c:PyDict_GET_SIZE
Unexecuted instantiation: specialize.c:PyDict_GET_SIZE
Unexecuted instantiation: symtable.c:PyDict_GET_SIZE
Unexecuted instantiation: sysmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: thread.c:PyDict_GET_SIZE
Unexecuted instantiation: traceback.c:PyDict_GET_SIZE
Unexecuted instantiation: tracemalloc.c:PyDict_GET_SIZE
Unexecuted instantiation: getopt.c:PyDict_GET_SIZE
Unexecuted instantiation: pystrcmp.c:PyDict_GET_SIZE
Unexecuted instantiation: pystrtod.c:PyDict_GET_SIZE
Unexecuted instantiation: dtoa.c:PyDict_GET_SIZE
Unexecuted instantiation: fileutils.c:PyDict_GET_SIZE
Unexecuted instantiation: suggestions.c:PyDict_GET_SIZE
Unexecuted instantiation: perf_trampoline.c:PyDict_GET_SIZE
Unexecuted instantiation: perf_jit_trampoline.c:PyDict_GET_SIZE
Unexecuted instantiation: remote_debugging.c:PyDict_GET_SIZE
Unexecuted instantiation: dynload_shlib.c:PyDict_GET_SIZE
Unexecuted instantiation: config.c:PyDict_GET_SIZE
Unexecuted instantiation: gcmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: _asynciomodule.c:PyDict_GET_SIZE
Unexecuted instantiation: atexitmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: faulthandler.c:PyDict_GET_SIZE
Unexecuted instantiation: posixmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: signalmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: _tracemalloc.c:PyDict_GET_SIZE
Unexecuted instantiation: _suggestions.c:PyDict_GET_SIZE
Unexecuted instantiation: _datetimemodule.c:PyDict_GET_SIZE
Unexecuted instantiation: _codecsmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: _collectionsmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: _iomodule.c:PyDict_GET_SIZE
Unexecuted instantiation: iobase.c:PyDict_GET_SIZE
Unexecuted instantiation: fileio.c:PyDict_GET_SIZE
Unexecuted instantiation: bytesio.c:PyDict_GET_SIZE
Unexecuted instantiation: bufferedio.c:PyDict_GET_SIZE
Unexecuted instantiation: textio.c:PyDict_GET_SIZE
Unexecuted instantiation: stringio.c:PyDict_GET_SIZE
Unexecuted instantiation: itertoolsmodule.c:PyDict_GET_SIZE
sre.c:PyDict_GET_SIZE
Line
Count
Source
53
2.18k
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
2.18k
    PyDictObject *mp;
55
2.18k
    assert(PyDict_Check(op));
56
2.18k
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
2.18k
    return mp->ma_used;
61
2.18k
#endif
62
2.18k
}
Unexecuted instantiation: _sysconfig.c:PyDict_GET_SIZE
Unexecuted instantiation: _threadmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: timemodule.c:PyDict_GET_SIZE
Unexecuted instantiation: _typesmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: _typingmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: _weakref.c:PyDict_GET_SIZE
Unexecuted instantiation: _abc.c:PyDict_GET_SIZE
_functoolsmodule.c:PyDict_GET_SIZE
Line
Count
Source
53
11
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
11
    PyDictObject *mp;
55
11
    assert(PyDict_Check(op));
56
11
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
11
    return mp->ma_used;
61
11
#endif
62
11
}
Unexecuted instantiation: _localemodule.c:PyDict_GET_SIZE
Unexecuted instantiation: _opcode.c:PyDict_GET_SIZE
Unexecuted instantiation: _operator.c:PyDict_GET_SIZE
Unexecuted instantiation: symtablemodule.c:PyDict_GET_SIZE
Unexecuted instantiation: pwdmodule.c:PyDict_GET_SIZE
Unexecuted instantiation: getpath.c:PyDict_GET_SIZE
Unexecuted instantiation: frozen.c:PyDict_GET_SIZE
Unexecuted instantiation: getbuildinfo.c:PyDict_GET_SIZE
Unexecuted instantiation: peg_api.c:PyDict_GET_SIZE
Unexecuted instantiation: file_tokenizer.c:PyDict_GET_SIZE
Unexecuted instantiation: helpers.c:PyDict_GET_SIZE
Unexecuted instantiation: myreadline.c:PyDict_GET_SIZE
Unexecuted instantiation: abstract.c:PyDict_GET_SIZE
Unexecuted instantiation: boolobject.c:PyDict_GET_SIZE
Unexecuted instantiation: bytes_methods.c:PyDict_GET_SIZE
Unexecuted instantiation: bytearrayobject.c:PyDict_GET_SIZE
Unexecuted instantiation: bytesobject.c:PyDict_GET_SIZE
call.c:PyDict_GET_SIZE
Line
Count
Source
53
6.21k
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
6.21k
    PyDictObject *mp;
55
6.21k
    assert(PyDict_Check(op));
56
6.21k
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
6.21k
    return mp->ma_used;
61
6.21k
#endif
62
6.21k
}
Unexecuted instantiation: capsule.c:PyDict_GET_SIZE
Unexecuted instantiation: cellobject.c:PyDict_GET_SIZE
Unexecuted instantiation: classobject.c:PyDict_GET_SIZE
Unexecuted instantiation: codeobject.c:PyDict_GET_SIZE
Unexecuted instantiation: complexobject.c:PyDict_GET_SIZE
Unexecuted instantiation: descrobject.c:PyDict_GET_SIZE
Unexecuted instantiation: enumobject.c:PyDict_GET_SIZE
Unexecuted instantiation: genobject.c:PyDict_GET_SIZE
Unexecuted instantiation: fileobject.c:PyDict_GET_SIZE
Unexecuted instantiation: floatobject.c:PyDict_GET_SIZE
Unexecuted instantiation: frameobject.c:PyDict_GET_SIZE
Unexecuted instantiation: funcobject.c:PyDict_GET_SIZE
Unexecuted instantiation: interpolationobject.c:PyDict_GET_SIZE
Unexecuted instantiation: iterobject.c:PyDict_GET_SIZE
Unexecuted instantiation: odictobject.c:PyDict_GET_SIZE
Unexecuted instantiation: memoryobject.c:PyDict_GET_SIZE
Unexecuted instantiation: methodobject.c:PyDict_GET_SIZE
Unexecuted instantiation: namespaceobject.c:PyDict_GET_SIZE
Unexecuted instantiation: unicode_format.c:PyDict_GET_SIZE
Unexecuted instantiation: _contextvars.c:PyDict_GET_SIZE
Unexecuted instantiation: Python-ast.c:PyDict_GET_SIZE
Unexecuted instantiation: Python-tokenize.c:PyDict_GET_SIZE
Unexecuted instantiation: asdl.c:PyDict_GET_SIZE
assemble.c:PyDict_GET_SIZE
Line
Count
Source
53
72.5k
static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
54
72.5k
    PyDictObject *mp;
55
72.5k
    assert(PyDict_Check(op));
56
72.5k
    mp = _Py_CAST(PyDictObject*, op);
57
#ifdef Py_GIL_DISABLED
58
    return _Py_atomic_load_ssize_relaxed(&mp->ma_used);
59
#else
60
72.5k
    return mp->ma_used;
61
72.5k
#endif
62
72.5k
}
Unexecuted instantiation: ast.c:PyDict_GET_SIZE
Unexecuted instantiation: ast_preprocess.c:PyDict_GET_SIZE
Unexecuted instantiation: ast_unparse.c:PyDict_GET_SIZE
Unexecuted instantiation: critical_section.c:PyDict_GET_SIZE
Unexecuted instantiation: crossinterp.c:PyDict_GET_SIZE
Unexecuted instantiation: getcopyright.c:PyDict_GET_SIZE
Unexecuted instantiation: getplatform.c:PyDict_GET_SIZE
Unexecuted instantiation: getversion.c:PyDict_GET_SIZE
Unexecuted instantiation: optimizer.c:PyDict_GET_SIZE
Unexecuted instantiation: pathconfig.c:PyDict_GET_SIZE
Unexecuted instantiation: pymath.c:PyDict_GET_SIZE
Unexecuted instantiation: structmember.c:PyDict_GET_SIZE
Unexecuted instantiation: pystrhex.c:PyDict_GET_SIZE
Unexecuted instantiation: pegen.c:PyDict_GET_SIZE
Unexecuted instantiation: pegen_errors.c:PyDict_GET_SIZE
Unexecuted instantiation: parser.c:PyDict_GET_SIZE
Unexecuted instantiation: buffer.c:PyDict_GET_SIZE
Unexecuted instantiation: lexer.c:PyDict_GET_SIZE
Unexecuted instantiation: state.c:PyDict_GET_SIZE
Unexecuted instantiation: readline_tokenizer.c:PyDict_GET_SIZE
Unexecuted instantiation: string_tokenizer.c:PyDict_GET_SIZE
Unexecuted instantiation: utf8_tokenizer.c:PyDict_GET_SIZE
Unexecuted instantiation: getcompiler.c:PyDict_GET_SIZE
Unexecuted instantiation: mystrtoul.c:PyDict_GET_SIZE
Unexecuted instantiation: token.c:PyDict_GET_SIZE
Unexecuted instantiation: action_helpers.c:PyDict_GET_SIZE
Unexecuted instantiation: string_parser.c:PyDict_GET_SIZE
63
1.23M
#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
64
65
PyAPI_FUNC(int) PyDict_ContainsString(PyObject *mp, const char *key);
66
67
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
68
69
PyAPI_FUNC(int) PyDict_Pop(PyObject *dict, PyObject *key, PyObject **result);
70
PyAPI_FUNC(int) PyDict_PopString(PyObject *dict, const char *key, PyObject **result);
71
72
// Use PyDict_Pop() instead
73
Py_DEPRECATED(3.14) PyAPI_FUNC(PyObject *) _PyDict_Pop(
74
    PyObject *dict,
75
    PyObject *key,
76
    PyObject *default_value);
77
78
/* Dictionary watchers */
79
80
#define PY_FOREACH_DICT_EVENT(V) \
81
0
    V(ADDED)                     \
82
0
    V(MODIFIED)                  \
83
0
    V(DELETED)                   \
84
0
    V(CLONED)                    \
85
0
    V(CLEARED)                   \
86
0
    V(DEALLOCATED)
87
88
typedef enum {
89
    #define PY_DEF_EVENT(EVENT) PyDict_EVENT_##EVENT,
90
    PY_FOREACH_DICT_EVENT(PY_DEF_EVENT)
91
    #undef PY_DEF_EVENT
92
} PyDict_WatchEvent;
93
94
// Callback to be invoked when a watched dict is cleared, dealloced, or modified.
95
// In clear/dealloc case, key and new_value will be NULL. Otherwise, new_value will be the
96
// new value for key, NULL if key is being deleted.
97
typedef int(*PyDict_WatchCallback)(PyDict_WatchEvent event, PyObject* dict, PyObject* key, PyObject* new_value);
98
99
// Register/unregister a dict-watcher callback
100
PyAPI_FUNC(int) PyDict_AddWatcher(PyDict_WatchCallback callback);
101
PyAPI_FUNC(int) PyDict_ClearWatcher(int watcher_id);
102
103
// Mark given dictionary as "watched" (callback will be called if it is modified)
104
PyAPI_FUNC(int) PyDict_Watch(int watcher_id, PyObject* dict);
105
PyAPI_FUNC(int) PyDict_Unwatch(int watcher_id, PyObject* dict);