summaryrefslogtreecommitdiffstats
path: root/macosx/tclMacOSXBundle.c
diff options
context:
space:
mode:
Diffstat (limited to 'macosx/tclMacOSXBundle.c')
-rw-r--r--macosx/tclMacOSXBundle.c164
1 files changed, 68 insertions, 96 deletions
diff --git a/macosx/tclMacOSXBundle.c b/macosx/tclMacOSXBundle.c
index dad3733..b2a88e5 100644
--- a/macosx/tclMacOSXBundle.c
+++ b/macosx/tclMacOSXBundle.c
@@ -25,7 +25,7 @@
# else
# define TCL_DYLD_USE_DLFCN 0
# endif
-#endif /* TCL_DYLD_USE_DLFCN */
+#endif
#ifndef TCL_DYLD_USE_NSMODULE
/*
@@ -36,7 +36,7 @@
# else
# define TCL_DYLD_USE_NSMODULE 0
# endif
-#endif /* TCL_DYLD_USE_NSMODULE */
+#endif
#if TCL_DYLD_USE_DLFCN
#include <dlfcn.h>
@@ -44,11 +44,10 @@
/*
* Support for weakly importing dlfcn API.
*/
-extern void * dlsym(void *handle, const char *symbol)
- WEAK_IMPORT_ATTRIBUTE;
-extern char * dlerror(void) WEAK_IMPORT_ATTRIBUTE;
+extern void *dlsym(void *handle, const char *symbol) WEAK_IMPORT_ATTRIBUTE;
+extern char *dlerror(void) WEAK_IMPORT_ATTRIBUTE;
+#endif
#endif
-#endif /* TCL_DYLD_USE_DLFCN */
#if TCL_DYLD_USE_NSMODULE
#include <mach-o/dyld.h>
@@ -56,92 +55,20 @@ extern char * dlerror(void) WEAK_IMPORT_ATTRIBUTE;
#if (TCL_DYLD_USE_DLFCN && MAC_OS_X_VERSION_MIN_REQUIRED < 1040) || \
(MAC_OS_X_VERSION_MIN_REQUIRED < 1050)
-MODULE_SCOPE long tclMacOSXDarwinRelease;
+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)
+#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 /* TCL_DEBUG_LOAD */
-
-/*
- * Forward declaration of functions defined in this file:
- */
-
-static short OpenResourceMap(CFBundleRef bundleRef);
-
-#endif /* HAVE_COREFOUNDATION */
-
-/*
- *----------------------------------------------------------------------
- *
- * OpenResourceMap --
- *
- * Wrapper that dynamically acquires the address for the function
- * CFBundleOpenBundleResourceMap before calling it, since it is only
- * present in full CoreFoundation on Mac OS X and not in CFLite on pure
- * Darwin. Factored out because it is moderately ugly code.
- *
- *----------------------------------------------------------------------
- */
-
-#ifdef HAVE_COREFOUNDATION
-
-static short
-OpenResourceMap(
- CFBundleRef bundleRef)
-{
- static int initialized = FALSE;
- static short (*openresourcemap)(CFBundleRef) = NULL;
-
- if (!initialized) {
-#if TCL_DYLD_USE_DLFCN
-#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040
- if (tclMacOSXDarwinRelease >= 8)
#endif
- {
- openresourcemap = dlsym(RTLD_NEXT,
- "CFBundleOpenBundleResourceMap");
-#ifdef TCL_DEBUG_LOAD
- if (!openresourcemap) {
- const char *errMsg = dlerror();
-
- TclLoadDbgMsg("dlsym() failed: %s", errMsg);
- }
-#endif /* TCL_DEBUG_LOAD */
- }
- if (!openresourcemap)
-#endif /* TCL_DYLD_USE_DLFCN */
- {
-#if TCL_DYLD_USE_NSMODULE
- if (NSIsSymbolNameDefinedWithHint(
- "_CFBundleOpenBundleResourceMap", "CoreFoundation")) {
- NSSymbol nsSymbol = NSLookupAndBindSymbolWithHint(
- "_CFBundleOpenBundleResourceMap", "CoreFoundation");
-
- if (nsSymbol) {
- openresourcemap = NSAddressOfSymbol(nsSymbol);
- }
- }
-#endif /* TCL_DYLD_USE_NSMODULE */
- }
- initialized = TRUE;
- }
-
- if (openresourcemap) {
- return openresourcemap(bundleRef);
- }
- return -1;
-}
#endif /* HAVE_COREFOUNDATION */
-
+
/*
*----------------------------------------------------------------------
*
@@ -165,13 +92,13 @@ OpenResourceMap(
int
Tcl_MacOSXOpenBundleResources(
Tcl_Interp *interp,
- const char *bundleName,
+ CONST char *bundleName,
int hasResourceFile,
int maxPathLen,
char *libraryPath)
{
- return Tcl_MacOSXOpenVersionedBundleResources(interp, bundleName, NULL,
- hasResourceFile, maxPathLen, libraryPath);
+ return Tcl_MacOSXOpenVersionedBundleResources(interp, bundleName,
+ NULL, hasResourceFile, maxPathLen, libraryPath);
}
/*
@@ -198,8 +125,8 @@ Tcl_MacOSXOpenBundleResources(
int
Tcl_MacOSXOpenVersionedBundleResources(
Tcl_Interp *interp,
- const char *bundleName,
- const char *bundleVersion,
+ CONST char *bundleName,
+ CONST char *bundleVersion,
int hasResourceFile,
int maxPathLen,
char *libraryPath)
@@ -266,7 +193,52 @@ Tcl_MacOSXOpenVersionedBundleResources(
if (bundleRef) {
if (hasResourceFile) {
- (void) OpenResourceMap(bundleRef);
+ /*
+ * Dynamically acquire address for CFBundleOpenBundleResourceMap
+ * symbol, since it is only present in full CoreFoundation on Mac
+ * OS X and not in CFLite on pure Darwin.
+ */
+
+ static int initialized = FALSE;
+ static short (*openresourcemap)(CFBundleRef) = NULL;
+
+ if (!initialized) {
+#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;
+ }
+
+ if (openresourcemap) {
+ openresourcemap(bundleRef);
+ }
}
libURL = CFBundleCopyResourceURL(bundleRef, CFSTR("Scripts"),
@@ -279,15 +251,12 @@ Tcl_MacOSXOpenVersionedBundleResources(
*/
CFURLGetFileSystemRepresentation(libURL, TRUE,
- (unsigned char *) libraryPath, maxPathLen);
+ (unsigned char*) libraryPath, maxPathLen);
CFRelease(libURL);
}
if (versionedBundleRef) {
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1050
- /*
- * Workaround CFBundle bug in Tiger and earlier. [Bug 2569449]
- */
-
+ /* Workaround CFBundle bug in Tiger and earlier. [Bug 2569449] */
if (tclMacOSXDarwinRelease >= 9)
#endif
{
@@ -298,9 +267,12 @@ Tcl_MacOSXOpenVersionedBundleResources(
if (libraryPath[0]) {
return TCL_OK;
+ } else {
+ return TCL_ERROR;
}
-#endif /* HAVE_COREFOUNDATION */
+#else /* HAVE_COREFOUNDATION */
return TCL_ERROR;
+#endif /* HAVE_COREFOUNDATION */
}
/*