// run time version of pointerset intrinsic DLLEXPORT void jl_pointerset(jl_value_t *p, jl_value_t *x, jl_value_t *i) { JL_TYPECHK(pointerset, pointer, p); JL_TYPECHK(pointerset, long, i); jl_value_t *ety = jl_tparam0(jl_typeof(p)); if (!jl_is_datatype(ety)) jl_error("pointerset: invalid pointer"); size_t nb = jl_datatype_size(ety); char *pp = (char*)jl_unbox_long(p) + (jl_unbox_long(i)-1)*nb; if (jl_typeof(x) != ety) jl_error("pointerset: type mismatch in assign"); jl_assign_bits(pp, x); }
static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v) { if (jl_is_symbol(v)) return symbol(fl_ctx, jl_symbol_name((jl_sym_t*)v)); if (v == jl_true) return jl_ast_ctx(fl_ctx)->true_sym; if (v == jl_false) return jl_ast_ctx(fl_ctx)->false_sym; if (v == jl_nothing) return fl_cons(fl_ctx, jl_ast_ctx(fl_ctx)->null_sym, fl_ctx->NIL); if (jl_is_expr(v)) { jl_expr_t *ex = (jl_expr_t*)v; value_t args = fl_ctx->NIL; fl_gc_handle(fl_ctx, &args); array_to_list(fl_ctx, ex->args, &args); value_t hd = julia_to_scm_(fl_ctx, (jl_value_t*)ex->head); if (ex->head == lambda_sym && jl_expr_nargs(ex)>0 && jl_is_array(jl_exprarg(ex,0))) { value_t llist = fl_ctx->NIL; fl_gc_handle(fl_ctx, &llist); array_to_list(fl_ctx, (jl_array_t*)jl_exprarg(ex,0), &llist); car_(args) = llist; fl_free_gc_handles(fl_ctx, 1); } value_t scmv = fl_cons(fl_ctx, hd, args); fl_free_gc_handles(fl_ctx, 1); return scmv; } // GC Note: jl_fieldref(v, 0) allocate for LabelNode, GotoNode // but we don't need a GC root here because julia_to_list2 // shouldn't allocate in this case. if (jl_typeis(v, jl_labelnode_type)) return julia_to_list2(fl_ctx, (jl_value_t*)label_sym, jl_fieldref(v,0)); if (jl_typeis(v, jl_linenumbernode_type)) return julia_to_list2(fl_ctx, (jl_value_t*)line_sym, jl_fieldref(v,0)); if (jl_typeis(v, jl_gotonode_type)) return julia_to_list2(fl_ctx, (jl_value_t*)goto_sym, jl_fieldref(v,0)); if (jl_typeis(v, jl_quotenode_type)) return julia_to_list2(fl_ctx, (jl_value_t*)inert_sym, jl_fieldref(v,0)); if (jl_typeis(v, jl_newvarnode_type)) return julia_to_list2(fl_ctx, (jl_value_t*)newvar_sym, jl_fieldref(v,0)); if (jl_is_long(v) && fits_fixnum(jl_unbox_long(v))) return fixnum(jl_unbox_long(v)); if (jl_is_ssavalue(v)) jl_error("SSAValue objects should not occur in an AST"); if (jl_is_slot(v)) jl_error("Slot objects should not occur in an AST"); value_t opaque = cvalue(fl_ctx, jl_ast_ctx(fl_ctx)->jvtype, sizeof(void*)); *(jl_value_t**)cv_data((cvalue_t*)ptr(opaque)) = v; return opaque; }
void jl_install_default_signal_handlers(void) { struct sigaction actf; memset(&actf, 0, sizeof(struct sigaction)); sigemptyset(&actf.sa_mask); actf.sa_sigaction = fpe_handler; actf.sa_flags = SA_SIGINFO; if (sigaction(SIGFPE, &actf, NULL) < 0) { jl_errorf("fatal error: sigaction: %s", strerror(errno)); } if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { jl_error("fatal error: Couldn't set SIGPIPE"); } if (signal(SIGTRAP, SIG_IGN) == SIG_ERR) { jl_error("fatal error: Couldn't set SIGTRAP"); } allocate_segv_handler(); struct sigaction act_die; memset(&act_die, 0, sizeof(struct sigaction)); sigemptyset(&act_die.sa_mask); act_die.sa_sigaction = sigdie_handler; act_die.sa_flags = SA_SIGINFO; if (sigaction(SIGILL, &act_die, NULL) < 0) { jl_errorf("fatal error: sigaction: %s", strerror(errno)); } if (sigaction(SIGABRT, &act_die, NULL) < 0) { jl_errorf("fatal error: sigaction: %s", strerror(errno)); } if (sigaction(SIGSYS, &act_die, NULL) < 0) { jl_errorf("fatal error: sigaction: %s", strerror(errno)); } // need to ensure the following signals are not SIG_IGN, even though they will be blocked act_die.sa_flags = SA_SIGINFO | SA_RESTART; #if defined(HAVE_ITIMER) if (sigaction(SIGPROF, &act_die, NULL) < 0) { jl_errorf("fatal error: sigaction: %s", strerror(errno)); } #endif #ifdef SIGINFO if (sigaction(SIGINFO, &act_die, NULL) < 0) { jl_errorf("fatal error: sigaction: %s", strerror(errno)); } #else if (sigaction(SIGUSR1, &act_die, NULL) < 0) { jl_errorf("fatal error: sigaction: %s", strerror(errno)); } #endif }
// run time version of box/unbox intrinsic JL_DLLEXPORT jl_value_t *jl_reinterpret(jl_value_t *ty, jl_value_t *v) { JL_TYPECHK(reinterpret, datatype, ty); if (!jl_is_leaf_type(ty) || !jl_is_bitstype(ty)) jl_error("reinterpret: target type not a leaf bitstype"); if (!jl_is_bitstype(jl_typeof(v))) jl_error("reinterpret: value not a bitstype"); if (jl_datatype_size(jl_typeof(v)) != jl_datatype_size(ty)) jl_error("reinterpret: argument size does not match size of target type"); if (ty == jl_typeof(v)) return v; if (ty == (jl_value_t*)jl_bool_type) return *(uint8_t*)jl_data_ptr(v) & 1 ? jl_true : jl_false; return jl_new_bits(ty, jl_data_ptr(v)); }
// run time version of bitcast intrinsic JL_DLLEXPORT jl_value_t *jl_bitcast(jl_value_t *ty, jl_value_t *v) { JL_TYPECHK(bitcast, datatype, ty); if (!jl_is_concrete_type(ty) || !jl_is_primitivetype(ty)) jl_error("bitcast: target type not a leaf primitive type"); if (!jl_is_primitivetype(jl_typeof(v))) jl_error("bitcast: value not a primitive type"); if (jl_datatype_size(jl_typeof(v)) != jl_datatype_size(ty)) jl_error("bitcast: argument size does not match size of target type"); if (ty == jl_typeof(v)) return v; if (ty == (jl_value_t*)jl_bool_type) return *(uint8_t*)jl_data_ptr(v) & 1 ? jl_true : jl_false; return jl_new_bits(ty, jl_data_ptr(v)); }
jl_value_t *jl_callback_call(jl_function_t *f,jl_value_t *val,int count,...) { if (val != 0) count += 1; jl_value_t **argv; JL_GC_PUSHARGS(argv,count); memset(argv, 0, count*sizeof(jl_value_t*)); jl_value_t *v; va_list argp; va_start(argp,count); int i; argv[0]=val; for(i=((val==0)?0:1); i<count; ++i) { switch(va_arg(argp,int)) { case CB_PTR: argv[i] = jl_box_voidpointer(va_arg(argp,void*)); break; case CB_INT32: argv[i] = jl_box_int32(va_arg(argp,int32_t)); break; case CB_INT64: argv[i] = jl_box_int64(va_arg(argp,int64_t)); break; default: jl_error("callback: only Ints and Pointers are supported at this time"); //excecution never reaches here break; } } v = jl_apply(f,(jl_value_t**)argv,count); JL_GC_POP(); return v; }
static void jl_init_ast_ctx(jl_ast_context_t *ast_ctx) { fl_context_t *fl_ctx = &ast_ctx->fl; fl_init(fl_ctx, 4*1024*1024); if (fl_load_system_image_str(fl_ctx, (char*)flisp_system_image, sizeof(flisp_system_image))) { jl_error("fatal error loading system image"); } fl_applyn(fl_ctx, 0, symbol_value(symbol(fl_ctx, "__init_globals"))); jl_ast_context_t *ctx = jl_ast_ctx(fl_ctx); ctx->jvtype = define_opaque_type(fl_ctx->jl_sym, sizeof(void*), NULL, NULL); assign_global_builtins(fl_ctx, julia_flisp_ast_ext); ctx->true_sym = symbol(fl_ctx, "true"); ctx->false_sym = symbol(fl_ctx, "false"); ctx->error_sym = symbol(fl_ctx, "error"); ctx->null_sym = symbol(fl_ctx, "null"); ctx->ssavalue_sym = symbol(fl_ctx, "ssavalue"); ctx->slot_sym = symbol(fl_ctx, "slot"); ctx->task = NULL; ctx->module = NULL; set(symbol(fl_ctx, "*depwarn-opt*"), fixnum(jl_options.depwarn)); }
// NOTE: llvm cannot express all julia types (for example unsigned), // so this is an approximation. it's only correct if the associated LLVM // value is not tagged with our value name hack. // boxed(v) below gets the correct type. static jl_value_t *llvm_type_to_julia(Type *t, bool throw_error) { if (t == T_int1) return (jl_value_t*)jl_bool_type; if (t == T_int8) return (jl_value_t*)jl_int8_type; if (t == T_int16) return (jl_value_t*)jl_int16_type; if (t == T_int32) return (jl_value_t*)jl_int32_type; if (t == T_int64) return (jl_value_t*)jl_int64_type; if (t == T_float32) return (jl_value_t*)jl_float32_type; if (t == T_float64) return (jl_value_t*)jl_float64_type; if (t == T_void) return (jl_value_t*)jl_bottom_type; if (t == jl_pvalue_llvmt) return (jl_value_t*)jl_any_type; if (t->isPointerTy()) { jl_value_t *elty = llvm_type_to_julia(t->getContainedType(0), throw_error); if (elty != NULL) { return (jl_value_t*)jl_apply_type((jl_value_t*)jl_pointer_type, jl_tuple1(elty)); } } if (throw_error) { jl_error("cannot convert type to a julia type"); } return NULL; }
DLLEXPORT void jl_close_uv(uv_handle_t *handle) { if (!handle || uv_is_closing(handle)) return; if (handle->type==UV_TTY) uv_tty_set_mode((uv_tty_t*)handle,0); if ( (handle->type == UV_NAMED_PIPE || handle->type == UV_TCP) && uv_is_writable( (uv_stream_t *) handle)) { // Make sure that the stream has not already been marked closed in Julia. // A double shutdown would cause the process to hang on exit. JULIA_CB(isopen, handle->data, 0); if (!jl_is_int32(ret)) { jl_error("jl_close_uv: _uv_hook_isopen must return an int32."); } if (!jl_unbox_int32(ret)){ return; } uv_shutdown_t *req = malloc(sizeof(uv_shutdown_t)); int err = uv_shutdown(req, (uv_stream_t*)handle, &shutdownCallback); if (err != 0) { printf("shutdown err: %s\n", uv_strerror(uv_last_error(jl_global_event_loop()))); uv_close(handle, &closeHandle); } } else { uv_close(handle,&closeHandle); } }
static void jl_serialize_fptr(ios_t *s, void *fptr) { void **pbp = ptrhash_bp(&fptr_to_id, fptr); if (*pbp == HT_NOTFOUND) jl_error("unknown function pointer"); write_int32(s, *(ptrint_t*)pbp); }
static jl_sym_t *mk_symbol(const char *str) { #ifndef MEMDEBUG static char *sym_pool = NULL; static char *pool_ptr = NULL; #endif jl_sym_t *sym; size_t len = strlen(str); size_t nb = (sizeof(jl_sym_t)+len+1+7)&-8; if (nb >= SYM_POOL_SIZE) { jl_error("Symbol length exceeds maximum length"); } #ifdef MEMDEBUG sym = (jl_sym_t*)malloc(nb); #else if (sym_pool == NULL || pool_ptr+nb > sym_pool+SYM_POOL_SIZE) { sym_pool = (char*)malloc(SYM_POOL_SIZE); pool_ptr = sym_pool; } sym = (jl_sym_t*)pool_ptr; pool_ptr += nb; #endif sym->type = (jl_value_t*)jl_sym_type; sym->left = sym->right = NULL; sym->hash = hash_symbol(str, len); strcpy(&sym->name[0], str); return sym; }
jl_value_t *jl_method_def(jl_sym_t *name, jl_value_t **bp, jl_binding_t *bnd, jl_tuple_t *argtypes, jl_function_t *f, jl_tuple_t *t) { jl_value_t *gf; if (bnd) { jl_declare_constant(bnd); } if (*bp == NULL) { gf = (jl_value_t*)jl_new_generic_function(name); *bp = gf; } else { gf = *bp; if (!jl_is_gf(gf)) jl_error("in method definition: not a generic function"); } JL_GC_PUSH(&gf); assert(jl_is_function(f)); assert(jl_is_tuple(argtypes)); check_type_tuple(argtypes, name, "method definition"); jl_add_method((jl_function_t*)gf, argtypes, f, t); if (jl_boot_file_loaded && f->linfo && f->linfo->ast && jl_is_expr(f->linfo->ast)) { jl_lambda_info_t *li = f->linfo; li->ast = jl_compress_ast(li->ast); } JL_GC_POP(); return gf; }
JL_DLLEXPORT void jl_sigatomic_end(void) { jl_ptls_t ptls = jl_get_ptls_states(); if (ptls->defer_signal == 0) jl_error("sigatomic_end called in non-sigatomic region"); JL_SIGATOMIC_END(); }
static void jl_init_ast_ctx(jl_ast_context_t *ast_ctx) { fl_context_t *fl_ctx = &ast_ctx->fl; fl_init(fl_ctx, 4*1024*1024); if (fl_load_system_image_str(fl_ctx, (char*)flisp_system_image, sizeof(flisp_system_image))) { jl_error("fatal error loading system image"); } fl_applyn(fl_ctx, 0, symbol_value(symbol(fl_ctx, "__init_globals"))); jl_ast_ctx(fl_ctx)->jvtype = define_opaque_type(fl_ctx->jl_sym, sizeof(void*), NULL, NULL); assign_global_builtins(fl_ctx, julia_flisp_ast_ext); jl_ast_ctx(fl_ctx)->true_sym = symbol(fl_ctx, "true"); jl_ast_ctx(fl_ctx)->false_sym = symbol(fl_ctx, "false"); jl_ast_ctx(fl_ctx)->error_sym = symbol(fl_ctx, "error"); jl_ast_ctx(fl_ctx)->null_sym = symbol(fl_ctx, "null"); jl_ast_ctx(fl_ctx)->ssavalue_sym = symbol(fl_ctx, "ssavalue"); jl_ast_ctx(fl_ctx)->slot_sym = symbol(fl_ctx, "slot"); // Enable / disable syntax deprecation warnings if (jl_options.depwarn == JL_OPTIONS_DEPWARN_ERROR) jl_parse_deperror(fl_ctx, 1); else jl_parse_depwarn_(fl_ctx, (int)jl_options.depwarn); }
JL_DLLEXPORT jl_value_t *jl_cglobal(jl_value_t *v, jl_value_t *ty) { JL_TYPECHK(cglobal, type, ty); JL_GC_PUSH1(&v); jl_value_t *rt = ty == (jl_value_t*)jl_void_type ? (jl_value_t*)jl_voidpointer_type : // a common case (jl_value_t*)jl_apply_type1((jl_value_t*)jl_pointer_type, ty); JL_GC_PROMISE_ROOTED(rt); // (JL_ALWAYS_LEAFTYPE) if (!jl_is_concrete_type(rt)) jl_error("cglobal: type argument not concrete"); if (jl_is_tuple(v) && jl_nfields(v) == 1) v = jl_fieldref(v, 0); if (jl_is_pointer(v)) { v = jl_bitcast(rt, v); JL_GC_POP(); return v; } char *f_lib = NULL; if (jl_is_tuple(v) && jl_nfields(v) > 1) { jl_value_t *t1 = jl_fieldref_noalloc(v, 1); v = jl_fieldref(v, 0); if (jl_is_symbol(t1)) f_lib = jl_symbol_name((jl_sym_t*)t1); else if (jl_is_string(t1)) f_lib = jl_string_data(t1); else JL_TYPECHK(cglobal, symbol, t1) }
void jl_array_del_end(jl_array_t *a, size_t dec) { if (dec > a->length) jl_error("array_del_end: index out of range"); memset((char*)a->data + (a->length-dec)*a->elsize, 0, dec*a->elsize); a->length -= dec; a->nrows -= dec; }
void jl_array_del_beg(jl_array_t *a, size_t dec) { if (dec == 0) return; if (dec > a->length) jl_error("array_del_beg: index out of range"); size_t es = a->elsize; size_t nb = dec*es; memset(a->data, 0, nb); size_t offset = a->offset; offset += dec; a->data = (char*)a->data + nb; a->length -= dec; a->nrows -= dec; // make sure offset doesn't grow forever due to deleting at beginning // and growing at end size_t newoffs = offset; if (offset >= 13*a->maxsize/20) { newoffs = 17*(a->maxsize - a->length)/100; } #ifdef __LP64__ while (newoffs > (size_t)((uint32_t)-1)) { newoffs = newoffs/2; } #endif if (newoffs != offset) { size_t anb = a->length*es; size_t delta = (offset - newoffs)*es; a->data = (char*)a->data - delta; memmove(a->data, (char*)a->data + delta, anb); } a->offset = newoffs; }
/* multiq_insert() */ static inline int multiq_insert(jl_task_t *task, int16_t priority) { jl_ptls_t ptls = jl_get_ptls_states(); uint64_t rn; task->prio = priority; do { rn = cong(heap_p, cong_unbias, &ptls->rngseed); } while (!jl_mutex_trylock_nogc(&heaps[rn].lock)); if (heaps[rn].ntasks >= tasks_per_heap) { jl_mutex_unlock_nogc(&heaps[rn].lock); jl_error("multiq insertion failed, increase #tasks per heap"); return -1; } heaps[rn].tasks[heaps[rn].ntasks++] = task; sift_up(&heaps[rn], heaps[rn].ntasks-1); jl_mutex_unlock_nogc(&heaps[rn].lock); int16_t prio = jl_atomic_load(&heaps[rn].prio); if (task->prio < prio) jl_atomic_compare_exchange(&heaps[rn].prio, prio, task->prio); return 0; }
JL_DLLEXPORT jl_value_t *jl_cglobal(jl_value_t *v, jl_value_t *ty) { JL_TYPECHK(cglobal, type, ty); jl_value_t *rt = v == (jl_value_t*)jl_void_type ? (jl_value_t*)jl_voidpointer_type : // a common case (jl_value_t*)jl_apply_type_((jl_value_t*)jl_pointer_type, &ty, 1); if (!jl_is_leaf_type(rt)) jl_error("cglobal: type argument not a leaftype"); if (jl_is_tuple(v) && jl_nfields(v) == 1) v = jl_fieldref(v, 0); if (jl_is_pointer(v)) return jl_reinterpret(rt, v); char *f_lib = NULL; if (jl_is_tuple(v) && jl_nfields(v) > 1) { jl_value_t *t1 = jl_fieldref(v, 1); v = jl_fieldref(v, 0); if (jl_is_symbol(t1)) f_lib = jl_symbol_name((jl_sym_t*)t1); else if (jl_is_string(t1)) f_lib = jl_string_data(t1); else JL_TYPECHK(cglobal, symbol, t1) }
jl_value_t *jl_method_def(jl_sym_t *name, jl_value_t **bp, jl_binding_t *bnd, jl_tuple_t *argtypes, jl_function_t *f, jl_tuple_t *t) { jl_value_t *gf; if (bnd) { //jl_declare_constant(bnd); if (bnd->value != NULL && !bnd->constp) { jl_errorf("cannot define function %s; it already has a value", bnd->name->name); } bnd->constp = 1; } if (*bp == NULL) { gf = (jl_value_t*)jl_new_generic_function(name); *bp = gf; } else { gf = *bp; if (!jl_is_gf(gf)) { if (jl_is_datatype(gf) && ((jl_function_t*)gf)->fptr == jl_f_ctor_trampoline) { jl_add_constructors((jl_datatype_t*)gf); } if (!jl_is_gf(gf)) { jl_error("invalid method definition: not a generic function"); } } } JL_GC_PUSH1(&gf); assert(jl_is_function(f)); assert(jl_is_tuple(argtypes)); assert(jl_is_tuple(t)); for(size_t i=0; i < jl_tuple_len(argtypes); i++) { jl_value_t *elt = jl_tupleref(argtypes,i); if (!jl_is_type(elt) && !jl_is_typevar(elt)) { jl_lambda_info_t *li = f->linfo; jl_errorf("invalid type for argument %s in method definition for %s at %s:%d", jl_is_expr(li->ast) ? ((jl_sym_t*)jl_arrayref(jl_lam_args((jl_expr_t*)li->ast),i))->name : "?", name->name, li->file->name, li->line); } } for(size_t i=0; i < jl_tuple_len(t); i++) { if (!jl_is_typevar(jl_tupleref(t,i))) jl_type_error_rt(name->name, "method definition", (jl_value_t*)jl_tvar_type, jl_tupleref(t,i)); } jl_add_method((jl_function_t*)gf, argtypes, f, t); if (jl_boot_file_loaded && f->linfo && f->linfo->ast && jl_is_expr(f->linfo->ast)) { jl_lambda_info_t *li = f->linfo; li->ast = jl_compress_ast(li, li->ast); } JL_GC_POP(); return gf; }
static jl_value_t *jl_typeid_to_type(int i) { std::map<int, jl_value_t*>::iterator it = typeIdToType.find(i); if (it == typeIdToType.end()) { jl_error("unexpected error: invalid type id"); } return (*it).second; }
JL_DLLEXPORT jl_value_t *jl_check_top_bit(jl_value_t *a) { jl_value_t *ty = jl_typeof(a); if (!jl_is_bitstype(ty)) jl_error("check_top_bit: value is not a bitstype"); if (signbitbyte(jl_data_ptr(a), jl_datatype_size(ty))) jl_throw(jl_inexact_exception); return a; }
jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data, jl_tuple_t *dims) { size_t i; jl_array_t *a; size_t ndims = jl_tuple_len(dims); int ndimwords = jl_array_ndimwords(ndims); a = allocobj((sizeof(jl_array_t) + sizeof(void*) + ndimwords*sizeof(size_t) + 15)&-16); a->type = atype; a->ndims = ndims; a->offset = 0; a->data = NULL; a->isaligned = data->isaligned; jl_value_t *el_type = jl_tparam0(atype); if (store_unboxed(el_type)) { a->elsize = jl_datatype_size(el_type); a->ptrarray = 0; } else { a->elsize = sizeof(void*); a->ptrarray = 1; } JL_GC_PUSH1(&a); jl_array_data_owner(a) = (jl_value_t*)data; a->how = 3; a->data = data->data; a->isshared = 1; data->isshared = 1; if (ndims == 1) { size_t l = jl_unbox_long(jl_tupleref(dims,0)); #ifdef STORE_ARRAY_LEN a->length = l; #endif a->nrows = l; a->maxsize = l; } else { size_t *adims = &a->nrows; size_t l=1; wideint_t prod; for(i=0; i < ndims; i++) { adims[i] = jl_unbox_long(jl_tupleref(dims, i)); prod = (wideint_t)l * (wideint_t)adims[i]; if (prod > (wideint_t) MAXINTVAL) jl_error("invalid Array dimensions"); l = prod; } #ifdef STORE_ARRAY_LEN a->length = l; #endif } JL_GC_POP(); return a; }
static void array_try_unshare(jl_array_t *a) { if (a->isshared) { if (a->how != 3) jl_error("cannot resize array with shared data"); size_t len = jl_array_nrows(a); array_resize_buffer(a, len, len, a->offset); } }
void restore_signals(void) { sigset_t sset; jl_sigsetset(&sset); sigprocmask(SIG_SETMASK, &sset, 0); #if !defined(HAVE_MACH) if (pthread_mutex_init(&in_signal_lock, NULL) != 0 || pthread_cond_init(&exit_signal_cond, NULL) != 0 || pthread_cond_init(&signal_caught_cond, NULL) != 0) { jl_error("SIGUSR pthread init failed"); } #endif if (pthread_create(&signals_thread, NULL, signal_listener, NULL) != 0) { jl_error("pthread_create(signal_listener) failed"); } }
// run time version of pointerset intrinsic DLLEXPORT void jl_pointerset(jl_value_t *p, jl_value_t *x, jl_value_t *i) { JL_TYPECHK(pointerset, pointer, p); JL_TYPECHK(pointerset, long, i); jl_value_t *ety = jl_tparam0(jl_typeof(p)); if (ety == (jl_value_t*)jl_any_type) { jl_value_t **pp = (jl_value_t**)(jl_unbox_long(p) + (jl_unbox_long(i)-1)*sizeof(void*)); *pp = x; } else { if (!jl_is_datatype(ety)) jl_error("pointerset: invalid pointer"); size_t nb = LLT_ALIGN(jl_datatype_size(ety), ((jl_datatype_t*)ety)->alignment); char *pp = (char*)jl_unbox_long(p) + (jl_unbox_long(i)-1)*nb; if (jl_typeof(x) != ety) jl_error("pointerset: type mismatch in assign"); jl_assign_bits(pp, x); } }
void jl_install_default_signal_handlers(void) { if (signal(SIGFPE, (void (__cdecl *)(int))crt_sig_handler) == SIG_ERR) { jl_error("fatal error: Couldn't set SIGFPE"); } if (signal(SIGILL, (void (__cdecl *)(int))crt_sig_handler) == SIG_ERR) { jl_error("fatal error: Couldn't set SIGILL"); } if (signal(SIGINT, (void (__cdecl *)(int))crt_sig_handler) == SIG_ERR) { jl_error("fatal error: Couldn't set SIGINT"); } if (signal(SIGSEGV, (void (__cdecl *)(int))crt_sig_handler) == SIG_ERR) { jl_error("fatal error: Couldn't set SIGSEGV"); } if (signal(SIGTERM, (void (__cdecl *)(int))crt_sig_handler) == SIG_ERR) { jl_error("fatal error: Couldn't set SIGTERM"); } SetUnhandledExceptionFilter(exception_handler); }
static jl_fptr_t jl_deserialize_fptr(ios_t *s) { int fptr = read_int32(s); if (fptr == 0) return NULL; void **pbp = ptrhash_bp(&id_to_fptr, (void*)(ptrint_t)fptr); if (*pbp == HT_NOTFOUND) jl_error("unknown function pointer ID"); return *(jl_fptr_t*)pbp; }
JL_DLLEXPORT jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data, jl_value_t *_dims, int own_buffer) { jl_ptls_t ptls = jl_get_ptls_states(); size_t elsz, nel = 1; jl_array_t *a; size_t ndims = jl_nfields(_dims); wideint_t prod; assert(is_ntuple_long(_dims)); size_t *dims = (size_t*)_dims; for (size_t i = 0; i < ndims; i++) { prod = (wideint_t)nel * (wideint_t)dims[i]; if (prod > (wideint_t) MAXINTVAL) jl_error("invalid Array dimensions"); nel = prod; } if (__unlikely(ndims == 1)) return jl_ptr_to_array_1d(atype, data, nel, own_buffer); jl_value_t *el_type = jl_tparam0(atype); int isunboxed = store_unboxed(el_type); if (isunboxed) elsz = jl_datatype_size(el_type); else elsz = sizeof(void*); int ndimwords = jl_array_ndimwords(ndims); int tsz = JL_ARRAY_ALIGN(sizeof(jl_array_t) + ndimwords*sizeof(size_t), JL_CACHE_BYTE_ALIGNMENT); a = (jl_array_t*)jl_gc_alloc(ptls, tsz, atype); // No allocation or safepoint allowed after this a->flags.pooled = tsz <= GC_MAX_SZCLASS; a->data = data; #ifdef STORE_ARRAY_LEN a->length = nel; #endif a->elsize = elsz; a->flags.ptrarray = !isunboxed; a->flags.ndims = ndims; a->offset = 0; a->flags.isshared = 1; a->flags.isaligned = 0; if (own_buffer) { a->flags.how = 2; jl_gc_track_malloced_array(ptls, a); jl_gc_count_allocd(nel*elsz + (elsz == 1 ? 1 : 0)); } else { a->flags.how = 0; } assert(ndims != 1); // handled above memcpy(&a->nrows, dims, ndims * sizeof(size_t)); return a; }
jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data, jl_tuple_t *dims, int own_buffer) { size_t i, elsz, nel=1; jl_array_t *a; size_t ndims = jl_tuple_len(dims); wideint_t prod; for(i=0; i < ndims; i++) { prod = (wideint_t)nel * (wideint_t)jl_unbox_long(jl_tupleref(dims, i)); if (prod > (wideint_t) MAXINTVAL) jl_error("invalid Array dimensions"); nel = prod; } jl_value_t *el_type = jl_tparam0(atype); int isunboxed = store_unboxed(el_type); if (isunboxed) elsz = jl_datatype_size(el_type); else elsz = sizeof(void*); int ndimwords = jl_array_ndimwords(ndims); a = allocobj((sizeof(jl_array_t) + ndimwords*sizeof(size_t)+15)&-16); a->type = atype; a->data = data; #ifdef STORE_ARRAY_LEN a->length = nel; #endif a->elsize = elsz; a->ptrarray = !isunboxed; a->ndims = ndims; a->offset = 0; a->isshared = 1; a->isaligned = 0; if (own_buffer) { a->how = 2; jl_gc_track_malloced_array(a); } else { a->how = 0; } if (ndims == 1) { a->nrows = nel; a->maxsize = nel; } else { size_t *adims = &a->nrows; for(i=0; i < ndims; i++) { adims[i] = jl_unbox_long(jl_tupleref(dims, i)); } } return a; }