diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-10-21 14:03:04 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-10-21 14:03:04 (GMT) |
commit | de1cef0dc80e5e6c32ee369b4e043cc4baf90145 (patch) | |
tree | f567884a345c0e830eb11c79205a22d9b430edf5 /generic/tclStubCall.c | |
parent | 45c406a3db22a0349dfabba2c0c9edfb924a6ea9 (diff) | |
parent | 2119ee5eb73d55cc417be2146168a9892187e409 (diff) | |
download | tcl-de1cef0dc80e5e6c32ee369b4e043cc4baf90145.zip tcl-de1cef0dc80e5e6c32ee369b4e043cc4baf90145.tar.gz tcl-de1cef0dc80e5e6c32ee369b4e043cc4baf90145.tar.bz2 |
Merge trunk. More simplifications, still WIP
Diffstat (limited to 'generic/tclStubCall.c')
-rw-r--r-- | generic/tclStubCall.c | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/generic/tclStubCall.c b/generic/tclStubCall.c index ae6566f..da8d47a 100644 --- a/generic/tclStubCall.c +++ b/generic/tclStubCall.c @@ -19,27 +19,24 @@ MODULE_SCOPE void *tclStubsHandle; /* *---------------------------------------------------------------------- * - * Tcl_InitSubsystems -- + * TclStubCall -- * * 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. + * Outputs a function returning the value of the "version" argument or NULL. * *---------------------------------------------------------------------- */ static const char PROCNAME[][24] = { + "_Tcl_SetPanicProc", "_Tcl_InitSubsystems", "_Tcl_FindExecutable", - "_Tcl_SetPanicProc", - "_TclZipfs_AppHook", - "_Tcl_StaticPackage", "_Tcl_MainEx", - "_Tcl_MainExW" + "_Tcl_MainExW", + "_Tcl_StaticPackage", + "_TclZipfs_AppHook" }; MODULE_SCOPE const void *nullVersionProc(void) { @@ -50,14 +47,18 @@ 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) +TclStubCall(void *arg) { static void *stubFn[] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL}; - const char *(*versionProc)(void) = (const char *(*)(void))nullVersionProc; + unsigned index = PTR2UINT(arg); - if (tclStubsHandle == (void *)-1) { - if (index == 2 && arg1 != NULL) { - ((Tcl_PanicProc *)arg1)(CANNOTCALL, PROCNAME[index] + 1); + if (index > 6) { + /* Any other value means Tcl_SetPanicProc() with non-null panicProc */ + index = 0; + } + if (tclStubsHandle == INT2PTR(-1)) { + if ((index == 0) && (arg != NULL)) { + ((Tcl_PanicProc *)arg)(CANNOTCALL, PROCNAME[index] + 1); } else { fprintf(stderr, CANNOTCALL, PROCNAME[index] + 1); abort(); @@ -67,8 +68,8 @@ TclStubCall(int index, void *arg1) if (!tclStubsHandle) { tclStubsHandle = dlopen(TCL_DLL_FILE, RTLD_NOW|RTLD_LOCAL); if (!tclStubsHandle) { - if (index == 2 && arg1 != NULL) { - ((Tcl_PanicProc *)arg1)(CANNOTFIND, TCL_DLL_FILE, dlerror()); + if ((index == 0) && (arg != NULL)) { + ((Tcl_PanicProc *)arg)(CANNOTFIND, TCL_DLL_FILE, dlerror()); } else { fprintf(stderr, CANNOTFIND, TCL_DLL_FILE, dlerror()); abort(); @@ -77,13 +78,13 @@ TclStubCall(int index, void *arg1) } stubFn[index] = dlsym(tclStubsHandle, PROCNAME[index] + 1); if (!stubFn[index]) { - stubFn[index] = dlsym(tclStubsHandle, PROCNAME[index]); - } - if (stubFn[index]) { - versionProc = ((const char *(*)(void))stubFn[index]); + stubFn[index] = dlsym(tclStubsHandle, PROCNAME[index]); + if (!stubFn[index]) { + stubFn[index] = nullVersionProc; + } } } - return versionProc; + return stubFn[index]; } /* |