From a19a172eb9946b4b38b243f06a011e6ffc3656a5 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Tue, 3 Dec 2024 17:07:27 +0200 Subject: [PATCH] Refactor rb_syserr_fail and rb_syserr_fail_str to call rb_syserr_fail Ruby method with nil instead of "" when custom message is NULL or Qnil --- lib/cext/ABI_check.txt | 2 +- src/main/c/cext/exception.c | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/cext/ABI_check.txt b/lib/cext/ABI_check.txt index b8626c4cff28..7ed6ff82de6b 100644 --- a/lib/cext/ABI_check.txt +++ b/lib/cext/ABI_check.txt @@ -1 +1 @@ -4 +5 diff --git a/src/main/c/cext/exception.c b/src/main/c/cext/exception.c index 00db66949047..8c204cd82a66 100644 --- a/src/main/c/cext/exception.c +++ b/src/main/c/cext/exception.c @@ -62,15 +62,12 @@ VALUE rb_errinfo(void) { } void rb_syserr_fail(int eno, const char *message) { - polyglot_invoke(RUBY_CEXT, "rb_syserr_fail", eno, rb_tr_unwrap(rb_str_new_cstr(message == NULL ? "" : message))); + VALUE messageValue = (message == NULL) ? Qnil : rb_str_new_cstr(message); + polyglot_invoke(RUBY_CEXT, "rb_syserr_fail", eno, rb_tr_unwrap(messageValue)); UNREACHABLE; } void rb_syserr_fail_str(int eno, VALUE message) { - if (message == Qnil) { - message = rb_str_new_cstr(""); - } - polyglot_invoke(RUBY_CEXT, "rb_syserr_fail", eno, rb_tr_unwrap(message)); UNREACHABLE; }