Support for global variables in Stubs
Closed / Fixed218407ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 00:57:12
OriginalBugID: 5340 RFE
Version: 8.3.1
SubmitDate: '2000-05-03'
LastModified: '2000-05-17'
Severity: SER
Status: Closed
Submitter: techsupp
ChangedBy: hobbs
OS: All
FixedDate: '2000-10-25'
ClosedDate: '2000-05-17'
Name:
Jan Nijtmans
Comments:
The upcoming plus-patches for 8.3.1 will contain this enhancement.
DesiredBehavior:
Currently it is impossuble under Windows to export global variables from Dll's.
This patch adds support to the Stubs implementation fully fixing this.
The basic idea is to adapting genStubs.tcl such that it can handle global
variables as well as functions in the same way: Let the Stub table contain
pointers to the actual locations which are addressed indrectly through macros.
The supplied patches give the best demonstration how to use it.
Even when not using Stubs, global variables are safe to be used, because
the __declspec(dllexport) attribute is supported by the latest versions of
VC++ and gcc. As a demonstration, see the modifications to tclTest.c below.
That's a lot simpler, isn't it?
Patch:
*** generic/tclInt.decls.origFri Mar 31 10:52:04 2000
--- generic/tclInt.declsTue May 2 20:15:40 2000
***************
*** 602,607 ****
--- 602,616 ----
int TclpMatchFilesTypes(Tcl_Interp *interp, char *separators, \
Tcl_DString *dirPtr, char *pattern, char *tail, GlobTypeData *types)
}
+ declare 161 generic {
+ TclPlatformType tclPlatform
+ }
+ declare 162 generic {
+ char *tclExecutableName
+ }
+ declare 163 generic {
+ char *tclNativeExecutableName
+ }
##############################################################################
*** generic/tclIntDecls.h.origTue May 2 20:16:18 2000
--- generic/tclIntDecls.hTue May 2 20:20:01 2000
***************
*** 529,534 ****
--- 529,540 ----
char * separators, Tcl_DString * dirPtr,
char * pattern, char * tail,
GlobTypeData * types));
+ /* 161 */
+ EXTERN TclPlatformTypetclPlatform;
+ /* 162 */
+ EXTERN char *tclExecutableName;
+ /* 163 */
+ EXTERN char *tclNativeExecutableName;
typedef struct TclIntStubs {
int magic;
***************
*** 727,732 ****
--- 733,741 ----
void (*tclSetStartupScriptFileName) _ANSI_ARGS_((char * filename)); /* 158 */
char * (*tclGetStartupScriptFileName) _ANSI_ARGS_((void)); /* 159 */
int (*tclpMatchFilesTypes) _ANSI_ARGS_((Tcl_Interp * interp, char * separators, Tcl_DString * dirPtr, char * pattern, char * tail, GlobTypeData * types)); /* 160 */
+ TclPlatformType *tclPlatform_; /* 161 */
+ char * *tclExecutableName_; /* 162 */
+ char * *tclNativeExecutableName_; /* 163 */
} TclIntStubs;
#ifdef __cplusplus
***************
*** 1379,1384 ****
--- 1388,1405 ----
#ifndef TclpMatchFilesTypes
#define TclpMatchFilesTypes \
(tclIntStubsPtr->tclpMatchFilesTypes) /* 160 */
+ #endif
+ #ifndef tclPlatform
+ #define tclPlatform \
+ (*tclIntStubsPtr->tclPlatform_) /* 161 */
+ #endif
+ #ifndef tclExecutableName
+ #define tclExecutableName \
+ (*tclIntStubsPtr->tclExecutableName_) /* 162 */
+ #endif
+ #ifndef tclNativeExecutableName
+ #define tclNativeExecutableName \
+ (*tclIntStubsPtr->tclNativeExecutableName_) /* 163 */
#endif
#endif /* defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS) */
*** generic/tclStubInit.c.origTue May 2 20:16:53 2000
--- generic/tclStubInit.cTue May 2 20:20:07 2000
***************
*** 236,241 ****
--- 236,244 ----
TclSetStartupScriptFileName, /* 158 */
TclGetStartupScriptFileName, /* 159 */
TclpMatchFilesTypes, /* 160 */
+ &tclPlatform, /* 161 */
+ &tclExecutableName, /* 162 */
+ &tclNativeExecutableName, /* 163 */
};
TclIntPlatStubs tclIntPlatStubs = {
*** generic/tclTest.c.origTue May 2 20:21:48 2000
--- generic/tclTest.cTue May 2 20:23:29 2000
***************
*** 1768,1780 ****
char **argv;/* Argument strings. */
{
static char *platformStrings[] = { "unix", "mac", "windows" };
- TclPlatformType *platform;
-
- #ifdef __WIN32__
- platform = TclWinGetPlatform();
- #else
- platform = &tclPlatform;
- #endif
if (argc != 1) {
Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0],
--- 1768,1773 ----
***************
*** 1782,1788 ****
return TCL_ERROR;
}
! Tcl_AppendResult(interp, platformStrings[*platform], NULL);
return TCL_OK;
}
--- 1775,1781 ----
return TCL_ERROR;
}
! Tcl_AppendResult(interp, platformStrings[tclPlatform], NULL);
return TCL_OK;
}
***************
*** 2909,2921 ****
char **argv;/* Argument strings. */
{
size_t length;
- TclPlatformType *platform;
-
- #ifdef __WIN32__
- platform = TclWinGetPlatform();
- #else
- platform = &tclPlatform;
- #endif
if (argc != 2) {
Tcl_AppendResult(interp, "wrong # arguments: should be \"", argv[0],
--- 2902,2907 ----
***************
*** 2925,2935 ****
length = strlen(argv[1]);
if (strncmp(argv[1], "unix", length) == 0) {
! *platform = TCL_PLATFORM_UNIX;
} else if (strncmp(argv[1], "mac", length) == 0) {
! *platform = TCL_PLATFORM_MAC;
} else if (strncmp(argv[1], "windows", length) == 0) {
! *platform = TCL_PLATFORM_WINDOWS;
} else {
Tcl_AppendResult(interp, "unsupported platform: should be one of ",
"unix, mac, or windows", (char *) NULL);
--- 2911,2921 ----
length = strlen(argv[1]);
if (strncmp(argv[1], "unix", length) == 0) {
! tclPlatform = TCL_PLATFORM_UNIX;
} else if (strncmp(argv[1], "mac", length) == 0) {
! tclPlatform = TCL_PLATFORM_MAC;
} else if (strncmp(argv[1], "windows", length) == 0) {
! tclPlatform = TCL_PLATFORM_WINDOWS;
} else {
Tcl_AppendResult(interp, "unsupported platform: should be one of ",
"unix, mac, or windows", (char *) NULL);
*** tools/genStubs.tcl.origThu Jun 10 06:29:01 1999
--- tools/genStubs.tclTue May 2 20:15:40 2000
***************
*** 267,274 ****
proc genStubs::parseDecl {decl} {
if {![regexp {^(.*)\((.*)\)$} $decl all prefix args]} {
! puts stderr "Malformed declaration: $decl"
! return
}
set prefix [string trim $prefix]
if {![regexp {^(.+[ ][*]*)([^ *]+)$} $prefix all rtype fname]} {
--- 267,274 ----
proc genStubs::parseDecl {decl} {
if {![regexp {^(.*)\((.*)\)$} $decl all prefix args]} {
! set prefix $decl
! set args {}
}
set prefix [string trim $prefix]
if {![regexp {^(.+[ ][*]*)([^ *]+)$} $prefix all rtype fname]} {
***************
*** 276,281 ****
--- 276,284 ----
return
}
set rtype [string trim $rtype]
+ if {$args == ""} {
+ return [list $rtype $fname {}]
+ }
foreach arg [split $args ,] {
lappend argList [string trim $arg]
}
***************
*** 357,362 ****
--- 360,371 ----
append line " "
set pad 0
}
+ if {$args == ""} {
+ append line $fname
+ append text $line
+ append text ";\n"
+ return $text
+ }
append line "$fname _ANSI_ARGS_("
set arg1 [lindex $args 0]
***************
*** 412,417 ****
--- 421,432 ----
append lfname [string range $fname 1 end]
set text "#ifndef $fname\n#define $fname"
+
+ if {$args == ""} {
+ append text " \\\n\t(*${name}StubsPtr->${lfname}_)"
+ append text " /* $index */\n#endif\n"
+ return $text
+ }
set arg1 [lindex $args 0]
set argList ""
switch -exact $arg1 {
***************
*** 518,523 ****
--- 533,543 ----
append lfname [string range $fname 1 end]
set text " "
+ if {$args == ""} {
+ append lfname _
+ append text $rtype " *" $lfname "; /* $index */\n"
+ return $text
+ }
append text $rtype " (*" $lfname ") _ANSI_ARGS_("
set arg1 [lindex $args 0]
***************
*** 557,563 ****
#Returns the formatted declaration string.
proc genStubs::makeInit {name decl index} {
! append text " " [lindex $decl 1] ", /* " $index " */\n"
return $text
}
--- 577,587 ----
#Returns the formatted declaration string.
proc genStubs::makeInit {name decl index} {
! if {[lindex $decl 2] == ""} {
! append text " &" [lindex $decl 1] ", /* " $index " */\n"
! } else {
! append text " " [lindex $decl 1] ", /* " $index " */\n"
! }
return $text
}
PatchFiles:
tclInt.decls tclIntDecls.h tclStubInit.c tclTest.c genStubs.tcl
We shouldn't open up global vars like this. Instead accessor
functions should be used.
-- 05/17/2000 hobbs
welch Closed ticket [218407ffff].
[History diff]2000-10-26 08:21:18
dgp Open ticket [218407ffff].
[History diff]2001-04-20 02:13:02
dgp Closed ticket [218407ffff].
[History diff]2001-04-20 02:16:37
Log in (anonymous is fine) to add a comment.