コード例 #1
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);
}
コード例 #2
0
ファイル: vm_method.c プロジェクト: alloy/mr-experimental
static void
remove_method(VALUE klass, ID mid)
{
    if (klass == rb_cObject) {
	rb_secure(4);
    }
    if (rb_safe_level() >= 4 && !OBJ_TAINTED(klass)) {
	rb_raise(rb_eSecurityError, "Insecure: can't remove method");
    }
    if (OBJ_FROZEN(klass))
	rb_error_frozen("class/module");
    if (mid == object_id || mid == __send__ || mid == idInitialize) {
	rb_warn("removing `%s' may cause serious problem", rb_id2name(mid));
    }
    SEL sel;
    Method m;

    sel = sel_registerName(rb_id2name(mid));
    m = class_getInstanceMethod((Class)klass, sel);
    if (m == NULL) {
	char buf[100];
	size_t len = strlen((char *)sel);
	if (((char *)sel)[len - 1] != ':') {
	    snprintf(buf, sizeof buf, "%s:", (char *)sel);
	    sel = sel_registerName(buf);
	    m = class_getInstanceMethod((Class)klass, sel);
	}
    }
    if (m == NULL) {
	rb_name_error(mid, "method `%s' not defined in %s",
		      rb_id2name(mid), rb_class2name(klass));
    }
    if (rb_vm_get_method_node(method_getImplementation(m)) == NULL) {
	rb_warn("removing pure Objective-C method `%s' may cause serious " \
		"problem", rb_id2name(mid));
    }
    method_setImplementation(m, NULL);

    if (RCLASS_SINGLETON(klass)) {
	rb_funcall(rb_iv_get(klass, "__attached__"), singleton_removed, 1,
		   ID2SYM(mid));
    }
    else {
	rb_funcall(klass, removed, 1, ID2SYM(mid));
    }
}