ObjFW  Check-in [c70fd7d7f3]

Overview
Comment:Never override CoreFoundations's forward handler

If an application links ObjFW and (Core)Foundation, overriding
CoreFoundation's forward handler breaks things.

Before this commit, this only worked depending on the load order: If
ObjFW was loaded first, everything was fine, as CoreFoundation would
just override ObjFW's forward handler. However, if CoreFoundation would
be loaded first, ObjFW would override CoreFoundation's forward handler
and break CoreFoundation.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c70fd7d7f3c396b2e9f523a0dd159ad62667393745cc1a807e63ba54439549c7
User & Date: js on 2016-10-08 15:57:45
Other Links: manifest | tags
Context
2016-10-08
15:57
OFStdIOStream: Add -[columns] and -[rows] check-in: b317a4d56d user: js tags: trunk
15:57
Never override CoreFoundations's forward handler check-in: c70fd7d7f3 user: js tags: trunk
15:57
scrypt: Add swaps for big endian systems check-in: 33b1eb8387 user: js tags: trunk
Changes

Modified configure.ac from [5e3c6c916d] to [97ecf45660].

402
403
404
405
406
407
408

409
410
411
412
413
414
415
])

case "$host_os" in
	darwin*)
		AC_SUBST(LDFLAGS_REEXPORT, ["-Wl,-reexport-lobjfw"])
		AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
			AC_SUBST(REEXPORT_LIBOBJC, ["-Wl,-reexport-lobjc"])

		])

		AS_IF([test x"$objc_runtime" = x"ObjFW runtime"], [
			AS_IF([test x"$exception_type" = x"DWARF"], [
				LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_v0"
			])
			AS_IF([test x"$exception_type" = x"SjLj"], [







>







402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
])

case "$host_os" in
	darwin*)
		AC_SUBST(LDFLAGS_REEXPORT, ["-Wl,-reexport-lobjfw"])
		AS_IF([test x"$objc_runtime" = x"Apple runtime"], [
			AC_SUBST(REEXPORT_LIBOBJC, ["-Wl,-reexport-lobjc"])
			LDFLAGS="$LDFLAGS -Wl,-U,_CFRetain"
		])

		AS_IF([test x"$objc_runtime" = x"ObjFW runtime"], [
			AS_IF([test x"$exception_type" = x"DWARF"], [
				LDFLAGS="$LDFLAGS -Wl,-U,___gxx_personality_v0"
			])
			AS_IF([test x"$exception_type" = x"SjLj"], [

Modified src/OFObject.m from [a2a40a09cb] to [efb4532301].

54
55
56
57
58
59
60




61
62
63
64
65
66
67

#import "instance.h"
#if defined(OF_HAVE_ATOMIC_OPS)
# import "atomic.h"
#elif defined(OF_HAVE_THREADS)
# import "threading.h"
#endif





#if defined(OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR)
extern id of_forward(id, SEL, ...);
extern struct stret of_forward_stret(id, SEL, ...);
#else
# define of_forward of_method_not_found
# define of_forward_stret of_method_not_found_stret







>
>
>
>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

#import "instance.h"
#if defined(OF_HAVE_ATOMIC_OPS)
# import "atomic.h"
#elif defined(OF_HAVE_THREADS)
# import "threading.h"
#endif

#ifdef OF_APPLE_RUNTIME
extern void* CFRetain(void*) __attribute__((__weak__));
#endif

#if defined(OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR)
extern id of_forward(id, SEL, ...);
extern struct stret of_forward_stret(id, SEL, ...);
#else
# define of_forward of_method_not_found
# define of_forward_stret of_method_not_found_stret
211
212
213
214
215
216
217









218

219
220
221
222
223
224
225
+ (void)load
{
#if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__)
	objc_setUncaughtExceptionHandler(uncaughtExceptionHandler);
#endif

#if defined(OF_APPLE_RUNTIME)









	objc_setForwardHandler((void*)&of_forward, (void*)&of_forward_stret);

#else
	objc_setForwardHandler((IMP)&of_forward, (IMP)&of_forward_stret);
#endif

	objc_setEnumerationMutationHandler(enumerationMutationHandler);

	of_hash_seed = 0;







>
>
>
>
>
>
>
>
>
|
>







215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
+ (void)load
{
#if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__)
	objc_setUncaughtExceptionHandler(uncaughtExceptionHandler);
#endif

#if defined(OF_APPLE_RUNTIME)
	/*
	 * If the CFRetain symbol is defined, we are linked against
	 * CoreFoundation. Since CoreFoundation sets its own forward handler
	 * on load, we should not set ours, as this will break CoreFoundation.
	 *
	 * Unfortunately, there is no way to check if a forward handler has
	 * already been set, so this is the best we can do.
	 */
	if (&CFRetain == NULL)
		objc_setForwardHandler((void*)&of_forward,
		    (void*)&of_forward_stret);
#else
	objc_setForwardHandler((IMP)&of_forward, (IMP)&of_forward_stret);
#endif

	objc_setEnumerationMutationHandler(enumerationMutationHandler);

	of_hash_seed = 0;