Created
November 23, 2013 00:52
-
-
Save tmm1/7609371 to your computer and use it in GitHub Desktop.
rbtree 2.1 compat
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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment