Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -429,10 +429,16 @@ ]) AC_CHECK_FUNC(madvise, [ AC_DEFINE(HAVE_MADVISE, 1, [Whether we have madvise]) ]) + +AS_IF([test x"$objc_runtime" = x"Apple"], [ + AC_CHECK_HEADER(Foundation/Foundation.h, [ + AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m") + ]) +]) AS_IF([test x"$GOBJC" = x"yes"], [ OBJCFLAGS="$OBJCFLAGS -Werror" AC_MSG_CHECKING(whether gcc has bug objc/27438) Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -5,10 +5,11 @@ OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR} ASPRINTF_M = @ASPRINTF_M@ ATOMIC_H = @ATOMIC_H@ BIN_PREFIX = @BIN_PREFIX@ +FOUNDATION_COMPAT_M = @FOUNDATION_COMPAT_M@ MACH_ALIAS_LIST = @MACH_ALIAS_LIST@ OFBLOCKTESTS_M = @OFBLOCKTESTS_M@ OBJC_PROPERTIES_M = @OBJC_PROPERTIES_M@ OBJC_SYNC_M = @OBJC_SYNC_M@ OFPLUGIN_M = @OFPLUGIN_M@ Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -53,10 +53,11 @@ macros.h \ objfw-defs.h \ ${THREADING_H} SRCS += ${ASPRINTF_M} \ + ${FOUNDATION_COMPAT_M} \ iso_8859_15.m \ windows_1252.m \ ${OBJC_PROPERTIES_M} \ ${OBJC_SYNC_M} ADDED src/foundation-compat.m Index: src/foundation-compat.m ================================================================== --- src/foundation-compat.m +++ src/foundation-compat.m @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +/* FIXME: + * Kommentar warum benötigt + */ + +#include "config.h" + +#import + +#import "OFAutoreleasePool.h" + +static id +alloc(Class self, SEL _cmd) +{ + return [OFAutoreleasePool alloc]; +} + +static void +addObject(Class self, SEL _cmd, id obj) +{ + [OFAutoreleasePool addObject: obj]; +} + +static id +autorelease(id self, SEL _cmd) +{ + [OFAutoreleasePool addObject: self]; + + return self; +} + +static void __attribute__((constructor)) +init() +{ + Class NSAutoreleasePool = objc_getClass("NSAutoreleasePool"); + Class NSObject = objc_getClass("NSObject"); + Method alloc_method; + Method addObject_method; + Method autorelease_method; + + if (NSAutoreleasePool == Nil || NSObject == Nil) + return; + + alloc_method = class_getClassMethod(NSAutoreleasePool, + @selector(alloc)); + addObject_method = class_getClassMethod(NSAutoreleasePool, + @selector(addObject:)); + autorelease_method = class_getInstanceMethod(NSObject, + @selector(autorelease)); + + if (alloc_method == NULL || addObject_method == NULL || + autorelease_method == NULL) + return; + + class_replaceMethod(NSAutoreleasePool->isa, @selector(alloc), + (IMP)alloc, method_getTypeEncoding(alloc_method)); + class_replaceMethod(NSAutoreleasePool->isa, @selector(addObject:), + (IMP)addObject, method_getTypeEncoding(addObject_method)); + class_replaceMethod(NSObject, @selector(autorelease), + (IMP)autorelease, method_getTypeEncoding(autorelease_method)); +}