Skip to content

Commit 3c069e4

Browse files
authored
Allow to use a differently suffixed jemalloc (#147)
1 parent 31f8048 commit 3c069e4

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
Changelog
88
=========
99

10+
3.0.2 - 2021-10-14
11+
------------------
12+
13+
**Bug fix**
14+
15+
- Allow to link to alternatively suffixed jemalloc installation to workaround `#113 <https://github.com/Quantco/tabmat/issues/113>`_ .
16+
1017
3.0.1 - 2021-10-07
1118
------------------
1219

conda.recipe/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ requirements:
2727
host:
2828
- python
2929
- cython
30-
- jemalloc # [not win]
30+
- jemalloc-local # [not win]
3131
- llvm-openmp # [osx]
3232
- mako
3333
- numpy

setup.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import io
22
import os
33
import platform
4+
import shutil
45
import sys
56
from os import path
7+
from pathlib import Path
68

79
import mako.template
810
import numpy as np
@@ -55,12 +57,25 @@
5557
# make sure we can find xsimd headers
5658
include_dirs.append(os.path.join(sys.prefix, "Library", "include"))
5759
else:
58-
allocator_libs = ["jemalloc"]
60+
jemalloc_config = shutil.which("jemalloc-config")
61+
if jemalloc_config is None:
62+
je_install_suffix = ""
63+
else:
64+
pkg_info = (
65+
Path(jemalloc_config).parent.parent / "lib" / "pkgconfig" / "jemalloc.pc"
66+
).read_text()
67+
je_install_suffix = [
68+
i.split("=")[1]
69+
for i in pkg_info.split("\n")
70+
if i.startswith("install_suffix=")
71+
].pop()
72+
allocator_libs = [f"jemalloc{je_install_suffix}"]
5973
extra_compile_args = [
6074
"-fopenmp",
6175
"-O3",
6276
"-ffast-math",
6377
"--std=c++17",
78+
f"-DJEMALLOC_INSTALL_SUFFIX={je_install_suffix}",
6479
]
6580
extra_link_args = ["-fopenmp"]
6681

src/tabmat/ext/alloc.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@
33
#ifndef _WIN32
44
#define JEMALLOC_NO_DEMANGLE
55
#if __APPLE__
6-
#define JEMALLOC_NO_RENAME
6+
#if !(!JEMALLOC_INSTALL_SUFFIX)
7+
#define JEMALLOC_NO_RENAME
8+
#endif
79
#endif
8-
#include <jemalloc/jemalloc.h>
10+
// Compute jemalloc include path
11+
#define STRINGIFY(X) STRINGIFY2(X)
12+
#define STRINGIFY2(X) #X
13+
#define CAT(X,Y) CAT2(X,Y)
14+
#define CAT2(X,Y) X##Y
15+
#define JE_INCLUDE STRINGIFY(CAT(jemalloc/jemalloc,JEMALLOC_INSTALL_SUFFIX).h)
16+
#include JE_INCLUDE
917
#endif
1018

1119
#include <functional>

0 commit comments

Comments
 (0)