Ejemplo n.º 1
0
static void rpmrubyFini(void * _ruby)
        /*@globals fileSystem @*/
        /*@modifies *_ruby, fileSystem @*/
{
    rpmruby ruby = _ruby;

    /* XXX FIXME: 0x40000000 => xruby.c wrapper without interpreter. */
    if (ruby->flags & 0x40000000) {
	ruby->main_coroutine_lock = yarnFreeLock(ruby->main_coroutine_lock);
	ruby->ruby_coroutine_lock = yarnFreeLock(ruby->ruby_coroutine_lock);
	ruby->zlog = rpmzLogDump(ruby->zlog, NULL);
	ruby->stack = _free(ruby->stack);
	ruby->nstack = 0;
	_rpmrubyI = NULL;
    } else {
#if defined(WITH_RUBYEMBED)
	ruby_finalize();
	ruby_cleanup(0);
#endif
    }
    ruby->I = NULL;
    ruby->flags = 0;
    ruby->av = argvFree(ruby->av);
    ruby->ac = 0;
}
Ejemplo n.º 2
0
static void destroy_rb(language_interpreter_t* li)
{
    rb_internal_t*rb = (rb_internal_t*)li->internal;
    if(--rb_reference_count == 0) {
        ruby_finalize();
    }
}
Ejemplo n.º 3
0
int initrb_start(int argc, char **argv, initrb_boot_fn_t boot) {
    int ret = 0;

    {
        /* Initialize the stack */
        RUBY_INIT_STACK;

        /* Initialize the interpreter */
        ruby_init();

        /* Initialize the loadpath */
        ruby_init_loadpath();

        /* We're initrb */
        ruby_script("initrb");

        /* Set the argv */
        ruby_set_argv(argc, argv);

        /* Boot statics */
        initrb_boot_statics();

        /* Run */
        ret = boot(argc, argv);

        /* Finalize the interpreter */
        ruby_finalize();
    }

    return ret;
}
Ejemplo n.º 4
0
static void run()
{
    VALUE stack_start;
    VALUE code;
    void Init_stack _((VALUE*));

    Init_stack(&stack_start);
    code = compile(eruby_filename);
    if (eruby_sync) {
	print_headers(-1);
    }
    else {
	replace_stdout();
    }
    code = eval(code, eruby_filename);
    if (eruby_mode == MODE_FILTER &&
	(RTEST(ruby_debug) || RTEST(ruby_verbose))) {
	print_generated_code(stderr, code, 0);
    }
    rb_exec_end_proc();
    if (!eruby_sync) {
	flush_buffer();
    }
    ruby_finalize();
}
Ejemplo n.º 5
0
DWORD WINAPI rh_thread_proc(LPVOID lpParam)
{
  DWORD dwWaitResult;
  int must_exit = 0;

#ifdef DEBUG_THREADS
  rh_log("RubyHoldem thread %d starting\n", GetCurrentThreadId());
#endif

  ruby_init();
  rh_safe_call("rh_load_init_script", (rh_function)rh_init_module, Qnil);
  
  while (!must_exit)
  {
#ifdef DEBUG_THREADS
    rh_log("RubyHoldem thread %d waiting for event...\n", GetCurrentThreadId());
#endif

    dwWaitResult = WaitForSingleObject(rh_event_job, INFINITE);
  
    switch (dwWaitResult) 
    {
      // Event object was signaled
      case WAIT_OBJECT_0: 
#ifdef DEBUG_THREADS
        rh_log("Event occured in RubyHoldem thread %d\n", GetCurrentThreadId());
#endif
        switch(rh_event_type)
        {
          case RH_EXIT:
#ifdef DEBUG_THREADS
            rh_log("Event is RH_EXIT\n");
#endif
            must_exit = 1;
            break;
          case RH_PROCESS_MESSAGE:
#ifdef DEBUG_THREADS
            rh_log("Event is RH_PROCESS_MESSAGE\n");
#endif
            rh_process_message();
            break;
        }
        break;

      // An error occurred
      default:
        rh_log("RubyHoldem thread: Wait error (%d)\n", GetLastError());
        return 0; 
    }
    rh_job_done();
  }
  ruby_finalize();
#ifdef DEBUG_THREADS
  rh_log("RubyHoldem thread %d finished\n", GetCurrentThreadId());
#endif

  return 1;
}
Ejemplo n.º 6
0
/* cleanup interpreter */
void shutdown_myruby(void)
{
  ruby_cleanup(0);
#if USE_RUBYVERSION < 19
  ruby_finalize();
#else
  /* segfaults with ruby19 */
#endif
}
Ejemplo n.º 7
0
static void * rpmrubyThread(void * _ruby)
{
    rpmruby ruby = _ruby;
    rpmzLog zlog = ruby->zlog;
    int i;

    Trace((zlog, "-- %s: running", __FUNCTION__));

    _rpmruby_ruby_to_main(ruby, Qnil);

    for (i = 0; i < 2; i++)
        _rpmruby_ruby_to_main(ruby, Qnil);

    {
	VALUE variable_in_this_stack_frame;
	uint8_t * b = ruby->stack;
	uint8_t * e = b + ruby->nstack;

	/* Start up the ruby interpreter. */
	Trace((zlog, "-- %s: interpreter starting", __FUNCTION__));
	ruby_sysinit(&ruby->ac, (char ***) &ruby->av);

        ruby_bind_stack((VALUE *)b, (VALUE *)e);

	ruby_init_stack(&variable_in_this_stack_frame);
        ruby_init();
	ruby_init_loadpath();

        /* allow Ruby script to relay */
        rb_define_module_function(rb_mKernel, "relay_from_ruby_to_main",
                                  relay_from_ruby_to_main, 0);
	Trace((zlog, "-- %s: interpreter started", __FUNCTION__));

	/* Run file.rb arguments. */
	for (i = 1; i < ruby->ac; i++) {
	    if (*ruby->av[i] == '-')	/* XXX FIXME: skip options. */
		continue;
	    Trace((zlog, "-- %s: require '%s' begin", __FUNCTION__, ruby->av[i]));
	    rpmrubyRunThreadFile(ruby, ruby->av[i], NULL);
	    Trace((zlog, "-- %s: require '%s' end", __FUNCTION__, ruby->av[i]));
	}

	/* Terminate the ruby interpreter. */
	Trace((zlog, "-- %s: interpreter terminating", __FUNCTION__));
	ruby_finalize();
        ruby_cleanup(0);
	Trace((zlog, "-- %s: interpreter terminated", __FUNCTION__));
    }

    /* Report interpreter end to main. */
    ruby->more = 0;
    /* Permit main thread to run without blocking. */
    yarnRelease(ruby->main_coroutine_lock);

    Trace((zlog, "-- %s: ended", __FUNCTION__));
    return NULL;
}
Ejemplo n.º 8
0
static void destroy_rb(language_t* li)
{
    if(li->internal) {
        rb_internal_t*rb = (rb_internal_t*)li->internal;
        if(--rb_reference_count == 0) {
            ruby_finalize();
        }
        free(rb);
    }
    free(li);
}
Ejemplo n.º 9
0
__attribute__ ((noreturn)) static void SysExit (
  int isThread,
  int num
) {
  if (isThread) {
    rb_protect(SysExit2,Qnil,NULL);
  } else {
    rb_protect(SysExit3,num,NULL);
    ruby_finalize();
  }
  exit(num);
}
Ejemplo n.º 10
0
int main ( int argc, char ** argv) 	{
    ruby_set_debug_option(getenv("RUBY_DEBUG"));
	ruby_sysinit(&argc, &argv);
	RUBY_INIT_STACK;
	ruby_init();
	ruby_init_loadpath();
	setbuf(stdout, NULL); // disable buffering
	rb_protect( test_iseq, 0, & error);// call our stuff rb_protect'ed
	perror("ERROR");
	return ruby_run_node(ruby_options(argc, argv));
 	ruby_finalize();
 	return 0;
}
Ejemplo n.º 11
0
int
weechat_plugin_end (struct t_weechat_plugin *plugin)
{
    /* make C compiler happy */
    (void) plugin;
    
    /* unload all scripts */
    weechat_ruby_unload_all ();
    
    ruby_finalize();
    
    return WEECHAT_RC_OK;
}
Ejemplo n.º 12
0
RUBY_GLOBAL_SETUP

