uint8_t _mk_nlbl_map(char **inputs, uint16_t ninputs, nlbl_map_t *map) { uint32_t i; graph_t g; if (array_create(&(map->labels), sizeof(graph_label_t), 1000)) goto fail; if (array_create(&(map->nodeids), sizeof(array_t), 1000)) goto fail; if (array_create(&(map->sizes), sizeof(uint32_t), ninputs)) goto fail; if (array_create(&(map->idmap), sizeof(array_t), ninputs)) goto fail; array_set_cmps(&(map->labels), _compare_glbl, _compare_glbl_ins); for (i = 0; i < ninputs; i++) { if (ngdb_read(inputs[i], &g)) goto fail; if (_update_nlbl_map(&g, ninputs, i, map)) goto fail; graph_free(&g); } for (i = 0; i < ninputs; i++) { if (_mk_id_map(map, i)) goto fail; } return 0; fail: return 1; }
static rebuilder* rebuilder_create() { rebuilder* re = (rebuilder*) malloc( sizeof(rebuilder) ); re->error = 0; re->root = array_create(); re->subroot = array_create(); return re; }
void* matrix_create(size_t width, size_t height, size_t size, const void* zero) { void* matrix; int i; matrix = array_create(width, sizeof(void*), NULL); if (matrix == NULL) goto exception_matrix_bad_alloc; for (i = 0; i < width; i++) { ((void**)matrix)[i] = array_create(height, size, zero); if (((void**)matrix)[i] == NULL) goto exception_matrix_i_bad_alloc; } return matrix; exception_matrix_i_bad_alloc: for (i--; i >= 0; i--) array_destroy(((void**)matrix)[i], height, size, NULL); array_destroy(matrix, width, sizeof(void*), NULL); exception_matrix_bad_alloc: return NULL; }
/* * Thread initialization. */ struct thread * thread_bootstrap(void) { struct thread *me; /* Create the data structures we need. */ sleepers = array_create(); if (sleepers==NULL) { panic("Cannot create sleepers array\n"); } zombies = array_create(); if (zombies==NULL) { panic("Cannot create zombies array\n"); } //as_array = array_create(); //if(as_array == NULL) //{ // panic("Cannot create addrspace array\n"); //} /*as_lock = lock_create("copy_lock"); if(as_lock == NULL) { panic("Cannot create addrspace array lock\n"); }*/ /* * Create the thread structure for the first thread * (the one that's already running) */ me = thread_create("<boot/menu>"); if (me==NULL) { panic("thread_bootstrap: Out of memory\n"); } /* * Leave me->t_stack NULL. This means we're using the boot stack, * which can't be freed. */ /* Initialize the first thread's pcb */ md_initpcb0(&me->t_pcb); /* Set curthread */ curthread = me; /* Number of threads starts at 1 */ numthreads = 1; forking = 0; /* Done */ return me; }
/* * Thread initialization. */ struct thread * thread_bootstrap(void) { struct thread *me; /* Create the data structures we need. */ sleepers = array_create(); if (sleepers==NULL) { panic("Cannot create sleepers array\n"); } zombies = array_create(); if (zombies==NULL) { panic("Cannot create zombies array\n"); } /* * Create the thread structure for the first thread * (the one that's already running) */ #if OPT_A2 int i; for (i = 1; i < MAX_FORKED_PROCESSES; i++) { // pid cannot be 0 process_table[i].active = 0; process_table[i].pid = 0; process_table[i].parentWaiting = 0; process_table[i].children = NULL; process_table[i].processSem = sem_create("process_sem", 0); // FIXME may init more fields here. } #endif me = thread_create("<boot/menu>"); if (me==NULL) { panic("thread_bootstrap: Out of memory\n"); } /* * Leave me->t_stack NULL. This means we're using the boot stack, * which can't be freed. */ /* Initialize the first thread's pcb */ md_initpcb0(&me->t_pcb); /* Set curthread */ curthread = me; /* Number of threads starts at 1 */ numthreads = 1; /* Done */ return me; }
/* * Thread initialization. */ struct thread * thread_bootstrap(void) { struct thread *me; /* Create the data structures we need. */ sleepers = array_create(); if (sleepers==NULL) { panic("Cannot create sleepers array\n"); } zombies = array_create(); if (zombies==NULL) { panic("Cannot create zombies array\n"); } /* * Create the thread structure for the first thread * (the one that's already running) */ me = thread_create("<boot/menu>"); if (me==NULL) { panic("thread_bootstrap: Out of memory\n"); } /* * Leave me->t_stack NULL. This means we're using the boot stack, * which can't be freed. */ /* Initialize the first thread's pcb */ md_initpcb0(&me->t_pcb); /* Set curthread */ curthread = me; /* Number of threads starts at 1 */ numthreads = 1; #if OPT_A2 /* init process table */ int i; for (i = 0 ; i < MAX_PROG+1 ; ++i) p_table[i] = NULL; #endif /* Done */ return me; }
struct addrspace * as_create(void) { struct addrspace *as; as = kmalloc(sizeof(struct addrspace)); if (as == NULL) { return NULL; } /* * Initialize as needed. */ as->pt_locks = kmalloc(PT_LEVEL_SIZE * sizeof(struct lock*)); for (int i = 0; i < PT_LEVEL_SIZE; i++) as->pt_locks[i] = NULL; as->pagetable = pagetable_create(); KASSERT(as->pt_locks); KASSERT(as->pagetable); as->as_regions = array_create(); as->heap_start = 0; as->heap_end = 0; return as; }
uint8_t graph_threshold_components( graph_t *gin, graph_t *gout, uint32_t cmplimit, uint32_t igndis, void *opt, uint8_t (*init)(graph_t *g), uint8_t (*remove)( graph_t *g, double *space, array_t *edges, graph_edge_t *edge), uint8_t (*recalc)( graph_t *g, graph_edge_t *edge) ) { uint32_t nnodes; uint64_t ncmps; double *space; array_t edges; graph_edge_t edge; edges.data = NULL; space = NULL; nnodes = graph_num_nodes(gin); if (cmplimit > nnodes) goto fail; if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail; if (graph_copy(gin, gout)) goto fail; if (stats_cache_init(gout)) goto fail; space = calloc(nnodes,sizeof(double)); if (space == NULL) goto fail; init(gout); ncmps = stats_num_components(gout, igndis, NULL, NULL); while (ncmps < cmplimit) { array_clear(&edges); if (remove(gout, space, &edges, &edge)) goto fail; ncmps = stats_num_components(gout, igndis, NULL, NULL); if (ncmps >= cmplimit) break; if (recalc(gout, &edge)) goto fail; } free(space); array_free(&edges); return 0; fail: if (space != NULL) free(space); if (edges.data != NULL) array_free(&edges); return 1; }
struct mail * virtual_mail_alloc(struct mailbox_transaction_context *t, enum mail_fetch_field wanted_fields, struct mailbox_header_lookup_ctx *wanted_headers) { struct virtual_mailbox *mbox = (struct virtual_mailbox *)t->box; struct virtual_mail *vmail; pool_t pool; pool = pool_alloconly_create("vmail", 1024); vmail = p_new(pool, struct virtual_mail, 1); vmail->imail.mail.pool = pool; vmail->imail.mail.v = virtual_mail_vfuncs; vmail->imail.mail.mail.box = t->box; vmail->imail.mail.mail.transaction = t; array_create(&vmail->imail.mail.module_contexts, pool, sizeof(void *), 5); vmail->imail.data_pool = pool_alloconly_create("virtual index_mail", 512); vmail->imail.ibox = INDEX_STORAGE_CONTEXT(t->box); vmail->imail.trans = (struct index_transaction_context *)t; vmail->wanted_fields = wanted_fields; if (wanted_headers != NULL) { vmail->wanted_headers = wanted_headers; mailbox_header_lookup_ref(wanted_headers); } i_array_init(&vmail->backend_mails, array_count(&mbox->backend_boxes)); return &vmail->imail.mail.mail; }
int main(void) { object *obj = object_create(64); assert(obj != NULL); /* Testing adding all of the types */ assert(object_add(obj, "integer", 12345) == JSON11_ERR_OK); assert(object_add(obj, "double", -1.2345e4) == JSON11_ERR_OK); assert(object_add(obj, "string", "abcdef") == JSON11_ERR_OK); assert(object_add(obj, "true", (bool)true) == JSON11_ERR_OK); assert(object_add(obj, "false", (bool)false) == JSON11_ERR_OK); assert(object_add(obj, "null", NULL) == JSON11_ERR_OK); object *inner_object = object_create(32); array *inner_array = array_create(32); assert(inner_object != NULL); assert(inner_array != NULL); assert(object_add(obj, "object", inner_object) == JSON11_ERR_OK); assert(object_add(obj, "array", inner_array) == JSON11_ERR_OK); // object_destroy(&obj); // assert(obj == NULL); }
/** * @brief Adds a new background image. */ unsigned int background_addImage( glTexture *image, double x, double y, double move, double scale, glColour *col, int foreground ) { background_image_t *bkg, **arr; if (foreground) arr = &bkg_image_arr_ft; else arr = &bkg_image_arr_bk; /* See if must create. */ if (*arr == NULL) *arr = array_create( background_image_t ); /* Create image. */ bkg = &array_grow( arr ); bkg->id = ++bkg_idgen; bkg->image = gl_dupTexture(image); bkg->x = x; bkg->y = y; bkg->move = move; bkg->scale = scale; memcpy( &bkg->col, (col!=NULL) ? col : &cWhite, sizeof(glColour) ); /* Sort if necessary. */ bkg_sort( *arr ); return bkg_idgen; }
struct mailbox_list_iterate_context * mailbox_list_subscriptions_iter_init(struct mailbox_list *list, const char *const *patterns, enum mailbox_list_iter_flags flags) { struct subscriptions_mailbox_list_iterate_context *ctx; pool_t pool; char sep = mail_namespace_get_sep(list->ns); pool = pool_alloconly_create("mailbox list subscriptions iter", 1024); ctx = p_new(pool, struct subscriptions_mailbox_list_iterate_context, 1); ctx->ctx.pool = pool; ctx->ctx.list = list; ctx->ctx.flags = flags; ctx->ctx.glob = imap_match_init_multiple(pool, patterns, TRUE, sep); array_create(&ctx->ctx.module_contexts, pool, sizeof(void *), 5); ctx->tree = mailbox_tree_init(sep); mailbox_list_subscriptions_fill(&ctx->ctx, ctx->tree, FALSE); ctx->info.ns = list->ns; /* the tree usually has only those entries we want to iterate through, but there are also non-matching root entries (e.g. "LSUB foo/%" will include the "foo"), which we'll drop with MAILBOX_MATCHED. */ ctx->iter = mailbox_tree_iterate_init(ctx->tree, NULL, MAILBOX_MATCHED); return &ctx->ctx; }
void index_mail_init(struct index_mail *mail, struct mailbox_transaction_context *_t, enum mail_fetch_field wanted_fields, struct mailbox_header_lookup_ctx *_wanted_headers) { struct index_transaction_context *t = (struct index_transaction_context *)_t; struct index_header_lookup_ctx *wanted_headers = (struct index_header_lookup_ctx *)_wanted_headers; const struct mail_index_header *hdr; array_create(&mail->mail.module_contexts, mail->mail.pool, sizeof(void *), 5); mail->mail.v = *_t->box->mail_vfuncs; mail->mail.mail.box = _t->box; mail->mail.mail.transaction = &t->mailbox_ctx; mail->mail.wanted_fields = wanted_fields; mail->mail.wanted_headers = _wanted_headers; hdr = mail_index_get_header(_t->box->view); mail->uid_validity = hdr->uid_validity; t->mail_ref_count++; mail->data_pool = pool_alloconly_create("index_mail", 16384); mail->ibox = INDEX_STORAGE_CONTEXT(_t->box); mail->trans = t; mail->wanted_fields = wanted_fields; if (wanted_headers != NULL) { mail->wanted_headers = wanted_headers; mailbox_header_lookup_ref(_wanted_headers); } }
int main(void) { int small_map = array_create(8, 1); struct bpf_insn insns[] = { // load NULL pointer, tracked as "NULL or value pointer", into r0 BPF_LD_MAP_FD(BPF_REG_ARG1, small_map), BPF_MOV64_REG(BPF_REG_ARG2, BPF_REG_FP), BPF_ALU64_IMM(BPF_ADD, BPF_REG_ARG2, -4), BPF_ST_MEM(BPF_W, BPF_REG_ARG2, 0, 9), //oob index BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), // compute r9 = laundered_frame_pointer BPF_MOV64_REG(BPF_REG_9, BPF_REG_FP), BPF_ALU64_REG(BPF_SUB, BPF_REG_9, BPF_REG_0), // store r9 into map BPF_LD_MAP_FD(BPF_REG_ARG1, small_map), BPF_MOV64_REG(BPF_REG_ARG2, BPF_REG_FP), BPF_ALU64_IMM(BPF_ADD, BPF_REG_ARG2, -4), BPF_ST_MEM(BPF_W, BPF_REG_ARG2, 0, 0), BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem), BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 1), BPF_EXIT_INSN(), BPF_STX_MEM(BPF_DW, BPF_REG_0, BPF_REG_9, 0), BPF_MOV64_IMM(BPF_REG_0, 0), BPF_EXIT_INSN() }; int sock_fd = create_filtered_socket_fd(insns, ARRSIZE(insns)); trigger_proc(sock_fd); printf("leaked pointer: 0x%lx\n", array_get_dw(small_map, 0)); }
void index_transaction_init(struct mailbox_transaction_context *t, struct mailbox *box, enum mailbox_transaction_flags flags) { enum mail_index_transaction_flags itrans_flags; i_assert(box->opened); itrans_flags = index_transaction_flags_get(flags); if ((flags & MAILBOX_TRANSACTION_FLAG_REFRESH) != 0) mail_index_refresh(box->index); t->box = box; t->itrans = mail_index_transaction_begin(box->view, itrans_flags); t->view = mail_index_transaction_open_updated_view(t->itrans); array_create(&t->module_contexts, default_pool, sizeof(void *), 5); t->cache_view = mail_cache_view_open(box->cache, t->view); t->cache_trans = mail_cache_get_transaction(t->cache_view, t->itrans); if ((flags & MAILBOX_TRANSACTION_FLAG_NO_CACHE_DEC) != 0) mail_cache_view_update_cache_decisions(t->cache_view, FALSE); /* set up after mail_cache_get_transaction(), so that we'll still have the cache_trans available in _index_commit() */ t->super = t->itrans->v; t->itrans->v.commit = index_transaction_index_commit; t->itrans->v.rollback = index_transaction_index_rollback; MODULE_CONTEXT_SET(t->itrans, mail_storage_mail_index_module, t); }
/** * @brief Adds a system marker to a mission. */ int mission_addMarker( Mission *misn, int id, int sys, SysMarker type ) { MissionMarker *marker; int i, n, m; /* Create array. */ if (misn->markers == NULL) misn->markers = array_create( MissionMarker ); /* Avoid ID collisions. */ if (id < 0) { m = -1; n = array_size( misn->markers ); for (i=0; i<n; i++) if (misn->markers[i].id > m) m = misn->markers[i].id; id = m+1; } /* Create the marker. */ marker = &array_grow( &misn->markers ); marker->id = id; marker->sys = sys; marker->type = type; return marker->id; }
void index_transaction_init(struct index_transaction_context *it, struct mailbox *box, enum mailbox_transaction_flags flags) { struct mailbox_transaction_context *t = &it->mailbox_ctx; enum mail_index_transaction_flags trans_flags; i_assert(box->opened); trans_flags = MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES; if ((flags & MAILBOX_TRANSACTION_FLAG_HIDE) != 0) trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_HIDE; if ((flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0) trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL; if ((flags & MAILBOX_TRANSACTION_FLAG_REFRESH) != 0) (void)mail_index_refresh(box->index); t->box = box; t->itrans = mail_index_transaction_begin(box->view, trans_flags); t->view = mail_index_transaction_open_updated_view(t->itrans); array_create(&t->module_contexts, default_pool, sizeof(void *), 5); it->cache_view = mail_cache_view_open(box->cache, t->view); it->cache_trans = mail_cache_get_transaction(it->cache_view, t->itrans); /* set up after mail_cache_get_transaction(), so that we'll still have the cache_trans available in _index_commit() */ it->super = t->itrans->v; t->itrans->v.commit = index_transaction_index_commit; t->itrans->v.rollback = index_transaction_index_rollback; MODULE_CONTEXT_SET(t->itrans, mail_storage_mail_index_module, it); }
static bool read_input() { char* line = read_line(stdin); userlog(LOG_DEBUG, "input: %s", (line ? line : "<null>")); if (line == NULL || strcmp(line, "EXIT") == 0) { userlog(LOG_INFO, "exiting: %s", line); return false; } if (strcmp(line, "ROOTS") == 0) { array* new_roots = array_create(20); CHECK_NULL(new_roots, false); while (1) { line = read_line(stdin); userlog(LOG_DEBUG, "input: %s", (line ? line : "<null>")); if (line == NULL || strlen(line) == 0) { return false; } else if (strcmp(line, "#") == 0) { break; } else { int l = strlen(line); if (l > 1 && line[l-1] == '/') line[l-1] = '\0'; CHECK_NULL(array_push(new_roots, strdup(line)), false); } } return update_roots(new_roots); } userlog(LOG_INFO, "unrecognised command: %s", line); return true; }
int lang_init() { // Get filename const char *filename = pm_get_resource_path(DAT_ENGLISH); // Load up language file language = malloc(sizeof(sd_language)); if(sd_language_create(language) != SD_SUCCESS) { goto error_0; } if(sd_language_load(language, filename)) { PERROR("Unable to load language file '%s'!", filename); goto error_1; } // Load language strings array_create(&language_strings); for(int i = 0; i < language->count; i++) { array_set(&language_strings, i, language->strings[i].data); } INFO("Loaded language file '%s'.", filename); return 0; error_1: sd_language_free(language); error_0: free(language); return 1; }
uint8_t _mk_id_map(nlbl_map_t *map, uint16_t inidx) { uint64_t i; uint32_t navgnodes; uint32_t ninnodes; uint32_t avgnodeid; int64_t innodeid; array_t *idmap; array_t *nodeids; idmap = array_getd(&(map->idmap), inidx); ninnodes = *(uint32_t *)array_getd(&(map->sizes), inidx); navgnodes = map->labels.size; if (array_create(idmap, sizeof(uint32_t), ninnodes)) goto fail; for (i = 0; i < navgnodes; i++) { nodeids = array_getd(&(map->nodeids), i); innodeid = *(int64_t *)array_getd(nodeids, inidx); if (innodeid == -1) continue; avgnodeid = i; array_set(idmap, innodeid, &avgnodeid); } return 0; fail: return 1; }
int main(){ Array a = array_create(100); printf("array size=%d\n",array_size(&a)); *array_at(&a,0)=10; printf("%d",*array_at(&a,0)); array_free(&a); }
/* in as_create, we just allocate a addrspace structure using kmalloc, and allocate a physical page (using page_alloc) as page directory and store it's address (either KVADDR or PADDR is OK, but you can just choose one). */ struct addrspace * as_create(void) { struct addrspace *as = kmalloc(sizeof(struct addrspace)); if (as == NULL) { return NULL; } // allocate the array of regions as->as_regions = array_create(); if (as->as_regions == NULL) { return NULL; } // we'll have to wait until the user bss segment is // defined before we know the start of heap as->heap_start = 0; as->heap_end = 0; // initiailize first level page table int i = 0; for (; i < FIRST_LEVEL_PT_SIZE; i++){ as->as_master_pagetable[i] = NULL; } return as; }
struct mailbox_list_iterate_context * mailbox_list_index_iter_init(struct mailbox_list *list, const char *const *patterns, enum mailbox_list_iter_flags flags) { struct mailbox_list_index *ilist = INDEX_LIST_CONTEXT(list); struct mailbox_list_index_iterate_context *ctx; pool_t pool; char ns_sep = mail_namespace_get_sep(list->ns); pool = pool_alloconly_create("mailbox list index iter", 2048); ctx = p_new(pool, struct mailbox_list_index_iterate_context, 1); ctx->ctx.pool = pool; ctx->ctx.list = list; ctx->ctx.flags = flags; ctx->ctx.glob = imap_match_init_multiple(pool, patterns, TRUE, ns_sep); array_create(&ctx->ctx.module_contexts, pool, sizeof(void *), 5); ctx->info_pool = pool_alloconly_create("mailbox list index iter info", 128); if (!iter_use_index(ctx)) { /* no indexing */ ctx->backend_ctx = ilist->module_ctx.super. iter_init(list, patterns, flags); } else { /* listing mailboxes from index */ ctx->info.ns = list->ns; ctx->path = str_new(pool, 128); ctx->next_node = ilist->mailbox_tree; ctx->mailbox_pool = ilist->mailbox_pool; pool_ref(ctx->mailbox_pool); } return &ctx->ctx; }
void index_storage_mailbox_alloc(struct mailbox *box, const char *vname, enum mailbox_flags flags, const char *index_prefix) { static unsigned int mailbox_generation_sequence = 0; struct index_mailbox_context *ibox; i_assert(vname != NULL); box->generation_sequence = ++mailbox_generation_sequence; box->vname = p_strdup(box->pool, vname); box->name = p_strdup(box->pool, mailbox_list_get_storage_name(box->list, vname)); box->flags = flags; box->index_prefix = p_strdup(box->pool, index_prefix); p_array_init(&box->search_results, box->pool, 16); array_create(&box->module_contexts, box->pool, sizeof(void *), 5); ibox = p_new(box->pool, struct index_mailbox_context, 1); ibox->list_index_sync_ext_id = (uint32_t)-1; ibox->index_flags = MAIL_INDEX_OPEN_FLAG_CREATE | mail_storage_settings_to_index_flags(box->storage->set); if ((box->flags & MAILBOX_FLAG_SAVEONLY) != 0) ibox->index_flags |= MAIL_INDEX_OPEN_FLAG_SAVEONLY; ibox->next_lock_notify = time(NULL) + LOCK_NOTIFY_INTERVAL; MODULE_CONTEXT_SET(box, index_storage_module, ibox); box->inbox_user = strcmp(box->name, "INBOX") == 0 && (box->list->ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0; box->inbox_any = strcmp(box->name, "INBOX") == 0 && (box->list->ns->flags & NAMESPACE_FLAG_INBOX_ANY) != 0; }
int main(int argc, char *argv[]) { const char *sockname = DEFAULT_SOCKET; int ch; while ((ch = getopt(argc, argv, ""))!=-1) { switch (ch) { default: usage(); } } if (optind < argc) { sockname = argv[optind++]; } if (optind < argc) { usage(); } senders = array_create(); if (!senders) { fprintf(stderr, "hub161: Out of memory\n"); exit(1); } opensock(sockname); printf("hub161: Listening on %s\n", sockname); loop(); closesock(); return 0; }
uint8_t _bfs_cb(bfs_state_t *state, void *context) { uint64_t i; uint32_t ni; cstack_t *st; array_t level; st = (cstack_t *)context; if (array_create(&level, sizeof(uint32_t), state->thislevel.size)) goto fail; for (i = 0; i < state->thislevel.size; i++) { array_get(&(state->thislevel), i, &ni); array_set(&level, i, &ni); } stack_push(st, &level); return 0; fail: return 1; }
int32_t obj_parser_init(obj_parser_t *p, const char *filename) { SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Parsing: %s\n", filename); FILE *f = fopen(filename, "rb"); // If file doesn't exist if(f == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to open file: %s\n", filename); return 1; } // Determine the size of the file fseek(f, 0, SEEK_END); size_t fsize = (size_t)ftell(f); fseek(f, 0, SEEK_SET); SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Size of \'%s\' file: %lu bytes\n", filename, fsize); // Read the whole file into memory char *fstring = (char*)malloc(fsize+1); fread(fstring, fsize, 1, f); fclose(f); // Null terminate the string fstring[fsize] = 0; // Initialize the parser object *p = (obj_parser_t){fstring, fsize, 0, {array_create(2, sizeof(char)), OBJ_UNKNOWN}}; return 0; }
void test_array() { START_CODE(node) IF IN RAW_PARAM(3) ARRAY_CONSTANT(array_create(3, 1,2,3)); END; THEN CATEGORY_CONSTANT(1) ELSE CATEGORY_CONSTANT(2) END; END_CODE; node_print(node); node = test_serialization(node); environment_t env = test_environment(); constant_t v = node_eval(node, &env); assert(v.c == 2); assert(v.type == CONSTANT_CATEGORY); env.row->inputs[3].category = 3; v = node_eval(node, &env); assert(v.c == 1); assert(v.type == CONSTANT_CATEGORY); row_destroy(env.row); node_destroy(node); }
int mesh_init(void) { uint16_t mesh_listen_port = \ (uint16_t)config_get_option_value("listen.mesh_port")->integer; if (mesh_listen_port == 0) { log_info("Mesh support is disabled"); return 0; } log_info("Initializing mesh subsystem"); if (mesh_start_listening(&mesh_listen_socket, mesh_listen_port, socket_create_allocated) >= 0) { is_mesh_listen_socket_open = true; } if (!is_mesh_listen_socket_open) { log_error("Could not open mesh listen socket"); return -1; } // Create mesh stack array. if (array_create(&mesh_stacks, MAX_MESH_STACKS, sizeof(MeshStack), false) < 0) { log_error("Could not create mesh stack array: %s (%d)", get_errno_name(errno), errno); return -1; } return 0; }
/* * Public functions */ search_info_t *search_parse (const char *search) /* {{{ */ { const char *ptr; char *token; search_info_t *si; if (search == NULL) return (NULL); si = malloc (sizeof (*si)); if (si == NULL) return (NULL); memset (si, 0, sizeof (*si)); si->terms = array_create (); if (si->terms == NULL) { free (si); return (NULL); } ptr = search; while ((token = next_token (&ptr)) != NULL) { store_token (si, token); free (token); } return (si); } /* }}} search_info_t *search_parse */