summaryrefslogtreecommitdiffstats
path: root/unix/tclLoadDyld.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/tclLoadDyld.c')
-rw-r--r--unix/tclLoadDyld.c94
1 files changed, 37 insertions, 57 deletions
diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c
index 3fba3a5..0a36215 100644
--- a/unix/tclLoadDyld.c
+++ b/unix/tclLoadDyld.c
@@ -84,23 +84,13 @@ 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
-
-/*
- * Static functions defined in this file.
- */
-
-static void * FindSymbol(Tcl_Interp *interp,
- Tcl_LoadHandle loadHandle, const char *symbol);
-static void UnloadFile(Tcl_LoadHandle handle);
#if TCL_DYLD_USE_NSMODULE || defined(TCL_LOAD_FROM_MEMORY)
/*
@@ -120,7 +110,7 @@ static void UnloadFile(Tcl_LoadHandle handle);
*----------------------------------------------------------------------
*/
-static const char *
+static CONST char*
DyldOFIErrorMsg(
int err)
{
@@ -175,7 +165,6 @@ TclpDlopen(
* file. */
{
Tcl_DyldLoadHandle *dyldLoadHandle;
- Tcl_LoadHandle newHandle;
#if TCL_DYLD_USE_DLFCN
void *dlHandle = NULL;
#endif
@@ -286,7 +275,8 @@ TclpDlopen(
| NSLINKMODULE_OPTION_RETURN_ON_ERROR);
NSDestroyObjectFileImage(dyldObjFileImage);
if (module) {
- modulePtr = ckalloc(sizeof(Tcl_DyldModuleHandle));
+ modulePtr = (Tcl_DyldModuleHandle *)
+ ckalloc(sizeof(Tcl_DyldModuleHandle));
modulePtr->module = module;
modulePtr->nextPtr = NULL;
TclLoadDbgMsg("NSLinkModule() successful");
@@ -312,7 +302,8 @@ TclpDlopen(
|| dyldLibHeader || modulePtr
#endif
) {
- dyldLoadHandle = ckalloc(sizeof(Tcl_DyldLoadHandle));
+ dyldLoadHandle = (Tcl_DyldLoadHandle *)
+ ckalloc(sizeof(Tcl_DyldLoadHandle));
#if TCL_DYLD_USE_DLFCN
dyldLoadHandle->dlHandle = dlHandle;
#endif
@@ -320,12 +311,8 @@ TclpDlopen(
dyldLoadHandle->dyldLibHeader = dyldLibHeader;
dyldLoadHandle->modulePtr = modulePtr;
#endif
- newHandle = ckalloc(sizeof(*newHandle));
- newHandle->clientData = dyldLoadHandle;
- newHandle->findSymbolProcPtr = &FindSymbol;
- newHandle->unloadFileProcPtr = &UnloadFile;
- *unloadProcPtr = &UnloadFile;
- *loadHandle = newHandle;
+ *loadHandle = (Tcl_LoadHandle) dyldLoadHandle;
+ *unloadProcPtr = &TclpUnloadFile;
result = TCL_OK;
} else {
Tcl_AppendResult(interp, errMsg, NULL);
@@ -346,7 +333,7 @@ TclpDlopen(
/*
*----------------------------------------------------------------------
*
- * FindSymbol --
+ * TclpFindSymbol --
*
* Looks up a symbol, by name, through a handle associated with a
* previously loaded piece of code (shared library).
@@ -359,13 +346,13 @@ TclpDlopen(
*----------------------------------------------------------------------
*/
-static void *
-FindSymbol(
+MODULE_SCOPE Tcl_PackageInitProc *
+TclpFindSymbol(
Tcl_Interp *interp, /* For error reporting. */
Tcl_LoadHandle loadHandle, /* Handle from TclpDlopen. */
- const char *symbol) /* Symbol name to look up. */
+ CONST char *symbol) /* Symbol name to look up. */
{
- Tcl_DyldLoadHandle *dyldLoadHandle = loadHandle->clientData;
+ Tcl_DyldLoadHandle *dyldLoadHandle = (Tcl_DyldLoadHandle *) loadHandle;
Tcl_PackageInitProc *proc = NULL;
const char *errMsg = NULL;
Tcl_DString ds;
@@ -417,7 +404,8 @@ FindSymbol(
modulePtr = modulePtr->nextPtr;
}
if (modulePtr == NULL) {
- modulePtr = ckalloc(sizeof(Tcl_DyldModuleHandle));
+ modulePtr = (Tcl_DyldModuleHandle *)
+ ckalloc(sizeof(Tcl_DyldModuleHandle));
modulePtr->module = module;
modulePtr->nextPtr = dyldLoadHandle->modulePtr;
dyldLoadHandle->modulePtr = modulePtr;
@@ -452,11 +440,8 @@ FindSymbol(
#endif /* TCL_DYLD_USE_NSMODULE */
}
Tcl_DStringFree(&ds);
- if (errMsg && (interp != NULL)) {
- Tcl_AppendResult(interp, "cannot find symbol \"", symbol, "\": ",
- errMsg, NULL);
- Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol,
- NULL);
+ if (errMsg) {
+ Tcl_AppendResult(interp, errMsg, NULL);
}
return proc;
}
@@ -464,7 +449,7 @@ FindSymbol(
/*
*----------------------------------------------------------------------
*
- * UnloadFile --
+ * TclpUnloadFile --
*
* Unloads a dynamically loaded binary code file from memory. Code
* pointers in the formerly loaded file are no longer valid after calling
@@ -481,13 +466,13 @@ FindSymbol(
*----------------------------------------------------------------------
*/
-static void
-UnloadFile(
+MODULE_SCOPE void
+TclpUnloadFile(
Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to
* TclpDlopen(). The loadHandle is a token
* that represents the loaded file. */
{
- Tcl_DyldLoadHandle *dyldLoadHandle = loadHandle->clientData;
+ Tcl_DyldLoadHandle *dyldLoadHandle = (Tcl_DyldLoadHandle *) loadHandle;
#if TCL_DYLD_USE_DLFCN
if (dyldLoadHandle->dlHandle) {
@@ -522,8 +507,7 @@ UnloadFile(
}
#endif /* TCL_DYLD_USE_NSMODULE */
}
- ckfree(dyldLoadHandle);
- ckfree(loadHandle);
+ ckfree((char*) dyldLoadHandle);
}
/*
@@ -548,7 +532,7 @@ UnloadFile(
int
TclGuessPackageName(
- const char *fileName, /* Name of file containing package (already
+ CONST char *fileName, /* Name of file containing package (already
* translated to local form if needed). */
Tcl_DString *bufPtr) /* Initialized empty dstring. Append package
* name to this if possible. */
@@ -633,7 +617,6 @@ TclpLoadMemory(
* function which should be used for this
* file. */
{
- Tcl_LoadHandle newHandle;
Tcl_DyldLoadHandle *dyldLoadHandle;
NSObjectFileImage dyldObjFileImage = NULL;
Tcl_DyldModuleHandle *modulePtr;
@@ -650,14 +633,14 @@ TclpLoadMemory(
uint32_t ms = 0;
#ifndef __LP64__
const struct mach_header *mh = NULL;
-# define mh_size sizeof(struct mach_header)
-# define mh_magic MH_MAGIC
-# define arch_abi 0
+ #define mh_size sizeof(struct mach_header)
+ #define mh_magic MH_MAGIC
+ #define arch_abi 0
#else
const struct mach_header_64 *mh = NULL;
-# define mh_size sizeof(struct mach_header_64)
-# define mh_magic MH_MAGIC_64
-# define arch_abi CPU_ARCH_ABI64
+ #define mh_size sizeof(struct mach_header_64)
+ #define mh_magic MH_MAGIC_64
+ #define arch_abi CPU_ARCH_ABI64
#endif
if ((size_t) codeSize >= sizeof(struct fat_header)
@@ -768,21 +751,18 @@ TclpLoadMemory(
* Stash the module reference within the load handle we create and return.
*/
- modulePtr = ckalloc(sizeof(Tcl_DyldModuleHandle));
+ modulePtr = (Tcl_DyldModuleHandle *) ckalloc(sizeof(Tcl_DyldModuleHandle));
modulePtr->module = module;
modulePtr->nextPtr = NULL;
- dyldLoadHandle = ckalloc(sizeof(Tcl_DyldLoadHandle));
+ dyldLoadHandle = (Tcl_DyldLoadHandle *)
+ ckalloc(sizeof(Tcl_DyldLoadHandle));
#if TCL_DYLD_USE_DLFCN
dyldLoadHandle->dlHandle = NULL;
#endif
dyldLoadHandle->dyldLibHeader = NULL;
dyldLoadHandle->modulePtr = modulePtr;
- newHandle = ckalloc(sizeof(*newHandle));
- newHandle->clientData = dyldLoadHandle;
- newHandle->findSymbolProcPtr = &FindSymbol;
- newHandle->unloadFileProcPtr = &UnloadFile;
- *loadHandle = newHandle;
- *unloadProcPtr = &UnloadFile;
+ *loadHandle = (Tcl_LoadHandle) dyldLoadHandle;
+ *unloadProcPtr = &TclpUnloadFile;
return TCL_OK;
}
#endif /* TCL_LOAD_FROM_MEMORY */