Skip to content

Commit

Permalink
more replacements of rb_funcall with direct calls of C api
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 28, 2013
1 parent 8ad8527 commit 8725521
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/binary/Y2RubyTypeConv.cc
Expand Up @@ -76,11 +76,10 @@ static YCPMap rbhash_2_ycpmap( VALUE value )
static YCPList rbarray_2_ycplist( VALUE value )
{
YCPList list;
int n = NUM2LONG(rb_funcall(value, rb_intern("size"), 0));
int n = RARRAY_LEN(value);
for ( int i=0; i<n; ++i)
{
VALUE element = rb_funcall(value, rb_intern("[]"), 1, INT2NUM(i));
list.add( rbvalue_2_ycpvalue(element) );
list.add(rbvalue_2_ycpvalue(*(RARRAY_PTR(value)+i)));
}
return list;
}
Expand Down Expand Up @@ -185,8 +184,7 @@ rbvalue_2_ycpvalue( VALUE value )
break;
default:
{
VALUE cname = rb_funcall(rb_funcall(value, rb_intern("class"), 0), rb_intern("to_s"), 0);
const char *class_name = StringValuePtr(cname);
const char *class_name = rb_obj_classname(value);
if ( !strcmp(class_name, "YCP::Path"))
{
return rbpath_2_ycppath(value);
Expand Down
7 changes: 4 additions & 3 deletions src/binary/Y2YCPTypeConv.cc
Expand Up @@ -55,7 +55,8 @@ ycp_path_to_rb_path( YCPPath ycppath )

VALUE ycp = rb_define_module("YCP");
VALUE cls = rb_const_get(ycp, rb_intern("Path"));
return rb_funcall(cls, rb_intern("new"), 1, rb_str_new2(ycppath->asString()->value().c_str()));
VALUE value = rb_str_new2(ycppath->asString()->value().c_str());
return rb_class_new_instance(1,&value,cls);
}

extern "C" VALUE
Expand All @@ -72,8 +73,8 @@ ycp_term_to_rb_term( YCPTerm ycpterm )
if (params == Qnil)
params = rb_ary_new2(1);
//we need to pass array of parameters to work properly with unlimited params in ruby
rb_funcall(cls,rb_intern("unshift"), 1, rb_intern(ycpterm->name().c_str()));
return rb_funcall3(cls, rb_intern("new"),RARRAY_LEN(params), &params);
rb_ary_unshift(cls, rb_intern(ycpterm->name().c_str()));
return rb_class_new_instance(RARRAY_LEN(params), &params,cls);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/binary/YRuby.cc
Expand Up @@ -56,7 +56,7 @@ void inject_last_exception_method(VALUE& module,const string& message, const str
code += "\ndef self.last_exception\n'";
code += m;
code += "'\nend\nend";
rb_funcall(module, rb_intern("eval"), 1, rb_str_new2(code.c_str()));
rb_eval_string(code.c_str());
}

YRuby * YRuby::_yRuby = 0;
Expand Down Expand Up @@ -204,7 +204,7 @@ YCPValue YRuby::callInner (string module_name, string function,
VALUE exception = rb_gv_get("$!"); /* get last exception */
VALUE reason = rb_funcall(exception, rb_intern("message"), 0 );
VALUE trace = rb_gv_get("$@"); /* get last exception trace */
VALUE backtrace = rb_funcall(trace, rb_intern("join"), 1, rb_str_new("\n\t", 2));
VALUE backtrace = rb_ary_join(trace, rb_str_new("\n\t", 2));
y2error("%s.%s failed\n%s\n\t%s", module_name.c_str(), function.c_str(), StringValuePtr(reason),StringValuePtr(backtrace));
//workaround if last_exception failed, then return always string with message
if(function == "last_exception") //TODO constantify last_exception
Expand Down

0 comments on commit 8725521

Please sign in to comment.