Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using IF in our Cython code #545

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/memray/_memray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import collections
import contextlib
import os
import pathlib
import platform
import sys

cimport cython
Expand Down Expand Up @@ -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

Expand Down
28 changes: 20 additions & 8 deletions src/memray/_memray_test_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 *:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice approach ❤️

"""
#ifdef __linux__
# include <sys/prctl.h>
inline int set_thread_name_impl(const char* new_name)
{
return prctl(PR_SET_NAME, new_name, NULL, NULL, NULL);
}
#else
# include <errno.h>
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:
Expand Down
Loading