Domanda

Voglio usare rb_require con rb_protect, come nell'esempio seguente:

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

Ma quando lo compilo, ottengo questo errore:

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)’
.

Dopo aver cercato su Google per vedere come usare rb_require con rb_protect, ho provato:

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

o

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

Ma ottengo sempre lo stesso errore.Questo errore non interrompe la compilation ma il binario Segfault quando lo lancio mentre tutto funziona senza RB_PROTECT.

__ modifica __

Si è verificato un errore nel mio file sorgente.Infatti tutte le soluzioni che ho testato funziona bene:

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

o

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

o

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

Grazie

È stato utile?

Soluzione

Soluzioni che funziona bene:

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

o

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

o

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top