1
votes

I need to extend my ruby code using C code. I have this function on my c file:

char * generateIt(char *valor) {
  struct NESSIEstruct w;
  u8 digest[DIGESTBYTES];

  int i;
  for(i=0; valor[i]!='\0'; ++i);
  int sizeo = i;

  NESSIEinit(&w);
  NESSIEadd((u8*)valor, 8*sizeo, &w);
  NESSIEfinalize(&w, digest);
  return displayIt(digest, DIGESTBYTES);
}

And to make it available to Ruby, at the same file, I have this:

void
Init_whirlpool(){
  rb_mWhirlpool = rb_define_module("Whirlpool");
  rb_cClass = rb_define_class_under(rb_mWhirlpool, "Class", rb_cObject);
  rb_define_method(rb_cClass, "generate", generateIt, 1);
}

But, when I try do run: make, I get this warning:

MacBook-Pro-de-Patricio:whirlpool psantos$ make compiling whirlpool.c whirlpool.c:2021:43: warning: incompatible pointer types passing 'char *(char )' to parameter of type 'VALUE ()()' [-Wincompatible-pointer-types] rb_define_method(rb_cClass, "generate", generateIt, 1); ^~~~~~~~~~ /Users/psantos/.rvm/rubies/ruby-2.0.0-p598/include/ruby-2.0.0/ruby/ruby.h:1290:48: note: passing argument to parameter here void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int); ^ 1 warning generated.

Error image: (to be more clear)

enter image description here

How can I solve this?

1

1 Answers

2
votes

rb_define_method() takes a Ruby VALUE type.

void rb_define_method(
    VALUE klass, 
    const char *name, 
    VALUE (*func)(ANYARGS), 
    int argc
);