diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2013-06-18 08:13:22 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2013-06-18 08:13:22 (GMT) |
commit | 69072d89d79fa10bb503736110fb3a72bc0462c9 (patch) | |
tree | 8a729d803cb5d4481499338642a698741b964b38 | |
parent | f498e25fe3bf5f45bf480cc450fa0f9e83910d64 (diff) | |
parent | ccd007fdf29b1594a648755f0e4aa1c812a30a96 (diff) | |
download | tcl-69072d89d79fa10bb503736110fb3a72bc0462c9.zip tcl-69072d89d79fa10bb503736110fb3a72bc0462c9.tar.gz tcl-69072d89d79fa10bb503736110fb3a72bc0462c9.tar.bz2 |
Simplify TIP #414 implementation by using the function TclInitStubTable() in stead of re-use Tcl_InitStubs().
-rw-r--r-- | doc/InitSubSyst.3 | 53 | ||||
-rw-r--r-- | generic/tcl.h | 12 | ||||
-rw-r--r-- | generic/tclEncoding.c | 27 | ||||
-rw-r--r-- | generic/tclInt.h | 2 | ||||
-rw-r--r-- | generic/tclMain.c | 3 |
5 files changed, 89 insertions, 8 deletions
diff --git a/doc/InitSubSyst.3 b/doc/InitSubSyst.3 new file mode 100644 index 0000000..08b3154 --- /dev/null +++ b/doc/InitSubSyst.3 @@ -0,0 +1,53 @@ +'\" +'\" Copyright (c) 2013 Tcl Core Team +'\" +'\" See the file "license.terms" for information on usage and redistribution +'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. +'\" +.so man.macros +.TH Tcl_InitSubsystems 3 8.6.1 Tcl "Tcl Library Procedures" +.BS +.SH NAME +Tcl_InitSubsystems \- initialize the Tcl library. +.SH SYNOPSIS +.nf +\fB#include <tcl.h>\fR +.sp +const char * +\fBTcl_InitSubsystems\fR(\fIpanicProc\fR) +.SH ARGUMENTS +.SH ARGUMENTS +.AS Tcl_PanicProc *panicProc +.AP Tcl_PanicProc *panicProc in +Desired panic function, for error reporting. If NULL, the default +panicProc is used, which normally writes the message to stderr. +.BE + +.SH DESCRIPTION +.PP +The \fBTcl_InitSubsystems\fR procedure initializes the Tcl +library. This procedure is typically invoked as the very +first thing in the application's main program. +.PP +\fBTcl_InitSubsystems\fR is very similar in use to +\fBTcl_FindExecutable\fR. It can be used when Tcl is +used as utility library, no other encodings than utf8, +iso8859-1 or unicode are used, and no interest exists in the +value of \fBinfo nameofexecutable\fR. The system encoding will not +be extracted from the environment, but falls back to iso8859-1. +.PP +The return value is the Tcl version. +.PP +If \fBTcl_InitSubsystems()\fR is called in code where +\fBUSE_TCL_STUBS\fR is set, it does one additional thing: +initialize the Stub table for using Tcl as utility +library, without needing a Tcl interpreter. For example: +.CS +const char *version = Tcl_InitSubSystems(NULL); +/* At this point, Tcl C API calls without interp are ready for use */ +int major, minor, patch; +Tcl_GetVersion(&major, &minor, &patch); +.CE +This will work as expected, both with and without stubs. +.SH KEYWORDS +binary, executable file diff --git a/generic/tcl.h b/generic/tcl.h index d47e931..739966c 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -2397,6 +2397,8 @@ const char * Tcl_InitStubs(Tcl_Interp *interp, const char *version, int exact); const char * TclTomMathInitializeStubs(Tcl_Interp *interp, const char *version, int epoch, int revision); +const char * TclInitStubTable(const char *version); + /* * When not using stubs, make it a macro. @@ -2411,13 +2413,21 @@ const char * TclTomMathInitializeStubs(Tcl_Interp *interp, * TODO - tommath stubs export goes here! */ +/* Tcl_InitSubsystems, see TIP #414 */ + +EXTERN const char *Tcl_InitSubsystems(Tcl_PanicProc *panicProc); +#ifdef USE_TCL_STUBS +#define Tcl_InitSubsystems(panicProc) \ + TclInitStubTable((Tcl_InitSubsystems)(panicProc)) +#endif + /* * Public functions that are not accessible via the stubs table. * Tcl_GetMemoryInfo is needed for AOLserver. [Bug 1868171] */ #define Tcl_Main(argc, argv, proc) Tcl_MainEx(argc, argv, proc, \ - (Tcl_FindExecutable(argv[0]), (Tcl_CreateInterp)())) + (Tcl_InitSubsystems(NULL), Tcl_CreateInterp())) EXTERN void Tcl_MainEx(int argc, char **argv, Tcl_AppInitProc *appInitProc, Tcl_Interp *interp); EXTERN const char * Tcl_PkgInitStubsCheck(Tcl_Interp *interp, diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 2cc55d6..b94e355 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -1411,21 +1411,40 @@ Tcl_UtfToExternal( /* *--------------------------------------------------------------------------- * - * Tcl_FindExecutable -- + * Tcl_InitSubsystems/Tcl_FindExecutable -- * - * This function computes the absolute path name of the current - * application, given its argv[0] value. + * This function initializes everything needed for the Tcl library + * to be able to operate. * * Results: * None. * * Side effects: * The absolute pathname for the application is computed and stored to be - * returned later be [info nameofexecutable]. + * returned later by [info nameofexecutable]. The system encoding is + * determined and stored to be returned later by [encoding system] * *--------------------------------------------------------------------------- */ +MODULE_SCOPE const TclStubs tclStubs; + +/* Structure returned by Tcl_InitSubsystems, which can be interpreted + * as the Tcl version, but also can be used to initialize the stub table. */ +static const TclStubInfoType stubInfo = { + TCL_PATCH_LEVEL, (ClientData) &tclStubs +}; + #undef Tcl_FindExecutable +const char * +Tcl_InitSubsystems(Tcl_PanicProc *panicProc) +{ + if (panicProc) { + Tcl_SetPanicProc(panicProc); + } + TclInitSubsystems(); + return stubInfo.version; +} + void Tcl_FindExecutable( const char *argv0) /* The value of the application's argv[0] diff --git a/generic/tclInt.h b/generic/tclInt.h index 3432b37..346fa96 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3840,8 +3840,6 @@ typedef struct { ClientData data; } TclStubInfoType; -MODULE_SCOPE const char *TclInitStubTable(const char *version); - /* * Functions defined in generic/tclVar.c and currenttly exported only for use * by the bytecode compiler and engine. Some of these could later be placed in diff --git a/generic/tclMain.c b/generic/tclMain.c index f445383..7a31d43 100644 --- a/generic/tclMain.c +++ b/generic/tclMain.c @@ -313,6 +313,8 @@ Tcl_MainEx( Tcl_Channel chan; InteractiveState is; + TclpSetInitialEncodings(); + TclpFindExecutable((void *)argv[0]); Tcl_InitMemory(interp); is.interp = interp; @@ -640,7 +642,6 @@ Tcl_Main( * function to call after most initialization * but before starting to execute commands. */ { - Tcl_FindExecutable(argv[0]); Tcl_MainEx(argc, argv, appInitProc, Tcl_CreateInterp()); } #endif /* TCL_MAJOR_VERSION == 8 && !UNICODE */ |