summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordas <das>2009-04-10 16:59:19 (GMT)
committerdas <das>2009-04-10 16:59:19 (GMT)
commit823edac52c51fd85660d75007473f05c8c29f84d (patch)
tree6f9e8a6a1e7bf8b7ad1ca807db57613f8eacbf88
parent7f03bcedc4828e74d510884c108c632aaae9fed2 (diff)
downloadtcl-823edac52c51fd85660d75007473f05c8c29f84d.zip
tcl-823edac52c51fd85660d75007473f05c8c29f84d.tar.gz
tcl-823edac52c51fd85660d75007473f05c8c29f84d.tar.bz2
* macosx/tclMacOSXBundle.c: on Mac OS X 10.4 and later, replace
deprecated NSModule API by dlfcn API.
-rw-r--r--ChangeLog5
-rw-r--r--macosx/tclMacOSXBundle.c87
2 files changed, 84 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 01172d7..f5e1597 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-10 Daniel Steffen <das@users.sourceforge.net>
+
+ * macosx/tclMacOSXBundle.c: on Mac OS X 10.4 and later, replace
+ deprecated NSModule API by dlfcn API.
+
2009-04-10 Donal K. Fellows <dkf@users.sf.net>
* doc/StringObj.3: [Bug 2089279]: Corrected example so that it works
diff --git a/macosx/tclMacOSXBundle.c b/macosx/tclMacOSXBundle.c
index 14be2f0..635eb7c 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.13 2008/12/07 16:28:44 das Exp $
+ * RCS: @(#) $Id: tclMacOSXBundle.c,v 1.14 2009/04/10 16:59:19 das Exp $
*/
#include "tclPort.h"
#ifdef HAVE_COREFOUNDATION
#include <CoreFoundation/CoreFoundation.h>
+
+#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 <dlfcn.h>
+#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 <mach-o/dyld.h>
+#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;
}