summaryrefslogtreecommitdiffstats
path: root/unix/dltest
diff options
context:
space:
mode:
Diffstat (limited to 'unix/dltest')
-rw-r--r--unix/dltest/Makefile.in77
-rw-r--r--unix/dltest/README4
-rw-r--r--unix/dltest/pkga.c61
-rw-r--r--unix/dltest/pkgb.c79
-rw-r--r--unix/dltest/pkgc.c75
-rw-r--r--unix/dltest/pkgd.c72
-rw-r--r--unix/dltest/pkge.c25
-rw-r--r--unix/dltest/pkgf.c51
-rw-r--r--unix/dltest/pkgua.c332
9 files changed, 552 insertions, 224 deletions
diff --git a/unix/dltest/Makefile.in b/unix/dltest/Makefile.in
index c0b2659..01589d9 100644
--- a/unix/dltest/Makefile.in
+++ b/unix/dltest/Makefile.in
@@ -2,15 +2,17 @@
# command. It also illustrates how to take advantage of configuration
# exported by Tcl to set up Makefiles for shared libraries.
-TCL_DBGX = @TCL_DBGX@
CC = @CC@
-LIBS = @TCL_BUILD_STUB_LIB_SPEC@ @DL_LIBS@ @LIBS@ @MATH_LIBS@
+LIBS = @TCL_BUILD_STUB_LIB_SPEC@ @TCL_LIBS@
AC_FLAGS = @DEFS@
-SHLIB_CFLAGS = @SHLIB_CFLAGS@
SHLIB_LD = @SHLIB_LD@
+SHLIB_CFLAGS = @SHLIB_CFLAGS@
SHLIB_LD_LIBS = @SHLIB_LD_LIBS@
SHLIB_SUFFIX = @SHLIB_SUFFIX@
-SRC_DIR = @srcdir@
+DLTEST_LD = @DLTEST_LD@
+DLTEST_SUFFIX = @DLTEST_SUFFIX@
+SRC_DIR = @TCL_SRC_DIR@/unix/dltest
+BUILD_DIR = @builddir@
TCL_VERSION= @TCL_VERSION@
CFLAGS_DEBUG = @CFLAGS_DEBUG@
@@ -20,39 +22,80 @@ LDFLAGS_DEBUG = @LDFLAGS_DEBUG@
LDFLAGS_OPTIMIZE = @LDFLAGS_OPTIMIZE@
LDFLAGS = @LDFLAGS_DEFAULT@ @LDFLAGS@
-CC_SWITCHES = $(CFLAGS) -I${SRC_DIR}/../../generic -DTCL_MEM_DEBUG \
+CC_SWITCHES = $(CFLAGS) -I${SRC_DIR}/../../generic -I${BUILD_DIR}/.. -DTCL_MEM_DEBUG \
${SHLIB_CFLAGS} -DUSE_TCL_STUBS ${AC_FLAGS}
-all: pkga${SHLIB_SUFFIX} pkgb${SHLIB_SUFFIX} pkgc${SHLIB_SUFFIX} pkgd${SHLIB_SUFFIX} pkge${SHLIB_SUFFIX}
+all: pkga${SHLIB_SUFFIX} pkgb${SHLIB_SUFFIX} pkgc${SHLIB_SUFFIX} pkgd${SHLIB_SUFFIX} pkge${SHLIB_SUFFIX} pkgua${SHLIB_SUFFIX}
+ @if test -n "$(DLTEST_SUFFIX)"; then $(MAKE) dltest_suffix; fi
+ @touch ../dltest.marker
+
+dltest_suffix: pkga${DLTEST_SUFFIX} pkgb${DLTEST_SUFFIX} pkgc${DLTEST_SUFFIX} pkgd${DLTEST_SUFFIX} pkge${DLTEST_SUFFIX} pkgua${DLTEST_SUFFIX}
@touch ../dltest.marker
-pkga${SHLIB_SUFFIX}: $(SRC_DIR)/pkga.c
+pkga.o: $(SRC_DIR)/pkga.c
$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/pkga.c
- ${SHLIB_LD} -o pkga${SHLIB_SUFFIX} pkga.o ${SHLIB_LD_LIBS}
-pkgb${SHLIB_SUFFIX}: $(SRC_DIR)/pkgb.c
+pkgb.o: $(SRC_DIR)/pkgb.c
$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/pkgb.c
- ${SHLIB_LD} -o pkgb${SHLIB_SUFFIX} pkgb.o ${SHLIB_LD_LIBS}
-pkgc${SHLIB_SUFFIX}: $(SRC_DIR)/pkgc.c
+pkgc.o: $(SRC_DIR)/pkgc.c
$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/pkgc.c
- ${SHLIB_LD} -o pkgc${SHLIB_SUFFIX} pkgc.o ${SHLIB_LD_LIBS}
-pkgd${SHLIB_SUFFIX}: $(SRC_DIR)/pkgd.c
+pkgd.o: $(SRC_DIR)/pkgd.c
$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/pkgd.c
- ${SHLIB_LD} -o pkgd${SHLIB_SUFFIX} pkgd.o ${SHLIB_LD_LIBS}
-pkge${SHLIB_SUFFIX}: $(SRC_DIR)/pkge.c
+pkge.o: $(SRC_DIR)/pkge.c
$(CC) -c $(CC_SWITCHES) $(SRC_DIR)/pkge.c
+
+pkgua.o: $(SRC_DIR)/pkgua.c
+ $(CC) -c $(CC_SWITCHES) $(SRC_DIR)/pkgua.c
+
+pkga${SHLIB_SUFFIX}: pkga.o
+ ${SHLIB_LD} -o pkga${SHLIB_SUFFIX} pkga.o ${SHLIB_LD_LIBS}
+
+pkgb${SHLIB_SUFFIX}: pkgb.o
+ ${SHLIB_LD} -o pkgb${SHLIB_SUFFIX} pkgb.o ${SHLIB_LD_LIBS}
+
+pkgc${SHLIB_SUFFIX}: pkgc.o
+ ${SHLIB_LD} -o pkgc${SHLIB_SUFFIX} pkgc.o ${SHLIB_LD_LIBS}
+
+pkgd${SHLIB_SUFFIX}: pkgd.o
+ ${SHLIB_LD} -o pkgd${SHLIB_SUFFIX} pkgd.o ${SHLIB_LD_LIBS}
+
+pkge${SHLIB_SUFFIX}: pkge.o
${SHLIB_LD} -o pkge${SHLIB_SUFFIX} pkge.o ${SHLIB_LD_LIBS}
+pkgua${SHLIB_SUFFIX}: pkgua.o
+ ${SHLIB_LD} -o pkgua${SHLIB_SUFFIX} pkgua.o ${SHLIB_LD_LIBS}
+
+pkga${DLTEST_SUFFIX}: pkga.o
+ ${DLTEST_LD} -o pkga${DLTEST_SUFFIX} pkga.o ${SHLIB_LD_LIBS}
+
+pkgb${DLTEST_SUFFIX}: pkgb.o
+ ${DLTEST_LD} -o pkgb${DLTEST_SUFFIX} pkgb.o ${SHLIB_LD_LIBS}
+
+pkgc${DLTEST_SUFFIX}: pkgc.o
+ ${DLTEST_LD} -o pkgc${DLTEST_SUFFIX} pkgc.o ${SHLIB_LD_LIBS}
+
+pkgd${DLTEST_SUFFIX}: pkgd.o
+ ${DLTEST_LD} -o pkgd${DLTEST_SUFFIX} pkgd.o ${SHLIB_LD_LIBS}
+
+pkge${DLTEST_SUFFIX}: pkge.o
+ ${DLTEST_LD} -o pkge${DLTEST_SUFFIX} pkge.o ${SHLIB_LD_LIBS}
+
+pkgua${DLTEST_SUFFIX}: pkgua.o
+ ${DLTEST_LD} -o pkgua${DLTEST_SUFFIX} pkgua.o ${SHLIB_LD_LIBS}
+
clean:
- rm -f *.o config.cache config.log config.status
- rm -f lib.exp ../dltest.marker
+ rm -f *.o lib.exp ../dltest.marker
@if test "$(SHLIB_SUFFIX)" != ""; then \
echo "rm -f *${SHLIB_SUFFIX}" ; \
rm -f *${SHLIB_SUFFIX} ; \
fi
+ @if test "$(DLTEST_SUFFIX)" != ""; then \
+ echo "rm -f *${DLTEST_SUFFIX}" ; \
+ rm -f *${DLTEST_SUFFIX} ; \
+ fi
distclean: clean
rm -f Makefile
diff --git a/unix/dltest/README b/unix/dltest/README
index 73f1cd1..3210f13 100644
--- a/unix/dltest/README
+++ b/unix/dltest/README
@@ -1,4 +1,4 @@
This directory contains several files for testing Tcl's dynamic
-loading capabilities. If shared libraries are supported then
-the build system in the parent directory will create
+loading/unloading capabilities. If shared libraries are supported
+then the build system in the parent directory will create
the shared libs and load them into the tcltest executable.
diff --git a/unix/dltest/pkga.c b/unix/dltest/pkga.c
index 85c9ebb..f001cdf 100644
--- a/unix/dltest/pkga.c
+++ b/unix/dltest/pkga.c
@@ -1,33 +1,34 @@
-/*
+/*
* pkga.c --
*
- * This file contains a simple Tcl package "pkga" that is intended
- * for testing the Tcl dynamic loading facilities.
+ * This file contains a simple Tcl package "pkga" that is intended for
+ * testing the Tcl dynamic loading facilities.
*
* Copyright (c) 1995 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
+
#include "tcl.h"
/*
* Prototypes for procedures defined later in this file:
*/
-static int Pkga_EqObjCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
-static int Pkga_QuoteObjCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
+static int Pkga_EqObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
+static int Pkga_QuoteObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
/*
*----------------------------------------------------------------------
*
* Pkga_EqObjCmd --
*
- * This procedure is invoked to process the "pkga_eq" Tcl command.
- * It expects two arguments and returns 1 if they are the same,
- * 0 if they are different.
+ * This procedure is invoked to process the "pkga_eq" Tcl command. It
+ * expects two arguments and returns 1 if they are the same, 0 if they
+ * are different.
*
* Results:
* A standard Tcl result.
@@ -39,11 +40,11 @@ static int Pkga_QuoteObjCmd _ANSI_ARGS_((ClientData clientData,
*/
static int
-Pkga_EqObjCmd(dummy, interp, objc, objv)
- ClientData dummy; /* Not used. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj * CONST objv[]; /* Argument objects. */
+Pkga_EqObjCmd(
+ ClientData dummy, /* Not used. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
int result;
CONST char *str1, *str2;
@@ -70,8 +71,8 @@ Pkga_EqObjCmd(dummy, interp, objc, objv)
*
* Pkga_QuoteObjCmd --
*
- * This procedure is invoked to process the "pkga_quote" Tcl command.
- * It expects one argument, which it returns as result.
+ * This procedure is invoked to process the "pkga_quote" Tcl command. It
+ * expects one argument, which it returns as result.
*
* Results:
* A standard Tcl result.
@@ -83,11 +84,11 @@ Pkga_EqObjCmd(dummy, interp, objc, objv)
*/
static int
-Pkga_QuoteObjCmd(dummy, interp, objc, objv)
- ClientData dummy; /* Not used. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj * CONST objv[]; /* Argument strings. */
+Pkga_QuoteObjCmd(
+ ClientData dummy, /* Not used. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument strings. */
{
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "value");
@@ -102,8 +103,8 @@ Pkga_QuoteObjCmd(dummy, interp, objc, objv)
*
* Pkga_Init --
*
- * This is a package initialization procedure, which is called
- * by Tcl when this package is to be added to an interpreter.
+ * This is a package initialization procedure, which is called by Tcl
+ * when this package is to be added to an interpreter.
*
* Results:
* None.
@@ -115,13 +116,13 @@ Pkga_QuoteObjCmd(dummy, interp, objc, objv)
*/
int
-Pkga_Init(interp)
- Tcl_Interp *interp; /* Interpreter in which the package is
- * to be made available. */
+Pkga_Init(
+ Tcl_Interp *interp) /* Interpreter in which the package is to be
+ * made available. */
{
int code;
- if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) {
+ if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
return TCL_ERROR;
}
code = Tcl_PkgProvide(interp, "Pkga", "1.0");
diff --git a/unix/dltest/pkgb.c b/unix/dltest/pkgb.c
index d7a7e5b..51c1bd9 100644
--- a/unix/dltest/pkgb.c
+++ b/unix/dltest/pkgb.c
@@ -1,33 +1,34 @@
-/*
+/*
* pkgb.c --
*
- * This file contains a simple Tcl package "pkgb" that is intended
- * for testing the Tcl dynamic loading facilities. It can be used
- * in both safe and unsafe interpreters.
+ * This file contains a simple Tcl package "pkgb" that is intended for
+ * testing the Tcl dynamic loading facilities. It can be used in both
+ * safe and unsafe interpreters.
*
* Copyright (c) 1995 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
+
#include "tcl.h"
/*
* Prototypes for procedures defined later in this file:
*/
-static int Pkgb_SubObjCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
-static int Pkgb_UnsafeObjCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
+static int Pkgb_SubObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
+static int Pkgb_UnsafeObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
/*
*----------------------------------------------------------------------
*
* Pkgb_SubObjCmd --
*
- * This procedure is invoked to process the "pkgb_sub" Tcl command.
- * It expects two arguments and returns their difference.
+ * This procedure is invoked to process the "pkgb_sub" Tcl command. It
+ * expects two arguments and returns their difference.
*
* Results:
* A standard Tcl result.
@@ -39,21 +40,21 @@ static int Pkgb_UnsafeObjCmd _ANSI_ARGS_((ClientData clientData,
*/
static int
-Pkgb_SubObjCmd(dummy, interp, objc, objv)
- ClientData dummy; /* Not used. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj * CONST objv[]; /* Argument objects. */
+Pkgb_SubObjCmd(
+ ClientData dummy, /* Not used. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
int first, second;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "num num");
- return TCL_ERROR;
+ return TCL_ERROR;
}
if ((Tcl_GetIntFromObj(interp, objv[1], &first) != TCL_OK)
|| (Tcl_GetIntFromObj(interp, objv[2], &second) != TCL_OK)) {
- return TCL_ERROR;
+ return TCL_ERROR;
}
Tcl_SetObjResult(interp, Tcl_NewIntObj(first - second));
return TCL_OK;
@@ -64,8 +65,8 @@ Pkgb_SubObjCmd(dummy, interp, objc, objv)
*
* Pkgb_UnsafeObjCmd --
*
- * This procedure is invoked to process the "pkgb_unsafe" Tcl command.
- * It just returns a constant string.
+ * This procedure is invoked to process the "pkgb_unsafe" Tcl command. It
+ * just returns a constant string.
*
* Results:
* A standard Tcl result.
@@ -77,11 +78,11 @@ Pkgb_SubObjCmd(dummy, interp, objc, objv)
*/
static int
-Pkgb_UnsafeObjCmd(dummy, interp, objc, objv)
- ClientData dummy; /* Not used. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj * CONST objv[]; /* Argument objects. */
+Pkgb_UnsafeObjCmd(
+ ClientData dummy, /* Not used. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1));
return TCL_OK;
@@ -92,8 +93,8 @@ Pkgb_UnsafeObjCmd(dummy, interp, objc, objv)
*
* Pkgb_Init --
*
- * This is a package initialization procedure, which is called
- * by Tcl when this package is to be added to an interpreter.
+ * This is a package initialization procedure, which is called by Tcl
+ * when this package is to be added to an interpreter.
*
* Results:
* None.
@@ -105,13 +106,13 @@ Pkgb_UnsafeObjCmd(dummy, interp, objc, objv)
*/
int
-Pkgb_Init(interp)
- Tcl_Interp *interp; /* Interpreter in which the package is
- * to be made available. */
+Pkgb_Init(
+ Tcl_Interp *interp) /* Interpreter in which the package is to be
+ * made available. */
{
int code;
- if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) {
+ if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
return TCL_ERROR;
}
code = Tcl_PkgProvide(interp, "Pkgb", "2.3");
@@ -130,8 +131,8 @@ Pkgb_Init(interp)
*
* Pkgb_SafeInit --
*
- * This is a package initialization procedure, which is called
- * by Tcl when this package is to be added to an unsafe interpreter.
+ * This is a package initialization procedure, which is called by Tcl
+ * when this package is to be added to a safe interpreter.
*
* Results:
* None.
@@ -143,18 +144,18 @@ Pkgb_Init(interp)
*/
int
-Pkgb_SafeInit(interp)
- Tcl_Interp *interp; /* Interpreter in which the package is
- * to be made available. */
+Pkgb_SafeInit(
+ Tcl_Interp *interp) /* Interpreter in which the package is to be
+ * made available. */
{
int code;
- if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) {
+ if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
return TCL_ERROR;
}
code = Tcl_PkgProvide(interp, "Pkgb", "2.3");
if (code != TCL_OK) {
- return code;
+ return code;
}
Tcl_CreateObjCommand(interp, "pkgb_sub", Pkgb_SubObjCmd, (ClientData) 0,
(Tcl_CmdDeleteProc *) NULL);
diff --git a/unix/dltest/pkgc.c b/unix/dltest/pkgc.c
index 1fda70b..6ad5ab4 100644
--- a/unix/dltest/pkgc.c
+++ b/unix/dltest/pkgc.c
@@ -1,33 +1,34 @@
-/*
+/*
* pkgc.c --
*
- * This file contains a simple Tcl package "pkgc" that is intended
- * for testing the Tcl dynamic loading facilities. It can be used
- * in both safe and unsafe interpreters.
+ * This file contains a simple Tcl package "pkgc" that is intended for
+ * testing the Tcl dynamic loading facilities. It can be used in both
+ * safe and unsafe interpreters.
*
* Copyright (c) 1995 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
+
#include "tcl.h"
/*
* Prototypes for procedures defined later in this file:
*/
-static int Pkgc_SubObjCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
-static int Pkgc_UnsafeObjCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
+static int Pkgc_SubObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
+static int Pkgc_UnsafeObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
/*
*----------------------------------------------------------------------
*
* Pkgc_SubObjCmd --
*
- * This procedure is invoked to process the "pkgc_sub" Tcl command.
- * It expects two arguments and returns their difference.
+ * This procedure is invoked to process the "pkgc_sub" Tcl command. It
+ * expects two arguments and returns their difference.
*
* Results:
* A standard Tcl result.
@@ -39,11 +40,11 @@ static int Pkgc_UnsafeObjCmd _ANSI_ARGS_((ClientData clientData,
*/
static int
-Pkgc_SubObjCmd(dummy, interp, objc, objv)
- ClientData dummy; /* Not used. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj * CONST objv[]; /* Argument objects. */
+Pkgc_SubObjCmd(
+ ClientData dummy, /* Not used. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
int first, second;
@@ -64,8 +65,8 @@ Pkgc_SubObjCmd(dummy, interp, objc, objv)
*
* Pkgc_UnsafeCmd --
*
- * This procedure is invoked to process the "pkgc_unsafe" Tcl command.
- * It just returns a constant string.
+ * This procedure is invoked to process the "pkgc_unsafe" Tcl command. It
+ * just returns a constant string.
*
* Results:
* A standard Tcl result.
@@ -77,11 +78,11 @@ Pkgc_SubObjCmd(dummy, interp, objc, objv)
*/
static int
-Pkgc_UnsafeObjCmd(dummy, interp, objc, objv)
- ClientData dummy; /* Not used. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj * CONST objv[]; /* Argument objects. */
+Pkgc_UnsafeObjCmd(
+ ClientData dummy, /* Not used. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1));
return TCL_OK;
@@ -92,8 +93,8 @@ Pkgc_UnsafeObjCmd(dummy, interp, objc, objv)
*
* Pkgc_Init --
*
- * This is a package initialization procedure, which is called
- * by Tcl when this package is to be added to an interpreter.
+ * This is a package initialization procedure, which is called by Tcl
+ * when this package is to be added to an interpreter.
*
* Results:
* None.
@@ -105,13 +106,13 @@ Pkgc_UnsafeObjCmd(dummy, interp, objc, objv)
*/
int
-Pkgc_Init(interp)
- Tcl_Interp *interp; /* Interpreter in which the package is
- * to be made available. */
+Pkgc_Init(
+ Tcl_Interp *interp) /* Interpreter in which the package is to be
+ * made available. */
{
int code;
- if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) {
+ if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
return TCL_ERROR;
}
code = Tcl_PkgProvide(interp, "Pkgc", "1.7.2");
@@ -130,8 +131,8 @@ Pkgc_Init(interp)
*
* Pkgc_SafeInit --
*
- * This is a package initialization procedure, which is called
- * by Tcl when this package is to be added to an unsafe interpreter.
+ * This is a package initialization procedure, which is called by Tcl
+ * when this package is to be added to a safe interpreter.
*
* Results:
* None.
@@ -143,18 +144,18 @@ Pkgc_Init(interp)
*/
int
-Pkgc_SafeInit(interp)
- Tcl_Interp *interp; /* Interpreter in which the package is
- * to be made available. */
+Pkgc_SafeInit(
+ Tcl_Interp *interp) /* Interpreter in which the package is to be
+ * made available. */
{
int code;
- if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) {
+ if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
return TCL_ERROR;
}
code = Tcl_PkgProvide(interp, "Pkgc", "1.7.2");
if (code != TCL_OK) {
- return code;
+ return code;
}
Tcl_CreateObjCommand(interp, "pkgc_sub", Pkgc_SubObjCmd, (ClientData) 0,
(Tcl_CmdDeleteProc *) NULL);
diff --git a/unix/dltest/pkgd.c b/unix/dltest/pkgd.c
index 3fa0aba..7fe7c49 100644
--- a/unix/dltest/pkgd.c
+++ b/unix/dltest/pkgd.c
@@ -1,14 +1,14 @@
-/*
+/*
* pkgd.c --
*
- * This file contains a simple Tcl package "pkgd" that is intended
- * for testing the Tcl dynamic loading facilities. It can be used
- * in both safe and unsafe interpreters.
+ * This file contains a simple Tcl package "pkgd" that is intended for
+ * testing the Tcl dynamic loading facilities. It can be used in both
+ * safe and unsafe interpreters.
*
* Copyright (c) 1995 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tcl.h"
@@ -17,18 +17,18 @@
* Prototypes for procedures defined later in this file:
*/
-static int Pkgd_SubObjCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
-static int Pkgd_UnsafeObjCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]));
+static int Pkgd_SubObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
+static int Pkgd_UnsafeObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
/*
*----------------------------------------------------------------------
*
* Pkgd_SubObjCmd --
*
- * This procedure is invoked to process the "pkgd_sub" Tcl command.
- * It expects two arguments and returns their difference.
+ * This procedure is invoked to process the "pkgd_sub" Tcl command. It
+ * expects two arguments and returns their difference.
*
* Results:
* A standard Tcl result.
@@ -40,11 +40,11 @@ static int Pkgd_UnsafeObjCmd _ANSI_ARGS_((ClientData clientData,
*/
static int
-Pkgd_SubObjCmd(dummy, interp, objc, objv)
- ClientData dummy; /* Not used. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj * CONST objv[]; /* Argument objects. */
+Pkgd_SubObjCmd(
+ ClientData dummy, /* Not used. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
int first, second;
@@ -65,8 +65,8 @@ Pkgd_SubObjCmd(dummy, interp, objc, objv)
*
* Pkgd_UnsafeCmd --
*
- * This procedure is invoked to process the "pkgd_unsafe" Tcl command.
- * It just returns a constant string.
+ * This procedure is invoked to process the "pkgd_unsafe" Tcl command. It
+ * just returns a constant string.
*
* Results:
* A standard Tcl result.
@@ -78,11 +78,11 @@ Pkgd_SubObjCmd(dummy, interp, objc, objv)
*/
static int
-Pkgd_UnsafeObjCmd(dummy, interp, objc, objv)
- ClientData dummy; /* Not used. */
- Tcl_Interp *interp; /* Current interpreter. */
- int objc; /* Number of arguments. */
- Tcl_Obj * CONST objv[]; /* Argument objects. */
+Pkgd_UnsafeObjCmd(
+ ClientData dummy, /* Not used. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
{
Tcl_SetObjResult(interp, Tcl_NewStringObj("unsafe command invoked", -1));
return TCL_OK;
@@ -93,8 +93,8 @@ Pkgd_UnsafeObjCmd(dummy, interp, objc, objv)
*
* Pkgd_Init --
*
- * This is a package initialization procedure, which is called
- * by Tcl when this package is to be added to an interpreter.
+ * This is a package initialization procedure, which is called by Tcl
+ * when this package is to be added to an interpreter.
*
* Results:
* None.
@@ -106,13 +106,13 @@ Pkgd_UnsafeObjCmd(dummy, interp, objc, objv)
*/
int
-Pkgd_Init(interp)
- Tcl_Interp *interp; /* Interpreter in which the package is
- * to be made available. */
+Pkgd_Init(
+ Tcl_Interp *interp) /* Interpreter in which the package is to be
+ * made available. */
{
int code;
- if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) {
+ if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
return TCL_ERROR;
}
code = Tcl_PkgProvide(interp, "Pkgd", "7.3");
@@ -131,8 +131,8 @@ Pkgd_Init(interp)
*
* Pkgd_SafeInit --
*
- * This is a package initialization procedure, which is called
- * by Tcl when this package is to be added to an unsafe interpreter.
+ * This is a package initialization procedure, which is called by Tcl
+ * when this package is to be added to a safe interpreter.
*
* Results:
* None.
@@ -144,13 +144,13 @@ Pkgd_Init(interp)
*/
int
-Pkgd_SafeInit(interp)
- Tcl_Interp *interp; /* Interpreter in which the package is
- * to be made available. */
+Pkgd_SafeInit(
+ Tcl_Interp *interp) /* Interpreter in which the package is to be
+ * made available. */
{
int code;
- if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) {
+ if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
return TCL_ERROR;
}
code = Tcl_PkgProvide(interp, "Pkgd", "7.3");
diff --git a/unix/dltest/pkge.c b/unix/dltest/pkge.c
index ed905f2..abd2359 100644
--- a/unix/dltest/pkge.c
+++ b/unix/dltest/pkge.c
@@ -1,14 +1,14 @@
-/*
+/*
* pkge.c --
*
- * This file contains a simple Tcl package "pkge" that is intended
- * for testing the Tcl dynamic loading facilities. Its Init
- * procedure returns an error in order to test how this is handled.
+ * This file contains a simple Tcl package "pkge" that is intended for
+ * testing the Tcl dynamic loading facilities. Its Init procedure returns
+ * an error in order to test how this is handled.
*
* Copyright (c) 1995 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
#include "tcl.h"
@@ -19,8 +19,8 @@
*
* Pkge_Init --
*
- * This is a package initialization procedure, which is called
- * by Tcl when this package is to be added to an interpreter.
+ * This is a package initialization procedure, which is called by Tcl
+ * when this package is to be added to an interpreter.
*
* Results:
* Returns TCL_ERROR and leaves an error message in interp->result.
@@ -32,12 +32,13 @@
*/
int
-Pkge_Init(interp)
- Tcl_Interp *interp; /* Interpreter in which the package is
- * to be made available. */
+Pkge_Init(
+ Tcl_Interp *interp) /* Interpreter in which the package is to be
+ * made available. */
{
static char script[] = "if 44 {open non_existent}";
- if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) {
+
+ if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
return TCL_ERROR;
}
return Tcl_Eval(interp, script);
diff --git a/unix/dltest/pkgf.c b/unix/dltest/pkgf.c
deleted file mode 100644
index e884ca9..0000000
--- a/unix/dltest/pkgf.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * pkgf.c --
- *
- * This file contains a simple Tcl package "pkgf" that is intended
- * for testing the Tcl dynamic loading facilities. Its Init
- * procedure returns an error in order to test how this is handled.
- *
- * Copyright (c) 1995 Sun Microsystems, Inc.
- *
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- */
-#include "tcl.h"
-
-/*
- * Prototypes for procedures defined later in this file:
- */
-
-static int Pkgd_SubCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int argc, char **argv));
-static int Pkgd_UnsafeCmd _ANSI_ARGS_((ClientData clientData,
- Tcl_Interp *interp, int argc, char **argv));
-
-/*
- *----------------------------------------------------------------------
- *
- * Pkgf_Init --
- *
- * This is a package initialization procedure, which is called
- * by Tcl when this package is to be added to an interpreter.
- *
- * Results:
- * Returns TCL_ERROR and leaves an error message in interp->result.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-Pkgf_Init(interp)
- Tcl_Interp *interp; /* Interpreter in which the package is
- * to be made available. */
-{
- static char script[] = "if 44 {open non_existent}";
- if (Tcl_InitStubs(interp, TCL_VERSION, 1) == NULL) {
- return TCL_ERROR;
- }
- return Tcl_Eval(interp, script);
-}
diff --git a/unix/dltest/pkgua.c b/unix/dltest/pkgua.c
new file mode 100644
index 0000000..9c36e88
--- /dev/null
+++ b/unix/dltest/pkgua.c
@@ -0,0 +1,332 @@
+/*
+ * pkgua.c --
+ *
+ * This file contains a simple Tcl package "pkgua" that is intended for
+ * testing the Tcl dynamic unloading facilities.
+ *
+ * Copyright (c) 1995 Sun Microsystems, Inc.
+ * Copyright (c) 2004 Georgios Petasis
+ *
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ */
+
+#include "tcl.h"
+
+/*
+ * Prototypes for procedures defined later in this file:
+ */
+
+static int PkguaEqObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
+static int PkguaQuoteObjCmd(ClientData clientData,
+ Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
+
+/*
+ * In the following hash table we are going to store a struct that holds all
+ * the command tokens created by Tcl_CreateObjCommand in an interpreter,
+ * indexed by the interpreter. In this way, we can find which command tokens
+ * we have registered in a specific interpreter, in order to unload them. We
+ * need to keep the various command tokens we have registered, as they are the
+ * only safe way to unregister our registered commands, even if they have been
+ * renamed.
+ *
+ * Note that this code is utterly single-threaded.
+ */
+
+static Tcl_HashTable interpTokenMap;
+static int interpTokenMapInitialised = 0;
+#define MAX_REGISTERED_COMMANDS 2
+
+
+static void
+PkguaInitTokensHashTable(void)
+{
+ if (interpTokenMapInitialised) {
+ return;
+ }
+ Tcl_InitHashTable(&interpTokenMap, TCL_ONE_WORD_KEYS);
+ interpTokenMapInitialised = 1;
+}
+
+void
+PkguaFreeTokensHashTable(void)
+{
+ Tcl_HashSearch search;
+ Tcl_HashEntry *entryPtr;
+
+ for (entryPtr = Tcl_FirstHashEntry(&interpTokenMap, &search);
+ entryPtr != NULL; entryPtr = Tcl_NextHashEntry(&search)) {
+ Tcl_Free((char *) Tcl_GetHashValue(entryPtr));
+ }
+ interpTokenMapInitialised = 0;
+}
+
+static Tcl_Command *
+PkguaInterpToTokens(
+ Tcl_Interp *interp)
+{
+ int newEntry;
+ Tcl_Command *cmdTokens;
+ Tcl_HashEntry *entryPtr =
+ Tcl_CreateHashEntry(&interpTokenMap, (char *) interp, &newEntry);
+
+ if (newEntry) {
+ cmdTokens = (Tcl_Command *)
+ Tcl_Alloc(sizeof(Tcl_Command) * (MAX_REGISTERED_COMMANDS+1));
+ for (newEntry=0 ; newEntry<MAX_REGISTERED_COMMANDS+1 ; ++newEntry) {
+ cmdTokens[newEntry] = NULL;
+ }
+ Tcl_SetHashValue(entryPtr, (ClientData) cmdTokens);
+ } else {
+ cmdTokens = (Tcl_Command *) Tcl_GetHashValue(entryPtr);
+ }
+ return cmdTokens;
+}
+
+static void
+PkguaDeleteTokens(
+ Tcl_Interp *interp)
+{
+ Tcl_HashEntry *entryPtr =
+ Tcl_FindHashEntry(&interpTokenMap, (char *) interp);
+
+ if (entryPtr) {
+ Tcl_Free((char *) Tcl_GetHashValue(entryPtr));
+ Tcl_DeleteHashEntry(entryPtr);
+ }
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * PkguaEqObjCmd --
+ *
+ * This procedure is invoked to process the "pkgua_eq" Tcl command. It
+ * expects two arguments and returns 1 if they are the same, 0 if they
+ * are different.
+ *
+ * Results:
+ * A standard Tcl result.
+ *
+ * Side effects:
+ * See the user documentation.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static int
+PkguaEqObjCmd(
+ ClientData dummy, /* Not used. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument objects. */
+{
+ int result;
+ CONST char *str1, *str2;
+ int len1, len2;
+
+ if (objc != 3) {
+ Tcl_WrongNumArgs(interp, 1, objv, "string1 string2");
+ return TCL_ERROR;
+ }
+
+ str1 = Tcl_GetStringFromObj(objv[1], &len1);
+ str2 = Tcl_GetStringFromObj(objv[2], &len2);
+ if (len1 == len2) {
+ result = (Tcl_UtfNcmp(str1, str2, len1) == 0);
+ } else {
+ result = 0;
+ }
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(result));
+ return TCL_OK;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * PkguaQuoteObjCmd --
+ *
+ * This procedure is invoked to process the "pkgua_quote" Tcl command. It
+ * expects one argument, which it returns as result.
+ *
+ * Results:
+ * A standard Tcl result.
+ *
+ * Side effects:
+ * See the user documentation.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static int
+PkguaQuoteObjCmd(
+ ClientData dummy, /* Not used. */
+ Tcl_Interp *interp, /* Current interpreter. */
+ int objc, /* Number of arguments. */
+ Tcl_Obj *CONST objv[]) /* Argument strings. */
+{
+ if (objc != 2) {
+ Tcl_WrongNumArgs(interp, 1, objv, "value");
+ return TCL_ERROR;
+ }
+ Tcl_SetObjResult(interp, objv[1]);
+ return TCL_OK;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Pkgua_Init --
+ *
+ * This is a package initialization procedure, which is called by Tcl
+ * when this package is to be added to an interpreter.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Pkgua_Init(
+ Tcl_Interp *interp) /* Interpreter in which the package is to be
+ * made available. */
+{
+ int code, cmdIndex = 0;
+ Tcl_Command *cmdTokens;
+
+ if (Tcl_InitStubs(interp, TCL_VERSION, 0) == NULL) {
+ return TCL_ERROR;
+ }
+
+ /*
+ * Initialise our Hash table, where we store the registered command tokens
+ * for each interpreter.
+ */
+
+ PkguaInitTokensHashTable();
+
+ code = Tcl_PkgProvide(interp, "Pkgua", "1.0");
+ if (code != TCL_OK) {
+ return code;
+ }
+
+ Tcl_SetVar(interp, "::pkgua_loaded", ".", TCL_APPEND_VALUE);
+
+ cmdTokens = PkguaInterpToTokens(interp);
+ cmdTokens[cmdIndex++] =
+ Tcl_CreateObjCommand(interp, "pkgua_eq", PkguaEqObjCmd,
+ (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
+ cmdTokens[cmdIndex++] =
+ Tcl_CreateObjCommand(interp, "pkgua_quote", PkguaQuoteObjCmd,
+ (ClientData) 0, (Tcl_CmdDeleteProc *) NULL);
+ return TCL_OK;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Pkgua_SafeInit --
+ *
+ * This is a package initialization procedure, which is called by Tcl
+ * when this package is to be added to a safe interpreter.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Pkgua_SafeInit(
+ Tcl_Interp *interp) /* Interpreter in which the package is to be
+ * made available. */
+{
+ return Pkgua_Init(interp);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Pkgua_Unload --
+ *
+ * This is a package unloading initialization procedure, which is called
+ * by Tcl when this package is to be unloaded from an interpreter.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Pkgua_Unload(
+ Tcl_Interp *interp, /* Interpreter from which the package is to be
+ * unloaded. */
+ int flags) /* Flags passed by the unloading mechanism */
+{
+ int code, cmdIndex;
+ Tcl_Command *cmdTokens = PkguaInterpToTokens(interp);
+
+ for (cmdIndex=0 ; cmdIndex<MAX_REGISTERED_COMMANDS ; cmdIndex++) {
+ if (cmdTokens[cmdIndex] == NULL) {
+ continue;
+ }
+ code = Tcl_DeleteCommandFromToken(interp, cmdTokens[cmdIndex]);
+ if (code != TCL_OK) {
+ return code;
+ }
+ }
+
+ PkguaDeleteTokens(interp);
+
+ Tcl_SetVar(interp, "::pkgua_detached", ".", TCL_APPEND_VALUE);
+
+ if (flags == TCL_UNLOAD_DETACH_FROM_PROCESS) {
+ /*
+ * Tcl is ready to detach this library from the running application.
+ * We should free all the memory that is not related to any
+ * interpreter.
+ */
+
+ PkguaFreeTokensHashTable();
+ Tcl_SetVar(interp, "::pkgua_unloaded", ".", TCL_APPEND_VALUE);
+ }
+ return TCL_OK;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Pkgua_SafeUnload --
+ *
+ * This is a package unloading initialization procedure, which is called
+ * by Tcl when this package is to be unloaded from an interpreter.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+Pkgua_SafeUnload(
+ Tcl_Interp *interp, /* Interpreter from which the package is to be
+ * unloaded. */
+ int flags) /* Flags passed by the unloading mechanism */
+{
+ return Pkgua_Unload(interp, flags);
+}