Fossil SCM

load Tcl dynamically using the Stubs mechanism in stead of linking in the library statically.

jan.nijtmans 2012-09-28 07:26 UTC trunk
Commit ba91fe5f9e999b98429601712faf8dca5f7f9a4d
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -424,11 +424,11 @@
424424
TCLINCDIR = $(TCLDIR)/include
425425
TCLLIBDIR = $(TCLDIR)/lib
426426
427427
#### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)?
428428
#
429
-LIBTCL = -ltcl86
429
+LIBTCL = -ltclstub86
430430
431431
#### C Compile and options for use in building executables that
432432
# will run on the target platform. This is usually the same
433433
# as BCC, unless you are cross-compiling. This C compiler builds
434434
# the finished binary for fossil. The BCC compiler above is used
@@ -462,13 +462,13 @@
462462
ifdef FOSSIL_ENABLE_SSL
463463
TCC += -DFOSSIL_ENABLE_SSL=1
464464
RCC += -DFOSSIL_ENABLE_SSL=1
465465
endif
466466
467
-# With Tcl support (statically linked)
467
+# With Tcl support
468468
ifdef FOSSIL_ENABLE_TCL
469
-TCC += -DFOSSIL_ENABLE_TCL=1 -DSTATIC_BUILD
469
+TCC += -DFOSSIL_ENABLE_TCL=1 -DUSE_TCL_STUBS
470470
RCC += -DFOSSIL_ENABLE_TCL=1
471471
endif
472472
473473
# With JSON support
474474
ifdef FOSSIL_ENABLE_JSON
475475
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -424,11 +424,11 @@
424 TCLINCDIR = $(TCLDIR)/include
425 TCLLIBDIR = $(TCLDIR)/lib
426
427 #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)?
428 #
429 LIBTCL = -ltcl86
430
431 #### C Compile and options for use in building executables that
432 # will run on the target platform. This is usually the same
433 # as BCC, unless you are cross-compiling. This C compiler builds
434 # the finished binary for fossil. The BCC compiler above is used
@@ -462,13 +462,13 @@
462 ifdef FOSSIL_ENABLE_SSL
463 TCC += -DFOSSIL_ENABLE_SSL=1
464 RCC += -DFOSSIL_ENABLE_SSL=1
465 endif
466
467 # With Tcl support (statically linked)
468 ifdef FOSSIL_ENABLE_TCL
469 TCC += -DFOSSIL_ENABLE_TCL=1 -DSTATIC_BUILD
470 RCC += -DFOSSIL_ENABLE_TCL=1
471 endif
472
473 # With JSON support
474 ifdef FOSSIL_ENABLE_JSON
475
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -424,11 +424,11 @@
424 TCLINCDIR = $(TCLDIR)/include
425 TCLLIBDIR = $(TCLDIR)/lib
426
427 #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)?
428 #
429 LIBTCL = -ltclstub86
430
431 #### C Compile and options for use in building executables that
432 # will run on the target platform. This is usually the same
433 # as BCC, unless you are cross-compiling. This C compiler builds
434 # the finished binary for fossil. The BCC compiler above is used
@@ -462,13 +462,13 @@
462 ifdef FOSSIL_ENABLE_SSL
463 TCC += -DFOSSIL_ENABLE_SSL=1
464 RCC += -DFOSSIL_ENABLE_SSL=1
465 endif
466
467 # With Tcl support
468 ifdef FOSSIL_ENABLE_TCL
469 TCC += -DFOSSIL_ENABLE_TCL=1 -DUSE_TCL_STUBS
470 RCC += -DFOSSIL_ENABLE_TCL=1
471 endif
472
473 # With JSON support
474 ifdef FOSSIL_ENABLE_JSON
475
+53 -2
--- src/th_tcl.c
+++ src/th_tcl.c
@@ -35,10 +35,16 @@
3535
** Tcl_EvalObjv instead of invoking the objProc directly.
3636
*/
3737
#define USE_TCL_EVALOBJV 1
3838
#endif
3939
40
+#ifdef _WIN32
41
+# include <windows.h>
42
+#else
43
+# include <dlfcn.h>
44
+#endif
45
+
4046
/*
4147
** These macros are designed to reduce the redundant code required to marshal
4248
** arguments from TH1 to Tcl.
4349
*/
4450
#define USE_ARGV_TO_OBJV() \
@@ -445,10 +451,28 @@
445451
){
446452
struct TclContext *tclContext = (struct TclContext *)pContext;
447453
int argc;
448454
char **argv;
449455
char *argv0 = 0;
456
+#ifdef USE_TCL_STUBS
457
+#ifdef _WIN32
458
+ WCHAR lib[] = L"tcl87.dll";
459
+#define minver lib[4]
460
+#define dlopen(a,b) (void *)LoadLibraryW(a);
461
+#define dlsym(a,b) GetProcAddress((HANDLE)(a),b);
462
+#else
463
+#ifdef __CYGWIN__
464
+ char lib[] = "libtcl8.7.dll";
465
+#else
466
+ char lib[] = "libtcl8.7.so";
467
+#endif
468
+#define minver lib[8]
469
+#endif
470
+ void *handle = NULL;
471
+ void (*findExecutable)(const char *) = 0;
472
+ Tcl_Interp *(*createInterp)() = 0;
473
+#endif /* USE_TCL_STUBS */
450474
Tcl_Interp *tclInterp;
451475
452476
if ( !tclContext ){
453477
Th_ErrorMessage(interp,
454478
"Invalid Tcl context", (const char *)"", 0);
@@ -460,17 +484,44 @@
460484
argc = tclContext->argc;
461485
argv = tclContext->argv;
462486
if( argc>0 && argv ){
463487
argv0 = argv[0];
464488
}
489
+#ifdef USE_TCL_STUBS
490
+ while( --minver>'3' ){
491
+ handle = dlopen(lib, RTLD_NOW | RTLD_LOCAL);
492
+ if( handle ) {
493
+ const char *sym = "_Tcl_FindExecutable";
494
+ findExecutable = (void (*)(const char *)) dlsym(handle, sym+1);
495
+ if (!findExecutable)
496
+ findExecutable = (void (*)(const char *)) dlsym(handle, sym);
497
+ sym = "_Tcl_CreateInterp";
498
+ createInterp = (Tcl_Interp * (*)(void)) dlsym(handle, sym+1);
499
+ if (!createInterp)
500
+ createInterp = (Tcl_Interp * (*)(void)) dlsym(handle, sym);
501
+ break;
502
+ }
503
+ }
504
+ if( !handle ){
505
+ Th_ErrorMessage(interp,
506
+ "Could not create Tcl interpreter", (const char *)"", 0);
507
+ return TH_ERROR;
508
+ }
509
+# undef Tcl_FindExecutable
510
+# define Tcl_FindExecutable findExecutable
511
+# undef Tcl_CreateInterp
512
+# define Tcl_CreateInterp createInterp
513
+#endif /* USE_TCL_STUBS */
465514
Tcl_FindExecutable(argv0);
466
- tclInterp = tclContext->interp = Tcl_CreateInterp();
467
- if( !tclInterp || Tcl_InterpDeleted(tclInterp) ){
515
+ tclInterp = Tcl_CreateInterp();
516
+ if( !tclInterp || !Tcl_InitStubs(tclInterp, "8.4", 0)
517
+ || Tcl_InterpDeleted(tclInterp) ){
468518
Th_ErrorMessage(interp,
469519
"Could not create Tcl interpreter", (const char *)"", 0);
470520
return TH_ERROR;
471521
}
522
+ tclContext->interp = tclInterp;
472523
if( Tcl_Init(tclInterp)!=TCL_OK ){
473524
Th_ErrorMessage(interp,
474525
"Tcl initialization error:", Tcl_GetStringResult(tclInterp), -1);
475526
Tcl_DeleteInterp(tclInterp);
476527
tclContext->interp = tclInterp = 0;
477528
--- src/th_tcl.c
+++ src/th_tcl.c
@@ -35,10 +35,16 @@
35 ** Tcl_EvalObjv instead of invoking the objProc directly.
36 */
37 #define USE_TCL_EVALOBJV 1
38 #endif
39
 
 
 
 
 
 
40 /*
41 ** These macros are designed to reduce the redundant code required to marshal
42 ** arguments from TH1 to Tcl.
43 */
44 #define USE_ARGV_TO_OBJV() \
@@ -445,10 +451,28 @@
445 ){
446 struct TclContext *tclContext = (struct TclContext *)pContext;
447 int argc;
448 char **argv;
449 char *argv0 = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450 Tcl_Interp *tclInterp;
451
452 if ( !tclContext ){
453 Th_ErrorMessage(interp,
454 "Invalid Tcl context", (const char *)"", 0);
@@ -460,17 +484,44 @@
460 argc = tclContext->argc;
461 argv = tclContext->argv;
462 if( argc>0 && argv ){
463 argv0 = argv[0];
464 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465 Tcl_FindExecutable(argv0);
466 tclInterp = tclContext->interp = Tcl_CreateInterp();
467 if( !tclInterp || Tcl_InterpDeleted(tclInterp) ){
 
468 Th_ErrorMessage(interp,
469 "Could not create Tcl interpreter", (const char *)"", 0);
470 return TH_ERROR;
471 }
 
472 if( Tcl_Init(tclInterp)!=TCL_OK ){
473 Th_ErrorMessage(interp,
474 "Tcl initialization error:", Tcl_GetStringResult(tclInterp), -1);
475 Tcl_DeleteInterp(tclInterp);
476 tclContext->interp = tclInterp = 0;
477
--- src/th_tcl.c
+++ src/th_tcl.c
@@ -35,10 +35,16 @@
35 ** Tcl_EvalObjv instead of invoking the objProc directly.
36 */
37 #define USE_TCL_EVALOBJV 1
38 #endif
39
40 #ifdef _WIN32
41 # include <windows.h>
42 #else
43 # include <dlfcn.h>
44 #endif
45
46 /*
47 ** These macros are designed to reduce the redundant code required to marshal
48 ** arguments from TH1 to Tcl.
49 */
50 #define USE_ARGV_TO_OBJV() \
@@ -445,10 +451,28 @@
451 ){
452 struct TclContext *tclContext = (struct TclContext *)pContext;
453 int argc;
454 char **argv;
455 char *argv0 = 0;
456 #ifdef USE_TCL_STUBS
457 #ifdef _WIN32
458 WCHAR lib[] = L"tcl87.dll";
459 #define minver lib[4]
460 #define dlopen(a,b) (void *)LoadLibraryW(a);
461 #define dlsym(a,b) GetProcAddress((HANDLE)(a),b);
462 #else
463 #ifdef __CYGWIN__
464 char lib[] = "libtcl8.7.dll";
465 #else
466 char lib[] = "libtcl8.7.so";
467 #endif
468 #define minver lib[8]
469 #endif
470 void *handle = NULL;
471 void (*findExecutable)(const char *) = 0;
472 Tcl_Interp *(*createInterp)() = 0;
473 #endif /* USE_TCL_STUBS */
474 Tcl_Interp *tclInterp;
475
476 if ( !tclContext ){
477 Th_ErrorMessage(interp,
478 "Invalid Tcl context", (const char *)"", 0);
@@ -460,17 +484,44 @@
484 argc = tclContext->argc;
485 argv = tclContext->argv;
486 if( argc>0 && argv ){
487 argv0 = argv[0];
488 }
489 #ifdef USE_TCL_STUBS
490 while( --minver>'3' ){
491 handle = dlopen(lib, RTLD_NOW | RTLD_LOCAL);
492 if( handle ) {
493 const char *sym = "_Tcl_FindExecutable";
494 findExecutable = (void (*)(const char *)) dlsym(handle, sym+1);
495 if (!findExecutable)
496 findExecutable = (void (*)(const char *)) dlsym(handle, sym);
497 sym = "_Tcl_CreateInterp";
498 createInterp = (Tcl_Interp * (*)(void)) dlsym(handle, sym+1);
499 if (!createInterp)
500 createInterp = (Tcl_Interp * (*)(void)) dlsym(handle, sym);
501 break;
502 }
503 }
504 if( !handle ){
505 Th_ErrorMessage(interp,
506 "Could not create Tcl interpreter", (const char *)"", 0);
507 return TH_ERROR;
508 }
509 # undef Tcl_FindExecutable
510 # define Tcl_FindExecutable findExecutable
511 # undef Tcl_CreateInterp
512 # define Tcl_CreateInterp createInterp
513 #endif /* USE_TCL_STUBS */
514 Tcl_FindExecutable(argv0);
515 tclInterp = Tcl_CreateInterp();
516 if( !tclInterp || !Tcl_InitStubs(tclInterp, "8.4", 0)
517 || Tcl_InterpDeleted(tclInterp) ){
518 Th_ErrorMessage(interp,
519 "Could not create Tcl interpreter", (const char *)"", 0);
520 return TH_ERROR;
521 }
522 tclContext->interp = tclInterp;
523 if( Tcl_Init(tclInterp)!=TCL_OK ){
524 Th_ErrorMessage(interp,
525 "Tcl initialization error:", Tcl_GetStringResult(tclInterp), -1);
526 Tcl_DeleteInterp(tclInterp);
527 tclContext->interp = tclInterp = 0;
528
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -96,11 +96,11 @@
9696
TCLINCDIR = $(TCLDIR)/include
9797
TCLLIBDIR = $(TCLDIR)/lib
9898
9999
#### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)?
100100
#
101
-LIBTCL = -ltcl86
101
+LIBTCL = -ltclstub86
102102
103103
#### C Compile and options for use in building executables that
104104
# will run on the target platform. This is usually the same
105105
# as BCC, unless you are cross-compiling. This C compiler builds
106106
# the finished binary for fossil. The BCC compiler above is used
@@ -134,13 +134,13 @@
134134
ifdef FOSSIL_ENABLE_SSL
135135
TCC += -DFOSSIL_ENABLE_SSL=1
136136
RCC += -DFOSSIL_ENABLE_SSL=1
137137
endif
138138
139
-# With Tcl support (statically linked)
139
+# With Tcl support
140140
ifdef FOSSIL_ENABLE_TCL
141
-TCC += -DFOSSIL_ENABLE_TCL=1 -DSTATIC_BUILD
141
+TCC += -DFOSSIL_ENABLE_TCL=1 -DUSE_TCL_STUBS
142142
RCC += -DFOSSIL_ENABLE_TCL=1
143143
endif
144144
145145
# With JSON support
146146
ifdef FOSSIL_ENABLE_JSON
147147
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -96,11 +96,11 @@
96 TCLINCDIR = $(TCLDIR)/include
97 TCLLIBDIR = $(TCLDIR)/lib
98
99 #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)?
100 #
101 LIBTCL = -ltcl86
102
103 #### C Compile and options for use in building executables that
104 # will run on the target platform. This is usually the same
105 # as BCC, unless you are cross-compiling. This C compiler builds
106 # the finished binary for fossil. The BCC compiler above is used
@@ -134,13 +134,13 @@
134 ifdef FOSSIL_ENABLE_SSL
135 TCC += -DFOSSIL_ENABLE_SSL=1
136 RCC += -DFOSSIL_ENABLE_SSL=1
137 endif
138
139 # With Tcl support (statically linked)
140 ifdef FOSSIL_ENABLE_TCL
141 TCC += -DFOSSIL_ENABLE_TCL=1 -DSTATIC_BUILD
142 RCC += -DFOSSIL_ENABLE_TCL=1
143 endif
144
145 # With JSON support
146 ifdef FOSSIL_ENABLE_JSON
147
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -96,11 +96,11 @@
96 TCLINCDIR = $(TCLDIR)/include
97 TCLLIBDIR = $(TCLDIR)/lib
98
99 #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)?
100 #
101 LIBTCL = -ltclstub86
102
103 #### C Compile and options for use in building executables that
104 # will run on the target platform. This is usually the same
105 # as BCC, unless you are cross-compiling. This C compiler builds
106 # the finished binary for fossil. The BCC compiler above is used
@@ -134,13 +134,13 @@
134 ifdef FOSSIL_ENABLE_SSL
135 TCC += -DFOSSIL_ENABLE_SSL=1
136 RCC += -DFOSSIL_ENABLE_SSL=1
137 endif
138
139 # With Tcl support
140 ifdef FOSSIL_ENABLE_TCL
141 TCC += -DFOSSIL_ENABLE_TCL=1 -DUSE_TCL_STUBS
142 RCC += -DFOSSIL_ENABLE_TCL=1
143 endif
144
145 # With JSON support
146 ifdef FOSSIL_ENABLE_JSON
147
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -96,11 +96,11 @@
9696
TCLINCDIR = $(TCLDIR)/include
9797
TCLLIBDIR = $(TCLDIR)/lib
9898
9999
#### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)?
100100
#
101
-LIBTCL = -ltcl86
101
+LIBTCL = -ltclstub86
102102
103103
#### C Compile and options for use in building executables that
104104
# will run on the target platform. This is usually the same
105105
# as BCC, unless you are cross-compiling. This C compiler builds
106106
# the finished binary for fossil. The BCC compiler above is used
@@ -134,13 +134,13 @@
134134
ifdef FOSSIL_ENABLE_SSL
135135
TCC += -DFOSSIL_ENABLE_SSL=1
136136
RCC += -DFOSSIL_ENABLE_SSL=1
137137
endif
138138
139
-# With Tcl support (statically linked)
139
+# With Tcl support
140140
ifdef FOSSIL_ENABLE_TCL
141
-TCC += -DFOSSIL_ENABLE_TCL=1 -DSTATIC_BUILD
141
+TCC += -DFOSSIL_ENABLE_TCL=1 -DUSE_TCL_STUBS
142142
RCC += -DFOSSIL_ENABLE_TCL=1
143143
endif
144144
145145
# With JSON support
146146
ifdef FOSSIL_ENABLE_JSON
147147
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -96,11 +96,11 @@
96 TCLINCDIR = $(TCLDIR)/include
97 TCLLIBDIR = $(TCLDIR)/lib
98
99 #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)?
100 #
101 LIBTCL = -ltcl86
102
103 #### C Compile and options for use in building executables that
104 # will run on the target platform. This is usually the same
105 # as BCC, unless you are cross-compiling. This C compiler builds
106 # the finished binary for fossil. The BCC compiler above is used
@@ -134,13 +134,13 @@
134 ifdef FOSSIL_ENABLE_SSL
135 TCC += -DFOSSIL_ENABLE_SSL=1
136 RCC += -DFOSSIL_ENABLE_SSL=1
137 endif
138
139 # With Tcl support (statically linked)
140 ifdef FOSSIL_ENABLE_TCL
141 TCC += -DFOSSIL_ENABLE_TCL=1 -DSTATIC_BUILD
142 RCC += -DFOSSIL_ENABLE_TCL=1
143 endif
144
145 # With JSON support
146 ifdef FOSSIL_ENABLE_JSON
147
--- win/Makefile.mingw.mistachkin
+++ win/Makefile.mingw.mistachkin
@@ -96,11 +96,11 @@
96 TCLINCDIR = $(TCLDIR)/include
97 TCLLIBDIR = $(TCLDIR)/lib
98
99 #### Tcl: Which Tcl library do we want to use (8.4, 8.5, 8.6, etc)?
100 #
101 LIBTCL = -ltclstub86
102
103 #### C Compile and options for use in building executables that
104 # will run on the target platform. This is usually the same
105 # as BCC, unless you are cross-compiling. This C compiler builds
106 # the finished binary for fossil. The BCC compiler above is used
@@ -134,13 +134,13 @@
134 ifdef FOSSIL_ENABLE_SSL
135 TCC += -DFOSSIL_ENABLE_SSL=1
136 RCC += -DFOSSIL_ENABLE_SSL=1
137 endif
138
139 # With Tcl support
140 ifdef FOSSIL_ENABLE_TCL
141 TCC += -DFOSSIL_ENABLE_TCL=1 -DUSE_TCL_STUBS
142 RCC += -DFOSSIL_ENABLE_TCL=1
143 endif
144
145 # With JSON support
146 ifdef FOSSIL_ENABLE_JSON
147

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button