我遇到了一些问题,如果我在 Rails 环境之外运行这个 C 扩展,它可以工作,但是当我在 Rails 内部运行时,它会给我一个堆栈转储。
我收到此错误消息:
NoMethodError Exception: undefined method `evaluate' for #<String:0x00000103557db0>
这大概是指我在 EV::Counters 评估函数中进行的调用,以及我正在调用的三个实例中存在的“评估”函数。
奇怪的是 valgrind 没有给我任何错误。但是我认为我在引用实例的方式上可能做错了一些基本的事情?
VALUE rFlushInstance, rPairCounterInstance, rStraightInstance;
static VALUE
evaluate(VALUE self, VALUE val, VALUE suit, VALUE index)
{
rb_funcall(rFlushInstance, rb_intern("evaluate"), 3, val, suit, index);
rb_funcall(rStraightInstance, rb_intern("evaluate"), 2, val, index);
rb_funcall(rPairCounterInstance, rb_intern("evaluate"), 2, val, index);
return Qnil;
}
VALUE EV;
void Init_counters()
{
EV = rb_define_module("EV");
VALUE Counters = rb_define_class_under(EV, "Counters", rb_cObject);
init_pair_counter();
init_straight();
init_flush();
VALUE Flush = rb_const_get(EV, rb_intern("Flush"));
VALUE PairCounter = rb_const_get(EV, rb_intern("PairCounter"));
VALUE Straight = rb_const_get(EV, rb_intern("Straight"));
rFlushInstance = rb_class_new_instance(0, NULL, Flush);
rStraightInstance = rb_class_new_instance(0, NULL, Straight);
rPairCounterInstance = rb_class_new_instance(0, NULL, PairCounter);
rb_define_method(Counters, "initialize", initialize_counters, 2);
rb_define_method(Counters, "evaluate", evaluate, 3);
}