about summary refs log tree commit homepage
path: root/ext/kcar/extconf.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/kcar/extconf.rb')
-rw-r--r--ext/kcar/extconf.rb15
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/kcar/extconf.rb b/ext/kcar/extconf.rb
index 89ac586..b65846a 100644
--- a/ext/kcar/extconf.rb
+++ b/ext/kcar/extconf.rb
@@ -6,15 +6,20 @@ dir_config("kcar")
 have_macro("SIZEOF_OFF_T", "ruby.h") or check_sizeof("off_t", "sys/types.h")
 have_macro("SIZEOF_LONG", "ruby.h") or check_sizeof("long", "sys/types.h")
 
-uminus_dedupe = false
+message('checking if String#-@ (str_uminus) dedupes... ')
 begin
-  # oddly, opt_str_freeze is not always effective:
-  # https://bugs.ruby-lang.org/issues/13282
   a = -(%w(t e s t).join)
   b = -(%w(t e s t).join)
-  uminus_dedupe = a.object_id == b.object_id
+  if a.equal?(b)
+    $CPPFLAGS += " -DSTR_UMINUS_DEDUPE=1 "
+    message("yes\n")
+  else
+    $CPPFLAGS += " -DSTR_UMINUS_DEDUPE=0 "
+    message("no, needs Ruby 2.5+\n")
+  end
 rescue NoMethodError
+  $CPPFLAGS += " -DSTR_UMINUS_DEDUPE=0 "
+  message("no, String#-@ not available\n")
 end
-$CFLAGS += " -DSTR_UMINUS_DEDUPE=#{uminus_dedupe ? 1 : 0}"
 
 create_makefile("kcar_ext")