ObjFW  Check-in [1a7c408c7d]

Overview
Comment:Add full blocks support for OS X.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1a7c408c7d15e6d342011fe6ad98428907bc2f7ab78847a3697be1ce107718d8
User & Date: js on 2010-11-11 20:47:13
Other Links: manifest | tags
Context
2010-11-11
20:52
Ignore BOM at start of string. check-in: 1e7e237e6e user: js tags: trunk
20:47
Add full blocks support for OS X. check-in: 1a7c408c7d user: js tags: trunk
2010-11-08
19:38
Rename run-on-iphone to run-on-ios and rename respective variables. check-in: 7312b92a1d user: js tags: trunk
Changes

Modified configure.ac from [5a82833b3a] to [7cb958a7ef].

71
72
73
74
75
76
77
78

79
80
81
82
83
84
85
	AC_DEFINE(OF_HAVE_BLOCKS, 1, [Compiler support for blocks])
	AC_SUBST(BLOCKS_FLAGS, "-fblocks")
	AC_MSG_RESULT(yes)
	], [
	AC_MSG_RESULT(no)
	OBJCFLAGS="$old_OBJCFLAGS"
	])
AC_CHECK_FUNC(_Block_copy,, AC_SUBST(OFBLOCK_M, "OFBlock.m"))


AC_CHECK_HEADERS([objfw-rt.h objc/objc.h])

test x"$ac_cv_header_objfw_rt_h" = x"yes" && objc_runtime="ObjFW-RT"

if test x"$ac_cv_header_objc_objc_h" = x"yes"; then
	dnl TODO: This is ugly. Let's think of a better check.







|
>







71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	AC_DEFINE(OF_HAVE_BLOCKS, 1, [Compiler support for blocks])
	AC_SUBST(BLOCKS_FLAGS, "-fblocks")
	AC_MSG_RESULT(yes)
	], [
	AC_MSG_RESULT(no)
	OBJCFLAGS="$old_OBJCFLAGS"
	])
AC_CHECK_FUNC(_Block_copy,,
	AC_DEFINE(HAVE_BLOCK_COPY, 1, [Whether we have _Block_copy]))

AC_CHECK_HEADERS([objfw-rt.h objc/objc.h])

test x"$ac_cv_header_objfw_rt_h" = x"yes" && objc_runtime="ObjFW-RT"

if test x"$ac_cv_header_objc_objc_h" = x"yes"; then
	dnl TODO: This is ugly. Let's think of a better check.
149
150
151
152
153
154
155

156
157
158
159
160
161
162
	AC_SUBST(OFPLUGINS_DEF, "-DOF_PLUGINS")
fi

case "$host_os" in
	darwin*)
		AC_SUBST(REEXPORT_LIBOBJC, [-Wl,-reexport-lobjc])
		AC_SUBST(LDFLAGS_REEXPORT, [-Wl,-reexport-lobjfw])

		;;
esac

AC_C_BIGENDIAN([
	AC_DEFINE(OF_BIG_ENDIAN, 1, [Whether we are big endian])
	AC_SUBST(ENDIANESS_DEF, "-DOF_BIG_ENDIAN")])








>







150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
	AC_SUBST(OFPLUGINS_DEF, "-DOF_PLUGINS")
fi

case "$host_os" in
	darwin*)
		AC_SUBST(REEXPORT_LIBOBJC, [-Wl,-reexport-lobjc])
		AC_SUBST(LDFLAGS_REEXPORT, [-Wl,-reexport-lobjfw])
		AC_SUBST(MACH_ALIAS_LIST, [-Wl,-alias_list,mach_alias_list])
		;;
esac

AC_C_BIGENDIAN([
	AC_DEFINE(OF_BIG_ENDIAN, 1, [Whether we are big endian])
	AC_SUBST(ENDIANESS_DEF, "-DOF_BIG_ENDIAN")])

Modified extra.mk.in from [0be9b4fca9] to [0e102eb3db].

1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
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@

OBJC_PROPERTIES_M = @OBJC_PROPERTIES_M@
OBJC_SYNC_M = @OBJC_SYNC_M@
OFBLOCK_M = @OFBLOCK_M@
OFPLUGIN_M = @OFPLUGIN_M@
OFPLUGINTESTS_M = @OFPLUGINTESTS_M@
OFTHREAD_M = @OFTHREAD_M@
OFTHREADTESTS_M = @OFTHREADTESTS_M@
PROPERTIESTESTS_M = @PROPERTIESTESTS_M@
REEXPORT_LIBOBJC = @REEXPORT_LIBOBJC@
TESTPLUGIN = @TESTPLUGIN@
TESTS = @TESTS@
TEST_LAUNCHER = @TEST_LAUNCHER@
THREADING_H = @THREADING_H@









>


<










1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
20
21
22
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@
OBJC_PROPERTIES_M = @OBJC_PROPERTIES_M@
OBJC_SYNC_M = @OBJC_SYNC_M@

OFPLUGIN_M = @OFPLUGIN_M@
OFPLUGINTESTS_M = @OFPLUGINTESTS_M@
OFTHREAD_M = @OFTHREAD_M@
OFTHREADTESTS_M = @OFTHREADTESTS_M@
PROPERTIESTESTS_M = @PROPERTIESTESTS_M@
REEXPORT_LIBOBJC = @REEXPORT_LIBOBJC@
TESTPLUGIN = @TESTPLUGIN@
TESTS = @TESTS@
TEST_LAUNCHER = @TEST_LAUNCHER@
THREADING_H = @THREADING_H@

Modified src/Makefile from [a78e57c409] to [a18fe9b7a4].

1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
include ../extra.mk

LIB = ${OBJFW_SHARED_LIB}
LIB_MAJOR = ${OBJFW_LIB_MAJOR}
LIB_MINOR = ${OBJFW_LIB_MINOR}
STATIC_LIB = ${OBJFW_STATIC_LIB}

SRCS = OFApplication.m		\
       OFArray.m		\
       OFAutoreleasePool.m	\

       OFConstantString.m	\
       OFDataArray.m		\
       OFDictionary.m		\
       OFExceptions.m		\
       OFFile.m			\
       OFHash.m			\
       OFEnumerator.m		\










>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
include ../extra.mk

LIB = ${OBJFW_SHARED_LIB}
LIB_MAJOR = ${OBJFW_LIB_MAJOR}
LIB_MINOR = ${OBJFW_LIB_MINOR}
STATIC_LIB = ${OBJFW_STATIC_LIB}

SRCS = OFApplication.m		\
       OFArray.m		\
       OFAutoreleasePool.m	\
       OFBlock.m		\
       OFConstantString.m	\
       OFDataArray.m		\
       OFDictionary.m		\
       OFExceptions.m		\
       OFFile.m			\
       OFHash.m			\
       OFEnumerator.m		\
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
       OFXMLAttribute.m		\
       OFXMLElement.m		\
       OFXMLElementBuilder.m	\
       OFXMLParser.m		\
       unicode.m

INCLUDES := ${SRCS:.m=.h}	\
	    OFBlock.h		\
	    OFCollection.h	\
	    ObjFW.h		\
	    asprintf.h		\
	    ${ATOMIC_H}		\
	    macros.h		\
	    objfw-defs.h	\
	    ${THREADING_H}

SRCS += ${OFBLOCK_M}		\
	${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}







<








<
|









|
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
       OFXMLAttribute.m		\
       OFXMLElement.m		\
       OFXMLElementBuilder.m	\
       OFXMLParser.m		\
       unicode.m

INCLUDES := ${SRCS:.m=.h}	\

	    OFCollection.h	\
	    ObjFW.h		\
	    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}

Modified src/OFBlock.m from [0cda48050d] to [daa6113db1].

8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#import "OFBlock.h"

#import "atomic.h"

/// \cond internal
@protocol RetainRelease
- retain;
- (void)release;
@end







<




>







8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24
25
26
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#include "config.h"

#include <stdint.h>

#include <stdlib.h>
#include <string.h>

#import "OFBlock.h"
#import "OFExceptions.h"
#import "atomic.h"

/// \cond internal
@protocol RetainRelease
- retain;
- (void)release;
@end
103
104
105
106
107
108
109
110
111
112
113
114





115
116
117
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
static void __attribute__((constructor))
constructor()
{
	__objc_exec_class(&module);
}
/* End of ObjC module */
#else
void *_NSConcreteStackBlock;
void *_NSConcreteGlobalBlock;
void *_NSConcreteMallocBlock;
#endif






