Coverage Report

Created: 2025-07-11 06:59

/src/Python-3.8.3/Include/objimpl.h
Line
Count
Source (jump to first uncovered line)
1
/* The PyObject_ memory family:  high-level object memory interfaces.
2
   See pymem.h for the low-level PyMem_ family.
3
*/
4
5
#ifndef Py_OBJIMPL_H
6
#define Py_OBJIMPL_H
7
8
#include "pymem.h"
9
10
#ifdef __cplusplus
11
extern "C" {
12
#endif
13
14
/* BEWARE:
15
16
   Each interface exports both functions and macros.  Extension modules should
17
   use the functions, to ensure binary compatibility across Python versions.
18
   Because the Python implementation is free to change internal details, and
19
   the macros may (or may not) expose details for speed, if you do use the
20
   macros you must recompile your extensions with each Python release.
21
22
   Never mix calls to PyObject_ memory functions with calls to the platform
23
   malloc/realloc/ calloc/free, or with calls to PyMem_.
24
*/
25
26
/*
27
Functions and macros for modules that implement new object types.
28
29
 - PyObject_New(type, typeobj) allocates memory for a new object of the given
30
   type, and initializes part of it.  'type' must be the C structure type used
31
   to represent the object, and 'typeobj' the address of the corresponding
32
   type object.  Reference count and type pointer are filled in; the rest of
33
   the bytes of the object are *undefined*!  The resulting expression type is
34
   'type *'.  The size of the object is determined by the tp_basicsize field
35
   of the type object.
36
37
 - PyObject_NewVar(type, typeobj, n) is similar but allocates a variable-size
38
   object with room for n items.  In addition to the refcount and type pointer
39
   fields, this also fills in the ob_size field.
40
41
 - PyObject_Del(op) releases the memory allocated for an object.  It does not
42
   run a destructor -- it only frees the memory.  PyObject_Free is identical.
43
44
 - PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) don't
45
   allocate memory.  Instead of a 'type' parameter, they take a pointer to a
46
   new object (allocated by an arbitrary allocator), and initialize its object
47
   header fields.
48
49
Note that objects created with PyObject_{New, NewVar} are allocated using the
50
specialized Python allocator (implemented in obmalloc.c), if WITH_PYMALLOC is
51
enabled.  In addition, a special debugging allocator is used if PYMALLOC_DEBUG
52
is also #defined.
53
54
In case a specific form of memory management is needed (for example, if you
55
must use the platform malloc heap(s), or shared memory, or C++ local storage or
56
operator new), you must first allocate the object with your custom allocator,
57
then pass its pointer to PyObject_{Init, InitVar} for filling in its Python-
58
specific fields:  reference count, type pointer, possibly others.  You should
59
be aware that Python has no control over these objects because they don't
60
cooperate with the Python memory manager.  Such objects may not be eligible
61
for automatic garbage collection and you have to make sure that they are
62
released accordingly whenever their destructor gets called (cf. the specific
63
form of memory management you're using).
64
65
Unless you have specific memory management requirements, use
66
PyObject_{New, NewVar, Del}.
67
*/
68
69
/*
70
 * Raw object memory interface
71
 * ===========================
72
 */
73
74
/* Functions to call the same malloc/realloc/free as used by Python's
75
   object allocator.  If WITH_PYMALLOC is enabled, these may differ from
76
   the platform malloc/realloc/free.  The Python object allocator is
77
   designed for fast, cache-conscious allocation of many "small" objects,
78
   and with low hidden memory overhead.
79
80
   PyObject_Malloc(0) returns a unique non-NULL pointer if possible.
81
82
   PyObject_Realloc(NULL, n) acts like PyObject_Malloc(n).
83
   PyObject_Realloc(p != NULL, 0) does not return  NULL, or free the memory
84
   at p.
85
86
   Returned pointers must be checked for NULL explicitly; no action is
87
   performed on failure other than to return NULL (no warning it printed, no
88
   exception is set, etc).
89
90
   For allocating objects, use PyObject_{New, NewVar} instead whenever
91
   possible.  The PyObject_{Malloc, Realloc, Free} family is exposed
92
   so that you can exploit Python's small-block allocator for non-object
93
   uses.  If you must use these routines to allocate object memory, make sure
94
   the object gets initialized via PyObject_{Init, InitVar} after obtaining
95
   the raw memory.
96
*/
97
PyAPI_FUNC(void *) PyObject_Malloc(size_t size);
98
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
99
PyAPI_FUNC(void *) PyObject_Calloc(size_t nelem, size_t elsize);
100
#endif
101
PyAPI_FUNC(void *) PyObject_Realloc(void *ptr, size_t new_size);
102
PyAPI_FUNC(void) PyObject_Free(void *ptr);
103
104
105
/* Macros */
106
337k
#define PyObject_MALLOC         PyObject_Malloc
107
14.2k
#define PyObject_REALLOC        PyObject_Realloc
108
53.2k
#define PyObject_FREE           PyObject_Free
109
3.59k
#define PyObject_Del            PyObject_Free
110
2.19k
#define PyObject_DEL            PyObject_Free
111
112
113
/*
114
 * Generic object allocator interface
115
 * ==================================
116
 */
117
118
/* Functions */
119
PyAPI_FUNC(PyObject *) PyObject_Init(PyObject *, PyTypeObject *);
120
PyAPI_FUNC(PyVarObject *) PyObject_InitVar(PyVarObject *,
121
                                                 PyTypeObject *, Py_ssize_t);
122
PyAPI_FUNC(PyObject *) _PyObject_New(PyTypeObject *);
123
PyAPI_FUNC(PyVarObject *) _PyObject_NewVar(PyTypeObject *, Py_ssize_t);
124
125
#define PyObject_New(type, typeobj) \
126
1.11k
                ( (type *) _PyObject_New(typeobj) )
127
#define PyObject_NewVar(type, typeobj, n) \
128
                ( (type *) _PyObject_NewVar((typeobj), (n)) )
129
130
/* Inline functions trading binary compatibility for speed:
131
   PyObject_INIT() is the fast version of PyObject_Init(), and
132
   PyObject_INIT_VAR() is the fast version of PyObject_InitVar.
133
   See also pymem.h.
134
135
   These inline functions expect non-NULL object pointers. */
136
static inline PyObject*
137
_PyObject_INIT(PyObject *op, PyTypeObject *typeobj)
138
625k
{
139
625k
    assert(op != NULL);
140
625k
    Py_TYPE(op) = typeobj;
141
625k
    if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
142
4.36k
        Py_INCREF(typeobj);
143
4.36k
    }
144
625k
    _Py_NewReference(op);
145
625k
    return op;
146
625k
}
Unexecuted instantiation: abstract.c:_PyObject_INIT
Unexecuted instantiation: boolobject.c:_PyObject_INIT
Unexecuted instantiation: bytearrayobject.c:_PyObject_INIT
bytesobject.c:_PyObject_INIT
Line
Count
Source
138
171k
{
139
171k
    assert(op != NULL);
140
171k
    Py_TYPE(op) = typeobj;
141
171k
    if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
142
0
        Py_INCREF(typeobj);
143
0
    }