int main(int argc, char *argv[])
{
  int status;
  {
    RUBY_INIT_STACK;
    ruby_init();
    ruby_script(argv[0]);
    rb_protect((VALUE (*)(VALUE))rb_require, (VALUE)"./embedded_ruby.rb", &status);
    // ruby_cleanup(0);
    ruby_finalize();
  };
  return status;
}
Ejemplo n.º 13
0
int main(int argc, char *argv[]) {
    HINSTANCE hDllInst = LoadLibrary(L"msvcrt-ruby220.dll");

    typedef int(*rb_init)();
    typedef int(*rb_eval_string_protect)(const char*, int*);
    typedef int(*rb_finalize)();
    rb_init ruby_init = (rb_init)GetProcAddress(hDllInst, "ruby_init");
    rb_eval_string_protect ruby_eval_string_protect = (rb_eval_string_protect)GetProcAddress(hDllInst, "rb_eval_string_protect");
    rb_finalize ruby_finalize = (rb_finalize)GetProcAddress(hDllInst, "ruby_finalize");

    ruby_init();
    ruby_eval_string_protect(argv[1], NULL);
    ruby_finalize();

    FreeLibrary(hDllInst);
}
Ejemplo n.º 14
0
static VALUE
rescue_callback(VALUE arg)
{

    VALUE error;
    VALUE e = rb_errinfo();
    VALUE bt = rb_funcall(e, rb_intern("backtrace"), 0);
    VALUE msg = rb_funcall(e, rb_intern("message"), 0);
    bt = rb_ary_entry(bt, 0);
    error = rb_sprintf("%"PRIsVALUE": %"PRIsVALUE" (%s)\n", bt, msg, rb_obj_classname(e));
    rb_write_error(StringValuePtr(error));
    rb_backtrace();
    ruby_finalize();
    exit(-1);

    return Qnil;
}
Ejemplo n.º 15
0
// keep on looking at the modification date of the file 'embed.rb' and eval it if it changes
int main () {
  time_t test_mod_time = 0;
  struct stat attrib;
  int    load_function_sym;
  VALUE file_name;
  VALUE loader;
  int count = 0;
  // register stop_running
  signal( SIGINT, stop_running );

  
  ruby_init();
  ruby_init_loadpath();
  ruby_script("rubyk");
  rb_require("embed_loader.rb");
  
  file_name = rb_str_new2("embed.rb");
  loader    = rb_class_new_instance(0,0,rb_const_get(rb_cObject, rb_intern("Loader")));
  load_function_sym = rb_intern("secure_load");

  running = 1;
  
  while(running) {
    sleep(0.1);
    count = count + 1;
    // get attributes
    stat("embed.rb", &attrib);
    if (test_mod_time != attrib.st_mtime) {
      printf("Finally a change (%i)\n", count);
      count = 0;
      test_mod_time = attrib.st_mtime;
      rb_funcall(loader, load_function_sym, 1, file_name);
    }
  }
  printf("\nbye...\n");
  ruby_finalize();
  exit(0);
}
Ejemplo n.º 16
0
/**
 * Load a Ruby file then run the function corresponding to the service by
 * passing the conf, inputs and outputs parameters by refernce as Ruby Hash.
 *
 * @param main_conf the conf maps containing the main.cfg settings
 * @param request the map containing the HTTP request
 * @param s the service structure
 * @param real_inputs the maps containing the inputs
 * @param real_outputs the maps containing the outputs
 * @return SERVICE_SUCCEEDED or SERVICE_FAILED if the service run, -1 
 *  if the service failed to load or throw error at runtime.
 */
