Skip to content

Commit

Permalink
commit WIP to prevent accidental lose
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Mar 1, 2013
1 parent 3b52bef commit b4b67e6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/binary/Builtin.cc
Expand Up @@ -12,18 +12,17 @@
#include "Y2YCPTypeConv.h"
#include "Y2RubyTypeConv.h"
#include "RubyLogger.h"
#include "YRuby.h"

static VALUE rb_mSCR;
static VALUE rb_mWFM;
static VALUE rb_mYCP;
static SCR scr;
static ScriptingAgent scra;
static WFM wfm;

extern "C" {

static VALUE call_builtin(const string &qualified_name, int argc, VALUE *argv)
{
YRuby::yRuby();
extern StaticDeclaration static_declarations;

declaration_t *bi_dt = static_declarations.findDeclaration(qualified_name.c_str());
Expand All @@ -50,7 +49,8 @@ extern "C" {
if (err_tp != NULL)
rb_raise(rb_eRuntimeError,"Error when finalizing builtin call: %s",err_tp->toString().c_str());

return ycpvalue_2_rbvalue(bi_call.evaluate(false));
VALUE result = ycpvalue_2_rbvalue(bi_call.evaluate(false));
return result;
}

static VALUE
Expand Down
17 changes: 17 additions & 0 deletions src/binary/Y2CCRuby.cc
Expand Up @@ -24,13 +24,30 @@ as published by the Free Software Foundation; either version
#define y2log_component "Y2Ruby"
#include <ycp/y2log.h>

#include "scr/SCR.h"
#include "scr/ScriptingAgent.h"
#include "wfm/WFM.h"

#include "YRuby.h"

// ensure that WFM is loaded before we load ruby environment
//static WFM wfm;
//static ScriptingAgent sa;
//static SCR scr;

// This is very important: We create one global variable of
// Y2CCRuby. Its constructor will register it automatically to
// the Y2ComponentBroker, so that will be able to find it.
// This all happens before main() is called!

Y2CCRuby g_y2ccruby;

Y2CCRuby::Y2CCRuby() : Y2ComponentCreator( Y2ComponentBroker::BUILTIN ),
cruby (0)
{
YRuby::yRuby();
}

Y2Component *Y2CCRuby::provideNamespace (const char *name)
{
y2debug ("Y2CCRuby::provideNamespace %s", name);
Expand Down
3 changes: 1 addition & 2 deletions src/binary/Y2CCRuby.h
Expand Up @@ -41,8 +41,7 @@ class Y2CCRuby : public Y2ComponentCreator
/**
* Creates a Ruby component creator
*/
Y2CCRuby() : Y2ComponentCreator( Y2ComponentBroker::BUILTIN ),
cruby (0) {};
Y2CCRuby();

~Y2CCRuby () {
if (cruby)
Expand Down
14 changes: 9 additions & 5 deletions src/binary/Y2YCPTypeConv.cc
Expand Up @@ -63,18 +63,22 @@ extern "C" VALUE
ycp_term_to_rb_term( YCPTerm ycpterm )
{
int error = 0;
rb_protect( (VALUE (*)(VALUE))rb_require, (VALUE) "ycp/term",&error);
// rb_protect( (VALUE (*)(VALUE))rb_require, (VALUE) "ycp/term",&error);
rb_require("ycp/term");
if (error)
{
y2internal("Cannot found ycp/term module.");
return Qnil;
}

VALUE ycp = rb_define_module("YCP");
VALUE cls = rb_const_get(ycp, rb_intern("Term"));
VALUE params = ycpvalue_2_rbvalue(ycpterm->args());
if (params == Qnil)
params = rb_ary_new2(1);
//we need to pass array of parameters to work properly with unlimited params in ruby
rb_ary_unshift(cls, rb_intern(ycpterm->name().c_str()));
return rb_class_new_instance(RARRAY_LEN(params), &params,cls);
rb_ary_unshift(params, ID2SYM(rb_intern(ycpterm->name().c_str())));
return rb_class_new_instance(RARRAY_LEN(params), RARRAY_PTR(params),cls);
}

/**
Expand Down Expand Up @@ -136,8 +140,8 @@ ycpvalue_2_rbvalue( YCPValue ycpval )
else if (ycpval->isList())
{
VALUE rblist;
rblist = rb_ary_new();
YCPList list = ycpval->asList();
rblist = rb_ary_new2(list.size());
//y2internal("list size %d\n",list.size());
for (int i=0; i < list.size(); i++)
{
Expand All @@ -148,7 +152,7 @@ ycpvalue_2_rbvalue( YCPValue ycpval )
else if (ycpval->isSymbol())
{
YCPSymbol symbol = ycpval->asSymbol();
return rb_intern(symbol->symbol_cstr());
return ID2SYM(rb_intern(symbol->symbol_cstr()));
}
else if (ycpval->isExternal())
{
Expand Down
5 changes: 3 additions & 2 deletions src/binary/YRuby.cc
Expand Up @@ -69,6 +69,7 @@ YRuby::YRuby()

VALUE ycp_references = Data_Wrap_Struct(rb_cObject, gc_mark, gc_free, & value_references_from_ycp);
rb_global_variable(&ycp_references);
// rb_gc_disable();
}

void YRuby::gc_mark(void *object)
Expand Down Expand Up @@ -132,7 +133,7 @@ YRuby::loadModule( YCPList argList )
YRuby::yRuby();
string module_path = argList->value(1)->asString()->value();
int error = 0;
rb_protect( (VALUE (*)(VALUE))rb_require, (VALUE) module_path.c_str(), &error);
rb_protect( (VALUE (*)(VALUE))rb_require, (VALUE) strdup(module_path.c_str()), &error);
if (error)
return YCPError( "Ruby::loadModule() / Can't load ruby module '" + module_path + "'" );
return YCPVoid();
Expand All @@ -152,7 +153,7 @@ protected_call(VALUE args)
YCPValue YRuby::callInner (string module_name, string function,
YCPList argList, constTypePtr wanted_result_type)
{
RUBY_INIT_STACK // bnc#708059
//RUBY_INIT_STACK // bnc#708059
VALUE module = y2ruby_nested_const_get(module_name);
if (module == Qnil)
{
Expand Down
4 changes: 3 additions & 1 deletion src/binary/YRubyNamespace.cc
Expand Up @@ -150,11 +150,13 @@ class VariableSymbolEntry : public SymbolEntry

YCPValue value () const
{
return YRuby::yRuby()->callInner ( module_name,
YCPValue result = YRuby::yRuby()->callInner ( module_name,
name(),
YCPList(),
type()
);
y2milestone("Called value on %s::%s and return %s",module_name.c_str(), name(), result->toString().c_str());
return result;
}

};
Expand Down

0 comments on commit b4b67e6

Please sign in to comment.