この C 拡張機能を Rails 環境の外で実行すると機能するが、Rails 内で実行するとスタック ダンプが発生するという問題がいくつかあります。
次のエラー メッセージが表示されます。
NoMethodError Exception: undefined method `evaluate' for #<String:0x00000103557db0>
これはおそらく、EV::Counters 評価関数内で行っている呼び出し、呼び出している 3 つのインスタンスに存在する「評価」関数を参照しています。
奇妙なことに、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);
}