void jl_gc_init(void) { int szc[N_POOLS] = { 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72, 80, 88, 96, //#=18 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 288, 320, 352, 384, 416, 448, 480, 512, 640, 768, 896, 1024, 1536, 2048 }; int i; for(i=0; i < N_POOLS; i++) { norm_pools[i].osize = szc[i]; norm_pools[i].pages = NULL; norm_pools[i].freelist = NULL; ephe_pools[i].osize = szc[i]; ephe_pools[i].pages = NULL; ephe_pools[i].freelist = NULL; } htable_new(&finalizer_table, 0); arraylist_new(&to_finalize, 0); arraylist_new(&preserved_values, 0); arraylist_new(&weak_refs, 0); #ifdef OBJPROFILE htable_new(&obj_counts, 0); #endif }
TEST(Arraylist, New) { int initial_size, sorted, allow_duplicates; /* * in order to create an arraylist, initial_size must be >= 0 and a * comparison callback must be given */ POINTERS_EQUAL(NULL, arraylist_new (-1, 0, 0, NULL, NULL, NULL, NULL)); POINTERS_EQUAL(NULL, arraylist_new (-1, 0, 0, &test_cmp_cb, NULL, NULL, NULL)); POINTERS_EQUAL(NULL, arraylist_new (0, 0, 0, NULL, NULL, NULL, NULL)); /* tests on arraylists */ for (initial_size = 0; initial_size < 2; initial_size++) { for (sorted = 0; sorted < 2; sorted++) { for (allow_duplicates = 0; allow_duplicates < 2; allow_duplicates++) { test_arraylist (initial_size, sorted, allow_duplicates); } } } }
void gui_completion_buffer_init (struct t_gui_completion *completion, struct t_gui_buffer *buffer) { completion->buffer = buffer; completion->context = GUI_COMPLETION_NULL; completion->base_command = NULL; completion->base_command_arg_index = 0; completion->base_word = NULL; completion->base_word_pos = 0; completion->position = -1; completion->args = NULL; completion->direction = 0; completion->add_space = 1; completion->force_partial_completion = 0; completion->reverse_partial_completion = 0; completion->list = arraylist_new ( 32, 1, 0, &gui_completion_word_compare_cb, NULL, &gui_completion_word_free_cb, NULL); completion->word_found = NULL; completion->word_found_is_nick = 0; completion->position_replace = 0; completion->diff_size = 0; completion->diff_length = 0; completion->partial_list = arraylist_new ( 0, 0, 0, &gui_completion_word_compare_cb, NULL, &gui_completion_word_free_cb, NULL); }
static void allocate_segv_handler() { #ifdef JULIA_ENABLE_THREADING arraylist_new(&suspended_threads, jl_n_threads); #endif pthread_t thread; pthread_attr_t attr; kern_return_t ret; mach_port_t self = mach_task_self(); ret = mach_port_allocate(self, MACH_PORT_RIGHT_RECEIVE, &segv_port); HANDLE_MACH_ERROR("mach_port_allocate",ret); ret = mach_port_insert_right(self, segv_port, segv_port, MACH_MSG_TYPE_MAKE_SEND); HANDLE_MACH_ERROR("mach_port_insert_right",ret); // Alright, create a thread to serve as the listener for exceptions if (pthread_attr_init(&attr) != 0) { jl_error("pthread_attr_init failed"); } pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (pthread_create(&thread, &attr, mach_segv_listener, NULL) != 0) { jl_error("pthread_create failed"); } pthread_attr_destroy(&attr); for (int16_t tid = 0;tid < jl_n_threads;tid++) { attach_exception_port(pthread_mach_thread_np(jl_all_task_states[tid].system_id)); } }
JL_DLLEXPORT jl_module_t *jl_new_module(jl_sym_t *name) { jl_ptls_t ptls = jl_get_ptls_states(); jl_module_t *m = (jl_module_t*)jl_gc_alloc(ptls, sizeof(jl_module_t), jl_module_type); JL_GC_PUSH1(&m); assert(jl_is_symbol(name)); m->name = name; m->parent = NULL; m->istopmod = 0; static unsigned int mcounter; // simple counter backup, in case hrtime is not incrementing m->uuid = jl_hrtime() + (++mcounter); if (!m->uuid) m->uuid++; // uuid 0 is invalid m->counter = 0; htable_new(&m->bindings, 0); arraylist_new(&m->usings, 0); if (jl_core_module) { jl_module_using(m, jl_core_module); } // export own name, so "using Foo" makes "Foo" itself visible jl_set_const(m, name, (jl_value_t*)m); jl_module_export(m, name); JL_GC_POP(); return m; }
p2p_ctx* p2p_init(char* ip_bind,uint32_t port) { p2p_ctx *ctx=malloc(sizeof(p2p_ctx)); if(ctx!=NULL) { pthread_mutex_init(&ctx->mutex,NULL); ctx->peers=arraylist_new(20); ctx->handler=libpeers_default_handle_message; ctx->port=port; ctx->s=sock_init(AF_INET,SOCK_DGRAM,0); ctx->packet_size=kKB4; // sock_setaddress(ctx->s,ip_bind); sock_setaddress_var(ctx->s,ctx->port,htonl(INADDR_ANY)); // int opt=1; // sock_setopt(ctx->s,SOL_SOCKET,SO_REUSEADDR,&opt,1); // sock_setopt(ctx->s,SOL_SOCKET,SO_REUSEPORT,&opt,1); // struct timeval timeout={1,0}; // timeout.tv_sec = 1; // timeout.tv_usec = 0; // sock_setopt(ctx->s,SOL_SOCKET,SO_RCVTIMEO,&timeout,sizeof(timeout)); ctx->status=0; } return ctx; }
void jl_gc_init(void) { int szc[N_POOLS] = { 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72, 80, 88, 96, //#=18 112, 128, 144, 160, 176, 192, 208, 224, 240, 256, 288, 320, 352, 384, 416, 448, 480, 512, 640, 768, 896, 1024, 1536, 2048 }; int i; for(i=0; i < N_POOLS; i++) { norm_pools[i].osize = szc[i]; norm_pools[i].pages = NULL; norm_pools[i].freelist = NULL; ephe_pools[i].osize = szc[i]; ephe_pools[i].pages = NULL; ephe_pools[i].freelist = NULL; } htable_new(&finalizer_table, 0); arraylist_new(&to_finalize, 0); arraylist_new(&preserved_values, 0); arraylist_new(&weak_refs, 0); #ifdef OBJPROFILE htable_new(&obj_counts, 0); #endif #ifdef GC_FINAL_STATS process_t0 = clock_now(); #endif #ifdef _P64 // on a big memory machine, set max_collect_interval to totalmem/ncores/2 size_t maxmem = (uv_get_total_memory()/jl_cpu_cores())/2; if (maxmem > max_collect_interval) max_collect_interval = maxmem; #endif }
jl_module_t *jl_new_module(jl_sym_t *name) { jl_module_t *m = (jl_module_t*)allocb(sizeof(jl_module_t)); m->name = name; htable_new(&m->bindings, 0); htable_new(&m->macros, 0); htable_new(&m->modules, 0); arraylist_new(&m->imports, 0); return m; }
jl_module_t *jl_new_module(jl_sym_t *name) { jl_module_t *m = (jl_module_t*)allocobj(sizeof(jl_module_t)); m->type = (jl_value_t*)jl_module_type; m->name = name; htable_new(&m->bindings, 0); jl_set_const(m, name, (jl_value_t*)m); arraylist_new(&m->usings, 0); if (jl_core_module) { jl_module_using(m, jl_core_module); } // export own name, so "using Foo" makes "Foo" itself visible jl_module_export(m, name); return m; }
ArrayList* simple_string_split(const char* self, const char* regex) { ArrayList* values = arraylist_new(-1); char* buffer = strdup(self); char* buf = buffer; char* ptr = NULL; char* sub = NULL; while ((sub = strtok_r(buf, regex, &ptr)) != NULL) { char* value = malloc(sizeof(strlen(sub) + 1)); bzero(value, strlen(sub) + 1); memcpy(value, sub, strlen(sub)); arraylist_add(values, value); buf = NULL; } free(buffer); return values; }
JL_DLLEXPORT jl_module_t *jl_new_module(jl_sym_t *name) { jl_module_t *m = (jl_module_t*)jl_gc_allocobj(sizeof(jl_module_t)); jl_set_typeof(m, jl_module_type); JL_GC_PUSH1(&m); assert(jl_is_symbol(name)); m->name = name; m->parent = NULL; m->istopmod = 0; m->uuid = uv_now(uv_default_loop()); m->counter = 0; htable_new(&m->bindings, 0); arraylist_new(&m->usings, 0); if (jl_core_module) { jl_module_using(m, jl_core_module); } // export own name, so "using Foo" makes "Foo" itself visible jl_set_const(m, name, (jl_value_t*)m); jl_module_export(m, name); JL_GC_POP(); return m; }
void test_arraylist (int initial_size, int sorted, int allow_duplicates) { struct t_arraylist *arraylist; int i, index, index_insert; void *pointer; const char *item_aaa = "aaa"; const char *item_abc = "abc"; const char *item_DEF = "DEF"; const char *item_Def = "Def"; const char *item_def = "def"; const char *item_xxx = "xxx"; const char *item_zzz = "zzz"; /* create arraylist */ arraylist = arraylist_new (initial_size, sorted, allow_duplicates, &test_cmp_cb, NULL, NULL, NULL); /* check values after creation */ CHECK(arraylist); LONGS_EQUAL(0, arraylist->size); LONGS_EQUAL(initial_size, arraylist->size_alloc); LONGS_EQUAL(initial_size, arraylist->size_alloc_min); if (initial_size > 0) { CHECK(arraylist->data); for (i = 0; i < initial_size; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } else { POINTERS_EQUAL(NULL, arraylist->data); } LONGS_EQUAL(sorted, arraylist->sorted); LONGS_EQUAL(allow_duplicates, arraylist->allow_duplicates); /* check size */ LONGS_EQUAL(0, arraylist_size (arraylist)); /* get element (this should always fail, the list is empty!) */ POINTERS_EQUAL(NULL, arraylist_get (NULL, -1)); POINTERS_EQUAL(NULL, arraylist_get (NULL, 0)); POINTERS_EQUAL(NULL, arraylist_get (NULL, 1)); POINTERS_EQUAL(NULL, arraylist_get (arraylist, -1)); POINTERS_EQUAL(NULL, arraylist_get (arraylist, 0)); POINTERS_EQUAL(NULL, arraylist_get (arraylist, 1)); /* search element (this should always fail, the list is empty!) */ POINTERS_EQUAL(NULL, arraylist_search (NULL, NULL, NULL, NULL)); POINTERS_EQUAL(NULL, arraylist_search (arraylist, NULL, NULL, NULL)); POINTERS_EQUAL(NULL, arraylist_search (NULL, (void *)item_abc, NULL, NULL)); POINTERS_EQUAL(NULL, arraylist_search (arraylist, (void *)item_abc, NULL, NULL)); /* invalid add of element */ LONGS_EQUAL(-1, arraylist_add (NULL, NULL)); /* add some elements */ if (sorted) { TEST_ARRAYLIST_ADD(0, item_zzz); TEST_ARRAYLIST_ADD(0, item_xxx); TEST_ARRAYLIST_ADD(0, NULL); TEST_ARRAYLIST_ADD(1, item_DEF); TEST_ARRAYLIST_ADD((allow_duplicates) ? 2 : 1, item_def); TEST_ARRAYLIST_ADD((allow_duplicates) ? 3 : 1, item_Def); TEST_ARRAYLIST_ADD(1, item_abc); } else { TEST_ARRAYLIST_ADD(0, item_zzz); TEST_ARRAYLIST_ADD(1, item_xxx); TEST_ARRAYLIST_ADD(2, NULL); TEST_ARRAYLIST_ADD(3, item_DEF); TEST_ARRAYLIST_ADD((allow_duplicates) ? 4 : 3, item_def); TEST_ARRAYLIST_ADD((allow_duplicates) ? 5 : 3, item_Def); TEST_ARRAYLIST_ADD((allow_duplicates) ? 6 : 4, item_abc); } /* * arraylist is now: * sorted: * dup : [NULL, "abc", "DEF", "def", "Def", "xxx", "zzz"] + 2 NULL * no dup: [NULL, "abc", "Def", "xxx", "zzz"] + 1 NULL * not sorted: * dup : ["zzz", "xxx", NULL, "DEF", "def", "Def", "abc"] + 2 NULL * no dup: ["zzz", "xxx", NULL, "Def", "abc"] + 1 NULL */ /* check size after adds */ LONGS_EQUAL((allow_duplicates) ? 7 : 5, arraylist->size); LONGS_EQUAL((allow_duplicates) ? 7 : 5, arraylist_size (arraylist)); LONGS_EQUAL((allow_duplicates) ? 9 : 6, arraylist->size_alloc); /* check content after adds */ if (sorted) { if (allow_duplicates) { POINTERS_EQUAL(NULL, arraylist->data[0]); STRCMP_EQUAL(item_abc, (const char *)arraylist->data[1]); STRCMP_EQUAL(item_DEF, (const char *)arraylist->data[2]); STRCMP_EQUAL(item_def, (const char *)arraylist->data[3]); STRCMP_EQUAL(item_Def, (const char *)arraylist->data[4]); STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[5]); STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[6]); for (i = 7; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } else { POINTERS_EQUAL(NULL, arraylist->data[0]); STRCMP_EQUAL(item_abc, (const char *)arraylist->data[1]); STRCMP_EQUAL(item_Def, (const char *)arraylist->data[2]); STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[3]); STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[4]); for (i = 5; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } } else { if (allow_duplicates) { STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[0]); STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[1]); POINTERS_EQUAL(NULL, arraylist->data[2]); STRCMP_EQUAL(item_DEF, (const char *)arraylist->data[3]); STRCMP_EQUAL(item_def, (const char *)arraylist->data[4]); STRCMP_EQUAL(item_Def, (const char *)arraylist->data[5]); STRCMP_EQUAL(item_abc, (const char *)arraylist->data[6]); for (i = 7; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } else { STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[0]); STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[1]); POINTERS_EQUAL(NULL, arraylist->data[2]); STRCMP_EQUAL(item_Def, (const char *)arraylist->data[3]); STRCMP_EQUAL(item_abc, (const char *)arraylist->data[4]); for (i = 5; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } } /* search elements */ if (sorted) { if (allow_duplicates) { TEST_ARRAYLIST_SEARCH(NULL, 0, 1, NULL); TEST_ARRAYLIST_SEARCH(item_abc, 1, 2, item_abc); TEST_ARRAYLIST_SEARCH(item_DEF, 2, 5, item_DEF); TEST_ARRAYLIST_SEARCH(item_DEF, 2, 5, item_def); TEST_ARRAYLIST_SEARCH(item_DEF, 2, 5, item_Def); TEST_ARRAYLIST_SEARCH(item_xxx, 5, 6, item_xxx); TEST_ARRAYLIST_SEARCH(item_zzz, 6, 7, item_zzz); } else { TEST_ARRAYLIST_SEARCH(NULL, 0, 1, NULL); TEST_ARRAYLIST_SEARCH(item_abc, 1, 2, item_abc); TEST_ARRAYLIST_SEARCH(item_Def, 2, 3, item_DEF); TEST_ARRAYLIST_SEARCH(item_Def, 2, 3, item_def); TEST_ARRAYLIST_SEARCH(item_Def, 2, 3, item_Def); TEST_ARRAYLIST_SEARCH(item_xxx, 3, 4, item_xxx); TEST_ARRAYLIST_SEARCH(item_zzz, 4, 5, item_zzz); } /* search non-existing element */ TEST_ARRAYLIST_SEARCH(NULL, -1, 1, item_aaa); } else { if (allow_duplicates) { TEST_ARRAYLIST_SEARCH(item_zzz, 0, -1, item_zzz); TEST_ARRAYLIST_SEARCH(item_xxx, 1, -1, item_xxx); TEST_ARRAYLIST_SEARCH(NULL, 2, -1, NULL); TEST_ARRAYLIST_SEARCH(item_DEF, 3, -1, item_DEF); TEST_ARRAYLIST_SEARCH(item_DEF, 3, -1, item_def); TEST_ARRAYLIST_SEARCH(item_DEF, 3, -1, item_Def); TEST_ARRAYLIST_SEARCH(item_abc, 6, -1, item_abc); } else { TEST_ARRAYLIST_SEARCH(item_zzz, 0, -1, item_zzz); TEST_ARRAYLIST_SEARCH(item_xxx, 1, -1, item_xxx); TEST_ARRAYLIST_SEARCH(NULL, 2, -1, NULL); TEST_ARRAYLIST_SEARCH(item_Def, 3, -1, item_DEF); TEST_ARRAYLIST_SEARCH(item_Def, 3, -1, item_def); TEST_ARRAYLIST_SEARCH(item_Def, 3, -1, item_Def); TEST_ARRAYLIST_SEARCH(item_abc, 4, -1, item_abc); } /* search non-existing element */ TEST_ARRAYLIST_SEARCH(NULL, -1, -1, item_aaa); } /* invalid remove of elements */ LONGS_EQUAL(-1, arraylist_remove (NULL, -1)); LONGS_EQUAL(-1, arraylist_remove (arraylist, -1)); LONGS_EQUAL(-1, arraylist_remove (NULL, 0)); /* remove the 3 first elements and check size after each remove */ LONGS_EQUAL(0, arraylist_remove (arraylist, 0)); LONGS_EQUAL((allow_duplicates) ? 6 : 4, arraylist->size); LONGS_EQUAL((allow_duplicates) ? 6 : 4, arraylist_size (arraylist)); LONGS_EQUAL((allow_duplicates) ? 9 : 6, arraylist->size_alloc); LONGS_EQUAL(0, arraylist_remove (arraylist, 0)); LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist->size); LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist_size (arraylist)); LONGS_EQUAL((allow_duplicates) ? 9 : 6, arraylist->size_alloc); LONGS_EQUAL(0, arraylist_remove (arraylist, 0)); LONGS_EQUAL((allow_duplicates) ? 4 : 2, arraylist->size); LONGS_EQUAL((allow_duplicates) ? 4 : 2, arraylist_size (arraylist)); LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist->size_alloc); /* * arraylist is now: * sorted: * dup : ["def", "Def", "xxx", "zzz"] + 1 NULL * no dup: ["xxx", "zzz"] + 1 NULL * not sorted: * dup : ["DEF", "def", "Def", "abc"] + 1 NULL * no dup: ["Def", "abc"] + 1 NULL */ /* check content after the 3 deletions */ if (sorted) { if (allow_duplicates) { STRCMP_EQUAL(item_def, (const char *)arraylist->data[0]); STRCMP_EQUAL(item_Def, (const char *)arraylist->data[1]); STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[2]); STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[3]); for (i = 4; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } else { STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[0]); STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[1]); for (i = 2; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } } else { if (allow_duplicates) { STRCMP_EQUAL(item_DEF, (const char *)arraylist->data[0]); STRCMP_EQUAL(item_def, (const char *)arraylist->data[1]); STRCMP_EQUAL(item_Def, (const char *)arraylist->data[2]); STRCMP_EQUAL(item_abc, (const char *)arraylist->data[3]); for (i = 4; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } else { STRCMP_EQUAL(item_Def, (const char *)arraylist->data[0]); STRCMP_EQUAL(item_abc, (const char *)arraylist->data[1]); for (i = 2; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } } /* invalid insert of element */ LONGS_EQUAL(-1, arraylist_insert (NULL, 0, NULL)); /* insert of one element */ LONGS_EQUAL(0, arraylist_insert (arraylist, 0, (void *)item_aaa)); /* * arraylist is now: * sorted: * dup : ["aaa", "def", "Def", "xxx", "zzz"] * no dup: ["aaa", "xxx", "zzz"] * not sorted: * dup : ["aaa", "DEF", "def", "Def", "abc"] * no dup: ["aaa", "Def", "abc"] */ /* check size after insert */ LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist->size); LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist_size (arraylist)); LONGS_EQUAL((allow_duplicates) ? 5 : 3, arraylist->size_alloc); /* check content after the insert */ if (sorted) { if (allow_duplicates) { STRCMP_EQUAL(item_aaa, (const char *)arraylist->data[0]); STRCMP_EQUAL(item_def, (const char *)arraylist->data[1]); STRCMP_EQUAL(item_Def, (const char *)arraylist->data[2]); STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[3]); STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[4]); for (i = 5; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } else { STRCMP_EQUAL(item_aaa, (const char *)arraylist->data[0]); STRCMP_EQUAL(item_xxx, (const char *)arraylist->data[1]); STRCMP_EQUAL(item_zzz, (const char *)arraylist->data[2]); for (i = 3; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } } else { if (allow_duplicates) { STRCMP_EQUAL(item_aaa, (const char *)arraylist->data[0]); STRCMP_EQUAL(item_DEF, (const char *)arraylist->data[1]); STRCMP_EQUAL(item_def, (const char *)arraylist->data[2]); STRCMP_EQUAL(item_Def, (const char *)arraylist->data[3]); STRCMP_EQUAL(item_abc, (const char *)arraylist->data[4]); for (i = 5; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } else { STRCMP_EQUAL(item_aaa, (const char *)arraylist->data[0]); STRCMP_EQUAL(item_Def, (const char *)arraylist->data[1]); STRCMP_EQUAL(item_abc, (const char *)arraylist->data[2]); for (i = 3; i < arraylist->size_alloc; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } } /* clear arraylist */ LONGS_EQUAL(0, arraylist_clear (NULL)); LONGS_EQUAL(1, arraylist_clear (arraylist)); /* check size and data after clear */ LONGS_EQUAL(0, arraylist->size); LONGS_EQUAL(0, arraylist_size (arraylist)); LONGS_EQUAL(initial_size, arraylist->size_alloc); if (initial_size > 0) { CHECK(arraylist->data); for (i = 0; i < initial_size; i++) { POINTERS_EQUAL(NULL, arraylist->data[i]); } } else { POINTERS_EQUAL(NULL, arraylist->data); } /* free arraylist */ arraylist_free (arraylist); }
jl_value_t *jl_eval_module_expr(jl_expr_t *ex) { static arraylist_t module_stack; static int initialized=0; static jl_module_t *outermost = NULL; if (!initialized) { arraylist_new(&module_stack, 0); initialized = 1; } assert(ex->head == module_sym); jl_module_t *last_module = jl_current_module; if (jl_array_len(ex->args) != 3 || !jl_is_expr(jl_exprarg(ex,2))) { jl_error("syntax: malformed module expression"); } int std_imports = (jl_exprarg(ex,0)==jl_true); jl_sym_t *name = (jl_sym_t*)jl_exprarg(ex, 1); if (!jl_is_symbol(name)) { jl_type_error("module", (jl_value_t*)jl_sym_type, (jl_value_t*)name); } jl_module_t *parent_module = jl_current_module; jl_binding_t *b = jl_get_binding_wr(parent_module, name); jl_declare_constant(b); if (b->value != NULL) { if (!jl_is_module(b->value)) { jl_errorf("invalid redefinition of constant %s", name->name); } if (jl_generating_output() && jl_options.incremental) { jl_errorf("cannot replace module %s during incremental compile", name->name); } if (!jl_generating_output()) { // suppress warning "replacing module Core.Inference" during bootstrapping jl_printf(JL_STDERR, "WARNING: replacing module %s\n", name->name); } } jl_module_t *newm = jl_new_module(name); newm->parent = parent_module; b->value = (jl_value_t*)newm; jl_gc_wb_binding(b, newm); if (parent_module == jl_main_module && name == jl_symbol("Base")) { // pick up Base module during bootstrap jl_old_base_module = jl_base_module; jl_base_module = newm; // reinitialize global variables // to pick up new types from Base jl_errorexception_type = NULL; jl_argumenterror_type = NULL; jl_methoderror_type = NULL; jl_loaderror_type = NULL; jl_current_task->tls = jl_nothing; // may contain an entry for :SOURCE_FILE that is not valid in the new base } // export all modules from Main if (parent_module == jl_main_module) jl_module_export(jl_main_module, name); // add standard imports unless baremodule if (std_imports) { if (jl_base_module != NULL) { jl_add_standard_imports(newm); } } JL_GC_PUSH1(&last_module); jl_module_t *task_last_m = jl_current_task->current_module; jl_current_task->current_module = jl_current_module = newm; jl_module_t *prev_outermost = outermost; size_t stackidx = module_stack.len; if (outermost == NULL) outermost = newm; jl_array_t *exprs = ((jl_expr_t*)jl_exprarg(ex, 2))->args; JL_TRY { for(int i=0; i < jl_array_len(exprs); i++) { // process toplevel form jl_value_t *form = jl_cellref(exprs, i); (void)jl_toplevel_eval_flex(form, 1); } } JL_CATCH { jl_current_module = last_module; jl_current_task->current_module = task_last_m; outermost = prev_outermost; module_stack.len = stackidx; jl_rethrow(); } JL_GC_POP(); jl_current_module = last_module; jl_current_task->current_module = task_last_m; outermost = prev_outermost; #if 0 // some optional post-processing steps size_t i; void **table = newm->bindings.table; for(i=1; i < newm->bindings.size; i+=2) { if (table[i] != HT_NOTFOUND) { jl_binding_t *b = (jl_binding_t*)table[i]; // remove non-exported macros if (b->name->name[0]=='@' && !b->exportp && b->owner==newm) b->value = NULL; // error for unassigned exports /* if (b->exportp && b->owner==newm && b->value==NULL) jl_errorf("identifier %s exported from %s is not initialized", b->name->name, newm->name->name); */ } } #endif arraylist_push(&module_stack, newm); if (outermost == NULL || jl_current_module == jl_main_module) { size_t i, l=module_stack.len; for(i = stackidx; i < l; i++) { jl_module_load_time_initialize((jl_module_t*)module_stack.items[i]); } assert(module_stack.len == l); module_stack.len = stackidx; } return (jl_value_t*)newm; }
jl_value_t *jl_eval_module_expr(jl_expr_t *ex) { static arraylist_t module_stack; static int initialized=0; if (!initialized) { arraylist_new(&module_stack, 0); initialized = 1; } assert(ex->head == module_sym); jl_module_t *last_module = jl_current_module; if (jl_array_len(ex->args) != 3 || !jl_is_expr(jl_exprarg(ex,2))) { jl_error("syntax: malformed module expression"); } int std_imports = (jl_exprarg(ex,0)==jl_true); jl_sym_t *name = (jl_sym_t*)jl_exprarg(ex, 1); if (!jl_is_symbol(name)) { jl_type_error("module", (jl_value_t*)jl_sym_type, (jl_value_t*)name); } jl_module_t *parent_module = jl_current_module; jl_binding_t *b = jl_get_binding_wr(parent_module, name); jl_declare_constant(b); if (b->value != NULL) { JL_PRINTF(JL_STDERR, "Warning: replacing module %s\n", name->name); } jl_module_t *newm = jl_new_module(name); newm->parent = parent_module; b->value = (jl_value_t*)newm; if (parent_module == jl_main_module && name == jl_symbol("Base")) { // pick up Base module during bootstrap jl_old_base_module = jl_base_module; jl_base_module = newm; // reinitialize global variables // to pick up new types from Base jl_errorexception_type = NULL; jl_typeerror_type = NULL; jl_methoderror_type = NULL; jl_loaderror_type = NULL; jl_weakref_type = NULL; jl_current_task->tls = jl_nothing; } // export all modules from Main if (parent_module == jl_main_module) jl_module_export(jl_main_module, name); // add standard imports unless baremodule if (std_imports) { if (jl_base_module != NULL) { jl_add_standard_imports(newm); } } JL_GC_PUSH1(&last_module); jl_module_t *task_last_m = jl_current_task->current_module; jl_current_task->current_module = jl_current_module = newm; jl_array_t *exprs = ((jl_expr_t*)jl_exprarg(ex, 2))->args; JL_TRY { for(int i=0; i < jl_array_len(exprs); i++) { // process toplevel form jl_value_t *form = jl_cellref(exprs, i); (void)jl_toplevel_eval_flex(form, 1); } } JL_CATCH { jl_current_module = last_module; jl_current_task->current_module = task_last_m; jl_rethrow(); } JL_GC_POP(); jl_current_module = last_module; jl_current_task->current_module = task_last_m; #if 0 // some optional post-processing steps size_t i; void **table = newm->bindings.table; for(i=1; i < newm->bindings.size; i+=2) { if (table[i] != HT_NOTFOUND) { jl_binding_t *b = (jl_binding_t*)table[i]; // remove non-exported macros if (b->name->name[0]=='@' && !b->exportp && b->owner==newm) b->value = NULL; // error for unassigned exports /* if (b->exportp && b->owner==newm && b->value==NULL) jl_errorf("identifier %s exported from %s is not initialized", b->name->name, newm->name->name); */ } } #endif arraylist_push(&module_stack, newm); if (jl_current_module == jl_main_module) { while (module_stack.len > 0) { jl_module_load_time_initialize((jl_module_t *) arraylist_pop(&module_stack)); } } return jl_nothing; }
jl_value_t *jl_eval_module_expr(jl_expr_t *ex) { jl_ptls_t ptls = jl_get_ptls_states(); static arraylist_t module_stack; static int initialized=0; static jl_module_t *outermost = NULL; if (!initialized) { arraylist_new(&module_stack, 0); initialized = 1; } assert(ex->head == module_sym); jl_module_t *last_module = ptls->current_module; if (jl_array_len(ex->args) != 3 || !jl_is_expr(jl_exprarg(ex,2))) { jl_error("syntax: malformed module expression"); } int std_imports = (jl_exprarg(ex,0)==jl_true); jl_sym_t *name = (jl_sym_t*)jl_exprarg(ex, 1); if (!jl_is_symbol(name)) { jl_type_error("module", (jl_value_t*)jl_sym_type, (jl_value_t*)name); } jl_module_t *parent_module = ptls->current_module; jl_binding_t *b = jl_get_binding_wr(parent_module, name); jl_declare_constant(b); if (b->value != NULL) { if (!jl_is_module(b->value)) { jl_errorf("invalid redefinition of constant %s", jl_symbol_name(name)); } if (jl_generating_output()) { jl_errorf("cannot replace module %s during compilation", jl_symbol_name(name)); } jl_printf(JL_STDERR, "WARNING: replacing module %s\n", jl_symbol_name(name)); } jl_module_t *newm = jl_new_module(name); newm->parent = parent_module; b->value = (jl_value_t*)newm; jl_gc_wb_binding(b, newm); if (parent_module == jl_main_module && name == jl_symbol("Base")) { // pick up Base module during bootstrap jl_base_module = newm; } // export all modules from Main if (parent_module == jl_main_module) jl_module_export(jl_main_module, name); // add standard imports unless baremodule if (std_imports) { if (jl_base_module != NULL) { jl_add_standard_imports(newm); } } jl_value_t *defaultdefs = NULL, *form = NULL; JL_GC_PUSH3(&last_module, &defaultdefs, &form); jl_module_t *task_last_m = ptls->current_task->current_module; ptls->current_task->current_module = ptls->current_module = newm; jl_module_t *prev_outermost = outermost; size_t stackidx = module_stack.len; if (outermost == NULL) outermost = newm; if (std_imports) { // add `eval` function defaultdefs = jl_call_scm_on_ast("module-default-defs", (jl_value_t*)ex); jl_toplevel_eval_flex(defaultdefs, 0, 1); defaultdefs = NULL; } jl_array_t *exprs = ((jl_expr_t*)jl_exprarg(ex, 2))->args; JL_TRY { for(int i=0; i < jl_array_len(exprs); i++) { // process toplevel form form = jl_expand(jl_array_ptr_ref(exprs, i)); (void)jl_toplevel_eval_flex(form, 1, 1); } } JL_CATCH { ptls->current_module = last_module; ptls->current_task->current_module = task_last_m; outermost = prev_outermost; module_stack.len = stackidx; jl_rethrow(); } JL_GC_POP(); ptls->current_module = last_module; ptls->current_task->current_module = task_last_m; outermost = prev_outermost; #if 0 // some optional post-processing steps size_t i; void **table = newm->bindings.table; for(i=1; i < newm->bindings.size; i+=2) { if (table[i] != HT_NOTFOUND) { jl_binding_t *b = (jl_binding_t*)table[i]; // remove non-exported macros if (jl_symbol_name(b->name)[0]=='@' && !b->exportp && b->owner == newm) b->value = NULL; // error for unassigned exports /* if (b->exportp && b->owner==newm && b->value==NULL) jl_errorf("identifier %s exported from %s is not initialized", jl_symbol_name(b->name), jl_symbol_name(newm->name)); */ } } #endif arraylist_push(&module_stack, newm); if (outermost == NULL || ptls->current_module == jl_main_module) { JL_TRY { size_t i, l=module_stack.len; for(i = stackidx; i < l; i++) { jl_module_load_time_initialize((jl_module_t*)module_stack.items[i]); } assert(module_stack.len == l); module_stack.len = stackidx; } JL_CATCH { module_stack.len = stackidx; jl_rethrow(); } }
ArrayList *seqstack_new(unsigned int length) { ArrayList *seqstack = arraylist_new(length); return seqstack; }
static void test_arraylist (void) { ArrayList* arraylist; arraylist = arraylist_new (0); arraylist_free (arraylist); }