/* * call-seq: * Rebase.commit(author = nil, committer, message = nil) * * Commit the current patch. Any conflicts must have been resolved. * * If +author+ is +nil+, the existing author for the commit will be * used. If +message+ is +nil+, the existing message will be used. */ static VALUE rb_git_rebase_commit(int argc, VALUE *argv, VALUE self) { int error; git_oid id; git_rebase *rebase; git_signature *author = NULL, *committer; const char *message = NULL; VALUE rb_options, rb_author, rb_committer, rb_message; Data_Get_Struct(self, git_rebase, rebase); rb_scan_args(argc, argv, ":", &rb_options); Check_Type(rb_options, T_HASH); rb_author = rb_hash_aref(rb_options, CSTR2SYM("author")); rb_committer = rb_hash_aref(rb_options, CSTR2SYM("committer")); rb_message = rb_hash_aref(rb_options, CSTR2SYM("message")); if (!NIL_P(rb_message)) { Check_Type(rb_message, T_STRING); message = StringValueCStr(rb_message); } if (NIL_P(rb_committer)) rb_raise(rb_eArgError, "Expected non-nil committer"); else committer = rugged_signature_get(rb_committer, NULL); if (!NIL_P(rb_author)) author = rugged_signature_get(rb_author, NULL); error = git_rebase_commit(&id, rebase, author, committer, NULL, message); git_signature_free(author); git_signature_free(committer); rugged_exception_check(error); return rugged_create_oid(&id); }
static void parse_rebase_options(git_rebase_options *ret, VALUE rb_options) { VALUE val; if (NIL_P(rb_options)) return; val = rb_hash_aref(rb_options, CSTR2SYM("quiet")); ret->quiet = RTEST(val); val = rb_hash_aref(rb_options, CSTR2SYM("inmemory")); ret->inmemory = RTEST(val); val = rb_hash_aref(rb_options, CSTR2SYM("rewrite_notes_ref")); if (!NIL_P(val)) { Check_Type(val, T_STRING); ret->rewrite_notes_ref = StringValueCStr(val); } rugged_parse_checkout_options(&ret->checkout_options, rb_options); rugged_parse_merge_options(&ret->merge_options, rb_options); }
/* * call-seq: * IplImage::load(<i>filename[,iscolor = CV_LOAD_IMAGE_COLOR]</i>) * * Load an image from file. * iscolor = CV_LOAD_IMAGE_COLOR, the loaded image is forced to be a 3-channel color image * iscolor = CV_LOAD_IMAGE_GRAYSCALE, the loaded image is forced to be grayscale * iscolor = CV_LOAD_IMAGE_UNCHANGED, the loaded image will be loaded as is. * Currently the following file format are supported. * * Windows bitmaps - BMP,DIB * * JPEG files - JPEG,JPG,JPE * * Portable Network Graphics - PNG * * Portable image format - PBM,PGM,PPM * * Sun rasters - SR,RAS * * TIFF files - TIFF,TIF */ VALUE rb_load_image(int argc, VALUE *argv, VALUE self) { VALUE filename, iscolor; rb_scan_args(argc, argv, "11", &filename, &iscolor); Check_Type(filename, T_STRING); int _iscolor; if (TYPE(iscolor) == T_NIL) { _iscolor = CV_LOAD_IMAGE_COLOR; } else { Check_Type(iscolor, T_FIXNUM); _iscolor = FIX2INT(iscolor); } IplImage *image; if ((image = cvLoadImage(StringValueCStr(filename), _iscolor)) == NULL) { rb_raise(rb_eStandardError, "file does not exist or invalid format image."); } return OPENCV_OBJECT(rb_klass, image); }
static VALUE rdwarf_initialize(VALUE self, VALUE filename) { rdwarf_t *rd = GetRDwarf(self); Dwarf_Debug dbg; Dwarf_Error err; int fd; int ret; SafeStringValue(filename); filename = rb_str_export_to_enc(filename, rb_filesystem_encoding()); fd = rb_cloexec_open(StringValueCStr(filename), O_RDONLY, 0); if (fd < 0) { rb_sys_fail("open"); } ret = dwarf_init(fd, DW_DLC_READ, NULL, NULL, &dbg, &err); if (ret != DW_DLV_OK) { rb_raise(rd_eError, "%s", dwarf_errmsg(err)); } rd->shared_data = rd_shared_data_alloc(dbg, fd, self); return self; }
/* * call-seq: * XML::Node.new_comment(content = nil) -> XML::Node * * Create a new comment node, optionally setting * the node's content. * */ static VALUE rxml_node_new_comment(int argc, VALUE *argv, VALUE klass) { VALUE content = Qnil; xmlNodePtr xnode; rb_scan_args(argc, argv, "01", &content); if (NIL_P(content)) { xnode = xmlNewComment(NULL); } else { content = rb_obj_as_string(content); xnode = xmlNewComment((xmlChar*) StringValueCStr(content)); } if (xnode == NULL) rxml_raise(&xmlLastError); return rxml_node_wrap(klass, xnode); }
static VALUE foreach(VALUE self, VALUE filename) { FILE *file = fopen(StringValueCStr(filename), "r"); if (file == NULL) rb_raise(rb_eRuntimeError, "File not found"); char *line = NULL; size_t len = 0; char *token; int idx; VALUE ary; while (getline(&line, &len, file) != -1) { ary = rb_ary_new(); token = strtok(line, DELIMITERS); idx = 0; while (token != NULL) { rb_ary_store(ary, idx, rb_str_new(token, strlen(token))); idx ++; token = strtok(NULL, DELIMITERS); } /* OBJ_FREEZE(ary); */ rb_yield(ary); /* FL_UNSET((ary), FL_FREEZE); */ /* for(idx = 0; idx < RARRAY_LEN(ary); idx ++) { rb_ary_store(ary, idx, Qnil); } */ } fclose(file); return Qnil; }
/* * call-seq: * context.find("xpath") -> XML::XPath::Object * * Find nodes matching the specified XPath expression */ static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr) { xmlXPathContextPtr xctxt; xmlXPathObjectPtr xobject; xmlXPathCompExprPtr xcompexpr; VALUE result; Data_Get_Struct(self, xmlXPathContext, xctxt); if (TYPE(xpath_expr) == T_STRING) { VALUE expression = rb_check_string_type(xpath_expr); xobject = xmlXPathEval((xmlChar*) StringValueCStr(expression), xctxt); } else if (rb_obj_is_kind_of(xpath_expr, cXMLXPathExpression)) { Data_Get_Struct(xpath_expr, xmlXPathCompExpr, xcompexpr); xobject = xmlXPathCompiledEval(xcompexpr, xctxt); } else { rb_raise(rb_eTypeError, "Argument should be an intance of a String or XPath::Expression"); } if (xobject == NULL) { /* xmlLastError is different than xctxt->lastError. Use xmlLastError since it has the message set while xctxt->lastError does not. */ xmlErrorPtr xerror = xmlGetLastError(); rxml_raise(xerror); } result = rxml_xpath_object_wrap(xobject); rb_iv_set(result, "@context", self); return result; }
/* * call-seq: * obj.notes(notes_ref = 'refs/notes/commits') -> hash * * Lookup a note for +obj+ from +notes_ref+: * - +notes_ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits" * * Returns a new Hash object. * * obj.notes #=> {:message=>"note text\n", :oid=>"94eca2de348d5f672faf56b0decafa5937e3235e"} */ static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self) { git_repository *repo; const char *notes_ref = NULL; VALUE rb_notes_ref; VALUE rb_note_hash; VALUE owner; git_note *note; git_object *object; int error; rb_scan_args(argc, argv, "01", &rb_notes_ref); if (!NIL_P(rb_notes_ref)) { Check_Type(rb_notes_ref, T_STRING); notes_ref = StringValueCStr(rb_notes_ref); } Data_Get_Struct(self, git_object, object); owner = rugged_owner(self); Data_Get_Struct(owner, git_repository, repo); error = git_note_read(¬e, repo, notes_ref, git_object_id(object)); if (error == GIT_ENOTFOUND) return Qnil; rugged_exception_check(error); rb_note_hash = rb_hash_new(); rb_hash_aset(rb_note_hash, CSTR2SYM("message"), rugged_git_note_message(note)); rb_hash_aset(rb_note_hash, CSTR2SYM("oid"), rugged_git_note_oid(note)); git_note_free(note); return rb_note_hash; }
/* call-seq: * XML::Reader.io(io) -> XML::Reader * XML::Reader.io(io, :encoding => XML::Encoding::UTF_8, * :options => XML::Parser::Options::NOENT) -> XML::Parser * * Creates a new reader by parsing the specified io object. * * You may provide an optional hash table to control how the * parsing is performed. Valid options are: * * base_uri - The base url for the parsed document. * encoding - The document encoding, defaults to nil. Valid values * are the encoding constants defined on XML::Encoding. * options - Controls the execution of the parser, defaults to 0. * Valid values are the constants defined on * XML::Parser::Options. Mutliple options can be combined * by using Bitwise OR (|). */ static VALUE rxml_reader_io(int argc, VALUE *argv, VALUE klass) { xmlTextReaderPtr xreader; VALUE io; VALUE options; char *xbaseurl = NULL; const char *xencoding = NULL; int xoptions = 0; rb_scan_args(argc, argv, "11", &io, &options); if (!NIL_P(options)) { VALUE baseurl = Qnil; VALUE encoding = Qnil; VALUE parserOptions = Qnil; Check_Type(options, T_HASH); baseurl = rb_hash_aref(options, base_uri_SYMBOL); xbaseurl = NIL_P(baseurl) ? NULL : StringValueCStr(baseurl); encoding = rb_hash_aref(options, ENCODING_SYMBOL); xencoding = NIL_P(encoding) ? NULL : xmlGetCharEncodingName(NUM2INT(encoding)); parserOptions = rb_hash_aref(options, OPTIONS_SYMBOL); xoptions = NIL_P(parserOptions) ? 0 : NUM2INT(parserOptions); } xreader = xmlReaderForIO((xmlInputReadCallback) rxml_read_callback, NULL, (void *) io, xbaseurl, xencoding, xoptions); if (xreader == NULL) rxml_raise(&xmlLastError); return rxml_reader_wrap(xreader); }
static void * initFunc(xsltTransformContextPtr ctxt, const xmlChar *uri) { VALUE modules = rb_iv_get(xslt, "@modules"); VALUE obj = rb_hash_aref(modules, rb_str_new2((const char *)uri)); VALUE args = { Qfalse }; VALUE methods = rb_funcall(obj, rb_intern("instance_methods"), 1, args); VALUE inst; nokogiriXsltStylesheetTuple *wrapper; int i; for(i = 0; i < RARRAY_LEN(methods); i++) { VALUE method_name = rb_obj_as_string(rb_ary_entry(methods, i)); xsltRegisterExtFunction(ctxt, (unsigned char *)StringValueCStr(method_name), uri, method_caller); } Data_Get_Struct(ctxt->style->_private, nokogiriXsltStylesheetTuple, wrapper); inst = rb_class_new_instance(0, NULL, obj); rb_ary_push(wrapper->func_instances, inst); return (void *)inst; }
static VALUE remove_buddy(VALUE self, VALUE buddy) { PurpleAccount *account; Data_Get_Struct(self, PurpleAccount, account); PurpleBuddy* pb = purple_find_buddy(account, StringValueCStr(buddy)); if (NULL == pb) { rb_raise(rb_eRuntimeError, "Failed to remove buddy for %s : %s does not exist", purple_account_get_username(account), StringValueCStr(buddy)); } char* group = _("Buddies"); PurpleGroup* grp = purple_find_group(group); if (!grp) { grp = purple_group_new(group); purple_blist_add_group(grp, NULL); } purple_blist_remove_buddy(pb); purple_account_remove_buddy(account, pb, grp); return Qtrue; }
/* * call-seq: * LinkParser::Sentence.new( str, dict ) -> sentence * * Create a new LinkParser::Sentence object from the given input string # using the specified LinkParser::Dictionary. * * dict = LinkParser::Dictionary.new * LinkParser::Sentence.new( "The boy runs", dict ) #=> #<LinkParser::Sentence:0x5481ac> */ static VALUE rlink_sentence_init( VALUE self, VALUE input_string, VALUE dictionary ) { if ( !check_sentence(self) ) { struct rlink_sentence *ptr; Sentence sent; struct rlink_dictionary *dictptr = rlink_get_dict( dictionary ); if ( !(sent = sentence_create( StringValueCStr(input_string), dictptr->dict )) ) rlink_raise_lp_error(); DATA_PTR( self ) = ptr = rlink_sentence_alloc(); ptr->sentence = sent; ptr->dictionary = dictionary; ptr->options = Qnil; } else { rb_raise( rb_eRuntimeError, "Cannot re-initialize a sentence once it's been created." ); } return self; }
static VALUE Font_initialize(VALUE self, VALUE rbRealFilePath, VALUE rbSize, VALUE rbBold, VALUE rbItalic, VALUE rbTtcIndex) { const char* path = StringValueCStr(rbRealFilePath); const int size = NUM2INT(rbSize); const bool bold = RTEST(rbBold); const bool italic = RTEST(rbItalic); const int ttcIndex = NUM2INT(rbTtcIndex); Font* font; Data_Get_Struct(self, Font, font); font->size = size; font->sdlFont = TTF_OpenFontIndex(path, size, ttcIndex); if (!font->sdlFont) { rb_raise(strb_GetStarRubyErrorClass(), "%s (%s)", TTF_GetError(), path); } const int style = TTF_STYLE_NORMAL | (bold ? TTF_STYLE_BOLD : 0) | (italic ? TTF_STYLE_ITALIC : 0); TTF_SetFontStyle(font->sdlFont, style); return Qnil; }
/* * call-seq: * remotes.create_anonymous(url) -> remote * * Return a new remote with +url+ in +repository+ , the remote is not persisted: * - +url+: a valid remote url * * Returns a new Rugged::Remote object. * * @repo.remotes.create_anonymous('git://github.com/libgit2/libgit2.git') #=> #<Rugged::Remote:0x00000001fbfa80> */ static VALUE rb_git_remote_collection_create_anonymous(VALUE self, VALUE rb_url) { git_remote *remote; git_repository *repo; int error; VALUE rb_repo = rugged_owner(self); rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); Check_Type(rb_url, T_STRING); error = git_remote_create_anonymous( &remote, repo, StringValueCStr(rb_url), NULL); rugged_exception_check(error); return rugged_remote_new(rb_repo, remote); }
/* * call-seq: * Settings[option] -> value * * Gets the value of a libgit2 library option. */ static VALUE rb_git_get_option(VALUE self, VALUE option) { const char *opt; Check_Type(option, T_STRING); opt = StringValueCStr(option); if (strcmp(opt, "mwindow_size") == 0) { size_t val; git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &val); return SIZET2NUM(val); } else if (strcmp(opt, "mwindow_mapped_limit") == 0) { size_t val; git_libgit2_opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, &val); return SIZET2NUM(val); } else { rb_raise(rb_eArgError, "Unknown option specified"); } }
static struct ngraph_array * allocate_sarray(VALUE self, volatile VALUE *tmpstr, VALUE arg, const char *field) { struct ngraph_array *narray; int i, num; VALUE str; VALUE ary; ary = get_array_arg(self, field, arg, &num); narray = rb_alloc_tmp_buffer(tmpstr, sizeof(*narray) + sizeof(ngraph_value) * num); if (narray == NULL) { return NULL; } narray->num = num; for (i = 0; i < num; i++) { str = rb_ary_entry(ary, i); narray->ary[i].str = StringValueCStr(str); } return narray; }
/* * call-seq: * reader[key] -> value * * Provide the value of the attribute with the specified index (if +key+ is an * integer) or with the specified name (if +key+ is a string) relative to the * containing element, as a string. */ static VALUE rxml_reader_attribute(VALUE self, VALUE key) { VALUE result = Qnil; xmlChar *xattr; xmlTextReaderPtr xReader = rxml_text_reader_get(self); const xmlChar *xencoding = xmlTextReaderConstEncoding(xReader); if (TYPE(key) == T_FIXNUM) { xattr = xmlTextReaderGetAttributeNo(xReader, FIX2INT(key)); } else { xattr = xmlTextReaderGetAttribute(xReader, (const xmlChar *) StringValueCStr(key)); } if (xattr) { result = rxml_new_cstr(xattr, xencoding); xmlFree(xattr); } return result; }
static VALUE inst_put_str(VALUE self, VALUE arg, const char *field) { struct ngraph_instance *inst; ngraph_value str; inst = check_id(self); if (inst == NULL) { return Qnil; } if (NIL_P(arg)) { str.str = NULL; } else { str.str = StringValueCStr(arg); } inst->rcode = ngraph_object_put(inst->obj, field, inst->id, &str); if (inst->rcode < 0) { return Qnil; } return arg; }
/* * call-seq: * index.conflict_get(path) -> conflict or nil * * Return index entries from the ancestor, our side and their side of * the conflict at +path+. * * If +:ancestor+, +:ours+ or +:theirs+ is +nil+, that indicates that +path+ * did not exist in the respective tree. * * Returns nil if no conflict is present at +path+. */ static VALUE rb_git_conflict_get(VALUE self, VALUE rb_path) { VALUE rb_result = rb_hash_new(); git_index *index; const git_index_entry *ancestor, *ours, *theirs; int error; Check_Type(rb_path, T_STRING); Data_Get_Struct(self, git_index, index); error = git_index_conflict_get(&ancestor, &ours, &theirs, index, StringValueCStr(rb_path)); if (error == GIT_ENOTFOUND) return Qnil; else rugged_exception_check(error); rb_hash_aset(rb_result, CSTR2SYM("ancestor"), rb_git_indexentry_fromC(ancestor)); rb_hash_aset(rb_result, CSTR2SYM("ours"), rb_git_indexentry_fromC(ours)); rb_hash_aset(rb_result, CSTR2SYM("theirs"), rb_git_indexentry_fromC(theirs)); return rb_result; }
static VALUE console_key_pressed_p(VALUE io, VALUE k) { int vk = -1; if (FIXNUM_P(k)) { vk = NUM2UINT(k); } else { const struct vktable *t; if (SYMBOL_P(k)) { k = rb_sym2str(k); } else { StringValueCStr(k); } t = console_win32_vk(RSTRING_PTR(k), RSTRING_LEN(k)); if (!t || (vk = (short)t->vk) == -1) { rb_raise(rb_eArgError, "unknown virtual key code: %"PRIsVALUE, k); } } return GetKeyState(vk) & 0x80 ? Qtrue : Qfalse; }
/* * TermInfo.wcswidth(str) * * TermInfo.wcswidth returns a the number of columns of str, * according to current locale. */ static VALUE rt_wcswidth(VALUE self, VALUE str) { char *s; size_t l, r; mbstate_t mbs; wchar_t wc; long cols; int width; #ifdef HAVE_RUBY_ENCODING_H /* The encoding of str is assumed to be the locale encoding on Ruby 1.8. */ str = rb_str_encode(str, rb_enc_from_encoding(rb_locale_encoding()), 0, Qnil); #endif memset(&mbs,0,sizeof(mbstate_t)); s = StringValueCStr(str); l = RSTRING_LEN(str); cols = 0; while (0 < l) { r = mbrtowc(&wc, s, l, &mbs); if (r == 0) rb_raise(rb_eArgError, "NUL found"); width = wcwidth(wc); if (width == -1) rb_raise(rb_eArgError, "non-printable charactor found"); cols += width; l -= r; s += r; } return LONG2NUM(cols); }
VALUE check_file_png(VALUE _self, VALUE _filename) { if (!RB_TYPE_P(_filename, T_STRING)) { rb_raise(rb_eTypeError, "you need to provide a string"); } char hd[8]; char* fn = StringValueCStr(_filename); FILE* fd = fopen(fn, "rb"); if (!fd) { rb_raise(rb_eStandardError, "no such file!"); } int _bytes = fread(hd, 1, 8, fd); fclose(fd); if (!png_sig_cmp(hd, 0, 8)) return Qtrue; else return Qfalse; return Qnil; }
/* grpc_rb_op_update_status_from_server adds the values in a ruby status struct to the 'send_status_from_server' portion of an op. */ static void grpc_rb_op_update_status_from_server(grpc_op *op, grpc_metadata_array *md_ary, VALUE status) { VALUE code = rb_struct_aref(status, sym_code); VALUE details = rb_struct_aref(status, sym_details); VALUE metadata_hash = rb_struct_aref(status, sym_metadata); /* TODO: add check to ensure status is the correct struct type */ if (TYPE(code) != T_FIXNUM) { rb_raise(rb_eTypeError, "invalid code : got <%s>, want <Fixnum>", rb_obj_classname(code)); return; } if (TYPE(details) != T_STRING) { rb_raise(rb_eTypeError, "invalid details : got <%s>, want <String>", rb_obj_classname(code)); return; } op->data.send_status_from_server.status = NUM2INT(code); op->data.send_status_from_server.status_details = StringValueCStr(details); grpc_rb_md_ary_convert(metadata_hash, md_ary); op->data.send_status_from_server.trailing_metadata_count = md_ary->count; op->data.send_status_from_server.trailing_metadata = md_ary->metadata; }
static VALUE rpmmi_new(int argc, VALUE *argv, VALUE s) { VALUE v_ts, v_tag, v_key; rpmts ts; rpmTag _tag = RPMDBI_PACKAGES; void * _key = NULL; int _len = 0; rpmmi mi; rb_scan_args(argc, argv, "12", &v_ts, &v_tag, &v_key); ts = rpmmi_ptr(v_ts); if (!NIL_P(v_tag)) _tag = FIX2INT(v_tag); if (!NIL_P(v_key)) _key = StringValueCStr(v_key); mi = rpmtsInitIterator(ts, _tag, _key, _len); if (_debug) fprintf(stderr, "==> %s(%p[%d], 0x%lx) mi %p\n", __FUNCTION__, argv, argc, s, mi); return Data_Wrap_Struct(s, 0, rpmmi_free, mi); }
static char * ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz, int sign) { VALUE value, result = (VALUE)fp->_bf._base; rb_encoding *enc; char *cp; if (valsize != sizeof(VALUE)) return 0; value = *(VALUE *)valp; if (RBASIC(result)->klass) { rb_raise(rb_eRuntimeError, "rb_vsprintf reentered"); } if (sign == '+') { value = rb_inspect(value); } else { value = rb_obj_as_string(value); if (sign == ' ') value = QUOTE(value); } enc = rb_enc_compatible(result, value); if (enc) { rb_enc_associate(result, enc); } else { enc = rb_enc_get(result); value = rb_str_conv_enc_opts(value, rb_enc_get(value), enc, ECONV_UNDEF_REPLACE|ECONV_INVALID_REPLACE, Qnil); *(volatile VALUE *)valp = value; } StringValueCStr(value); RSTRING_GETMEM(value, cp, *sz); ((rb_printf_buffer_extra *)fp)->value = value; OBJ_INFECT(result, value); return cp; }
/* * call-seq: * submodules[name] -> submodule or nil * * Lookup +submodule+ by +name+ or +path+ (they are usually the same) in * +repository+. * * Returns +nil+ if submodule does not exist. * * Raises <tt>Rugged::SubmoduleError</tt> if submodule exists only in working * directory (i.e. there is a subdirectory that is a valid self-contained git * repository) and is not mentioned in the +HEAD+, the index and the config. */ static VALUE rb_git_submodule_collection_aref(VALUE self, VALUE rb_name) { git_repository *repo; git_submodule *submodule; int error; VALUE rb_repo = rugged_owner(self); Data_Get_Struct(rb_repo, git_repository, repo); Check_Type(rb_name, T_STRING); error = git_submodule_lookup( &submodule, repo, StringValueCStr(rb_name) ); if (error == GIT_ENOTFOUND) return Qnil; rugged_exception_check(error); return rugged_submodule_new(rb_repo, submodule); }
/* * call-seq: * Liblicense.licenses => array * * Returns array of all known licenses */ static VALUE rbll_licenses_get(int argc, VALUE *argv, VALUE klass) { VALUE licenses, juris; ll_uri_t *l; int i; NO_WARN_UNUSED( klass ); rb_scan_args(argc, argv, "01", &juris); if (juris != Qnil) l = ll_get_licenses(StringValueCStr(juris)); else l = ll_get_licenses(NULL); licenses = rb_ary_new(); i = 0; while (l != NULL && l[i] != NULL) { licenses = rb_ary_push(licenses, rb_str_new2(l[i])); i++; } ll_free_list(l); return licenses; }
VALUE csymbol_init(VALUE self, VALUE name_or_id) { const char *str_ptr; switch (TYPE(name_or_id)) { case T_STRING: str_ptr = StringValueCStr(name_or_id); break; case T_SYMBOL: str_ptr = rb_id2name(rb_to_id(name_or_id)); break; default: rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol or String)", rb_obj_classname(name_or_id)); } basic_struct *this; Data_Get_Struct(self, basic_struct, this); symbol_set(this, str_ptr); return self; }
/* * Load a Cryptoki library into process memory. * @see PKCS11::Library#initialize */ static VALUE pkcs11_load_library(VALUE self, VALUE path) { const char *so_path; pkcs11_ctx *ctx; so_path = StringValueCStr(path); Data_Get_Struct(self, pkcs11_ctx, ctx); #ifdef compile_for_windows if((ctx->module = LoadLibrary(so_path)) == NULL) { char error_text[999] = "LoadLibrary() error"; FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&error_text, sizeof(error_text), NULL); rb_raise(ePKCS11Error, "%s", error_text); } #else if((ctx->module = dlopen(so_path, RTLD_NOW)) == NULL) { rb_raise(ePKCS11Error, "%s", dlerror()); } #endif return self; }
/* * call-seq: * index[path[, stage = 0]] -> entry or nil * index[position] -> entry or nil * index.get(path[, stage = 0]) -> entry or nil * index.get(position) -> entry or nil * * Return a specific entry in the index. * * The first two forms returns entries based on their +path+ in the index and an optional +stage+, * while the last two forms return entries based on their position in the index. */ static VALUE rb_git_index_get(int argc, VALUE *argv, VALUE self) { git_index *index; const git_index_entry *entry = NULL; VALUE rb_entry, rb_stage; Data_Get_Struct(self, git_index, index); rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage); if (TYPE(rb_entry) == T_STRING) { int stage = 0; if (!NIL_P(rb_stage)) { Check_Type(rb_stage, T_FIXNUM); stage = FIX2INT(rb_stage); } entry = git_index_get_bypath(index, StringValueCStr(rb_entry), stage); } else if (TYPE(rb_entry) == T_FIXNUM) { if (argc > 1) { rb_raise(rb_eArgError, "Too many arguments when trying to lookup entry by index"); } entry = git_index_get_byindex(index, FIX2INT(rb_entry)); } else { rb_raise(rb_eArgError, "Invalid type for `entry`: expected String or Fixnum"); } return entry ? rb_git_indexentry_fromC(entry) : Qnil; }