Exemple #1
0
static void iroffer_ruby_errro(int error)
{
  VALUE lasterr;
  VALUE inclass;
  VALUE message;
  VALUE ary;
  long c;

  if (error == 0)
    return;

  lasterr = rb_gv_get("$!"); /* NOTRANSLATE */
  inclass = rb_class_path(CLASS_OF(lasterr));
  message = rb_obj_as_string(lasterr);
  outerror(OUTERROR_TYPE_WARN_LOUD,
           "error ruby_script: class=%s, message=%s",
           RSTRING_PTR(inclass), RSTRING_PTR(message));

  if (!NIL_P(rb_errinfo())) {
    ary = rb_funcall(rb_errinfo(), rb_intern("backtrace"), 0);
    for (c=0; c<RARRAY_LEN(ary); ++c) {
      outerror(OUTERROR_TYPE_WARN_LOUD,
               "backtrace from %s",
               RSTRING_PTR(RARRAY_PTR(ary)[c]));
    }
  }
}
Exemple #2
0
void uwsgi_ruby_exception(void) {

        VALUE lasterr = rb_gv_get("$!");
        VALUE message = rb_obj_as_string(lasterr);

        uwsgi_log("%s\n", RSTRING_PTR(message));
        if(!NIL_P(rb_errinfo())) {
                VALUE ary = rb_funcall(rb_errinfo(), rb_intern("backtrace"), 0);
                int i;
                for (i=0; i<RARRAY_LEN(ary); i++) {
                        uwsgi_log("%s\n", RSTRING_PTR(RARRAY_PTR(ary)[i]));
                }
        }
}
Exemple #3
0
static G_GNUC_NORETURN VALUE
ana_set_extra_attrs_rescue(VALUE value)
{
    g_slist_free(((struct ana_set_extra_attrs_args *)value)->result);

    rb_exc_raise(rb_errinfo());
}
Exemple #4
0
static gboolean
rg_regex_eval_callback(const GMatchInfo *match_info,
                       GString *result,
                       gpointer user_data)
{
    VALUE returned_data;
    RGRegexEvalCallbackData *data = user_data;

    data->match_info = match_info;
    returned_data = rb_protect(rg_regex_eval_callback_body,
                               (VALUE)data,
                               &(data->status));

    if (data->status == RUBY_TAG_BREAK) {
        returned_data = THROW_DATA_VAL(rb_errinfo());
    }

    if (NIL_P(returned_data)) {
        gchar *matched;
        matched = g_match_info_fetch(match_info, 0);
        g_string_append(result, matched);
        g_free(matched);
    } else {
        g_string_append(result, RVAL2CSTR(returned_data));
    }

    return data->status != 0;
}
static gboolean
protect_proccall(VALUE receiver, int argc, const VALUE *argv)
{
    funcall_arguments call_args;
    VALUE result;
    int state = 0;

    call_args.receiver = receiver;
    call_args.name = rb_intern("call");
    call_args.argc = argc;
    call_args.argv = argv;
    result = rb_protect(invoke_rb_funcall2, (VALUE)&call_args, &state);
    if (state) {
	VALUE errinfo = rb_errinfo();
	VALUE logger = rb_protect(default_logger, Qfalse, &state);
	if (state == 0 && !NIL_P(logger)) {
	    call_args.receiver = logger;
	    call_args.name = rb_intern("error");
	    call_args.argc = 1;
	    call_args.argv = &errinfo;
	    rb_protect(invoke_rb_funcall2, (VALUE)&call_args, &state);
	}
	return FALSE;
    }
    return RVAL2CBOOL(result);
}
Exemple #6
0
static G_GNUC_NORETURN VALUE
rval2atkstatetype_rescue(VALUE value)
{
    g_free(((struct rval2atkstatetype_args *)value)->result);

    rb_exc_raise(rb_errinfo());
}
Exemple #7
0
static int
load_encoding(const char *name)
{
    VALUE enclib = rb_sprintf("enc/%s.so", name);
    VALUE verbose = ruby_verbose;
    VALUE debug = ruby_debug;
    VALUE errinfo;
    char *s = RSTRING_PTR(enclib) + 4, *e = RSTRING_END(enclib) - 3;
    int loaded;
    int idx;

    while (s < e) {
	if (!ISALNUM(*s)) *s = '_';
	else if (ISUPPER(*s)) *s = (char)TOLOWER(*s);
	++s;
    }
    FL_UNSET(enclib, FL_TAINT);
    enclib = rb_fstring(enclib);
    ruby_verbose = Qfalse;
    ruby_debug = Qfalse;
    errinfo = rb_errinfo();
    loaded = rb_require_internal(enclib, rb_safe_level());
    ruby_verbose = verbose;
    ruby_debug = debug;
    rb_set_errinfo(errinfo);
    if (loaded < 0 || 1 < loaded) return -1;
    if ((idx = rb_enc_registered(name)) < 0) return -1;
    if (enc_autoload_p(enc_table.list[idx].enc)) return -1;
    return idx;
}
Exemple #8
0
static G_GNUC_NORETURN VALUE
layout_line_set_runs_rescue(VALUE value)
{
    g_slist_free(((struct layout_line_set_runs_args *)value)->result);

    rb_exc_raise(rb_errinfo());
}
Exemple #9
0
static VALUE
rbgdk_rval2gdkpixbufglist_rescue(VALUE value)
{
    g_list_free(((struct rval2gdkpixbufglist_args *)value)->result);

    rb_exc_raise(rb_errinfo());
}
static VALUE
rbgtk_rval2gtkradiotoolbuttongslist_rescue(VALUE value)
{
    g_slist_free(((struct rbgtk_rval2gtkradiotoolbuttongslist_args *)value)->result);

    rb_exc_raise(rb_errinfo());
}
Exemple #11
0
static VALUE
rbgdk_rval2gdkatoms_rescue(VALUE value)
{
    g_free(((struct rbgdk_rval2gdkatoms_args *)value)->result);

    rb_exc_raise(rb_errinfo());
}
Exemple #12
0
static G_GNUC_NORETURN VALUE
rbgdk_rval2gdkspans_rescue(VALUE value)
{
    g_free(((struct rbgdk_rval2gdkspans_args *)value)->result);

    rb_exc_raise(rb_errinfo());
}
Exemple #13
0
static G_GNUC_NORETURN VALUE
rbg_rval2gtkradioactionentries_rescue(VALUE value)
{
    g_free(((struct rbg_rval2gtkradioactionentries_args *)value)->result);

    rb_exc_raise(rb_errinfo());
}
Exemple #14
0
static void
err_append(const char *s)
{

    if (rb_vm_parse_in_eval()) {
	VALUE err = rb_errinfo();
	if (err == Qnil) {
	    err = rb_exc_new2(rb_eSyntaxError, s);
	    rb_set_errinfo(err);
	}
	else {
	    VALUE str = rb_obj_as_string(err);

	    rb_str_cat2(str, "\n");
	    rb_str_cat2(str, s);
	    rb_set_errinfo(rb_exc_new3(rb_eSyntaxError, str));
	}
    }
    else {
	VALUE err = rb_vm_current_exception();
	if (err == Qnil) {
	    err = rb_exc_new2(rb_eSyntaxError, "compile error");
	    rb_vm_set_current_exception(err);
	}
	rb_write_error(s);
	rb_write_error("\n");
    }
}
Exemple #15
0
/*
 *  call-seq:
 *    Byebug.debug_load(file, stop = false) -> nil
 *
 *  Same as Kernel#load but resets current context's frames.
 *  +stop+ parameter forces byebug to stop at the first line of code in +file+
 */
