Fossil SCM
Eliminate the need for the Tcl stub library to be linked with. Fossil uses public Tcl functions only, so tclStubPtr is the only variable which needs to be present and initialized. The function Tcl_InitStubs reduces to only 15 lines of code, which as well can be put in directly. Advantage: Presence of 3 header files (tcl.h, tclDecls.h and tclPlatDecls.h) from whatever Tcl version is sufficient to compile Fossil with Tcl support through stubs.
Commit
9f77be88a2da8ea675010efa268f8a37a963d00d
Parent
0bcb7707cee102f…
5 files changed
+5
-7
+1
-3
+25
-2
+1
-3
+1
-3
M
auto.def
+5
-7
| --- auto.def | ||
| +++ auto.def | ||
| @@ -122,24 +122,22 @@ | ||
| 122 | 122 | define USE_TCL_STUBS |
| 123 | 123 | } else { |
| 124 | 124 | set libs "$tclconfig(TCL_LIB_SPEC) $tclconfig(TCL_LIBS)" |
| 125 | 125 | } |
| 126 | 126 | set cflags $tclconfig(TCL_INCLUDE_SPEC) |
| 127 | - cc-with [list -cflags $cflags -libs $libs] { | |
| 128 | - if {$tclstubs} { | |
| 129 | - if {![cc-check-functions Tcl_InitStubs]} { | |
| 130 | - user-error "Cannot find a usable Tcl stubs library $msg" | |
| 131 | - } | |
| 132 | - } else { | |
| 127 | + if {!$tclstubs} { | |
| 128 | + cc-with [list -cflags $cflags -libs $libs] { | |
| 133 | 129 | if {![cc-check-functions Tcl_CreateInterp]} { |
| 134 | 130 | user-error "Cannot find a usable Tcl library $msg" |
| 135 | 131 | } |
| 136 | 132 | } |
| 137 | 133 | } |
| 138 | 134 | set version $tclconfig(TCL_VERSION)$tclconfig(TCL_PATCH_LEVEL) |
| 139 | 135 | msg-result "Found Tcl $version at $tclconfig(TCL_PREFIX)" |
| 140 | - define-append LIBS $libs | |
| 136 | + if {!$tclstubs} { | |
| 137 | + define-append LIBS $libs | |
| 138 | + } | |
| 141 | 139 | define-append EXTRA_CFLAGS $cflags |
| 142 | 140 | define-append EXTRA_LDFLAGS $tclconfig(TCL_LD_FLAGS) |
| 143 | 141 | define FOSSIL_ENABLE_TCL |
| 144 | 142 | } |
| 145 | 143 | |
| 146 | 144 |
| --- auto.def | |
| +++ auto.def | |
| @@ -122,24 +122,22 @@ | |
| 122 | define USE_TCL_STUBS |
| 123 | } else { |
| 124 | set libs "$tclconfig(TCL_LIB_SPEC) $tclconfig(TCL_LIBS)" |
| 125 | } |
| 126 | set cflags $tclconfig(TCL_INCLUDE_SPEC) |
| 127 | cc-with [list -cflags $cflags -libs $libs] { |
| 128 | if {$tclstubs} { |
| 129 | if {![cc-check-functions Tcl_InitStubs]} { |
| 130 | user-error "Cannot find a usable Tcl stubs library $msg" |
| 131 | } |
| 132 | } else { |
| 133 | if {![cc-check-functions Tcl_CreateInterp]} { |
| 134 | user-error "Cannot find a usable Tcl library $msg" |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | set version $tclconfig(TCL_VERSION)$tclconfig(TCL_PATCH_LEVEL) |
| 139 | msg-result "Found Tcl $version at $tclconfig(TCL_PREFIX)" |
| 140 | define-append LIBS $libs |
| 141 | define-append EXTRA_CFLAGS $cflags |
| 142 | define-append EXTRA_LDFLAGS $tclconfig(TCL_LD_FLAGS) |
| 143 | define FOSSIL_ENABLE_TCL |
| 144 | } |
| 145 | |
| 146 |
| --- auto.def | |
| +++ auto.def | |
| @@ -122,24 +122,22 @@ | |
| 122 | define USE_TCL_STUBS |
| 123 | } else { |
| 124 | set libs "$tclconfig(TCL_LIB_SPEC) $tclconfig(TCL_LIBS)" |
| 125 | } |
| 126 | set cflags $tclconfig(TCL_INCLUDE_SPEC) |
| 127 | if {!$tclstubs} { |
| 128 | cc-with [list -cflags $cflags -libs $libs] { |
| 129 | if {![cc-check-functions Tcl_CreateInterp]} { |
| 130 | user-error "Cannot find a usable Tcl library $msg" |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | set version $tclconfig(TCL_VERSION)$tclconfig(TCL_PATCH_LEVEL) |
| 135 | msg-result "Found Tcl $version at $tclconfig(TCL_PREFIX)" |
| 136 | if {!$tclstubs} { |
| 137 | define-append LIBS $libs |
| 138 | } |
| 139 | define-append EXTRA_CFLAGS $cflags |
| 140 | define-append EXTRA_LDFLAGS $tclconfig(TCL_LD_FLAGS) |
| 141 | define FOSSIL_ENABLE_TCL |
| 142 | } |
| 143 | |
| 144 |
+1
-3
| --- src/makemake.tcl | ||
| +++ src/makemake.tcl | ||
| @@ -449,13 +449,11 @@ | ||
| 449 | 449 | TCLINCDIR = $(TCLDIR)/include |
| 450 | 450 | TCLLIBDIR = $(TCLDIR)/lib |
| 451 | 451 | |
| 452 | 452 | #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? |
| 453 | 453 | # |
| 454 | -ifdef FOSSIL_ENABLE_TCL_STUBS | |
| 455 | -LIBTCL = -ltclstub86 | |
| 456 | -else | |
| 454 | +ifndef FOSSIL_ENABLE_TCL_STUBS | |
| 457 | 455 | LIBTCL = -ltcl86 |
| 458 | 456 | endif |
| 459 | 457 | |
| 460 | 458 | #### C Compile and options for use in building executables that |
| 461 | 459 | # will run on the target platform. This is usually the same |
| 462 | 460 |
| --- src/makemake.tcl | |
| +++ src/makemake.tcl | |
| @@ -449,13 +449,11 @@ | |
| 449 | TCLINCDIR = $(TCLDIR)/include |
| 450 | TCLLIBDIR = $(TCLDIR)/lib |
| 451 | |
| 452 | #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? |
| 453 | # |
| 454 | ifdef FOSSIL_ENABLE_TCL_STUBS |
| 455 | LIBTCL = -ltclstub86 |
| 456 | else |
| 457 | LIBTCL = -ltcl86 |
| 458 | endif |
| 459 | |
| 460 | #### C Compile and options for use in building executables that |
| 461 | # will run on the target platform. This is usually the same |
| 462 |
| --- src/makemake.tcl | |
| +++ src/makemake.tcl | |
| @@ -449,13 +449,11 @@ | |
| 449 | TCLINCDIR = $(TCLDIR)/include |
| 450 | TCLLIBDIR = $(TCLDIR)/lib |
| 451 | |
| 452 | #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? |
| 453 | # |
| 454 | ifndef FOSSIL_ENABLE_TCL_STUBS |
| 455 | LIBTCL = -ltcl86 |
| 456 | endif |
| 457 | |
| 458 | #### C Compile and options for use in building executables that |
| 459 | # will run on the target platform. This is usually the same |
| 460 |
+25
-2
| --- src/th_tcl.c | ||
| +++ src/th_tcl.c | ||
| @@ -119,10 +119,18 @@ | ||
| 119 | 119 | # define TCL_FINDEXECUTABLE_NAME "_Tcl_FindExecutable" |
| 120 | 120 | # endif |
| 121 | 121 | # ifndef TCL_CREATEINTERP_NAME |
| 122 | 122 | # define TCL_CREATEINTERP_NAME "_Tcl_CreateInterp" |
| 123 | 123 | # endif |
| 124 | +#define tclStubsPtr staticTclStubsPtr | |
| 125 | +static const TclStubs *tclStubsPtr = NULL; | |
| 126 | +typedef struct { | |
| 127 | + char *notused1; | |
| 128 | + Tcl_FreeProc *notused2; | |
| 129 | + int notused3; | |
| 130 | + const struct TclStubs *stubTable; | |
| 131 | +} Interp; | |
| 124 | 132 | #endif /* defined(USE_TCL_STUBS) */ |
| 125 | 133 | |
| 126 | 134 | /* |
| 127 | 135 | ** The function types for Tcl_FindExecutable and Tcl_CreateInterp are needed |
| 128 | 136 | ** when the Tcl library is being loaded dynamically by a stubs-enabled |
| @@ -673,14 +681,29 @@ | ||
| 673 | 681 | if( argc>0 && argv ){ |
| 674 | 682 | argv0 = argv[0]; |
| 675 | 683 | } |
| 676 | 684 | tclContext->xFindExecutable(argv0); |
| 677 | 685 | tclInterp = tclContext->xCreateInterp(); |
| 678 | - if( !tclInterp || | |
| 686 | + | |
| 679 | 687 | #if defined(USE_TCL_STUBS) |
| 680 | - !Tcl_InitStubs(tclInterp, "8.4", 0) || | |
| 688 | + if( tclInterp ){ | |
| 689 | + tclStubsPtr = ((Interp *) tclInterp)->stubTable; | |
| 690 | + if (!tclStubsPtr || (tclStubsPtr->magic != TCL_STUB_MAGIC)) { | |
| 691 | + Th_ErrorMessage(interp, | |
| 692 | + "could not create Tcl interpreter: " | |
| 693 | + "incompatible stubs mechanism", (const char *)"", 0); | |
| 694 | + return TH_ERROR; | |
| 695 | + } | |
| 696 | + if( Tcl_PkgRequireEx(tclInterp, "Tcl", "8.4", 0, (void *)&tclStubsPtr)==0 ){ | |
| 697 | + Th_ErrorMessage(interp, | |
| 698 | + "could not create Tcl interpreter: " | |
| 699 | + "incompatible version", (const char *)"", 0); | |
| 700 | + return TH_ERROR; | |
| 701 | + } | |
| 702 | + } | |
| 681 | 703 | #endif |
| 704 | + if( !tclInterp || | |
| 682 | 705 | Tcl_InterpDeleted(tclInterp) ){ |
| 683 | 706 | Th_ErrorMessage(interp, |
| 684 | 707 | "could not create Tcl interpreter", (const char *)"", 0); |
| 685 | 708 | return TH_ERROR; |
| 686 | 709 | } |
| 687 | 710 |
| --- src/th_tcl.c | |
| +++ src/th_tcl.c | |
| @@ -119,10 +119,18 @@ | |
| 119 | # define TCL_FINDEXECUTABLE_NAME "_Tcl_FindExecutable" |
| 120 | # endif |
| 121 | # ifndef TCL_CREATEINTERP_NAME |
| 122 | # define TCL_CREATEINTERP_NAME "_Tcl_CreateInterp" |
| 123 | # endif |
| 124 | #endif /* defined(USE_TCL_STUBS) */ |
| 125 | |
| 126 | /* |
| 127 | ** The function types for Tcl_FindExecutable and Tcl_CreateInterp are needed |
| 128 | ** when the Tcl library is being loaded dynamically by a stubs-enabled |
| @@ -673,14 +681,29 @@ | |
| 673 | if( argc>0 && argv ){ |
| 674 | argv0 = argv[0]; |
| 675 | } |
| 676 | tclContext->xFindExecutable(argv0); |
| 677 | tclInterp = tclContext->xCreateInterp(); |
| 678 | if( !tclInterp || |
| 679 | #if defined(USE_TCL_STUBS) |
| 680 | !Tcl_InitStubs(tclInterp, "8.4", 0) || |
| 681 | #endif |
| 682 | Tcl_InterpDeleted(tclInterp) ){ |
| 683 | Th_ErrorMessage(interp, |
| 684 | "could not create Tcl interpreter", (const char *)"", 0); |
| 685 | return TH_ERROR; |
| 686 | } |
| 687 |
| --- src/th_tcl.c | |
| +++ src/th_tcl.c | |
| @@ -119,10 +119,18 @@ | |
| 119 | # define TCL_FINDEXECUTABLE_NAME "_Tcl_FindExecutable" |
| 120 | # endif |
| 121 | # ifndef TCL_CREATEINTERP_NAME |
| 122 | # define TCL_CREATEINTERP_NAME "_Tcl_CreateInterp" |
| 123 | # endif |
| 124 | #define tclStubsPtr staticTclStubsPtr |
| 125 | static const TclStubs *tclStubsPtr = NULL; |
| 126 | typedef struct { |
| 127 | char *notused1; |
| 128 | Tcl_FreeProc *notused2; |
| 129 | int notused3; |
| 130 | const struct TclStubs *stubTable; |
| 131 | } Interp; |
| 132 | #endif /* defined(USE_TCL_STUBS) */ |
| 133 | |
| 134 | /* |
| 135 | ** The function types for Tcl_FindExecutable and Tcl_CreateInterp are needed |
| 136 | ** when the Tcl library is being loaded dynamically by a stubs-enabled |
| @@ -673,14 +681,29 @@ | |
| 681 | if( argc>0 && argv ){ |
| 682 | argv0 = argv[0]; |
| 683 | } |
| 684 | tclContext->xFindExecutable(argv0); |
| 685 | tclInterp = tclContext->xCreateInterp(); |
| 686 | |
| 687 | #if defined(USE_TCL_STUBS) |
| 688 | if( tclInterp ){ |
| 689 | tclStubsPtr = ((Interp *) tclInterp)->stubTable; |
| 690 | if (!tclStubsPtr || (tclStubsPtr->magic != TCL_STUB_MAGIC)) { |
| 691 | Th_ErrorMessage(interp, |
| 692 | "could not create Tcl interpreter: " |
| 693 | "incompatible stubs mechanism", (const char *)"", 0); |
| 694 | return TH_ERROR; |
| 695 | } |
| 696 | if( Tcl_PkgRequireEx(tclInterp, "Tcl", "8.4", 0, (void *)&tclStubsPtr)==0 ){ |
| 697 | Th_ErrorMessage(interp, |
| 698 | "could not create Tcl interpreter: " |
| 699 | "incompatible version", (const char *)"", 0); |
| 700 | return TH_ERROR; |
| 701 | } |
| 702 | } |
| 703 | #endif |
| 704 | if( !tclInterp || |
| 705 | Tcl_InterpDeleted(tclInterp) ){ |
| 706 | Th_ErrorMessage(interp, |
| 707 | "could not create Tcl interpreter", (const char *)"", 0); |
| 708 | return TH_ERROR; |
| 709 | } |
| 710 |
+1
-3
| --- win/Makefile.mingw | ||
| +++ win/Makefile.mingw | ||
| @@ -110,13 +110,11 @@ | ||
| 110 | 110 | TCLINCDIR = $(TCLDIR)/include |
| 111 | 111 | TCLLIBDIR = $(TCLDIR)/lib |
| 112 | 112 | |
| 113 | 113 | #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? |
| 114 | 114 | # |
| 115 | -ifdef FOSSIL_ENABLE_TCL_STUBS | |
| 116 | -LIBTCL = -ltclstub86 | |
| 117 | -else | |
| 115 | +ifndef FOSSIL_ENABLE_TCL_STUBS | |
| 118 | 116 | LIBTCL = -ltcl86 |
| 119 | 117 | endif |
| 120 | 118 | |
| 121 | 119 | #### C Compile and options for use in building executables that |
| 122 | 120 | # will run on the target platform. This is usually the same |
| 123 | 121 |
| --- win/Makefile.mingw | |
| +++ win/Makefile.mingw | |
| @@ -110,13 +110,11 @@ | |
| 110 | TCLINCDIR = $(TCLDIR)/include |
| 111 | TCLLIBDIR = $(TCLDIR)/lib |
| 112 | |
| 113 | #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? |
| 114 | # |
| 115 | ifdef FOSSIL_ENABLE_TCL_STUBS |
| 116 | LIBTCL = -ltclstub86 |
| 117 | else |
| 118 | LIBTCL = -ltcl86 |
| 119 | endif |
| 120 | |
| 121 | #### C Compile and options for use in building executables that |
| 122 | # will run on the target platform. This is usually the same |
| 123 |
| --- win/Makefile.mingw | |
| +++ win/Makefile.mingw | |
| @@ -110,13 +110,11 @@ | |
| 110 | TCLINCDIR = $(TCLDIR)/include |
| 111 | TCLLIBDIR = $(TCLDIR)/lib |
| 112 | |
| 113 | #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? |
| 114 | # |
| 115 | ifndef FOSSIL_ENABLE_TCL_STUBS |
| 116 | LIBTCL = -ltcl86 |
| 117 | endif |
| 118 | |
| 119 | #### C Compile and options for use in building executables that |
| 120 | # will run on the target platform. This is usually the same |
| 121 |
+1
-3
| --- win/Makefile.mingw.mistachkin | ||
| +++ win/Makefile.mingw.mistachkin | ||
| @@ -110,13 +110,11 @@ | ||
| 110 | 110 | TCLINCDIR = $(TCLDIR)/include |
| 111 | 111 | TCLLIBDIR = $(TCLDIR)/lib |
| 112 | 112 | |
| 113 | 113 | #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? |
| 114 | 114 | # |
| 115 | -ifdef FOSSIL_ENABLE_TCL_STUBS | |
| 116 | -LIBTCL = -ltclstub86 | |
| 117 | -else | |
| 115 | +ifndef FOSSIL_ENABLE_TCL_STUBS | |
| 118 | 116 | LIBTCL = -ltcl86 |
| 119 | 117 | endif |
| 120 | 118 | |
| 121 | 119 | #### C Compile and options for use in building executables that |
| 122 | 120 | # will run on the target platform. This is usually the same |
| 123 | 121 |
| --- win/Makefile.mingw.mistachkin | |
| +++ win/Makefile.mingw.mistachkin | |
| @@ -110,13 +110,11 @@ | |
| 110 | TCLINCDIR = $(TCLDIR)/include |
| 111 | TCLLIBDIR = $(TCLDIR)/lib |
| 112 | |
| 113 | #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? |
| 114 | # |
| 115 | ifdef FOSSIL_ENABLE_TCL_STUBS |
| 116 | LIBTCL = -ltclstub86 |
| 117 | else |
| 118 | LIBTCL = -ltcl86 |
| 119 | endif |
| 120 | |
| 121 | #### C Compile and options for use in building executables that |
| 122 | # will run on the target platform. This is usually the same |
| 123 |
| --- win/Makefile.mingw.mistachkin | |
| +++ win/Makefile.mingw.mistachkin | |
| @@ -110,13 +110,11 @@ | |
| 110 | TCLINCDIR = $(TCLDIR)/include |
| 111 | TCLLIBDIR = $(TCLDIR)/lib |
| 112 | |
| 113 | #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)? |
| 114 | # |
| 115 | ifndef FOSSIL_ENABLE_TCL_STUBS |
| 116 | LIBTCL = -ltcl86 |
| 117 | endif |
| 118 | |
| 119 | #### C Compile and options for use in building executables that |
| 120 | # will run on the target platform. This is usually the same |
| 121 |