void*
_Block_copy(const void *block_)
{
	of_block_literal_t *block = (of_block_literal_t*)block_;

	if (block->isa == (Class)&_NSConcreteStackBlock) {
		of_block_literal_t *copy;

		if ((copy = malloc(block->descriptor->size)) == NULL) {
			fputs("Not enough memory to copy block!\n", stderr);
			exit(1);

		}
		memcpy(copy, block, block->descriptor->size);

		copy->isa = (Class)&_NSConcreteMallocBlock;
		copy->reserved++;

		if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE)







|
|
|


>
>
>
>
>









|
|
>







103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
static void __attribute__((constructor))
constructor()
{
	__objc_exec_class(&module);
}
/* End of ObjC module */
#else
extern void *_NSConcreteStackBlock;
extern void *_NSConcreteGlobalBlock;
extern void *_NSConcreteMallocBlock;
#endif

#ifndef HAVE_BLOCK_COPY
static struct {
	Class isa;
} alloc_failed_exception;

void*
_Block_copy(const void *block_)
{
	of_block_literal_t *block = (of_block_literal_t*)block_;

	if (block->isa == (Class)&_NSConcreteStackBlock) {
		of_block_literal_t *copy;

		if ((copy = malloc(block->descriptor->size)) == NULL) {
			alloc_failed_exception.isa =
			    [OFAllocFailedException class];
			@throw (OFAllocFailedException*)&alloc_failed_exception;
		}
		memcpy(copy, block, block->descriptor->size);

		copy->isa = (Class)&_NSConcreteMallocBlock;
		copy->reserved++;

		if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE)
172
173
174
175
176
177
178
179
180

181
182
183
184
185
186
187
188
		break;
	case OF_BLOCK_FIELD_IS_BYREF:;
		of_block_byref_t *src = (of_block_byref_t*)src_;
		of_block_byref_t **dst = (of_block_byref_t**)dst_;

		if ((src->flags & ~OF_BLOCK_HAS_COPY_DISPOSE) == 0) {
			if ((*dst = malloc(src->size)) == NULL) {
				fputs("Not enough memory for block "
				    "variables!\n", stderr);

				exit(1);
			}

			if (src->forwarding == src)
				src->forwarding = *dst;

			memcpy(*dst, src, src->size);








|
|
>
|







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
		break;
	case OF_BLOCK_FIELD_IS_BYREF:;
		of_block_byref_t *src = (of_block_byref_t*)src_;
		of_block_byref_t **dst = (of_block_byref_t**)dst_;

		if ((src->flags & ~OF_BLOCK_HAS_COPY_DISPOSE) == 0) {
			if ((*dst = malloc(src->size)) == NULL) {
				alloc_failed_exception.isa =
				    [OFAllocFailedException class];
				@throw (OFAllocFailedException*)
				    &alloc_failed_exception;
			}

			if (src->forwarding == src)
				src->forwarding = *dst;

			memcpy(*dst, src, src->size);

217
218
219
220
221
222
223

224
225
226




227
228
229
230
231
232
233
234
235
236
237
238
239
240
241











242
				obj->byref_dispose(obj);

			free(obj);
		}
		break;
	}
}


/// \cond internal
@implementation OFBlock




+ (Class)class
{
	return self;
}

- copy
{
	return Block_copy(self);
}

- (void)release
{
	Block_release(self);
}
@end











/// \endcond







>



>
>
>
>















>
>
>
>
>
>
>
>
>
>
>

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
				obj->byref_dispose(obj);

			free(obj);
		}
		break;
	}
}
#endif

/// \cond internal
@implementation OFBlock
+ (void)initialize
{
}

+ (Class)class
{
	return self;
}

- copy
{
	return Block_copy(self);
}

- (void)release
{
	Block_release(self);
}
@end

#if !defined(OF_GNU_RUNTIME) && !defined(OF_OBJFW_RUNTIME)
@implementation OFStackBlock
@end

@implementation OFGlobalBlock
@end

@implementation OFMallocBlock
@end
#endif
/// \endcond

Added src/mach_alias_list version [2e2aa5bb87].









>
>
>
>
1
2
3
4
# List of aliases for Mach-O
_OBJC_CLASS_$_OFStackBlock __NSConcreteStackBlock
_OBJC_CLASS_$_OFGlobalBlock __NSConcreteGlobalBlock
_OBJC_CLASS_$_OFMallocBlock __NSConcreteMallocBlock