public
Created

rbtree 2.1 compat

  • Download Gist
rbtree.patch
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/extconf.rb b/extconf.rb
index 9f6f0c7..674eb08 100644
--- a/extconf.rb
+++ b/extconf.rb
@@ -9,6 +9,7 @@ have_header('ruby/st.h')
have_func('rb_exec_recursive', 'ruby.h')
have_func('rb_exec_recursive_paired', 'ruby.h')
have_func('rb_proc_lambda_p', 'ruby.h')
+have_func('rb_obj_hide', 'ruby.h')
if Hash.method_defined?(:flatten)
$defs << '-DHAVE_HASH_FLATTEN'
end
diff --git a/rbtree.c b/rbtree.c
index 1f10fea..a7e0d5b 100644
--- a/rbtree.c
+++ b/rbtree.c
@@ -752,7 +752,11 @@ static void
copy_dict(VALUE src, VALUE dest, dict_comp_t cmp_func, VALUE cmp_proc)
{
VALUE temp = rbtree_alloc(CLASS_OF(dest));
+#ifdef HAVE_RB_OBJ_HIDE
+ rb_obj_hide(temp);
+#else
RBASIC(temp)->klass = 0;
+#endif
DICT(temp)->dict_compare = cmp_func;
CMP_PROC(temp) = cmp_proc;
@@ -1289,7 +1293,11 @@ rbtree_to_hash(VALUE self)
hash = rb_hash_new();
rbtree_for_each(self, to_hash_i, (void*)hash);
+#ifdef RHASH_SET_IFNONE
+ RHASH_SET_IFNONE(hash, IFNONE(self));
+#else
RHASH_IFNONE(hash) = IFNONE(self);
+#endif
if (FL_TEST(self, RBTREE_PROC_DEFAULT))
FL_SET(hash, HASH_PROC_DEFAULT);
OBJ_INFECT(hash, self);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.