static VALUE
Debug_load(int argc, VALUE * argv, VALUE self)
{
  VALUE file, stop, context;
  debug_context_t *dc;
  VALUE status = Qnil;
  int state = 0;

  UNUSED(self);

  if (rb_scan_args(argc, argv, "11", &file, &stop) == 1)
    stop = Qfalse;

  Start(self);

  context = Current_context(self);
  Data_Get_Struct(context, debug_context_t, dc);

  dc->calced_stack_size = 1;

  if (RTEST(stop))
    dc->steps = 1;

  rb_load_protect(file, 0, &state);
  if (0 != state)
  {
    status = rb_errinfo();
    reset_stepping_stop_points(dc);
  }

  return status;
}
static G_GNUC_NORETURN VALUE
value_array_from_ruby_rescue(VALUE value)
{
    g_value_array_free(((struct value_array_from_ruby_args *)value)->result);

    rb_exc_raise(rb_errinfo());
}
Exemple #17
0
static int
load_encoding(const char *name)
{
    VALUE enclib = rb_sprintf("enc/%s.so", name);
    VALUE verbose = ruby_verbose;
    VALUE debug = ruby_debug;
    VALUE errinfo;
    VALUE loaded;
    char *s = RSTRING_PTR(enclib) + 4, *e = RSTRING_END(enclib) - 3;
    int idx;

    while (s < e) {
	if (!ISALNUM(*s)) *s = '_';
	else if (ISUPPER(*s)) *s = (char)TOLOWER(*s);
	++s;
    }
    FL_UNSET(enclib, FL_TAINT|FL_UNTRUSTED);
    OBJ_FREEZE(enclib);
    ruby_verbose = Qfalse;
    ruby_debug = Qfalse;
    errinfo = rb_errinfo();
    loaded = rb_protect(require_enc, enclib, 0);
    ruby_verbose = verbose;
    ruby_debug = debug;
    rb_set_errinfo(errinfo);
    if (NIL_P(loaded)) return -1;
    if ((idx = rb_enc_registered(name)) < 0) return -1;
    if (enc_autoload_p(enc_table.list[idx].enc)) return -1;
    return idx;
}
Exemple #18
0
// 尝试执行脚本
VALUE ThisApp::TryEval(const char* str){
	static char buffer[1024];
	VALUE rc = Qnil;
	VALUE err;
	__try{
		rc = rb_eval_string(str);
	}
	__except (EXCEPTION_EXECUTE_HANDLER){}
	if (!NIL_P(err = rb_errinfo())){
		// class
		VALUE kclass = rb_class_path(CLASS_OF(err));
		// message
		VALUE message = rb_obj_as_string(err);
		// backtrace
		VALUE ary = rb_funcall(err, rb_intern("backtrace"), 0);
		VALUE brstr = rb_funcall(ary, rb_intern("to_s"), 0);
		// sprintf
		sprintf_s(buffer, "Error:  %s\n%s\nbacktrace:  %s\n", StringValuePtr(kclass),
			StringValuePtr(message),
			StringValuePtr(brstr));
		MessageBoxA(nullptr, buffer, "Error", MB_OK);
		rb_set_errinfo(Qnil);
	}
	return rc;
}
Exemple #19
0
static void mriBindingExecute()
{
	/* Normally only a ruby executable would do a sysinit,
	 * but not doing it will lead to crashes due to closed
	 * stdio streams on some platforms (eg. Windows) */
	int argc = 0;
	char **argv = 0;
	ruby_sysinit(&argc, &argv);

	ruby_setup();
	rb_enc_set_default_external(rb_enc_from_encoding(rb_utf8_encoding()));

	Config &conf = shState->rtData().config;

	if (!conf.rubyLoadpaths.empty())
	{
		/* Setup custom load paths */
		VALUE lpaths = rb_gv_get(":");

		for (size_t i = 0; i < conf.rubyLoadpaths.size(); ++i)
		{
			std::string &path = conf.rubyLoadpaths[i];

			VALUE pathv = rb_str_new(path.c_str(), path.size());
			rb_ary_push(lpaths, pathv);
		}
	}

	RbData rbData;
	shState->setBindingData(&rbData);
	BacktraceData btData;

	mriBindingInit();


	STEAMSHIM_init();
	_rb_define_module_function(rb_mKernel, "_steam_achievement_unlock",
	                           _steamAchievementUnlock);


	std::string &customScript = conf.customScript;
	if (!customScript.empty())
		runCustomScript(customScript);
	else
		runRMXPScripts(btData);

	VALUE exc = rb_errinfo();
	if (!NIL_P(exc) && !rb_obj_is_kind_of(exc, rb_eSystemExit))
		showExc(exc, btData);

	ruby_cleanup(0);


	STEAMSHIM_deinit();


	shState->rtData().rqTermAck.set();
}
Exemple #20
0
static VALUE initrb_interpreter_protect(initrb_ruby_fn_t fn, VALUE args) {
    int exc = 0;
    VALUE ret = rb_protect(fn, args, &exc);
    if (exc != 0) {
        initrb_interpreter_print_exception(rb_errinfo());
        return Qundef;
    }
    return ret;
}
Exemple #21
0
static VALUE
get_errinfo(void)
{
    VALUE exc = rb_vm_current_exception();
    if (NIL_P(exc)) {
	exc = rb_errinfo();
    }
    return exc;
}
Exemple #22
0
static G_GNUC_NORETURN VALUE
clipboard_set_rescue(VALUE value)
{
    struct clipboard_set_args *args = (struct clipboard_set_args *)value;

    G_CHILD_REMOVE(args->self, args->func);

    rb_exc_raise(rb_errinfo());
}
Exemple #23
0
static struct uwsgi_buffer *uwsgi_ruby_exception_class(struct wsgi_request *wsgi_req) {
	VALUE err = rb_errinfo();
        VALUE e = rb_class_name(rb_class_of(err));
        struct uwsgi_buffer *ub = uwsgi_buffer_new(RSTRING_LEN(e));
        if (uwsgi_buffer_append(ub, RSTRING_PTR(e), RSTRING_LEN(e))) {
                uwsgi_buffer_destroy(ub);
                return NULL;
        }
        return ub;
}
Exemple #24
0
/**
 * Print message from last exception triggered by ruby
 */
