int IoAudioMixer_isActive(IoAudioMixer *self) { return List_size(DATA(self)->sounds) || List_size(DATA(self)->soundsToRemove) || List_size(DATA(self)->events) || List_size(DATA(self)->activeEvents); }
static void dns(Dict* dns, struct Context* ctx, struct Except* eh) { List* servers = Dict_getList(dns, String_CONST("servers")); int count = List_size(servers); for (int i = 0; i < count; i++) { String* server = List_getString(servers, i); if (!server) { Except_throw(eh, "dns.servers[%d] is not a string", i); } Dict* d = Dict_new(ctx->alloc); Dict_putString(d, String_CONST("addr"), server, ctx->alloc); rpcCall(String_CONST("RainflyClient_addServer"), d, ctx, ctx->alloc); } List* keys = Dict_getList(dns, String_CONST("keys")); count = List_size(keys); for (int i = 0; i < count; i++) { String* key = List_getString(keys, i); if (!key) { Except_throw(eh, "dns.keys[%d] is not a string", i); } Dict* d = Dict_new(ctx->alloc); Dict_putString(d, String_CONST("ident"), key, ctx->alloc); rpcCall(String_CONST("RainflyClient_addKey"), d, ctx, ctx->alloc); } int64_t* minSigs = Dict_getInt(dns, String_CONST("minSignatures")); if (minSigs) { Dict* d = Dict_new(ctx->alloc); Dict_putInt(d, String_CONST("count"), *minSigs, ctx->alloc); rpcCall(String_CONST("RainflyClient_minSignatures"), d, ctx, ctx->alloc); } }
static void getSomething(Dict* args, struct RouteGen_admin_Ctx* ctx, String* txid, struct Allocator* requestAlloc, Dict* genRoutes) { int page = getIntVal(args, String_CONST("page")); List* routes; if (getIntVal(args, String_CONST("ip6"))) { routes = Dict_getList(genRoutes, String_CONST("ipv6")); } else { routes = Dict_getList(genRoutes, String_CONST("ipv4")); } Assert_true(routes); List* outList = List_new(requestAlloc); bool more = false; for (int i = page * ROUTES_PER_PAGE, j = 0; i < List_size(routes) && j < ROUTES_PER_PAGE; j++) { String* route = List_getString(routes, i); Assert_true(route); List_addString(outList, route, requestAlloc); if (++i >= List_size(routes)) { more = false; break; } more = true; } Dict* out = Dict_new(requestAlloc); if (more) { Dict_putInt(out, String_new("more", requestAlloc), 1, requestAlloc); } Dict_putList(out, String_new("routes", requestAlloc), outList, requestAlloc); Admin_sendMessage(out, txid, ctx->admin); }
int IoList_compare(IoList *self, IoList *otherList) { if (!ISLIST(otherList)) { return IoObject_defaultCompare(self, otherList); } else { size_t s1 = List_size(DATA(self)); size_t s2 = List_size(DATA(otherList)); size_t i; if (s1 != s2) { return s1 > s2 ? 1 : -1; } for (i = 0; i < s1; i ++) { IoObject *v1 = LIST_AT_(DATA(self), i); IoObject *v2 = LIST_AT_(DATA(otherList), i); int c = IoObject_compare(v1, v2); if (c) { return c; } } } return 0; }
END_TEST START_TEST (test_List_findIf) { List_t *list; const char *foo = "foo"; const char *bar = "bar"; const char *baz = "baz"; const char *bop = "bop"; List_add(L, (void *) foo); List_add(L, (void *) bop); list = List_findIf(L, myPredicate); fail_unless( list != NULL ); fail_unless( List_size(list) == 0 ); List_free(list); List_add(L, (void *) foo); List_add(L, (void *) bar); List_add(L, (void *) baz); List_add(L, (void *) bop); list = List_findIf(L, myPredicate); fail_unless( list != NULL ); fail_unless( List_size(list) == 2 ); fail_unless( List_get(list, 0) == bar ); fail_unless( List_get(list, 1) == baz ); List_free(list); List_add(L, (void *) baz); list = List_findIf(L, myPredicate); fail_unless( list != NULL ); fail_unless( List_size(list) == 3 ); fail_unless( List_get(list, 0) == bar ); fail_unless( List_get(list, 1) == baz ); fail_unless( List_get(list, 2) == baz ); List_free(list); }
static void authorizedPasswords(List* list, struct Context* ctx) { uint32_t count = List_size(list); for (uint32_t i = 0; i < count; i++) { Dict* d = List_getDict(list, i); Log_info(ctx->logger, "Checking authorized password %d.", i); if (!d) { Log_critical(ctx->logger, "Not a dictionary type %d.", i); exit(-1); } String* passwd = Dict_getString(d, String_CONST("password")); if (!passwd) { Log_critical(ctx->logger, "Must specify a password %d.", i); exit(-1); } } Log_info(ctx->logger, "Flushing existing authorized passwords"); rpcCall(String_CONST("AuthorizedPasswords_flush"), NULL, ctx, ctx->alloc); for (uint32_t i = 0; i < count; i++) { Dict* d = List_getDict(list, i); String* passwd = Dict_getString(d, String_CONST("password")); Log_info(ctx->logger, "Adding authorized password #[%d].", i); Dict args = Dict_CONST( String_CONST("authType"), Int_OBJ(1), Dict_CONST( String_CONST("password"), String_OBJ(passwd), NULL )); struct Allocator* child = ctx->alloc->child(ctx->alloc); rpcCall(String_CONST("AuthorizedPasswords_add"), &args, ctx, child); child->free(child); } }
long Datum_find_(Datum *self, void *delimsList, size_t startIndex) { List *delims = (List *)delimsList; List *results = List_new(); size_t i, last = 0; if (startIndex > self->size) return -1; for (i = startIndex; i < self->size; i ++) { Datum d = Datum_datumAt_(self, i); size_t j; for (j = 0; j < (size_t)List_size(delims); j ++) { Datum *delim = (Datum *)List_at_(delims, j); if (Datum_beginsWith_(&d, delim)) { return i; } } } return -1; }
void *Datum_split_(Datum *self, void *delimsList) /* returns a List */ { List *delims = (List *)delimsList; List *results = List_new(); size_t i, last = 0; for (i = 0; i < self->size; i ++) { Datum d = Datum_datumAt_(self, i); size_t j; for (j = 0; j < (size_t)List_size(delims); j ++) { Datum *delim = (Datum *)List_at_(delims, j); if (Datum_beginsWith_(&d, delim)) { List_append_(results, Datum_newFrom_to_(self, last, i)); last = i + delim->size; i = last - 1; /* since for() will increment it */ break; } } } if (last != self->size) { List_append_(results, Datum_newFrom_to_(self, last, self->size)); } return results; }
int IoLexer_lex(IoLexer *self) { IoLexer_clear(self); IoLexer_pushPos(self); IoLexer_messageChain(self); if (*(self->current)) { //printf("Lexing error after: "); //IoLexer_printLast_(self, 30); //printf("\n"); if (!self->errorToken) { if (List_size(self->tokenStream)) { self->errorToken = IoLexer_currentToken(self); } else { self->errorToken = IoLexer_addTokenString_length_type_(self, self->current, 30, NO_TOKEN); } IoToken_error_(self->errorToken, "Syntax error near this location"); } return -1; } return 0; }
IoMessage *IoMessage_opShuffle(IoMessage *self, IoObject *locals, IoMessage *m) { Levels *levels = Levels_new(self); List *expressions = List_new(); List_push_(expressions, self); while (List_size(expressions) >= 1) { IoMessage *n = List_pop(expressions); do { Levels_attach(levels, n, expressions); List_appendSeq_(expressions, DATA(n)->args); } while ((n = DATA(n)->next)); Levels_nextMessage(levels); } List_free(expressions); Levels_free(levels); return self; }
struct EncodingScheme* EncodingScheme_fromList(List* scheme, struct Allocator* alloc) { struct EncodingScheme* list = Allocator_malloc(alloc, sizeof(struct EncodingScheme)); list->count = List_size(scheme); list->forms = Allocator_malloc(alloc, sizeof(struct EncodingScheme_Form) * list->count); for (int i = 0; i < (int)list->count; i++) { Dict* form = List_getDict(scheme, i); uint64_t* prefixLen = Dict_getInt(form, String_CONST("prefixLen")); uint64_t* bitCount = Dict_getInt(form, String_CONST("bitCount")); String* prefixStr = Dict_getString(form, String_CONST("prefix")); if (!prefixLen || !bitCount || !prefixStr || prefixStr->len != 8) { return NULL; } uint32_t prefix_be; if (Hex_decode((uint8_t*)&prefix_be, 4, prefixStr->bytes, 8) != 4) { return NULL; } list->forms[i].prefixLen = *prefixLen; list->forms[i].bitCount = *bitCount; list->forms[i].prefix = Endian_bigEndianToHost32(prefix_be); } if (!EncodingScheme_isSane(list)) { return NULL; } return list; }
void LongNum_multi(LongNum **num1, LongNum **num2, LongNum **result) { node *temp1 = (*num1)->digits; node *temp2 = (*num2)->digits; node *temp = NULL; LongNum *temp1S = LongNum_empty (); LongNum *temp2S = LongNum_empty (); LongNum *tempResult = LongNum_empty (); int curr = 0, fact = 0, i = 0, point = 0; if (List_size(&(*num1)->digits) > List_size(&(*num2)->digits)) { while (temp2 != NULL) { fact = temp2->val; while (temp1 != NULL) { curr = curr + fact * temp1->val; List_additionElement (&temp1S->digits, curr % 10); curr = curr / 10; temp1 = temp1->next; } if (curr) List_additionElement (&temp1S->digits, curr); LongNum_revert(&temp1S); for (i = 0; i < curr; i++) (&temp1S->digits, 0); LongNum_sum (&temp1S, &temp2S,&tempResult); temp = tempResult->digits; while (temp != NULL) { fact = (int)*(&temp->val); List_additionElement (&(*result)->digits, fact); temp = temp->next; } point = point + 1; temp2 = temp2->next; } temp = temp2S->digits; while (temp != NULL) { fact = (int)*(&temp->val); List_additionElement (&(*result)->digits, fact); temp = temp->next; } } return; }
/* Return value negative indicates failure */ int Allocate_list( int list_size /* in */, LOCAL_LIST_T* local_keys /* out */) { List_allocated_size(local_keys) = list_size/p; List_size(local_keys) = list_size/p; return 0; } /* Allocate_list */
IO_METHOD(IoObject, recycledObjectCount) { /*doc System recycledObjectCount Returns the current number of objects being held for recycling. */ return IONUMBER(List_size(IOSTATE->recycledObjects)); }
void IoMessage_assertArgCount_receiver_(IoMessage *self, int n, IoObject *receiver) { if (List_size(DATA(self)->args) < n) { IoState_error_(IOSTATE, self, "[%s %s] requires %i arguments\n", IoObject_name(receiver), CSTRING(DATA(self)->name), n); } }
void remove_mid(List *list) { List_push(list, 12); List_push(list, 7); List_push(list, 8); List_remove(list, List_index(list, 1)); assert(List_size(list) == 2); assert(List_first(list)->data == 12); assert(List_last(list)->data == 8); }
IoObject *IoCFFIFunction_call(IoCFFIFunction *self, IoObject *locals, IoMessage *m) { IoCFFILibrary *library; const char *funName; void *funPointer, **funArgVals, *funRetVal; ffi_type **funArgTypes, *funRetType; ffi_cif *funInterface; int funArgCount, i; ffi_status status; IoObject *returnValAsObj, *funRetTypeObject, *o; List *funArgTypeObjects; library = IoObject_getSlot_(self, IOSYMBOL("library")); funInterface = &(DATA(self)->interface); funName = CSTRING(IoObject_getSlot_(self, IOSYMBOL("name"))); funPointer = IoCFFILibrary_rawGetFuctionPointer_(library, funName); funArgTypeObjects = IoList_rawList(IoObject_getSlot_(self, IOSYMBOL("argumentTypes"))); funRetTypeObject = IoObject_getSlot_(self, IOSYMBOL("returnType")); funArgCount = (int)List_size(funArgTypeObjects); funArgTypes = calloc(funArgCount, sizeof(ffi_type *)); for (i = 0; i < funArgCount; i++) { o = List_at_(funArgTypeObjects, i); funArgTypes[i] = IoCFFIDataType_ffiType(o); } funRetType = IoCFFIDataType_ffiType(funRetTypeObject); status = ffi_prep_cif(funInterface, FFI_DEFAULT_ABI, funArgCount, funRetType, funArgTypes); if (status != FFI_OK) { printf("\n\nUh oh. Something went wrong in IoCFFIFunction_call.\n\n"); free(funArgTypes); return IONIL(self); } funArgVals = calloc(funArgCount, sizeof(void *)); funRetVal = calloc(1, funRetType->size); IoState_pushCollectorPause(IOSTATE); { for (i = 0; i < funArgCount; i++) { o = IoMessage_locals_valueArgAt_(m, locals, i); funArgVals[i] = IoCFFIDataType_ValuePointerFromObject_(o); } ffi_call(funInterface, funPointer, funRetVal, funArgVals); returnValAsObj = IoCFFIDataType_objectFromData_(funRetTypeObject, funRetVal); } IoState_popCollectorPause(IOSTATE); free(funArgTypes); free(funArgVals); free(funRetVal); return returnValAsObj; }
IoObject *IoAudioMixer_removeAllSounds(IoAudioMixer *self, IoObject *locals, IoMessage *m) { List *sounds = DATA(self)->sounds; while (List_size(sounds)) { IoAudioMixer_justRemoveSound_(self, List_at_(sounds, 0)); } return self; }
void Get_local_keys(LOCAL_LIST_T* local_keys) { int i; /* Seed the generator */ srand(my_rank); for (i = 0; i < List_size(local_keys); i++) Insert_key(rand() % KEY_MOD, i, local_keys); } /* Get_local_keys */
void IoLexer_printTokens(IoLexer *self) { int i; for (i = 0; i < List_size(self->tokenStream); i ++) { IoToken *t = List_at_(self->tokenStream, i); printf("'%s'", t->name); printf(" %s ", IoToken_typeName(t)); if (i < List_size(self->tokenStream) - 1) { printf(", "); } } printf("\n"); }
static int PD_IsMemWriteExpr (Expr expr) { P_memdep_t md; P_memdep_core_t dep; md = P_GetMemDep (expr); assert (List_size (md->deps) > 0); dep = List_get_first (md->deps); return (dep->is_def == 1); }
static void AddExprToList (Expr expr, List * plist) { P_memdep_t md; md = P_GetMemDep (expr); if ((List_size (md->deps) > 0)) *plist = List_insert_last (*plist, expr); return; }
END_TEST START_TEST (test_List_freeItems) { List_add(L, safe_strdup("foo")); List_add(L, safe_strdup("bar")); List_add(L, safe_strdup("baz")); fail_unless(List_size(L) == 3); List_freeItems(L, safe_free, void); fail_unless(List_size(L) == 0); /* fail_unless(L->head == NULL); fail_unless(L->tail == NULL); */ }
void IoAudioMixer_showEvents(IoAudioMixer *self) { List *events = DATA(self)->events; int i; for (i=0; i<List_size(events); i++) { printf("%i: ", i); AudioEvent_show(List_at_(events, i)); } /*List_do_(events, (ListDoCallback *)AudioEvent_show);*/ printf("\n"); }
IoObject *IoThread_threadCount(IoObject *self, IoObject *locals, IoMessage *m) { Thread_Init(); List *threads; size_t count; threads = Thread_Threads(); count = List_size(threads); List_free(threads); return IONUMBER(count); }
static char* setUser(List* config) { for (int i = 0; i < List_size(config); i++) { Dict* d = List_getDict(config, i); if (d) { String* uname = Dict_getString(d, BSTR("setuser")); if (uname) { return uname->bytes; } } } return NULL; }
static void create_compact_summary() { effect_t *effect; int cnt = 0; local_sum = IPA_cg_cgraph_new(cg->data.fninfo); effect_list = NULL; SE_initial_effects(); DEBUG_IPA(2, printf("\nInitial Effects: %d (%d cg nodes)\n", List_size(effect_list), IPA_htab_size(cg->nodes)););
int Set_equals (T set1, T set2) { T newSet; List_t p; Assert_ASSERT(set1); Assert_ASSERT(set1); if (List_size (set1->list) != List_size (set2->list)) return 0; p = List_getFirst (set1->list); while (p){ Poly_t v = (Poly_t)p->data; if (List_exists (set2->list, v, set1->equals)) ; else return 0; p = p->next; } return 1; }
/* * classify IGNORE * * this is to classify dumb SCC's that we find because we * are not using a pruned SSA * * return 1 if we are classifying */ static int Classify_Ignore(PSS_TarSCC scc) { /* you cannot have an SCC with a single node (the mu node) * cause this does not do anything */ if (List_size(scc->tnode_list) == 1) { scc->type = IGNORE; PSS_PrintSCC(scc); return 1; } return 0; }
int main(int argc, char **argv) { List_t l = List_new(); fprintf(stdout, "test List...\n"); int i; for (i = 0; i < 100; i++) { List_addFirst(l, i); } fprintf(stdout, "List_getFirst\n"); int r = (int) List_getFirst(l); assert(r == 99); fprintf(stdout, "List_getIndexOf\n"); for (i = 0; i < 100; i++) { r = (int) List_getIndexOf(l, i); assert(r == (99 - i)); } fprintf(stdout, "List_addLast\n"); List_addLast(l, 200); r = (int) List_getIndexOf(l, 100); assert(r == 200); fprintf(stdout, "List_size\n"); r = List_size(l); assert(r == 101); fprintf(stdout, "List_isEmpty\n"); r = List_isEmpty(l); assert(r == 0); List_t l2 = List_new(); r = List_isEmpty(l2); assert(r == 1); fprintf(stdout, "List_remove\n"); for (i = 0; i < 100; i++) { r = (int) List_removeFirst(l); assert(r == (99 - i)); } r = (int) List_removeFirst(l); assert(r == 200); r = List_isEmpty(l); assert(r == 1); return 0; }