static VALUE dh_equal(VALUE self, VALUE other) { // TODO: for == and ===, allow 'other' to be a subclass of Usb::Device // but keep the behavior of eql? the same return ( CLASS_OF(other) == cDeviceHandle && RDATA(self)->data == RDATA(other)->data ) ? Qtrue : Qfalse; }
static void rdata_finalize(void *rcv, SEL sel) { if (RDATA(rcv)->dfree != NULL && RDATA(rcv)->data != NULL) { RDATA(rcv)->dfree(RDATA(rcv)->data); RDATA(rcv)->data = NULL; } }
VALUE sws_change_struct(VALUE self, VALUE obj, VALUE new_val) { struct sample_wrapped_struct *old_struct, *new_struct; new_struct = (struct sample_wrapped_struct *)malloc(sizeof(struct sample_wrapped_struct)); new_struct->foo = FIX2INT(new_val); old_struct = RDATA(obj)->data; free(old_struct); RDATA(obj)->data = new_struct; return Qnil; }
void Init_hijack(void) { VALUE proc; rb_define_global_function("hijack", f_hijack, 0); proc = rb_eval_string("lambda {}"); blk_mark = (void (*)(struct BLOCK*)) RDATA(proc)->dmark; blk_free = (void (*)(struct BLOCK*)) RDATA(proc)->dfree; }
/* nodoc */ static VALUE rb_trie_node_initialize_copy(VALUE self, VALUE from) { RDATA(self)->data = trie_state_clone(RDATA(from)->data); VALUE state = rb_iv_get(from, "@state"); rb_iv_set(self, "@state", state == Qnil ? Qnil : rb_str_dup(state)); VALUE full_state = rb_iv_get(from, "@full_state"); rb_iv_set(self, "@full_state", full_state == Qnil ? Qnil : rb_str_dup(full_state)); return self; }
void wrap_Node_free (struct fs_node* ptr) { if(ptr){ VALUE vid = fs_node_get_script_id(ptr); if (vid != Qnil && RDATA(vid)->data) { RDATA(vid)->data = NULL; fs_node_set_script_id(ptr, Qnil); fs_free(ptr); } } }
/* * call-seq: * attr.remove! -> nil * * Removes this attribute from it's parent. Note * the attribute and its content is freed and can * no longer be used. If you try to use it you * will get a segmentation fault. */ static VALUE rxml_attr_remove_ex(VALUE self) { xmlAttrPtr xattr; Data_Get_Struct(self, xmlAttr, xattr); xmlRemoveProp(xattr); RDATA(self)->data = NULL; RDATA(self)->dfree = NULL; RDATA(self)->dmark = NULL; return Qnil; }
VALUE MHWorldBindings::DestroyInstance(VALUE rSelf) { MHWorld *cSelf = MHWorldBindings::Get()->getPointer(rSelf); // We're sort of taking over the free-up process, so nuke the ruby struct. RDATA(rSelf)->dmark = NULL; RDATA(rSelf)->dfree = NULL; RDATA(rSelf)->data = NULL; Free(cSelf); return Qnil; }
static void prof_call_info_ruby_gc_free(prof_call_info_t *call_info) { /* Has this thread object been accessed by Ruby? If yes clean it up so to avoid a segmentation fault. */ if (call_info->object != Qnil) { RDATA(call_info->object)->data = NULL; RDATA(call_info->object)->dfree = NULL; RDATA(call_info->object)->dmark = NULL; } call_info->object = Qnil; }
static void rxml_node_deregisterNode(xmlNodePtr xnode) { /* Has the node been wrapped and exposed to Ruby? */ if (xnode->_private) { /* Node was wrapped. Set the _private member to free and then dislabe the dfree function so that Ruby will not try to free the node a second time. */ VALUE node = (VALUE) xnode->_private; RDATA(node)->data = NULL; RDATA(node)->dfree = NULL; RDATA(node)->dmark = NULL; } }
static mrb_value pcre_regexp_match(mrb_state *mrb, mrb_value self) { const char *str; char global_match[3]; mrb_value regexp; struct mrb_pcre_regexp *reg; int i; mrb_value mrb_i, mrb_match; size_t nmatch = 999; int match[999]; int regno; int ai; struct RClass* clazz; mrb_value c; mrb_value args[2]; mrb_get_args(mrb, "z", &str); regexp = mrb_iv_get(mrb, self, mrb_intern_lit(mrb, "@regexp")); Data_Get_Struct(mrb, regexp, &mrb_pcre_regexp_type, reg); regno = pcre_exec(reg->re, NULL, str, strlen(str), 0, 0, match, nmatch); if (regno < 0) return mrb_nil_value(); mrb_obj_iv_set(mrb, (struct RObject *)mrb_class_real(RDATA(self)->c), mrb_intern_lit(mrb, "@last_match"), mrb_nil_value()); ai = mrb_gc_arena_save(mrb); clazz = mrb_class_get(mrb, "PcreMatchData"); c = mrb_obj_new(mrb, clazz, 0, NULL); mrb_iv_set(mrb, c,mrb_intern_lit(mrb, "@string"), mrb_str_new_cstr(mrb, str)); for (i = 0; i < regno; i++) { args[0] = mrb_fixnum_value(match[i * 2]); args[1] = mrb_fixnum_value(match[i * 2 + 1] - match[i * 2]); mrb_funcall_argv(mrb, c, mrb_intern_lit(mrb, "push"), sizeof(args)/sizeof(args[0]), &args[0]); if (i > 0 && i < 10) { sprintf(global_match, "$%i", i); mrb_i = mrb_fixnum_value(i); mrb_match = mrb_funcall_argv(mrb, c, mrb_intern_lit(mrb, "[]"), 1, &mrb_i); mrb_gv_set(mrb, mrb_intern_cstr(mrb, global_match), mrb_match); } mrb_gc_arena_restore(mrb, ai); } mrb_obj_iv_set(mrb, (struct RObject *)mrb_class_real(RDATA(self)->c), mrb_intern_lit(mrb, "@last_match"), c); return c; }
VALUE rxml_xpath_object_wrap(xmlDocPtr xdoc, xmlXPathObjectPtr xpop) { int i; rxml_xpath_object *rxpop = ALLOC(rxml_xpath_object); rxpop->xdoc =xdoc; rxpop->xpop = xpop; rxpop->nsnodes = rb_ary_new(); /* Find all the extra namespace nodes and wrap them. */ if (xpop->nodesetval && xpop->nodesetval->nodeNr) { for (i = 0;i < xpop->nodesetval->nodeNr; i++) { xmlNodePtr xnode = xpop->nodesetval->nodeTab[i]; if (xnode != NULL && xnode->type == XML_NAMESPACE_DECL) { VALUE ns = Qnil; xmlNsPtr xns = (xmlNsPtr)xnode; /* Get rid of libxml's -> next hack. The issue here is the rxml_namespace code assumes that ns->next refers to another namespace. */ xns->next = NULL; /* Specify a custom free function here since by default namespace nodes will not be freed */ ns = rxml_namespace_wrap((xmlNsPtr)xnode); RDATA(ns)->dfree = (RUBY_DATA_FUNC)rxml_xpath_namespace_free; rb_ary_push(rxpop->nsnodes, ns); } } } return Data_Wrap_Struct(cXMLXPathObject, rxml_xpath_object_mark, rxml_xpath_object_free, rxpop); }
/** * This function provides the initialize method for the Transaction class. * * @param self A reference to the new Transaction class instance. * @param connections Either a reference to a single Connection object or to * an array of Connection objects that the transaction * will apply to. * */ static VALUE transactionInitialize(VALUE self, VALUE connections) { TransactionHandle *transaction = NULL; VALUE array = Qnil; /* Determine if an array has been passed as a parameter. */ if(TYPE(connections) == T_ARRAY) { array = connections; } else if(TYPE(connections) == T_DATA && RDATA(connections)->dfree == (RUBY_DATA_FUNC)connectionFree) { array = rb_ary_new(); rb_ary_push(array, connections); } else { rb_fireruby_raise(NULL, "Invalid connection parameter(s) for transaction."); } /* Store the database details. */ rb_iv_set(self, "@connections", array); /* Fetch the data structure and start the transaction. */ Data_Get_Struct(self, TransactionHandle, transaction); startTransaction(transaction, array, 0, NULL); rb_tx_started(self, array); return(self); }
/* Clones CallCredentials instances. Gives CallCredentials a consistent implementation of Ruby's object copy/dup protocol. */ static VALUE grpc_rb_call_credentials_init_copy(VALUE copy, VALUE orig) { grpc_rb_call_credentials *orig_cred = NULL; grpc_rb_call_credentials *copy_cred = NULL; if (copy == orig) { return copy; } /* Raise an error if orig is not a credentials object or a subclass. */ if (TYPE(orig) != T_DATA || RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_call_credentials_free) { rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cCallCredentials)); } TypedData_Get_Struct(orig, grpc_rb_call_credentials, &grpc_rb_call_credentials_data_type, orig_cred); TypedData_Get_Struct(copy, grpc_rb_call_credentials, &grpc_rb_call_credentials_data_type, copy_cred); /* use ruby's MEMCPY to make a byte-for-byte copy of the credentials * wrapper object. */ MEMCPY(copy_cred, orig_cred, grpc_rb_call_credentials, 1); return copy; }
/** * 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 VALUE dnssd_service_stop(VALUE self) { VALUE thread; DNSServiceRef *client; get(cDNSSDService, self, DNSServiceRef, client); RDATA(self)->data = NULL; if (client == NULL) rb_raise(eDNSSDError, "service is already stopped"); thread = rb_ivar_get(self, dnssd_iv_thread); rb_ivar_set(self, dnssd_iv_continue, Qfalse); if (!NIL_P(thread) && thread != rb_thread_current()) { rb_thread_run(thread); rb_funcall(thread, dnssd_id_join, 0); } dnssd_service_free_client(client); rb_ivar_set(self, dnssd_iv_type, Qnil); return self; }
static VALUE rxml_node_remove_ex(VALUE self) { xmlNodePtr xnode, xresult; xnode = rxml_get_xnode(self); /* First unlink the node from its parent. */ xmlUnlinkNode(xnode); /* Now copy the node we want to remove and make the current Ruby object point to it. We do this because a node has a number of dependencies on its parent document - its name (if using a dictionary), entities, namespaces, etc. For a node to live on its own, it needs to get its own copies of this information.*/ xresult = xmlDocCopyNode(xnode, NULL, 1); /* Now free the original node. */ xmlFreeNode(xnode); /* Now wrap the new node */ RDATA(self)->data = xresult; xresult->_private = (void*) self; /* Now return the removed node so the user can do something with it.*/ return self; }
static VALUE ossl_ocspcid_initialize(int argc, VALUE *argv, VALUE self) { OCSP_CERTID *id, *newid; X509 *x509s, *x509i; VALUE subject, issuer, digest; const EVP_MD *md; if (rb_scan_args(argc, argv, "21", &subject, &issuer, &digest) == 0) { return self; } x509s = GetX509CertPtr(subject); /* NO NEED TO DUP */ x509i = GetX509CertPtr(issuer); /* NO NEED TO DUP */ if (!NIL_P(digest)) { md = GetDigestPtr(digest); newid = OCSP_cert_to_id(md, x509s, x509i); } else { newid = OCSP_cert_to_id(NULL, x509s, x509i); } if(!newid) ossl_raise(eOCSPError, NULL); GetOCSPCertId(self, id); OCSP_CERTID_free(id); RDATA(self)->data = newid; return self; }
static VALUE rxml_node_modify_dom(VALUE self, VALUE target, xmlNodePtr (*xmlFunc)(xmlNodePtr, xmlNodePtr)) { xmlNodePtr xnode, xtarget, xresult; if (rb_obj_is_kind_of(target, cXMLNode) == Qfalse) rb_raise(rb_eTypeError, "Must pass an XML::Node object"); xnode = rxml_get_xnode(self); xtarget = rxml_get_xnode(target); if (xtarget->doc != NULL && xtarget->doc != xnode->doc) rb_raise(eXMLError, "Nodes belong to different documents. You must first import the node by calling XML::Document.import"); xmlUnlinkNode(xtarget); /* This target node could be freed here. */ xresult = xmlFunc(xnode, xtarget); if (!xresult) rxml_raise(&xmlLastError); /* Was the target freed? If yes, then wrap the new node */ if (xresult != xtarget) { RDATA(target)->data = xresult; xresult->_private = (void*) target; } return target; }
/* * call-seq: * reader.expand -> node * * Returns the current node and its full subtree. Note the returned node * is valid ONLY until the next read call. */ static VALUE rxml_reader_expand(VALUE self) { xmlTextReaderPtr xreader = rxml_text_reader_get(self); xmlNodePtr xnode = NULL; /* At this point we need to wrap the reader's document as explained above. */ xmlDocPtr xdoc = xmlTextReaderCurrentDoc(xreader); if (!xdoc) rb_raise(rb_eRuntimeError, "The reader does not have a document. Did you forget to call read?"); rxml_document_wrap(xdoc); /* And now hook in a mark function */ RDATA(self)->dmark = (RUBY_DATA_FUNC)rxml_reader_mark; xnode = xmlTextReaderExpand(xreader); if (!xnode) { return Qnil; } else { return rxml_node_wrap(xnode); } }
static mrb_value hs_regexp_match(mrb_state *mrb, mrb_value self) { const char *str; struct mrb_hs_regexp *reg; mrb_value m; regexp_info ri = { mrb }; mrb_get_args(mrb, "z", &str); Data_Get_Struct(mrb, self, &mrb_hs_regexp_type, reg); if (!reg->reg){ mrb_raise(mrb, E_ARGUMENT_ERROR, "HsRegexp is not initialized."); } ri.flag = reg->flag; if (hs_regexec(&ri, reg->reg, str)){ m = hs_regexp_get_match_data(mrb, self, str); }else{ m = mrb_nil_value(); } mrb_obj_iv_set(mrb, (struct RObject *)mrb_class_real(RDATA(self)->c), INTERN("@last_match"), m); return m; }
void ruby_buffer_free(buf_T *buf) { if (buf->b_ruby_ref) { rb_hash_aset(objtbl, rb_obj_id((VALUE) buf->b_ruby_ref), Qnil); RDATA(buf->b_ruby_ref)->data = NULL; } }
/* * call-seq: * root -> TrieNode * * Returns a TrieNode representing the root of the Trie. * */ static VALUE rb_trie_root(VALUE self) { Trie *trie; Data_Get_Struct(self, Trie, trie); VALUE trie_node = rb_trie_node_alloc(cTrieNode); TrieState *state = trie_root(trie); RDATA(trie_node)->data = state; return trie_node; }
static int enc_check_encoding(VALUE obj) { if (!is_obj_encoding(obj)) { return -1; } return check_encoding(RDATA(obj)->data); }
VALUE ossl_x509stctx_clear_ptr(VALUE obj) { OSSL_Check_Kind(obj, cX509StoreContext); RDATA(obj)->data = NULL; return obj; }
static int enc_check_encoding(mrb_state *mrb, mrb_value obj) { if (SPECIAL_CONST_P(obj) || !is_data_encoding(obj)) { return -1; } return check_encoding(mrb, RDATA(obj)->data); }
static int enc_check_encoding(VALUE obj) { if (SPECIAL_CONST_P(obj) || !rb_typeddata_is_kind_of(obj, &encoding_data_type)) { return -1; } return check_encoding(RDATA(obj)->data); }
static VALUE rb_obj_is_method(VALUE m) { if (TYPE(m) == T_DATA && RDATA(m)->dmark == (RUBY_DATA_FUNC) bm_mark) { return Qtrue; } return Qfalse; }
void ruby_window_free(win_T *win) { if (win->w_ruby_ref) { rb_hash_aset(objtbl, rb_obj_id((VALUE) win->w_ruby_ref), Qnil); RDATA(win->w_ruby_ref)->data = NULL; } }
rb_encoding * rb_find_encoding(VALUE enc) { int idx; if (enc_check_encoding(enc) >= 0) return RDATA(enc)->data; idx = str_find_encindex(enc); if (idx < 0) return NULL; return rb_enc_from_index(idx); }