Created
August 22, 2013 06:20
-
-
Save djberg96/6303793 to your computer and use it in GitHub Desktop.
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
// bar.c | |
#include <ruby.h> | |
static VALUE bar_init(int argc, VALUE* argv, VALUE self){ | |
VALUE v_func, v_proto, v_return, v_dll, v_array; | |
int size; | |
rb_scan_args(argc, argv, "13", &v_func, &v_proto, &v_return, &v_dll); | |
v_array = rb_str_split(v_proto, ""); | |
// Segfault or bad behavior on Ruby 2.x | |
if(RARRAY_LEN(v_array) > 5) | |
rb_raise(rb_eArgError, "too many parameters: %li", RARRAY_LEN(v_array)); | |
size = RARRAY_LEN(v_array); | |
printf("Size: %li\n", size); | |
return self; | |
} | |
void Init_bar(){ | |
VALUE cBar; | |
cBar = rb_define_class("Bar", rb_cObject); | |
rb_define_method(cBar, "initialize", bar_init, -1); | |
} | |
# extconf.rb | |
require 'mkmf' | |
create_makefile('bar') | |
# test.rb | |
$:.unshift Dir.pwd | |
require 'bar' | |
Bar.new('test', 's' * 6, 'x', 'whatever') | |
# Ruby 1.9.x => test.rb:4:in `initialize': too many parameters: 6 (ArgumentError) | |
# Ruby 2.x => Segfault |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment