PHP 8.2.30
Preview: pycore_pymem.h Size: 5.24 KB
//opt/alt/python313/include/python3.13/internal/pycore_pymem.h

#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
};

/* Set the memory allocator of the specified domain to the default.
   Save the old allocator into *old_alloc if it's non-NULL.
   Return on success, or return -1 if the domain is unknown. */
extern int _PyMem_SetDefaultAllocator(
    PyMemAllocatorDomain domain,
    PyMemAllocatorEx *old_alloc);

/* 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 <= 0xff  // NULL, 0x1, 0x2, ..., 0xff
            || value == (uintptr_t)0xCDCDCDCDCDCDCDCD
            || value == (uintptr_t)0xDDDDDDDDDDDDDDDD
            || value == (uintptr_t)0xFDFDFDFDFDFDFDFD
            || value >= (uintptr_t)0xFFFFFFFFFFFFFF00);  // -0xff, ..., -2, -1
#elif SIZEOF_VOID_P == 4
    return (value <= 0xff
            || value == (uintptr_t)0xCDCDCDCD
            || value == (uintptr_t)0xDDDDDDDD
            || value == (uintptr_t)0xFDFDFDFD
            || value >= (uintptr_t)0xFFFFFF00);
#else
#  error "unknown pointer size"
#endif
}

// Similar to _PyMem_IsPtrFreed() but expects an 'unsigned long' instead of a
// pointer.
static inline int _PyMem_IsULongFreed(unsigned long value)
{
#if SIZEOF_LONG == 8
    return (value == 0
            || value == (unsigned long)0xCDCDCDCDCDCDCDCD
            || value == (unsigned long)0xDDDDDDDDDDDDDDDD
            || value == (unsigned long)0xFDFDFDFDFDFDFDFD
            || value == (unsigned long)0xFFFFFFFFFFFFFFFF);
#elif SIZEOF_LONG == 4
    return (value == 0
            || value == (unsigned long)0xCDCDCDCD
            || value == (unsigned long)0xDDDDDDDD
            || value == (unsigned long)0xFDFDFDFD
            || value == (unsigned long)0xFFFFFFFF);
#else
#  error "unknown long 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);

/* 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, size_t size);

// Enqueue an object to be freed possibly after some delay
extern void _PyObject_FreeDelayed(void *ptr);

// Periodically process delayed free requests.
extern void _PyMem_ProcessDelayed(PyThreadState *tstate);

// 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

Directory Contents

Dirs: 1 × Files: 122

Name Size Perms Modified Actions
mimalloc DIR
- drwxr-xr-x 2026-02-10 08:09:23
Edit Download
1.87 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.96 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
30.78 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
6.62 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.40 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.81 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
5.88 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
8.57 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.05 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
4.98 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.84 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
5.99 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
397 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.03 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
11.10 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.83 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
19.71 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.41 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.66 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
588 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.64 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.15 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
7.78 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
11.84 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
543 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
11.98 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
732 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.69 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
685 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.11 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
900 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.19 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
9.25 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.65 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.46 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.45 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
480 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
12.08 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
4.70 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.50 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
12.66 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
859 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
490 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.14 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.02 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
115.04 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
26.08 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.65 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
4.26 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
515 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
7.55 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.96 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
6.23 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.11 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.28 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
14.72 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.71 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
527 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.82 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.36 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
8.34 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
9.73 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
427 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.60 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.27 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.54 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
435 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
27.28 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.13 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.33 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
942 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
26.78 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.89 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
82.88 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.07 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
8.11 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.27 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.04 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
658 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.79 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
7.87 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
510 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
4.84 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.75 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
4.36 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
8.40 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
5.24 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.44 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
9.73 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
420 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
758 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
5.95 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
5.39 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
346 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
12.86 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
12.74 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
45.72 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.69 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
951 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.86 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
369 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
5.06 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1013 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
963 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
8.47 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.15 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
11.52 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
2.93 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.54 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
4.43 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
1.32 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
820 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
8.67 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
924 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
958 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
12.96 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
129.04 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
742 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
10.06 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
38.72 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download
840 B lrw-r--r-- 2025-12-05 16:06:33
Edit Download
3.80 KB lrw-r--r-- 2025-12-05 16:06:33
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).