static void proxenet_ruby_print_last_exception()
{
	VALUE rException, rExceptStr;

	rException = rb_errinfo();         /* get last exception */
        rb_set_errinfo(Qnil);              /* clear last exception */
        rExceptStr = rb_funcall(rException, rb_intern("to_s"), 0, Qnil);
        xlog_ruby(LOG_ERROR, "Exception: %s\n", StringValuePtr(rExceptStr));
	return;
}
Exemple #25
0
static struct uwsgi_buffer *uwsgi_ruby_exception_msg(struct wsgi_request *wsgi_req) {
	VALUE err = rb_errinfo();
	VALUE e = rb_funcall(err, rb_intern("message"), 0, 0);
	struct uwsgi_buffer *ub = uwsgi_buffer_new(RSTRING_LEN(e));
	if (uwsgi_buffer_append(ub, RSTRING_PTR(e), RSTRING_LEN(e))) {
		uwsgi_buffer_destroy(ub);
		return NULL;
	}
	return ub;
}
static gboolean
filter_func(const GtkRecentFilterInfo *info, gpointer func)
{
    VALUE result;
    struct callback_arg arg;

    arg.callback = (VALUE)func;
    arg.info = BOXED2RVAL((gpointer)info, GTK_TYPE_RECENT_FILTER_INFO);

    result = G_PROTECT_CALLBACK(invoke_callback, &arg);
    return NIL_P(rb_errinfo()) ? TRUE : RVAL2CBOOL(result);
}
Exemple #27
0
/*
 * When any AsyncEngine handler runs a handle method having the GVL,
 * it must use this function, which can receive an optional VALUE parameter.
 */
