summaryrefslogtreecommitdiffstats
path: root/macosx/tclMacOSXBundle.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2010-03-25 14:02:10 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2010-03-25 14:02:10 (GMT)
commit851cf874f33c0a191357ff2968e12e7a91147b85 (patch)
tree39a27674f3c5208bf5305d3b1756ae1ca4bc58f4 /macosx/tclMacOSXBundle.c
parent6eb70f006fff06733664d05b19756a3e8e06dce8 (diff)
downloadtcl-851cf874f33c0a191357ff2968e12e7a91147b85.zip
tcl-851cf874f33c0a191357ff2968e12e7a91147b85.tar.gz
tcl-851cf874f33c0a191357ff2968e12e7a91147b85.tar.bz2
* macosx/tclMacOSXBundle.c, macosx/tclMacOSXFCmd.c:
* macosx/tclMacOSXNotify.c: Reduce the level of ifdeffery in the functions of these files to improve readability. They need to be audited for whether complexity can be removed based on the minimum supported version of OSX, but that requires a real expert.
Diffstat (limited to 'macosx/tclMacOSXBundle.c')
-rw-r--r--macosx/tclMacOSXBundle.c153
1 files changed, 86 insertions, 67 deletions
diff --git a/macosx/tclMacOSXBundle.c b/macosx/tclMacOSXBundle.c
index 97124cf..1748ee3 100644
--- a/macosx/tclMacOSXBundle.c
+++ b/macosx/tclMacOSXBundle.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclMacOSXBundle.c,v 1.16 2009/10/05 02:41:07 das Exp $
+ * RCS: @(#) $Id: tclMacOSXBundle.c,v 1.17 2010/03/25 14:02:11 dkf Exp $
*/
#include "tclPort.h"
@@ -27,7 +27,7 @@
# else
# define TCL_DYLD_USE_DLFCN 0
# endif
-#endif
+#endif /* TCL_DYLD_USE_DLFCN */
#ifndef TCL_DYLD_USE_NSMODULE
/*
@@ -38,7 +38,7 @@
# else
# define TCL_DYLD_USE_NSMODULE 0
# endif
-#endif
+#endif /* TCL_DYLD_USE_NSMODULE */
#if TCL_DYLD_USE_DLFCN
#include <dlfcn.h>
@@ -46,10 +46,11 @@
/*
* 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
+extern void * dlsym(void *handle, const char *symbol)
+ WEAK_IMPORT_ATTRIBUTE;
+extern char * dlerror(void) WEAK_IMPORT_ATTRIBUTE;
#endif
+#endif /* TCL_DYLD_USE_DLFCN */
#if TCL_DYLD_USE_NSMODULE
#include <mach-o/dyld.h>
@@ -57,21 +58,89 @@ 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
+#endif /* TCL_DEBUG_LOAD */
#endif /* HAVE_COREFOUNDATION */
/*
+ * Forward declaration of functions defined in this file:
+ */
+
+static short OpenResourceMap(CFBundleRef bundleRef);
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * 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.
+ *
+ *----------------------------------------------------------------------
+ */
+
+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;
+}
+
+/*
*----------------------------------------------------------------------
*
* Tcl_MacOSXOpenBundleResources --
@@ -99,8 +168,8 @@ Tcl_MacOSXOpenBundleResources(
int maxPathLen,
char *libraryPath)
{
- return Tcl_MacOSXOpenVersionedBundleResources(interp, bundleName,
- NULL, hasResourceFile, maxPathLen, libraryPath);
+ return Tcl_MacOSXOpenVersionedBundleResources(interp, bundleName, NULL,
+ hasResourceFile, maxPathLen, libraryPath);
}
/*
@@ -195,54 +264,7 @@ Tcl_MacOSXOpenVersionedBundleResources(
if (bundleRef) {
if (hasResourceFile) {
- /*
- * 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) {
- short refNum;
-
- refNum = openresourcemap(bundleRef);
- }
+ (void) OpenResourceMap(bundleRef);
}
libURL = CFBundleCopyResourceURL(bundleRef, CFSTR("Scripts"),
@@ -255,7 +277,7 @@ Tcl_MacOSXOpenVersionedBundleResources(
*/
CFURLGetFileSystemRepresentation(libURL, TRUE,
- (unsigned char*) libraryPath, maxPathLen);
+ (unsigned char *) libraryPath, maxPathLen);
CFRelease(libURL);
}
if (versionedBundleRef) {
@@ -271,12 +293,9 @@ Tcl_MacOSXOpenVersionedBundleResources(
if (libraryPath[0]) {
return TCL_OK;
- } else {
- return TCL_ERROR;
}
-#else /* HAVE_COREFOUNDATION */
- return TCL_ERROR;
#endif /* HAVE_COREFOUNDATION */
+ return TCL_ERROR;
}
/*