144
171k
    _Py_NewReference(op);
145
171k
    return op;
146
171k
}
Unexecuted instantiation: call.c:_PyObject_INIT
Unexecuted instantiation: capsule.c:_PyObject_INIT
Unexecuted instantiation: exceptions.c:_PyObject_INIT
floatobject.c:_PyObject_INIT
Line
Count
Source
138
2.69k
{
139
2.69k
    assert(op != NULL);
140
2.69k
    Py_TYPE(op) = typeobj;
141
2.69k
    if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
142
0
        Py_INCREF(typeobj);
143
0
    }
144
2.69k
    _Py_NewReference(op);
145
2.69k
    return op;
146
2.69k
}
Unexecuted instantiation: frameobject.c:_PyObject_INIT
Unexecuted instantiation: funcobject.c:_PyObject_INIT
Unexecuted instantiation: iterobject.c:_PyObject_INIT
Unexecuted instantiation: listobject.c:_PyObject_INIT
longobject.c:_PyObject_INIT
Line
Count
Source
138
32.1k
{
139
32.1k
    assert(op != NULL);
140
32.1k
    Py_TYPE(op) = typeobj;
141
32.1k
    if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
142
0
        Py_INCREF(typeobj);
143
0
    }
144
32.1k
    _Py_NewReference(op);
145
32.1k
    return op;
146
32.1k
}
Unexecuted instantiation: dictobject.c:_PyObject_INIT
Unexecuted instantiation: memoryobject.c:_PyObject_INIT
methodobject.c:_PyObject_INIT
Line
Count
Source
138
8.84k
{
139
8.84k
    assert(op != NULL);
140
8.84k
    Py_TYPE(op) = typeobj;
141
8.84k
    if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
142
0
        Py_INCREF(typeobj);
143
0
    }
144
8.84k
    _Py_NewReference(op);
145
8.84k
    return op;
146
8.84k
}
Unexecuted instantiation: moduleobject.c:_PyObject_INIT
object.c:_PyObject_INIT
Line
Count
Source
138
127k
{
139
127k
    assert(op != NULL);
140
127k
    Py_TYPE(op) = typeobj;
141
127k
    if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
142
0
        Py_INCREF(typeobj);
143
0
    }
144
127k
    _Py_NewReference(op);
145
127k
    return op;
146
127k
}
Unexecuted instantiation: obmalloc.c:_PyObject_INIT
Unexecuted instantiation: picklebufobject.c:_PyObject_INIT
Unexecuted instantiation: rangeobject.c:_PyObject_INIT
Unexecuted instantiation: setobject.c:_PyObject_INIT
Unexecuted instantiation: sliceobject.c:_PyObject_INIT
Unexecuted instantiation: structseq.c:_PyObject_INIT
Unexecuted instantiation: tupleobject.c:_PyObject_INIT
typeobject.c:_PyObject_INIT
Line
Count
Source
138
43.7k
{
139
43.7k
    assert(op != NULL);
140
43.7k
    Py_TYPE(op) = typeobj;
141
43.7k
    if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
142
3.51k
        Py_INCREF(typeobj);
143
3.51k
    }
144
43.7k
    _Py_NewReference(op);
145
43.7k
    return op;
146
43.7k
}
unicodeobject.c:_PyObject_INIT
Line
Count
Source
138
144k
{
139
144k
    assert(op != NULL);
140
144k
    Py_TYPE(op) = typeobj;
141
144k
    if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
142
0
        Py_INCREF(typeobj);
143
0
    }
144
144k
    _Py_NewReference(op);
145
144k
    return op;
146
144k
}
Unexecuted instantiation: unicodectype.c:_PyObject_INIT
Unexecuted instantiation: weakrefobject.c:_PyObject_INIT
Unexecuted instantiation: _warnings.c:_PyObject_INIT
Unexecuted instantiation: ceval.c:_PyObject_INIT
Unexecuted instantiation: codecs.c:_PyObject_INIT
Unexecuted instantiation: compile.c:_PyObject_INIT
Unexecuted instantiation: errors.c:_PyObject_INIT
Unexecuted instantiation: future.c:_PyObject_INIT
Unexecuted instantiation: getargs.c:_PyObject_INIT
Unexecuted instantiation: getversion.c:_PyObject_INIT
Unexecuted instantiation: import.c:_PyObject_INIT
Unexecuted instantiation: importdl.c:_PyObject_INIT
Unexecuted instantiation: initconfig.c:_PyObject_INIT
Unexecuted instantiation: marshal.c:_PyObject_INIT
Unexecuted instantiation: modsupport.c:_PyObject_INIT
Unexecuted instantiation: mysnprintf.c:_PyObject_INIT
Unexecuted instantiation: pathconfig.c:_PyObject_INIT
Unexecuted instantiation: peephole.c:_PyObject_INIT
Unexecuted instantiation: preconfig.c:_PyObject_INIT
Unexecuted instantiation: pyarena.c:_PyObject_INIT
Unexecuted instantiation: pyctype.c:_PyObject_INIT
Unexecuted instantiation: pyhash.c:_PyObject_INIT
Unexecuted instantiation: pylifecycle.c:_PyObject_INIT
Unexecuted instantiation: pymath.c:_PyObject_INIT
Unexecuted instantiation: pystate.c:_PyObject_INIT
Unexecuted instantiation: pythonrun.c:_PyObject_INIT
Unexecuted instantiation: pytime.c:_PyObject_INIT
Unexecuted instantiation: bootstrap_hash.c:_PyObject_INIT
Unexecuted instantiation: symtable.c:_PyObject_INIT
Unexecuted instantiation: sysmodule.c:_PyObject_INIT
Unexecuted instantiation: thread.c:_PyObject_INIT
Unexecuted instantiation: traceback.c:_PyObject_INIT
Unexecuted instantiation: getopt.c:_PyObject_INIT
Unexecuted instantiation: pystrcmp.c:_PyObject_INIT
Unexecuted instantiation: pystrtod.c:_PyObject_INIT
Unexecuted instantiation: pystrhex.c:_PyObject_INIT
Unexecuted instantiation: dtoa.c:_PyObject_INIT
Unexecuted instantiation: formatter_unicode.c:_PyObject_INIT
Unexecuted instantiation: fileutils.c:_PyObject_INIT
Unexecuted instantiation: dynload_shlib.c:_PyObject_INIT
Unexecuted instantiation: config.c:_PyObject_INIT
Unexecuted instantiation: getpath.c:_PyObject_INIT
gcmodule.c:_PyObject_INIT
Line
Count
Source
138
88.3k
{
139
88.3k
    assert(op != NULL);
140
88.3k
    Py_TYPE(op) = typeobj;
141
88.3k
    if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
142
854
        Py_INCREF(typeobj);
143
854
    }
