Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace assert with RUBY_ASSERT #9884

Merged
merged 14 commits into from
Feb 12, 2024
Merged

Conversation

peterzhu2118
Copy link
Member

assert does not print the bug report, only the file and line number of the assertion that failed. RUBY_ASSERT prints the full bug report, which makes it much easier to debug.

assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
assert does not print the bug report, only the file and line number of
the assertion that failed. RUBY_ASSERT prints the full bug report, which
makes it much easier to debug.
@nobu
Copy link
Member

nobu commented Feb 8, 2024

These files include "ruby_assert.h", so assert is substituted to RUBY_ASSERT_NDEBUG.

@peterzhu2118
Copy link
Member Author

But when I use a assert(false), I get:

Assertion failed: (false), function ary_new, file array.c, line 700.

Whereas, RUBY_ASSERT(false) is:

Assertion Failed: ../array.c:700:ary_new:false
ruby 3.4.0dev (2024-02-08T15:22:07Z master b74c8abd11) [arm64-darwin23]

-- Crash Report log information --------------------------------------------
   See Crash Report log file in one of the following locations:             
     * ~/Library/Logs/DiagnosticReports                                     
     * /Library/Logs/DiagnosticReports                                      
   for more details.                                                        
Don't forget to include the above Crash Report log file in bug reports.     

-- Control frame information -----------------------------------------------
c:0001 p:---- s:0003 e:000002 DUMMY  [FINISH]


-- Threading information ---------------------------------------------------
Total ractor count: 0
Ruby thread count for this ractor: 0

-- C level backtrace information -------------------------------------------
/Users/peter/src/ruby/build/miniruby(rb_vm_bugreport+0xb60) [0x1051f4154] ../vm_dump.c:1151
/Users/peter/src/ruby/build/miniruby(rb_vm_bugreport) (null):0
/Users/peter/src/ruby/build/miniruby(rb_assert_failure_detail+0xa4) [0x1052fdb40] ../error.c:1146
/Users/peter/src/ruby/build/miniruby(rb_assert_failure_detail+0x0) [0x1052fda9c] ../error.c:1126
/Users/peter/src/ruby/build/miniruby(rb_assert_failure) (null):0
/Users/peter/src/ruby/build/miniruby(rb_ary_hidden_new_fill+0x0) [0x104f7001c] ../array.c:700
/Users/peter/src/ruby/build/miniruby(ary_new) (null):0
/Users/peter/src/ruby/build/miniruby(rb_ary_hidden_new) ../array.c:847
/Users/peter/src/ruby/build/miniruby(Init_vm_objects+0x24) [0x1051da7e8] ../vm.c:4240
/Users/peter/src/ruby/build/miniruby(rb_current_execution_context+0x0) [0x1050188cc] ../eval.c:83
/Users/peter/src/ruby/build/miniruby(ruby_setup) ../eval.c:85
/Users/peter/src/ruby/build/miniruby(ruby_init+0x10) [0x105018ab0] ../eval.c:99
/Users/peter/src/ruby/build/miniruby(rb_main+0xc) [0x104f6e66c] ../main.c:38
/Users/peter/src/ruby/build/miniruby(main) ../main.c:58

@peterzhu2118
Copy link
Member Author

It looks like the implementation of assert.h doesn't have header guards, so any #include <assert.h> after the first #include "ruby/assert.h" will override the #define assert RUBY_ASSERT_NDEBUG.

@nobu
Copy link
Member

nobu commented Feb 9, 2024

assert.h doesn’t have the guard because the standard assert should be able to redefined according to NDEBUG every time the file is included.

@peterzhu2118
Copy link
Member Author

assert.h doesn’t have the guard because the standard assert should be able to redefined according to NDEBUG every time the file is included.

I'm not sure what the optimal solution is then. Do we replace all assert with RUBY_ASSERT? Do we forbid using assert.h and only allow using ruby_assert.h?

@peterzhu2118
Copy link
Member Author

@nobu can I merge this or do you prefer this solved using another way?

@peterzhu2118 peterzhu2118 merged commit 0536b2c into ruby:master Feb 12, 2024
98 checks passed
@peterzhu2118 peterzhu2118 deleted the ruby-assert branch February 12, 2024 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants