void ruby_init(void) { static int initialized = 0; int state; if (initialized) return; initialized = 1; ruby_init_stack((void *)&state); Init_BareVM(); Init_heap(); PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { rb_call_inits(); ruby_prog_init(); } POP_TAG(); if (state) { error_print(); exit(EXIT_FAILURE); } GET_VM()->running = 1; }
/* Initializes the Ruby VM and builtin libraries. * @retval 0 if succeeded. * @retval non-zero an error occurred. */ int ruby_setup(void) { static int initialized = 0; int state; if (initialized) return 0; initialized = 1; ruby_init_stack((void *)&state); Init_BareVM(); Init_heap(); Init_vm_objects(); PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { rb_call_inits(); ruby_prog_init(); GET_VM()->running = 1; } POP_TAG(); return state; }
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; }
static int ensure_ruby_initialized(void) { if (!ruby_initialized) { #ifdef DYNAMIC_RUBY if (ruby_enabled(TRUE)) { #endif #ifdef _WIN32 /* suggested by Ariya Mizutani */ int argc = 1; char *argv[] = {"gvim.exe"}; char **argvp = argv; NtInitialize(&argc, &argvp); #endif { #if defined(RUBY19_OR_LATER) || defined(RUBY_INIT_STACK) ruby_init_stack(ruby_stack_start); #endif ruby_init(); } #ifdef RUBY19_OR_LATER { int dummy_argc = 2; char *dummy_argv[] = {"vim-ruby", "-e0"}; ruby_options(dummy_argc, dummy_argv); } ruby_script("vim-ruby"); #else ruby_init_loadpath(); #endif ruby_io_init(); ruby_vim_init(); ruby_initialized = 1; #ifdef DYNAMIC_RUBY } else { EMSG(_("E266: Sorry, this command is disabled, the Ruby library could not be loaded.")); return 0; } #endif } return ruby_initialized; }
/*! Processes command line arguments and compiles the Ruby source to execute. * * This function does: * \li Processes the given command line flags and arguments for ruby(1) * \li compiles the source code from the given argument, -e or stdin, and * \li returns the compiled source as an opaque pointer to an internal data structure * * @return an opaque pointer to the compiled source or an internal special value. * @sa ruby_executable_node(). */ void * ruby_options(int argc, char **argv) { int state; void *volatile iseq = 0; ruby_init_stack((void *)&iseq); PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { SAVE_ROOT_JMPBUF(GET_THREAD(), iseq = ruby_process_options(argc, argv)); } else { rb_clear_trace_func(); state = error_handle(state); iseq = (void *)INT2FIX(state); } POP_TAG(); return iseq; }
void ruby_init(void) { static int initialized = 0; int state; //RHO const_cache_version++; rb_mKernel = 0; rb_mComparable = 0; rb_mEnumerable = 0; rb_mErrno = 0; rb_mFileTest = 0; rb_mGC = 0; rb_mMath = 0; rb_mProcess = 0; rb_mWaitReadable = 0; rb_mWaitWritable = 0; rb_cBasicObject = 0; rb_cObject = 0; rb_cArray = 0; rb_cBignum = 0; rb_cBinding = 0; rb_cClass = 0; //rb_cCont = 0; rb_cDir = 0; rb_cData = 0; rb_cFalseClass = 0; rb_cEncoding = 0; rb_cEnumerator = 0; rb_cFile = 0; rb_cFixnum = 0; rb_cFloat = 0; rb_cHash = 0; rb_cInteger = 0; rb_cIO = 0; rb_cMatch = 0; rb_cMethod = 0; rb_cModule = 0; rb_cNameErrorMesg = 0; rb_cNilClass = 0; rb_cNumeric = 0; rb_cProc = 0; rb_cRandom = 0; rb_cRange = 0; rb_cRational = 0; rb_cComplex = 0; rb_cRegexp = 0; rb_cStat = 0; rb_cString = 0; rb_cStruct = 0; rb_cSymbol = 0; rb_cThread = 0; rb_cTime = 0; rb_cTrueClass = 0; rb_cUnboundMethod = 0; rb_eException = 0; rb_eStandardError = 0; rb_eSystemExit = 0; rb_eInterrupt = 0; rb_eSignal = 0; rb_eFatal = 0; rb_eArgError = 0; rb_eEOFError = 0; rb_eIndexError = 0; rb_eStopIteration = 0; rb_eKeyError = 0; rb_eRangeError = 0; rb_eIOError = 0; rb_eRuntimeError = 0; rb_eSecurityError = 0; rb_eSystemCallError = 0; rb_eThreadError = 0; rb_eTypeError = 0; rb_eZeroDivError = 0; rb_eNotImpError = 0; rb_eNoMemError = 0; rb_eNoMethodError = 0; rb_eFloatDomainError = 0; rb_eLocalJumpError = 0; rb_eSysStackError = 0; rb_eRegexpError = 0; rb_eEncodingError = 0; rb_eEncCompatError = 0; rb_eScriptError = 0; rb_eNameError = 0; rb_eSyntaxError = 0; rb_eLoadError = 0; rb_eMathDomainError = 0; ruby_current_vm = 0; rb_cISeq = 0; rb_cRubyVM = 0; rb_cEnv = 0; rb_mRubyVMFrozenCore = 0; //RHO //RHO //if (initialized) //return; //RHO initialized = 1; ruby_init_stack((void *)&state); Init_BareVM(); Init_heap(); PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { rb_call_inits(); ruby_prog_init(); } POP_TAG(); if (state) { error_print(); exit(EXIT_FAILURE); } GET_VM()->running = 1; }
int ruby_cleanup(volatile int ex) { int state; volatile VALUE errs[2]; rb_thread_t *th = GET_THREAD(); int nerr; errs[1] = th->errinfo; th->safe_level = 0; ruby_init_stack(&errs[STACK_UPPER(errs, 0, 1)]); PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { SAVE_ROOT_JMPBUF(th, ruby_finalize_0()); } POP_TAG(); errs[0] = th->errinfo; PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { SAVE_ROOT_JMPBUF(th, rb_thread_terminate_all()); } else if (ex == 0) { ex = state; } th->errinfo = errs[1]; ex = error_handle(ex); ruby_finalize_1(); POP_TAG(); rb_thread_stop_timer_thread(); state = 0; for (nerr = 0; nerr < numberof(errs); ++nerr) { VALUE err = errs[nerr]; if (!RTEST(err)) continue; /* th->errinfo contains a NODE while break'ing */ if (TYPE(err) == T_NODE) continue; if (rb_obj_is_kind_of(err, rb_eSystemExit)) { return sysexit_status(err); } else if (rb_obj_is_kind_of(err, rb_eSignal)) { VALUE sig = rb_iv_get(err, "signo"); state = NUM2INT(sig); break; } else if (ex == 0) { ex = 1; } } ruby_vm_destruct(GET_VM()); if (state) ruby_default_signal(state); #if EXIT_SUCCESS != 0 || EXIT_FAILURE != 1 switch (ex) { #if EXIT_SUCCESS != 0 case 0: return EXIT_SUCCESS; #endif #if EXIT_FAILURE != 1 case 1: return EXIT_FAILURE; #endif } #endif return ex; }
rpmruby rpmrubyNew(char ** av, uint32_t flags) { static char * _av[] = { "rpmruby", NULL }; rpmruby ruby = (flags & 0x80000000) ? rpmrubyI() : rpmrubyGetPool(_rpmrubyPool); int xx; RUBYDBG((stderr, "--> %s(%p,0x%x) ruby %p\n", __FUNCTION__, av, flags, ruby)); /* If failure, or retrieving already initialized _rpmrubyI, just exit. */ if (ruby == NULL || ruby == _rpmrubyI) goto exit; if (av == NULL) av = _av; ruby->flags = flags; xx = argvAppend(&ruby->av, (ARGV_t)av); ruby->ac = argvCount(ruby->av); /* XXX FIXME: 0x40000000 => xruby.c wrapper without interpreter. */ if (ruby->flags & 0x40000000) { static size_t _rpmrubyStackSize = 4 * 1024 * 1024; /* XXX save as global interpreter. */ _rpmrubyI = ruby; ruby->nstack = _rpmrubyStackSize; ruby->stack = malloc(ruby->nstack); assert(ruby->stack != NULL); gettimeofday(&ruby->start, NULL); /* starting time for log entries */ if (_rpmruby_debug) ruby->zlog = rpmzLogNew(&ruby->start); /* initialize logging */ /* initialize the relay mechanism */ ruby->ruby_coroutine_lock = yarnNewLock(0); ruby->main_coroutine_lock = yarnNewLock(0); } else { #if defined(WITH_RUBYEMBED) VALUE variable_in_this_stack_frame; /* RUBY_INIT_STSCK */ #if defined(HAVE_RUBY_DEFINES_H) /* XXX ruby-1.9.2 */ ruby_sysinit(&ruby->ac, (char ***) &ruby->av); /* XXX ruby-1.9.2p0 ruby_bind_stack() patch needed */ { uint8_t * b = ruby->stack; uint8_t * e = b + ruby->nstack; ruby_bind_stack((VALUE *)b, (VALUE *) e); } #endif /* NOTYET */ ruby_init_stack(&variable_in_this_stack_frame); /* RUBY_INIT_STACK */ ruby_init(); ruby_init_loadpath(); ruby_script((char *)av[0]); if (av[1]) ruby_set_argv(argvCount((ARGV_t)av)-1, av+1); rb_gv_set("$result", rb_str_new2("")); #if !defined(HAVE_RUBY_DEFINES_H) /* XXX ruby-1.8.6 */ (void) rpmrubyRun(ruby, rpmrubyInitStringIO, NULL); #endif #endif /* WITH_RUBYEMBED */ } exit: return rpmrubyLink(ruby); }