summaryrefslogtreecommitdiffstats
path: root/unix/tclLoadShl.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix/tclLoadShl.c')
-rw-r--r--unix/tclLoadShl.c85
1 files changed, 47 insertions, 38 deletions
diff --git a/unix/tclLoadShl.c b/unix/tclLoadShl.c
index e8c4d32..4be3d7b 100644
--- a/unix/tclLoadShl.c
+++ b/unix/tclLoadShl.c
@@ -9,21 +9,18 @@
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: tclLoadShl.c,v 1.15 2005/10/05 04:23:28 hobbs Exp $
*/
#include <dl.h>
+#include "tclInt.h"
/*
- * On some HP machines, dl.h defines EXTERN; remove that definition.
+ * Static functions defined within this file.
*/
-#ifdef EXTERN
-# undef EXTERN
-#endif
-
-#include "tclInt.h"
+static void * FindSymbol(Tcl_Interp *interp,
+ Tcl_LoadHandle loadHandle, const char *symbol);
+static void UnloadFile(Tcl_LoadHandle handle);
/*
*----------------------------------------------------------------------
@@ -44,20 +41,22 @@
*/
int
-TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
- Tcl_Interp *interp; /* Used for error reporting. */
- Tcl_Obj *pathPtr; /* Name of the file containing the desired
+TclpDlopen(
+ Tcl_Interp *interp, /* Used for error reporting. */
+ Tcl_Obj *pathPtr, /* Name of the file containing the desired
* code (UTF-8). */
- Tcl_LoadHandle *loadHandle; /* Filled with token for dynamically loaded
+ Tcl_LoadHandle *loadHandle, /* Filled with token for dynamically loaded
* file which will be passed back to
* (*unloadProcPtr)() to unload the file. */
- Tcl_FSUnloadFileProc **unloadProcPtr;
+ Tcl_FSUnloadFileProc **unloadProcPtr,
/* Filled with address of Tcl_FSUnloadFileProc
* function which should be used for this
* file. */
+ int flags)
{
shl_t handle;
- CONST char *native;
+ Tcl_LoadHandle newHandle;
+ const char *native;
char *fileName = Tcl_GetString(pathPtr);
/*
@@ -93,19 +92,23 @@ TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
}
if (handle == NULL) {
- Tcl_AppendResult(interp, "couldn't load file \"", fileName, "\": ",
- Tcl_PosixError(interp), (char *) NULL);
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "couldn't load file \"%s\": %s",
+ fileName, Tcl_PosixError(interp)));
return TCL_ERROR;
}
- *loadHandle = (Tcl_LoadHandle) handle;
- *unloadProcPtr = &TclpUnloadFile;
+ newHandle = ckalloc(sizeof(*newHandle));
+ newHandle->clientData = handle;
+ newHandle->findSymbolProcPtr = &FindSymbol;
+ newHandle->unloadFileProcPtr = *unloadProcPtr = &UnloadFile;
+ *loadHandle = newHandle;
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
- * TclpFindSymbol --
+ * Tcl_FindSymbol --
*
* Looks up a symbol, by name, through a handle associated with a
* previously loaded piece of code (shared library).
@@ -117,15 +120,16 @@ TclpDlopen(interp, pathPtr, loadHandle, unloadProcPtr)
*
*----------------------------------------------------------------------
*/
-Tcl_PackageInitProc*
-TclpFindSymbol(interp, loadHandle, symbol)
- Tcl_Interp *interp;
- Tcl_LoadHandle loadHandle;
- CONST char *symbol;
+
+static void*
+FindSymbol(
+ Tcl_Interp *interp,
+ Tcl_LoadHandle loadHandle,
+ const char *symbol)
{
Tcl_DString newName;
- Tcl_PackageInitProc *proc=NULL;
- shl_t handle = (shl_t)loadHandle;
+ Tcl_PackageInitProc *proc = NULL;
+ shl_t handle = (shl_t) loadHandle->clientData;
/*
* Some versions of the HP system software still use "_" at the beginning
@@ -135,7 +139,7 @@ TclpFindSymbol(interp, loadHandle, symbol)
if (shl_findsym(&handle, symbol, (short) TYPE_PROCEDURE,
(void *) &proc) != 0) {
Tcl_DStringInit(&newName);
- Tcl_DStringAppend(&newName, "_", 1);
+ TclDStringAppendLiteral(&newName, "_");
Tcl_DStringAppend(&newName, symbol, -1);
if (shl_findsym(&handle, Tcl_DStringValue(&newName),
(short) TYPE_PROCEDURE, (void *) &proc) != 0) {
@@ -143,13 +147,18 @@ TclpFindSymbol(interp, loadHandle, symbol)
}
Tcl_DStringFree(&newName);
}
+ if (proc == NULL && interp != NULL) {
+ Tcl_SetObjResult(interp, Tcl_ObjPrintf(
+ "cannot find symbol \"%s\": %s",
+ symbol, Tcl_PosixError(interp)));
+ }
return proc;
}
/*
*----------------------------------------------------------------------
*
- * TclpUnloadFile --
+ * UnloadFile --
*
* Unloads a dynamically loaded binary code file from memory. Code
* pointers in the formerly loaded file are no longer valid after calling
@@ -164,16 +173,16 @@ TclpFindSymbol(interp, loadHandle, symbol)
*----------------------------------------------------------------------
*/
-void
-TclpUnloadFile(loadHandle)
- Tcl_LoadHandle loadHandle; /* loadHandle returned by a previous call to
- * TclpDlopen(). The loadHandle is a token
+static void
+UnloadFile(
+ Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to
+ * TclpDlopen(). The loadHandle is a token
* that represents the loaded file. */
{
- shl_t handle;
+ shl_t handle = (shl_t) loadHandle->clientData;
- handle = (shl_t) loadHandle;
shl_unload(handle);
+ ckfree(loadHandle);
}
/*
@@ -187,7 +196,7 @@ TclpUnloadFile(loadHandle)
* Results:
* Always returns 0 to indicate that we couldn't figure out a package
* name; generic code will then try to guess the package from the file
- * name. A return value of 1 would have meant that we figured out the
+ * name. A return value of 1 would have meant that we figured out the
* package name and put it in bufPtr.
*
* Side effects:
@@ -197,10 +206,10 @@ TclpUnloadFile(loadHandle)
*/
int
-TclGuessPackageName(fileName, bufPtr)
- CONST char *fileName; /* Name of file containing package (already
+TclGuessPackageName(
+ const char *fileName, /* Name of file containing package (already
* translated to local form if needed). */
- Tcl_DString *bufPtr; /* Initialized empty dstring. Append package
+ Tcl_DString *bufPtr) /* Initialized empty dstring. Append package
* name to this if possible. */
{
return 0;