Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -50,10 +50,13 @@ AC_DEFINE(OF_APPLE_RUNTIME, 1, [Whether we use the Apple ObjC runtime]) AC_SUBST(RUNTIME_DEF, "-DOF_APPLE_RUNTIME") objc_runtime="Apple"]) AC_MSG_RESULT($objc_runtime) +AC_CHECK_FUNC(objc_getProperty,, [ + AC_SUBST(OBJC_PROPERTIES_M, "objc_properties.m")]) + AC_CHECK_FUNC(objc_enumerationMutation, [ AC_DEFINE(HAVE_OBJC_ENUMERATIONMUTATION, 1, [Whether we have objc_enumerationMutation])]) BUILDSYS_LIB Index: extra.mk.in ================================================================== --- extra.mk.in +++ extra.mk.in @@ -1,8 +1,9 @@ ASPRINTF_M = @ASPRINTF_M@ +OBJC_PROPERTIES_M = @OBJC_PROPERTIES_M@ OBJC_SYNC_M = @OBJC_SYNC_M@ OFPLUGIN_M = @OFPLUGIN_M@ OFTHREAD_M = @OFTHREAD_M@ TESTPLUGIN = @TESTPLUGIN@ TESTS = @TESTS@ TEST_LAUNCHER = @TEST_LAUNCHER@ THREADING_H = @THREADING_H@ Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -36,15 +36,16 @@ ObjFW.h \ asprintf.h \ objfw-defs.h \ ${THREADING_H} -SRCS += ${OBJC_SYNC_M} \ - ${ASPRINTF_M} \ - iso_8859_15.m \ - windows_1252.m +SRCS += ${AS_PRINTF_M} \ + iso_8859_15.m \ + windows_1252.m \ + ${OBJC_PROPERTIES_M} \ + ${OBJC_SYNC_M} include ../buildsys.mk CPPFLAGS += -I.. OBJCFLAGS += ${LIB_CFLAGS} LD = ${OBJC} ADDED src/objc_properties.m Index: src/objc_properties.m ================================================================== --- src/objc_properties.m +++ src/objc_properties.m @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2008 - 2009 + * 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 included in + * the packaging of this file. + */ + +#include "config.h" + +#import + +#import "OFExceptions.h" + +id +objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, BOOL atomic) +{ + if (atomic) { + @synchronized (self) { + id ptr = *(id*)((char*)self + offset); + return [[ptr retain] autorelease]; + } + } + + return [[*(id*)((char*)self + offset) retain] autorelease]; +} + +void +objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id value, BOOL atomic, + BOOL copy) +{ + if (atomic) { + @synchronized ((atomic ? self : nil)) { + id *ptr = (id*)((char*)self + offset); + id old = *ptr; + + *ptr = (copy ? [value copy] : [value retain]); + [old release]; + } + } + + id *ptr = (id*)((char*)self + offset); + id old = *ptr; + + *ptr = (copy ? [value copy] : [value retain]); + [old release]; +}