tort_v _tort_m_mtable__add_method (tort_tp tort_mtable *mtable, tort_symbol *symbol, tort_method *method) { // fprintf(stderr, " add_method %s %s %p\n", tort_object_name(mtable), tort_object_name(symbol), method->applyf); if ( ! (symbol->name == tort_nil || symbol->name == 0) ) { if ( method->name == tort_nil || method->name == 0 ) { char *buf = tort_malloc(strlen(tort_mtable_name_(mtable)) + 2 + strlen(tort_symbol_charP(symbol)) + 1); sprintf(buf, "%s::%s", tort_mtable_name_(mtable), tort_symbol_charP(symbol)); method->name = tort_symbol_new(buf); } } _tort_m_symbol___version_change(tort_ta symbol); #if TORT_ANON_SYMBOL_MTABLE if ( symbol->name == tort_nil || symbol->name == 0 ) { _tort_m_map__set(tort_ta (tort_v) symbol->mtable_method_map, mtable, method); } else #endif _tort_m_map__set(tort_ta (tort_v) mtable, symbol, method); _tort_m_mtable___method_changed(tort_ta mtable, symbol, method); return method; }
tort_v _tort_m_initializer__malloc(tort_tp tort_v init) { const char *var; _tort_gc_disabled ++; // temporarily disabled till boot is finished. (void) _tort_finalization_proc; // avoid warning. var = getenv("TORT_GC"); if ( ! var || ! *var || ! strcmp(var, "0") ) var = "bdw"; #if TORT_GC_BDW if ( ! strcmp(var, "bdw") ) { GC_set_all_interior_pointers(1); GC_set_finalize_on_demand(0); GC_INIT(); _tort_gc_mode = "bdw"; _tort_malloc = GC_malloc; _tort_malloc_atomic = GC_malloc_atomic; _tort_free = GC_free; _tort_free_atomic = GC_free; /* ??? */ _tort_realloc = GC_realloc; _tort_realloc_atomic = GC_realloc; /* ??? */ _tort_gc_collect = GC_gcollect; _tort_gc_register_finalizer = _tort_gc_register_finalizer_bdw; _tort_gc_invoke_finalizers = (void*) GC_invoke_finalizers; _tort_gc_stats = _tort_gc_stats_bdw; } #endif #if TORT_GC_SMAL if ( ! strcmp(var, "smal") ) { _tort_gc_mode = "smal"; smal_debug_set_level(smal_debug_all, 1); smal_init(); _tort_gc_collect = _tort_gc_collect_smal; _tort_object_alloc = _tort_object_alloc_smal; _tort_gc_stats = _tort_gc_stats_smal; { const char *s = getenv("TORT_GC_ALLOCS_PER_GC"); allocs_per_gc = s && *s ? atoi(s) : 10000; } } #endif if ( ! strcmp(var, "malloc") ) _tort_gc_mode = "malloc"; if ( ! _tort_gc_mode ) { _tort_gc_mode = "malloc"; fprintf(stderr, " tort: WARNING: defaulting to TORT_GC=%s\n", _tort_gc_mode); } if ( ! strcmp(_tort_gc_mode, "malloc") ) fprintf(stderr, " tort: WARNING: using malloc(), NO GC!\n"); { /* assert alignments. */ void *p; assert((size_t) (p = tort_malloc(sizeof(tort_header))) % sizeof(tort_v) == 0); tort_free(p); assert((size_t) (p = tort_malloc_atomic(sizeof(tort_header))) % sizeof(tort_v) == 0); tort_free_atomic(p); } return init; }
static void *_tort_object_alloc_default(tort_mtable *mtable, size_t size) { return tort_malloc(size); }