/* call-seq: children -> hash Returns an array of call info objects of methods that this method called (ie, children).*/ static VALUE prof_call_info_children(VALUE self) { prof_call_info_t *call_info = prof_get_call_info_result(self); if (call_info->children == Qnil) { call_info->children = rb_ary_new(); st_foreach(call_info->call_infos, prof_call_info_collect_children, call_info->children); } return call_info->children; }
void TestSyckParseString2( CuTest *tc ) { SyckParser *parser; parser = syck_new_parser(); syck_parser_handler( parser, SyckParseStringHandler ); syck_parser_str_auto( parser, "--- {test: 1, and: 2, or: &test 13}", NULL ); syckparse( parser ); st_foreach( parser->anchors, ListAnchors, tc ); syck_free_parser( parser ); }
static void print_trans_modules(const char *filename) { extern st_table_t module_table; int count, counter; count = count_modules(); counter = 0; fprintf(OUT, "struct trans_module trans_%s_maindata_modules[%d] = {\n", filename, count); st_foreach(module_table, print_trans_module_f, (st_data_t)&counter); fprintf(OUT, "};\n\n"); }
VALUE rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach) { VALUE klass = RBASIC(obj)->klass; if (!FL_TEST(klass, FL_SINGLETON)) return klass; else { /* copy singleton(unnamed) class */ VALUE clone = class_alloc(RBASIC(klass)->flags, 0); if (BUILTIN_TYPE(obj) == T_CLASS) { RBASIC_SET_CLASS(clone, clone); } else { RBASIC_SET_CLASS(clone, rb_singleton_class_clone(klass)); } RCLASS_SET_SUPER(clone, RCLASS_SUPER(klass)); RCLASS_EXT(clone)->allocator = RCLASS_EXT(klass)->allocator; if (RCLASS_IV_TBL(klass)) { RCLASS_IV_TBL(clone) = rb_st_copy(clone, RCLASS_IV_TBL(klass)); } if (RCLASS_CONST_TBL(klass)) { struct clone_const_arg arg; RCLASS_CONST_TBL(clone) = st_init_numtable(); arg.klass = clone; arg.tbl = RCLASS_CONST_TBL(clone); st_foreach(RCLASS_CONST_TBL(klass), clone_const_i, (st_data_t)&arg); } if (attach != Qundef) { rb_singleton_class_attached(clone, attach); } RCLASS_M_TBL_INIT(clone); st_foreach(RCLASS_M_TBL(klass), clone_method_i, (st_data_t)clone); rb_singleton_class_attached(RBASIC(clone)->klass, clone); FL_SET(clone, FL_SINGLETON); return clone; } }
static VALUE memprof_stats(int argc, VALUE *argv, VALUE self) { st_table *tmp_table; struct results res; int i; VALUE str; FILE *out = NULL; if (!track_objs) rb_raise(rb_eRuntimeError, "object tracking disabled, call Memprof.start first"); rb_scan_args(argc, argv, "01", &str); if (RTEST(str)) { out = fopen(StringValueCStr(str), "w"); if (!out) rb_raise(rb_eArgError, "unable to open output file"); } track_objs = 0; tmp_table = st_init_strtable(); st_foreach(objs, objs_tabulate, (st_data_t)tmp_table); res.num_entries = 0; res.entries = malloc(sizeof(char*) * tmp_table->num_entries); st_foreach(tmp_table, memprof_do_dump, (st_data_t)&res); st_free_table(tmp_table); qsort(res.entries, res.num_entries, sizeof(char*), &memprof_strcmp); for (i=0; i < res.num_entries; i++) { fprintf(out ? out : stderr, "%s\n", res.entries[i]); free(res.entries[i]); } free(res.entries); track_objs = 1; return Qnil; }
static VALUE stop_stat_server() { if (logger->enabled == Qtrue) stop_stat_tracing(); // Destroy the list which aggregates messages message_list_destroy(); // Clear object_table which holds object allocation info st_foreach(logger->object_table, free_values_i, 0); st_clear(logger->object_table); st_foreach(logger->str_table, free_keys_i, 0); st_clear(logger->str_table); msgpack_sbuffer_free(logger->sbuf); msgpack_packer_free(logger->msgpacker); zmq_close(zmq_publisher); zmq_close(zmq_response_socket); zmq_ctx_destroy(zmq_context); free(logger); logger = 0; return Qnil; }
/* * call-seq: * Coverage.peek_result => hash * * Returns a hash that contains filename as key and coverage array as value. */ static VALUE rb_coverage_peek_result(VALUE klass) { VALUE coverages = rb_get_coverages(); VALUE ncoverages = rb_hash_new(); if (!RTEST(coverages)) { rb_raise(rb_eRuntimeError, "coverage measurement is not enabled"); } st_foreach(RHASH_TBL(coverages), coverage_peek_result_i, ncoverages); rb_hash_freeze(ncoverages); return ncoverages; }
int osm_db_clear(IN osm_db_domain_t * p_domain) { osm_db_domain_imp_t *p_domain_imp = (osm_db_domain_imp_t *) p_domain->p_domain_imp; cl_spinlock_acquire(&p_domain_imp->lock); st_foreach(p_domain_imp->p_hash, __osm_clear_tbl_entry, (st_data_t) NULL); cl_spinlock_release(&p_domain_imp->lock); return 0; }
int osm_db_store(IN osm_db_domain_t * p_domain) { osm_log_t *p_log = p_domain->p_db->p_log; osm_db_domain_imp_t *p_domain_imp; FILE *p_file; int status = 0; char *p_tmp_file_name; OSM_LOG_ENTER(p_log); p_domain_imp = (osm_db_domain_imp_t *) p_domain->p_domain_imp; p_tmp_file_name = (char *)malloc(sizeof(char) * (strlen(p_domain_imp->file_name) + 8)); strcpy(p_tmp_file_name, p_domain_imp->file_name); strcat(p_tmp_file_name, ".tmp"); cl_spinlock_acquire(&p_domain_imp->lock); /* open up the output file */ p_file = fopen(p_tmp_file_name, "w"); if (!p_file) { OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 6107: " "Failed to open the db file:%s for writing\n", p_domain_imp->file_name); status = 1; goto Exit; } st_foreach(p_domain_imp->p_hash, __osm_dump_tbl_entry, (st_data_t) p_file); fclose(p_file); /* move the domain file */ status = remove(p_domain_imp->file_name); if (status) { OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 6109: " "Failed to remove file:%s (err:%u)\n", p_domain_imp->file_name, status); } status = rename(p_tmp_file_name, p_domain_imp->file_name); if (status) { OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 6108: " "Failed to rename the db file to:%s (err:%u)\n", p_domain_imp->file_name, status); } Exit: cl_spinlock_release(&p_domain_imp->lock); free(p_tmp_file_name); OSM_LOG_EXIT(p_log); return status; }
static int map_equal(struct avro_map_datum_t *a, struct avro_map_datum_t *b) { if (!avro_schema_equal(a->schema, b->schema)) { return 0; } struct st_equal_args args = { 1, b->map }; if (a->map->num_entries != b->map->num_entries) { return 0; } st_foreach(a->map, st_equal_foreach, (st_data_t) & args); return args.rval; }
static VALUE cov_generate_coverage_info(VALUE self) { VALUE cover; if (rb_const_defined_at(mRCOV__, id_cover)) rb_mod_remove_const(mRCOV__, ID2SYM(id_cover)); cover = rb_hash_new(); if (coverinfo) st_foreach(coverinfo, populate_cover, cover); rb_define_const(mRCOV__, "COVER", cover); return cover; }
static void rusb_gc_mark(void *p) { st_foreach(bus_objects, mark_data_i, 0); st_foreach(device_objects, mark_data_i, 0); st_foreach(config_descriptor_objects, mark_data_i, 0); st_foreach(interface_objects, mark_data_i, 0); st_foreach(interface_descriptor_objects, mark_data_i, 0); st_foreach(endpoint_descriptor_objects, mark_data_i, 0); }
VALUE gc_never_free(VALUE obj) { if (!obj) return Qnil; BASIC(obj).refcount = GC_NEVER_FREE; if (TYPE(obj) == T_ARRAY) vector_foreach(ARRAY(obj)->ptr, gc_never_free0); else if (TYPE(obj) == T_HASH) st_foreach(HASH(obj)->ptr, gc_never_free_hash0, 0); return obj; }
int osm_db_keys(IN osm_db_domain_t * p_domain, OUT cl_list_t * p_key_list) { osm_db_domain_imp_t *p_domain_imp = (osm_db_domain_imp_t *) p_domain->p_domain_imp; cl_spinlock_acquire(&p_domain_imp->lock); st_foreach(p_domain_imp->p_hash, __osm_get_key_of_tbl_entry, (st_data_t) p_key_list); cl_spinlock_release(&p_domain_imp->lock); return 0; }
static VALUE class_variable_hash(VALUE module) { VALUE class_variables = rb_hash_new(); #if RUBY_VERSION_CODE < 190 struct st_table * iv_tbl = ROBJECT(module)->iv_tbl; if (iv_tbl) { st_foreach(iv_tbl, add_var_to_hash, class_variables); } #else rb_ivar_foreach(module, add_var_to_hash, class_variables); #endif return class_variables; }
VALUE rb_extract_keywords(VALUE *orighash) { VALUE parthash[2] = {0, 0}; VALUE hash = *orighash; if (RHASH_EMPTY_P(hash)) { *orighash = 0; return hash; } st_foreach(rb_hash_tbl_raw(hash), separate_symbol, (st_data_t)&parthash); *orighash = parthash[1]; return parthash[0]; }
static int record_equal(struct avro_record_datum_t *a, struct avro_record_datum_t *b) { if (!avro_schema_equal(a->schema, b->schema)) { return 0; } struct st_equal_args args = { 1, b->fields_byname }; if (a->fields_byname->num_entries != b->fields_byname->num_entries) { return 0; } st_foreach(a->fields_byname, st_equal_foreach, (st_data_t) & args); return args.rval; }
static VALUE cov_reset_coverage(VALUE self) { if(coverage_hook_set_p) { rb_raise(rb_eRuntimeError, "Cannot reset the coverage info in the middle of a traced run."); return Qnil; } cached_array = 0; cached_file = 0; st_foreach(coverinfo, free_table, Qnil); st_free_table(coverinfo); coverinfo = 0; return Qnil; }
static VALUE instance_method_hash(VALUE module) { VALUE methods = rb_hash_new(); st_foreach( RCLASS(module)->m_tbl, add_to_method_hash, #ifdef ST_DATA_T_DEFINED (st_data_t)methods #else methods #endif ); return methods; }
VALUE rb_singleton_class_clone(VALUE obj) { VALUE klass = RBASIC(obj)->klass; if (!FL_TEST(klass, FL_SINGLETON)) return klass; else { struct clone_method_data data; /* copy singleton(unnamed) class */ VALUE clone = class_alloc((RBASIC(klass)->flags & ~(FL_MARK)), 0); if (BUILTIN_TYPE(obj) == T_CLASS) { RBASIC(clone)->klass = (VALUE)clone; } else { RBASIC(clone)->klass = rb_singleton_class_clone(klass); } RCLASS_SUPER(clone) = RCLASS_SUPER(klass); if (RCLASS_IV_TBL(klass)) { RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(klass)); } if (RCLASS_CONST_TBL(klass)) { RCLASS_CONST_TBL(clone) = st_init_numtable(); st_foreach(RCLASS_CONST_TBL(klass), clone_const, (st_data_t)RCLASS_CONST_TBL(clone)); } RCLASS_M_TBL(clone) = st_init_numtable(); data.tbl = RCLASS_M_TBL(clone); data.klass = (VALUE)clone; st_foreach(RCLASS_M_TBL(klass), clone_method, (st_data_t)&data); rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone); FL_SET(clone, FL_SINGLETON); return (VALUE)clone; } }
static int include_modules_at(const VALUE klass, VALUE c, VALUE module) { VALUE p; int changed = 0; const st_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass)); while (module) { int superclass_seen = FALSE; if (RCLASS_ORIGIN(module) != module) goto skip; if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module)) return -1; /* ignore if the module included already in superclasses */ for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) { switch (BUILTIN_TYPE(p)) { case T_ICLASS: if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) { if (!superclass_seen) { c = p; /* move insertion point */ } goto skip; } break; case T_CLASS: superclass_seen = TRUE; break; } } c = RCLASS_SET_SUPER(c, rb_include_class_new(module, RCLASS_SUPER(c))); if (FL_TEST(klass, RMODULE_IS_REFINEMENT)) { VALUE refined_class = rb_refinement_module_get_refined_class(klass); st_foreach(RMODULE_M_TBL(module), add_refined_method_entry_i, (st_data_t) refined_class); FL_SET(c, RMODULE_INCLUDED_INTO_REFINEMENT); } if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries) changed = 1; if (RMODULE_CONST_TBL(module) && RMODULE_CONST_TBL(module)->num_entries) changed = 1; skip: module = RCLASS_SUPER(module); } return changed; }
/* USB.find_busses */ static VALUE rusb_find_busses(VALUE cUSB) { st_foreach(bus_objects, revoke_data_i, 0); st_foreach(device_objects, revoke_data_i, 0); st_foreach(config_descriptor_objects, revoke_data_i, 0); st_foreach(interface_objects, revoke_data_i, 0); st_foreach(interface_descriptor_objects, revoke_data_i, 0); st_foreach(endpoint_descriptor_objects, revoke_data_i, 0); return INT2NUM(usb_find_busses()); }
void lumi_world_free(lumi_world_t *world) { #ifdef VLC_0_9 if (world->vlc != NULL) libvlc_release(world->vlc); #endif lumi_native_cleanup(world); st_foreach(world->image_cache, CASTFOREACH(lumi_world_free_image_cache), 0); st_free_table(world->image_cache); SHOE_FREE(world->blank_cache); cairo_surface_destroy(world->blank_image); pango_font_description_free(world->default_font); rb_gc_unregister_address(&world->apps); rb_gc_unregister_address(&world->msgs); if (world != NULL) SHOE_FREE(world); }
static VALUE setup_hash(int argc, VALUE *argv) { VALUE hash; if (rb_scan_args(argc, argv, "01", &hash) == 1) { if (!RB_TYPE_P(hash, T_HASH)) rb_raise(rb_eTypeError, "non-hash given"); } if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } return hash; }
void RecordUndoOperation::undo() { if( mType == INSERT || mType == DELETE ) { RecordList temp = mRecords.reversed(); if( mType == INSERT ) { temp.remove(); } else { // Clear the DELETED state st_foreach( RecordIter, it, temp ) it.imp()->mState = RecordImp::NEWRECORD | RecordImp::COMMIT_ALL_FIELDS; temp.commit( false ); } } else if( mType == UPDATE ) { RecordList list = mRecords; Record oldvals( mRecords[0].imp()->copy(), false ); mRecords[1].commit(); mRecords[1] = oldvals; } }
static void dealloc(xmlDocPtr doc) { NOKOGIRI_DEBUG_START(doc); st_table *node_hash = DOC_UNLINKED_NODE_HASH(doc); xmlDeregisterNodeFunc func = xmlDeregisterNodeDefault(NULL); st_foreach(node_hash, dealloc_node_i, (st_data_t)doc); st_free_table(node_hash); free(doc->_private); doc->_private = NULL; xmlFreeDoc(doc); xmlDeregisterNodeDefault(func); NOKOGIRI_DEBUG_END(doc); }
static int fc_i(ID key, rb_const_entry_t *ce, struct fc_result *res) { VALUE value = ce->value; if (!rb_is_const_id(key)) return ST_CONTINUE; if (value == res->klass) { res->path = fc_path(res, key); return ST_STOP; } switch (TYPE(value)) { case T_MODULE: case T_CLASS: if (!RCLASS_CONST_TBL(value)) return ST_CONTINUE; else { struct fc_result arg; struct fc_result *list; list = res; while (list) { if (list->track == value) return ST_CONTINUE; list = list->prev; } arg.name = key; arg.path = 0; arg.klass = res->klass; arg.track = value; arg.prev = res; st_foreach(RCLASS_CONST_TBL(value), fc_i, (st_data_t)&arg); if (arg.path) { res->path = arg.path; return ST_STOP; } } break; default: break; } return ST_CONTINUE; }
/* * call-seq: * context.register_namespaces(["prefix:uri"]) -> self * * Register the specified namespaces in this context. There are * three different forms that libxml accepts. These include * a string, an array of strings, or a hash table: * * context.register_namespaces('xi:http://www.w3.org/2001/XInclude') * context.register_namespaces(['xlink:http://www.w3.org/1999/xlink', * 'xi:http://www.w3.org/2001/XInclude') * context.register_namespaces('xlink' => 'http://www.w3.org/1999/xlink', * 'xi' => 'http://www.w3.org/2001/XInclude') */ static VALUE rxml_xpath_context_register_namespaces(VALUE self, VALUE nslist) { char *cp; long i; VALUE rprefix, ruri; /* Need to loop through the 2nd argument and iterate through the * list of namespaces that we want to allow */ switch (TYPE(nslist)) { case T_STRING: cp = strchr(StringValuePtr(nslist), (int) ':'); if (cp == NULL) { rprefix = nslist; ruri = Qnil; } else { rprefix = rb_str_new(StringValuePtr(nslist), (int) ((long) cp - (long) StringValuePtr(nslist))); ruri = rb_str_new2(&cp[1]); } /* Should test the results of this */ rxml_xpath_context_register_namespace(self, rprefix, ruri); break; case T_ARRAY: for (i = 0; i < RARRAY_LEN(nslist); i++) { rxml_xpath_context_register_namespaces(self, RARRAY_PTR(nslist)[i]); } break; case T_HASH: st_foreach(RHASH_TBL(nslist), iterate_ns_hash, self); break; default: rb_raise( rb_eArgError, "Invalid argument type, only accept string, array of strings, or an array of arrays"); } return self; }
static VALUE count_tdata_objects(int argc, VALUE *argv, VALUE self) { VALUE hash; if (rb_scan_args(argc, argv, "01", &hash) == 1) { if (TYPE(hash) != T_HASH) rb_raise(rb_eTypeError, "non-hash given"); } if (hash == Qnil) { hash = rb_hash_new(); } else if (!RHASH_EMPTY_P(hash)) { st_foreach(RHASH_TBL(hash), set_zero_i, hash); } rb_objspace_each_objects(cto_i, (void *)hash); return hash; }
static VALUE reachable_objects_from(VALUE self, VALUE obj) { if (rb_objspace_markable_object_p(obj)) { VALUE ret = rb_ary_new(); struct rof_data data; if (rb_typeddata_is_kind_of(obj, &iow_data_type)) { obj = (VALUE)DATA_PTR(obj); } data.refs = st_init_numtable(); data.internals = rb_ary_new(); rb_objspace_reachable_objects_from(obj, reachable_object_from_i, &data); st_foreach(data.refs, collect_values, (st_data_t)ret); return ret; } else { return Qnil; } }