summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2010-04-02 21:21:04 (GMT)
committerKevin B Kenny <kennykb@acm.org>2010-04-02 21:21:04 (GMT)
commitbd2c56d7039122dcb51ef36f39766e245c84d821 (patch)
treefe391271cb3355eb790c38ed7e17ab484df92009 /unix
parent859e9838d18c82b7c6fbcc1c9af736f6be73aecb (diff)
downloadtcl-bd2c56d7039122dcb51ef36f39766e245c84d821.zip
tcl-bd2c56d7039122dcb51ef36f39766e245c84d821.tar.gz
tcl-bd2c56d7039122dcb51ef36f39766e245c84d821.tar.bz2
* generic/tcl.decls: [TIP #357]: First round of changes
* generic/tclDecls.h: to export Tcl_LoadFile, Tcl_FindSymbol, * generic/tclIOUtil.c: and Tcl_FSUnloadFile to the public API. * generic/tclInt.h: * generic/tclLoad.c: * generic/tclLoadNone.c: * generic/tclStubInit.c: * tests/fileSystem.test: * tests/load.test: * tests/unload.test: * unix/tclLoadDl.c: * unix/tclLoadDyld.c: * unix/tclLoadNext.c: * unix/tclLoadOSF.c: * unix/tclLoadShl.c: * unix/tclUnixPipe.c: * win/Makefile.in: * win/tclWinLoad.c:
Diffstat (limited to 'unix')
-rw-r--r--unix/tclLoadDl.c42
-rw-r--r--unix/tclLoadDyld.c50
-rw-r--r--unix/tclLoadNext.c35
-rw-r--r--unix/tclLoadOSF.c38
-rw-r--r--unix/tclLoadShl.c40
-rw-r--r--unix/tclUnixPipe.c36
6 files changed, 185 insertions, 56 deletions
diff --git a/unix/tclLoadDl.c b/unix/tclLoadDl.c
index 282d5bb..802e0dd 100644
--- a/unix/tclLoadDl.c
+++ b/unix/tclLoadDl.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLoadDl.c,v 1.19 2010/03/11 15:02:33 nijtmans Exp $
+ * RCS: @(#) $Id: tclLoadDl.c,v 1.20 2010/04/02 21:21:06 kennykb Exp $
*/
#include "tclInt.h"
@@ -34,6 +34,12 @@
# define RTLD_GLOBAL 0
#endif
+/* Static procedures defined within this file */
+
+static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle,
+ const char* symbol);
+static void UnloadFile(Tcl_LoadHandle loadHandle);
+
/*
*---------------------------------------------------------------------------
*
@@ -66,6 +72,7 @@ TclpDlopen(
* file. */
{
void *handle;
+ Tcl_LoadHandle newHandle;
const char *native;
/*
@@ -103,16 +110,20 @@ TclpDlopen(
Tcl_GetString(pathPtr), "\": ", errorStr, NULL);
return TCL_ERROR;
}
+ newHandle = (Tcl_LoadHandle) ckalloc(sizeof(*newHandle));
+ newHandle->clientData = (ClientData) handle;
+ newHandle->findSymbolProcPtr = &FindSymbol;
+ newHandle->unloadFileProcPtr = &UnloadFile;
+ *unloadProcPtr = &UnloadFile;
+ *loadHandle = newHandle;
- *unloadProcPtr = &TclpUnloadFile;
- *loadHandle = (Tcl_LoadHandle) handle;
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
- * TclpFindSymbol --
+ * FindSymbol --
*
* Looks up a symbol, by name, through a handle associated with a
* previously loaded piece of code (shared library).
@@ -125,15 +136,15 @@ TclpDlopen(
*----------------------------------------------------------------------
*/
-Tcl_PackageInitProc *
-TclpFindSymbol(
+static void *
+FindSymbol(
Tcl_Interp *interp, /* Place to put error messages. */
Tcl_LoadHandle loadHandle, /* Value from TcpDlopen(). */
const char *symbol) /* Symbol to look up. */
{
const char *native;
Tcl_DString newName, ds;
- void *handle = (void *) loadHandle;
+ void *handle = (void *)(loadHandle->clientData);
Tcl_PackageInitProc *proc;
/*
@@ -154,14 +165,20 @@ TclpFindSymbol(
Tcl_DStringFree(&newName);
}
Tcl_DStringFree(&ds);
-
+ if (proc == NULL && interp != NULL) {
+ Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp, "cannot find symbol \"", symbol, "\": ",
+ dlerror(), NULL);
+ Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol,
+ NULL);
+ }
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
@@ -176,16 +193,17 @@ TclpFindSymbol(
*----------------------------------------------------------------------
*/
-void
-TclpUnloadFile(
+static void
+UnloadFile(
Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to
* TclpDlopen(). The loadHandle is a token
* that represents the loaded file. */
{
void *handle;
- handle = (void *) loadHandle;
+ handle = (void *)(loadHandle->clientData);
dlclose(handle);
+ ckfree((char*)loadHandle);
}
/*
diff --git a/unix/tclLoadDyld.c b/unix/tclLoadDyld.c
index 4b64032..2f833cd 100644
--- a/unix/tclLoadDyld.c
+++ b/unix/tclLoadDyld.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLoadDyld.c,v 1.34 2010/03/11 15:02:33 nijtmans Exp $
+ * RCS: @(#) $Id: tclLoadDyld.c,v 1.35 2010/04/02 21:21:06 kennykb Exp $
*/
#include "tclInt.h"
@@ -94,6 +94,14 @@ MODULE_SCOPE long tclMacOSXDarwinRelease;
#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)
/*
*----------------------------------------------------------------------
@@ -167,6 +175,7 @@ TclpDlopen(
* file. */
{
Tcl_DyldLoadHandle *dyldLoadHandle;
+ Tcl_LoadHandle* newHandle;
#if TCL_DYLD_USE_DLFCN
void *dlHandle = NULL;
#endif
@@ -307,8 +316,12 @@ TclpDlopen(
dyldLoadHandle->dyldLibHeader = dyldLibHeader;
dyldLoadHandle->modulePtr = modulePtr;
#endif
- *loadHandle = (Tcl_LoadHandle) dyldLoadHandle;
- *unloadProcPtr = &TclpUnloadFile;
+ newHandle = (Tcl_LoadHandle) ckalloc(sizeof(*newHandle));
+ newHandle->clientData = dyldLoadHandle;
+ newHandle->findSymbolProcPtr = &FindSymbol;
+ newHandle->unloadProcPtr = &UnloadFile;
+ *unloadProcPtr = &UnloadFile;
+ *loadHandle = newHandle;
result = TCL_OK;
} else {
Tcl_AppendResult(interp, errMsg, NULL);
@@ -329,7 +342,7 @@ TclpDlopen(
/*
*----------------------------------------------------------------------
*
- * TclpFindSymbol --
+ * FindSymbol --
*
* Looks up a symbol, by name, through a handle associated with a
* previously loaded piece of code (shared library).
@@ -342,13 +355,14 @@ TclpDlopen(
*----------------------------------------------------------------------
*/
-MODULE_SCOPE Tcl_PackageInitProc *
-TclpFindSymbol(
+static void*
+FindSymbol(
Tcl_Interp *interp, /* For error reporting. */
Tcl_LoadHandle loadHandle, /* Handle from TclpDlopen. */
const char *symbol) /* Symbol name to look up. */
{
- Tcl_DyldLoadHandle *dyldLoadHandle = (Tcl_DyldLoadHandle *) loadHandle;
+ Tcl_DyldLoadHandle *dyldLoadHandle =
+ (Tcl_DyldLoadHandle *) (loadHandle->clientData);
Tcl_PackageInitProc *proc = NULL;
const char *errMsg = NULL;
Tcl_DString ds;
@@ -436,8 +450,9 @@ TclpFindSymbol(
#endif /* TCL_DYLD_USE_NSMODULE */
}
Tcl_DStringFree(&ds);
- if (errMsg) {
+ if (errMsg && (interp != NULL)) {
Tcl_AppendResult(interp, errMsg, NULL);
+ Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, NULL);
}
return proc;
}
@@ -445,7 +460,7 @@ TclpFindSymbol(
/*
*----------------------------------------------------------------------
*
- * TclpUnloadFile --
+ * UnloadFile --
*
* Unloads a dynamically loaded binary code file from memory. Code
* pointers in the formerly loaded file are no longer valid after calling
@@ -462,13 +477,14 @@ TclpFindSymbol(
*----------------------------------------------------------------------
*/
-MODULE_SCOPE void
-TclpUnloadFile(
+static void
+UnloadFile(
Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to
* TclpDlopen(). The loadHandle is a token
* that represents the loaded file. */
{
- Tcl_DyldLoadHandle *dyldLoadHandle = (Tcl_DyldLoadHandle *) loadHandle;
+ Tcl_DyldLoadHandle *dyldLoadHandle =
+ (Tcl_DyldLoadHandle *) (loadHandle->clientData);
#if TCL_DYLD_USE_DLFCN
if (dyldLoadHandle->dlHandle) {
@@ -504,6 +520,7 @@ TclpUnloadFile(
#endif /* TCL_DYLD_USE_NSMODULE */
}
ckfree((char*) dyldLoadHandle);
+ ckfree((char*) loadHandle);
}
/*
@@ -613,6 +630,7 @@ TclpLoadMemory(
* function which should be used for this
* file. */
{
+ Tcl_LoadHandle newHandle;
Tcl_DyldLoadHandle *dyldLoadHandle;
NSObjectFileImage dyldObjFileImage = NULL;
Tcl_DyldModuleHandle *modulePtr;
@@ -757,8 +775,12 @@ TclpLoadMemory(
#endif
dyldLoadHandle->dyldLibHeader = NULL;
dyldLoadHandle->modulePtr = modulePtr;
- *loadHandle = (Tcl_LoadHandle) dyldLoadHandle;
- *unloadProcPtr = &TclpUnloadFile;
+ newHandle = (Tcl_LoadHandle) ckalloc(sizeof(*newHandle));
+ newHandle->clientData = dyldLoadHandle;
+ newHandle->findSymbolProcPtr = &FindSymbol;
+ newHandle->unloadFileProcPtr = &UnloadFile;
+ *loadHandle = newHandle;
+ *unloadProcPtr = &UnloadFile;
return TCL_OK;
}
#endif /* TCL_LOAD_FROM_MEMORY */
diff --git a/unix/tclLoadNext.c b/unix/tclLoadNext.c
index 0f82593..35aeba4 100644
--- a/unix/tclLoadNext.c
+++ b/unix/tclLoadNext.c
@@ -9,12 +9,19 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLoadNext.c,v 1.16 2010/03/11 15:02:33 nijtmans Exp $
+ * RCS: @(#) $Id: tclLoadNext.c,v 1.17 2010/04/02 21:21:06 kennykb Exp $
*/
#include "tclInt.h"
#include <mach-o/rld.h>
#include <streams/streams.h>
+
+/* Static procedures defined within this file */
+
+static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle,
+ const char* symbol);
+static void UnloadFile(Tcl_LoadHandle loadHandle);
+
/*
*----------------------------------------------------------------------
@@ -47,6 +54,7 @@ TclpDlopen(
* function which should be used for this
* file. */
{
+ Tcl_LoadHandle newHandle;
struct mach_header *header;
char *fileName;
char *files[2];
@@ -95,8 +103,12 @@ TclpDlopen(
}
NXCloseMemory(errorStream, NX_FREEBUFFER);
- *loadHandle = (Tcl_LoadHandle)1; /* A dummy non-NULL value */
- *unloadProcPtr = &TclpUnloadFile;
+ newHandle = (Tcl_LoadHandle) ckalloc(sizeof(*newHandle));
+ newHandle->clientData = (ClientData) 1;
+ newHandle->findSymbolProcPtr = &FindSymbol;
+ newHandle->unloadFileProcPtr = &UnloadFile;
+ *loadHandle = newHandle;
+ *unloadProcPtr = &UnloadFile;
return TCL_OK;
}
@@ -104,7 +116,7 @@ TclpDlopen(
/*
*----------------------------------------------------------------------
*
- * TclpFindSymbol --
+ * FindSymbol --
*
* Looks up a symbol, by name, through a handle associated with a
* previously loaded piece of code (shared library).
@@ -117,8 +129,8 @@ TclpDlopen(
*----------------------------------------------------------------------
*/
-Tcl_PackageInitProc *
-TclpFindSymbol(
+static void*
+FindSymbol(
Tcl_Interp *interp,
Tcl_LoadHandle loadHandle,
const char *symbol)
@@ -132,13 +144,19 @@ TclpFindSymbol(
strcat(sym, symbol);
rld_lookup(NULL, sym, (unsigned long *)&proc);
}
+ if (proc == NULL && interp != NULL) {
+ Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp, "cannot find symbol \"", symbol,
+ "\"", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, NULL);
+ }
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
@@ -154,11 +172,12 @@ TclpFindSymbol(
*/
void
-TclpUnloadFile(
+UnloadFile(
Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to
* TclpDlopen(). The loadHandle is a token
* that represents the loaded file. */
{
+ ckfree((char*) loadHandle);
}
/*
diff --git a/unix/tclLoadOSF.c b/unix/tclLoadOSF.c
index 136fad9..2810a7c 100644
--- a/unix/tclLoadOSF.c
+++ b/unix/tclLoadOSF.c
@@ -31,13 +31,19 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLoadOSF.c,v 1.16 2010/03/11 15:02:33 nijtmans Exp $
+ * RCS: @(#) $Id: tclLoadOSF.c,v 1.17 2010/04/02 21:21:06 kennykb Exp $
*/
#include "tclInt.h"
#include <sys/types.h>
#include <loader.h>
+/* Static functions defined within this file */
+
+static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle,
+ const char* symbol);
+static void UnloadFile(Tcl_LoadHandle handle);
+
/*
*----------------------------------------------------------------------
*
@@ -69,6 +75,7 @@ TclpDlopen(
* function which should be used for this
* file. */
{
+ Tcl_LoadHandle newHandle;
ldr_module_t lm;
char *pkg;
char *fileName = Tcl_GetString(pathPtr);
@@ -119,15 +126,19 @@ TclpDlopen(
} else {
pkg++;
}
- *loadHandle = pkg;
- *unloadProcPtr = &TclpUnloadFile;
+ newHandle = (Tcl_LoadHandle*) ckalloc(sizeof(*newHandle));
+ newHandle->clientData = pkg;
+ newHandle->findSymbolProcPtr = &FindSymbol;
+ newHandle->unloadFileProcPtr = &UnloadFile;
+ *loadHandle = newHandle;
+ *unloadProcPtr = &UnloadFile;
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
- * TclpFindSymbol --
+ * FindSymbol --
*
* Looks up a symbol, by name, through a handle associated with a
* previously loaded piece of code (shared library).
@@ -140,19 +151,25 @@ TclpDlopen(
*----------------------------------------------------------------------
*/
-Tcl_PackageInitProc *
-TclpFindSymbol(
+static void *
+FindSymbol(
Tcl_Interp *interp,
Tcl_LoadHandle loadHandle,
const char *symbol)
{
- return ldr_lookup_package((char *)loadHandle, symbol);
+ void* retval = ldr_lookup_package((char *)loadHandle, symbol);
+ if (retval == NULL && interp != NULL) {
+ Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp, "cannot find symbol\"", symbol, "\"", NULL);
+ Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "LOAD_SYMBOL", symbol, NULL);
+ }
+ return retval;
}
/*
*----------------------------------------------------------------------
*
- * TclpUnloadFile --
+ * UnloadFile --
*
* Unloads a dynamically loaded binary code file from memory. Code
* pointers in the formerly loaded file are no longer valid after calling
@@ -167,12 +184,13 @@ TclpFindSymbol(
*----------------------------------------------------------------------
*/
-void
-TclpUnloadFile(
+static void
+UnloadFile(
Tcl_LoadHandle loadHandle) /* loadHandle returned by a previous call to
* TclpDlopen(). The loadHandle is a token
* that represents the loaded file. */
{
+ ckfree((char*) loadHandle);
}
/*
diff --git a/unix/tclLoadShl.c b/unix/tclLoadShl.c
index bf46cf5..a690dac 100644
--- a/unix/tclLoadShl.c
+++ b/unix/tclLoadShl.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: tclLoadShl.c,v 1.19 2010/03/11 15:02:33 nijtmans Exp $
+ * RCS: @(#) $Id: tclLoadShl.c,v 1.20 2010/04/02 21:21:06 kennykb Exp $
*/
#include <dl.h>
@@ -25,6 +25,14 @@
#include "tclInt.h"
+/* Static functions defined within this file */
+
+static void* FindSymbol(Tcl_Interp* interp, Tcl_LoadHandle loadHandle,
+ const char* symbol);
+static void
+UnloadFile(Tcl_LoadHandle handle);
+
+
/*
*----------------------------------------------------------------------
*
@@ -57,6 +65,7 @@ TclpDlopen(
* file. */
{
shl_t handle;
+ Tcl_LoadHandle newHandle;
const char *native;
char *fileName = Tcl_GetString(pathPtr);
@@ -97,15 +106,18 @@ TclpDlopen(
Tcl_PosixError(interp), (char *) NULL);
return TCL_ERROR;
}
- *loadHandle = (Tcl_LoadHandle) handle;
- *unloadProcPtr = &TclpUnloadFile;
+ newHandle = (Tcl_LoadHandle) 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).
@@ -118,15 +130,15 @@ TclpDlopen(
*----------------------------------------------------------------------
*/
-Tcl_PackageInitProc *
-TclpFindSymbol(
+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;
+ shl_t handle = (shl_t)(loadHandle->clientData);
/*
* Some versions of the HP system software still use "_" at the beginning
@@ -144,13 +156,18 @@ TclpFindSymbol(
}
Tcl_DStringFree(&newName);
}
+ if (proc == NULL && interp != NULL) {
+ Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp, "cannot find symbol\"", symbol,
+ "\": ", Tcl_PosixError(interp), NULL);
+ }
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
@@ -165,16 +182,17 @@ TclpFindSymbol(
*----------------------------------------------------------------------
*/
-void
-TclpUnloadFile(
+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;
- handle = (shl_t) loadHandle;
+ handle = (shl_t) (loadHandle -> clientData);
shl_unload(handle);
+ ckfree((char*) loadHandle);
}
/*
diff --git a/unix/tclUnixPipe.c b/unix/tclUnixPipe.c
index 21a0153..ccb97c2 100644
--- a/unix/tclUnixPipe.c
+++ b/unix/tclUnixPipe.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: tclUnixPipe.c,v 1.51 2010/01/10 22:58:41 nijtmans Exp $
+ * RCS: @(#) $Id: tclUnixPipe.c,v 1.52 2010/04/02 21:21:06 kennykb Exp $
*/
#include "tclInt.h"
@@ -269,6 +269,40 @@ TclpTempFileName(void)
}
/*
+ *-----------------------------------------------------------------------------
+ *
+ * TclpTempFileNameForLibrary --
+ *
+ * Constructs a file name in the native file system where a
+ * dynamically loaded library may be placed.
+ *
+ * Results:
+ * Returns the constructed file name. If an error occurs,
+ * returns NULL and leaves an error message in the interpreter
+ * result.
+ *
+ * On Unix, it works to load a shared object from a file of any
+ * name, so this function is merely a thin wrapper around
+ * TclpTempFileName().
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+Tcl_Obj*
+TclpTempFileNameForLibrary(Tcl_Interp* interp, /* Tcl interpreter */
+ Tcl_Obj* path) /* Path name of the library
+ * in the VFS */
+{
+ Tcl_Obj* retval;
+ retval = TclpTempFileName();
+ if (retval == NULL) {
+ Tcl_AppendResult(interp, "couldn't create temporary file: ",
+ Tcl_PosixError(interp), NULL);
+ }
+ return retval;
+}
+
+/*
*----------------------------------------------------------------------
*
* TclpCreatePipe --