IoAudioMixer *IoAudioMixer_rawClone(IoAudioMixer *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); self->data = cpalloc(proto->data, sizeof(IoAudioMixerData)); DATA(self)->ioBuffer = IoSeq_new(IOSTATE); DATA(self)->buffer = IoSeq_rawUArray(DATA(self)->ioBuffer); DATA(proto)->mixBuffer = UArray_new(); DATA(self)->writeMessage = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("write"), IOSYMBOL("AudioMixer")); IoMessage_setCachedArg_to_(DATA(self)->writeMessage, 0, DATA(self)->ioBuffer); DATA(self)->nonBlockingWriteMessage = IoMessage_newWithName_label_(IOSTATE, IOSYMBOL("nonBlockingWrite"), IOSYMBOL("AudioMixer")); IoMessage_setCachedArg_to_(DATA(self)->nonBlockingWriteMessage, 0, DATA(self)->ioBuffer); DATA(self)->sounds = List_new(); DATA(self)->soundsToRemove = List_new(); DATA(self)->events = List_new(); DATA(self)->activeEvents = List_new(); DATA(self)->volume = DATA(self)->volume; DATA(self)->soundTouch = SoundTouch_init(); SoundTouch_setSampleRate(DATA(self)->soundTouch, 44100); SoundTouch_setChannels(DATA(self)->soundTouch, 2); DATA(self)->tempo = 1.0; IoState_addValue_(IOSTATE, self); return self; }
svc_t * s16_svc_new () { svc_t * newSvc = calloc (1, sizeof (svc_t)); newSvc->properties = List_new (); newSvc->instances = List_new (); return newSvc; }
Post_t Post_new(int xCoord, int yCoord){ Post_t self = (Post_t) malloc(sizeof(struct Post)); self->wantedCars = List_new(); self->wantedCarEvents = List_new(); self->transists = List_new(); self->xCoord = xCoord; self->yCoord = yCoord; return self; }
// Creates a new RULE CONDITION GRAPH - it creates a RCG node for every tuple variable // Takes the tuple variable and the data source list along with the number of tuple variables // as the input RCG *RCG_new(int num_tuple_var, List *tuple_var_list, List *datasrc_list) { RCG *graph; int i; ListElement *cursor1, *cursor2; RCG_node *node; void *tuple_var_name, *datasrc_name; ASSERT(tuple_var_list); ASSERT(datasrc_list); graph = (RCG *)tman_malloc(sizeof(RCG)); memset(graph, '\0', sizeof(RCG)); graph->type = RCG_TYPE; graph->num_tuple_variables = num_tuple_var; graph->nodes = List_new(); graph->catch_all = List_new(); if (!num_tuple_var) { /* The RCG does not have any tuple variables. For ex. ** when 1 = 1. */ return graph; } /* create the individual nodes -- one for each tuple variable*/ node = RCG_node_new(); tuple_var_name = (char *)List_getFirst(tuple_var_list, &cursor1); datasrc_name = (char *)List_getFirst(datasrc_list, &cursor2); node->tuple_variable_name = get_chars(tuple_var_name); node->datasrc_name = get_chars(datasrc_name); /* Insert the node into the RCG */ List_insertElement(graph->nodes, node); for (i = 1; i < num_tuple_var; i++) { /* create the individual nodes */ node = RCG_node_new(); tuple_var_name = (char *)List_getNext(&cursor1); datasrc_name = (char *)List_getNext(&cursor2); node->tuple_variable_name = get_chars(tuple_var_name); node->datasrc_name = get_chars(datasrc_name); /* Insert the node into the RCG */ List_insertElement(graph->nodes, node); } return graph; }
IoLexer *IoLexer_new(void) { IoLexer *self = (IoLexer *)io_calloc(1, sizeof(IoLexer)); self->s = (char *)io_calloc(1, 1); self->s[0] = 0; self->posStack = Stack_new(); self->tokenStack = Stack_new(); self->tokenStream = List_new(); self->charLineIndex = List_new(); return self; }
IoODEWorld *IoODEWorld_rawClone(IoODEWorld *proto) { IoObject *self = IoObject_rawClonePrimitive(proto); IoObject_setDataPointer_(self, calloc(1, sizeof(IoODEWorldData))); WORLDID = dWorldCreate(); DATA(self)->bodies = List_new(); DATA(self)->jointGroups = List_new(); IoObject_inlineSetSlot_to_(self, IOSYMBOL("Body"), IoODEBody_newBodyProtoWithWorld(IOSTATE, self)); IoObject_inlineSetSlot_to_(self, IOSYMBOL("JointGroup"), IoODEJointGroup_newJointGroupProtoWithWorld(IOSTATE, self)); return self; }
T Command_new(const char *path, const char *arg0, ...) { T C; if (! File_exist(path)) THROW(AssertException, "File '%s' does not exist", path ? path : "null"); NEW(C); C->env = List_new(); C->args = List_new(); List_append(C->env, Str_dup(Command_Path)); va_list ap; va_start(ap, arg0); buildArgs(C, path, arg0, ap); va_end(ap); return C; }
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; }
RCG_node * RCG_node_new(void) { RCG_node *node; node = (RCG_node *) tman_malloc(sizeof(RCG_node)); memset(node, '\0', sizeof(RCG_node)); node->selection_predicates_list = List_new(); node->join_predicates_list = List_new(); node->already_inserted = 0; node->decorated_selection_predicate = NULL; node->type = RCG_NODE_TYPE; return node; }
//Update the clipping rectangles to only include those areas within both the //existing clipping region AND the passed Rect void Context_intersect_clip_rect(Context* context, Rect* rect) { int i; List* output_rects; Rect* current_rect; Rect* intersect_rect; context->clipping_on = 1; if(!(output_rects = List_new())) return; for(i = 0; i < context->clip_rects->count; i++) { current_rect = (Rect*)List_get_at(context->clip_rects, i); intersect_rect = Rect_intersect(current_rect, rect); if(intersect_rect) List_add(output_rects, (Object*)intersect_rect); } //Delete the original rectangle list Object_delete((Object*)context->clip_rects); //And re-point it to the new one we built above context->clip_rects = output_rects; //Free the input rect Object_delete((Object*)rect); }
static void adminInterfaces(Dict* args, void* vcontext, String* txid, struct Allocator* alloc) { struct Context* context = Identity_check((struct Context*)vcontext); int64_t* page = Dict_getIntC(args, "page"); int i = (page) ? *page * ENTRIES_PER_PAGE : 0; int count = InterfaceController_ifaceCount(context->ic); //int count = InterfaceController_getIface(context->ic, alloc, &stats); List* list = List_new(alloc); for (int counter = 0; i < count && counter++ < ENTRIES_PER_PAGE; i++) { struct InterfaceController_Iface* iface = InterfaceController_getIface(context->ic, i); Dict* d = Dict_new(alloc); Dict_putIntC(d, "ifNum", iface->ifNum, alloc); Dict_putStringC(d, "name", iface->name, alloc); char* bs = InterfaceController_beaconStateString(iface->beaconState); Dict_putStringCC(d, "beaconState", bs, alloc); List_addDict(list, d, alloc); } Dict* resp = Dict_new(alloc); Dict_putListC(resp, "ifaces", list, alloc); Dict_putIntC(resp, "total", count, alloc); if (i < count) { Dict_putIntC(resp, "more", 1, alloc); } Admin_sendMessage(resp, txid, context->admin); }
static void searchResponse(struct RouterModule_Promise* promise, uint32_t lag, struct Address* from, Dict* responseDict) { struct Search* search = Identity_check((struct Search*) promise->userData); struct Allocator* alloc = Allocator_child(search->alloc); Dict* resp = Dict_new(alloc); if (!from) { Dict_putStringCC(resp, "error", "none", alloc); Dict_putIntC(resp, "complete", 1, alloc); Admin_sendMessage(resp, search->txid, search->ctx->admin); Allocator_free(alloc); return; } String* fromStr = Address_toString(from, alloc); Dict_putStringC(resp, "from", fromStr, alloc); Dict_putIntC(resp, "ms", lag, alloc); struct Address_List* addrs = ReplySerializer_parse(from, responseDict, NULL, true, alloc); List* nodes = List_new(alloc); for (int i = 0; addrs && i < addrs->length; i++) { String* addr = Address_toString(&addrs->elems[i], alloc); List_addString(nodes, addr, alloc); } Dict_putListC(resp, "nodes", nodes, alloc); Admin_sendMessage(resp, search->txid, search->ctx->admin); }
Levels *Levels_new(IoMessage *msg) { Levels *self = io_calloc(1, sizeof(Levels)); IoState *state = IoObject_state(msg); IoSymbol *operatorTableSymbol = IoState_symbolWithCString_(state, "OperatorTable"); // Be ultra flexable, and try to use the first message's operator table. IoObject *opTable = IoObject_rawGetSlot_(msg, operatorTableSymbol); // Otherwise, use Core OperatorTable, and if that doesn't exist, create it. if (opTable == NULL) { // There is a chance the message didn't have it, but the core did---due // to the Core not being part of the message's protos. Use Core // Message's OperatorTable opTable = IoObject_rawGetSlot_(state->core, operatorTableSymbol); // If Core doesn't have an OperatorTable, then create it. if (opTable == NULL) { opTable = IoObject_new(state); IoObject_setSlot_to_(state->core, operatorTableSymbol, opTable); IoObject_setSlot_to_(opTable, IoState_symbolWithCString_(state, "precedenceLevelCount"), IoState_numberWithDouble_(state, IO_OP_MAX_LEVEL)); } } self->operatorTable = getOpTable(opTable, "operators", IoState_createOperatorTable); self->assignOperatorTable = getOpTable(opTable, "assignOperators", IoState_createAssignOperatorTable); self->stack = List_new(); Levels_reset(self); return self; }
Section* Section_new(double x, double y, double z, double width, double height, double length, int enemies) { Section* inst = (Section*) malloc(sizeof(Section)); int i; Vector spawn; double spacing; inst->pos[0] = x, inst->pos[1] = y, inst->pos[2] = z; inst->size[0] = width, inst->size[1] = height, inst->size[2] = length; inst->entities = List_new(); for(i = 0, spacing = 0; i < enemies; ++i) { spawn[0] = randomInterval(x, x + width - Enemy_DEF_SIZE[0]); spawn[1] = randomInterval(y, y + height - Enemy_DEF_SIZE[1]); spawn[2] = randomInterval(z + spacing, z + length); List_pushBack(inst->entities, Enemy_new( spawn[0], spawn[1], spawn[2], random(), random() * 5 + 1, 800)); spacing += Enemy_DEF_SIZE[2] + length/enemies; } return inst; }
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; }
//Constructor for our context Context* Context_new(uint16_t width, uint16_t height, uint32_t* buffer) { static unsigned int handle_source = 0; //Attempt to allocate Context* context; if(!(context = (Context*)malloc(sizeof(Context)))) return context; //Init base object Object_init((Object*)context, Context_delete_function); //Attempt to allocate new rect list if(!(context->clip_rects = List_new())) { free(context); return (Context*)0; } //Finish assignments context->id = ++handle_source; context->translate_x = 0; context->translate_y = 0; context->width = width; context->height = height; context->buffer = buffer; context->clipping_on = 0; context->finalize_handler = (ContextFinalizeHandler)0; return context; }
static void getHandles(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc) { struct Context* context = Identity_check((struct Context*) vcontext); struct Allocator* alloc = Allocator_child(context->alloc); int64_t* page = Dict_getInt(args, String_CONST("page")); int i = (page) ? *page * ENTRIES_PER_PAGE : 0; struct SessionManager_HandleList* hList = SessionManager_getHandleList(context->sm, alloc); List* list = List_new(alloc); for (int counter = 0; i < hList->length && counter++ < ENTRIES_PER_PAGE; i++) { List_addInt(list, hList->handles[i], alloc); } Dict* r = Dict_new(alloc); Dict_putList(r, String_CONST("handles"), list, alloc); Dict_putInt(r, String_CONST("total"), hList->length, alloc); String* more = String_CONST("more"); if (i < hList->length) { Dict_putInt(r, more, 1, alloc); } Admin_sendMessage(r, txid, context->admin); Allocator_free(alloc); }
void Trace_addFunc(char *s) { if (!traceList) traceList = List_new(); List_addFirst(traceList, s); }
static void dumpRumorMill(Dict* args, void* vcontext, String* txid, struct Allocator* requestAlloc) { struct Context* ctx = Identity_check((struct Context*) vcontext); Dict* out = Dict_new(requestAlloc); struct RumorMill* rm = getRumorMill(ctx, Dict_getString(args, String_CONST("mill"))); if (!rm) { Dict_putString(out, String_CONST("error"), String_CONST("mill must be one of " "[externalMill,linkMill,nodeMill,dhtMill,splitMill]"), requestAlloc); Admin_sendMessage(out, txid, ctx->admin); return; } int64_t* page = Dict_getInt(args, String_CONST("page")); int ctr = (page) ? *page * ENTRIES_PER_PAGE : 0; List* table = List_new(requestAlloc); for (int i = 0; i < ENTRIES_PER_PAGE && ctr < rm->count; i++) { String* addr = Address_toString(&rm->addresses[ctr++], requestAlloc); List_addString(table, addr, requestAlloc); } Dict_putList(out, String_CONST("addresses"), table, requestAlloc); Dict_putInt(out, String_CONST("total"), rm->count, requestAlloc); Admin_sendMessage(out, txid, ctx->admin); }
static void genericResponse(struct RouterModule_Promise* promise, uint32_t lag, struct Address* from, Dict* responseDict, String* name) { struct Ping* ping = Identity_check((struct Ping*)promise->userData); Dict* out = Dict_new(promise->alloc); String* result = (responseDict) ? name : String_CONST("timeout"); Dict_putString(out, String_CONST("result"), result, promise->alloc); if (responseDict) { struct Address_List* addrs = ReplySerializer_parse(from, responseDict, NULL, promise->alloc); List* nodes = List_new(promise->alloc); for (int i = 0; i < addrs->length; i++) { String* addr = Address_toString(&addrs->elems[i], promise->alloc); List_addString(nodes, addr, promise->alloc); } Dict_putList(out, name, nodes, promise->alloc); } Dict_putInt(out, String_CONST("ms"), lag, promise->alloc); Dict_putString(out, String_CONST("error"), String_CONST("none"), promise->alloc); Admin_sendMessage(out, ping->txid, ping->ctx->admin); }
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); }
// phrase_word_list -> word+ static syntree *phrase_word_list (token ** lookahead, err_context context) { syntree *left = NULL; List *word_list = NULL; RETURN_NULL_IF_OVER_DEPTH_LIMIT(context); // It has already been tested that the lookahead is a word node. left = (syntree *) ft_word_new ((*lookahead)->lexeme->contents); advance (lookahead); // If more than one word is present, form the list of all the words and // make a phrase. if (ft_test (lookahead, TOK_FT_WORD)) { int num_words = 0; word_list = List_new (); // Add the word already parsed. List_insertElement (word_list, left); num_words++; // Add subsequent words. do { left = (syntree *) ft_word_new ((*lookahead)->lexeme->contents); List_insertElement (word_list, left); num_words++; advance (lookahead); } while (ft_test(lookahead, TOK_FT_WORD)); return ((syntree *)ft_phrase_new (word_list, num_words)); } // Otherwise return a word node. return (left); }
process_tracker_t * pt_new (int kq) { process_tracker_t * pt = s16mem_alloc (sizeof (process_tracker_t)); pt->kq = kq; pt->pids = List_new (); return pt; }
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; }
List_errno_t List_append(ListPtr l, const ListElPtr el) { ListPtr it = l; if (l == NULL) { return LIST_NULL; } if (l->node == NULL) { l->node = ListEl_new(); ListEl_copy(l->node, el); } while(it->next != NIL) { it = it->next; } it->next = List_new(); if (it->next == NIL) { return LIST_MEMALLOC_ERR; } it = it->next; it->node = ListEl_new(); if (it->node == NULL) { return LIST_MEMALLOC_ERR; } return ListEl_copy(it->node, el); }
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; }
Collector *Collector_new(void) { Collector *self = (Collector *)io_calloc(1, sizeof(Collector)); self->retainedValues = List_new(); self->whites = CollectorMarker_new(); self->grays = CollectorMarker_new(); self->blacks = CollectorMarker_new(); self->freed = CollectorMarker_new(); CollectorMarker_loop(self->whites); CollectorMarker_removeIfNeededAndInsertAfter_(self->grays, self->whites); CollectorMarker_removeIfNeededAndInsertAfter_(self->blacks, self->grays); CollectorMarker_removeIfNeededAndInsertAfter_(self->freed, self->blacks); // important to set colors *after* inserts, since inserts set colors CollectorMarker_setColor_(self->whites, COLLECTOR_INITIAL_WHITE); CollectorMarker_setColor_(self->blacks, COLLECTOR_INITIAL_BLACK); CollectorMarker_setColor_(self->grays, COLLECTOR_GRAY); CollectorMarker_setColor_(self->freed, COLLECTOR_FREE); Collector_setSafeModeOn_(self, 1); self->allocated = 0; self->allocatedSweepLevel = 3000; self->allocatedStep = 1.1f; self->marksPerAlloc = 2; self->clocksUsed = 0; Collector_check(self); return self; }
UDBIndex *UDBIndex_new(void) { UDBIndex *self = (UDBIndex *)calloc(1, sizeof(UDBIndex)); self->file = JFile_new(); UDBIndex_setPath_(self, "default"); self->holes = List_new(); return self; }
List List_copy(List list){ List listCopy = List_new(); void* ptr; int i; List_foreach(list, ptr, i){ List_insert(listCopy,ptr); }
List * Person_newlist() { List *l = List_new( (int (*)(void *, void *))Person_cmp, (void (*)(void *))Person_print, (bool (*)(void *, void *))Person_query ); return l; }