/** * This function provides the execute_immediate method for the Connection class. * * @param self A reference to the connection object to perform the execution * through. * @param sql A reference to the SQL statement to be executed. * * @return Always returns nil. * */ static VALUE executeOnConnectionImmediate(VALUE self, VALUE sql) { VALUE transaction = rb_transaction_new(self), set = Qnil, results = Qnil, array = rb_ary_new(), dialect = INT2FIX(3), statement = rb_statement_new(self, transaction, sql, dialect); rb_ary_push(array, self); rb_ary_push(array, transaction); rb_ary_push(array, sql); rb_ary_push(array, statement); set = rb_rescue(executeBlock, array, executeRescue, array); if(set != Qnil) { if(TYPE(set) == T_DATA && RDATA(set)->dfree == (RUBY_DATA_FUNC)resultSetFree) { rb_assign_transaction(set, transaction); if(rb_block_given_p()) { results = rb_rescue(executeImmediateBlock, set, executeImmediateRescue, set); } else { results = set; } } else { rb_funcall(transaction, rb_intern("commit"), 0); results = set; } } else { rb_funcall(transaction, rb_intern("commit"), 0); } return(results); }
static void grpc_rb_call_credentials_callback_with_gil(void* param) { callback_params* const params = (callback_params*)param; VALUE auth_uri = rb_str_new_cstr(params->context.service_url); /* Pass the arguments to the proc in a hash, which currently only has they key 'auth_uri' */ VALUE callback_args = rb_ary_new(); VALUE args = rb_hash_new(); VALUE result; grpc_metadata_array md_ary; grpc_status_code status; VALUE details; char* error_details; grpc_metadata_array_init(&md_ary); rb_hash_aset(args, ID2SYM(rb_intern("jwt_aud_uri")), auth_uri); rb_ary_push(callback_args, params->get_metadata); rb_ary_push(callback_args, args); result = rb_rescue(grpc_rb_call_credentials_callback, callback_args, grpc_rb_call_credentials_callback_rescue, Qnil); // Both callbacks return a hash, so result should be a hash grpc_rb_md_ary_convert(rb_hash_aref(result, rb_str_new2("metadata")), &md_ary); status = NUM2INT(rb_hash_aref(result, rb_str_new2("status"))); details = rb_hash_aref(result, rb_str_new2("details")); error_details = StringValueCStr(details); params->callback(params->user_data, md_ary.metadata, md_ary.count, status, error_details); grpc_rb_metadata_array_destroy_including_entries(&md_ary); gpr_free(params); }
static VALUE rb_gsl_object_info(VALUE obj) { char buf[256]; VALUE s; sprintf(buf, "Class: %s\n", rb_class2name(CLASS_OF(obj))); #ifdef RUBY_1_9_LATER sprintf(buf, "%sSuperClass: %s\n", buf, rb_class2name(RCLASS_SUPER(CLASS_OF(obj)))); #else sprintf(buf, "%sSuperClass: %s\n", buf, rb_class2name(RCLASS(CLASS_OF(obj))->super)); #endif s = rb_rescue(rb_gsl_call_name, obj, rb_gsl_call_rescue, obj); if (s) sprintf(buf, "%sType: %s\n", buf, STR2CSTR(s)); s = rb_rescue(rb_gsl_call_size, obj, rb_gsl_call_rescue, obj); if (s) sprintf(buf, "%sSize: %d\n", buf, (int) FIX2INT(s)); return rb_str_new2(buf); }
/* * Extern: rm_str_to_pct * Purpose: Given a string in the form NN% return the corresponding double. * */ double rm_str_to_pct(VALUE str) { long pct; char *pct_str, *end; str = rb_rescue(rb_str_to_str, str, rescue_not_str, str); pct_str = StringValuePtr(str); errno = 0; pct = strtol(pct_str, &end, 10); if (errno == ERANGE) { rb_raise(rb_eRangeError, "`%s' out of range", pct_str); } if (*end != '%') { rb_raise(rb_eArgError, "expected percentage, got `%s'", pct_str); } if (pct < 0L) { rb_raise(rb_eArgError, "percentages may not be negative (got `%s')", pct_str); } return pct / 100.0; }
static gint flags_compare(VALUE self, VALUE rhs) { flags_holder* p = flags_get_holder(self); compare_data data; data.gtype = G_TYPE_FROM_CLASS(p->gclass); data.rb_value = rhs; data.value = 0; data.compatible = TRUE; rb_rescue(flags_compare_get_flags_body, (VALUE)&data, flags_compare_get_flags_rescue, (VALUE)&data); if (!data.compatible) { return FLAGS_COMP_INCOMPARABLE; } if (p->value == data.value) return FLAGS_COMP_EQUAL; else if ((p->value & data.value) == data.value) return FLAGS_COMP_GREATER; else if ((p->value & data.value) == p->value) return FLAGS_COMP_LESS; else return FLAGS_COMP_ELSE; }
int io_write_callback(void * ctx, char * buffer, int len) { VALUE args[2]; args[0] = (VALUE)ctx; args[1] = rb_str_new(buffer, (long)len); rb_rescue(write_check, (VALUE)args, write_failed, 0); return len; }
static bool define_function_rb(language_interpreter_t*li, const char*script) { ruby_dfunc_t dfunc; dfunc.li = li; dfunc.script = script; dfunc.fail = false; VALUE ret = rb_rescue(define_function_internal, (VALUE)&dfunc, define_function_exception, (VALUE)&dfunc); return !dfunc.fail; }
static void rb_block_arg_dispatcher(rb_vm_block_t *block, VALUE param) { assert(block != NULL); VALUE args[2]; args[0] = (VALUE)block; args[1] = param; rb_rescue(rb_block_arg_eval, (VALUE) args, rb_block_rescue, (VALUE)"gcd.c: Exception in rb_block_arg_dispatcher"); }
/** * This function provides the start_transaction method for the Database class. * * @param self A reference to the Database object to start the transaction * on. * * @return A reference to a Transaction object or nil if a problem occurs. * */ static VALUE startConnectionTransaction(VALUE self) { VALUE result = rb_transaction_new(self); if(rb_block_given_p()) { result = rb_rescue(startTransactionBlock, result, startTransactionRescue, result); } return(result); }
static VALUE rg_set(VALUE self, VALUE targets) { struct clipboard_set_args args = { self, targets, rb_block_proc() }; G_CHILD_ADD(self, args.func); return rb_rescue(clipboard_set_body, (VALUE)&args, clipboard_set_rescue, (VALUE)&args); }
static VALUE cmp_equal(VALUE x, VALUE y) { VALUE a[2]; if (x == y) return Qtrue; a[0] = x; a[1] = y; return rb_rescue(cmp_eq, (VALUE)a, cmp_failed, 0); }
VALUE cb_encode_value(VALUE val, uint32_t flags) { VALUE blob, args[2]; args[0] = val; args[1] = (VALUE)flags; blob = rb_rescue(do_encode, (VALUE)args, coding_failed, 0); return blob; /* bytestring or exception object */ }
/* * call-seq: * == image -> bool * * compares two image. * * */ DLL_LOCAL VALUE _equal(VALUE self, VALUE other) { equal_obj obj; obj.self = _self; obj.other = other; return rb_rescue( RUBY_METHOD_FUNC(_equal_block),(VALUE)&obj, RUBY_METHOD_FUNC(_equal_rescue),Qnil ); }
GSList * rbg_rval2gslist(VALUE rb_array) { struct rval2gslist_args args; args.list = NULL; args.rb_array = rb_array; rb_rescue(rval2gslist_body, (VALUE)&args, rval2gslist_rescue, (VALUE)&args); return args.list; }
static void event_callback_wrapper (const unsigned long signature, int event, const char *data_str, const unsigned long data_num) { struct em_event e; e.signature = signature; e.event = event; e.data_str = data_str; e.data_num = data_num; if (!rb_ivar_defined(EmModule, Intern_at_error_handler)) event_callback(&e); else rb_rescue((VALUE (*)(ANYARGS))event_callback, (VALUE)&e, (VALUE (*)(ANYARGS))event_error_handler, Qnil); }
static void event_callback_wrapper (const unsigned long a1, int a2, const char *a3, const unsigned long a4) { struct em_event e; e.a1 = a1; e.a2 = a2; e.a3 = a3; e.a4 = a4; if (!rb_ivar_defined(EmModule, Intern_at_error_handler)) event_callback(&e); else rb_rescue((VALUE (*)(ANYARGS))event_callback, (VALUE)&e, (VALUE (*)(ANYARGS))event_error_handler, Qnil); }
VALUE rb_lapack_determinant(VALUE self) { Matrix *m; VALUE copy; //char error_msg[64]; int i; float result_c[2]; double result_z[2]; float r_tmp[2]; double d_tmp[2]; Data_Get_Struct(self, Matrix, m); if(m->nrows != m->ncols) { //sprintf(error_msg, "Matrix not square"); rb_raise(rb_eRuntimeError, "Matrix not square"); } if(m->matrix_type != LU) { copy = rb_rescue( rb_getrf_mod_helper, self, rb_lapack_getrf_rescue, Qnil); if(copy == Qnil) return INT2FIX(0); //any error, we return a determinant of 0 Data_Get_Struct(copy, Matrix, m); } switch(m->data_type) { case Single_t: result_c[0] = (float) 1.0; for(i=0; i < m->nrows; i++) { rb_blas_get_member(r_tmp, m, i, i); result_c[0] *= r_tmp[0]; } return rb_float_new(result_c[0]); case Double_t: result_z[0] = 1.0; for(i=0; i < m->nrows; i++) { rb_blas_get_member(d_tmp, m, i, i); result_z[0] *= d_tmp[0]; } return rb_float_new(result_z[0]); case Complex_t: case Double_Complex_t: //sprintf(error_msg, "Complex yet to be implemented"); rb_raise(rb_eRuntimeError, "Complex yet to be implemented"); break; } }
/* * Extern: rm_percentage(obj) * Purpose: Return a double between 0.0 and 1.0, inclusive. * If the argument is a number convert to a Float object, * otherwise it's supposed to be a string in the form "NN%". * Convert to a number and then to a Float. */ double rm_percentage(VALUE arg) { double pct; long pct_long; char *pct_str, *end; int not_num; // Try to convert the argument to a number. If failure, sets not_num to non-zero. (void) rb_protect(arg_is_number, arg, ¬_num); if (not_num) { arg = rb_rescue(rb_str_to_str, arg, rescue_not_str, arg); pct_str = StringValuePtr(arg); errno = 0; pct_long = strtol(pct_str, &end, 10); if (errno == ERANGE) { rb_raise(rb_eRangeError, "`%s' out of range", pct_str); } if (*end != '\0' && *end != '%') { rb_raise(rb_eArgError, "expected percentage, got `%s'", pct_str); } if (*end == '%' && pct_long != 0) { pct = ((double)pct_long) / 100.0; } else { pct = (double) pct_long; } if (pct < 0.0) { rb_raise(rb_eArgError, "percentages may not be negative (got `%s')", pct_str); } } else { pct = NUM2DBL(arg); if (pct < 0.0) { rb_raise(rb_eArgError, "percentages may not be negative (got `%g')", pct); } } return pct; }
GList * rbgdk_rval2gdkpixbufglist(VALUE value) { struct rval2gdkpixbufglist_args args; args.ary = rb_ary_to_ary(value); args.n = RARRAY_LEN(args.ary); args.result = NULL; rb_rescue(rbgdk_rval2gdkpixbufglist_body, (VALUE)&args, rbgdk_rval2gdkpixbufglist_rescue, (VALUE)&args); return args.result; }
static VALUE rg_set_extra_attrs(VALUE self, VALUE attrs) { struct ana_set_extra_attrs_args args; args.analysis = _SELF(self); args.ary = rb_ary_to_ary(attrs); args.n = RARRAY_LEN(args.ary); args.result = NULL; rb_rescue(ana_set_extra_attrs_body, (VALUE)&args, ana_set_extra_attrs_rescue, (VALUE)&args); return self; }
static VALUE rg_set_runs(VALUE self, VALUE attrs) { struct layout_line_set_runs_args args; args.line = _SELF(self); args.ary = rb_ary_to_ary(attrs); args.n = RARRAY_LEN(args.ary); args.result = NULL; rb_rescue(layout_line_set_runs_body, (VALUE)&args, layout_line_set_runs_rescue, (VALUE)&args); return self; }
static GSList * rbgtk_rval2gtkradiotoolbuttongslist(VALUE value) { struct rbgtk_rval2gtkradiotoolbuttongslist_args args; args.ary = rb_ary_to_ary(value); args.n = RARRAY_LEN(args.ary); args.result = NULL; rb_rescue(rbgtk_rval2gtkradiotoolbuttongslist_body, (VALUE)&args, rbgtk_rval2gtkradiotoolbuttongslist_rescue, (VALUE)&args); return args.result; }
int io_read_callback(void * ctx, char * buffer, int len) { VALUE string, args[2]; args[0] = (VALUE)ctx; args[1] = INT2NUM(len); string = rb_rescue(read_check, (VALUE)args, read_failed, 0); if(NIL_P(string)) return 0; memcpy(buffer, StringValuePtr(string), (size_t)RSTRING_LEN(string)); return (int)RSTRING_LEN(string); }
void rb_exec_end_proc(void) { while (true) { const int count = RARRAY_LEN(at_exit_procs); if (count > 0) { VALUE proc = RARRAY_AT(at_exit_procs, count - 1); rb_ary_delete_at(at_exit_procs, count - 1); rb_rescue(rb_end_proc_call_try, proc, rb_end_proc_call_catch, 0); continue; } break; } }
static int template_execute_wrap(msgpack_unpack_t* mp, VALUE str, size_t dlen, size_t* from) { VALUE args[4] = { (VALUE)mp, (VALUE)RSTRING_PTR(str), (VALUE)dlen, (VALUE)from, }; #ifdef HAVE_RUBY_ENCODING_H int enc_orig = rb_enc_get_index(str); rb_enc_set_index(str, s_ascii_8bit); #endif // FIXME execute実行中はmp->topが更新されないのでGC markが機能しない rb_gc_disable(); mp->user.source = str; #ifdef HAVE_RUBY_ENCODING_H VALUE resc[2] = {str, enc_orig}; int ret = (int)rb_rescue(template_execute_do, (VALUE)args, template_execute_rescue_enc, (VALUE)resc); #else int ret = (int)rb_rescue(template_execute_do, (VALUE)args, template_execute_rescue, Qnil); #endif rb_gc_enable(); #ifdef HAVE_RUBY_ENCODING_H rb_enc_set_index(str, enc_orig); #endif return ret; }
VALUE cb_decode_value(VALUE blob, uint32_t flags, VALUE force_format) { VALUE val, args[3]; /* first it must be bytestring */ if (TYPE(blob) != T_STRING) { return Qundef; } args[0] = blob; args[1] = (VALUE)flags; args[2] = (VALUE)force_format; val = rb_rescue(do_decode, (VALUE)args, coding_failed, 0); return val; /* the value or exception object */ }
VALUE kernel_spec_rb_rescue(VALUE self, VALUE main_proc, VALUE arg, VALUE raise_proc, VALUE arg2) { VALUE main_array, raise_array; main_array = rb_ary_new(); rb_ary_push(main_array, main_proc); rb_ary_push(main_array, arg); raise_array = rb_ary_new(); rb_ary_push(raise_array, raise_proc); rb_ary_push(raise_array, arg2); return rb_rescue(kernel_spec_call_proc, main_array, kernel_spec_call_proc_with_raised_exc, raise_array); }
static GtkRadioActionEntry * rbg_rval2gtkradioactionentries(volatile VALUE *value, long *n) { struct rbg_rval2gtkradioactionentries_args args; args.ary = *value = rb_ary_dup(rb_ary_to_ary(*value)); args.n = RARRAY_LEN(args.ary); args.result = g_new0(GtkRadioActionEntry, args.n + 1); rb_rescue(rbg_rval2gtkradioactionentries_body, (VALUE)&args, rbg_rval2gtkradioactionentries_rescue, (VALUE)&args); *n = args.n; return args.result; }
GdkPoint * rbgdk_rval2gdkpoints(VALUE value, long *n) { struct rbgdk_rval2gdkpoints_args args; args.ary = rb_ary_to_ary(value); args.n = RARRAY_LEN(args.ary); args.result = g_new(GdkPoint, args.n + 1); rb_rescue(rbgdk_rval2gdkpoints_body, (VALUE)&args, rbgdk_rval2gdkpoints_rescue, (VALUE)&args); *n = args.n; return args.result; }
static void rb_gtk3_spin_button_input(RGClosureCallData *data) { InputData input_data; VALUE args; args = rb_ary_new_from_args(1, GVAL2RVAL(&(data->param_values[0]))); if (!NIL_P(data->extra_args)) { rb_ary_concat(args, data->extra_args); } input_data.data = data; input_data.args = args; input_data.new_value = g_value_get_pointer(&(data->param_values[1])); rb_rescue(rb_gtk3_spin_button_input_body, (VALUE)&input_data, rb_gtk3_spin_button_input_rescue, (VALUE)&input_data); }