Debian Codegraph @

pTk/mTk/tclGeneric/tclStubLib.c

raw symbols SCIP
1 /*
2 * tclStubLib.c --
3 *
4 * Stub object that will be statically linked into extensions that wish
5 * to access Tcl.
6 *
7 * Copyright (c) 1998-1999 by Scriptics Corporation.
8 * Copyright (c) 1998 Paul Duffin.
9 *
10 * See the file "license.terms" for information on usage and redistribution
11 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 *
13 * RCS: @(#) $Id: tclStubLib.c,v 1.6 2002/12/04 07:07:59 hobbs Exp $
14 */
15
16 /*
17 * We need to ensure that we use the stub macros so that this file contains
18 * no references to any of the stub functions. This will make it possible
19 * to build an extension that references Tcl_InitStubs but doesn't end up
20 * including the rest of the stub functions.
21 */
22
23 #ifndef USE_TCL_STUBS
24 #define USE_TCL_STUBS
25 #endif
26 #undef USE_TCL_STUB_PROCS
27
28 #include "tclInt.h"
29 #include "tclPort.h"
30
31 /*
32 * Ensure that Tcl_InitStubs is built as an exported symbol. The other stub
33 * functions should be built as non-exported symbols.
34 */
35
36 #undef TCL_STORAGE_CLASS
37 #define TCL_STORAGE_CLASS DLLEXPORT
38
39 TclStubs *tclStubsPtr = NULL;
40 TclPlatStubs *tclPlatStubsPtr = NULL;
41 TclIntStubs *tclIntStubsPtr = NULL;
42 TclIntPlatStubs *tclIntPlatStubsPtr = NULL;
43
44 static TclStubs * HasStubSupport _ANSI_ARGS_((Tcl_Interp *interp));
45
46 static TclStubs *
47 HasStubSupport (interp)
48 Tcl_Interp *interp;
49 {
50 Interp *iPtr = (Interp *) interp;
51
52 if (iPtr->stubTable && (iPtr->stubTable->magic == TCL_STUB_MAGIC)) {
53 return iPtr->stubTable;
54 }
55 interp->result = "This interpreter does not support stubs-enabled extensions.";
56 interp->freeProc = TCL_STATIC;
57
58 return NULL;
59 }
60
61 /*
62 *----------------------------------------------------------------------
63 *
64 * Tcl_InitStubs --
65 *
66 * Tries to initialise the stub table pointers and ensures that
67 * the correct version of Tcl is loaded.
68 *
69 * Results:
70 * The actual version of Tcl that satisfies the request, or
71 * NULL to indicate that an error occurred.
72 *
73 * Side effects:
74 * Sets the stub table pointers.
75 *
76 *----------------------------------------------------------------------
77 */
78
79 #ifdef Tcl_InitStubs
80 #undef Tcl_InitStubs
81 #endif
82
83 CONST char *
84 Tcl_InitStubs (interp, version, exact)
85 Tcl_Interp *interp;
86 CONST char *version;
87 int exact;
88 {
89 CONST char *actualVersion = NULL;
90 TclStubs *tmp;
91
92 /*
93 * We can't optimize this check by caching tclStubsPtr because
94 * that prevents apps from being able to load/unload Tcl dynamically
95 * multiple times. [Bug 615304]
96 */
97
98 tclStubsPtr = HasStubSupport(interp);
99 if (!tclStubsPtr) {
100 return NULL;
101 }
102
103 actualVersion = Tcl_PkgRequireEx(interp, "Tcl", version, exact,
104 (ClientData *) &tmp);
105 if (actualVersion == NULL) {
106 tclStubsPtr = NULL;
107 return NULL;
108 }
109
110 if (tclStubsPtr->hooks) {
111 tclPlatStubsPtr = tclStubsPtr->hooks->tclPlatStubs;
112 tclIntStubsPtr = tclStubsPtr->hooks->tclIntStubs;
113 tclIntPlatStubsPtr = tclStubsPtr->hooks->tclIntPlatStubs;
114 } else {
115 tclPlatStubsPtr = NULL;
116 tclIntStubsPtr = NULL;
117 tclIntPlatStubsPtr = NULL;
118 }
119
120 return actualVersion;
121 }