LIST * list_push_back( LIST * head, OBJECT * value ) { unsigned int size = list_length( head ); unsigned int i; if ( DEBUG_LISTS ) out_printf( "list > %s <\n", object_str( value ) ); /* If the size is a power of 2, reallocate. */ if ( size == 0 ) { head = list_alloc( 1 ); } else if ( ( ( size - 1 ) & size ) == 0 ) { LIST * l = list_alloc( size + 1 ); memcpy( l, head, sizeof( LIST ) + size * sizeof( OBJECT * ) ); list_dealloc( head ); head = l; } list_begin( head )[ size ] = value; head->impl.size = size + 1; return head; }
/* * Initialize the monitor. * Creates list data structures. * If a saved list data file exists it is loaded. * The /proc directory is opened. * No actual scanning of /proc is done. * * Returns 0 if OK or -1 on error (leaving errno unchanged) */ int monitor_start() { if (setjmp(dm_jmpbuffer) == 0) { lwpid_init(); fd_init(Setrlimit()); list_alloc(&lwps, LS_LWPS); list_alloc(&processes, LT_PROCESS); list_alloc(&users, LS_USERS); list_alloc(&projects, LS_PROJECTS); list_init(&lwps, LT_LWPS); list_init(&processes, LT_PROCESS); list_init(&users, LT_USERS); list_init(&projects, LT_PROJECTS); sys_info.name = NULL; sys_info.nodename = NULL; if ((procdir = opendir("/proc")) == NULL) dmerror("cannot open /proc directory\n"); /* restore the lists state */ if (ltdb_file != NULL) (void) list_restore(ltdb_file); return (0); } else { return (-1); } }
cfg_t *cfg_alloc() { cfg_t *ret = MALLOC_ONE(cfg_t); int capacity = 5; ret->non_terminals = list_alloc(capacity, sizeof(token_t)); ret->terminals = list_alloc(capacity, sizeof(token_t)); ret->start_symbols = list_alloc(capacity, sizeof(token_t)); ret->rule_list = list_alloc(capacity, sizeof(cfg_rule_t)); return ret; }
int main () { list_t* listPtr; #ifdef LIST_NO_DUPLICATES long data1[] = {3, 1, 4, 1, 5, -1}; #else long data1[] = {3, 1, 4, 5, -1}; #endif long data2[] = {3, 1, 4, 1, 5, -1}; long i; puts("Starting..."); puts("List sorted by values:"); listPtr = list_alloc(&compare); for (i = 0; data1[i] >= 0; i++) { insertInt(listPtr, &data1[i]); assert(*((long*)list_find(listPtr, &data1[i])) == data1[i]); } for (i = 0; data1[i] >= 0; i++) { removeInt(listPtr, &data1[i]); assert(list_find(listPtr, &data1[i]) == NULL); } list_free(listPtr); puts("List sorted by addresses:"); listPtr = list_alloc(NULL); for (i = 0; data2[i] >= 0; i++) { insertInt(listPtr, &data2[i]); assert(*((long*)list_find(listPtr, &data2[i])) == data2[i]); } for (i = 0; data2[i] >= 0; i++) { removeInt(listPtr, &data2[i]); assert(list_find(listPtr, &data2[i]) == NULL); } list_free(listPtr); puts("Done."); return 0; }
hint32 hdata_set_tree(hdata_set_t data_set, hdata_set_tree_key_t key,hdata_set_tree_key_t parent_key,hash_code_t key_hash,equal_t key_equal,list_compare_t comparator,hany param,InvokeTickDeclare){ data_set_t * ds = (data_set_t *)data_set; hany k; hany pk; hint32 i,c; hdata_t items,item; data_set_tree_item_t * tree_item,*tree_pitem; data_set_tree_item_compare_param_t compare_param; if(ds && key && parent_key){ data_set_tree_item_dealloc(ds->tree_root,InvokeTickArg); ds->tree_root = data_set_tree_item_alloc( NULL, ext_data(ds->data),NULL,NULL,NULL,InvokeTickArg); ds->tree_level = 0; if(ds->tree_cache == NULL){ ds->tree_cache = map_alloc( key_hash, key_equal); } else{ map_clear(ds->tree_cache); } items = ext_data(ds->data); c = hdata_array_size(ext_data_class(ds->data), items); for(i=0;i<c;i++){ item = hdata_array(ext_data_class(ds->data),items,i); k = (*key)(data_set,item,param,InvokeTickArg); pk = (*parent_key)(data_set,item,param,InvokeTickArg); tree_pitem = map_get(ds->tree_cache, pk); tree_item = data_set_tree_item_alloc( k, item, tree_pitem == NULL?ds->tree_root:tree_pitem,comparator,param,InvokeTickArg); data_set_tree_item_dealloc( map_put(ds->tree_cache, k, tree_item),InvokeTickArg); if(ds->tree_level < tree_item->level){ ds->tree_level = tree_item->level; } } c = list_count(ds->tree_root->childs); for(i=0;i<c;i++){ tree_item = list_get(ds->tree_root->childs, i); pk = (*parent_key)(data_set,tree_item->data,param,InvokeTickArg); tree_pitem = map_get(ds->tree_cache, pk); if(tree_pitem){ list_remove_at(ds->tree_root->childs, i--); c = list_count(ds->tree_root->childs); if(tree_pitem->childs==NULL){ tree_pitem->childs = list_alloc(20, 20); } if(comparator){ compare_param.compare = comparator; compare_param.param = param; list_add_and_order(tree_pitem->childs, tree_item, data_set_tree_item_compare, &compare_param); } else{ list_add(tree_pitem->childs,tree_item); } tree_item->level = tree_pitem->level +1; if(ds->tree_level < tree_item->level){ ds->tree_level = tree_item->level; } } } return ds->tree_level; } return 0; }
bool create_preload_list(void) { ComponentHandlePtr component_handle; int index; bool ret = true; for (index=0;omx_components[index][0];index++) { struct list *entry; component_handle = (ComponentHandlePtr) malloc(sizeof(ComponentHandle)); strncpy(component_handle->comp_name, omx_components[index][0], OMX_MAX_STRINGNAME_SIZE); component_handle->comp_handle = NULL; component_handle->parser_handle = NULL; /* skip libraries starting with # */ if (component_handle->comp_name[0] == '#') continue; entry = list_alloc(component_handle); if (!entry) { ret=false; goto unload_comphandle; } preload_list = __list_add_tail(preload_list, entry); omx_infoLog("Added component %s to list", component_handle->comp_name); continue; unload_comphandle: dlclose(component_handle->comp_handle); } return ret; }
LIST * list_new( OBJECT * value ) { LIST * const head = list_alloc( 1 ) ; head->impl.size = 1; list_begin( head )[ 0 ] = value; return head; }
LIST * list_append( LIST * l, LIST * nl ) { if ( list_empty( l ) ) return nl; if ( !list_empty( nl ) ) { int const l_size = list_length( l ); int const nl_size = list_length( nl ); int const size = l_size + nl_size; unsigned const bucket = get_bucket( size ); /* Do we need to reallocate? */ if ( l_size <= ( 1u << ( bucket - 1 ) ) ) { LIST * result = list_alloc( size ); memcpy( list_begin( result ), list_begin( l ), l_size * sizeof( OBJECT * ) ); list_dealloc( l ); l = result; } l->impl.size = size; memcpy( list_begin( l ) + l_size, list_begin( nl ), nl_size * sizeof( OBJECT * ) ); list_dealloc( nl ); } return l; }
LIST * list_pop_front( LIST * l ) { unsigned size = list_length( l ); assert( size ); --size; object_free( list_front( l ) ); if ( size == 0 ) { list_dealloc( l ); return L0; } if ( ( ( size - 1 ) & size ) == 0 ) { LIST * const nl = list_alloc( size ); nl->impl.size = size; memcpy( list_begin( nl ), list_begin( l ) + 1, size * sizeof( OBJECT * ) ); list_dealloc( l ); return nl; } l->impl.size = size; memmove( list_begin( l ), list_begin( l ) + 1, size * sizeof( OBJECT * ) ); return l; }
void *my_first_alloc(int size) { if (total_free_size < size) { sbrk(size); } list_node_t *current = free_head.next; do { // 找到一个足够大的块 if (current->free && current->size >= size) { void *ret = current->start; current->free = 0; // 如果空闲块比需要的大则把剩余的部分新建成为一个块 if (current->size != size) { list_node_t *new_node = list_alloc(); new_node->free = 1; new_node->size = current->size - size; new_node->start = (char*)current->start + size; list_add(current, new_node); current->size = size; } total_free_size -= size; return ret; } current = current->next; } while (current != &free_head); return 0; }
int makeListOrganisations (struct namelist **olistp) { entrystruct * x; int retval; if (rebind() != OK) return NOTOK; retval = ds_search(&sarg, &serror, &sresult); if ((retval == DSE_INTR_ABANDONED) && (serror.dse_type == DSE_ABANDONED)) abandoned = TRUE; if (retval != OK) return NOTOK; correlate_search_results (&sresult); setProblemFlags(sresult); highNumber = 0; for (x = sresult.CSR_entries; x != NULLENTRYINFO; x = x->ent_next) { *olistp = list_alloc(); (*olistp)->name = dn2pstr(x->ent_dn); (*olistp)->ats = as_cpy(x->ent_attr); olistp = &(*olistp)->next; highNumber++; } *olistp = NULLLIST; entryinfo_free(sresult.CSR_entries, 0); dn_free (sresult.CSR_object); crefs_free (sresult.CSR_cr); filter_free(sarg.sra_filter); return OK; }
/** return item count */ hlist_t hdata_set_sort(hdata_set_t data_set, list_compare_t comparator ,hany param,InvokeTickDeclare){ data_set_t *ds = (data_set_t *)data_set; if(ds && comparator){ hdata_t items = ext_data(ds->data); hdata_t item; hint32 i,c; c = hdata_array_size(ext_data_class(ds->data), items); if(c >0){ if(ds->items==NULL){ ds->items = list_alloc( c, 20); } else{ list_clear(ds->items); } for(i=0;i<c;i++){ item = hdata_array(ext_data_class(ds->data),items,i); if(comparator){ list_add_and_order(ds->items, item, comparator, param); } else{ list_add(ds->items,item); } } } return ds->items; } return NULL; }
/* ============================================================================= * table_alloc * -- Returns NULL on failure * ============================================================================= */ table_t* table_alloc (long numBucket, comparator_t* compare) { table_t* tablePtr; long i; tablePtr = (table_t*)SEQ_MALLOC(sizeof(table_t)); if (tablePtr == NULL) { return NULL; } tablePtr->buckets = (list_t**)SEQ_MALLOC(numBucket * sizeof(list_t*)); if (tablePtr->buckets == NULL) { return NULL; } for (i = 0; i < numBucket; i++) { tablePtr->buckets[i] = list_alloc(compare); if (tablePtr->buckets[i] == NULL) { return NULL; } } tablePtr->numBucket = numBucket; return tablePtr; }
static data_xpath_tag_t * data_xpath_tag_alloc(hcchar * tagName,InvokeTickDeclare){ data_xpath_tag_t * tag = (data_xpath_tag_t *)mem_malloc( sizeof(data_xpath_tag_t)); memset(tag,0,sizeof(data_xpath_tag_t)); tag->tagName = tagName; tag->selectors = list_alloc( 20, 20); return tag; }
static void hdata_xpath_selctor(data_xpath_t * xpath,data_xpath_selector_t * selector,hlist_t result, hcchar * selector_name,hcchar * exp,hbool r,InvokeTickDeclare){ data_xpath_tag_t * tag = NULL; hint32 i,c ; hlist_t filters = list_alloc( 10, 10); hint32 index = data_xpath_tag_filter_parse( filters, exp,InvokeTickArg); if(r ){ tag = data_xpath_search_tag(selector,selector_name,index<0?filters:NULL,InvokeTickArg); } else{ tag = data_xpath_find_tag(selector,selector_name,index<0?filters:NULL,InvokeTickArg); } if(tag){ if(index <0){ data_xpath_tag_filter_handle( tag, result, filters,InvokeTickArg); } else if(index < list_count(tag->selectors)){ list_add(result, list_get(tag->selectors, index)); } } c = list_count(filters); for(i=0;i<c;i++){ data_xpath_tag_filter_dealloc( list_get(filters, i),InvokeTickArg); } list_dealloc(filters); }
hdata_t hdata_array_alloc(hint32 capacity,hint32 extendSize,InvokeTickDeclare){ data_t * d = (data_t *)mem_malloc(sizeof(data_t)); memset(d,0,sizeof(data_t)); d->version = DATA_STRUCT_VERSION; d->type = HDATA_TYPE_ARRAY; d->value.array_value = list_alloc( capacity, extendSize); return (hdata_t)d; }
static struct list *construct_components(void) { struct list *head = NULL, *preload_entry; ComponentHandlePtr component_handle; /* In Chromium OS, the OMX IL Client will call preload_components() * so that the preload_list is already populated. In non-chrome case, * we need to create the list here */ if (!preload_list) { if (!create_preload_list()) { omx_verboseLog("error: Preload list cannot be populated"); } } list_foreach(preload_list, preload_entry) { CModule *cmodule; struct list *entry; OMX_ERRORTYPE ret; component_handle = (ComponentHandlePtr) preload_entry->data; /* skip libraries starting with # */ if (component_handle->comp_name[0] == '#') continue; cmodule = new CModule(component_handle->comp_name); if (!cmodule) continue; omx_verboseLog("found component library %s", component_handle->comp_name); ret = cmodule->Load(MODULE_NOW, component_handle->comp_handle); if (ret != OMX_ErrorNone) goto delete_cmodule; ret = cmodule->SetParser(component_handle->parser_handle); if (ret != OMX_ErrorNone) goto delete_cmodule; ret = cmodule->QueryComponentNameAndRoles(); if (ret != OMX_ErrorNone) goto unload_cmodule; entry = list_alloc(cmodule); if (!entry) goto unload_cmodule; head = __list_add_tail(head, entry); omx_verboseLog("module %s:%s added to component list", cmodule->GetLibraryName(), cmodule->GetComponentName()); continue; unload_cmodule: cmodule->Unload(); delete_cmodule: delete cmodule; }
/* * Allocate a variable for a List and fill it from "*arg". * Return OK or FAIL. */ int get_list_tv(char_u **arg, typval_T *rettv, int evaluate) { list_T *l = NULL; typval_T tv; listitem_T *item; if (evaluate) { l = list_alloc(); if (l == NULL) return FAIL; } *arg = skipwhite(*arg + 1); while (**arg != ']' && **arg != NUL) { if (eval1(arg, &tv, evaluate) == FAIL) /* recursive! */ goto failret; if (evaluate) { item = listitem_alloc(); if (item != NULL) { item->li_tv = tv; item->li_tv.v_lock = 0; list_append(l, item); } else clear_tv(&tv); } if (**arg == ']') break; if (**arg != ',') { EMSG2(_("E696: Missing comma in List: %s"), *arg); goto failret; } *arg = skipwhite(*arg + 1); } if (**arg != ']') { EMSG2(_("E697: Missing end of List ']': %s"), *arg); failret: if (evaluate) list_free(l); return FAIL; } *arg = skipwhite(*arg + 1); if (evaluate) rettv_list_set(rettv, l); return OK; }
/* * list_alloc() with an ID for alloc_fail(). */ list_T * list_alloc_id(alloc_id_T id UNUSED) { #ifdef FEAT_EVAL if (alloc_fail_id == id && alloc_does_fail((long_u)sizeof(list_T))) return NULL; #endif return (list_alloc()); }
List * list_prepend (List *list, void *data) { List *ret = list_alloc (); ret->data = data; ret->next = list; return ret; }
HOOK* init_hook(HOOK_MODE mode) { HOOK* hook = xalloc(sizeof(HOOK)); List* results; hook->mode = mode; list_alloc(results, HOOK_RESULT, NULL, NULL); hook->results = results; return hook; }
extern "C" bool preload_components(void) { /* this function is called by openMAX-IL client when libraries are to be * loaded at initial stages. Security features of the operating system require * to load libraries upfront */ ComponentHandlePtr component_handle; int index; bool ret = true; for (index=0;omx_components[index][0];index++) { struct list *entry; component_handle = (ComponentHandlePtr) malloc(sizeof(ComponentHandle)); strncpy(component_handle->comp_name, omx_components[index][0], OMX_MAX_STRINGNAME_SIZE); /* parser is not always needed */ if (omx_components[index][1]) strncpy(component_handle->parser_name, omx_components[index][1], OMX_MAX_STRINGNAME_SIZE); /* skip libraries starting with # */ if (component_handle->comp_name[0] == '#') continue; component_handle->comp_handle = dlopen(component_handle->comp_name, RTLD_NOW); if (!component_handle->comp_handle) { ret=false; goto delete_comphandle; } if (component_handle->parser_name) { /* some components don't need a parser */ component_handle->parser_handle = dlopen(component_handle->parser_name, RTLD_NOW); if (!component_handle->parser_handle) { ret=false; goto delete_comphandle; } } entry = list_alloc(component_handle); if (!entry) { ret=false; goto unload_comphandle; } preload_list = __list_add_tail(preload_list, entry); omx_infoLog("open component %s and parser %s", component_handle->comp_name, component_handle->parser_name == NULL ? "No parser provided":component_handle->parser_name ); continue; unload_comphandle: dlclose(component_handle->comp_handle); delete_comphandle: free(component_handle); } return ret; }
/*-------------------------------------------------------------------------*/ scheduler_t *scheduler_alloc(int nthreads) { scheduler_t *sched = (scheduler_t*)malloc(sizeof(scheduler_t)); sched->nthreads = nthreads; sched->ntasks = 0; sched->pause = 0; sched->disk = -1; sched->queue[low] = list_alloc(); sched->queue[disk] = list_alloc(); sched->queue[high] = list_alloc(); /* Create and initialise the semaphore. */ #ifndef OSX sched->sem = (sem_t*)malloc(sizeof(sem_t)); if (sem_init(sched->sem, 0, 0) != 0) { fprintf(stderr, "scheduler_alloc: cannot initialise the semaphore\n"); exit(1); } #else sem_unlink("ophcrack_scheduler"); sched->sem = sem_open("ophcrack_scheduler", O_CREAT | O_EXCL, 0, 0); if (sched->sem == SEM_FAILED) { fprintf(stderr, "scheduler_alloc: cannot initialise the semaphore\n"); exit(1); } #endif /* Create and initialise the mutex and conditional variable, and allocate space to store the threads. */ sched->mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(sched->mutex, 0); sched->cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t)); pthread_cond_init(sched->cond, 0); sched->thread = (pthread_t*)malloc(nthreads*sizeof(pthread_t)); return sched; }
static void sssp_bfs(void) { list_t *todo_list = list_alloc(NULL); /* Clear visited status on nodes */ for splay_each(node_t, n, node_tree) { n->status.visited = false; n->status.indirect = true; n->distance = -1; }
static int list_ensure_space( list *a ) { int status = LIST_OK; if ( a->max==0 ) status = list_alloc( a ); else if ( a->n >= a->max ) status = list_realloc( a ); return status; }
list_t list_append(list_t *plist,void *ptr) #endif { register list_t list; while (*plist) plist = &(list_next(*plist)); /* find end of list */ #if MEM_DEBUG list = list_alloc(file,line); #else list = list_alloc(); #endif if (list) { *plist = list; list_next(list) = 0; list_ptr(list) = ptr; list->count = 1; } return list; }
list_t list_prepend(list_t *plist,void *ptr) { register list_t list; list = list_alloc(fileline); if (list) { list_next(list) = *plist; list_ptr(list) = ptr; list->count = 1; *plist = list; } return list; }
/* * Allocate an empty list for a return value, with reference count set. * Returns OK or FAIL. */ int rettv_list_alloc(typval_T *rettv) { list_T *l = list_alloc(); if (l == NULL) return FAIL; rettv->v_lock = 0; rettv_list_set(rettv, l); return OK; }
hdata_xpath_selector_t hdata_xpath_single(hdata_xpath_t data_xpath, hcchar * path,hdata_xpath_selector_t parent_selector,InvokeTickDeclare){ if(data_xpath && path){ hlist_t selectors = list_alloc( 20, 20); data_xpath_selector_t * s = NULL; hdata_xpath(data_xpath,path,selectors,parent_selector,InvokeTickArg); if(list_count(selectors) >0){ s = list_get(selectors, 0); } list_dealloc(selectors); return (hdata_xpath_selector_t)s; } return NULL; }
/*-------------------------------------------------------------------------*/ fsm_t *fsm_alloc(ophcrack_t *crack) { fsm_t *fsm = (fsm_t*)malloc(sizeof(fsm_t)); fsm->oldstate = st_wait; fsm->state = st_wait; fsm->crack = crack; fsm->arg = crack->arg; fsm->preload = 1; fsm->bforce = fsm->arg->bforce; fsm->pwait = 0; fsm->ssave = 0; fsm->pending_msg = list_alloc(); fsm->htoremove = list_alloc(); fsm_reset_preload(fsm); fsm_reset_bforce(fsm); return fsm; }