Question

Je veux utiliser rb_require avec rb_protect, comme dans l'exemple suivant:

int error;
rb_protect( (VALUE (*)(VALUE))rb_require, (VALUE) "./test", &error);

Mais quand je le compile, je reçois cette erreur:

passing argument 1 of ‘rb_protect’ from incompatible pointer type [enabled by default]
/usr/include/ruby-1.9.1/ruby/intern.h:357:7: note: expected ‘VALUE (*)(VALUE)’ but argument is of type ‘VALUE (*)(VALUE,  VALUE)’

Après avoir recherché sur Google pour voir comment utiliser rb_require avec rb_protect, j'ai essayé:

int error;
rb_protect( RUBY_METHOD_FUNC(rb_require), (VALUE) "./test", &error);

ou

VALUE require_wrap(VALUE arg)
{
return rb_require("./test");
}
/*in main:*/
rb_protect( require_wrap, 0, & error);

Mais j'ai toujours la même erreur.Cette erreur n'arrête pas la compilation mais le segfault binaire lorsque je le lance alors que tout fonctionne sans le RB_Protect.

__ éditer __

Il y avait une erreur dans mon fichier source.En fait, toutes les solutions que j'ai testées fonctionnent bien:

int error;
rb_protect( (VALUE (*)(VALUE))rb_require, (VALUE) "./test", &error);

ou

int error;
rb_protect( RUBY_METHOD_FUNC(rb_require), (VALUE) "./test", &error);

ou

VALUE require_wrap(VALUE arg)
{
  return rb_require("./test");
}
/*in main:*/
rb_protect( require_wrap, 0, & error);

merci

Était-ce utile?

La solution

solutions qui fonctionne bien:

int error;
rb_protect( (VALUE (*)(VALUE))rb_require, (VALUE) "./test", &error);

ou

int error;
rb_protect( RUBY_METHOD_FUNC(rb_require), (VALUE) "./test", &error);

ou

VALUE require_wrap(VALUE arg)
{
  return rb_require("./test");
}
/*in main:*/
rb_protect( require_wrap, 0, & error);

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top