void slist_partition_destructive( slist **xs , slist **notmatch , void *cc , bool (*filt)(void*, void*) ) { if( !xs ) return; if( !notmatch ) return; slist *new_l = slist_nil(); slist *phead = slist_nil(); slist *new_l2 = slist_nil(); slist *phead2 = slist_nil(); while( xs ) { slist *i = slist_uncons(xs); if( i == NULL ) break; i->next = slist_nil(); if( filt && filt(cc, i->value) ) { if( new_l == NULL ) { new_l = slist_cons(i, new_l); phead = new_l; continue; } phead->next = i; phead = phead->next; } else { if( new_l2 == NULL ) { new_l2 = slist_cons(i, new_l2); phead2 = new_l2; continue; } phead2->next = i; phead2 = phead2->next; } } *xs = new_l; *notmatch = new_l2; }
void slist_reverse(slist **r) { slist *hd = 0; while( r && *r ) { hd = slist_cons(slist_uncons(r), hd); } *r = hd; }
slist* slist_pool_(slist *root, void *mem, size_t chunk_size, size_t mem_size) { const size_t chunks = mem_size / chunk_size; char *p = (char *) mem; char *e = (char *) mem + chunks * chunk_size; for( ; p < e; p += chunk_size ) { root = slist_cons((slist *) p, root); } return root; }
void slist_filt_destructive( slist **xs , void *cc , bool (*cb)(void*, void*) , void *ccd , void (*destroy)(void*, slist*) ) { slist *new_l = slist_nil(); slist *phead = slist_nil(); if( !xs ) return; while( xs ) { slist *i = slist_uncons(xs); if( i == NULL ) break; i->next = slist_nil(); if( cb && cb(cc, i->value) ) { if( new_l == NULL ) { new_l = slist_cons(i, new_l); phead = new_l; continue; } phead->next = i; phead = phead->next; } else { if( destroy ) { destroy(ccd, i); } } } *xs = new_l; }
/* Hook VTABLE into our global LOADERS list according to its own PRIORITY field value. */ int lt_dlloader_add (const lt_dlvtable *vtable) { SList *item; if ((vtable == 0) /* diagnose invalid vtable fields */ || (vtable->module_open == 0) || (vtable->module_close == 0) || (vtable->find_sym == 0) || ((vtable->priority != LT_DLLOADER_PREPEND) && (vtable->priority != LT_DLLOADER_APPEND))) { LT__SETERROR (INVALID_LOADER); return RETURN_FAILURE; } item = slist_box (vtable); if (!item) { (*lt__alloc_die) (); /* Let the caller know something went wrong if lt__alloc_die doesn't abort. */ return RETURN_FAILURE; } if (vtable->priority == LT_DLLOADER_PREPEND) { loaders = slist_cons (item, loaders); } else { assert (vtable->priority == LT_DLLOADER_APPEND); loaders = slist_concat (loaders, item); } return RETURN_SUCCESS; }