Skip to content

Commit

Permalink
make native extension compilable under rubinius
Browse files Browse the repository at this point in the history
  • Loading branch information
funny-falcon committed Aug 8, 2012
1 parent 3682830 commit c60920f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ext/bin_utils/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
if RUBY_ENGINE == 'ruby'
if RUBY_ENGINE == 'ruby' || RUBY_ENGINE == 'rbx'
require 'mkmf'
# rubinius has no rb_str_drop_bytes
have_func('rb_str_drop_bytes')
create_makefile("native_bin_utils")
else
File.open(File.dirname(__FILE__) + "/Makefile", 'w') do |f|
Expand Down
14 changes: 14 additions & 0 deletions ext/bin_utils/native.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ typedef unsigned long long uint64_t;

ID rshft;
ID band;
#ifndef HAVE_RB_STR_DROP_BYTES
/* rubinius has no rb_str_drop_bytes */
ID aset;
static VALUE
rb_str_drop_bytes(VALUE str, long bytes)
{
VALUE args[3] = {INT2FIX(0), INT2FIX(bytes), rb_str_new(0, 0)};
rb_funcall2(str, aset, 3, args);
return str;
}
#endif

static long
check_size(long i, long strlen, long ilen)
Expand Down Expand Up @@ -1589,6 +1600,9 @@ Init_native_bin_utils()
VALUE mod_native = rb_define_module_under(mod_bin_utils, "Native");
rshft = rb_intern(">>");
band = rb_intern("&");
#ifndef HAVE_RB_STR_DROP_BYTES
aset = rb_intern("[]=");
#endif

rb_define_method(mod_native, "get_ber", rb_get_ber, -1);
rb_define_method(mod_native, "get_int8", rb_get_int8, -1);
Expand Down

0 comments on commit c60920f

Please sign in to comment.