STATIC void mp_reset(void) { mp_stack_set_top((void*)0x40000000); mp_stack_set_limit(8192); mp_hal_init(); gc_init(heap, heap + sizeof(heap)); mp_init(); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script) mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib)); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_)); mp_obj_list_init(mp_sys_argv, 0); #if MICROPY_VFS_FAT memset(MP_STATE_PORT(fs_user_mount), 0, sizeof(MP_STATE_PORT(fs_user_mount))); #endif MP_STATE_PORT(mp_kbd_exception) = mp_obj_new_exception(&mp_type_KeyboardInterrupt); MP_STATE_PORT(term_obj) = MP_OBJ_NULL; MP_STATE_PORT(dupterm_arr_obj) = MP_OBJ_NULL; pin_init0(); readline_init0(); dupterm_task_init(); #if MICROPY_MODULE_FROZEN pyexec_frozen_module("_boot.py"); pyexec_file("boot.py"); pyexec_file("main.py"); #endif }
vm_t *vm_new() { vm_t *vm; vm = malloc(sizeof(struct vm)); if (!vm) return NULL; memset(vm, '\0', sizeof(struct vm)); // Allocate 64k for code vm->code = malloc(0xFFFF); if (vm->code == NULL) { return NULL; } memset(vm->code, '\0', 0xFFFF); vm->code_size = 0; // Allocate a 64k heap GCState* gc = gc_init(0xFFFF * 2); vm->gc = gc; vm->function_names = strings_new(); vm->intern_pool = strings_new(); vm->ip = 0; vm->current_frame = 0; vm->current_function = NULL; memset(vm->functions, NO_FUNCTION, MAX_FUNCTIONS * sizeof(uint64_t)); opcode_init(vm); return vm; }
inline void do_str(const char *src) { gc_init(heap, (char*)heap + HEAP_SIZE); mp_init(); mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); if (lex == NULL) { tt_abort_msg("Lexer initialization error"); } nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { qstr source_name = lex->source_name; mp_parse_tree_t parse_tree = mp_parse(lex, MP_PARSE_FILE_INPUT); mp_obj_t module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, true); mp_call_function_0(module_fun); nlr_pop(); } else { mp_obj_t exc = (mp_obj_t)nlr.ret_val; if (mp_obj_is_subclass_fast(mp_obj_get_type(exc), &mp_type_SystemExit)) { // Assume that sys.exit() is called to skip the test. // TODO: That can be always true, we should set up convention to // use specific exit code as skip indicator. tinytest_set_test_skipped_(); goto end; } mp_obj_print_exception(&mp_plat_print, exc); tt_abort_msg("Uncaught exception"); } end: mp_deinit(); }
Test(data, initializer_type_to_array) { struct type **types; gc_t gc = gc_init(); cr_assert_eq(initializer_type_to_array, itta); types = itta(stt{ construct_type(tid_integral, NULL, &gc), construct_type(tid_real, NULL, &gc), }, 2, &gc); cr_assert_eq(types[0]->single, tid_integral); cr_assert_null(types[0]->multiple); cr_assert_eq(types[1]->single, tid_real); cr_assert_null(types[1]->multiple); cr_assert_null(types[2]); types = itta(stt{ construct_type(tid_real, NULL, &gc), construct_type(tid_integral, NULL, &gc), construct_type(tid_tuple, itta( stt{construct_type(tid_string, NULL, &gc)}, 1, &gc ), &gc), }, 3, &gc); cr_assert_eq(types[0]->single, tid_real); cr_assert_null(types[0]->multiple); cr_assert_eq(types[1]->single, tid_integral); cr_assert_null(types[1]->multiple); cr_assert_eq(types[2]->single, tid_tuple); cr_assert_eq(types[2]->multiple[0]->single, tid_string); cr_assert_null(types[2]->multiple[0]->multiple); cr_assert_null(types[2]->multiple[1]); cr_assert_null(types[3]); gc_clean(&gc); }
int main() { gc_init(); invoke_method("test1.so","method1"); invoke_method("test.so","test"); gc_free(); return 0; }
int main(int argc, char **argv) { //int stack_dummy; //stack_top = (char*)&stack_dummy; uint32_t sp = gc_helper_get_sp(); gc_collect_init (sp); #if MICROPY_ENABLE_GC gc_init(heap, heap + sizeof(heap)); #endif mp_init(); pin_init0(); mp_irq_init0(); #if MICROPY_REPL_EVENT_DRIVEN pyexec_event_repl_init(); for (;;) { int c = mp_hal_stdin_rx_chr(); if (pyexec_event_repl_process_char(c)) { break; } } #else pyexec_friendly_repl(); #endif //do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT); //do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT); mp_deinit(); return 0; }
//----------------------------------------------------------------------------- // Mach: // ---------------------------------------------------------------------------- struct ymd_mach *ymd_init() { struct ymd_mach *vm = calloc(1, sizeof(*vm)); if (!vm) return NULL; // Basic memory functions: vm->zalloc = default_zalloc; vm->free = default_free; vm->tick = 0; // Init gc: gc_init(vm, GC_THESHOLD); // Init global map: kpool_init(vm); vm->global = hmap_new(vm, -1); vm->global->marked = GC_FIXED; // global is a fixed object. // Init context vm_init_context(vm); // Load symbols // `__loaded__' variable: for all of loaded chunks ymd_hmap(ioslate(vm), 1); ymd_putg(ioslate(vm), "__loaded__"); // `__g__' is global map setv_hmap(ymd_push(ioslate(vm)), vm->global); ymd_putg(ioslate(vm), "__g__"); return vm; }
RState* r_state_new (RAllocFunc alloc_fn, rpointer aux) { RState* r; RState zero = { { 0 } }; r = alloc_fn (NULL, NULL, sizeof (RState)); if (!r) goto exit; *r = zero; /* Initialize memory allocator */ r->alloc_fn = alloc_fn; r->alloc_aux = aux; /* Initialize error handling facilities */ r->last_error = R_UNDEFINED; gc_init (r); init_builtin_types (r); init_global_objects (r); vm_init (r); gc_enable (r); exit: return r; }
void gc_test(void) { machine_uint_t len = 500; machine_uint_t *heap = malloc(len); gc_init(heap, heap + len / sizeof(machine_uint_t)); void *ptrs[100]; { machine_uint_t **p = gc_alloc(16, false); p[0] = gc_alloc(64, false); p[1] = gc_alloc(1, false); p[2] = gc_alloc(1, false); p[3] = gc_alloc(1, false); machine_uint_t ***p2 = gc_alloc(16, false); p2[0] = p; p2[1] = p; ptrs[0] = p2; } for (int i = 0; i < 25; i+=2) { machine_uint_t *p = gc_alloc(i, false); printf("p=%p\n", p); if (i & 3) { //ptrs[i] = p; } } printf("Before GC:\n"); gc_dump_alloc_table(); printf("Starting GC...\n"); gc_collect_start(); gc_collect_root(ptrs, sizeof(ptrs) / sizeof(void*)); gc_collect_end(); printf("After GC:\n"); gc_dump_alloc_table(); }
int main(int argc, char **argv) { int stack_dummy; stack_top = (char*)&stack_dummy; memset(heap, 0, sizeof(heap)); memset(&mp_state_ctx, 0, sizeof(mp_state_ctx)); #if MICROPY_ENABLE_GC gc_init(heap, heap + sizeof(heap)); #endif mp_init(); #if MICROPY_REPL_EVENT_DRIVEN pyexec_event_repl_init(); for (;;) { int c = mp_hal_stdin_rx_chr(); if (pyexec_event_repl_process_char(c)) { break; } } #else pyexec_friendly_repl(); #endif //do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT); //do_str("for i in range(10):\r\n print(i)", MP_PARSE_FILE_INPUT); mp_deinit(); return 0; }
int main (int argc, char * argv[]) { gc_init(); init_constants(); init_symeval(); execute(0); return 0; }
STATIC void mp_reset(void) { mp_stack_set_top((void*)0x40000000); mp_stack_set_limit(8192); mp_hal_init(); gc_init(heap, heap + sizeof(heap)); mp_init(); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); // current dir (or base dir of the script) mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash_slash_lib)); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_flash)); mp_obj_list_init(mp_sys_argv, 0); MP_STATE_PORT(term_obj) = MP_OBJ_NULL; MP_STATE_PORT(dupterm_arr_obj) = MP_OBJ_NULL; #if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA extern void esp_native_code_init(void); esp_native_code_init(); #endif pin_init0(); readline_init0(); dupterm_task_init(); #if MICROPY_MODULE_FROZEN pyexec_frozen_module("_boot.py"); pyexec_file("boot.py"); if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) { pyexec_file("main.py"); } #endif }
/** * oath_init: * * This function initializes the OATH library. Every user of this * library needs to call this function before using other functions. * You should call oath_done() when use of the OATH library is no * longer needed. * * Note that this function may also initialize Libgcrypt, if the OATH * library is built with libgcrypt support and libgcrypt has not been * initialized before. Thus if you want to manually initialize * libgcrypt you must do it before calling this function. This is * useful in cases you want to disable libgcrypt's internal lockings * etc. * * Returns: On success, %OATH_OK (zero) is returned, otherwise an * error code is returned. **/ int oath_init (void) { if (gc_init () != GC_OK) return OATH_CRYPTO_ERROR; return OATH_OK; }
static void plugin_vlog(openvpn_plugin_log_flags_t flags, const char *name, const char *format, va_list arglist) { unsigned int msg_flags = 0; if (!format) { return; } if (!name || name[0] == '\0') { msg(D_PLUGIN_DEBUG, "PLUGIN: suppressed log message from plugin with unknown name"); return; } if (flags & PLOG_ERR) { msg_flags = M_INFO | M_NONFATAL; } else if (flags & PLOG_WARN) { msg_flags = M_INFO | M_WARN; } else if (flags & PLOG_NOTE) { msg_flags = M_INFO; } else if (flags & PLOG_DEBUG) { msg_flags = D_PLUGIN_DEBUG; } if (flags & PLOG_ERRNO) { msg_flags |= M_ERRNO; } if (flags & PLOG_NOMUTE) { msg_flags |= M_NOMUTE; } if (msg_test(msg_flags)) { struct gc_arena gc; char *msg_fmt; /* Never add instance prefix; not thread safe */ msg_flags |= M_NOIPREFIX; gc_init(&gc); msg_fmt = gc_malloc(ERR_BUF_SIZE, false, &gc); openvpn_snprintf(msg_fmt, ERR_BUF_SIZE, "PLUGIN %s: %s", name, format); x_msg_va(msg_flags, msg_fmt, arglist); gc_free(&gc); } }
static void test(void) { gc_init(); test_mini_gc_malloc_free(); test_garbage_collect(); test_garbage_collect_load_test(); }
/* * Called once (from main) to initialize STM infrastructure. */ _CALLCONV void stm_init(void) { #if CM == CM_MODULAR char *s; #endif /* CM == CM_MODULAR */ #ifdef SIGNAL_HANDLER struct sigaction act; #endif /* SIGNAL_HANDLER */ PRINT_DEBUG("==> stm_init()\n"); if (_tinystm.initialized) return; PRINT_DEBUG("\tsizeof(word)=%d\n", (int)sizeof(stm_word_t)); PRINT_DEBUG("\tVERSION_MAX=0x%lx\n", (unsigned long)VERSION_MAX); COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(void *)); COMPILE_TIME_ASSERT(sizeof(stm_word_t) == sizeof(atomic_t)); #ifdef EPOCH_GC gc_init(stm_get_clock); #endif /* EPOCH_GC */ #if CM == CM_MODULAR s = getenv(VR_THRESHOLD); if (s != NULL) _tinystm.vr_threshold = (int)strtol(s, NULL, 10); else _tinystm.vr_threshold = VR_THRESHOLD_DEFAULT; PRINT_DEBUG("\tVR_THRESHOLD=%d\n", _tinystm.vr_threshold); #endif /* CM == CM_MODULAR */ /* Set locks and clock but should be already to 0 */ memset((void *)_tinystm.locks, 0, LOCK_ARRAY_SIZE * sizeof(stm_word_t)); CLOCK = 0; stm_quiesce_init(); tls_init(); #ifdef SIGNAL_HANDLER if (getenv(NO_SIGNAL_HANDLER) == NULL) { /* Catch signals for non-faulting load */ act.sa_handler = signal_catcher; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGBUS, &act, NULL) < 0 || sigaction(SIGSEGV, &act, NULL) < 0) { perror("sigaction"); exit(1); } } #endif /* SIGNAL_HANDLER */ _tinystm.initialized = 1; }
int test_gc_init(struct tf_test *thiz) { int rc; rc = gc_init(); rc = (rc == 0) ? TF_SUCC : TF_FAIL; return (rc); }
int main(void) { // Initialize system upon power-up. serial_init(); // Setup serial baud rate and interrupts settings_init(); // Load grbl settings from EEPROM stepper_init(); // Configure stepper pins and interrupt timers system_init(); // Configure pinout pins and pin-change interrupt memset(&sys, 0, sizeof(sys)); // Clear all system variables sys.abort = true; // Set abort to complete initialization sei(); // Enable interrupts // Check for power-up and set system alarm if homing is enabled to force homing cycle // by setting Grbl's alarm state. Alarm locks out all g-code commands, including the // startup scripts, but allows access to settings and internal commands. Only a homing // cycle '$H' or kill alarm locks '$X' will disable the alarm. // NOTE: The startup script will run after successful completion of the homing cycle, but // not after disabling the alarm locks. Prevents motion startup blocks from crashing into // things uncontrollably. Very bad. #ifdef HOMING_INIT_LOCK if (bit_istrue(settings.flags,BITFLAG_HOMING_ENABLE)) { sys.state = STATE_ALARM; } #endif // Grbl initialization loop upon power-up or a system abort. For the latter, all processes // will return to this loop to be cleanly re-initialized. for(;;) { // TODO: Separate configure task that require interrupts to be disabled, especially upon // a system abort and ensuring any active interrupts are cleanly reset. // Reset Grbl primary systems. serial_reset_read_buffer(); // Clear serial read buffer gc_init(); // Set g-code parser to default state spindle_init(); coolant_init(); limits_init(); probe_init(); plan_reset(); // Clear block buffer and planner variables st_reset(); // Clear stepper subsystem variables. // Sync cleared gcode and planner positions to current system position. plan_sync_position(); gc_sync_position(); // Reset system variables. sys.abort = false; sys.execute = 0; if (bit_istrue(settings.flags,BITFLAG_AUTO_START)) { sys.auto_start = true; } else { sys.auto_start = false; } // Start Grbl main loop. Processes program inputs and executes them. protocol_main_loop(); } return 0; /* Never reached */ }
static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */ { OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage); if (GC_G(gc_enabled)) { gc_init(); } return SUCCESS; }
//Allocation heap_object *gc_alloc(object_metadata *metadata, size_t size) { if ( start_of_heap==NULL ) { gc_init(DEFAULT_MAX_HEAP_SIZE); } size = align_to_word_boundary(size); heap_object *p = gc_raw_alloc(size); memset(p, 0, size); p->metadata = metadata; p->size = (uint32_t)size; return p; }
int GGPROTO::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPARAM lParam) { switch( eventType ) { case EV_PROTO_ONLOAD: { HookProtoEvent(ME_OPT_INITIALISE, &GGPROTO::options_init); HookProtoEvent(ME_USERINFO_INITIALISE, &GGPROTO::details_init); // Init misc stuff gg_icolib_init(); initpopups(); gc_init(); keepalive_init(); img_init(); block_init(); // Try to fetch user avatar getOwnAvatar(); break; } case EV_PROTO_ONEXIT: // Stop avatar request thread pth_avatar.dwThreadId = 0; // Stop main connection session thread pth_sess.dwThreadId = 0; img_shutdown(); sessions_closedlg(); break; case EV_PROTO_ONOPTIONS: return options_init(wParam, lParam); case EV_PROTO_ONMENU: menus_init(); break; case EV_PROTO_ONRENAME: if (hMenuRoot) { CLISTMENUITEM mi = { sizeof(mi) }; mi.flags = CMIM_NAME | CMIF_TCHAR | CMIF_KEEPUNTRANSLATED; mi.ptszName = m_tszUserName; Menu_ModifyItem(hMenuRoot, &mi); } break; case EV_PROTO_ONCONTACTDELETED: return contactdeleted(wParam, lParam); case EV_PROTO_DBSETTINGSCHANGED: return dbsettingchanged(wParam, lParam); } return TRUE; }
int main() { const char a[] = {"sim"}; mp_stack_set_limit(10240); void *heap = malloc(256 * 1024); gc_init(heap, (char*)heap + 256 * 1024); mp_init(); int r = tinytest_main(1, (const char **) a, groups); mp_deinit(); printf( "status: %i\n", r); return r; }
void mp_task(void *pvParameter) { volatile uint32_t sp = (uint32_t)get_sp(); #if MICROPY_PY_THREAD mp_thread_init(&mp_task_stack[0], MP_TASK_STACK_LEN); #endif uart_init(); soft_reset: // initialise the stack pointer for the main thread mp_stack_set_top((void *)sp); mp_stack_set_limit(MP_TASK_STACK_SIZE - 1024); gc_init(mp_task_heap, mp_task_heap + sizeof(mp_task_heap)); mp_init(); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR_)); mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib)); mp_obj_list_init(mp_sys_argv, 0); readline_init0(); // initialise peripherals machine_pins_init(); // run boot-up scripts pyexec_frozen_module("_boot.py"); pyexec_file("boot.py"); if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) { pyexec_file("main.py"); } for (;;) { if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { if (pyexec_raw_repl() != 0) { break; } } else { if (pyexec_friendly_repl() != 0) { break; } } } #if MICROPY_PY_THREAD mp_thread_deinit(); #endif mp_hal_stdout_tx_str("PYB: soft reboot\r\n"); // deinitialise peripherals machine_pins_deinit(); mp_deinit(); fflush(stdout); goto soft_reset; }
STATIC void mp_reset(void) { mp_stack_set_limit(10240); mp_hal_init(); gc_init(heap, heap + sizeof(heap)); mp_init(); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_init(mp_sys_argv, 0); #if MICROPY_MODULE_FROZEN pyexec_frozen_module("main"); #endif }
void mp_run(void) { int stack_dummy; stack_top = (char*)&stack_dummy; mp_stack_ctrl_init(); mp_stack_set_limit(1800); // stack is 2k // allocate the heap statically in the bss static uint32_t heap[9820 / 4]; gc_init(heap, (uint8_t*)heap + sizeof(heap)); /* // allocate the heap using system malloc extern void *malloc(int); void *mheap = malloc(2000); gc_init(mheap, (byte*)mheap + 2000); */ /* // allocate the heap statically (will clash with BLE) gc_init((void*)0x20000100, (void*)0x20002000); */ mp_init(); mp_hal_init(); readline_init0(); microbit_init(); if (APPENDED_SCRIPT->header[0] == 'M' && APPENDED_SCRIPT->header[1] == 'P') { // run appended script do_strn(APPENDED_SCRIPT->str, APPENDED_SCRIPT->len); } else if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) { // from microbit import * mp_import_all(mp_import_name(MP_QSTR_microbit, mp_const_empty_tuple, MP_OBJ_NEW_SMALL_INT(0))); } for (;;) { if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { if (pyexec_raw_repl() != 0) { break; } } else { if (pyexec_friendly_repl() != 0) { break; } } } mp_hal_stdout_tx_str("soft reboot\r\n"); memset(&MP_STATE_PORT(async_data)[0], 0, sizeof(MP_STATE_PORT(async_data))); MP_STATE_PORT(async_music_data) = NULL; mp_deinit(); }
int main(int argc, char *argv[]) { init(); if(init_setting() != 0){ print_errmsg("ERROR: SETTING init fail. \n"); return 1; } if(gc_init() != 0){ print_errmsg("ERROR: G_CODE init fail. \n"); return 1; } if (cm_init() == false) { print_errmsg("ERROR: USB-DEV init fail. \n"); return 1; } if (cmd_init() == false) { print_errmsg("ERROR: G code init fail.\n"); cm_close(); return 1; } if (tp_init() == false) { print_errmsg("ERROR: Temperature library init fail. \n"); cmd_close(); cm_close(); return 1; } plan_init(); Config_ResetDefault(); st_init(); while(1) { LCD(10UL); getCommand(10UL); process_commands(50UL); stepper(1000L); manageHeater(10UL); } st_close(); plan_close(); tp_close(); cmd_close(); cm_close(); //debug //sfp_close(); return 0; }
int main() { gc_init(); test(); gc_free(); printf("---\n"); gc_init(); test2(); gc_free(); printf("---\n"); gc_init(); test3(); gc_free(); printf("---\n"); gc_init(); test_record(); gc_free(); printf("sizeof type %ld header %ld\n", sizeof(ObjectType), sizeof(ObjectHeader)); return 0; }
int main() { // Initialized stack limit mp_stack_set_limit(40000 * (BYTES_PER_WORD / 4)); // Initialize heap gc_init(heap, heap + sizeof(heap)); // Initialize interpreter mp_init(); const char str[] = "print('Hello world of easy embedding!')"; if (execute_from_str(str)) { printf("Error\n"); } }
STATIC void mp_reset(void) { mp_stack_set_top((void*)0x40000000); mp_stack_set_limit(8192); mp_hal_init(); gc_init(heap, heap + sizeof(heap)); mp_init(); mp_obj_list_init(mp_sys_path, 0); mp_obj_list_init(mp_sys_argv, 0); MP_STATE_PORT(mp_kbd_exception) = mp_obj_new_exception(&mp_type_KeyboardInterrupt); #if MICROPY_MODULE_FROZEN pyexec_frozen_module("boot"); #endif }
int main(int argc, char** argv){ register void* base asm("ebp"); gc_init(100, base, false); void* x1 = gc_malloc(49); void* x2 = gc_malloc(49); assert(x2 != NULL); x1 = gc_malloc(49); assert(x1 == NULL); gc_shutdown(); return 0; }