summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-10-20 16:28:37 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-10-20 16:28:37 (GMT)
commit45c406a3db22a0349dfabba2c0c9edfb924a6ea9 (patch)
treec2a20757f437e8ff2c1f3a73b0397a091ed006f1 /generic
parent7aa855f962a06be0007a47a5330934a4fa4b110a (diff)
parent8ac4aee0fc7e4d4020c874ab41fecad788d1c848 (diff)
downloadtcl-45c406a3db22a0349dfabba2c0c9edfb924a6ea9.zip
tcl-45c406a3db22a0349dfabba2c0c9edfb924a6ea9.tar.gz
tcl-45c406a3db22a0349dfabba2c0c9edfb924a6ea9.tar.bz2
Merge trunk.
Implementation simplifications
Diffstat (limited to 'generic')
-rw-r--r--generic/tcl.h26
-rw-r--r--generic/tclCmdIL.c2
-rw-r--r--generic/tclCmdMZ.c2
-rw-r--r--generic/tclInt.h5
-rw-r--r--generic/tclScan.c2
-rw-r--r--generic/tclStubCall.c38
-rw-r--r--generic/tclStubMainEx.c73
-rw-r--r--generic/tclStubStaticPackage.c74
8 files changed, 44 insertions, 178 deletions
diff --git a/generic/tcl.h b/generic/tcl.h
index fb96e3c..ab2b0a8 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -2202,11 +2202,7 @@ EXTERN const char *TclZipfs_AppHook(int *argc, char ***argv);
#endif
extern void TclStubMainEx(int index, int argc, const void *argv,
Tcl_AppInitProc *appInitProc, Tcl_Interp *interp);
-extern const char *TclStubStaticPackage(Tcl_Interp *interp,
- const char *pkgName,
- Tcl_PackageInitProc *initProc,
- Tcl_PackageInitProc *safeInitProc);
-extern const char *TclStubCall(int flags, void *arg1, void *arg2);
+extern void *TclStubCall(int flags, void *arg1);
#if defined(_WIN32) && defined(UNICODE)
#ifndef USE_TCL_STUBS
# define Tcl_FindExecutable(arg) ((Tcl_FindExecutable)((const char *)(arg)))
@@ -2217,18 +2213,24 @@ extern const char *TclStubCall(int flags, void *arg1, void *arg2);
#endif
#ifdef USE_TCL_STUBS
#define Tcl_InitSubsystems() \
- TclInitStubTable(TclStubCall(0, NULL, NULL))
+ TclInitStubTable(((const char *(*)(void))TclStubCall(0, NULL))())
#define Tcl_FindExecutable(argv0) \
- TclInitStubTable(TclStubCall(1, (void *)argv0, NULL))
+ TclInitStubTable(((const char *(*)(const char *))TclStubCall(1, NULL))(argv0))
#define Tcl_SetPanicProc(panicProc) \
- TclInitStubTable(TclStubCall(2, (void *)panicProc, NULL))
+ TclInitStubTable(((const char *(*)(Tcl_PanicProc *))TclStubCall(1, (void *)panicProc))(panicProc))
#define TclZipfs_AppHook(argcp, argvp) \
- TclInitStubTable(TclStubCall(3, (void *)argcp, (void *)argvp))
+ TclInitStubTable(((const char *(*)(int *, void *))TclStubCall(1, NULL))(argcp, argvp))
+#define Tcl_StaticPackage(interp, pkgName, initProc, safeInitProc) \
+ ((void(*)(Tcl_Interp *, const char *, Tcl_PackageInitProc *, Tcl_PackageInitProc *)) \
+ TclStubCall(4, NULL))(interp, pkgName, initProc, safeInitProc)
#if !defined(_WIN32) || !defined(UNICODE)
-#define Tcl_MainEx(argc, argv, appInitProc, interp) TclStubMainEx(0, argc, argv, appInitProc, interp)
+#define Tcl_MainEx(argc, argv, appInitProc, interp) \
+ ((void(*)(int, const void *, Tcl_AppInitProc *, Tcl_Interp *)) \
+ TclStubCall(5, NULL))(argc, argv, appInitProc, interp)
#endif
-#define Tcl_MainExW(argc, argv, appInitProc, interp) TclStubMainEx(1, argc, argv, appInitProc, interp)
-#define Tcl_StaticPackage TclStubStaticPackage
+#define Tcl_MainExW(argc, argv, appInitProc, interp) \
+ ((void(*)(int, const void *, Tcl_AppInitProc *, Tcl_Interp *)) \
+ TclStubCall(6, NULL))(argc, argv, appInitProc, interp)
#endif
/*
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index b2f1216..5a8ef22 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.c
@@ -3518,7 +3518,7 @@ Tcl_LsearchObjCmd(
if (allMatches || inlineReturn) {
Tcl_ResetResult(interp);
} else {
- TclNewIndexObj(itemPtr, -1);
+ TclNewIndexObj(itemPtr, TCL_INDEX_NONE);
Tcl_SetObjResult(interp, itemPtr);
}
goto done;
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index ae4f25f..d5828cd 100644
--- a/generic/tclCmdMZ.c
+++ b/generic/tclCmdMZ.c
@@ -3789,7 +3789,7 @@ TclNRSwitchObjCmd(
TclNewIndexObj(rangeObjAry[0], info.matches[j].start);
TclNewIndexObj(rangeObjAry[1], info.matches[j].end-1);
} else {
- TclNewIndexObj(rangeObjAry[1], -1);
+ TclNewIndexObj(rangeObjAry[1], TCL_INDEX_NONE);
rangeObjAry[0] = rangeObjAry[1];
}
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 2e88348..2a0dfa6 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -4816,11 +4816,12 @@ MODULE_SCOPE Tcl_PackageInitProc Procbodytest_SafeInit;
#define TclNewIndexObj(objPtr, w) \
do { \
+ size_t _w = (w); \
TclIncrObjsAllocated(); \
TclAllocObjStorage(objPtr); \
(objPtr)->refCount = 0; \
(objPtr)->bytes = NULL; \
- (objPtr)->internalRep.wideValue = (Tcl_WideInt)((w) + 1) - 1; \
+ (objPtr)->internalRep.wideValue = ((_w) == TCL_INDEX_NONE) ? -1 : (Tcl_WideInt)(_w); \
(objPtr)->typePtr = &tclIntType; \
TCL_DTRACE_OBJ_CREATE(objPtr); \
} while (0)
@@ -4851,7 +4852,7 @@ MODULE_SCOPE Tcl_PackageInitProc Procbodytest_SafeInit;
(objPtr) = Tcl_NewWideIntObj(w)
#define TclNewIndexObj(objPtr, w) \
- (objPtr) = Tcl_NewWideIntObj((Tcl_WideInt)((w) + 1) - 1)
+ (objPtr) = ((w) == TCL_INDEX_NONE) ? Tcl_NewWideIntObj(-1) : Tcl_NewWideIntObj(w)
#define TclNewDoubleObj(objPtr, d) \
(objPtr) = Tcl_NewDoubleObj(d)
diff --git a/generic/tclScan.c b/generic/tclScan.c
index 468d5bb..3387f34 100644
--- a/generic/tclScan.c
+++ b/generic/tclScan.c
@@ -1089,7 +1089,7 @@ Tcl_ScanObjCmd(
if (code == TCL_OK) {
if (underflow && (nconversions == 0)) {
if (numVars) {
- TclNewIndexObj(objPtr, -1);
+ TclNewIndexObj(objPtr, TCL_INDEX_NONE);
} else {
if (objPtr) {
Tcl_SetListObj(objPtr, 0, NULL);
diff --git a/generic/tclStubCall.c b/generic/tclStubCall.c
index 82cd60a..ae6566f 100644
--- a/generic/tclStubCall.c
+++ b/generic/tclStubCall.c
@@ -33,23 +33,33 @@ MODULE_SCOPE void *tclStubsHandle;
*/
static const char PROCNAME[][24] = {
- "_Tcl_InitSubsystems",
- "_Tcl_FindExecutable",
- "_Tcl_SetPanicProc",
- "_TclZipfs_AppHook"
+ "_Tcl_InitSubsystems",
+ "_Tcl_FindExecutable",
+ "_Tcl_SetPanicProc",
+ "_TclZipfs_AppHook",
+ "_Tcl_StaticPackage",
+ "_Tcl_MainEx",
+ "_Tcl_MainExW"
};
-MODULE_SCOPE const char *
-TclStubCall(int index, void *arg1, void *arg2)
+MODULE_SCOPE const void *nullVersionProc(void) {
+ return NULL;
+}
+
+static const char CANNOTCALL[] = "Cannot call %s from stubbed extension\n";
+static const char CANNOTFIND[] = "Cannot find %s: %s\n";
+
+MODULE_SCOPE void *
+TclStubCall(int index, void *arg1)
{
- static void *stubFn[] = {NULL,NULL,NULL,NULL};
- static const char *version = NULL;
+ static void *stubFn[] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
+ const char *(*versionProc)(void) = (const char *(*)(void))nullVersionProc;
if (tclStubsHandle == (void *)-1) {
if (index == 2 && arg1 != NULL) {
- ((Tcl_PanicProc *)arg1)("Cannot call %s from stubbed extension\n", PROCNAME[index] + 1);
+ ((Tcl_PanicProc *)arg1)(CANNOTCALL, PROCNAME[index] + 1);
} else {
- fprintf(stderr, "Cannot call %s from stubbed extension\n", PROCNAME[index] + 1);
+ fprintf(stderr, CANNOTCALL, PROCNAME[index] + 1);
abort();
}
}
@@ -58,9 +68,9 @@ TclStubCall(int index, void *arg1, void *arg2)
tclStubsHandle = dlopen(TCL_DLL_FILE, RTLD_NOW|RTLD_LOCAL);
if (!tclStubsHandle) {
if (index == 2 && arg1 != NULL) {
- ((Tcl_PanicProc *)arg1)("Cannot find " TCL_DLL_FILE ": %s\n", dlerror());
+ ((Tcl_PanicProc *)arg1)(CANNOTFIND, TCL_DLL_FILE, dlerror());
} else {
- fprintf(stderr, "Cannot find " TCL_DLL_FILE ": %s\n", dlerror());
+ fprintf(stderr, CANNOTFIND, TCL_DLL_FILE, dlerror());
abort();
}
}
@@ -70,10 +80,10 @@ TclStubCall(int index, void *arg1, void *arg2)
stubFn[index] = dlsym(tclStubsHandle, PROCNAME[index]);
}
if (stubFn[index]) {
- version = ((const char *(*)(void *,void *))stubFn[index])(arg1, arg2);
+ versionProc = ((const char *(*)(void))stubFn[index]);
}
}
- return version;
+ return versionProc;
}
/*
diff --git a/generic/tclStubMainEx.c b/generic/tclStubMainEx.c
deleted file mode 100644
index df807a7..0000000
--- a/generic/tclStubMainEx.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * tclStubMainEx.c --
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- */
-
-#include "tclInt.h"
-#ifndef _WIN32
-# include <dlfcn.h>
-#else
-# define dlopen(a,b) (void *)LoadLibraryW(JOIN(L,a))
-# define dlsym(a,b) (void *)GetProcAddress((HMODULE)(a),b)
-# define dlerror() ""
-#endif
-
-MODULE_SCOPE void *tclStubsHandle;
-
-/*
- *----------------------------------------------------------------------
- *
- * Tcl_InitSubsystems --
- *
- * Load the Tcl core dynamically, version "9.0" (or higher, in future versions)
- *
- * Results:
- * Outputs the value of the "version" argument.
- *
- * Side effects:
- * Sets the stub table pointers.
- *
- *----------------------------------------------------------------------
- */
-
-static const char PROCNAME[][24] = {
- "_Tcl_MainEx",
- "_Tcl_MainExW"
-};
-
-MODULE_SCOPE void
-TclStubMainEx(int index, int argc, const void *argv,
- Tcl_AppInitProc *appInitProc, Tcl_Interp *interp)
-{
- static void *stubFn[] = {NULL,NULL};
-
- if (!stubFn[index]) {
- if (tclStubsHandle == (void *)-1) {
- fprintf(stderr, "Cannot call %s from stubbed extension\n", PROCNAME[index] + 1);
- abort();
- }
- if (!tclStubsHandle) {
- tclStubsHandle = dlopen(TCL_DLL_FILE, RTLD_NOW|RTLD_LOCAL);
- if (!tclStubsHandle) {
- tclStubsPtr->tcl_Panic("Cannot find " TCL_DLL_FILE ": %s\n", dlerror());
- }
- }
- stubFn[index] = dlsym(tclStubsHandle, PROCNAME[index] + 1);
- if (!stubFn[index]) {
- stubFn[index] = dlsym(tclStubsHandle, PROCNAME[index]);
- }
- if (stubFn[index]) {
- ((void(*)(int, const void *, Tcl_AppInitProc *, Tcl_Interp *))stubFn[index])(argc, argv, appInitProc, interp);
- }
- }
-}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */
diff --git a/generic/tclStubStaticPackage.c b/generic/tclStubStaticPackage.c
deleted file mode 100644
index 2765b3b..0000000
--- a/generic/tclStubStaticPackage.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * tclStubStaticPackage.c --
- *
- * See the file "license.terms" for information on usage and redistribution of
- * this file, and for a DISCLAIMER OF ALL WARRANTIES.
- */
-
-#include "tclInt.h"
-#ifndef _WIN32
-# include <dlfcn.h>
-#else
-# define dlopen(a,b) (void *)LoadLibraryW(JOIN(L,a))
-# define dlsym(a,b) (void *)GetProcAddress((HMODULE)(a),b)
-# define dlerror() ""
-#endif
-
-MODULE_SCOPE void *tclStubsHandle;
-
-/*
- *----------------------------------------------------------------------
- *
- * Tcl_InitSubsystems --
- *
- * Load the Tcl core dynamically, version "9.0" (or higher, in future versions)
- *
- * Results:
- * Outputs the value of the "version" argument.
- *
- * Side effects:
- * Sets the stub table pointers.
- *
- *----------------------------------------------------------------------
- */
-
-static const char PROCNAME[] = "_Tcl_StaticPackage";
-
-MODULE_SCOPE const char *
-TclStubStaticPackage(Tcl_Interp *interp,
- const char *pkgName,
- Tcl_PackageInitProc *initProc,
- Tcl_PackageInitProc *safeInitProc)
-{
- static void *stubFn = NULL;
- static const char *version = NULL;
-
- if (tclStubsHandle == (void *)-1) {
- fprintf(stderr, "Cannot call %s from stubbed extension\n", PROCNAME + 1);
- abort();
- }
- if (!stubFn) {
- if (!tclStubsHandle) {
- tclStubsHandle = dlopen(TCL_DLL_FILE, RTLD_NOW|RTLD_LOCAL);
- if (!tclStubsHandle) {
- tclStubsPtr->tcl_Panic("Cannot find " TCL_DLL_FILE ": %s\n", dlerror());
- }
- }
- stubFn = dlsym(tclStubsHandle, PROCNAME + 1);
- if (!stubFn) {
- stubFn = dlsym(tclStubsHandle, PROCNAME);
- }
- if (stubFn) {
- version = ((const char *(*)(Tcl_Interp *, const char *, Tcl_PackageInitProc *, Tcl_PackageInitProc *))stubFn)(interp, pkgName, initProc, safeInitProc);
- }
- }
- return version;
-}
-
-/*
- * Local Variables:
- * mode: c
- * c-basic-offset: 4
- * fill-column: 78
- * End:
- */