From: Ryan Davis Date: 2011-11-08T17:48:47+09:00 Subject: Re: Compiling Ruby Inline C code - resolving errors It is generally best to send these types of questions to a more targeted medium, like writing the author directly or filing a support ticket on github. On Nov 8, 2011, at 00:04 , Martin Hansen wrote: > I am trying to get this Ruby inline C code http://pastie.org/2825882 to > work. The code works in vanilla C, but here I get errors and warnings. > What causes this error? > > ./backtrack_inline.rb:67: error: lvalue required as unary '&' operand This one took me a bit... #define StringValuePtr(v) rb_string_value_ptr(&(v)) and you're using it in: char* s = StringValuePtr(rb_iv_get(self, "@seq")); so you're essentially doing: char* s = rb_string_value_ptr(&rb_iv_get(self, "@seq")); which you can't really do in C. > Also, why do I get the following error? > > ./backtrack_inline.rb:73: error: too few arguments to function > 'backtrack' Because you're passing too few arguments to the function (6 to 7 arity function): static VALUE backtrack(VALUE self, VALUE _ss, VALUE _s, VALUE _p, VALUE _mm, VALUE _ins, VALUE _del) vs: backtrack(ss, s + 1, p + 1, mm - 1, ins, del))) Since you're not actually using self for anything, there is no reason for this to be a registered method. You might want to add this to the prefix section. > Inspecting the resulting C code ( http://pastie.org/2826036) I fail to > see anything wrong with the arguments. But I do also get the following > warnings: > > ./backtrack_inline.rb:73: warning: passing argument 1 of 'backtrack' > makes integer from pointer without a cast > ./backtrack_inline.rb:73: warning: passing argument 2 of 'backtrack' > makes integer from pointer without a cast > ./backtrack_inline.rb:73: warning: passing argument 3 of 'backtrack' > makes integer from pointer without a cast This is simply because of the above lack of self, I assume. I changed your code (with the above) like so: # above w/ prefixens builder.add_static "id_seq", 'rb_intern("@seq")', "ID" # in patscan: VALUE seq = rb_ivar_get(self, id_seq); char* s = StringValuePtr(seq); and got '14' as the output (off by 1?).