static void init_history(void) { using_history(); char *home = getenv("HOME"); if (!home) return; if (disable_history) return; asprintf(&history_file, "%s/.julia_history", home); struct stat stat_info; if (!stat(history_file, &stat_info)) { read_history(history_file); for (;;) { HIST_ENTRY *entry = history_get(history_base); if (entry && isspace(entry->line[0])) free_history_entry(history_rem(history_base)); else break; } int i, j, k; for (i=1 ;; i++) { HIST_ENTRY *first = history_get(i); if (!first) break; int length = strlen(first->line)+1; for (j = i+1 ;; j++) { HIST_ENTRY *child = history_get(j); if (!child || !isspace(child->line[0])) break; length += strlen(child->line)+1; } if (j == i+1) continue; first->line = (char*)realloc(first->line, length); char *p = strchr(first->line, '\0'); for (k = i+1; k < j; k++) { *p = '\n'; p = stpcpy(p+1, history_get(i+1)->line); free_history_entry(history_rem(i+1)); } } } else if (errno == ENOENT) { write_history(history_file); } else { ios_printf(ios_stderr, "history file error: %s\n", strerror(errno)); exit(1); } }
static void show_type(jl_value_t *t) { ios_t *s = jl_current_output_stream(); if (jl_is_func_type(t)) { if (t == (jl_value_t*)jl_any_func) { ios_printf(s, "Function"); } else { jl_show((jl_value_t*)((jl_func_type_t*)t)->from); ios_write(s, "-->", 3); jl_show((jl_value_t*)((jl_func_type_t*)t)->to); } } else if (jl_is_union_type(t)) { if (t == (jl_value_t*)jl_bottom_type) { ios_write(s, "None", 4); } else if (t == jl_top_type) { ios_write(s, "Top", 3); } else { ios_write(s, "Union", 5); show_tuple(((jl_uniontype_t*)t)->types, '(', ')', 0); } } else if (jl_is_seq_type(t)) { jl_show(jl_tparam0(t)); ios_write(s, "...", 3); } else { assert(jl_is_some_tag_type(t)); jl_tag_type_t *tt = (jl_tag_type_t*)t; ios_puts(tt->name->name->name, s); jl_tuple_t *p = tt->parameters; if (p->length > 0) show_tuple(p, '{', '}', 0); } }
// locate a file in the search path // fpath needs to be freed if != fname char *jl_find_file_in_path(const char *fname) { char *fpath = (char*)fname; int fid = open (fpath, O_RDONLY); // try adding julia home if (fid == -1 && julia_home && fname[0] != '/') { asprintf(&fpath, "%s/%s", julia_home, fname); fid = open (fpath, O_RDONLY); } if (fid == -1) { if (fpath != fname) free(fpath); if (jl_errorexception_type == NULL) { ios_printf(ios_stderr, "could not open file %s\n", fname); exit(1); } else { jl_errorf("could not open file %s", fname); } } close(fid); return fpath; }
void sigdie_handler(int sig, siginfo_t *info, void *context) { if (sig != SIGINFO) { sigset_t sset; uv_tty_reset_mode(); sigfillset(&sset); sigprocmask(SIG_UNBLOCK, &sset, NULL); signal(sig, SIG_DFL); } ios_printf(ios_stderr,"\nsignal (%d): %s\n", sig, strsignal(sig)); #ifdef __APPLE__ bt_size = rec_backtrace_ctx(bt_data, MAX_BT_SIZE, (bt_context_t)&((ucontext64_t*)context)->uc_mcontext64->__ss); #else bt_size = rec_backtrace_ctx(bt_data, MAX_BT_SIZE, (ucontext_t*)context); #endif jlbacktrace(); if (sig != SIGSEGV && sig != SIGBUS && sig != SIGILL && sig != SIGINFO) { raise(sig); } }
void __cdecl crt_sig_handler(int sig, int num) { switch (sig) { case SIGFPE: fpreset(); signal(SIGFPE, (void (__cdecl *)(int))crt_sig_handler); switch(num) { case _FPE_INVALID: case _FPE_OVERFLOW: case _FPE_UNDERFLOW: default: jl_errorf("Unexpected FPE Error 0x%X", num); break; case _FPE_ZERODIVIDE: jl_throw(jl_diverror_exception); break; } break; case SIGINT: signal(SIGINT, (void (__cdecl *)(int))crt_sig_handler); if (exit_on_sigint) jl_exit(0); if (jl_defer_signal) { jl_signal_pending = sig; } else { jl_signal_pending = 0; jl_throw(jl_interrupt_exception); } break; default: // SIGSEGV, (SSIGTERM, IGILL) ios_printf(ios_stderr,"\nsignal (%d): %s\n", sig, strsignal(sig)); bt_size = rec_backtrace(bt_data, MAX_BT_SIZE); jlbacktrace(); raise(sig); } }
void parse_opts(int *argcp, char ***argvp) { static char* shortopts = "+H:T:hJ:"; static struct option longopts[] = { { "home", required_argument, 0, 'H' }, { "tab", required_argument, 0, 'T' }, { "build", required_argument, 0, 'b' }, { "lisp", no_argument, &lisp_prompt, 1 }, { "help", no_argument, 0, 'h' }, { "sysimage", required_argument, 0, 'J' }, { 0, 0, 0, 0 } }; int c; opterr = 0; int imagepathspecified=0; image_file = JL_SYSTEM_IMAGE_PATH; int skip = 0; int lastind = optind; while ((c = getopt_long(*argcp,*argvp,shortopts,longopts,0)) != -1) { switch (c) { case 0: break; case '?': if (optind != lastind) skip++; lastind = optind; break; case 'H': julia_home = strdup(optarg); break; case 'T': // TODO: more robust error checking. tab_width = atoi(optarg); break; case 'b': build_mode = strdup(optarg); if (!imagepathspecified) image_file = NULL; break; case 'J': image_file = strdup(optarg); imagepathspecified = 1; break; case 'h': printf("%s%s", usage, opts); exit(0); default: ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c); ios_printf(ios_stderr, "This is a bug, please report it.\n"); exit(1); } } if (!julia_home) { julia_home = getenv("JULIA_HOME"); if (julia_home) { julia_home = strdup(julia_home); } else { char *julia_path = (char*)malloc(PATH_MAX); size_t path_size = PATH_MAX; uv_exepath(julia_path, &path_size); julia_home = strdup(dirname(julia_path)); free(julia_path); } } optind -= skip; *argvp += optind; *argcp -= optind; if (image_file==NULL && *argcp > 0) { if (strcmp((*argvp)[0], "-")) { program = (*argvp)[0]; } } if (image_file) { if (image_file[0] != PATHSEP) { struct stat stbuf; char path[512]; if (!imagepathspecified) { // build time path relative to JULIA_HOME snprintf(path, sizeof(path), "%s%s", julia_home, PATHSEPSTRING JL_SYSTEM_IMAGE_PATH); image_file = strdup(path); } else if (jl_stat(image_file, (char*)&stbuf) != 0) { // otherwise try julia_home/../lib/julia/%s snprintf(path, sizeof(path), "%s%s%s", julia_home, PATHSEPSTRING ".." PATHSEPSTRING "lib" PATHSEPSTRING "julia" PATHSEPSTRING, image_file); image_file = strdup(path); } } } }
static LONG WINAPI _exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo, int in_ctx) { if (ExceptionInfo->ExceptionRecord->ExceptionFlags == 0) { switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { case EXCEPTION_INT_DIVIDE_BY_ZERO: fpreset(); if (!in_ctx) jl_throw(jl_diverror_exception); jl_throw_in_ctx(jl_diverror_exception, ExceptionInfo->ContextRecord, 0); return EXCEPTION_CONTINUE_EXECUTION; case EXCEPTION_STACK_OVERFLOW: bt_size = 0; if (!in_ctx) jl_rethrow_other(jl_stackovf_exception); jl_throw_in_ctx(jl_stackovf_exception, ExceptionInfo->ContextRecord, 0); return EXCEPTION_CONTINUE_EXECUTION; } ios_puts("Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.\nException: ", ios_stderr); switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { case EXCEPTION_ACCESS_VIOLATION: ios_puts("EXCEPTION_ACCESS_VIOLATION", ios_stderr); break; case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: ios_puts("EXCEPTION_ARRAY_BOUNDS_EXCEEDED", ios_stderr); break; case EXCEPTION_BREAKPOINT: ios_puts("EXCEPTION_BREAKPOINT", ios_stderr); break; case EXCEPTION_DATATYPE_MISALIGNMENT: ios_puts("EXCEPTION_DATATYPE_MISALIGNMENT", ios_stderr); break; case EXCEPTION_FLT_DENORMAL_OPERAND: ios_puts("EXCEPTION_FLT_DENORMAL_OPERAND", ios_stderr); break; case EXCEPTION_FLT_DIVIDE_BY_ZERO: ios_puts("EXCEPTION_FLT_DIVIDE_BY_ZERO", ios_stderr); break; case EXCEPTION_FLT_INEXACT_RESULT: ios_puts("EXCEPTION_FLT_INEXACT_RESULT", ios_stderr); break; case EXCEPTION_FLT_INVALID_OPERATION: ios_puts("EXCEPTION_FLT_INVALID_OPERATION", ios_stderr); break; case EXCEPTION_FLT_OVERFLOW: ios_puts("EXCEPTION_FLT_OVERFLOW", ios_stderr); break; case EXCEPTION_FLT_STACK_CHECK: ios_puts("EXCEPTION_FLT_STACK_CHECK", ios_stderr); break; case EXCEPTION_FLT_UNDERFLOW: ios_puts("EXCEPTION_FLT_UNDERFLOW", ios_stderr); break; case EXCEPTION_ILLEGAL_INSTRUCTION: ios_puts("EXCEPTION_ILLEGAL_INSTRUCTION", ios_stderr); break; case EXCEPTION_IN_PAGE_ERROR: ios_puts("EXCEPTION_IN_PAGE_ERROR", ios_stderr); break; case EXCEPTION_INT_DIVIDE_BY_ZERO: ios_puts("EXCEPTION_INT_DIVIDE_BY_ZERO", ios_stderr); break; case EXCEPTION_INT_OVERFLOW: ios_puts("EXCEPTION_INT_OVERFLOW", ios_stderr); break; case EXCEPTION_INVALID_DISPOSITION: ios_puts("EXCEPTION_INVALID_DISPOSITION", ios_stderr); break; case EXCEPTION_NONCONTINUABLE_EXCEPTION: ios_puts("EXCEPTION_NONCONTINUABLE_EXCEPTION", ios_stderr); break; case EXCEPTION_PRIV_INSTRUCTION: ios_puts("EXCEPTION_PRIV_INSTRUCTION", ios_stderr); break; case EXCEPTION_SINGLE_STEP: ios_puts("EXCEPTION_SINGLE_STEP", ios_stderr); break; case EXCEPTION_STACK_OVERFLOW: ios_puts("EXCEPTION_STACK_OVERFLOW", ios_stderr); break; default: ios_puts("UNKNOWN", ios_stderr); break; } ios_printf(ios_stderr," at 0x%Ix -- ", (size_t)ExceptionInfo->ExceptionRecord->ExceptionAddress); gdblookup((ptrint_t)ExceptionInfo->ExceptionRecord->ExceptionAddress); bt_size = rec_backtrace_ctx(bt_data, MAX_BT_SIZE, ExceptionInfo->ContextRecord); jlbacktrace(); } return EXCEPTION_CONTINUE_SEARCH; }
// for bootstrap DLLEXPORT void jl_print_int64(int64_t i) { ios_t *s = jl_current_output_stream(); ios_printf(s, "%lld", i); }
void parse_opts(int *argcp, char ***argvp) { static char* shortopts = "+H:T:bhJ:"; static struct option longopts[] = { { "home", required_argument, 0, 'H' }, { "tab", required_argument, 0, 'T' }, { "bare", no_argument, 0, 'b' }, { "lisp", no_argument, &lisp_prompt, 1 }, { "help", no_argument, 0, 'h' }, { "sysimage", required_argument, 0, 'J' }, { 0, 0, 0, 0 } }; int c; opterr = 0; int ind = 1; while ((c = getopt_long(*argcp,*argvp,shortopts,longopts,0)) != -1) { switch (c) { case 0: break; case '?': break; case 'H': julia_home = strdup(optarg); ind+=2; break; case 'T': // TODO: more robust error checking. tab_width = atoi(optarg); ind+=2; break; case 'b': image_file = NULL; ind+=1; break; case 'J': image_file = optarg; ind+=2; break; case 'h': printf("%s%s", usage, opts); exit(0); default: ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c); ios_printf(ios_stderr, "This is a bug, please report it.\n"); exit(1); } } if (!julia_home) { julia_home = getenv("JULIA_HOME"); if (julia_home) { julia_home = strdup(julia_home); } else { char *julia_path = (char*)malloc(PATH_MAX); get_exename(julia_path, PATH_MAX); julia_home = strdup(dirname(julia_path)); free(julia_path); } } *argvp += ind; *argcp -= ind; if (image_file==NULL && *argcp > 0) { if (strcmp((*argvp)[0], "-")) { program = (*argvp)[0]; } } }
static LONG WINAPI exception_handler(struct _EXCEPTION_POINTERS *ExceptionInfo) { if (ExceptionInfo->ExceptionRecord->ExceptionFlags == 0) { switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { case EXCEPTION_STACK_OVERFLOW: #if defined(_CPU_X86_64_) ExceptionInfo->ContextRecord->Rip = (DWORD64)&win_raise_exception; ExceptionInfo->ContextRecord->Rcx = (DWORD64)jl_stackovf_exception; ExceptionInfo->ContextRecord->Rsp &= (DWORD64)-16; ExceptionInfo->ContextRecord->Rsp -= 8; //fix up the stack pointer -- this seems to be correct by observation #elif defined(_CPU_X86_) ExceptionInfo->ContextRecord->Eip = (DWORD)&win_raise_exception; ExceptionInfo->ContextRecord->Ecx = (DWORD)jl_stackovf_exception; ExceptionInfo->ContextRecord->Esp &= (DWORD)-16; ExceptionInfo->ContextRecord->Esp -= 4; //fix up the stack pointer #else #error WIN16 not supported :P #endif return EXCEPTION_CONTINUE_EXECUTION; default: ios_puts("Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.\nException: ", ios_stderr); switch (ExceptionInfo->ExceptionRecord->ExceptionCode) { case EXCEPTION_ACCESS_VIOLATION: ios_puts("EXCEPTION_ACCESS_VIOLATION", ios_stderr); break; case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: ios_puts("EXCEPTION_ARRAY_BOUNDS_EXCEEDED", ios_stderr); break; case EXCEPTION_BREAKPOINT: ios_puts("EXCEPTION_BREAKPOINT", ios_stderr); break; case EXCEPTION_DATATYPE_MISALIGNMENT: ios_puts("EXCEPTION_DATATYPE_MISALIGNMENT", ios_stderr); break; case EXCEPTION_FLT_DENORMAL_OPERAND: ios_puts("EXCEPTION_FLT_DENORMAL_OPERAND", ios_stderr); break; case EXCEPTION_FLT_DIVIDE_BY_ZERO: ios_puts("EXCEPTION_FLT_DIVIDE_BY_ZERO", ios_stderr); break; case EXCEPTION_FLT_INEXACT_RESULT: ios_puts("EXCEPTION_FLT_INEXACT_RESULT", ios_stderr); break; case EXCEPTION_FLT_INVALID_OPERATION: ios_puts("EXCEPTION_FLT_INVALID_OPERATION", ios_stderr); break; case EXCEPTION_FLT_OVERFLOW: ios_puts("EXCEPTION_FLT_OVERFLOW", ios_stderr); break; case EXCEPTION_FLT_STACK_CHECK: ios_puts("EXCEPTION_FLT_STACK_CHECK", ios_stderr); break; case EXCEPTION_FLT_UNDERFLOW: ios_puts("EXCEPTION_FLT_UNDERFLOW", ios_stderr); break; case EXCEPTION_ILLEGAL_INSTRUCTION: ios_puts("EXCEPTION_ILLEGAL_INSTRUCTION", ios_stderr); break; case EXCEPTION_IN_PAGE_ERROR: ios_puts("EXCEPTION_IN_PAGE_ERROR", ios_stderr); break; case EXCEPTION_INT_DIVIDE_BY_ZERO: ios_puts("EXCEPTION_INT_DIVIDE_BY_ZERO", ios_stderr); break; case EXCEPTION_INT_OVERFLOW: ios_puts("EXCEPTION_INT_OVERFLOW", ios_stderr); break; case EXCEPTION_INVALID_DISPOSITION: ios_puts("EXCEPTION_INVALID_DISPOSITION", ios_stderr); break; case EXCEPTION_NONCONTINUABLE_EXCEPTION: ios_puts("EXCEPTION_NONCONTINUABLE_EXCEPTION", ios_stderr); break; case EXCEPTION_PRIV_INSTRUCTION: ios_puts("EXCEPTION_PRIV_INSTRUCTION", ios_stderr); break; case EXCEPTION_SINGLE_STEP: ios_puts("EXCEPTION_SINGLE_STEP", ios_stderr); break; case EXCEPTION_STACK_OVERFLOW: ios_puts("EXCEPTION_STACK_OVERFLOW", ios_stderr); break; default: ios_puts("UNKNOWN", ios_stderr); break; } ios_printf(ios_stderr," at 0x%Ix -- ", (size_t)ExceptionInfo->ExceptionRecord->ExceptionAddress); gdblookup((ptrint_t)ExceptionInfo->ExceptionRecord->ExceptionAddress); bt_size = rec_backtrace_ctx(bt_data, MAX_BT_SIZE, ExceptionInfo->ContextRecord); jlbacktrace(); break; } } return EXCEPTION_CONTINUE_SEARCH; }
DLLEXPORT void jl_restore_system_image(char *fname) { ios_t f; char *fpath = jl_find_file_in_path(fname); if (ios_file(&f, fpath, 1, 0, 0, 0) == NULL) { ios_printf(ios_stderr, "system image file not found\n"); exit(1); } #ifdef JL_GC_MARKSWEEP int en = jl_gc_is_enabled(); jl_gc_disable(); #endif tagtype_list = jl_alloc_cell_1d(0); jl_array_type->env = jl_deserialize_value(&f); jl_base_module = (jl_module_t*)jl_deserialize_value(&f); jl_current_module = (jl_module_t*)jl_deserialize_value(&f); jl_system_module = (jl_module_t*)jl_get_global(jl_base_module, jl_symbol("System")); jl_array_t *idtl = (jl_array_t*)jl_deserialize_value(&f); // rehash IdTables for(int i=0; i < idtl->length; i++) { jl_value_t *v = jl_cellref(idtl, i); jl_idtable_rehash(&((jl_array_t**)v)[1], ((jl_array_t**)v)[1]->length); } // cache builtin parametric types for(int i=0; i < tagtype_list->length; i++) { jl_value_t *v = jl_cellref(tagtype_list, i); uint32_t uid=0; if (jl_is_struct_type(v)) uid = ((jl_struct_type_t*)v)->uid; else if (jl_is_bits_type(v)) uid = ((jl_bits_type_t*)v)->uid; jl_cache_type_((jl_tag_type_t*)v); if (jl_is_struct_type(v)) ((jl_struct_type_t*)v)->uid = uid; else if (jl_is_bits_type(v)) ((jl_bits_type_t*)v)->uid = uid; } jl_get_builtin_hooks(); jl_get_system_hooks(); jl_boot_file_loaded = 1; jl_typeinf_func = (jl_function_t*)jl_get_global(jl_system_module, jl_symbol("typeinf_ext")); jl_init_box_caches(); //jl_deserialize_finalizers(&f); jl_set_t_uid_ctr(read_int32(&f)); jl_set_gs_ctr(read_int32(&f)); htable_reset(&backref_table, 0); ios_t ss; ios_mem(&ss, 0); ios_copyuntil(&ss, &f, '\0'); ios_close(&f); if (fpath != fname) free(fpath); #ifdef JL_GC_MARKSWEEP if (en) jl_gc_enable(); #endif // TODO: there is no exception handler here! jl_load_file_string(ss.buf); ios_close(&ss); }
void parse_opts(int *argcp, char ***argvp) { static char* shortopts = "+H:T:hJ:"; static struct option longopts[] = { { "home", required_argument, 0, 'H' }, { "tab", required_argument, 0, 'T' }, { "build", required_argument, 0, 'b' }, { "lisp", no_argument, &lisp_prompt, 1 }, { "help", no_argument, 0, 'h' }, { "sysimage", required_argument, 0, 'J' }, { "code-coverage", optional_argument, 0, 'c' }, { "track-allocation",required_argument, 0, 'm' }, { "check-bounds", required_argument, 0, 300 }, { "int-literals", required_argument, 0, 301 }, { "dump-bitcode", required_argument, 0, 302 }, { "compile", required_argument, 0, 303 }, { 0, 0, 0, 0 } }; int c; opterr = 0; int imagepathspecified=0; image_file = system_image; int skip = 0; int lastind = optind; while ((c = getopt_long(*argcp,*argvp,shortopts,longopts,0)) != -1) { switch (c) { case 0: break; case '?': if (optind != lastind) skip++; lastind = optind; break; case 'H': julia_home = strdup(optarg); break; case 'b': jl_compileropts.build_path = strdup(optarg); if (!imagepathspecified) image_file = NULL; break; case 'J': image_file = strdup(optarg); imagepathspecified = 1; break; case 'h': printf("%s%s", usage, opts); exit(0); case 'c': if (optarg != NULL) { if (!strcmp(optarg,"user")) codecov = JL_LOG_USER; else if (!strcmp(optarg,"all")) codecov = JL_LOG_ALL; else if (!strcmp(optarg,"none")) codecov = JL_LOG_NONE; break; } else codecov = JL_LOG_USER; break; case 'm': if (optarg != NULL) { if (!strcmp(optarg,"user")) malloclog = JL_LOG_USER; else if (!strcmp(optarg,"all")) malloclog = JL_LOG_ALL; else if (!strcmp(optarg,"none")) malloclog = JL_LOG_NONE; break; } case 300: if (!strcmp(optarg,"yes")) jl_compileropts.check_bounds = JL_COMPILEROPT_CHECK_BOUNDS_ON; else if (!strcmp(optarg,"no")) jl_compileropts.check_bounds = JL_COMPILEROPT_CHECK_BOUNDS_OFF; break; case 301: if (!strcmp(optarg,"32")) jl_compileropts.int_literals = 32; else if (!strcmp(optarg,"64")) jl_compileropts.int_literals = 64; else { ios_printf(ios_stderr, "julia: invalid integer literal size (%s)\n", optarg); exit(1); } break; case 302: if (!strcmp(optarg,"yes")) jl_compileropts.dumpbitcode = JL_COMPILEROPT_DUMPBITCODE_ON; else if (!strcmp(optarg,"no")) jl_compileropts.dumpbitcode = JL_COMPILEROPT_DUMPBITCODE_OFF; break; case 303: if (!strcmp(optarg,"yes")) jl_compileropts.compile_enabled = 1; else if (!strcmp(optarg,"no")) jl_compileropts.compile_enabled = 0; else if (!strcmp(optarg,"all")) jl_compileropts.compile_enabled = 2; else { ios_printf(ios_stderr, "julia: invalid argument to --compile (%s)\n", optarg); exit(1); } break; default: ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c); ios_printf(ios_stderr, "This is a bug, please report it.\n"); exit(1); } } jl_compileropts.code_coverage = codecov; jl_compileropts.malloc_log = malloclog; if (!julia_home) { julia_home = getenv("JULIA_HOME"); if (julia_home) { julia_home = strdup(julia_home); } else { char *julia_path = (char*)malloc(PATH_MAX); size_t path_size = PATH_MAX; uv_exepath(julia_path, &path_size); julia_home = strdup(dirname(julia_path)); free(julia_path); } } optind -= skip; *argvp += optind; *argcp -= optind; if (image_file==NULL && *argcp > 0) { if (strcmp((*argvp)[0], "-")) { program = (*argvp)[0]; } } if (image_file) { if (image_file[0] != PATHSEP) { uv_stat_t stbuf; char path[512]; if (!imagepathspecified) { // build time path relative to JULIA_HOME snprintf(path, sizeof(path), "%s%s%s", julia_home, PATHSEPSTRING, system_image); image_file = strdup(path); } else if (jl_stat(image_file, (char*)&stbuf) != 0) { // otherwise try julia_home/../lib/julia/%s snprintf(path, sizeof(path), "%s%s%s", julia_home, PATHSEPSTRING ".." PATHSEPSTRING "lib" PATHSEPSTRING "julia" PATHSEPSTRING, image_file); image_file = strdup(path); } } } }
void parse_opts(int *argcp, char ***argvp) { static char* shortopts = "+H:hJ:C:O"; static struct option longopts[] = { { "home", required_argument, 0, 'H' }, { "build", required_argument, 0, 'b' }, { "lisp", no_argument, &lisp_prompt, 1 }, { "help", no_argument, 0, 'h' }, { "sysimage", required_argument, 0, 'J' }, { "code-coverage", optional_argument, 0, 'c' }, { "cpu-target", required_argument, 0, 'C' }, { "track-allocation",required_argument, 0, 'm' }, { "check-bounds", required_argument, 0, 300 }, { "optimize", no_argument, 0, 'O' }, { "int-literals", required_argument, 0, 301 }, { "dump-bitcode", required_argument, 0, 302 }, { "compile", required_argument, 0, 303 }, { "depwarn", required_argument, 0, 304 }, { "inline", required_argument, 0, 305 }, { 0, 0, 0, 0 } }; int c; opterr = 0; int skip = 0; int lastind = optind; while ((c = getopt_long(*argcp,*argvp,shortopts,longopts,0)) != -1) { switch (c) { case 0: break; case '?': if (optind != lastind) skip++; lastind = optind; break; case 'H': jl_compileropts.julia_home = strdup(optarg); break; case 'b': jl_compileropts.build_path = strdup(optarg); if (!imagepathspecified) jl_compileropts.image_file = NULL; break; case 'J': jl_compileropts.image_file = strdup(optarg); imagepathspecified = 1; break; case 'C': jl_compileropts.cpu_target = strdup(optarg); break; case 'h': ios_printf(ios_stdout, "%s%s", usage, opts); exit(0); case 'O': jl_compileropts.opt_level = 1; break; case 'c': if (optarg != NULL) { if (!strcmp(optarg,"user")) codecov = JL_LOG_USER; else if (!strcmp(optarg,"all")) codecov = JL_LOG_ALL; else if (!strcmp(optarg,"none")) codecov = JL_LOG_NONE; break; } else { codecov = JL_LOG_USER; } break; case 'm': if (optarg != NULL) { if (!strcmp(optarg,"user")) malloclog = JL_LOG_USER; else if (!strcmp(optarg,"all")) malloclog = JL_LOG_ALL; else if (!strcmp(optarg,"none")) malloclog = JL_LOG_NONE; break; } case 300: if (!strcmp(optarg,"yes")) jl_compileropts.check_bounds = JL_COMPILEROPT_CHECK_BOUNDS_ON; else if (!strcmp(optarg,"no")) jl_compileropts.check_bounds = JL_COMPILEROPT_CHECK_BOUNDS_OFF; break; case 301: if (!strcmp(optarg,"32")) jl_compileropts.int_literals = 32; else if (!strcmp(optarg,"64")) jl_compileropts.int_literals = 64; else { ios_printf(ios_stderr, "julia: invalid integer literal size (%s)\n", optarg); exit(1); } break; case 302: if (!strcmp(optarg,"yes")) jl_compileropts.dumpbitcode = JL_COMPILEROPT_DUMPBITCODE_ON; else if (!strcmp(optarg,"no")) jl_compileropts.dumpbitcode = JL_COMPILEROPT_DUMPBITCODE_OFF; break; case 303: if (!strcmp(optarg,"yes")) jl_compileropts.compile_enabled = 1; else if (!strcmp(optarg,"no")) jl_compileropts.compile_enabled = 0; else if (!strcmp(optarg,"all")) jl_compileropts.compile_enabled = 2; else { ios_printf(ios_stderr, "julia: invalid argument to --compile (%s)\n", optarg); exit(1); } break; case 304: if (!strcmp(optarg,"yes")) jl_compileropts.depwarn = 1; else if (!strcmp(optarg,"no")) jl_compileropts.depwarn = 0; else { ios_printf(ios_stderr, "julia: invalid argument to --depwarn (%s)\n", optarg); exit(1); } break; case 305: /* inline */ if (!strcmp(optarg,"yes")) jl_compileropts.can_inline = 1; else if (!strcmp(optarg,"no")) jl_compileropts.can_inline = 0; else { ios_printf(ios_stderr, "julia: invalid argument to --inline (%s)\n", optarg); exit(1); } break; default: ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c); ios_printf(ios_stderr, "This is a bug, please report it.\n"); exit(1); } } jl_compileropts.code_coverage = codecov; jl_compileropts.malloc_log = malloclog; optind -= skip; *argvp += optind; *argcp -= optind; if (jl_compileropts.image_file==NULL && *argcp > 0) { if (strcmp((*argvp)[0], "-")) { program = (*argvp)[0]; } } }
void julia_init(char *imageFile) { jl_page_size = sysconf(_SC_PAGESIZE); jl_find_stack_bottom(); jl_dl_handle = jl_load_dynamic_library(NULL); #ifdef JL_GC_MARKSWEEP jl_gc_init(); jl_gc_disable(); #endif jl_init_frontend(); jl_init_types(); jl_init_tasks(jl_stack_lo, jl_stack_hi-jl_stack_lo); jl_init_codegen(); jl_an_empty_cell = (jl_value_t*)jl_alloc_cell_1d(0); jl_init_serializer(); if (!imageFile) { jl_core_module = jl_new_module(jl_symbol("Core")); jl_current_module = jl_core_module; jl_init_intrinsic_functions(); jl_init_primitives(); jl_load("src/boot.jl"); jl_get_builtin_hooks(); jl_boot_file_loaded = 1; jl_init_box_caches(); } if (imageFile) { JL_TRY { jl_restore_system_image(imageFile); } JL_CATCH { ios_printf(ios_stderr, "error during init:\n"); jl_show(jl_exception_in_transit); ios_printf(ios_stdout, "\n"); exit(1); } } struct sigaction actf; memset(&actf, 0, sizeof(struct sigaction)); sigemptyset(&actf.sa_mask); actf.sa_handler = fpe_handler; actf.sa_flags = 0; if (sigaction(SIGFPE, &actf, NULL) < 0) { ios_printf(ios_stderr, "sigaction: %s\n", strerror(errno)); exit(1); } stack_t ss; ss.ss_flags = 0; ss.ss_size = SIGSTKSZ; ss.ss_sp = malloc(ss.ss_size); if (sigaltstack(&ss, NULL) < 0) { ios_printf(ios_stderr, "sigaltstack: %s\n", strerror(errno)); exit(1); } struct sigaction act; memset(&act, 0, sizeof(struct sigaction)); sigemptyset(&act.sa_mask); act.sa_sigaction = segv_handler; act.sa_flags = SA_ONSTACK | SA_SIGINFO; if (sigaction(SIGSEGV, &act, NULL) < 0) { ios_printf(ios_stderr, "sigaction: %s\n", strerror(errno)); exit(1); } #ifdef JL_GC_MARKSWEEP jl_gc_enable(); #endif }
void *jl_load_dynamic_library(char *fname) { module_handle_t handle; char *modname, *ext; char path[PATHBUF]; int i; #ifdef WIN32 LPVOID lpMsgBuf; DWORD dw; #endif modname = fname; #ifndef WIN32 if (modname == NULL) { return (void*)dlopen(NULL, RTLD_NOW); } char *cwd; for(i=0; i < N_EXTENSIONS; i++) { ext = extensions[i]; path[0] = '\0'; handle = NULL; if (modname[0] != '/') { cwd = getcwd(path, PATHBUF); if (cwd != NULL) { /* first, try load from current directory */ strncat(path, "/", PATHBUF-1-strlen(path)); strncat(path, modname, PATHBUF-1-strlen(path)); strncat(path, ext, PATHBUF-1-strlen(path)); handle = dlopen(path, RTLD_NOW); if (handle != NULL) return handle; } if (julia_home) { /* now try julia home */ strncpy(path, julia_home, PATHBUF-1); strncat(path, "/", PATHBUF-1-strlen(path)); strncat(path, modname, PATHBUF-1-strlen(path)); strncat(path, ext, PATHBUF-1-strlen(path)); handle = dlopen(path, RTLD_NOW); if (handle != NULL) return handle; /* now try julia_home/lib */ strncpy(path, julia_home, PATHBUF-1); strncat(path, "/lib/", PATHBUF-1-strlen(path)); strncat(path, modname, PATHBUF-1-strlen(path)); strncat(path, ext, PATHBUF-1-strlen(path)); handle = dlopen(path, RTLD_NOW); if (handle != NULL) return handle; } } /* try loading from standard library path */ strncpy(path, modname, PATHBUF-1); strncat(path, ext, PATHBUF-1-strlen(path)); handle = dlopen(path, RTLD_NOW); if (handle != NULL) return handle; } assert(handle == NULL); ios_printf(ios_stderr, "%s\n", dlerror()); jl_errorf("could not load module %s", fname); #else if (modname == NULL) { return (void*)GetModuleHandle(NULL); } for(i=0; i < N_EXTENSIONS; i++) { ext = extensions[i]; path[0] = '\0'; handle = NULL; if (julia_home) { strncpy(path, julia_home, PATHBUF-1); strncat(path, "\\", PATHBUF-1-strlen(path)); strncat(path, modname, PATHBUF-1-strlen(path)); strncat(path, ext, PATHBUF-1-strlen(path)); handle = LoadLibrary(path); if (handle != NULL) return handle; } strncpy(path, modname, PATHBUF-1); strncat(path, ext, PATHBUF-1-strlen(path)); handle = LoadLibrary(path); if (handle != NULL) return handle; } assert(handle == NULL); dw = GetLastError(); FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); jl_errorf("could not load module %s: (%d) %s", fname, dw, lpMsgBuf); #endif return NULL; }