Bug #18777
closedNDEBUG macro defined after including ruby.h
Description
Hello,
When using ruby 3+, including ruby.h
results in the NDEBUG
macro becoming defined, which deactivates assertions.
This simple (see attached test.c
file) example illustrates this:
#include <assert.h>
#include <ruby.h>
int main() {
assert(0);
return 0;
}
I expect:
gcc test.c
./a.out
To fail, and it does not. Commenting the #include <ruby.h>
yields the expected result.
I found several discussion in the issues regarding NDEBUG
in Ruby 3+, but none seem to describe this particular behavior. Sorry if I missed something.
Thanks.
Files
Updated by shyouhei (Shyouhei Urabe) over 2 years ago
- Status changed from Open to Closed
This is intentional. Devs hate assertions. See also https://bugs.ruby-lang.org/issues/16837 .
Updated by Kerilk (Brice Videau) over 2 years ago
shyouhei (Shyouhei Urabe) wrote in #note-1:
This is intentional. Devs hate assertions. See also https://bugs.ruby-lang.org/issues/16837 .
Thanks for confirming.
Here is the workaround I use, should anybody with the same issue need a solution.
// Ruby 3+ bleeds NDEBUG
// see https://bugs.ruby-lang.org/issues/18777#change-97580
#ifdef NDEBUG
#include <ruby.h>
#else
#include <ruby.h>
#undef NDEBUG
#endif
// DO NOT MOVE. If assert.h is included before ruby.h asserts will turn to no-op.
#include <assert.h>