File indexing completed on 2025-01-18 10:06:46
0001 #ifndef Py_INTERNAL_PYMEM_H
0002 #define Py_INTERNAL_PYMEM_H
0003 #ifdef __cplusplus
0004 extern "C" {
0005 #endif
0006
0007 #ifndef Py_BUILD_CORE
0008 # error "this header requires Py_BUILD_CORE define"
0009 #endif
0010
0011 #include "pymem.h" // PyMemAllocatorName
0012
0013
0014 typedef struct {
0015
0016 char api_id;
0017 PyMemAllocatorEx alloc;
0018 } debug_alloc_api_t;
0019
0020 struct _pymem_allocators {
0021 PyThread_type_lock mutex;
0022 struct {
0023 PyMemAllocatorEx raw;
0024 PyMemAllocatorEx mem;
0025 PyMemAllocatorEx obj;
0026 } standard;
0027 struct {
0028 debug_alloc_api_t raw;
0029 debug_alloc_api_t mem;
0030 debug_alloc_api_t obj;
0031 } debug;
0032 PyObjectArenaAllocator obj_arena;
0033 };
0034
0035
0036
0037
0038
0039 PyAPI_FUNC(int) _PyMem_SetDefaultAllocator(
0040 PyMemAllocatorDomain domain,
0041 PyMemAllocatorEx *old_alloc);
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 #define PYMEM_CLEANBYTE 0xCD
0055 #define PYMEM_DEADBYTE 0xDD
0056 #define PYMEM_FORBIDDENBYTE 0xFD
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 static inline int _PyMem_IsPtrFreed(const void *ptr)
0068 {
0069 uintptr_t value = (uintptr_t)ptr;
0070 #if SIZEOF_VOID_P == 8
0071 return (value == 0
0072 || value == (uintptr_t)0xCDCDCDCDCDCDCDCD
0073 || value == (uintptr_t)0xDDDDDDDDDDDDDDDD
0074 || value == (uintptr_t)0xFDFDFDFDFDFDFDFD);
0075 #elif SIZEOF_VOID_P == 4
0076 return (value == 0
0077 || value == (uintptr_t)0xCDCDCDCD
0078 || value == (uintptr_t)0xDDDDDDDD
0079 || value == (uintptr_t)0xFDFDFDFD);
0080 #else
0081 # error "unknown pointer size"
0082 #endif
0083 }
0084
0085 PyAPI_FUNC(int) _PyMem_GetAllocatorName(
0086 const char *name,
0087 PyMemAllocatorName *allocator);
0088
0089
0090
0091
0092 PyAPI_FUNC(int) _PyMem_SetupAllocators(PyMemAllocatorName allocator);
0093
0094
0095 #ifdef __cplusplus
0096 }
0097 #endif
0098 #endif