1
1
// Licence at LICENSES/KLIB_LICENSE
2
2
3
+ #pragma once
4
+
3
5
#include <Python.h>
6
+ #include <pymem.h>
4
7
#include <string.h>
5
8
6
9
typedef struct {
@@ -12,36 +15,24 @@ typedef struct {
12
15
double imag ;
13
16
} khcomplex128_t ;
14
17
15
- // khash should report usage to tracemalloc
16
- #if PY_VERSION_HEX >= 0x03060000
17
- #include <pymem.h>
18
- #if PY_VERSION_HEX < 0x03070000
19
- #define PyTraceMalloc_Track _PyTraceMalloc_Track
20
- #define PyTraceMalloc_Untrack _PyTraceMalloc_Untrack
21
- #endif
22
- #else
23
- #define PyTraceMalloc_Track (...)
24
- #define PyTraceMalloc_Untrack (...)
25
- #endif
26
-
27
18
static const int KHASH_TRACE_DOMAIN = 424242 ;
28
- void * traced_malloc (size_t size ) {
19
+ static inline void * traced_malloc (size_t size ) {
29
20
void * ptr = malloc (size );
30
21
if (ptr != NULL ) {
31
22
PyTraceMalloc_Track (KHASH_TRACE_DOMAIN , (uintptr_t )ptr , size );
32
23
}
33
24
return ptr ;
34
25
}
35
26
36
- void * traced_calloc (size_t num , size_t size ) {
27
+ static inline void * traced_calloc (size_t num , size_t size ) {
37
28
void * ptr = calloc (num , size );
38
29
if (ptr != NULL ) {
39
30
PyTraceMalloc_Track (KHASH_TRACE_DOMAIN , (uintptr_t )ptr , num * size );
40
31
}
41
32
return ptr ;
42
33
}
43
34
44
- void * traced_realloc (void * old_ptr , size_t size ) {
35
+ static inline void * traced_realloc (void * old_ptr , size_t size ) {
45
36
void * ptr = realloc (old_ptr , size );
46
37
if (ptr != NULL ) {
47
38
if (old_ptr != ptr ) {
@@ -52,7 +43,7 @@ void *traced_realloc(void *old_ptr, size_t size) {
52
43
return ptr ;
53
44
}
54
45
55
- void traced_free (void * ptr ) {
46
+ static inline void traced_free (void * ptr ) {
56
47
if (ptr != NULL ) {
57
48
PyTraceMalloc_Untrack (KHASH_TRACE_DOMAIN , (uintptr_t )ptr );
58
49
}
0 commit comments