144
88.3k
    _Py_NewReference(op);
145
88.3k
    return op;
146
88.3k
}
Unexecuted instantiation: posixmodule.c:_PyObject_INIT
Unexecuted instantiation: errnomodule.c:_PyObject_INIT
Unexecuted instantiation: pwdmodule.c:_PyObject_INIT
Unexecuted instantiation: _sre.c:_PyObject_INIT
Unexecuted instantiation: _codecsmodule.c:_PyObject_INIT
Unexecuted instantiation: _weakref.c:_PyObject_INIT
Unexecuted instantiation: _functoolsmodule.c:_PyObject_INIT
Unexecuted instantiation: _operator.c:_PyObject_INIT
Unexecuted instantiation: _collectionsmodule.c:_PyObject_INIT
Unexecuted instantiation: _abc.c:_PyObject_INIT
Unexecuted instantiation: itertoolsmodule.c:_PyObject_INIT
Unexecuted instantiation: atexitmodule.c:_PyObject_INIT
Unexecuted instantiation: signalmodule.c:_PyObject_INIT
Unexecuted instantiation: _stat.c:_PyObject_INIT
Unexecuted instantiation: timemodule.c:_PyObject_INIT
Unexecuted instantiation: _threadmodule.c:_PyObject_INIT
Unexecuted instantiation: _localemodule.c:_PyObject_INIT
Unexecuted instantiation: _iomodule.c:_PyObject_INIT
Unexecuted instantiation: iobase.c:_PyObject_INIT
Unexecuted instantiation: fileio.c:_PyObject_INIT
Unexecuted instantiation: bytesio.c:_PyObject_INIT
Unexecuted instantiation: bufferedio.c:_PyObject_INIT
Unexecuted instantiation: textio.c:_PyObject_INIT
Unexecuted instantiation: stringio.c:_PyObject_INIT
Unexecuted instantiation: faulthandler.c:_PyObject_INIT
Unexecuted instantiation: _tracemalloc.c:_PyObject_INIT
Unexecuted instantiation: hashtable.c:_PyObject_INIT
Unexecuted instantiation: symtablemodule.c:_PyObject_INIT
Unexecuted instantiation: xxsubtype.c:_PyObject_INIT
Unexecuted instantiation: frozen.c:_PyObject_INIT
Unexecuted instantiation: getbuildinfo.c:_PyObject_INIT
Unexecuted instantiation: acceler.c:_PyObject_INIT
Unexecuted instantiation: grammar1.c:_PyObject_INIT
Unexecuted instantiation: node.c:_PyObject_INIT
Unexecuted instantiation: token.c:_PyObject_INIT
Unexecuted instantiation: parsetok.c:_PyObject_INIT
Unexecuted instantiation: tokenizer.c:_PyObject_INIT
Unexecuted instantiation: accu.c:_PyObject_INIT
Unexecuted instantiation: bytes_methods.c:_PyObject_INIT
Unexecuted instantiation: cellobject.c:_PyObject_INIT
classobject.c:_PyObject_INIT
Line
Count
Source
138
7.91k
{
139
7.91k
    assert(op != NULL);
140
7.91k
    Py_TYPE(op) = typeobj;
141
7.91k
    if (PyType_GetFlags(typeobj) & Py_TPFLAGS_HEAPTYPE) {
142
0
        Py_INCREF(typeobj);
143
0
    }
144
7.91k
    _Py_NewReference(op);
145
7.91k
    return op;
146
7.91k
}
Unexecuted instantiation: codeobject.c:_PyObject_INIT
Unexecuted instantiation: complexobject.c:_PyObject_INIT
Unexecuted instantiation: descrobject.c:_PyObject_INIT
Unexecuted instantiation: enumobject.c:_PyObject_INIT
Unexecuted instantiation: genobject.c:_PyObject_INIT
Unexecuted instantiation: fileobject.c:_PyObject_INIT
Unexecuted instantiation: interpreteridobject.c:_PyObject_INIT
Unexecuted instantiation: odictobject.c:_PyObject_INIT
Unexecuted instantiation: namespaceobject.c:_PyObject_INIT
Unexecuted instantiation: Python-ast.c:_PyObject_INIT
Unexecuted instantiation: asdl.c:_PyObject_INIT
Unexecuted instantiation: ast.c:_PyObject_INIT
Unexecuted instantiation: ast_opt.c:_PyObject_INIT
Unexecuted instantiation: ast_unparse.c:_PyObject_INIT
Unexecuted instantiation: bltinmodule.c:_PyObject_INIT
Unexecuted instantiation: context.c:_PyObject_INIT
Unexecuted instantiation: getcompiler.c:_PyObject_INIT
Unexecuted instantiation: getcopyright.c:_PyObject_INIT
Unexecuted instantiation: getplatform.c:_PyObject_INIT
Unexecuted instantiation: hamt.c:_PyObject_INIT
Unexecuted instantiation: mystrtoul.c:_PyObject_INIT
Unexecuted instantiation: structmember.c:_PyObject_INIT
Unexecuted instantiation: parser.c:_PyObject_INIT
Unexecuted instantiation: myreadline.c:_PyObject_INIT
147
148
#define PyObject_INIT(op, typeobj) \
149
625k
    _PyObject_INIT(_PyObject_CAST(op), (typeobj))
150
151
static inline PyVarObject*
152
_PyObject_INIT_VAR(PyVarObject *op, PyTypeObject *typeobj, Py_ssize_t size)
153
239k
{
154
239k
    assert(op != NULL);
155
239k
    Py_SIZE(op) = size;
156
239k
    PyObject_INIT((PyObject *)op, typeobj);
157
239k
    return op;
158
239k
}
Unexecuted instantiation: abstract.c:_PyObject_INIT_VAR
Unexecuted instantiation: boolobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: bytearrayobject.c:_PyObject_INIT_VAR
bytesobject.c:_PyObject_INIT_VAR
Line
Count
Source
153
171k
{
154
171k
    assert(op != NULL);
155
171k
    Py_SIZE(op) = size;
156
171k
    PyObject_INIT((PyObject *)op, typeobj);
157
171k
    return op;
158
171k
}
Unexecuted instantiation: call.c:_PyObject_INIT_VAR
Unexecuted instantiation: capsule.c:_PyObject_INIT_VAR
Unexecuted instantiation: exceptions.c:_PyObject_INIT_VAR
Unexecuted instantiation: floatobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: frameobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: funcobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: iterobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: listobject.c:_PyObject_INIT_VAR
longobject.c:_PyObject_INIT_VAR
Line
Count
Source
153
28.4k
{
154
28.4k
    assert(op != NULL);
155
28.4k
    Py_SIZE(op) = size;
156
28.4k
    PyObject_INIT((PyObject *)op, typeobj);
157
28.4k
    return op;
158
28.4k
}
Unexecuted instantiation: dictobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: memoryobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: methodobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: moduleobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: object.c:_PyObject_INIT_VAR
Unexecuted instantiation: obmalloc.c:_PyObject_INIT_VAR
Unexecuted instantiation: picklebufobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: rangeobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: setobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: sliceobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: structseq.c:_PyObject_INIT_VAR
Unexecuted instantiation: tupleobject.c:_PyObject_INIT_VAR
typeobject.c:_PyObject_INIT_VAR
Line
Count
Source
153
1.57k
{
154
1.57k
    assert(op != NULL);
155
1.57k
    Py_SIZE(op) = size;
156
1.57k
    PyObject_INIT((PyObject *)op, typeobj);
157
1.57k
    return op;
158
1.57k
}
Unexecuted instantiation: unicodeobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: unicodectype.c:_PyObject_INIT_VAR
Unexecuted instantiation: weakrefobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: _warnings.c:_PyObject_INIT_VAR
Unexecuted instantiation: ceval.c:_PyObject_INIT_VAR
Unexecuted instantiation: codecs.c:_PyObject_INIT_VAR
Unexecuted instantiation: compile.c:_PyObject_INIT_VAR
Unexecuted instantiation: errors.c:_PyObject_INIT_VAR
Unexecuted instantiation: future.c:_PyObject_INIT_VAR
Unexecuted instantiation: getargs.c:_PyObject_INIT_VAR
Unexecuted instantiation: getversion.c:_PyObject_INIT_VAR
Unexecuted instantiation: import.c:_PyObject_INIT_VAR
Unexecuted instantiation: importdl.c:_PyObject_INIT_VAR
Unexecuted instantiation: initconfig.c:_PyObject_INIT_VAR
Unexecuted instantiation: marshal.c:_PyObject_INIT_VAR
Unexecuted instantiation: modsupport.c:_PyObject_INIT_VAR
Unexecuted instantiation: mysnprintf.c:_PyObject_INIT_VAR
Unexecuted instantiation: pathconfig.c:_PyObject_INIT_VAR
Unexecuted instantiation: peephole.c:_PyObject_INIT_VAR
Unexecuted instantiation: preconfig.c:_PyObject_INIT_VAR
Unexecuted instantiation: pyarena.c:_PyObject_INIT_VAR
Unexecuted instantiation: pyctype.c:_PyObject_INIT_VAR
Unexecuted instantiation: pyhash.c:_PyObject_INIT_VAR
Unexecuted instantiation: pylifecycle.c:_PyObject_INIT_VAR
Unexecuted instantiation: pymath.c:_PyObject_INIT_VAR
Unexecuted instantiation: pystate.c:_PyObject_INIT_VAR
Unexecuted instantiation: pythonrun.c:_PyObject_INIT_VAR
Unexecuted instantiation: pytime.c:_PyObject_INIT_VAR
Unexecuted instantiation: bootstrap_hash.c:_PyObject_INIT_VAR
Unexecuted instantiation: symtable.c:_PyObject_INIT_VAR
Unexecuted instantiation: sysmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: thread.c:_PyObject_INIT_VAR
Unexecuted instantiation: traceback.c:_PyObject_INIT_VAR
Unexecuted instantiation: getopt.c:_PyObject_INIT_VAR
Unexecuted instantiation: pystrcmp.c:_PyObject_INIT_VAR
Unexecuted instantiation: pystrtod.c:_PyObject_INIT_VAR
Unexecuted instantiation: pystrhex.c:_PyObject_INIT_VAR
Unexecuted instantiation: dtoa.c:_PyObject_INIT_VAR
Unexecuted instantiation: formatter_unicode.c:_PyObject_INIT_VAR
Unexecuted instantiation: fileutils.c:_PyObject_INIT_VAR
Unexecuted instantiation: dynload_shlib.c:_PyObject_INIT_VAR
Unexecuted instantiation: config.c:_PyObject_INIT_VAR
Unexecuted instantiation: getpath.c:_PyObject_INIT_VAR
gcmodule.c:_PyObject_INIT_VAR
Line
Count
Source
153
38.4k
{
154
38.4k
    assert(op != NULL);
155
38.4k
    Py_SIZE(op) = size;
156
38.4k
    PyObject_INIT((PyObject *)op, typeobj);
157
38.4k
    return op;
158
38.4k
}
Unexecuted instantiation: posixmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: errnomodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: pwdmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: _sre.c:_PyObject_INIT_VAR
Unexecuted instantiation: _codecsmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: _weakref.c:_PyObject_INIT_VAR
Unexecuted instantiation: _functoolsmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: _operator.c:_PyObject_INIT_VAR
Unexecuted instantiation: _collectionsmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: _abc.c:_PyObject_INIT_VAR
Unexecuted instantiation: itertoolsmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: atexitmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: signalmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: _stat.c:_PyObject_INIT_VAR
Unexecuted instantiation: timemodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: _threadmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: _localemodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: _iomodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: iobase.c:_PyObject_INIT_VAR
Unexecuted instantiation: fileio.c:_PyObject_INIT_VAR
Unexecuted instantiation: bytesio.c:_PyObject_INIT_VAR
Unexecuted instantiation: bufferedio.c:_PyObject_INIT_VAR
Unexecuted instantiation: textio.c:_PyObject_INIT_VAR
Unexecuted instantiation: stringio.c:_PyObject_INIT_VAR
Unexecuted instantiation: faulthandler.c:_PyObject_INIT_VAR
Unexecuted instantiation: _tracemalloc.c:_PyObject_INIT_VAR
Unexecuted instantiation: hashtable.c:_PyObject_INIT_VAR
Unexecuted instantiation: symtablemodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: xxsubtype.c:_PyObject_INIT_VAR
Unexecuted instantiation: frozen.c:_PyObject_INIT_VAR
Unexecuted instantiation: getbuildinfo.c:_PyObject_INIT_VAR
Unexecuted instantiation: acceler.c:_PyObject_INIT_VAR
Unexecuted instantiation: grammar1.c:_PyObject_INIT_VAR
Unexecuted instantiation: node.c:_PyObject_INIT_VAR
Unexecuted instantiation: token.c:_PyObject_INIT_VAR
Unexecuted instantiation: parsetok.c:_PyObject_INIT_VAR
Unexecuted instantiation: tokenizer.c:_PyObject_INIT_VAR
Unexecuted instantiation: accu.c:_PyObject_INIT_VAR
Unexecuted instantiation: bytes_methods.c:_PyObject_INIT_VAR
Unexecuted instantiation: cellobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: classobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: codeobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: complexobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: descrobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: enumobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: genobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: fileobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: interpreteridobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: odictobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: namespaceobject.c:_PyObject_INIT_VAR
Unexecuted instantiation: Python-ast.c:_PyObject_INIT_VAR
Unexecuted instantiation: asdl.c:_PyObject_INIT_VAR
Unexecuted instantiation: ast.c:_PyObject_INIT_VAR
Unexecuted instantiation: ast_opt.c:_PyObject_INIT_VAR
Unexecuted instantiation: ast_unparse.c:_PyObject_INIT_VAR
Unexecuted instantiation: bltinmodule.c:_PyObject_INIT_VAR
Unexecuted instantiation: context.c:_PyObject_INIT_VAR
Unexecuted instantiation: getcompiler.c:_PyObject_INIT_VAR
Unexecuted instantiation: getcopyright.c:_PyObject_INIT_VAR
Unexecuted instantiation: getplatform.c:_PyObject_INIT_VAR
Unexecuted instantiation: hamt.c:_PyObject_INIT_VAR
Unexecuted instantiation: mystrtoul.c:_PyObject_INIT_VAR
Unexecuted instantiation: structmember.c:_PyObject_INIT_VAR
Unexecuted instantiation: parser.c:_PyObject_INIT_VAR
Unexecuted instantiation: myreadline.c:_PyObject_INIT_VAR
159
160
#define PyObject_INIT_VAR(op, typeobj, size) \
161
239k
    _PyObject_INIT_VAR(_PyVarObject_CAST(op), (typeobj), (size))
