Project

General

Profile

Actions

Bug #18777

closed

NDEBUG macro defined after including ruby.h

Added by Kerilk (Brice Videau) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
3.0.2p107;3.1.2p20
[ruby-core:108534]

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

test.c (79 Bytes) test.c Kerilk (Brice Videau), 05/12/2022 08:15 PM

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>
Actions

Also available in: Atom PDF

Like0
Like0Like0