Skip to content

Commit 7802c09

Browse files
committed
Implement rb_bug() and rb_fatal() to show the error message passed to them
1 parent 8843340 commit 7802c09

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/cext/ABI_check.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1
1+
2

lib/truffle/truffle/cext.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,14 @@ def rb_f_notimplement
17841784
raise NotImplementedError, "#{function}() function is unimplemented on this machine"
17851785
end
17861786

1787+
def rb_bug(message)
1788+
raise Exception, "rb_bug: #{message}"
1789+
end
1790+
1791+
def rb_fatal(message)
1792+
raise Exception, "rb_fatal: #{message}"
1793+
end
1794+
17871795
def test_kwargs(kwargs, raise_error)
17881796
return false if Primitive.nil?(kwargs)
17891797

src/main/c/cext/exception.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,19 @@ void rb_eof_error(void) {
156156
}
157157

158158
void rb_tr_bug_va_list(const char *fmt, va_list args) {
159-
rb_tr_not_implemented("rb_bug");
159+
char buffer[1024];
160+
vsnprintf(buffer, 1024, fmt, args);
161+
VALUE message = rb_str_new_cstr(buffer);
162+
RUBY_CEXT_INVOKE_NO_WRAP("rb_bug", message);
163+
UNREACHABLE;
160164
}
161165

162166
void rb_tr_fatal_va_list(const char *fmt, va_list args) {
163-
rb_tr_not_implemented("rb_fatal");
167+
char buffer[1024];
168+
vsnprintf(buffer, 1024, fmt, args);
169+
VALUE message = rb_str_new_cstr(buffer);
170+
RUBY_CEXT_INVOKE_NO_WRAP("rb_fatal", message);
171+
UNREACHABLE;
164172
}
165173

166174
VALUE rb_make_exception(int argc, const VALUE *argv) {

0 commit comments

Comments
 (0)