162
163
188k
#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
164
165
/* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for a
166
   vrbl-size object with nitems items, exclusive of gc overhead (if any).  The
167
   value is rounded up to the closest multiple of sizeof(void *), in order to
168
   ensure that pointer fields at the end of the object are correctly aligned
169
   for the platform (this is of special importance for subclasses of, e.g.,
170
   str or int, so that pointers can be stored after the embedded data).
171
172
   Note that there's no memory wastage in doing this, as malloc has to
173
   return (at worst) pointer-aligned memory anyway.
174
*/
175
#if ((SIZEOF_VOID_P - 1) & SIZEOF_VOID_P) != 0
176
#   error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2"
177
#endif
178
179
#define _PyObject_VAR_SIZE(typeobj, nitems)     \
180
83.5k
    _Py_SIZE_ROUND_UP((typeobj)->tp_basicsize + \
181
83.5k
        (nitems)*(typeobj)->tp_itemsize,        \
182
83.5k
        SIZEOF_VOID_P)
183
184
11.0k
#define PyObject_NEW(type, typeobj) \
185
11.0k
( (type *) PyObject_Init( \
186
11.0k
    (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) )
187
188
12
#define PyObject_NEW_VAR(type, typeobj, n) \
189
12
( (type *) PyObject_InitVar( \
190
12
      (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\
191
12
      (typeobj), (n)) )
192
193
/* This example code implements an object constructor with a custom
194
   allocator, where PyObject_New is inlined, and shows the important
195
   distinction between two steps (at least):
196
       1) the actual allocation of the object storage;
197
       2) the initialization of the Python specific fields
198
      in this storage with PyObject_{Init, InitVar}.
199
200
   PyObject *
201
   YourObject_New(...)
202
   {
203
       PyObject *op;
204
205
       op = (PyObject *) Your_Allocator(_PyObject_SIZE(YourTypeStruct));
206
       if (op == NULL)
207
       return PyErr_NoMemory();
208
209
       PyObject_Init(op, &YourTypeStruct);
210
211
       op->ob_field = value;
212
       ...
213
       return op;
214
   }
215
216
   Note that in C++, the use of the new operator usually implies that
217
   the 1st step is performed automatically for you, so in a C++ class
218
   constructor you would start directly with PyObject_Init/InitVar
219
*/
220
221
222
223
/*
224
 * Garbage Collection Support
225
 * ==========================
226
 */
227
228
/* C equivalent of gc.collect() which ignores the state of gc.enabled. */
229
PyAPI_FUNC(Py_ssize_t) PyGC_Collect(void);
230
231
/* Test if a type has a GC head */
232
1.44M
#define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC)
233
234
PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t);
235
#define PyObject_GC_Resize(type, op, n) \
236
158
                ( (type *) _PyObject_GC_Resize(_PyVarObject_CAST(op), (n)) )
237
238
239
240
PyAPI_FUNC(PyObject *) _PyObject_GC_New(PyTypeObject *);
241
PyAPI_FUNC(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, Py_ssize_t);
242
243
/* Tell the GC to track this object.
244
 *
245
 * See also private _PyObject_GC_TRACK() macro. */
246
PyAPI_FUNC(void) PyObject_GC_Track(void *);
247
248
/* Tell the GC to stop tracking this object.
249
 *
250
 * See also private _PyObject_GC_UNTRACK() macro. */
251
PyAPI_FUNC(void) PyObject_GC_UnTrack(void *);
252
253
PyAPI_FUNC(void) PyObject_GC_Del(void *);
254
255
#define PyObject_GC_New(type, typeobj) \
256
49.8k
                ( (type *) _PyObject_GC_New(typeobj) )
257
#define PyObject_GC_NewVar(type, typeobj, n) \
258
38.4k
                ( (type *) _PyObject_GC_NewVar((typeobj), (n)) )
259
260
261
/* Utility macro to help write tp_traverse functions.
262
 * To use this macro, the tp_traverse function must name its arguments
263
 * "visit" and "arg".  This is intended to keep tp_traverse functions
264
 * looking as much alike as possible.
265
 */
266
#define Py_VISIT(op)                                                    \
267
754k
    do {                                                                \
268
754k
        if (op) {                                                       \
269
661k
            int vret = visit(_PyObject_CAST(op), arg);                  \
270
661k
            if (vret)                                                   \
271
661k
                return vret;                                            \
272
661k
        }                                                               \
273
754k
    } while (0)
274
275
#ifndef Py_LIMITED_API
276
#  define Py_CPYTHON_OBJIMPL_H
277
#  include  "cpython/objimpl.h"
278
#  undef Py_CPYTHON_OBJIMPL_H
279
#endif
280
281
#ifdef __cplusplus
282
}
283
#endif
284
#endif /* !Py_OBJIMPL_H */