ObjFW  Check-in [3d0a1604ae]

Overview
Comment:Increase blocks compatibility by replacing NSAutoreleasePool.

NSAutoreleasePool is replaced by OFAutoreleasePool now so that there is
no conflict because OFBlocks are used (blocks are OFBlocks as soon as
ObjFW is linked). An application expecting an NSBlock, but getting an
OFBlock because ObjFW is linked, would fail to autorelease the block
otherwise, as the block would be in an OFAutoreleasePool. By replacing
NSAutoreleasePool with OFAutoreleasePool, the application will still
properly free the autoreleased block.

This will also make it easier to write applications using both,
Foundation and ObjFW, since the developer does not need to take care
about two different autorelease pools, but they are united instead.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3d0a1604aea19fe83d86b73c9c47977f6e48cdb88eef14d08ebd7bf9d68d1641
User & Date: js on 2011-02-02 22:26:45
Other Links: manifest | tags
Context
2011-02-03
20:58
Improve README. check-in: ce1e81bdb2 user: js tags: trunk
2011-02-02
22:26
Increase blocks compatibility by replacing NSAutoreleasePool. check-in: 3d0a1604ae user: js tags: trunk
17:38
Work around some annoying compiler bugs. check-in: 1dcfbcb479 user: js tags: trunk
Changes

Modified configure.ac from [aad91aaffc] to [18c25283af].

427
428
429
430
431
432
433






434
435
436
437
438
439
440
], [
	AC_MSG_RESULT(no)
])

AC_CHECK_FUNC(madvise, [
	AC_DEFINE(HAVE_MADVISE, 1, [Whether we have madvise])
])







AS_IF([test x"$GOBJC" = x"yes"], [
	OBJCFLAGS="$OBJCFLAGS -Werror"

	AC_MSG_CHECKING(whether gcc has bug objc/27438)
	AC_TRY_COMPILE([
		#import <objc/objc.h>







>
>
>
>
>
>







427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
], [
	AC_MSG_RESULT(no)
])

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)
	AC_TRY_COMPILE([
		#import <objc/objc.h>

Modified extra.mk.in from [f7112abbb6] to [abea8b5d75].

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@
OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@
OBJFW_LIB_MAJOR = 3
OBJFW_LIB_MINOR = 0
OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR}

ASPRINTF_M = @ASPRINTF_M@
ATOMIC_H = @ATOMIC_H@
BIN_PREFIX = @BIN_PREFIX@

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@
OFPLUGINTESTS_M = @OFPLUGINTESTS_M@
OFTHREAD_M = @OFTHREAD_M@









>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@
OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@
OBJFW_LIB_MAJOR = 3
OBJFW_LIB_MINOR = 0
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@
OFPLUGINTESTS_M = @OFPLUGINTESTS_M@
OFTHREAD_M = @OFTHREAD_M@

Modified src/Makefile from [25fedfa6c0] to [f7798a36a9].

51
52
53
54
55
56
57

58
59
60
61
62
63
64
65
66
67
	    asprintf.h		\
	    ${ATOMIC_H}		\
	    macros.h		\
	    objfw-defs.h	\
	    ${THREADING_H}

SRCS += ${ASPRINTF_M} 		\

	iso_8859_15.m		\
	windows_1252.m		\
	${OBJC_PROPERTIES_M}	\
	${OBJC_SYNC_M}

include ../buildsys.mk

CPPFLAGS += -I..
LD = ${OBJC}
LDFLAGS += ${REEXPORT_LIBOBJC} ${MACH_ALIAS_LIST}







>










51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
	    asprintf.h		\
	    ${ATOMIC_H}		\
	    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}

include ../buildsys.mk

CPPFLAGS += -I..
LD = ${OBJC}
LDFLAGS += ${REEXPORT_LIBOBJC} ${MACH_ALIAS_LIST}

Added src/foundation-compat.m version [7aefac85c2].

























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Copyright (c) 2008, 2009, 2010, 2011
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 <objc/runtime.h>

#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));
}