/** * This method will check an array of strings for misspelled words. * This method needs a block to work proper. Each misspelled word is yielded, * a correct word as result from the block is assumed. * Common use: * * a = Aspell.new(...) * text = ... * a.correct_lines(text) { |badword| * puts "Error: #{badword}\n" * puts a.suggest(badword).join(" | ") * gets #the input is returned as right word * } * * @param ary the array of strings to check. * @result an array holding all lines with corrected words. */ static VALUE aspell_correct_lines(VALUE self, VALUE ary) { VALUE result = ary; if (rb_block_given_p()) { //create checker AspellSpeller *speller = get_speller(self); AspellDocumentChecker * checker = get_checker(speller); AspellToken token; //some tmp values VALUE vline, sline; VALUE word, rword; char *line; int count=RARRAY_LEN(ary); int c=0; //create new result array result = rb_ary_new(); //iterate over array while(c<count) { int offset=0; //fetch line vline = RARRAY_PTR(ary)[c]; //save line sline = rb_funcall(vline, rb_intern("dup"), 0); //c representation line = STR2CSTR(vline); //process line aspell_document_checker_process(checker, line, -1); //iterate over all misspelled words while (token = aspell_document_checker_next_misspelling(checker), token.len != 0) { //extract word by start/length qualifier word = rb_funcall(vline, rb_intern("[]"), 2, INT2FIX(token.offset), INT2FIX(token.len)); //get the right word from the block rword = rb_yield(word); //nil -> do nothing if(rword == Qnil) continue; //check for string if (TYPE(rword) != T_STRING) rb_raise(cAspellError, "%s", "Need a String to substitute"); //chomp the string rb_funcall(rword, rb_intern("chomp!"), 0); //empty string -> do nothing if(strlen(STR2CSTR(rword)) == 0) continue; //remember word for later suggestion aspell_speller_store_replacement(speller, STR2CSTR(word), -1, STR2CSTR(rword), -1); //substitute the word by replacement rb_funcall(sline, rb_intern("[]="), 3, INT2FIX(token.offset+offset), INT2FIX(token.len), rword); //adjust offset offset += strlen(STR2CSTR(rword))-strlen(STR2CSTR(word)); //printf("replace >%s< with >%s< (offset now %d)\n", STR2CSTR(word), STR2CSTR(rword), offset); } //push the substituted line to result rb_ary_push(result, sline); c++; } //free checker delete_aspell_document_checker(checker); } else { rb_raise(cAspellError, "%s", "No block given. How to correct?"); } return result; }
// // function to count the number of events for which amplitudes were generated. // // VALUE count_amps(VALUE __self, VALUE __file_name){ char *filename = STR2CSTR(__file_name); ifstream in_file; in_file.open(filename); int event = 0; complex<float> amp; while(!in_file.eof()){ event++; in_file.read((char*)&,sizeof(amp)); } return rb_int_new(event-1); }
static const gsl_rng_type* get_gsl_rng_type(VALUE t) { switch (TYPE(t)) { case T_STRING: return get_gsl_rng_type_name(STR2CSTR(t)); break; case T_FIXNUM: return get_gsl_rng_type_int(FIX2INT(t)); break; default: rb_raise(rb_eTypeError, "String or Fixnum expected"); } }
/** * Simple utility function to correct a file. * The file gets read, content will be checked and write back. * Please note: This method will change the file! - no backup and of course: no warranty! * @param filename the name of the file as String. * @exception Exception due to lack of read/write permissions. */ static VALUE aspell_correct_file(VALUE self, VALUE filename) { if (rb_block_given_p()) { VALUE content = rb_funcall(rb_cFile, rb_intern("readlines"), 1, filename); VALUE newcontent = aspell_correct_lines(self, content); VALUE file = rb_file_open(STR2CSTR(filename), "w+"); rb_funcall(file, rb_intern("write"), 1, newcontent); rb_funcall(file, rb_intern("close"), 0); } else { rb_raise(cAspellError, "%s", "No block given. How to correct?"); } return self; }
static VALUE rb_gsl_permutation_printf(int argc, VALUE *argv, VALUE obj) { gsl_permutation *h; int status; Data_Get_Struct(obj, gsl_permutation, h); if (argc == 0) { status = gsl_permutation_fprintf(stdout, h, "%u\n"); } else { Check_Type(argv[0], T_STRING); status = gsl_permutation_fprintf(stdout, h, STR2CSTR(argv[0])); } return INT2FIX(status); }
// service.setCustomThemes(regexps) // @param regexps string // @return nil static VALUE wrap_ma_set_custom_themes(VALUE self, VALUE vstring) { const char *cstring; geoword::MAPtr *pServicePtr; Data_Get_Struct(self, geoword::MAPtr, pServicePtr); Check_Type(vstring, T_STRING); cstring = STR2CSTR(vstring); if (*cstring != '\0') { (*pServicePtr)->setCustomThemes(cstring); } else { (*pServicePtr)->resetCustomThemes(); } return Qnil; }
VALUE rb_luxiobtree_get(VALUE self, VALUE _key) { LuxIO *ptr; Data_Get_Struct(self, LuxIO, ptr); char *key = STR2CSTR(_key); Lux::IO::data_t lux_key = {key, strlen(key)}; Lux::IO::data_t *lux_val = ptr->bt->get(&lux_key); if (lux_val) { return rb_str_new2((char *)lux_val->data); } return Qnil; }
VALUE rb_luxiobtree_open(VALUE self, VALUE _filename, VALUE _flag) { LuxIO *ptr; Data_Get_Struct(self, LuxIO, ptr); char *filename = STR2CSTR(_filename); int flag = NUM2INT(_flag); ptr->bt = new Lux::IO::Btree(Lux::IO::CLUSTER); if (ptr->bt->open(filename, flag)){ return Qtrue; } return Qnil; }
VALUE rb_yp_match(VALUE self, VALUE domain, VALUE map, VALUE inkey) { int res; char *val; int vallen; if( domain == Qnil ) { domain = rb_yp_get_default_domain(self); }; res = yp_match(STR2CSTR(domain), STR2CSTR(map), STR2CSTR(inkey), RSTRING(inkey)->len, &val, &vallen); rb_yp_check_yperr(res); if( vallen > 0 ) { return rb_tainted_str_new(val, vallen); } else { return Qnil; }; };
/** * Ctor for aspell objects: * Aspell.new(language, jargon, size, encoding) * Please note: All parameters are optional. If a parameter is omitted, a default value is assumed from * the environment (eg lang from $LANG). To retain default values, you can use nil * as value: to set only size: Aspell.new(nil, nil, "80") * @param language ISO639 language code plus optional ISO 3166 counry code as string (eg: "de" or "us_US") * @param jargon a special jargon of the selected language * @param size the size of the dictionary to chose (if there are options) * @param encoding the encoding to use * @exception Exception if the specified dictionary is not found. */ static VALUE aspell_s_new(int argc, VALUE *argv, VALUE klass) { VALUE vlang, vjargon, vsize, vencoding; const char *tmp; //aspell values AspellCanHaveError * ret; AspellSpeller * speller; AspellConfig * config; //create new config config = new_aspell_config(); //extract values rb_scan_args(argc, argv, "04", &vlang, &vjargon, &vsize, &vencoding); //language: if (RTEST(vlang)) set_option(config, "lang", STR2CSTR(vlang)); //jargon: if (RTEST(vjargon)) set_option(config, "jargon", STR2CSTR(vjargon)); //size: if (RTEST(vsize)) set_option(config, "size", STR2CSTR(vsize)); //encoding: if (RTEST(vencoding)) set_option(config, "encoding", STR2CSTR(vencoding)); //create speller: ret = new_aspell_speller(config); delete_aspell_config(config); if (aspell_error(ret) != 0) { tmp = strdup(aspell_error_message(ret)); delete_aspell_can_have_error(ret); rb_raise(cAspellError, "%s", tmp); } speller = to_aspell_speller(ret); //wrap pointer return Data_Wrap_Struct(klass, 0, aspell_free, speller); }
static VALUE connectionToString(VALUE self) { VALUE result = rb_str_new2("(CLOSED)"); ConnectionHandle *connection = NULL; Data_Get_Struct(self, ConnectionHandle, connection); if(connection->handle != 0) { VALUE database = rb_iv_get(self, "@database"), user = rb_iv_get(self, "@user"), file = rb_iv_get(database, "@file"); char text[256]; sprintf(text, "%s@%s (OPEN)", STR2CSTR(user), STR2CSTR(file)); result = rb_str_new2(text); } return(result); }
static const gsl_odeiv_step_type* rb_gsl_odeiv_step_type_get(VALUE tt) { const gsl_odeiv_step_type *T; int type; char name[64]; switch (TYPE(tt)) { case T_FIXNUM: type = FIX2INT(tt); switch (type) { case GSL_ODEIV_STEP_RK2: T = gsl_odeiv_step_rk2; break; case GSL_ODEIV_STEP_RK4: T = gsl_odeiv_step_rk4; break; case GSL_ODEIV_STEP_RKF45: T = gsl_odeiv_step_rkf45; break; case GSL_ODEIV_STEP_RKCK: T = gsl_odeiv_step_rkck; break; case GSL_ODEIV_STEP_RK8PD: T = gsl_odeiv_step_rk8pd; break; case GSL_ODEIV_STEP_RK2IMP: T = gsl_odeiv_step_rk2imp; break; case GSL_ODEIV_STEP_RK4IMP: T = gsl_odeiv_step_rk4imp; break; case GSL_ODEIV_STEP_BSIMP: T = gsl_odeiv_step_bsimp; break; case GSL_ODEIV_STEP_GEAR1: T = gsl_odeiv_step_gear1; break; case GSL_ODEIV_STEP_GEAR2: T = gsl_odeiv_step_gear2; break; case GSL_ODEIV_STEP_RK2SIMP: T = gsl_odeiv_step_rk2simp; break; default: rb_raise(rb_eArgError, "wrong argument type (Fixnum expected)"); break; } break; case T_STRING: strcpy(name, STR2CSTR(tt)); if (str_tail_grep(name, "rk2") == 0) T = gsl_odeiv_step_rk2; else if (str_tail_grep(name, "rk4") == 0) T = gsl_odeiv_step_rk4; else if (str_tail_grep(name, "rkf45") == 0) T = gsl_odeiv_step_rkf45; else if (str_tail_grep(name, "rkck") == 0) T = gsl_odeiv_step_rkck; else if (str_tail_grep(name, "rk8pd") == 0) T = gsl_odeiv_step_rk8pd; else if (str_tail_grep(name, "rk2imp") == 0) T = gsl_odeiv_step_rk2imp; else if (str_tail_grep(name, "rk4imp") == 0) T = gsl_odeiv_step_rk4imp; else if (str_tail_grep(name, "bsimp") == 0) T = gsl_odeiv_step_bsimp; else if (str_tail_grep(name, "gear1") == 0) T = gsl_odeiv_step_gear1; else if (str_tail_grep(name, "gear2") == 0) T = gsl_odeiv_step_gear2; else if (str_tail_grep(name, "rk2simp") == 0) T = gsl_odeiv_step_rk2simp; else { rb_raise(rb_eArgError, "wrong argument type %s", name); } break; default: rb_raise(rb_eArgError, "wrong argument type %s (String or Fixnum expected)", rb_class2name(CLASS_OF(tt))); break; } return T; }
static VALUE proj_initialize(VALUE self, VALUE proj_params){ _wrap_pj* wpj; int size = RARRAY(proj_params)->len; char** c_params = (char **) malloc(size*sizeof(char *)); VALUE *ptr = RARRAY(proj_params)->ptr; int i; for (i=0; i < size; i++, ptr++) c_params[i]= STR2CSTR(*ptr); Data_Get_Struct(self,_wrap_pj,wpj); wpj->pj = pj_init(size,c_params); if(wpj->pj == 0) rb_raise(rb_eArgError,"invalid initialization parameters"); free(c_params); return self; }
// service.getGeowordEntries(str) // @param str string // @return array of Geoword static VALUE wrap_ma_get_geoword_entries(VALUE self, VALUE vstring) { const char *cstring; geoword::MAPtr *pServicePtr; Data_Get_Struct(self, geoword::MAPtr, pServicePtr); Check_Type(vstring, T_STRING); cstring = STR2CSTR(vstring); std::map<ID, geoword::Geoword> geowords = (*pServicePtr)->getGeowordEntries(cstring); VALUE rb_geowords = rb_hash_new(); for (std::map<ID, geoword::Geoword>::iterator it = geowords.begin(); it != geowords.end(); it++) { rb_hash_aset(rb_geowords, INT2FIX((*it).first), _geoword_to_ruby_hash(&((*it).second))); } return rb_geowords; }
VALUE rh_new(VALUE tds_socket, VALUE sqlstring) { VALUE oSybRes; SYBRESULT *sybres; sybres = ALLOC(SYBRESULT); Data_Get_Struct(tds_socket, TDSSOCKET, sybres->tds); sybres->sqlstring=STR2CSTR(sqlstring); oSybRes = Data_Wrap_Struct(cResultHandle, 0, rh_free, sybres); rb_obj_call_init(oSybRes, 0, 0); return oSybRes; } // rh_new
/* This functions is used as a predicate function. Every function name for which it returns true will be removed from the blank object dictionary. */ VALUE blank_undef_if(VALUE name, VALUE klass) { VALUE mname = rb_funcall(name, rb_intern("to_s"), 0); VALUE methodRe = rb_str_new2("(?:^__)|(?:\\?$)|(?:^send$)|(?:^class$)"); if(rb_funcall(mname, rb_intern("match"), 1, methodRe) == Qnil) { rb_undef_method(klass, STR2CSTR(mname)); return Qtrue; } else { return Qfalse; } }
PyObject* rtopString(VALUE rString) { PyObject* pString; char* cString; char* cStringCopy; cString = STR2CSTR(rString); cStringCopy = malloc(strlen(cString) * sizeof(char)); strcpy(cStringCopy, cString); pString = PyString_FromString(cStringCopy); return pString; }
static VALUE lorcon_device_open(int argc, VALUE *argv, VALUE self) { struct rldev *rld; int ret = 0; int drivertype = INJ_NODRIVER; char *driver, *intf; VALUE rbdriver, rbintf; VALUE obj; rb_scan_args(argc, argv, "2", &rbintf, &rbdriver); driver = STR2CSTR(rbdriver); intf = STR2CSTR(rbintf); obj = Data_Make_Struct(cDevice, struct rldev, 0, lorcon_device_free, rld); drivertype = tx80211_resolvecard(driver); if (drivertype == INJ_NODRIVER) { rb_raise(rb_eArgError, "Lorcon did not recognize the specified driver"); return(Qnil); } if (tx80211_init(&rld->in_tx, intf, drivertype) < 0) { rb_raise(rb_eRuntimeError, "Lorcon could not initialize the interface: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } /* Open the interface to get a socket */ ret = tx80211_open(&rld->in_tx); if (ret < 0) { rb_raise(rb_eRuntimeError, "Lorcon could not open the interface: %s", tx80211_geterrstr(&rld->in_tx)); return(Qnil); } rb_obj_call_init(obj, 0, 0); return(obj); }
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); }
static VALUE rb_gsl_combination_printf(int argc, VALUE *argv, VALUE obj) { gsl_combination *h = NULL; int status; Data_Get_Struct(obj, gsl_combination, h); switch (argc) { case 0: status = gsl_combination_fprintf(stdout, h, "%u\n"); break; default: Check_Type(argv[0], T_STRING); status = gsl_combination_fprintf(stdout, h, STR2CSTR(argv[0])); break; } return INT2FIX(status); }
/* * PhysicsFS::File#write buffer, obj_size, num_objects * * return nil on failure or number of objects written. */ VALUE physfs_file_write (VALUE self, VALUE buf, VALUE objSize, VALUE objCount) { int result; PHYSFS_File *file; Data_Get_Struct (self, PHYSFS_File, file); if (file == 0) return Qnil; result = PHYSFS_write (file, STR2CSTR(buf), FIX2UINT(objSize), FIX2UINT(objCount)); if (result == -1) return Qnil; return INT2FIX(result); }
static VALUE dh_do(VALUE self, VALUE sqlstring) { TDSSOCKET *tds; Data_Get_Struct(rb_iv_get(self, "@tds_socket"), TDSSOCKET, tds); if(tds_submit_query(tds,STR2CSTR(sqlstring)) != TDS_SUCCEED) { rb_raise(rb_eRuntimeError, "SQL-query failed (1)"); } else { process_results(tds); } return Qnil; } // dh_do
static VALUE dh_init(int argc, VALUE* argv, VALUE self) { VALUE db_user, db_pass, db_args, db_name, db_host, tds_socket; TDSSOCKET *tds; /* Let's fill our variables... */ rb_scan_args(argc, argv, "2*", &db_user, &db_pass, &db_args); db_args = rb_ary_shift(db_args); if(db_args != Qnil) { db_args = rb_str_split(db_args, ":"); db_name = rb_ary_entry(db_args, 0); db_host = rb_ary_entry(db_args, 1); } if(db_host == Qnil) { db_host = rb_str_new2("localhost"); } /* Get a TDSSOCKET */ tds_socket = tdss_new(db_host, db_user, db_pass); rb_iv_set(self, "@tds_socket", tds_socket); Data_Get_Struct(tds_socket, TDSSOCKET, tds); /* If the user submited a database-name, change to it */ if(db_name != Qnil) { if(tds_submit_query(tds,STR2CSTR(rb_str_concat(rb_str_new2("USE "), db_name))) != TDS_SUCCEED) { rb_raise(rb_eRuntimeError, "SQL-USE failed (1)"); } else { process_results(tds); } } return self; } // dh_init
const gsl_interp_type* get_interp_type(VALUE t) { int type; char name[32]; switch (TYPE(t)) { case T_FIXNUM: type = FIX2INT(t); switch (type) { case GSL_INTERP_LINEAR: return gsl_interp_linear; break; #ifdef GSL_1_1_LATER case GSL_INTERP_POLYNOMIAL: return gsl_interp_polynomial; break; #endif case GSL_INTERP_CSPLINE: return gsl_interp_cspline; break; case GSL_INTERP_CSPLINE_PERIODIC: return gsl_interp_cspline_periodic; break; case GSL_INTERP_AKIMA: return gsl_interp_akima; break; case GSL_INTERP_AKIMA_PERIODIC: return gsl_interp_akima_periodic; break; default: rb_raise(rb_eTypeError, "unknown type %d\n", type); break; } break; case T_STRING: strcpy(name, STR2CSTR(t)); if (str_tail_grep(name, "linear") == 0) { return gsl_interp_linear; #ifdef GSL_1_1_LATER } else if (str_tail_grep(name, "polynomial") == 0) { return gsl_interp_polynomial; #endif } else if (str_tail_grep(name, "cspline") == 0) { return gsl_interp_cspline; } else if (str_tail_grep(name, "cspline_periodic") == 0) { return gsl_interp_cspline_periodic; } else if (str_tail_grep(name, "akima") == 0) { return gsl_interp_akima; } else if (str_tail_grep(name, "akima_periodic") == 0) { return gsl_interp_akima_periodic; } else { rb_raise(rb_eTypeError, "Unknown type"); } break; default: rb_raise(rb_eTypeError, "Unknown type"); break; } }
static const gsl_multimin_fdfminimizer_type* get_fdfminimizer_type(VALUE t) { char name[64]; switch (TYPE(t)) { case T_STRING: strcpy(name, STR2CSTR(t)); if (str_tail_grep(name, "conjugate_fr") == 0) return gsl_multimin_fdfminimizer_conjugate_fr; else if (str_tail_grep(name, "conjugate_pr") == 0) return gsl_multimin_fdfminimizer_conjugate_pr; else if (str_tail_grep(name, "vector_bfgs") == 0) return gsl_multimin_fdfminimizer_vector_bfgs; else if (str_tail_grep(name, "steepest_descent") == 0) return gsl_multimin_fdfminimizer_steepest_descent; #ifdef GSL_1_9_LATER else if (str_tail_grep(name, "vector_bfgs2") == 0) return gsl_multimin_fdfminimizer_vector_bfgs2; #endif else rb_raise(rb_eTypeError, "%s: unknown minimizer type", name); break; case T_FIXNUM: switch (FIX2INT(t)) { case GSL_FDFMINIMIZER_CONJUGATE_FR: return gsl_multimin_fdfminimizer_conjugate_fr; break; case GSL_FDFMINIMIZER_CONJUGATE_PR: return gsl_multimin_fdfminimizer_conjugate_pr; break; case GSL_FDFMINIMIZER_VECTOR_BFGS: return gsl_multimin_fdfminimizer_vector_bfgs; break; case GSL_FDFMINIMIZER_STEEPEST_DESCENT: return gsl_multimin_fdfminimizer_steepest_descent; break; #ifdef GSL_1_9_LATER case GSL_FDFMINIMIZER_VECTOR_BFGS2: return gsl_multimin_fdfminimizer_vector_bfgs2; break; #endif default: rb_raise(rb_eTypeError, "%d: unknown type", FIX2INT(t)); break; } break; default: rb_raise(rb_eTypeError, "type is given by a String or a Fixnum"); break; } }
static VALUE with_image(VALUE self, VALUE _input) { char * input = STR2CSTR(_input); FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; fif = FreeImage_GetFileType(input, 0); if (fif == FIF_UNKNOWN) fif = FreeImage_GetFIFFromFilename(input); if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { FIBITMAP *bitmap; VALUE result = Qnil; int flags = fif == FIF_JPEG ? JPEG_ACCURATE : 0; if (bitmap = FreeImage_Load(fif, input, flags)) { result = wrap_and_yield(bitmap, self, fif); } return (result); } rb_raise(rb_eTypeError, "Unknown file format"); }
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; }
static VALUE fortran_file_close(int argc, VALUE *argv, VALUE klass) { VALUE vlun, vstatus; int lun; char *status; rb_scan_args(argc, argv, "11", &vlun, &vstatus); lun = FIX2INT(vlun); if (NIL_P(vstatus)) status = "KEEP"; else status = STR2CSTR(vstatus); fortfileclose_(&lun, status, strlen(status)); return Qnil; }
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 char* value_to_cstr(VALUE value) { VALUE str; char* result = NULL; int max; if(RTEST(value)) { str = value; if( TYPE(str) != T_STRING ) { str = rb_str_to_str(str); } str = StringValue(value); max = RSTRING(str)->len; result = malloc(max+1); bzero(result, max+1); strncpy(result, STR2CSTR(str), max); } return result; }