/** * Convert either a String color name or a Magick::Pixel to a PixelPacket. * * No Ruby usage (internal function) * * @param pp the PixelPacket to modify * @param color the color name or Magick::Pixel */ void Color_to_PixelPacket(PixelPacket *pp, VALUE color) { Pixel *pixel; // Allow color name or Pixel if (CLASS_OF(color) == Class_Pixel) { Data_Get_Struct(color, Pixel, pixel); *pp = *pixel; } else { // require 'to_str' here instead of just 'to_s'. color = rb_rescue(rb_str_to_str, color, color_arg_rescue, color); Color_Name_to_PixelPacket(pp, color); } }
static const gsl_wavelet_type* rb_gsl_wavelet_get_type(VALUE t) { const gsl_wavelet_type *T; switch (TYPE(t)) { case T_STRING: T = rb_gsl_wavelet_get_type_str(STR2CSTR(t)); break; case T_FIXNUM: T = rb_gsl_wavelet_get_type_int(FIX2INT(t)); break; default: rb_raise(rb_eTypeError, "wrong type of argument %s (String or Fixnum expected)", rb_class2name(CLASS_OF(t))); break; } return T; }
VALUE rb_obj_methods(int argc, VALUE *argv, VALUE obj) { retry: if (argc == 0) { return class_instance_method_list(argc, argv, CLASS_OF(obj), 1, ins_methods_i); } else { VALUE recur; rb_scan_args(argc, argv, "1", &recur); if (RTEST(recur)) { argc = 0; goto retry; } return rb_obj_singleton_methods(argc, argv, obj); } }
void Init_Binding(void) { rb_cBinding = rb_define_class("Binding", rb_cObject); rb_undef_alloc_func(rb_cBinding); rb_undef_method(CLASS_OF(rb_cBinding), "new"); rb_objc_define_method(rb_cBinding, "clone", binding_clone, 0); rb_objc_define_method(rb_cBinding, "dup", binding_dup, 0); rb_objc_define_method(rb_cBinding, "eval", bind_eval, -1); rb_objc_define_module_function(rb_mKernel, "binding", rb_f_binding, 0); rb_vm_binding_t *binding = (rb_vm_binding_t *)xmalloc( sizeof(rb_vm_binding_t)); GC_WB(&binding->self, rb_vm_top_self()); binding->outer_stack = NULL; rb_define_global_const("TOPLEVEL_BINDING", rb_binding_new_from_binding(binding)); }
static VALUE bmcall(VALUE args, VALUE method) { volatile VALUE a; #if WITH_OBJC if (TYPE(args) != T_ARRAY) { return rb_method_call(1, &args, method); } #else if (CLASS_OF(args) != rb_cArray) { args = rb_ary_new3(1, args); } #endif a = args; return rb_method_call(RARRAY_LEN(a), (VALUE *)RARRAY_PTR(a), method); }
SEXP R_rb_class_instance_methods(SEXP r_obj, SEXP r_convert, SEXP super) { SEXP r_ans; VALUE args[1]; VALUE obj, ans; args[0] = LOGICAL(super)[0] ? Qtrue : Qfalse ; obj = getRubyObjectFromR(r_obj); if(TYPE(obj) == RUBY_T_OBJECT) obj = CLASS_OF(obj); obj = rb_cString; ans = rb_class_instance_methods(1, args, obj); return(convertRubyToR(ans, r_convert)); }
static VALUE rmitem_initialize(int argc, VALUE *argv, VALUE self) { VALUE arg1, arg2, arg3; GtkWidget *widget; GSList *list = NULL; const gchar *label = NULL; const gchar *mnemonic = NULL; if (rb_scan_args(argc, argv, "03", &arg1, &arg2, &arg3) > 0 && TYPE(arg1) == T_STRING) { if (NIL_P(arg2) || RVAL2CBOOL(arg2)) mnemonic = RVAL2CSTR(arg1); else label = RVAL2CSTR(arg1); } else { if (!NIL_P(arg2)) { if (NIL_P(arg3) || RVAL2CBOOL(arg3)) mnemonic = RVAL2CSTR(arg2); else label = RVAL2CSTR(arg2); } if (rb_obj_is_kind_of(arg1, GTYPE2CLASS(GTK_TYPE_RADIO_MENU_ITEM))) list = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(RVAL2GOBJ(arg1))); else if (TYPE(arg1) == T_ARRAY) /* TODO: This might leak. */ list = RVAL2GTKRADIOMENUITEMGSLIST(arg1); else if (!NIL_P(arg1)) rb_raise(rb_eArgError, "invalid argument %s (expect Array or Gtk::RadioMenuItem)", rb_class2name(CLASS_OF(arg1))); } if (label != NULL) widget = gtk_radio_menu_item_new_with_label(list, label); else if (mnemonic != NULL) widget = gtk_radio_menu_item_new_with_mnemonic(list, mnemonic); else widget = gtk_radio_menu_item_new(list); RBGTK_INITIALIZE(self, widget); return Qnil; }
static VALUE na_aref_md(int argc, VALUE *argv, VALUE self, int keep_dim, int result_nd) { VALUE args; // should be GC protected narray_t *na1; na_aref_md_data_t data; VALUE store = 0; VALUE idx; narray_t *nidx; GetNArray(self,na1); args = rb_ary_new4(argc,argv); if (argc == 1 && result_nd == 1) { idx = argv[0]; if (rb_obj_is_kind_of(idx, rb_cArray)) { idx = rb_apply(numo_cNArray,id_bracket,idx); } if (rb_obj_is_kind_of(idx, numo_cNArray)) { GetNArray(idx,nidx); if (NA_NDIM(nidx)>1) { store = nary_new(CLASS_OF(self),NA_NDIM(nidx),NA_SHAPE(nidx)); idx = na_flatten(idx); RARRAY_ASET(args,0,idx); } } // flatten should be done only for narray-view with non-uniform stride. if (na1->ndim > 1) { self = na_flatten(self); GetNArray(self,na1); } } data.args = args; data.self = self; data.store = store; data.ndim = result_nd; data.q = na_allocate_index_args(result_nd); data.na1 = na1; data.keep_dim = keep_dim; return rb_ensure(na_aref_md_protected, (VALUE)&data, na_aref_md_ensure, (VALUE)&data); }
void Init_ossl_engine() { cEngine = rb_define_class_under(mOSSL, "Engine", rb_cObject); eEngineError = rb_define_class_under(cEngine, "EngineError", eOSSLError); rb_define_alloc_func(cEngine, ossl_engine_s_alloc); rb_define_singleton_method(cEngine, "load", ossl_engine_s_load, -1); rb_define_singleton_method(cEngine, "cleanup", ossl_engine_s_cleanup, 0); rb_define_singleton_method(cEngine, "engines", ossl_engine_s_engines, 0); rb_define_singleton_method(cEngine, "by_id", ossl_engine_s_by_id, 1); rb_undef_method(CLASS_OF(cEngine), "new"); rb_define_method(cEngine, "id", ossl_engine_get_id, 0); rb_define_method(cEngine, "name", ossl_engine_get_name, 0); rb_define_method(cEngine, "finish", ossl_engine_finish, 0); rb_define_method(cEngine, "cipher", ossl_engine_get_cipher, 1); rb_define_method(cEngine, "digest", ossl_engine_get_digest, 1); rb_define_method(cEngine, "load_private_key", ossl_engine_load_privkey, -1); rb_define_method(cEngine, "load_public_key", ossl_engine_load_pubkey, -1); rb_define_method(cEngine, "set_default", ossl_engine_set_default, 1); rb_define_method(cEngine, "ctrl_cmd", ossl_engine_ctrl_cmd, -1); rb_define_method(cEngine, "cmds", ossl_engine_get_cmds, 0); rb_define_method(cEngine, "inspect", ossl_engine_inspect, 0); DefEngineConst(METHOD_RSA); DefEngineConst(METHOD_DSA); DefEngineConst(METHOD_DH); DefEngineConst(METHOD_RAND); #ifdef ENGINE_METHOD_BN_MOD_EXP DefEngineConst(METHOD_BN_MOD_EXP); #endif #ifdef ENGINE_METHOD_BN_MOD_EXP_CRT DefEngineConst(METHOD_BN_MOD_EXP_CRT); #endif #ifdef ENGINE_METHOD_CIPHERS DefEngineConst(METHOD_CIPHERS); #endif #ifdef ENGINE_METHOD_DIGESTS DefEngineConst(METHOD_DIGESTS); #endif DefEngineConst(METHOD_ALL); DefEngineConst(METHOD_NONE); }
static VALUE rb_gsl_multifit_ndlinear_design(int argc, VALUE *argv, VALUE obj) { gsl_multifit_ndlinear_workspace *w; gsl_matrix *vars = NULL, *X = NULL; int argc2, flag = 0, ret; switch (TYPE(obj)) { case T_MODULE: case T_CLASS: case T_OBJECT: if (!rb_obj_is_kind_of(argv[argc-1], cWorkspace)) { rb_raise(rb_eTypeError, "Wrong argument type %s (GSL::MultiFit::Ndlinear::Workspace expected)", rb_class2name(CLASS_OF(argv[argc-1]))); } Data_Get_Struct(argv[argc-1], gsl_multifit_ndlinear_workspace, w); argc2 = argc-1; break; default: Data_Get_Struct(obj, gsl_multifit_ndlinear_workspace, w); argc2 = argc; } switch (argc2) { case 1: CHECK_MATRIX(argv[0]); Data_Get_Struct(argv[0], gsl_matrix, vars); X = gsl_matrix_alloc(vars->size1, w->n_coeffs); flag = 1; break; case 2: CHECK_MATRIX(argv[0]); CHECK_MATRIX(argv[1]); Data_Get_Struct(argv[0], gsl_matrix, vars); Data_Get_Struct(argv[1], gsl_matrix, X); break; default: rb_raise(rb_eArgError, "Wrong number of arguments."); } ret = gsl_multifit_ndlinear_design(vars, X, w); if (flag == 1) { return Data_Wrap_Struct(cgsl_matrix, 0, gsl_matrix_free, X); } else { return INT2FIX(ret); } }
/* * call-seq: * graph.serialized_as( format, nshash={} ) -> string * * Return the graph serialized to a String in the specified +format+. Valid +format+s are keys * of the Hash returned by ::serializers. * * The +nshash+ argument can be used to set namespaces in the output (for serializers that * support them). It should be of the form: * * { :nsname => <namespace URI> } * * Examples: * turtle = graph.serialized_as( 'turtle' ) * xml = graph.serialized_as( 'rdfxml-abbrev', :foaf => 'http://xmlns.com/foaf/0.1/' ) * */ static VALUE rleaf_redleaf_graph_serialized_as( int argc, VALUE *argv, VALUE self ) { rleaf_GRAPH *ptr = rleaf_get_graph( self ); librdf_serializer *serializer; size_t length = 0; const char *formatname; unsigned char *serialized; VALUE format = Qnil; VALUE nshash = Qnil; rb_scan_args( argc, argv, "11", &format, &nshash ); rleaf_log_with_context( self, "debug", "Serializing as %s. Namespace hash is: %s", RSTRING_PTR(rb_inspect( format )), RSTRING_PTR(rb_inspect( nshash )) ); formatname = StringValuePtr( format ); rleaf_log_with_context( self, "debug", "trying to serialize as '%s'", formatname ); if ( !RTEST(rb_funcall(CLASS_OF(self), valid_format_p, 1, format)) ) rb_raise( rleaf_eRedleafFeatureError, "unsupported serialization format '%s'", formatname ); rleaf_log_with_context( self, "debug", "valid format '%s' specified.", formatname ); serializer = librdf_new_serializer( rleaf_rdf_world, formatname, NULL, NULL ); if ( !serializer ) rb_raise( rleaf_eRedleafError, "could not create a '%s' serializer", formatname ); /* Set namespaces in the serializer for entries in the argshash */ if ( RTEST(nshash) ) rb_iterate( rb_each, nshash, rleaf_set_serializer_ns, (VALUE)serializer ); /* :TODO: Support for the 'baseuri' argument? */ serialized = librdf_serializer_serialize_model_to_counted_string( serializer, NULL, ptr->model, &length ); librdf_free_serializer( serializer ); if ( !serialized ) rb_raise( rleaf_eRedleafError, "could not serialize model as '%s'", formatname ); rleaf_log_with_context( self, "debug", "got %d bytes of '%s'", length, formatname ); return rb_str_new( (char *)serialized, length ); }
static VALUE mSyslog_log(int argc, VALUE *argv, VALUE self) { VALUE pri; if (argc < 2) { rb_raise(rb_eArgError, "wrong number of arguments (%d for 2+)", argc); } argc--; pri = *argv++; if (!FIXNUM_P(pri)) { rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(pri))); } syslog_write(FIX2INT(pri), argc, argv); return self; }
static int add_method_iter(VALUE name, VALUE value, VALUE module) { NODE * n; rb_check_type(name, T_SYMBOL); if(!rb_obj_is_kind_of(value, rb_cNode)) { rb_raise( rb_eTypeError, "Expected Node, but got %s", rb_class2name(CLASS_OF(value))); } Data_Get_Struct(value, NODE, n); #if RUBY_VERSION_CODE >= 192 rb_raise(rb_eRuntimeError, "NOT SUPPORTED"); #else rb_add_method(module, SYM2ID(name), n->nd_body, n->nd_noex); #endif return ST_CONTINUE; }
static VALUE rb_gsl_fsolver_new(VALUE klass, VALUE t) { gsl_root_fsolver *s = NULL; const gsl_root_fsolver_type *T; char name[32]; switch (TYPE(t)) { case T_STRING: strcpy(name, STR2CSTR(t)); if (!str_tail_grep(name, "bisection")) { T = gsl_root_fsolver_bisection; } else if (!str_tail_grep(name, "falsepos")) { T = gsl_root_fsolver_falsepos; } else if (!str_tail_grep(name, "brent")) { T = gsl_root_fsolver_brent; } else { rb_raise(rb_eTypeError, "type must be \"bisection\" or \"falsepos\", or \"brent\"."); } break; case T_FIXNUM: switch (FIX2INT(t)) { case GSL_ROOT_FSOLVER_BISECTION: T = gsl_root_fsolver_bisection; break; case GSL_ROOT_FSOLVER_FALSEPOS: T = gsl_root_fsolver_falsepos; break; case GSL_ROOT_FSOLVER_BRENT: T = gsl_root_fsolver_brent; break; default: rb_raise(rb_eTypeError, "type must be BISECTION or FALSEPOS, or BRENT."); break; } break; default: rb_raise(rb_eTypeError, "wrong argument type %s (String or Fixnum expected)", rb_class2name(CLASS_OF(t))); break; } s = gsl_root_fsolver_alloc(T); return Data_Wrap_Struct(klass, 0, gsl_root_fsolver_free, s); }
static VALUE rb_thrift_struct_write(VALUE self, VALUE protocol) { // call validate rb_funcall(self, validate_method_id, 0); // check_native_proto_method_table(protocol); // write struct begin mt->write_struct_begin(protocol, rb_class_name(CLASS_OF(self))); // iterate through all the fields here VALUE struct_fields = STRUCT_FIELDS(self); VALUE struct_field_ids_unordered = rb_funcall(struct_fields, keys_method_id, 0); VALUE struct_field_ids_ordered = rb_funcall(struct_field_ids_unordered, sort_method_id, 0); int i = 0; for (i=0; i < RARRAY_LEN(struct_field_ids_ordered); i++) { VALUE field_id = rb_ary_entry(struct_field_ids_ordered, i); VALUE field_info = rb_hash_aref(struct_fields, field_id); VALUE ttype_value = rb_hash_aref(field_info, type_sym); int ttype = FIX2INT(ttype_value); VALUE field_name = rb_hash_aref(field_info, name_sym); VALUE field_value = get_field_value(self, field_name); if (!NIL_P(field_value)) { mt->write_field_begin(protocol, field_name, ttype_value, field_id); write_anything(ttype, field_value, protocol, field_info); mt->write_field_end(protocol); } } mt->write_field_stop(protocol); // write struct end mt->write_struct_end(protocol); return Qnil; }
static VALUE oci8_lob_clone(VALUE self) { oci8_lob_t *lob = TO_LOB(self); oci8_lob_t *newlob; VALUE newobj = lob->svcctx ? lob->svcctx->base.self : Qnil; boolean is_temporary; newobj = rb_class_new_instance(1, &newobj, CLASS_OF(self)); newlob = DATA_PTR(newobj); if (OCILobIsTemporary(oci8_envhp, oci8_errhp, lob->base.hp.lob, &is_temporary) == OCI_SUCCESS && is_temporary) { oci8_svcctx_t *svcctx = check_svcctx(lob); chker2(OCILobLocatorAssign_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob), &svcctx->base); } else { chker2(OCILobAssign(oci8_envhp, oci8_errhp, lob->base.hp.lob, &newlob->base.hp.lob), &lob->base); } return newobj; }
/* Document-class: LDAP::Entry * * These methods can be used to probe the entries returned by LDAP searches. */ void Init_ldap_entry () { rb_cLDAP_Entry = rb_define_class_under (rb_mLDAP, "Entry", rb_cObject); rb_define_const (rb_mLDAP, "Message", rb_cLDAP_Entry); /* for compatibility */ rb_undef_method (CLASS_OF (rb_cLDAP_Entry), "new"); rb_undef_alloc_func (rb_cLDAP_Entry); rb_ldap_entry_define_method ("get_dn", rb_ldap_entry_get_dn, 0); rb_ldap_entry_define_method ("get_values", rb_ldap_entry_get_values, 1); rb_ldap_entry_define_method ("get_attributes", rb_ldap_entry_get_attributes, 0); rb_alias (rb_cLDAP_Entry, rb_intern ("dn"), rb_intern ("get_dn")); rb_alias (rb_cLDAP_Entry, rb_intern ("vals"), rb_intern ("get_values")); rb_alias (rb_cLDAP_Entry, rb_intern ("[]"), rb_intern ("get_values")); rb_alias (rb_cLDAP_Entry, rb_intern ("attrs"), rb_intern ("get_attributes")); rb_ldap_entry_define_method ("to_hash", rb_ldap_entry_to_hash, 0); rb_ldap_entry_define_method ("inspect", rb_ldap_entry_inspect, 0); }
static VALUE zipruby_archive_add_function(int argc, VALUE *argv, VALUE self) { VALUE name, mtime; struct zipruby_archive *p_archive; struct zip_source *zsource; struct read_proc *z; rb_scan_args(argc, argv, "11", &name, &mtime); rb_need_block(); Check_Type(name, T_STRING); if (NIL_P(mtime)) { mtime = rb_funcall(rb_cTime, rb_intern("now"), 0); } else if (!rb_obj_is_instance_of(mtime, rb_cTime)) { rb_raise(rb_eTypeError, "wrong argument type %s (expected Time)", rb_class2name(CLASS_OF(mtime))); } Data_Get_Struct(self, struct zipruby_archive, p_archive); Check_Archive(p_archive); if ((z = malloc(sizeof(struct read_proc))) == NULL) { zip_unchange_all(p_archive->archive); zip_unchange_archive(p_archive->archive); rb_raise(rb_eRuntimeError, "Add failed - %s: Cannot allocate memory", RSTRING_PTR(name)); } z->proc = rb_block_proc(); rb_ary_push(p_archive->sources, z->proc); z->mtime = TIME2LONG(mtime); if ((zsource = zip_source_proc(p_archive->archive, z)) == NULL) { free(z); rb_raise(Error, "Add failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive)); } if (zip_add(p_archive->archive, RSTRING_PTR(name), zsource) == -1) { zip_source_free(zsource); zip_unchange_all(p_archive->archive); zip_unchange_archive(p_archive->archive); rb_raise(Error, "Add file failed - %s: %s", RSTRING_PTR(name), zip_strerror(p_archive->archive)); } return Qnil; }
static VALUE rb_gsl_fdfsolver_new(VALUE klass, VALUE t) { gsl_root_fdfsolver *s = NULL; const gsl_root_fdfsolver_type *T; char name[32]; switch (TYPE(t)) { case T_STRING: strcpy(name, STR2CSTR(t)); if (!str_tail_grep(name, "newton")) { T = gsl_root_fdfsolver_newton; } else if (!str_tail_grep(name, "secant")) { T = gsl_root_fdfsolver_secant; } else if (!str_tail_grep(name, "steffenson")) { T = gsl_root_fdfsolver_steffenson; } else { rb_raise(rb_eTypeError, "type must be NEWTON or SECANT, or STEFFENSON."); } break; case T_FIXNUM: switch (FIX2INT(t)) { case GSL_ROOT_FDFSOLVER_NEWTON: T = gsl_root_fdfsolver_newton; break; case GSL_ROOT_FDFSOLVER_SECANT: T = gsl_root_fdfsolver_secant; break; case GSL_ROOT_FDFSOLVER_STEFFENSON: T = gsl_root_fdfsolver_steffenson; break; default: rb_raise(rb_eTypeError, "type must be NEWTON or SECANT, or STEFFENSON."); break; } break; default: rb_raise(rb_eTypeError, "wrong argument type %s (String or Fixnum expected)", rb_class2name(CLASS_OF(t))); break; } s = gsl_root_fdfsolver_alloc(T); return Data_Wrap_Struct(klass, 0, gsl_root_fdfsolver_free, s); }
/* :nodoc: */ VALUE rb_mod_init_copy(VALUE clone, VALUE orig) { rb_obj_init_copy(clone, orig); if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) { RBASIC(clone)->klass = rb_singleton_class_clone(orig); rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone); } RCLASS_SUPER(clone) = RCLASS_SUPER(orig); if (RCLASS_IV_TBL(orig)) { st_data_t id; if (RCLASS_IV_TBL(clone)) { st_free_table(RCLASS_IV_TBL(clone)); } RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(orig)); CONST_ID(id, "__classpath__"); st_delete(RCLASS_IV_TBL(clone), &id, 0); CONST_ID(id, "__classid__"); st_delete(RCLASS_IV_TBL(clone), &id, 0); } if (RCLASS_CONST_TBL(orig)) { if (RCLASS_CONST_TBL(clone)) { rb_free_const_table(RCLASS_CONST_TBL(clone)); } RCLASS_CONST_TBL(clone) = st_init_numtable(); st_foreach(RCLASS_CONST_TBL(orig), clone_const, (st_data_t)RCLASS_CONST_TBL(clone)); } if (RCLASS_M_TBL(orig)) { struct clone_method_data data; if (RCLASS_M_TBL(clone)) { rb_free_m_table(RCLASS_M_TBL(clone)); } data.tbl = RCLASS_M_TBL(clone) = st_init_numtable(); data.klass = clone; st_foreach(RCLASS_M_TBL(orig), clone_method, (st_data_t)&data); } return clone; }
static const gsl_min_fminimizer_type* rb_gsl_min_fminimizer_type_get(VALUE t) { char name[32]; switch (TYPE(t)) { case T_STRING: strcpy(name, STR2CSTR(t)); if (str_tail_grep(name, "goldensection") == 0) return gsl_min_fminimizer_goldensection; else if (str_tail_grep(name, "brent") == 0) return gsl_min_fminimizer_brent; #ifdef GSL_1_13_LATER else if (str_tail_grep(name, "quad_golden") == 0) return gsl_min_fminimizer_quad_golden; #endif else rb_raise(rb_eTypeError, "unknown type %s (goldensection, brent or quad_golden expected)", name); break; case T_FIXNUM: switch (FIX2INT(t)) { case GSL_MIN_FMINIMIZER_GOLDENSECTION: return gsl_min_fminimizer_goldensection; break; case GSL_MIN_FMINIMIZER_BRENT: return gsl_min_fminimizer_brent; break; #ifdef GSL_1_13_LATER case GSL_MIN_FMINIMIZER_QUAD_GOLDEN: return gsl_min_fminimizer_quad_golden; break; #endif default: rb_raise(rb_eTypeError, "unknown type (GOLDENSECION or BRENT or QUAD_GOLDEN expected)"); break; } break; default: rb_raise(rb_eTypeError, "wrong argument type %s (String of Fixnum)", rb_class2name(CLASS_OF(t))); break; } }
void rb_threadptr_error_print(rb_thread_t *volatile th, volatile VALUE errinfo) { volatile VALUE errat = Qundef; volatile int raised_flag = th->raised_flag; volatile VALUE eclass = Qundef, emesg = Qundef; if (NIL_P(errinfo)) return; rb_thread_raised_clear(th); TH_PUSH_TAG(th); if (TH_EXEC_TAG() == 0) { errat = rb_get_backtrace(errinfo); } else if (errat == Qundef) { errat = Qnil; } else if (eclass == Qundef || emesg != Qundef) { goto error; } if ((eclass = CLASS_OF(errinfo)) != Qundef) { VALUE e = rb_check_funcall(errinfo, rb_intern("message"), 0, 0); if (e != Qundef) { if (!RB_TYPE_P(e, T_STRING)) e = rb_check_string_type(e); emesg = e; } } if (rb_stderr_tty_p()) { if (0) warn_print("Traceback (most recent call last):\n"); print_backtrace(eclass, errat, TRUE); print_errinfo(eclass, errat, emesg); } else { print_errinfo(eclass, errat, emesg); print_backtrace(eclass, errat, FALSE); } error: TH_POP_TAG(); th->errinfo = errinfo; rb_thread_raised_set(th, raised_flag); }
static VALUE cr_glyph_to_s (VALUE self) { VALUE ret; ret = rb_str_new2 ("#<"); rb_str_cat2 (ret, rb_class2name (CLASS_OF (self))); rb_str_cat2 (ret, ": "); rb_str_cat2 (ret, "index="); rb_str_concat (ret, rb_inspect (cr_glyph_index (self))); rb_str_cat2 (ret, ", "); rb_str_cat2 (ret, "x="); rb_str_concat (ret, rb_inspect (cr_glyph_x (self))); rb_str_cat2 (ret, ", "); rb_str_cat2 (ret, "y="); rb_str_concat (ret, rb_inspect (cr_glyph_y (self))); rb_str_cat2 (ret, ">"); return ret; }
static VALUE exc_inspect(VALUE exc) { VALUE str, klass; klass = CLASS_OF(exc); exc = rb_obj_as_string(exc); if (RSTRING_LEN(exc) == 0) { return rb_str_dup(rb_class_name(klass)); } str = rb_str_buf_new2("#<"); klass = rb_class_name(klass); rb_str_buf_append(str, klass); rb_str_buf_cat(str, ": ", 2); rb_str_buf_append(str, exc); rb_str_buf_cat(str, ">", 1); return str; }
static VALUE obj_respond_to(int argc, VALUE *argv, VALUE obj) { VALUE mid, priv; ID id; rb_scan_args(argc, argv, "11", &mid, &priv); if (!(id = rb_check_id(&mid))) { if (!rb_method_basic_definition_p(CLASS_OF(obj), idRespond_to_missing)) { VALUE args[2]; args[0] = rb_to_symbol(mid); args[1] = priv; return rb_funcall2(obj, idRespond_to_missing, 2, args); } return Qfalse; } if (basic_obj_respond_to(obj, id, !RTEST(priv))) return Qtrue; return Qfalse; }
/* * Set the source of the amf reader to a StringIO object, creating a new one to * wrap the source if it's only a string */ void des_set_src(AMF_DESERIALIZER *des, VALUE src) { VALUE klass = CLASS_OF(src); if(klass == cStringIO) { VALUE str = rb_funcall(src, rb_intern("string"), 0); des->src = src; des->stream = RSTRING_PTR(str); des->pos = NUM2LONG(rb_funcall(src, rb_intern("pos"), 0)); des->size = RSTRING_LEN(str); } else if(klass == rb_cString) { VALUE args[1] = {src}; des->src = rb_class_new_instance(1, args, cStringIO); des->stream = RSTRING_PTR(src); des->pos = 0; des->size = RSTRING_LEN(src); } else { rb_raise(rb_eArgError, "Invalid source type to deserialize from"); } if(des->pos >= des->size) rb_raise(rb_eRangeError, "already at the end of the source"); }
static VALUE rb_condvar_wait(VALUE self, VALUE mutex_v) { ConditionVariable *condvar; Data_Get_Struct(self, ConditionVariable, condvar); if (CLASS_OF(mutex_v) != rb_cMutex) { /* interoperate with legacy mutex */ legacy_wait_args args; args.condvar = condvar; args.mutex = mutex_v; rb_iterate(legacy_exclusive_unlock, mutex_v, legacy_wait, (VALUE)&args); } else { Mutex *mutex; Data_Get_Struct(mutex_v, Mutex, mutex); wait_condvar(condvar, mutex); } return self; }
/* * call-seq: * solver[var] -> true or false * * Returns a value of specified variable if the SAT is satisfied. Raises an * exception if not. * */ static VALUE solver_ref_var(VALUE rslv, VALUE rvar) { csolver *cslv; cvariable *cvar; Data_Get_Struct(rslv, csolver, cslv); if(CLASS_OF(rvar) != rb_cVariable) { rb_raise(rb_eTypeError, "wrong argument type %s (expected Variable)", rb_obj_classname(rvar)); } check_model_available(cslv->result, 0); Data_Get_Struct(rvar, cvariable, cvar); switch(wrap_solver_ref_var(cslv->solver, cvar->value)) { case 0: return Qfalse; case 1: return Qtrue; } return Qnil; }
int rb_to_encoding_index(VALUE enc) { if (CLASS_OF(enc) != rb_cEncoding && TYPE(enc) != T_STRING) { return -1; } else { int idx = index_of_encoding((rb_encoding_t *)enc); if (idx >= 0) { return idx; } else if (NIL_P(enc = rb_check_string_type(enc))) { return -1; } if (!rb_enc_asciicompat(rb_enc_get(enc))) { return -1; } return rb_enc_find_index(StringValueCStr(enc)); } }
gsl_complex ary2complex(VALUE obj) { gsl_complex *z, c; switch (TYPE(obj)) { case T_ARRAY: GSL_SET_REAL(&c, NUM2DBL(rb_ary_entry(obj, 0))); GSL_SET_IMAG(&c, NUM2DBL(rb_ary_entry(obj, 1))); break; default: if (COMPLEX_P(obj)) { Data_Get_Struct(obj, gsl_complex, z); c = *z; } else { rb_raise(rb_eTypeError, "wrong argument type %s (Array or Complex expected)", rb_class2name(CLASS_OF(obj))); } break; } return c; }