void PoolAllocator::free(ID p_mem) { mt_lock(); Entry *e=get_entry(p_mem); if (!e) { mt_unlock(); ERR_PRINT("!e"); return; } if (e->lock) { mt_unlock(); ERR_PRINT("e->lock"); return; } EntryIndicesPos entry_indices_pos; bool index_found = find_entry_index(&entry_indices_pos,e); if (!index_found) { mt_unlock(); ERR_FAIL_COND(!index_found); } for (int i=entry_indices_pos;i<(entry_count-1);i++) { entry_indices[ i ] = entry_indices[ i+1 ]; } entry_count--; free_mem+=aligned(e->len); e->clear(); mt_unlock(); }
int odp_pktio_close(odp_pktio_t id) { pktio_entry_t *entry; int res = -1; entry = get_entry(id); if (entry == NULL) return -1; lock_entry(entry); if (!is_free(entry)) { switch (entry->s.params.type) { case ODP_PKTIO_TYPE_SOCKET_BASIC: case ODP_PKTIO_TYPE_SOCKET_MMSG: res = close_pkt_sock(&entry->s.pkt_sock); break; case ODP_PKTIO_TYPE_SOCKET_MMAP: res = close_pkt_sock_mmap(&entry->s.pkt_sock_mmap); break; #ifdef ODP_HAVE_NETMAP case ODP_PKTIO_TYPE_NETMAP: res = close_pkt_netmap(&entry->s.pkt_nm); break; #endif default: break; res |= free_pktio_entry(id); } } unlock_entry(entry); if (res != 0) return -1; return 0; }
config_t store_value( unsigned char key, const char * value, config_t config){ entry_t e; if( config == NULL) { return NULL; } config_t conf = config; e = get_entry(key, conf); if(e == NULL) { conf->err = CONF_ERR; return conf; } switch(e->type_tag){ case ENTRY_INT: e->e.scalar_int = atoi(value); break; case ENTRY_STR: e->e.scalar_str = strdup_r(e->e.scalar_str, value); break; default: return conf; } conf->map[key] = e; return conf; }
void Table::build_keys( vector<string> key_list ) { // construct file pat string path( "./data/" ); path.append( name ); path.append( ".tbl" ); ifstream fs( path.c_str() ); if ( !fs.is_open() ) { cout << path << endl; cerr << "ERROR: file does not exist in Table::build_keys(). " << endl; return; } for ( int i = 0; i < key_list.size(); i++ ) { if( has_index_file( key_list[i] ) ) { build_key_from_file( key_list[i] ); continue; } int pos = get_col_pos( key_list[i] ); streampos offset = 0; BTree * btree = new BTree ( 5, 6 ); string line; getline( fs, line ); // get rid of the first line offset = fs.tellg(); while ( getline ( fs, line ) && line.size() > 0) { // to ignore the deleted lines //cout << line << endl; if( line[0] == '@' ) { //cout << line << endl; offset = fs.tellg(); continue; } string entry = get_entry( line, pos ); if ( is_number ( entry ) ) { Tuple cur_tuple( atoi( entry.c_str() ), offset ); btree->insert( cur_tuple ); } else { Tuple cur_tuple( entry.c_str() , offset ); btree->insert( cur_tuple ); } offset = fs.tellg(); } keys.insert( pair<string, BTree*>( key_list[i], btree ) ); fs.clear(); fs.seekg( fs.beg ); BTreeNode * node = btree->get_first(); dump_tree( key_list[i], node ); } fs.close(); }
static inline int check_entry(const STRUCT_ENTRY *e, unsigned int *i, unsigned int *off, unsigned int user_offset, int *was_return, struct iptc_handle *h) { unsigned int toff; STRUCT_STANDARD_TARGET *t; assert(e->target_offset >= sizeof(STRUCT_ENTRY)); assert(e->next_offset >= e->target_offset + sizeof(STRUCT_ENTRY_TARGET)); toff = sizeof(STRUCT_ENTRY); IPT_MATCH_ITERATE(e, check_match, &toff); assert(toff == e->target_offset); t = (STRUCT_STANDARD_TARGET *) GET_TARGET((STRUCT_ENTRY *)e); /* next_offset will have to be multiple of entry alignment. */ assert(e->next_offset == ALIGN(e->next_offset)); assert(e->target_offset == ALIGN(e->target_offset)); assert(t->target.u.target_size == ALIGN(t->target.u.target_size)); assert(!TC_IS_CHAIN(t->target.u.user.name, h)); if (strcmp(t->target.u.user.name, STANDARD_TARGET) == 0) { assert(t->target.u.target_size == ALIGN(sizeof(STRUCT_STANDARD_TARGET))); assert(t->verdict == -NF_DROP-1 || t->verdict == -NF_ACCEPT-1 || t->verdict == RETURN || t->verdict < (int)h->entries->size); if (t->verdict >= 0) { STRUCT_ENTRY *te = get_entry(h, t->verdict); int idx; idx = iptcb_entry2index(h, te); assert(strcmp(GET_TARGET(te)->u.user.name, IPT_ERROR_TARGET) != 0); assert(te != e); /* Prior node must be error node, or this node. */ assert(t->verdict == iptcb_entry2offset(h, e)+e->next_offset || strcmp(GET_TARGET(index2entry(h, idx-1)) ->u.user.name, IPT_ERROR_TARGET) == 0); } if (t->verdict == RETURN && unconditional(&e->ip) && e->target_offset == sizeof(*e)) *was_return = 1; else *was_return = 0; } else if (strcmp(t->target.u.user.name, IPT_ERROR_TARGET) == 0) { assert(t->target.u.target_size == ALIGN(sizeof(struct ipt_error_target))); /* If this is in user area, previous must have been return */ if (*off > user_offset) assert(*was_return); *was_return = 0; } else *was_return = 0; if (*off == user_offset) assert(strcmp(t->target.u.user.name, IPT_ERROR_TARGET) == 0); (*off) += e->next_offset; (*i)++; return 0; }
ir_function *glsl_symbol_table::get_function(const char *name) { symbol_table_entry *entry = get_entry(name); return entry != NULL ? entry->f : NULL; }
ir_variable *glsl_symbol_table::get_variable(const char *name) { symbol_table_entry *entry = get_entry(name); return entry != NULL ? entry->v : NULL; }
static struct entry *get_sentinel(struct entry_alloc *ea, unsigned level, bool which) { return get_entry(ea, which ? level : NR_CACHE_LEVELS + level); }
Symbol* PlaceholderTable::find_entry(int index, unsigned int hash, Symbol* class_name, ClassLoaderData* loader_data) { PlaceholderEntry* probe = get_entry(index, hash, class_name, loader_data); return (probe? probe->klassname(): (Symbol*)NULL); }
int main(int numarg,char** argo){ int opzione=0; int show_help=0; int show_version=0; int list=0; int current_argument; int ingresso; int uscita; char* output_file_name=NULL; char* override_entry_name=NULL; char* temporary_file_name; char* end; int append_WAV=0; int WAV_descriptor; filetype type; int count,used,total,used_entries; int start_address,end_address,offset; char entry_name[17]; struct entry_element* current_file; int first_done=0; int dsp_output=0; int sample_speed; /* Get options */ while ((opzione=getopt(numarg,argo,"hiloe:v"))!=EOF){ switch(opzione){ case 'h': show_help=1; break; case 'i': inverted_waveform=1; break; case 'l': list=1; break; case 'o': output_file_name=(char*)malloc(strlen(optarg)+4); strcpy(output_file_name,optarg); break; case 'e': override_entry=1; override_entry_name=(char*)malloc(strlen(optarg)+4); strcpy(override_entry_name,optarg); break; case 'v': show_version=1; break; default: help(); return 1; }; } if (show_help==1){ help(); return 0; }; if (show_version==1){ version(); return 0; }; if (output_file_name==NULL){ /* -o is not used */ dsp_output=1; output_file_name=(char*)malloc(strlen(SOUNDDEV)+1); strcpy(output_file_name,SOUNDDEV); }; current_argument=optind; if (current_argument==numarg){ printf("No input files specified!\n"); help(); return 1; } if (!list){ if (dsp_output){ if ((uscita=open(SOUNDDEV,O_WRONLY))==-1){ printf("Could not open file %s\n",SOUNDDEV); return 3; } sample_speed = 44100; if (ioctl(uscita, SNDCTL_DSP_SPEED, &sample_speed) != 0 || sample_speed != 44100){ printf("Could not set playback speed to 44100 Hz in file %s\n",SOUNDDEV); return 3; } } else{ if((uscita=open(temporary_file_name=tempnam("/tmp","prg2w"),O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))==-1){ printf("Could not create temporary file in /tmp directory\n"); return 5; }; if (strlen(output_file_name)<5) append_WAV=1; else{ end=output_file_name+strlen(output_file_name)-4; if((strcmp(end,".WAV"))&&(strcmp(end,".wav"))) append_WAV=1; }; if (append_WAV) strcat(output_file_name,".wav"); if((WAV_descriptor=open(output_file_name,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))==-1){ printf("Could not create file %s\n",output_file_name); unlink(temporary_file_name); return 5; }; } } while (current_argument<numarg){ if ((ingresso=open(argo[current_argument],O_RDONLY))==-1){ printf("Could not open file %s\n",argo[current_argument]); goto fine; }; switch(type=detect_type(ingresso)){ case t64: printf("%s: T64 file\n",argo[current_argument]); break; case p00: printf("%s: P00 file\n",argo[current_argument]); break; case prg: printf("%s: program file\n",argo[current_argument]); break; default: printf("%s is not a recognized file type\n",argo[current_argument]); goto fine; }; if (list){ list_contents(ingresso); goto fine; }; switch(type){ case t64: used_entries=get_used_entries(ingresso); total=get_total_entries(ingresso); empty_list(files_to_convert); files_to_convert=0; if (used_entries==1){ for(count=1;count<=total;count++) if(used=get_entry(count,ingresso,&start_address,&end_address,&offset, entry_name)) set_range(count,count,ingresso); } /* If there is only one used entry, */ /* Only the used one will be */ /* converted */ /* otherwise ask the user */ else get_range_from_keyboard(ingresso); current_file=files_to_convert; while(current_file!=0){ count=current_file->entry; get_entry(count,ingresso,&start_address,&end_address,&offset, entry_name); if (!first_done) first_done=1; else add_silence(uscita); printf("Converting %d (%s)\n",count,entry_name); convert(ingresso,uscita,start_address,end_address,offset,entry_name); current_file=current_file->next; } break; case p00: case prg: if (!first_done) first_done=1; else add_silence(uscita); printf("Converting %s\n",argo[current_argument]); get_entry(count,ingresso,&start_address,&end_address,&offset, entry_name); if(override_entry) { int ix; for(ix = 0; ix < strlen(override_entry_name); ix++) { entry_name[ix] = toupper(override_entry_name[ix]); } } printf("Entry Name: %s (%d)\n",entry_name,strlen(entry_name)); convert(ingresso,uscita,start_address,end_address,offset,entry_name); }; fine: ++current_argument; }; close(uscita); if((!list)&&(!dsp_output)){ if(first_done){ printf("Creating WAV file...\n"); create_WAV(temporary_file_name,WAV_descriptor); } else unlink(output_file_name); } }
const char *get_value(const char *keystr) { entry *ep = get_entry(keystr); return ep->val; }
/* * Read the table from a file. */ int CVmMetaTable::read_from_file(CVmFile *fp) { size_t cnt; size_t i; /* clear the existing table */ clear(); /* read the number of entries */ cnt = fp->read_uint2(); /* read the entries */ for (i = 0 ; i < cnt ; ++i) { char buf[256]; size_t len; vm_prop_id_t min_prop; vm_prop_id_t max_prop; ushort func_cnt; ushort j; vm_meta_entry_t *entry; vm_obj_id_t class_obj; /* read the length of this entry, and make sure it's valid */ len = fp->read_uint2(); if (len > sizeof(buf) - 1) return VMERR_SAVED_META_TOO_LONG; /* read the name and null-terminate it */ fp->read_bytes(buf, len); buf[len] = '\0'; /* read the associated IntrinsicClass object */ class_obj = (vm_obj_id_t)fp->read_uint4(); /* read the property table description */ func_cnt = (ushort)fp->read_uint2(); min_prop = (vm_prop_id_t)fp->read_uint2(); max_prop = (vm_prop_id_t)fp->read_uint2(); /* add this entry */ add_entry(buf, func_cnt, min_prop, max_prop); /* get the new entry's record */ entry = get_entry(i); /* set the class ID */ entry->class_obj_ = class_obj; /* * Read the property mappings. We stored the function table * entries, so we simply need to load those entries. Note that * the function table has a 1-based index, so run our counter * from 1 to the function count. */ for (j = 1 ; j <= func_cnt ; ++j) entry->add_prop_xlat((short)fp->read_int2(), j); } /* success */ return 0; }
//------------------------------------------------------------------------------ bool get_entry( Elf_Xword index, Elf64_Addr& offset, Elf64_Addr& symbolValue, std::string& symbolName, Elf_Word& type, Elf_Sxword& addend, Elf_Sxword& calcValue ) const { // Do regular job Elf_Word symbol; bool ret = get_entry( index, offset, symbol, type, addend ); // Find the symbol Elf_Xword size; unsigned char bind; unsigned char symbolType; Elf_Half section; unsigned char other; symbol_section_accessor symbols( elf_file, elf_file.sections[get_symbol_table_index()] ); ret = symbols.get_symbol( symbol, symbolName, symbolValue, size, bind, symbolType, section, other ); if ( ret ) { // Was it successful? switch ( type ) { case R_386_NONE: // none calcValue = 0; break; case R_386_32: // S + A calcValue = symbolValue + addend; break; case R_386_PC32: // S + A - P calcValue = symbolValue + addend - offset; break; case R_386_GOT32: // G + A - P calcValue = 0; break; case R_386_PLT32: // L + A - P calcValue = 0; break; case R_386_COPY: // none calcValue = 0; break; case R_386_GLOB_DAT: // S case R_386_JMP_SLOT: // S calcValue = symbolValue; break; case R_386_RELATIVE: // B + A calcValue = addend; break; case R_386_GOTOFF: // S + A - GOT calcValue = 0; break; case R_386_GOTPC: // GOT + A - P calcValue = 0; break; default: // Not recognized symbol! calcValue = 0; break; } } return ret; }
int kt_purge(struct purge_options *opt, int argc, char **argv) { krb5_error_code ret = 0; krb5_kt_cursor cursor; krb5_keytab keytab; krb5_keytab_entry entry; int age; struct e *head = NULL; time_t judgement_day; age = parse_time(opt->age_string, "s"); if(age < 0) { krb5_warnx(context, "unparasable time `%s'", opt->age_string); return 1; } if((keytab = ktutil_open_keytab()) == NULL) return 1; ret = krb5_kt_start_seq_get(context, keytab, &cursor); if(ret){ krb5_warn(context, ret, "%s", keytab_string); goto out; } while(krb5_kt_next_entry(context, keytab, &entry, &cursor) == 0) { add_entry (entry.principal, entry.vno, entry.timestamp, &head); krb5_kt_free_entry(context, &entry); } krb5_kt_end_seq_get(context, keytab, &cursor); judgement_day = time (NULL); ret = krb5_kt_start_seq_get(context, keytab, &cursor); if(ret){ krb5_warn(context, ret, "%s", keytab_string); goto out; } while(krb5_kt_next_entry(context, keytab, &entry, &cursor) == 0) { struct e *e = get_entry (entry.principal, head); if (e == NULL) { krb5_warnx (context, "ignoring extra entry"); continue; } if (entry.vno < e->max_vno && judgement_day - e->timestamp > age) { if (verbose_flag) { char *name_str; krb5_unparse_name (context, entry.principal, &name_str); printf ("removing %s vno %d\n", name_str, entry.vno); free (name_str); } ret = krb5_kt_remove_entry (context, keytab, &entry); if (ret) krb5_warn (context, ret, "remove"); } krb5_kt_free_entry(context, &entry); } ret = krb5_kt_end_seq_get(context, keytab, &cursor); delete_list (head); out: krb5_kt_close (context, keytab); return ret != 0; }
static void write_entries_to_window(HWND window, char *filename){ int num_of_entries, entry, row_num = 0; char numstr[6]; filetype type; LVITEMA row; FILE *fd; struct program_block program; HWND preview = GetDlgItem(window, IDC_PREVIEW); HWND text = GetDlgItem(window, IDC_FILE_TYPE); HWND c64name = GetDlgItem(window, IDC_C64_NAME); fd = fopen(filename, "rb"); if (fd == NULL) return; switch (type = detect_type(fd)) { case not_a_valid_file: EnableWindow(preview, FALSE); EnableWindow(c64name, FALSE); SetWindowTextA(text, ""); SetWindowTextA(c64name, ""); fclose(fd); return; case t64: { char message[1000]; char tape_name[25]; int num_of_used_entries; num_of_entries = get_total_entries(fd); num_of_used_entries = get_used_entries(fd); get_tape_name(tape_name, fd); _snprintf(message, 1000, "T64 file with %u total entr%s, %u used entr%s, name %s", num_of_entries, num_of_entries == 1 ? "y" : "ies", num_of_used_entries, num_of_used_entries == 1 ? "y" : "ies", tape_name); SetWindowTextA(text, message); EnableWindow(preview, num_of_used_entries > 1); } EnableWindow(c64name, FALSE); break; case p00: EnableWindow(preview, FALSE); num_of_entries = 1; SetWindowTextA(text, "P00 file"); EnableWindow(c64name, TRUE); break; case prg: EnableWindow(preview, FALSE); num_of_entries = 1; SetWindowTextA(text, "PRG file"); EnableWindow(c64name, TRUE); break; } for (entry = 1; entry <= num_of_entries; entry++) { if (get_entry(entry, fd, &program)) { row.mask = LVIF_TEXT; row.iItem = row_num++; row.iSubItem = 0; row.pszText = numstr; sprintf(numstr, "%u", entry); ListView_InsertItem(preview, &row); row.iSubItem = 1; row.pszText = program.info.name; ListView_SetItem(preview, &row); row.iSubItem = 2; row.pszText = numstr; sprintf(numstr, "%u", program.info.start); ListView_SetItem(preview, &row); row.iSubItem = 3; sprintf(numstr, "%u", program.info.end); ListView_SetItem(preview, &row); } } if (row_num == 1) { ListView_SetItemState(preview, 0, LVIS_SELECTED, LVIS_SELECTED); SetWindowTextA(c64name, program.info.name); } else { SetWindowTextA(c64name, ""); if (IsWindowEnabled(preview)) ListView_SetItemState(preview, 0, LVIS_FOCUSED, LVIS_FOCUSED); } fclose(fd); }
void qr_decomp(double* a, int rows, int cols, int ldim) { double rho, s, c, tau, alpha; int i, k, j; for (k = 0; k < min_int(rows, cols); k++) { for (i = k + 1; i < rows; i++) { if (get_entry(a, ldim, i, k) == 0) { rho = 1.0; c = 1.0; s = 0.0; } else if (fabs(get_entry(a, ldim, k, k)) >= fabs(get_entry(a, ldim, i, k))) { tau = get_entry(a, ldim, i, k) / get_entry(a, ldim, k, k); rho = tau / (sqrt(tau*tau + 1.0)); s = rho; c = sqrt(1.0 - (s*s)); } else { tau = get_entry(a, ldim, k, k) / get_entry(a, ldim, i, k); rho = sqrt(tau*tau + 1.0) / tau; c = 1.0 / rho; s = sqrt(1.0 - (c*c)); } set_entry(a, ldim, k, k, c*get_entry(a, ldim, k, k) + s*get_entry(a, ldim, i, k)); set_entry(a, ldim, i, k, rho); for (j = k + 1; j < cols; j++) { alpha = get_entry(a, ldim, k, j); set_entry(a, ldim, k, j, c*alpha + s * get_entry(a, ldim, i, j)); set_entry(a, ldim, i, j, -s*alpha + c* get_entry(a, ldim, i, j)); } } } }
void bcf_file::print_bcf(const parameters ¶ms) { LOG.printLOG("Outputting BCF file...\n"); BGZF * out; if(!params.stream_out) { string output_file = params.output_prefix + ".recode.bcf"; out = bgzf_open(output_file.c_str(), "w"); } else out = bgzf_dopen(1, "w"); string header_str; uint32_t len_text = 0; vector<char> header; char magic[5] = {'B','C','F','\2','\2'}; bgzf_write(out, magic, 5); for (unsigned int ui=0; ui<meta_data.lines.size(); ui++) { for (unsigned int uj=0; uj<meta_data.lines[ui].length(); uj++) header.push_back( meta_data.lines[ui][uj] ); header.push_back('\n'); } header_str = "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO"; if (meta_data.N_indv > 0) header_str += "\tFORMAT"; for (unsigned int ui=0; ui<meta_data.N_indv; ui++) if (include_indv[ui]) { header_str += "\t"; header_str += meta_data.indv[ui]; } header_str += "\n"; for (unsigned int ui=0; ui<header_str.length(); ui++) header.push_back( header_str[ui] ); header.push_back( '\0' ); len_text = header.size(); bgzf_write(out, (char *)&len_text, sizeof(len_text) ); bgzf_write(out, (char *)&header[0], len_text ); vector<char> variant_line; entry * e = new bcf_entry(meta_data, include_indv); while(!eof()) { get_entry(variant_line); e->reset(variant_line); N_entries += e->apply_filters(params); if(!e->passed_filters) continue; N_kept_entries++; e->parse_basic_entry(true, true, true); e->parse_full_entry(true); e->parse_genotype_entries(true); e->print_bcf(out, params.recode_INFO_to_keep, params.recode_all_INFO); } delete e; bgzf_close(out); }
const glsl_type *glsl_symbol_table::get_interface(const char *name, enum ir_variable_mode mode) { symbol_table_entry *entry = get_entry(name); return entry != NULL ? entry->get_interface(mode) : NULL; }
static struct dm_cache_policy *smq_create(dm_cblock_t cache_size, sector_t origin_size, sector_t cache_block_size) { unsigned i; unsigned nr_sentinels_per_queue = 2u * NR_CACHE_LEVELS; unsigned total_sentinels = 2u * nr_sentinels_per_queue; struct smq_policy *mq = kzalloc(sizeof(*mq), GFP_KERNEL); if (!mq) return NULL; init_policy_functions(mq); mq->cache_size = cache_size; mq->cache_block_size = cache_block_size; calc_hotspot_params(origin_size, cache_block_size, from_cblock(cache_size), &mq->hotspot_block_size, &mq->nr_hotspot_blocks); mq->cache_blocks_per_hotspot_block = div64_u64(mq->hotspot_block_size, mq->cache_block_size); mq->hotspot_level_jump = 1u; if (space_init(&mq->es, total_sentinels + mq->nr_hotspot_blocks + from_cblock(cache_size))) { DMERR("couldn't initialize entry space"); goto bad_pool_init; } init_allocator(&mq->writeback_sentinel_alloc, &mq->es, 0, nr_sentinels_per_queue); for (i = 0; i < nr_sentinels_per_queue; i++) get_entry(&mq->writeback_sentinel_alloc, i)->sentinel = true; init_allocator(&mq->demote_sentinel_alloc, &mq->es, nr_sentinels_per_queue, total_sentinels); for (i = 0; i < nr_sentinels_per_queue; i++) get_entry(&mq->demote_sentinel_alloc, i)->sentinel = true; init_allocator(&mq->hotspot_alloc, &mq->es, total_sentinels, total_sentinels + mq->nr_hotspot_blocks); init_allocator(&mq->cache_alloc, &mq->es, total_sentinels + mq->nr_hotspot_blocks, total_sentinels + mq->nr_hotspot_blocks + from_cblock(cache_size)); mq->hotspot_hit_bits = alloc_bitset(mq->nr_hotspot_blocks); if (!mq->hotspot_hit_bits) { DMERR("couldn't allocate hotspot hit bitset"); goto bad_hotspot_hit_bits; } clear_bitset(mq->hotspot_hit_bits, mq->nr_hotspot_blocks); if (from_cblock(cache_size)) { mq->cache_hit_bits = alloc_bitset(from_cblock(cache_size)); if (!mq->cache_hit_bits) { DMERR("couldn't allocate cache hit bitset"); goto bad_cache_hit_bits; } clear_bitset(mq->cache_hit_bits, from_cblock(mq->cache_size)); } else mq->cache_hit_bits = NULL; mq->tick = 0; spin_lock_init(&mq->lock); q_init(&mq->hotspot, &mq->es, NR_HOTSPOT_LEVELS); mq->hotspot.nr_top_levels = 8; mq->hotspot.nr_in_top_levels = min(mq->nr_hotspot_blocks / NR_HOTSPOT_LEVELS, from_cblock(mq->cache_size) / mq->cache_blocks_per_hotspot_block); q_init(&mq->clean, &mq->es, NR_CACHE_LEVELS); q_init(&mq->dirty, &mq->es, NR_CACHE_LEVELS); stats_init(&mq->hotspot_stats, NR_HOTSPOT_LEVELS); stats_init(&mq->cache_stats, NR_CACHE_LEVELS); if (h_init(&mq->table, &mq->es, from_cblock(cache_size))) goto bad_alloc_table; if (h_init(&mq->hotspot_table, &mq->es, mq->nr_hotspot_blocks)) goto bad_alloc_hotspot_table; sentinels_init(mq); mq->write_promote_level = mq->read_promote_level = NR_HOTSPOT_LEVELS; mq->next_hotspot_period = jiffies; mq->next_cache_period = jiffies; return &mq->policy; bad_alloc_hotspot_table: h_exit(&mq->table); bad_alloc_table: free_bitset(mq->cache_hit_bits); bad_cache_hit_bits: free_bitset(mq->hotspot_hit_bits); bad_hotspot_hit_bits: space_exit(&mq->es); bad_pool_init: kfree(mq); return NULL; }
void vcf_file::print_bcf(const parameters ¶ms) { LOG.printLOG("Outputting BCF file...\n"); BGZF * out; if(!params.stream_out) { string output_file = params.output_prefix + ".recode.bcf"; out = bgzf_open(output_file.c_str(), "w"); } else out = bgzf_dopen(1, "w"); string header_str; uint32_t len_text = 0; vector<char> header; char magic[5] = {'B','C','F','\2', '\1'}; bgzf_write(out, magic, 5); if (meta_data.has_idx) { LOG.warning("VCF file contains IDX values in header. These are being removed for conversion to BCF."); meta_data.reprint(); meta_data.reparse(); } for (unsigned int ui=0; ui<meta_data.lines.size(); ui++) { for (unsigned int uj=0; uj<meta_data.lines[ui].length(); uj++) header.push_back( meta_data.lines[ui][uj] ); header.push_back('\n'); } if (meta_data.has_contigs == false) { vector<string> contig_vector; get_contigs(params.contigs_file, contig_vector); for(unsigned int ui=0; ui<contig_vector.size(); ui++) { meta_data.add_CONTIG_descriptor(contig_vector[ui].substr(10, contig_vector[ui].size()-8),int(ui)); for(unsigned int uj=0; uj<contig_vector[ui].size(); uj++) header.push_back(contig_vector[ui][uj]); header.push_back('\n'); } } header_str = "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO"; if (meta_data.N_indv > 0) header_str += "\tFORMAT"; for (unsigned int ui=0; ui<meta_data.N_indv; ui++) if (include_indv[ui]) { header_str += "\t"; header_str += meta_data.indv[ui]; } header_str += "\n"; for (unsigned int ui=0; ui<header_str.length(); ui++) header.push_back( header_str[ui] ); header.push_back( '\0' ); len_text = header.size(); bgzf_write(out, (char *)&len_text, sizeof(len_text) ); bgzf_write(out, (char *)&header[0], len_text ); vector<char> variant_line; entry * e = new vcf_entry(meta_data, include_indv); while(!eof()) { get_entry(variant_line); e->reset(variant_line); N_entries += e->apply_filters(params); if(!e->passed_filters) continue; N_kept_entries++; e->parse_basic_entry(true, true, true); e->parse_full_entry(true); e->parse_genotype_entries(true,true,true,true); e->print_bcf(out, params.recode_INFO_to_keep, params.recode_all_INFO); } delete e; bgzf_close(out); }
// return nullptr if the actor wasn't put *or* finished execution inline abstract_actor_ptr get(actor_id key) const { return get_entry(key).first; }
static inline xmlSchemaPtr get_node_schema(schema_cache* This, xmlNodePtr node) { cache_entry* entry = get_entry(This, get_node_nsURI(node)); return (!entry)? NULL : entry->schema; }
const glsl_type *glsl_symbol_table::get_type(const char *name) { symbol_table_entry *entry = get_entry(name); return entry != NULL ? entry->t : NULL; }
OM_uint32 KRB5_CALLCONV gss_import_cred(OM_uint32 *minor_status, gss_buffer_t token, gss_cred_id_t *cred_handle) { OM_uint32 status, tmpmin, count; gss_union_cred_t cred = NULL; gss_mechanism mech; gss_buffer_desc tok, mech_token; gss_OID_desc mech_oid; gss_OID selected_mech; gss_cred_id_t mech_cred; void *elemcopy; status = val_imp_cred_args(minor_status, token, cred_handle); if (status != GSS_S_COMPLETE) return status; /* Count the entries in token. */ for (tok = *token, count = 0; tok.length > 0; count++) { status = get_entry(minor_status, &tok, &mech_oid, &mech_token); if (status != GSS_S_COMPLETE) return status; } /* Allocate a union credential. */ cred = calloc(1, sizeof(*cred)); if (cred == NULL) goto oom; cred->loopback = cred; cred->count = 0; cred->mechs_array = calloc(count, sizeof(*cred->mechs_array)); if (cred->mechs_array == NULL) goto oom; cred->cred_array = calloc(count, sizeof(*cred->cred_array)); if (cred->cred_array == NULL) goto oom; tok = *token; while (tok.length > 0) { (void)get_entry(minor_status, &tok, &mech_oid, &mech_token); /* Import this entry's mechanism token. */ status = gssint_select_mech_type(minor_status, &mech_oid, &selected_mech); if (status != GSS_S_COMPLETE) goto error; mech = gssint_get_mechanism(selected_mech); if (mech == NULL || (mech->gss_import_cred == NULL && mech->gssspi_import_cred_by_mech == NULL)) { status = GSS_S_DEFECTIVE_TOKEN; goto error; } if (mech->gssspi_import_cred_by_mech) { status = mech->gssspi_import_cred_by_mech(minor_status, gssint_get_public_oid(selected_mech), &mech_token, &mech_cred); } else { status = mech->gss_import_cred(minor_status, &mech_token, &mech_cred); } if (status != GSS_S_COMPLETE) { map_error(minor_status, mech); goto error; } /* Add the resulting mechanism cred to the union cred. */ elemcopy = malloc(selected_mech->length); if (elemcopy == NULL) { if (mech->gss_release_cred != NULL) mech->gss_release_cred(&tmpmin, &mech_cred); goto oom; } memcpy(elemcopy, selected_mech->elements, selected_mech->length); cred->mechs_array[cred->count].length = selected_mech->length; cred->mechs_array[cred->count].elements = elemcopy; cred->cred_array[cred->count++] = mech_cred; } *cred_handle = cred; return GSS_S_COMPLETE; oom: status = GSS_S_FAILURE; *minor_status = ENOMEM; error: (void)gss_release_cred(&tmpmin, &cred); return status; }
Error PoolAllocator::resize(ID p_mem, int p_new_size) { mt_lock(); Entry *e = get_entry(p_mem); if (!e) { mt_unlock(); ERR_FAIL_COND_V(!e, ERR_INVALID_PARAMETER); } if (needs_locking && e->lock) { mt_unlock(); ERR_FAIL_COND_V(e->lock, ERR_ALREADY_IN_USE); } int alloc_size = aligned(p_new_size); if (aligned(e->len) == alloc_size) { e->len = p_new_size; mt_unlock(); return OK; } else if (e->len > (uint32_t)p_new_size) { free_mem += aligned(e->len); free_mem -= alloc_size; e->len = p_new_size; mt_unlock(); return OK; } //p_new_size = align(p_new_size) int _free = free_mem; // - static_area_size; if ((_free + aligned(e->len)) - alloc_size < 0) { mt_unlock(); ERR_FAIL_V(ERR_OUT_OF_MEMORY); }; EntryIndicesPos entry_indices_pos; bool index_found = find_entry_index(&entry_indices_pos, e); if (!index_found) { mt_unlock(); ERR_FAIL_COND_V(!index_found, ERR_BUG); } //no need to move stuff around, it fits before the next block int next_pos; if (entry_indices_pos + 1 == entry_count) { next_pos = pool_size; // - static_area_size; } else { next_pos = entry_array[entry_indices[entry_indices_pos + 1]].pos; }; if ((next_pos - e->pos) > alloc_size) { free_mem += aligned(e->len); e->len = p_new_size; free_mem -= alloc_size; mt_unlock(); return OK; } //it doesn't fit, compact around BEFORE current index (make room behind) compact(entry_indices_pos + 1); if ((next_pos - e->pos) > alloc_size) { //now fits! hooray! free_mem += aligned(e->len); e->len = p_new_size; free_mem -= alloc_size; mt_unlock(); if (free_mem < free_mem_peak) free_mem_peak = free_mem; return OK; } //STILL doesn't fit, compact around AFTER current index (make room after) compact_up(entry_indices_pos + 1); if ((entry_array[entry_indices[entry_indices_pos + 1]].pos - e->pos) > alloc_size) { //now fits! hooray! free_mem += aligned(e->len); e->len = p_new_size; free_mem -= alloc_size; mt_unlock(); if (free_mem < free_mem_peak) free_mem_peak = free_mem; return OK; } mt_unlock(); ERR_FAIL_V(ERR_OUT_OF_MEMORY); }
const char * get_rttables_group(uint32_t id) { return get_entry(id, &rt_groups, RT_GROUPS_FILE, NULL, INT32_MAX); }
/* Do every conceivable sanity check on the handle */ static void do_check(struct iptc_handle *h, unsigned int line) { unsigned int i, n; unsigned int user_offset; /* Offset of first user chain */ int was_return; assert(h->changed == 0 || h->changed == 1); if (strcmp(h->info.name, "filter") == 0) { assert(h->info.valid_hooks == (1 << NF_IP_LOCAL_IN | 1 << NF_IP_FORWARD | 1 << NF_IP_LOCAL_OUT)); /* Hooks should be first three */ assert(h->info.hook_entry[NF_IP_LOCAL_IN] == 0); n = get_chain_end(h, 0); n += get_entry(h, n)->next_offset; assert(h->info.hook_entry[NF_IP_FORWARD] == n); n = get_chain_end(h, n); n += get_entry(h, n)->next_offset; assert(h->info.hook_entry[NF_IP_LOCAL_OUT] == n); user_offset = h->info.hook_entry[NF_IP_LOCAL_OUT]; } else if (strcmp(h->info.name, "nat") == 0) { assert((h->info.valid_hooks == (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_POST_ROUTING | 1 << NF_IP_LOCAL_OUT)) || (h->info.valid_hooks == (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_IN | 1 << NF_IP_POST_ROUTING | 1 << NF_IP_LOCAL_OUT))); assert(h->info.hook_entry[NF_IP_PRE_ROUTING] == 0); n = get_chain_end(h, 0); n += get_entry(h, n)->next_offset; assert(h->info.hook_entry[NF_IP_POST_ROUTING] == n); n = get_chain_end(h, n); n += get_entry(h, n)->next_offset; assert(h->info.hook_entry[NF_IP_LOCAL_OUT] == n); user_offset = h->info.hook_entry[NF_IP_LOCAL_OUT]; if (h->info.valid_hooks & (1 << NF_IP_LOCAL_IN)) { n = get_chain_end(h, n); n += get_entry(h, n)->next_offset; assert(h->info.hook_entry[NF_IP_LOCAL_IN] == n); user_offset = h->info.hook_entry[NF_IP_LOCAL_IN]; } } else if (strcmp(h->info.name, "mangle") == 0) { /* This code is getting ugly because linux < 2.4.18-pre6 had * two mangle hooks, linux >= 2.4.18-pre6 has five mangle hooks * */ assert((h->info.valid_hooks == (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_OUT)) || (h->info.valid_hooks == (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_IN | 1 << NF_IP_FORWARD | 1 << NF_IP_LOCAL_OUT | 1 << NF_IP_POST_ROUTING))); /* Hooks should be first five */ assert(h->info.hook_entry[NF_IP_PRE_ROUTING] == 0); n = get_chain_end(h, 0); if (h->info.valid_hooks & (1 << NF_IP_LOCAL_IN)) { n += get_entry(h, n)->next_offset; assert(h->info.hook_entry[NF_IP_LOCAL_IN] == n); n = get_chain_end(h, n); } if (h->info.valid_hooks & (1 << NF_IP_FORWARD)) { n += get_entry(h, n)->next_offset; assert(h->info.hook_entry[NF_IP_FORWARD] == n); n = get_chain_end(h, n); } n += get_entry(h, n)->next_offset; assert(h->info.hook_entry[NF_IP_LOCAL_OUT] == n); user_offset = h->info.hook_entry[NF_IP_LOCAL_OUT]; if (h->info.valid_hooks & (1 << NF_IP_POST_ROUTING)) { n = get_chain_end(h, n); n += get_entry(h, n)->next_offset; assert(h->info.hook_entry[NF_IP_POST_ROUTING] == n); user_offset = h->info.hook_entry[NF_IP_POST_ROUTING]; } } else if (strcmp(h->info.name, "raw") == 0) { assert(h->info.valid_hooks == (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_OUT)); /* Hooks should be first three */ assert(h->info.hook_entry[NF_IP_PRE_ROUTING] == 0); n = get_chain_end(h, n); n += get_entry(h, n)->next_offset; assert(h->info.hook_entry[NF_IP_LOCAL_OUT] == n); user_offset = h->info.hook_entry[NF_IP_LOCAL_OUT]; #ifdef NF_IP_DROPPING } else if (strcmp(h->info.name, "drop") == 0) { assert(h->info.valid_hooks == (1 << NF_IP_DROPPING)); /* Hook should be first */ assert(h->info.hook_entry[NF_IP_DROPPING] == 0); user_offset = 0; #endif } else { fprintf(stderr, "Unknown table `%s'\n", h->info.name); abort(); } /* User chain == end of last builtin + policy entry */ user_offset = get_chain_end(h, user_offset); user_offset += get_entry(h, user_offset)->next_offset; /* Overflows should be end of entry chains, and unconditional policy nodes. */ for (i = 0; i < NUMHOOKS; i++) { STRUCT_ENTRY *e; STRUCT_STANDARD_TARGET *t; if (!(h->info.valid_hooks & (1 << i))) continue; assert(h->info.underflow[i] == get_chain_end(h, h->info.hook_entry[i])); e = get_entry(h, get_chain_end(h, h->info.hook_entry[i])); assert(unconditional(&e->ip)); assert(e->target_offset == sizeof(*e)); t = (STRUCT_STANDARD_TARGET *)GET_TARGET(e); assert(t->target.u.target_size == ALIGN(sizeof(*t))); assert(e->next_offset == sizeof(*e) + ALIGN(sizeof(*t))); assert(strcmp(t->target.u.user.name, STANDARD_TARGET)==0); assert(t->verdict == -NF_DROP-1 || t->verdict == -NF_ACCEPT-1); /* Hooks and underflows must be valid entries */ entry2index(h, get_entry(h, h->info.hook_entry[i])); entry2index(h, get_entry(h, h->info.underflow[i])); } assert(h->info.size >= h->info.num_entries * (sizeof(STRUCT_ENTRY) +sizeof(STRUCT_STANDARD_TARGET))); assert(h->entries.size >= (h->new_number * (sizeof(STRUCT_ENTRY) + sizeof(STRUCT_STANDARD_TARGET)))); assert(strcmp(h->info.name, h->entries.name) == 0); i = 0; n = 0; was_return = 0; /* Check all the entries. */ ENTRY_ITERATE(h->entries.entrytable, h->entries.size, check_entry, &i, &n, user_offset, &was_return, h); assert(i == h->new_number); assert(n == h->entries.size); /* Final entry must be error node */ assert(strcmp(GET_TARGET(index2entry(h, h->new_number-1)) ->u.user.name, ERROR_TARGET) == 0); }
const char * get_rttables_scope(uint32_t id) { return get_entry(id, &rt_scopes, RT_SCOPES_FILE, rtscope_default, 255); }
void Table::deleterow( streampos pos, string tuple, string col ) { //cout << col << endl; ifstream ifs( get_path( ) ); string temp_file; if( !ifs.is_open() ) { cerr << "ERROR opening file in Executor::deleterow(). " << endl; return; } string s; string line; while ( ifs.tellg() != pos ) { getline( ifs, line ); temp_file.append( line + string( "\n") ); } getline( ifs, line ); //temp_file.append( line + string( "\n") ); //cout << line << endl; // update btree index if( has_index( col ) ) { map<string, BTree*>::iterator map_itr = keys.find( col ); BTree * btree = map_itr->second; //construct tuple int type; string entry( get_entry( line, get_col_pos( col ) ) ); if( is_number( entry ) ) btree->remove( Tuple ( atoi( entry.c_str() ), pos ) ); else btree->remove( Tuple ( entry.c_str(), pos ) ); dump_tree( col, btree->get_first() ); } line[0] = '@'; temp_file.append( line + string( "\n") ); while ( getline( ifs, line ) ) temp_file.append( line + string( "\n") ); ifs.close(); // rewrite the whole file ofstream ofs ( get_path( ), std::ofstream::out | std::ofstream::trunc ); if( !ofs.is_open() ) { cerr << "ERROR opening out file in Executor::deleterow(). " << endl; return; } ofs << temp_file; ofs.close(); }
void cmd_task(void) { static char rst = 0; char *sp,*cp,*next; //,str[4]; long i=0; if(rcv_cmd) { rcv = 0; wdt_feed(); sp = get_entry (&buf_rx[0], &next); if(*sp == 0) { if(rst++ >= 10) { printf ("[FAIL CMD..restart now]\r"); fflush(stdout); LPC_WDT->WDTC = 0x003FFFF; /*0.5s*/ wdt_feed(); while(1); } sprintf(buf_tx,"ERROR %u",ERROR_COMMAND); }else { for (cp = sp; *cp && *cp != ' '; cp++) *cp = toupper (*cp); for (i = 0; i < CMD_COUNT; i++) { if (strcmp (sp, (const char *)&cmd[i].val)) continue; cmd[i].func (next); rst = 0; break; } } if(i == CMD_COUNT) sprintf(buf_tx,"ERROR %u",ERROR_COMMAND); if(i!=6 && rcv_cmd == RCV_CMD_UART_0) /*i=6 (Rcv Touch lpc1113)*/ { if(buf_tx[0] == 'E') beep(BEEP_ERROR); else beep(BEEP_CFG); }else /*Função IR learn, IR learn Scene, Detect Swing e IR learn app via TCP?*/ if((i == 0 || i == 12 || i == 13 || i == 17) && (rcv_cmd == RCV_CMD_TCP_SERVER || rcv_cmd == RCV_CMD_TCP_CLIENT)) { if(buf_tx[0] == 'E') beep(BEEP_ERROR); else beep(BEEP_CFG); } strcat(buf_tx,"\r\n\0"); if(rcv_cmd == RCV_CMD_UART_2) { // uart_putString(2,buf_tx); }else if(rcv_cmd == RCV_CMD_UART_0) uart_putString(0,buf_tx); #if USE_TCP_CLIENT /*Comunicação TCP CLIENT será usada?*/ else if((rcv_cmd == RCV_CMD_TCP_CLIENT)) { tcpSend (buf_tx, strlen(buf_tx), last_soc_client,CMD_SEND_TO_CLIENT); uart_putString(0,buf_tx); } #endif #if USE_TCP_SERVER /*Comunicação TCP SERVER será usada?*/ else if((rcv_cmd == RCV_CMD_TCP_SERVER)) { tcpSend (buf_tx, strlen(buf_tx), tcp_server_soc,CMD_SEND_TO_SERVER); uart_putString(0,buf_tx); } #endif memset(buf_rx,0,sizeof(buf_rx)); memset(buf_tx,0,sizeof(buf_tx)); if(!rcv) rcv_cmd = __FALSE; cntUART2 = 0; cntUART0 = 0; NVIC_EnableIRQ(UART2_IRQn); NVIC_EnableIRQ(UART0_IRQn); } }