FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Python/object_stack.c at 3.13 · python/cpython · GitHub
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.3k
Star
74.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
Expand file tree
Breadcrumbs
cpython
/
Python
/
object_stack.c
Copy path
More file actions
More file actions
Latest commit
History
History
History
108 lines (97 loc) · 2.92 KB
Breadcrumbs
cpython
/
Python
/
object_stack.c
Copy path
File metadata and controls
108 lines (97 loc) · 2.92 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
// Stack of Python objects
#include
"Python.h"
#include
"pycore_freelist.h"
#include
"pycore_pystate.h"
#include
"pycore_object_stack.h"
extern
_PyObjectStackChunk
*
_PyObjectStackChunk_New
(
void
);
extern
void
_PyObjectStackChunk_Free
(
_PyObjectStackChunk
*
);
static
struct
_Py_object_stack_freelist
*
get_object_stack_freelist
(
void
)
{
struct
_Py_object_freelists
*
freelists
=
_Py_object_freelists_GET
();
return
&
freelists
->
object_stacks
;
}
_PyObjectStackChunk
*
_PyObjectStackChunk_New
(
void
)
{
_PyObjectStackChunk
*
buf
;
struct
_Py_object_stack_freelist
*
obj_stack_freelist
=
get_object_stack_freelist
();
if
(
obj_stack_freelist
->
numfree
>
0
) {
buf
=
obj_stack_freelist
->
items
;
obj_stack_freelist
->
items
=
buf
->
prev
;
obj_stack_freelist
->
numfree
--
;
}
else
{
// NOTE: we use PyMem_RawMalloc() here because this is used by the GC
// during mimalloc heap traversal. In that context, it is not safe to
// allocate mimalloc memory, such as via PyMem_Malloc().
buf
=
PyMem_RawMalloc
(
sizeof
(
_PyObjectStackChunk
));
if
(
buf
==
NULL
) {
return
NULL
;
}
}
buf
->
prev
=
NULL
;
buf
->
n
=
0
;
return
buf
;
}
void
_PyObjectStackChunk_Free
(
_PyObjectStackChunk
*
buf
)
{
assert
(
buf
->
n
==
0
);
struct
_Py_object_stack_freelist
*
obj_stack_freelist
=
get_object_stack_freelist
();
if
(
obj_stack_freelist
->
numfree
>=
0
&&
obj_stack_freelist
->
numfree
<
_PyObjectStackChunk_MAXFREELIST
)
{
buf
->
prev
=
obj_stack_freelist
->
items
;
obj_stack_freelist
->
items
=
buf
;
obj_stack_freelist
->
numfree
++
;
}
else
{
PyMem_RawFree
(
buf
);
}
}
void
_PyObjectStack_Clear
(
_PyObjectStack
*
queue
)
{
while
(
queue
->
head
!=
NULL
) {
_PyObjectStackChunk
*
buf
=
queue
->
head
;
buf
->
n
=
0
;
queue
->
head
=
buf
->
prev
;
_PyObjectStackChunk_Free
(
buf
);
}
}
void
_PyObjectStack_Merge
(
_PyObjectStack
*
dst
,
_PyObjectStack
*
src
)
{
if
(
src
->
head
==
NULL
) {
return
;
}
if
(
dst
->
head
!=
NULL
) {
// First, append dst to the bottom of src
_PyObjectStackChunk
*
last
=
src
->
head
;
while
(
last
->
prev
!=
NULL
) {
last
=
last
->
prev
;
}
last
->
prev
=
dst
->
head
;
}
// Now that src has all the chunks, set dst to src
dst
->
head
=
src
->
head
;
src
->
head
=
NULL
;
}
void
_PyObjectStackChunk_ClearFreeList
(
struct
_Py_object_freelists
*
freelists
,
int
is_finalization
)
{
if
(!
is_finalization
) {
// Ignore requests to clear the free list during GC. We use object
// stacks during GC, so emptying the free-list is counterproductive.
return
;
}
struct
_Py_object_stack_freelist
*
freelist
=
&
freelists
->
object_stacks
;
while
(
freelist
->
numfree
>
0
) {
_PyObjectStackChunk
*
buf
=
freelist
->
items
;
freelist
->
items
=
buf
->
prev
;
freelist
->
numfree
--
;
PyMem_RawFree
(
buf
);
}
freelist
->
numfree
=
-1
;
}
Back
|
FazBrowse Home
|
New Git URL