From 9332db29f3d85a24100439f3f2fda07c19c0131c Mon Sep 17 00:00:00 2001 From: "bozo.kopic" Date: Tue, 20 Aug 2024 21:27:32 +0200 Subject: [PATCH] c py_allocator update --- src_c/hat/py_allocator.c | 12 +++++++++++- src_c/hat/py_allocator.h | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src_c/hat/py_allocator.c b/src_c/hat/py_allocator.c index 2af835d..ce6db8c 100644 --- a/src_c/hat/py_allocator.c +++ b/src_c/hat/py_allocator.c @@ -1,4 +1,4 @@ -#include "allocator.h" +#include "py_allocator.h" #include @@ -10,4 +10,14 @@ static void *py_realloc(hat_allocator_t *a, size_t size, void *old) { } +static void *py_raw_realloc(hat_allocator_t *a, size_t size, void *old) { + if (size) + return PyMem_RawRealloc(old, size); + PyMem_RawFree(old); + return NULL; +} + + hat_allocator_t hat_py_allocator = {.realloc = py_realloc}; + +hat_allocator_t hat_py_raw_allocator = {.realloc = py_raw_realloc}; diff --git a/src_c/hat/py_allocator.h b/src_c/hat/py_allocator.h index a383c11..5c6d450 100644 --- a/src_c/hat/py_allocator.h +++ b/src_c/hat/py_allocator.h @@ -14,6 +14,9 @@ extern "C" { /** \brief allocator instance */ extern hat_allocator_t hat_py_allocator; +/** \brief raw allocator instance */ +extern hat_allocator_t hat_py_raw_allocator; + #ifdef __cplusplus } #endif