From 01c5ac34b88b950eb4465857577102ff071032ca Mon Sep 17 00:00:00 2001 From: das Date: Fri, 10 Apr 2009 16:59:22 +0000 Subject: * macosx/tclMacOSXBundle.c: on Mac OS X 10.4 and later, replace deprecated NSModule API by dlfcn API. --- ChangeLog | 5 +++ macosx/tclMacOSXBundle.c | 87 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 84 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79ad9e1..d036ef1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,11 @@ * tests/httpd: Backport new tests for http 2.7.3. * tests/http.tcl: +2008-04-10 Daniel Steffen + + * macosx/tclMacOSXBundle.c: on Mac OS X 10.4 and later, replace + deprecated NSModule API by dlfcn API. + 2008-04-09 Kevin B. Kenny * tools/tclZIC.tcl: Always emit Unix-style line terminators. diff --git a/macosx/tclMacOSXBundle.c b/macosx/tclMacOSXBundle.c index f9af0b9..0d12a28 100644 --- a/macosx/tclMacOSXBundle.c +++ b/macosx/tclMacOSXBundle.c @@ -48,14 +48,64 @@ * permission to use and distribute the software in accordance with the * terms specified in this license. * - * RCS: @(#) $Id: tclMacOSXBundle.c,v 1.11.4.1 2008/12/07 16:39:32 das Exp $ + * RCS: @(#) $Id: tclMacOSXBundle.c,v 1.11.4.2 2009/04/10 16:59:22 das Exp $ */ #include "tclPort.h" #ifdef HAVE_COREFOUNDATION #include + +#ifndef TCL_DYLD_USE_DLFCN +/* + * Use preferred dlfcn API on 10.4 and later + */ +# if !defined(NO_DLFCN_H) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 +# define TCL_DYLD_USE_DLFCN 1 +# else +# define TCL_DYLD_USE_DLFCN 0 +# endif +#endif + +#ifndef TCL_DYLD_USE_NSMODULE +/* + * Use deprecated NSModule API only to support 10.3 and earlier: + */ +# if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 +# define TCL_DYLD_USE_NSMODULE 1 +# else +# define TCL_DYLD_USE_NSMODULE 0 +# endif +#endif + +#if TCL_DYLD_USE_DLFCN +#include +#if defined(HAVE_WEAK_IMPORT) && MAC_OS_X_VERSION_MIN_REQUIRED < 1040 +/* + * Support for weakly importing dlfcn API. + */ +extern void *dlsym(void *handle, const char *symbol) WEAK_IMPORT_ATTRIBUTE; +extern char *dlerror(void) WEAK_IMPORT_ATTRIBUTE; +#endif +#endif + +#if TCL_DYLD_USE_NSMODULE #include +#endif + +#if TCL_DYLD_USE_DLFCN && MAC_OS_X_VERSION_MIN_REQUIRED < 1040 +MODULE_SCOPE long tclMacOSXDarwinRelease; +#endif + +#ifdef TCL_DEBUG_LOAD +#define TclLoadDbgMsg(m, ...) do { \ + fprintf(stderr, "%s:%d: %s(): " m ".\n", \ + strrchr(__FILE__, '/')+1, __LINE__, __func__, ##__VA_ARGS__); \ + } while (0) +#else +#define TclLoadDbgMsg(m, ...) +#endif + #endif /* HAVE_COREFOUNDATION */ /* @@ -192,14 +242,35 @@ Tcl_MacOSXOpenVersionedBundleResources( static short (*openresourcemap)(CFBundleRef) = NULL; if (!initialized) { - NSSymbol nsSymbol = NULL; - if (NSIsSymbolNameDefinedWithHint( - "_CFBundleOpenBundleResourceMap", "CoreFoundation")) { - nsSymbol = NSLookupAndBindSymbolWithHint( - "_CFBundleOpenBundleResourceMap","CoreFoundation"); - if (nsSymbol) { - openresourcemap = NSAddressOfSymbol(nsSymbol); +#if TCL_DYLD_USE_DLFCN +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 + if (tclMacOSXDarwinRelease >= 8) +#endif + { + const char *errMsg = nil; + openresourcemap = dlsym(RTLD_NEXT, + "CFBundleOpenBundleResourceMap"); + if (!openresourcemap) { + errMsg = dlerror(); + TclLoadDbgMsg("dlsym() failed: %s", errMsg); + } + } + if (!openresourcemap) +#endif + { +#if TCL_DYLD_USE_NSMODULE + NSSymbol nsSymbol = NULL; + if (NSIsSymbolNameDefinedWithHint( + "_CFBundleOpenBundleResourceMap", + "CoreFoundation")) { + nsSymbol = NSLookupAndBindSymbolWithHint( + "_CFBundleOpenBundleResourceMap", + "CoreFoundation"); + if (nsSymbol) { + openresourcemap = NSAddressOfSymbol(nsSymbol); + } } +#endif } initialized = TRUE; } -- cgit v0.12