Skip to content

Commit e757dd9

Browse files
committed
Address code review
1 parent 0c5a495 commit e757dd9

File tree

7 files changed

+14
-13
lines changed

7 files changed

+14
-13
lines changed

Include/internal/pycore_pymem.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ extern "C" {
1111
# error "this header requires Py_BUILD_CORE define"
1212
#endif
1313

14-
#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME)
14+
#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__)
15+
#include <linux/prctl.h>
1516
#include <sys/prctl.h>
1617
#endif
1718

@@ -96,9 +97,9 @@ static inline int _PyMem_IsULongFreed(unsigned long value)
9697
}
9798

9899
static inline int
99-
_PyMem_Annotate_Mmap(void *addr, size_t size, const char *name)
100+
_PyAnnotateMemoryMap(void *addr, size_t size, const char *name)
100101
{
101-
#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME)
102+
#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__)
102103
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name);
103104
// Ignore errno from prctl
104105
// See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746

Modules/_ctypes/malloc_closure.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# endif
1515
#endif
1616
#include "ctypes.h"
17-
#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap()
17+
#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap()
1818

1919
/* BLOCKSIZE can be adjusted. Larger blocksize will take a larger memory
2020
overhead, but allocate less blocks from the system. It may be that some
@@ -84,7 +84,7 @@ static void more_core(void)
8484
0);
8585
if (item == (void *)MAP_FAILED)
8686
return;
87-
_PyMem_Annotate_Mmap(item, mem_size, "Python:more_core");
87+
_PyAnnotateMemoryMap(item, mem_size, "Python:more_core");
8888
#endif
8989

9090
#ifdef MALLOC_CLOSURE_DEBUG

Modules/mmapmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
2727
#include "pycore_bytesobject.h" // _PyBytes_Find()
2828
#include "pycore_fileutils.h" // _Py_stat_struct
29-
#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap()
29+
#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap()
3030
#include "pycore_weakref.h" // FT_CLEAR_WEAKREFS()
3131

3232
#include <stddef.h> // offsetof()
@@ -1952,7 +1952,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
19521952
PyErr_SetFromErrno(PyExc_OSError);
19531953
return NULL;
19541954
}
1955-
_PyMem_Annotate_Mmap(m_obj->data, map_size, "Python:new_mmap_object");
1955+
_PyAnnotateMemoryMap(m_obj->data, map_size, "Python:new_mmap_object");
19561956
m_obj->access = (access_mode)access;
19571957
return (PyObject *)m_obj;
19581958
}

Objects/obmalloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ _PyMem_ArenaAlloc(void *Py_UNUSED(ctx), size_t size)
467467
if (ptr == MAP_FAILED)
468468
return NULL;
469469
assert(ptr != NULL);
470-
_PyMem_Annotate_Mmap(ptr, size, "Python:PyMem_ArenaAlloc");
470+
_PyAnnotateMemoryMap(ptr, size, "Python:PyMem_ArenaAlloc");
471471
return ptr;
472472
#else
473473
return malloc(size);

Python/jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jit_alloc(size_t size)
7272
unsigned char *memory = mmap(NULL, size, prot, flags, -1, 0);
7373
int failed = memory == MAP_FAILED;
7474
if (!failed) {
75-
_PyMem_Annotate_Mmap(memory, size, "Python:jit_alloc");
75+
_PyAnnotateMemoryMap(memory, size, "Python:jit_alloc");
7676
}
7777
#endif
7878
if (failed) {

Python/perf_jit_trampoline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#include "pycore_ceval.h" // _PyPerf_Callbacks
6262
#include "pycore_frame.h"
6363
#include "pycore_interp.h"
64-
#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap()
64+
#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap()
6565
#include "pycore_runtime.h" // _PyRuntime
6666

6767
#ifdef PY_HAVE_PERF_TRAMPOLINE
@@ -1086,7 +1086,7 @@ static void* perf_map_jit_init(void) {
10861086
close(fd);
10871087
return NULL; // Memory mapping failed
10881088
}
1089-
_PyMem_Annotate_Mmap(perf_jit_map_state.mapped_buffer, page_size, "Python:perf_map_jit_init");
1089+
_PyAnnotateMemoryMap(perf_jit_map_state.mapped_buffer, page_size, "Python:perf_map_jit_init");
10901090
#endif
10911091

10921092
perf_jit_map_state.mapped_size = page_size;

Python/perf_trampoline.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ any DWARF information available for them).
132132
#include "Python.h"
133133
#include "pycore_ceval.h" // _PyPerf_Callbacks
134134
#include "pycore_interpframe.h" // _PyFrame_GetCode()
135-
#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap()
135+
#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap()
136136
#include "pycore_runtime.h" // _PyRuntime
137137

138138

@@ -291,7 +291,7 @@ new_code_arena(void)
291291
perf_status = PERF_STATUS_FAILED;
292292
return -1;
293293
}
294-
_PyMem_Annotate_Mmap(memory, mem_size, "Python:new_code_arena");
294+
_PyAnnotateMemoryMap(memory, mem_size, "Python:new_code_arena");
295295
void *start = &_Py_trampoline_func_start;
296296
void *end = &_Py_trampoline_func_end;
297297
size_t code_size = end - start;

0 commit comments

Comments
 (0)