diff --git a/src/memray/_memray.pyx b/src/memray/_memray.pyx index 578db87f37..32053383cc 100644 --- a/src/memray/_memray.pyx +++ b/src/memray/_memray.pyx @@ -2,6 +2,7 @@ import collections import contextlib import os import pathlib +import platform import sys cimport cython @@ -865,9 +866,9 @@ cdef class FileReader: except OSError as exc: raise OSError(f"Could not open file {file_name}: {exc.strerror}") from None - IF UNAME_SYSNAME == "Linux": + if platform.system() == "Linux": self._path = "/proc/self/fd/" + str(self._file.fileno()) - ELSE: + else: self._path = str(file_name) self._report_progress = report_progress diff --git a/src/memray/_memray_test_utils.pyx b/src/memray/_memray_test_utils.pyx index 1e144eee6a..d3fa2352ef 100644 --- a/src/memray/_memray_test_utils.pyx +++ b/src/memray/_memray_test_utils.pyx @@ -46,17 +46,29 @@ from libcpp.vector cimport vector from ._destination import Destination -IF UNAME_SYSNAME == "Linux": - cdef extern from "sys/prctl.h": - int prctl(int, char*, char*, char*, char*) + +cdef extern from *: + """ + #ifdef __linux__ + # include + inline int set_thread_name_impl(const char* new_name) + { + return prctl(PR_SET_NAME, new_name, NULL, NULL, NULL); + } + #else + # include + inline int set_thread_name_impl(const char* new_name) + { + errno = ENOTSUP; + return -1; + } + #endif + """ + int set_thread_name_impl(const char* new_name) def set_thread_name(new_name): - cdef int PR_SET_NAME = 15 - IF UNAME_SYSNAME == "Linux": - return prctl(PR_SET_NAME, new_name, NULL, NULL, NULL) - ELSE: - return None + return set_thread_name_impl(new_name) cdef class MemoryAllocator: