Permalink
Browse files

ext/libcdb/ruby_cdb_reader.[ch]: Remove usage of RARRAY_PTR.

<https://bugs.ruby-lang.org/issues/8399>

NOTE: Dropped support for Ruby 1.8.7 in the process due to switching to rb_block_call instead of rb_iterate (which is obsolete since 1.9).
  • Loading branch information...
1 parent eb67941 commit cf1d3ac2954dd9453e20a75d9b28fce4d8107314 @blackwinter committed Jun 11, 2013
Showing with 25 additions and 42 deletions.
  1. +4 −5 README
  2. +2 −1 Rakefile
  3. +8 −17 ext/libcdb/ruby_cdb_reader.c
  4. +11 −19 ext/libcdb/ruby_cdb_reader.h
View
9 README
@@ -63,8 +63,7 @@ creating and reading {constant databases}[http://cr.yp.to/cdb.html].
== PREREQUISITES
<b></b>
-* Ruby 1.8.7+ or 1.9+ (see {below}[rdoc-label:label-SUPPORTED+PLATFORMS]
- for details)
+* Ruby 1.9+ (see {below}[rdoc-label:label-SUPPORTED+PLATFORMS] for details)
* TinyCDB[http://www.corpit.ru/mjt/tinycdb.html] headers (not needed when
installing the fat binary gem on Windows)
@@ -76,9 +75,9 @@ creating and reading {constant databases}[http://cr.yp.to/cdb.html].
== SUPPORTED PLATFORMS
<b></b>
-Linux:: MRI 1.8, 1.9 & 2.0 (Tested on 64-bit Ubuntu GNU/Linux with 1.8.7p371,
- 1.9.2p323, 1.9.3p286 and 2.0.0p119)
-Windows:: MRI 1.9 only (Tested on 32-bit Windows XP with 1.9.2p290 and 1.9.3p194)
+Linux:: MRI 1.9 & 2.0 (Tested on 64-bit Ubuntu GNU/Linux with 1.9.2p323,
+ 1.9.3p286 and 2.0.0p119)
+Windows:: MRI 1.9 (Tested on 32-bit Windows XP with 1.9.2p290 and 1.9.3p194)
== LINKS
View
3 Rakefile
@@ -25,7 +25,8 @@ begin
:extension => {
:cross_config_options => cco,
:ruby_versions => RUBY_VERSION
- }
+ },
+ required_ruby_version: '>= 1.9.2'
}
}}
rescue LoadError => err
View
25 ext/libcdb/ruby_cdb_reader.c
@@ -128,11 +128,6 @@ rcdb_reader_yield_dump2(VALUE val, VALUE ary) {
return rb_yield(rcdb_reader_dump_pair(rb_ary_entry(ary, 0), val));
}
-RCDB_READER_DEFINE_CALL(each)
-RCDB_READER_DEFINE_CALL(each_key)
-RCDB_READER_DEFINE_CALL(each_value)
-RCDB_READER_DEFINE_CALL(each_dump)
-
/*
* call-seq:
* reader.each { |key, val| ... } -> reader
@@ -187,19 +182,16 @@ rcdb_reader_each(int argc, VALUE *argv, VALUE self) {
*/
static VALUE
rcdb_reader_each_dump(int argc, VALUE *argv, VALUE self) {
- VALUE key, args = rb_ary_new3(1, self), ary = rb_ary_new();
- VALUE (*block)(ANYARGS) = rcdb_reader_yield_dump;
+ VALUE key;
RCDB_RETURN_ENUMERATOR(self, argc, argv, 1);
if (rb_scan_args(argc, argv, "01", &key) == 1 && !NIL_P(key)) {
- rb_ary_push(ary, key);
- rb_ary_push(args, key);
-
- block = rcdb_reader_yield_dump2;
+ RCDB_READER_ITERATE0(each, yield_dump2, rb_ary_new3(1, key))
+ }
+ else {
+ RCDB_READER_ITERATE1(each, yield_dump, rb_ary_new())
}
-
- rb_iterate(rcdb_reader_call_each, args, block, ary);
return self;
}
@@ -262,10 +254,9 @@ rcdb_reader_each_value(VALUE self) {
*/
static VALUE
rcdb_reader_fetch(VALUE self, VALUE key) {
- RCDB_READER_ITERATE0(each, iter_push,
- rb_ary_new(), rb_ary_new3(2, self, key))
-
- return arg;
+ VALUE ary = rb_ary_new();
+ RCDB_READER_ITERATE0(each, iter_push, ary)
+ return ary;
}
/*
View
30 ext/libcdb/ruby_cdb_reader.h
@@ -3,28 +3,20 @@
#define RCDB_READER_GET(obj, ptr) RCDB_GET_STRUCT(read, cdb, obj, ptr)
-#define RCDB_READER_DEFINE_CALL(iter) \
-static VALUE \
-rcdb_reader_call_##iter(VALUE args) {\
- VALUE self = rb_ary_shift(args);\
- return rb_funcall2(self, rb_intern(#iter),\
- RARRAY_LEN(args), RARRAY_PTR(args));\
-}
-
-#define RCDB_READER_ITERATE0(method, block, arg1, arg2) \
- VALUE arg = arg1;\
- rb_iterate(rcdb_reader_call_##method, arg2, rcdb_reader_##block, arg);
+#define RCDB_READER_ITERATE0(method, block, arg) \
+ rb_block_call(self, rb_intern(#method), 1, &key, rcdb_reader_##block, arg);
-#define RCDB_READER_ITERATE1(method, block, arg1) \
- RCDB_READER_ITERATE0(method, block, arg1, rb_ary_new3(1, self))
+#define RCDB_READER_ITERATE1(method, block, arg) \
+ VALUE ret = arg;\
+ rb_block_call(self, rb_intern(#method), 0, 0, rcdb_reader_##block, ret);
-#define RCDB_READER_ITERATE(method, block, arg1) \
- RCDB_READER_ITERATE1(method, block, arg1)\
- return arg;
+#define RCDB_READER_ITERATE(method, block, arg) \
+ RCDB_READER_ITERATE1(method, block, arg)\
+ return ret;
-#define RCDB_READER_ITERATE_ARY(method, block, arg1) \
- RCDB_READER_ITERATE1(method, block, arg1)\
- return rb_ary_entry(arg, 0);
+#define RCDB_READER_ITERATE_ARY(method, block, arg) \
+ RCDB_READER_ITERATE1(method, block, arg)\
+ return rb_ary_entry(ret, 0);
#define RCDB_READER_BREAK_EQUAL(val, ret) \
if (RTEST(rb_funcall(val, rb_intern("=="), 1, rb_ary_entry(ary, 1)))) {\

0 comments on commit cf1d3ac

Please sign in to comment.