Skip to content

Commit dc4cd33

Browse files
authored
chore(profiling): explicitly set or clear NDEBUG for memalloc extension (#13218)
The memalloc C extension has debug assert statements. We want them off by default in case they guard a costly call we wouldn't normally want to happen. Depending on how the CPython interpreter running setup.py was built, we may already get -DNDEBUG via the CFLAGS from sysconfig, which disables asserts. See the [setuptools docs](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html#compiler-and-linker-options). But rather than rely on that, make sure that asserts are explicitly disabled for normal builds and explicitly enabled for debug builds.
1 parent 002e5f9 commit dc4cd33

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

setup.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,14 @@ def get_exts_for(name):
614614
"ddtrace/profiling/collector/_memalloc_reentrant.c",
615615
],
616616
extra_compile_args=(
617-
debug_compile_args + ["-D_POSIX_C_SOURCE=200809L", "-std=c11"] + fast_build_args
617+
debug_compile_args
618+
# If NDEBUG is set, assert statements are compiled out. Make
619+
# sure we explicitly set this for normal builds, and explicitly
620+
# _unset_ it for debug builds in case the CFLAGS from sysconfig
621+
# include -DNDEBUG
622+
+ (["-DNDEBUG"] if not debug_compile_args else ["-UNDEBUG"])
623+
+ ["-D_POSIX_C_SOURCE=200809L", "-std=c11"]
624+
+ fast_build_args
618625
if CURRENT_OS != "Windows"
619626
else ["/std:c11"]
620627
),

0 commit comments

Comments
 (0)