int zoo_ruby_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
#if RUBY_API_VERSION_MAJOR >= 2 || RUBY_API_VERSION_MINOR == 9
  ruby_sysinit(&argc,&argv);
  RUBY_INIT_STACK;
#endif
  ruby_init();
  maps* m=*main_conf;
  maps* inputs=*real_inputs;
  maps* outputs=*real_outputs;
  map* tmp0=getMapFromMaps(*main_conf,"lenv","cwd");
  char *ntmp=tmp0->value;
  map* tmp=NULL;
  ruby_init_loadpath();
  ruby_script("ZOO_EMBEDDED_ENV");
  
  VALUE klass=rb_define_module("Zoo");
  rb_define_const(klass,"SERVICE_SUCCEEDED",INT2FIX(3));
  rb_define_const(klass,"SERVICE_FAILED",INT2FIX(4));
  typedef VALUE (*HOOK)(...);
  rb_define_module_function(klass,"Translate",reinterpret_cast<HOOK>(RubyTranslate),-1);
  rb_define_module_function(klass,"UpdateStatus",reinterpret_cast<HOOK>(RubyUpdateStatus),-1);

  int error = 0;
		
  ID rFunc=Qnil;
  tmp=getMap(s->content,"serviceProvider");
  if(tmp!=NULL){
#if RUBY_VERSION_MINOR == 8
    const char* script = ruby_sourcefile = rb_source_filename(tmp->value);
    rb_protect(LoadWrap, reinterpret_cast<VALUE>(script), &error);
#else
    rb_load_protect(rb_str_new2(tmp->value), 0, &error);
#endif
    if(error) {
      ruby_trace_error(m);
      return -1;
    }
#if RUBY_VERSION_MINOR == 8
    ruby_exec();
#else
    ruby_exec_node(NULL);
#endif
  }
  else{
    map* err=createMap("text","Unable to parse serviceProvider please check your zcfg file.");
    addToMap(err,"code","NoApplicableCode");
    printExceptionReportResponse(m,err);
    return -1;
  }
  int res=SERVICE_FAILED;
  rFunc=rb_intern(s->name);
  if(rFunc!=Qnil){
    VALUE arg1=RubyHash_FromMaps(m);
    VALUE arg2=RubyHash_FromMaps(inputs);
    VALUE arg3=RubyHash_FromMaps(outputs);
    VALUE rArgs[3]={arg1,arg2,arg3};
    if (!rArgs)
      return -1;
    struct my_callback data;
    data.obj=Qnil;
    data.method_id=rFunc;
    data.nargs=3;
    data.args[0]=rArgs[0];
    data.args[1]=rArgs[1];
    data.args[2]=rArgs[2];
    typedef VALUE (*HOOK)(VALUE);
    VALUE tres=rb_protect(reinterpret_cast<HOOK>(FunCallWrap),(VALUE)(&data),&error);
    if (TYPE(tres) == T_FIXNUM) {
      res=FIX2INT(tres);
      freeMaps(real_outputs);
      free(*real_outputs);
      freeMaps(main_conf);
      free(*main_conf);
      *main_conf=mapsFromRubyHash(arg1);
      *real_outputs=mapsFromRubyHash(arg3);
#ifdef DEBUG
      dumpMaps(*main_conf);
      dumpMaps(*real_outputs);
#endif
    }else{
      ruby_trace_error(m);
      res=-1;
    }
  }
  else{
    char tmpS[1024];
    sprintf(tmpS, "Cannot find the %s function in the %s file.\n", s->name, tmp->value);
    map* tmps=createMap("text",tmpS);
    printExceptionReportResponse(m,tmps);
    res=-1;
  }
  ruby_finalize();
  return res;
}
Ejemplo n.º 17
0
static void eruby_exit(status)
{
    ruby_finalize();
    exit(status);
}
Ejemplo n.º 18
0
int main( int argc, char** argv ) 
{
  int state  = 0;
  int rc     = 0;
  int opt_mv = 0;

  crate_app ca;

  /** startup items from ruby's original main.c */
#ifdef _WIN32
  NtInitialize(&argc, &argv);
#endif
#if defined(__MACOS__) && defined(__MWERKS__)
  argc = ccommand(&argv);
#endif

  /* setup ruby */
  ruby_init();
  ruby_script( argv[0] );
  ruby_init_loadpath();

  /* strip out the crate specific arguments from argv using --crate- */
  opt_mv = crate_init_from_options( &ca, argc, argv );
  argc -= opt_mv;
  argv += opt_mv;
 
  /* printf("crate file  : %s\n", ca.file_name);   */
  /* printf("crate class : %s\n", ca.class_name);  */
  /* printf("crate method: %s\n", ca.method_name); */

  /* make ARGV available */
  ruby_set_argv( argc, argv );

  /* initialize all extensions */
  Init_ext();

  /* load up the amalgalite libs */
  am_bootstrap_lift( cARB, Qnil );
 
  /* remove the current LOAD_PATH */
  rb_ary_clear( rb_gv_get( "$LOAD_PATH" ) );

  /* invoke the class / method passing in ARGV and ENV */
  rb_protect( crate_wrap_app, (VALUE)&ca, &state );

  /* check the results */
  if ( state ) {

    /* exception was raised, check the $! var */
    VALUE lasterr  = rb_gv_get("$!");
   
    /* system exit was called so just propogate that up to our exit */
    if ( rb_obj_is_instance_of( lasterr, rb_eSystemExit ) ) {

      rc = NUM2INT( rb_attr_get( lasterr, rb_intern("status") ) );
      /*printf(" Caught SystemExit -> $? will be %d\n", rc ); */

    } else {

      /* some other exception was raised so dump that out */
      VALUE klass     = rb_class_path( CLASS_OF( lasterr ) );
      VALUE message   = rb_obj_as_string( lasterr );
      VALUE backtrace = rb_funcall( lasterr, rb_intern("backtrace"), 0 );

      fprintf( stderr, "%s: %s\n", RSTRING( klass )->ptr, RSTRING( message )->ptr );
      rb_iterate( rb_each, backtrace, dump_backtrace, Qnil );

      rc = state;
    }
  } 

  free( ca.file_name );
  free( ca.class_name );
  free( ca.method_name );

  /* shut down ruby */
  ruby_finalize();

  /* exit the program */
  exit( rc );
}
Ejemplo n.º 19
0
void CleanupInterpreter()
{
    ruby_finalize();
}
Ejemplo n.º 20
0
void RubyInterpreter::finalizeRuby()
{
    delete d;
    d = 0;
    ruby_finalize();
}
Ejemplo n.º 21
0
Archivo: eruta.c Proyecto: beoran/eruta
int eruta_ruby_quit() {
  ruby_finalize();
}
Ejemplo n.º 22
0
static int fini(void *user)
{
	ruby_finalize();
	return R_TRUE;
}