CoolFace
Apppublic

vidya7732/AI_Doctor_LLM_GenModel

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
pymem.h109 linesDownload Raw Back to cpython
1#ifndef Py_CPYTHON_PYMEM_H2#  error "this header file must not be included directly"3#endif4 5#ifdef __cplusplus6extern "C" {7#endif8 9PyAPI_FUNC(void *) PyMem_RawMalloc(size_t size);10PyAPI_FUNC(void *) PyMem_RawCalloc(size_t nelem, size_t elsize);11PyAPI_FUNC(void *) PyMem_RawRealloc(void *ptr, size_t new_size);12PyAPI_FUNC(void) PyMem_RawFree(void *ptr);13 14/* Try to get the allocators name set by _PyMem_SetupAllocators(). */15PyAPI_FUNC(const char*) _PyMem_GetCurrentAllocatorName(void);16 17PyAPI_FUNC(void *) PyMem_Calloc(size_t nelem, size_t elsize);18 19/* strdup() using PyMem_RawMalloc() */20PyAPI_FUNC(char *) _PyMem_RawStrdup(const char *str);21 22/* strdup() using PyMem_Malloc() */23PyAPI_FUNC(char *) _PyMem_Strdup(const char *str);24 25/* wcsdup() using PyMem_RawMalloc() */26PyAPI_FUNC(wchar_t*) _PyMem_RawWcsdup(const wchar_t *str);27 28 29typedef enum {30    /* PyMem_RawMalloc(), PyMem_RawRealloc() and PyMem_RawFree() */31    PYMEM_DOMAIN_RAW,32 33    /* PyMem_Malloc(), PyMem_Realloc() and PyMem_Free() */34    PYMEM_DOMAIN_MEM,35 36    /* PyObject_Malloc(), PyObject_Realloc() and PyObject_Free() */37    PYMEM_DOMAIN_OBJ38} PyMemAllocatorDomain;39 40typedef enum {41    PYMEM_ALLOCATOR_NOT_SET = 0,42    PYMEM_ALLOCATOR_DEFAULT = 1,43    PYMEM_ALLOCATOR_DEBUG = 2,44    PYMEM_ALLOCATOR_MALLOC = 3,45    PYMEM_ALLOCATOR_MALLOC_DEBUG = 4,46#ifdef WITH_PYMALLOC47    PYMEM_ALLOCATOR_PYMALLOC = 5,48    PYMEM_ALLOCATOR_PYMALLOC_DEBUG = 6,49#endif50} PyMemAllocatorName;51 52 53typedef struct {54    /* user context passed as the first argument to the 4 functions */55    void *ctx;56 57    /* allocate a memory block */58    void* (*malloc) (void *ctx, size_t size);59 60    /* allocate a memory block initialized by zeros */61    void* (*calloc) (void *ctx, size_t nelem, size_t elsize);62 63    /* allocate or resize a memory block */64    void* (*realloc) (void *ctx, void *ptr, size_t new_size);65 66    /* release a memory block */67    void (*free) (void *ctx, void *ptr);68} PyMemAllocatorEx;69 70/* Get the memory block allocator of the specified domain. */71PyAPI_FUNC(void) PyMem_GetAllocator(PyMemAllocatorDomain domain,72                                    PyMemAllocatorEx *allocator);73 74/* Set the memory block allocator of the specified domain.75 76   The new allocator must return a distinct non-NULL pointer when requesting77   zero bytes.78 79   For the PYMEM_DOMAIN_RAW domain, the allocator must be thread-safe: the GIL80   is not held when the allocator is called.81 82   If the new allocator is not a hook (don't call the previous allocator), the83   PyMem_SetupDebugHooks() function must be called to reinstall the debug hooks84   on top on the new allocator. */85PyAPI_FUNC(void) PyMem_SetAllocator(PyMemAllocatorDomain domain,86                                    PyMemAllocatorEx *allocator);87 88/* Setup hooks to detect bugs in the following Python memory allocator89   functions:90 91   - PyMem_RawMalloc(), PyMem_RawRealloc(), PyMem_RawFree()92   - PyMem_Malloc(), PyMem_Realloc(), PyMem_Free()93   - PyObject_Malloc(), PyObject_Realloc() and PyObject_Free()94 95   Newly allocated memory is filled with the byte 0xCB, freed memory is filled96   with the byte 0xDB. Additional checks:97 98   - detect API violations, ex: PyObject_Free() called on a buffer allocated99     by PyMem_Malloc()100   - detect write before the start of the buffer (buffer underflow)101   - detect write after the end of the buffer (buffer overflow)102 103   The function does nothing if Python is not compiled is debug mode. */104PyAPI_FUNC(void) PyMem_SetupDebugHooks(void);105 106#ifdef __cplusplus107}108#endif109