FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Include/internal/pycore_object_stack.h 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
75k
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
/
Include
/
internal
/
pycore_object_stack.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
97 lines (80 loc) · 2.33 KB
Breadcrumbs
cpython
/
Include
/
internal
/
pycore_object_stack.h
Copy path
File metadata and controls
97 lines (80 loc) · 2.33 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
#ifndef
Py_INTERNAL_OBJECT_STACK_H
#define
Py_INTERNAL_OBJECT_STACK_H
#include
"pycore_freelist.h"
// _PyFreeListState
#ifdef
__cplusplus
extern
"C"
{
#endif
#ifndef
Py_BUILD_CORE
# error
"this header requires Py_BUILD_CORE define"
#endif
// _PyObjectStack is a stack of Python objects implemented as a linked list of
// fixed size buffers.
// Chosen so that _PyObjectStackChunk is a power-of-two size.
#define
_Py_OBJECT_STACK_CHUNK_SIZE
254
typedef
struct
_PyObjectStackChunk
{
struct
_PyObjectStackChunk
*
prev
;
Py_ssize_t
n
;
PyObject
*
objs
[
_Py_OBJECT_STACK_CHUNK_SIZE
];
}
_PyObjectStackChunk
;
typedef
struct
_PyObjectStack
{
_PyObjectStackChunk
*
head
;
}
_PyObjectStack
;
extern
_PyObjectStackChunk
*
_PyObjectStackChunk_New
(
void
);
extern
void
_PyObjectStackChunk_Free
(
_PyObjectStackChunk
*
);
// Push an item onto the stack. Return -1 on allocation failure, 0 on success.
static
inline
int
_PyObjectStack_Push
(
_PyObjectStack
*
stack
,
PyObject
*
obj
)
{
_PyObjectStackChunk
*
buf
=
stack
->
head
;
if
(
buf
==
NULL
||
buf
->
n
==
_Py_OBJECT_STACK_CHUNK_SIZE
) {
buf
=
_PyObjectStackChunk_New
();
if
(
buf
==
NULL
) {
return
-1
;
}
buf
->
prev
=
stack
->
head
;
buf
->
n
=
0
;
stack
->
head
=
buf
;
}
assert
(
buf
->
n
>=
0
&&
buf
->
n
<
_Py_OBJECT_STACK_CHUNK_SIZE
);
buf
->
objs
[
buf
->
n
]
=
obj
;
buf
->
n
++
;
return
0
;
}
// Pop the top item from the stack. Return NULL if the stack is empty.
static
inline
PyObject
*
_PyObjectStack_Pop
(
_PyObjectStack
*
stack
)
{
_PyObjectStackChunk
*
buf
=
stack
->
head
;
if
(
buf
==
NULL
) {
return
NULL
;
}
assert
(
buf
->
n
>
0
&&
buf
->
n
<=
_Py_OBJECT_STACK_CHUNK_SIZE
);
buf
->
n
--
;
PyObject
*
obj
=
buf
->
objs
[
buf
->
n
];
if
(
buf
->
n
==
0
) {
stack
->
head
=
buf
->
prev
;
_PyObjectStackChunk_Free
(
buf
);
}
return
obj
;
}
static
inline
Py_ssize_t
_PyObjectStack_Size
(
_PyObjectStack
*
stack
)
{
Py_ssize_t
size
=
0
;
for
(
_PyObjectStackChunk
*
buf
=
stack
->
head
;
buf
!=
NULL
;
buf
=
buf
->
prev
) {
size
+=
buf
->
n
;
}
return
size
;
}
// Merge src into dst, leaving src empty
extern
void
_PyObjectStack_Merge
(
_PyObjectStack
*
dst
,
_PyObjectStack
*
src
);
// Remove all items from the stack
extern
void
_PyObjectStack_Clear
(
_PyObjectStack
*
stack
);
#ifdef
__cplusplus
}
#endif
#endif
// !Py_INTERNAL_OBJECT_STACK_H
Back
|
FazBrowse Home
|
New Git URL