简体   繁体   English

我在这个 C 扩展中引用我的实例的方式有什么问题吗?

[英]Is there something wrong with how I'm referencing my instances in this C extension?

I'm having some issues where when if I run this C extension outside of a Rails environment it works, but when I run inside Rails it gives me a stack dump.我遇到了一些问题,如果我在 Rails 环境之外运行这个 C 扩展,它可以工作,但是当我在 Rails 中运行时,它会给我一个堆栈转储。

I get this error message:我收到此错误消息:

NoMethodError Exception: undefined method `evaluate' for #<String:0x00000103557db0>

This is presumably referring to the calls I am making within the EV::Counters evaluate function, to the "evaluate" functions that exist in the three instances that I am calling.这大概是指我在 EV::Counters 中进行的调用评估 function,以及我正在调用的三个实例中存在的“评估”函数。

Strangely valgrind is not giving me any errors.奇怪的是 valgrind 没有给我任何错误。 But I think there is something basic I might be doing wrong with how I reference my instances?但是我认为我在引用实例的方式上可能做错了一些基本的事情?

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);

}

What I needed to do was to store the instances as instance variables, like:我需要做的是将实例存储为实例变量,例如:

VALUE rPairCounterInstance = rb_class_new_instance(0, NULL, PairCounter);   
rb_ivar_set(self, rb_intern("@pair"), rPairCounterInstance);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 C 语法有问题吗? - Is there something wrong with my C syntax? 我的搜索功能无法正常工作,因为我的if语句出了点问题,并且我正在使用链表 - My search function is not working because there is something wrong with my if statement,and I'm using linked list 在C中遇到错误,“ _的类型冲突”。很抱歉再次询问,我不是很明白,或者是其他错误 - Getting error, “conflicting types for '_'” in C. Sorry to ask this again, I'm either not understanding or something else is wrong 为什么我的C扩展没有创建唯一的实例? - Why is my C extension not creating unique instances? 我正在尝试利用缓冲区溢出,我做错了什么? - I'm trying to exploit a bufferoverflow, am I doing something wrong? 这是GMP 4.1.2中的错误,还是我做错了什么? - Is this a bug in GMP 4.1.2 or is it something I'm doing wrong? 我正在尝试制作字符串解析器,但出了点问题 - I'm trying to make string parser but something is going wrong 我试图在 C 中创建一个队列 ADT,但我的代码有问题……有人可以解决这个问题吗? - I was trying to create a Queue ADT in C but something is wrong in my code… can Anyone Fix this? 为什么我从ruby数组中提取的值到我的c扩展名错了? - Why are the values I am pulling from my ruby array to my c extension wrong? 如何限制C程序的实例数? - How can I restrict the number of instances of my C program?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM