Created
February 10, 2019 16:01
-
-
Save packrat386/deacbc6fa401af143d137d7b92380eb3 to your computer and use it in GitHub Desktop.
Git patch to override RB_TEST to attempt to check class instead of specific values. Didn't work very well.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From ee8b5f5c1f4072affd1c3d68209e39889831c56e Mon Sep 17 00:00:00 2001 | |
From: Aidan Coyle <packrat386@gmail.com> | |
Date: Sun, 10 Feb 2019 15:54:21 +0000 | |
Subject: [PATCH] Override the RB_TEST macro to check falsiness | |
Rather than only accepting the exact values Qnil and Qfalse, instead | |
check the class of the VALUE passed to see if it is FalseClass. | |
--- | |
eval.c | 16 ++++++++++++++++ | |
include/ruby/ruby.h | 12 ++++++------ | |
object.c | 2 -- | |
3 files changed, 22 insertions(+), 8 deletions(-) | |
diff --git a/eval.c b/eval.c | |
index 4476390270..5843005104 100644 | |
--- a/eval.c | |
+++ b/eval.c | |
@@ -1976,3 +1976,19 @@ Init_eval(void) | |
id_signo = rb_intern_const("signo"); | |
id_status = rb_intern_const("status"); | |
} | |
+ | |
+int do_rb_test(VALUE v) | |
+{ | |
+ if (v == RUBY_Qfalse) { | |
+ return 0; | |
+ } | |
+ if (v == RUBY_Qnil) { | |
+ return 0; | |
+ } | |
+ | |
+ if (rb_obj_is_kind_of(v, rb_cFalseClass) == RUBY_Qtrue) { | |
+ return 0; | |
+ } | |
+ | |
+ return 1; | |
+} | |
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h | |
index d983114e0a..7a2028de7b 100644 | |
--- a/include/ruby/ruby.h | |
+++ b/include/ruby/ruby.h | |
@@ -474,8 +474,8 @@ enum ruby_special_consts { | |
#define FLONUM_FLAG RUBY_FLONUM_FLAG | |
#endif | |
#define SYMBOL_FLAG RUBY_SYMBOL_FLAG | |
- | |
-#define RB_TEST(v) !(((VALUE)(v) & (VALUE)~RUBY_Qnil) == 0) | |
+int do_rb_test(VALUE v); | |
+#define RB_TEST(v) do_rb_test(v) | |
#define RB_NIL_P(v) !((VALUE)(v) != RUBY_Qnil) | |
#define RTEST(v) RB_TEST(v) | |
#define NIL_P(v) RB_NIL_P(v) | |
@@ -2061,10 +2061,10 @@ rb_class_of(VALUE obj) | |
if (obj == RUBY_Qtrue) return rb_cTrueClass; | |
if (RB_STATIC_SYM_P(obj)) return rb_cSymbol; | |
} | |
- else if (!RB_TEST(obj)) { | |
- if (obj == RUBY_Qnil) return rb_cNilClass; | |
- if (obj == RUBY_Qfalse) return rb_cFalseClass; | |
- } | |
+ | |
+ if (obj == RUBY_Qnil) return rb_cNilClass; | |
+ if (obj == RUBY_Qfalse) return rb_cFalseClass; | |
+ | |
return RBASIC(obj)->klass; | |
} | |
diff --git a/object.c b/object.c | |
index d37c923fa6..a9d7a79a0d 100644 | |
--- a/object.c | |
+++ b/object.c | |
@@ -4283,8 +4283,6 @@ InitVM_Object(void) | |
rb_define_method(rb_cFalseClass, "|", false_or, 1); | |
rb_define_method(rb_cFalseClass, "^", false_xor, 1); | |
rb_define_method(rb_cFalseClass, "===", rb_equal, 1); | |
- rb_undef_alloc_func(rb_cFalseClass); | |
- rb_undef_method(CLASS_OF(rb_cFalseClass), "new"); | |
/* | |
* An obsolete alias of +false+ | |
*/ | |
-- | |
2.17.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment