Skip to content

Commit bf60b12

Browse files
WillAydpmhatre1
authored andcommitted
CLN: Assorted khash-python cleanups (pandas-dev#57575)
* CLN: Assort khash-python cleanups * add static inline to memory tracers * revert mistake with hashdouble * try less
1 parent 8648ff0 commit bf60b12

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

pandas/_libs/include/pandas/vendored/klib/khash_python.h

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Licence at LICENSES/KLIB_LICENSE
22

3+
#pragma once
4+
35
#include <Python.h>
6+
#include <pymem.h>
47
#include <string.h>
58

69
typedef struct {
@@ -12,36 +15,24 @@ typedef struct {
1215
double imag;
1316
} khcomplex128_t;
1417

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-
2718
static const int KHASH_TRACE_DOMAIN = 424242;
28-
void *traced_malloc(size_t size) {
19+
static inline void *traced_malloc(size_t size) {
2920
void *ptr = malloc(size);
3021
if (ptr != NULL) {
3122
PyTraceMalloc_Track(KHASH_TRACE_DOMAIN, (uintptr_t)ptr, size);
3223
}
3324
return ptr;
3425
}
3526

36-
void *traced_calloc(size_t num, size_t size) {
27+
static inline void *traced_calloc(size_t num, size_t size) {
3728
void *ptr = calloc(num, size);
3829
if (ptr != NULL) {
3930
PyTraceMalloc_Track(KHASH_TRACE_DOMAIN, (uintptr_t)ptr, num * size);
4031
}
4132
return ptr;
4233
}
4334

44-
void *traced_realloc(void *old_ptr, size_t size) {
35+
static inline void *traced_realloc(void *old_ptr, size_t size) {
4536
void *ptr = realloc(old_ptr, size);
4637
if (ptr != NULL) {
4738
if (old_ptr != ptr) {
@@ -52,7 +43,7 @@ void *traced_realloc(void *old_ptr, size_t size) {
5243
return ptr;
5344
}
5445

55-
void traced_free(void *ptr) {
46+
static inline void traced_free(void *ptr) {
5647
if (ptr != NULL) {
5748
PyTraceMalloc_Untrack(KHASH_TRACE_DOMAIN, (uintptr_t)ptr);
5849
}

0 commit comments

Comments
 (0)