VALUE ae_run_with_error_handler(void* function, VALUE param)
{
  AE_TRACE();

  VALUE ret, error;
  int error_tag;

  AE_ASSERT(AE_status != AE_STOPPED);

  if (param)
    ret = rb_protect(function, (VALUE)param, &error_tag);
  else
    ret = rb_protect(function, Qnil, &error_tag);

  /*
   * If an error occurs while in function() it can be due:
   *
   * - An Exception (including SystemExit), this is "rescue-able" via "rescue Exception"
   *   and will run the "ensure" code if present. In this case rb_errinfo() returns the
   *   exact Exception object.
   *
   * - A Thread#kill. This is NOT "rescue-able" via "rescue Exception" but it WILL run
   *   the "ensure" code if present. In this case rb_errinfo() returns FIXNUM 8.
   *
   * So, check the class of the object returned by rb_errinfo(). If it's an Exception then
   * store it, release the loop and raise it. Otherwise (Thread#kill) then don't store the
   * exception returned by rb_errinfo() and just release the loop. Ruby will do the rest.
   */

  if (error_tag) {
    // NOTE: This could return Fixnum 8: https://github.com/ibc/AsyncEngine/issues/4,
    // so the error handler must check it.
    error = rb_errinfo();
    rb_set_errinfo(Qnil);

    // NOTE: While in RELEASING status ignore errors in user's provided callback/method.
    if (AE_status == AE_RELEASING) {
      AE_DEBUG2("error %s rescued while in RELEASING status, ignoring it", rb_obj_classname(error));
      return Qnil;
    }
    else {
      AE_DEBUG("error %s rescued, passing it to the error handler", rb_obj_classname(error));
      ae_handle_error(error);
      return Qnil;
    }
  }
  else
    return ret;
}
Exemple #28
0
VALUE
rb_require_safe(VALUE fname, int safe)
{
    int result = rb_require_internal(fname, safe);

    if (result > TAG_RETURN) {
	if (result == TAG_RAISE) rb_exc_raise(rb_errinfo());
	EC_JUMP_TAG(GET_EC(), result);
    }
    if (result < 0) {
	load_failed(fname);
    }

    return result ? Qtrue : Qfalse;
}
Exemple #29
0
static gboolean
each_printer(GtkPrinter *printer, gpointer data)
{
    VALUE result;
    VALUE argv[1];
    struct callback_arg arg;

    argv[0] = GOBJ2RVAL(printer);

    arg.callback = (VALUE)data;
    arg.argc = 1;
    arg.argv = argv;

    result = G_PROTECT_CALLBACK(invoke_callback, &arg);
    return NIL_P(rb_errinfo()) ? TRUE : RVAL2CBOOL(result);
}
Exemple #30
0
// simulate ruby_error_print (this is sad... but it works well)
static void uwsgi_ruby_exception_log(struct wsgi_request *wsgi_req) {
	VALUE err = rb_errinfo();
	VALUE eclass = rb_class_name(rb_class_of(err));
	VALUE msg = rb_funcall(err, rb_intern("message"), 0, 0);
	
	VALUE ary = rb_funcall(err, rb_intern("backtrace"), 0);
        int i;
        for (i=0; i<RARRAY_LEN(ary); i++) {
		if (i == 0) {
			uwsgi_log("%s: %s (%s)\n", RSTRING_PTR(RARRAY_PTR(ary)[i]), RSTRING_PTR(msg), RSTRING_PTR(eclass));
		}
		else {
        		uwsgi_log("\tfrom %s\n", RSTRING_PTR(RARRAY_PTR(ary)[i]));
		}
        }
}