Skip to content

Commit

Permalink
c py_allocator update
Browse files Browse the repository at this point in the history
  • Loading branch information
bozokopic committed Aug 20, 2024
1 parent a1af4de commit 9332db2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src_c/hat/py_allocator.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "allocator.h"
#include "py_allocator.h"
#include <Python.h>


Expand All @@ -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};
3 changes: 3 additions & 0 deletions src_c/hat/py_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9332db2

Please sign in to comment.