예제 #1
0
파일: gc.c 프로젝트: 1nueve/MacRuby
void
Init_PreGC(void)
{
    auto_collection_control_t *control;

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
    __auto_zone = objc_collectableZone();
#else
    __auto_zone = auto_zone();
#endif
    
    if (__auto_zone == NULL) {
	rb_objc_no_gc_error();
    }

    __nsobject = (void *)objc_getClass("NSObject");

    control = auto_collection_parameters(__auto_zone);
    if (getenv("GC_DEBUG")) {
	control->log = AUTO_LOG_COLLECTIONS | AUTO_LOG_REGIONS | AUTO_LOG_UNUSUAL;
    }
    if (getenv("GC_DISABLE")) {
	gc_disabled = true;
	auto_collector_disable(__auto_zone);
    }
}
예제 #2
0
파일: gc.c 프로젝트: prototype/MacRuby
void
Init_PreGC(void)
{
    auto_collection_control_t *control;

    __auto_zone = auto_zone();
    
    if (__auto_zone == NULL) {
	rb_objc_no_gc_error();
    }

    __nsobject = (void *)objc_getClass("NSObject");

    control = auto_collection_parameters(__auto_zone);
    if (getenv("GC_DEBUG")) {
	control->log = AUTO_LOG_COLLECTIONS | AUTO_LOG_REGIONS | AUTO_LOG_UNUSUAL;
    }
    if (getenv("GC_DISABLE")) {
	gc_disabled = true;
    }

    Method m = class_getInstanceMethod((Class)objc_getClass("NSObject"), sel_registerName("finalize"));
    assert(m != NULL);
    method_setImplementation(m, (IMP)rb_obj_imp_finalize);

    auto_collector_disable(__auto_zone);
}
예제 #3
0
파일: gc.c 프로젝트: 1nueve/MacRuby
VALUE
rb_gc_disable(VALUE self, SEL sel)
{
    int old = dont_gc;

    auto_collector_disable(__auto_zone);
    dont_gc = Qtrue;
    return old ? Qtrue : Qfalse;
}
예제 #4
0
파일: gc.c 프로젝트: 1nueve/MacRuby
static VALUE
os_each_obj(VALUE os, SEL sel, int argc, VALUE *argv)
{
    VALUE of;
    int count;

    rb_secure(4);
    if (argc == 0) {
	of = 0;
    }
    else {
	rb_scan_args(argc, argv, "01", &of);
    }
    RETURN_ENUMERATOR(os, 1, &of);

    /* Class/Module are a special case, because they are not auto objects */
    if (of == rb_cClass || of == rb_cModule) {
	count = rb_objc_yield_classes(of);
    }
    else {
	struct rb_objc_recorder_context ctx = {of, 0, Qundef};

	auto_collector_disable(__auto_zone);

	(((malloc_zone_t *)__auto_zone)->introspect->enumerator)(
	    mach_task_self(), (void *)&ctx, MALLOC_PTR_IN_USE_RANGE_TYPE,
	    (vm_address_t)__auto_zone, NULL, rb_objc_recorder);

	auto_collector_reenable(__auto_zone);

	if (ctx.break_value != Qundef) {
	    return ctx.break_value;
	}

	count = ctx.count;
    }

    return INT2FIX(count);
}