@@ -81,6 +81,8 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
81
81
82
82
def create_memory_allocator_venvs () -> List [Venv ]:
83
83
"""Create venv variants for testing different Python memory allocators."""
84
+ import ctypes
85
+
84
86
allocator_configs = [
85
87
{
86
88
"name_suffix" : "pymalloc" ,
@@ -101,9 +103,36 @@ def create_memory_allocator_venvs() -> List[Venv]:
101
103
"name_suffix" : "pymalloc-debug" ,
102
104
"env" : {"PYTHONMALLOC" : "pymalloc_debug" },
103
105
"description" : "Python malloc with debug hooks"
104
- },
106
+ }
107
+ ]
108
+
109
+ # Conditionally add jemalloc variant if the library is available
110
+ jemalloc_names = [
111
+ "libjemalloc.so.2" , # Ubuntu/Debian
112
+ "libjemalloc.so.1" , # Older versions
113
+ "libjemalloc.so" , # Generic
114
+ "libjemalloc.dylib" , # macOS (though less common)
105
115
]
106
116
117
+ for lib_name in jemalloc_names :
118
+ try :
119
+ # Try to load jemalloc library (OSError is raised if not found)
120
+ ctypes .CDLL (lib_name )
121
+
122
+ allocator_configs .append ({
123
+ "name_suffix" : "jemalloc" ,
124
+ "env" : {
125
+ "PYTHONMALLOC" : "malloc" ,
126
+ "LD_PRELOAD" : lib_name
127
+ },
128
+ "description" : "jemalloc high-performance allocator"
129
+ })
130
+
131
+ break
132
+ except (OSError , AttributeError ):
133
+ # Library not found or ctypes issue - try next name
134
+ continue
135
+
107
136
venvs = []
108
137
for config in allocator_configs :
109
138
venvs .append (Venv (
@@ -3348,7 +3377,6 @@ def create_memory_allocator_venvs() -> List[Venv]:
3348
3377
pys = select_pys (),
3349
3378
pkgs = {"uwsgi" : "<2.0.30" },
3350
3379
),
3351
- # Memory allocator testing variants
3352
3380
* create_memory_allocator_venvs (),
3353
3381
# Python 3.8 + 3.9
3354
3382
Venv (
0 commit comments