D
Daniel Berger
Hi all,
I found this snippet posted to handle doing const_get for nested
classes/modules:
def class_for(class_name)
names = class_name.split("::")
result = Object
names.each { |n|
result = result.const_get(n)
}
result
rescue NameError
nil
end
I'm trying to convert this to a C extension, but I'm having some
trouble:
static VALUE class_for(VALUE klass_name){
VALUE v_names, v_result;
ID id_split = rb_intern("split");
int i;
v_names = rb_funcall(klass_name, id_split, 1, rb_str_new2("::"));
v_result = rb_cObject;
return v_result;
}
With this code I get "uninitialized constant Class:null)
(NameError)".
It appears to be a problem with the first argument to rb_const_get().
I'm not sure what that value should be, but I also tried
TYPE(v_result) - which caused a segfault - and just v_result - which
resulted in a similar "uninitialized constant (null) (NameError)"
error.
What am I doing wrong here?
Thanks,
Dan
PS - Yes, I realize I'm not doing error handling in the C extension -
I'm not worried about that for now.
I found this snippet posted to handle doing const_get for nested
classes/modules:
def class_for(class_name)
names = class_name.split("::")
result = Object
names.each { |n|
result = result.const_get(n)
}
result
rescue NameError
nil
end
I'm trying to convert this to a C extension, but I'm having some
trouble:
static VALUE class_for(VALUE klass_name){
VALUE v_names, v_result;
ID id_split = rb_intern("split");
int i;
v_names = rb_funcall(klass_name, id_split, 1, rb_str_new2("::"));
v_result = rb_cObject;
for(i = 0; i said:ptr);
return v_result;
}
With this code I get "uninitialized constant Class:null)
(NameError)".
It appears to be a problem with the first argument to rb_const_get().
I'm not sure what that value should be, but I also tried
TYPE(v_result) - which caused a segfault - and just v_result - which
resulted in a similar "uninitialized constant (null) (NameError)"
error.
What am I doing wrong here?
Thanks,
Dan
PS - Yes, I realize I'm not doing error handling in the C extension -
I'm not worried about that for now.