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/internal/pycore_pymem.h at issue-130160-httpserver · donbarbos/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 }}
donbarbos
/
cpython
Public
forked from
python/cpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
issue-130160-httpserver
Breadcrumbs
cpython
/
Include
/
internal
/
pycore_pymem.h
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
151 lines (124 loc) · 4.85 KB
issue-130160-httpserver
Breadcrumbs
cpython
/
Include
/
internal
/
pycore_pymem.h
Copy path
Top
File metadata and controls
Code
Blame
151 lines (124 loc) · 4.85 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef
Py_INTERNAL_PYMEM_H
#define
Py_INTERNAL_PYMEM_H
#include
"pycore_llist.h"
// struct llist_node
#include
"pycore_lock.h"
// PyMutex
#ifdef
__cplusplus
extern
"C"
{
#endif
#ifndef
Py_BUILD_CORE
# error
"this header requires Py_BUILD_CORE define"
#endif
// Try to get the allocators name set by _PyMem_SetupAllocators().
// Return NULL if unknown.
// Export for '_testinternalcapi' shared extension.
PyAPI_FUNC
(
const
char
*
)
_PyMem_GetCurrentAllocatorName
(
void
);
// strdup() using PyMem_RawMalloc()
extern
char
*
_PyMem_RawStrdup
(
const
char
*
str
);
// strdup() using PyMem_Malloc().
// Export for '_pickle ' shared extension.
PyAPI_FUNC
(
char
*
)
_PyMem_Strdup
(
const
char
*
str
);
// wcsdup() using PyMem_RawMalloc()
extern
wchar_t
*
_PyMem_RawWcsdup
(
const
wchar_t
*
str
);
typedef
struct
{
/* We tag each block with an API ID in order to tag API violations */
char
api_id
;
PyMemAllocatorEx
alloc
;
}
debug_alloc_api_t
;
struct
_pymem_allocators
{
PyMutex
mutex
;
struct
{
PyMemAllocatorEx
raw
;
PyMemAllocatorEx
mem
;
PyMemAllocatorEx
obj
;
}
standard
;
struct
{
debug_alloc_api_t
raw
;
debug_alloc_api_t
mem
;
debug_alloc_api_t
obj
;
}
debug
;
int
is_debug_enabled
;
PyObjectArenaAllocator
obj_arena
;
};
struct
_Py_mem_interp_free_queue
{
int
has_work
;
// true if the queue is not empty
PyMutex
mutex
;
// protects the queue
struct
llist_node
head
;
// queue of _mem_work_chunk items
};
/* Special bytes broadcast into debug memory blocks at appropriate times.
Strings of these are unlikely to be valid addresses, floats, ints or
7-bit ASCII.
- PYMEM_CLEANBYTE: clean (newly allocated) memory
- PYMEM_DEADBYTE dead (newly freed) memory
- PYMEM_FORBIDDENBYTE: untouchable bytes at each end of a block
Byte patterns 0xCB, 0xDB and 0xFB have been replaced with 0xCD, 0xDD and
0xFD to use the same values as Windows CRT debug malloc() and free().
If modified, _PyMem_IsPtrFreed() should be updated as well. */
#define
PYMEM_CLEANBYTE
0xCD
#define
PYMEM_DEADBYTE
0xDD
#define
PYMEM_FORBIDDENBYTE
0xFD
/* Heuristic checking if a pointer value is newly allocated
(uninitialized), newly freed or NULL (is equal to zero).
The pointer is not dereferenced, only the pointer value is checked.
The heuristic relies on the debug hooks on Python memory allocators which
fills newly allocated memory with CLEANBYTE (0xCD) and newly freed memory
with DEADBYTE (0xDD). Detect also "untouchable bytes" marked
with FORBIDDENBYTE (0xFD). */
static
inline
int
_PyMem_IsPtrFreed
(
const
void
*
ptr
)
{
uintptr_t
value
=
(
uintptr_t
)
ptr
;
#if
SIZEOF_VOID_P
==
8
return
(
value
==
0
||
value
==
(
uintptr_t
)
0xCDCDCDCDCDCDCDCD
||
value
==
(
uintptr_t
)
0xDDDDDDDDDDDDDDDD
||
value
==
(
uintptr_t
)
0xFDFDFDFDFDFDFDFD
);
#elif
SIZEOF_VOID_P
==
4
return
(
value
==
0
||
value
==
(
uintptr_t
)
0xCDCDCDCD
||
value
==
(
uintptr_t
)
0xDDDDDDDD
||
value
==
(
uintptr_t
)
0xFDFDFDFD
);
#else
# error
"unknown pointer size"
#endif
}
extern
int
_PyMem_GetAllocatorName
(
const
char
*
name
,
PyMemAllocatorName
*
allocator
);
/* Configure the Python memory allocators.
Pass PYMEM_ALLOCATOR_DEFAULT to use default allocators.
PYMEM_ALLOCATOR_NOT_SET does nothing. */
extern
int
_PyMem_SetupAllocators
(
PyMemAllocatorName
allocator
);
// Default raw memory allocator that is not affected by PyMem_SetAllocator()
extern
void
*
_PyMem_DefaultRawMalloc
(
size_t
);
extern
void
*
_PyMem_DefaultRawCalloc
(
size_t
,
size_t
);
extern
void
*
_PyMem_DefaultRawRealloc
(
void
*
,
size_t
);
extern
void
_PyMem_DefaultRawFree
(
void
*
);
extern
wchar_t
*
_PyMem_DefaultRawWcsdup
(
const
wchar_t
*
str
);
/* Is the debug allocator enabled? */
extern
int
_PyMem_DebugEnabled
(
void
);
// Enqueue a pointer to be freed possibly after some delay.
extern
void
_PyMem_FreeDelayed
(
void
*
ptr
);
// Enqueue an object to be freed possibly after some delay
#ifdef
Py_GIL_DISABLED
PyAPI_FUNC
(
void
)
_PyObject_XDecRefDelayed
(
PyObject
*
obj
);
#else
static
inline
void
_PyObject_XDecRefDelayed
(
PyObject
*
obj
)
{
Py_XDECREF
(
obj
);
}
#endif
// Periodically process delayed free requests.
extern
void
_PyMem_ProcessDelayed
(
PyThreadState
*
tstate
);
// Periodically process delayed free requests when the world is stopped.
// Notify of any objects whic should be freeed.
typedef
void
(
*
delayed_dealloc_cb
)(
PyObject
*
,
void
*
);
extern
void
_PyMem_ProcessDelayedNoDealloc
(
PyThreadState
*
tstate
,
delayed_dealloc_cb
cb
,
void
*
state
);
// Abandon all thread-local delayed free requests and push them to the
// interpreter's queue.
extern
void
_PyMem_AbandonDelayed
(
PyThreadState
*
tstate
);
// On interpreter shutdown, frees all delayed free requests.
extern
void
_PyMem_FiniDelayed
(
PyInterpreterState
*
interp
);
#ifdef
__cplusplus
}
#endif
#endif
// !Py_INTERNAL_PYMEM_H
You can’t perform that action at this time.