Tcl package Thread source code

Changes On Branch trunk
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch main Excluding Merge-Ins

This is equivalent to a diff from a1b6d578a2 to 3d0494d96d

2025-06-16
12:47
Updated configure from TEA/tclconfig changes. Leaf check-in: 3d0494d96d user: dgp tags: trunk, main, thread-3-0-2
2025-05-22
15:19
Merge-mark check-in: 1b68cd167b user: jan.nijtmans tags: trunk, main
2020-10-16
20:11
Rename "trunk" to "main", but keep "trunk" as propagating tag. Experiment to see if we can this way mitigate the "master"- > "main" change on GitHub check-in: faa8fa1b30 user: jan.nijtmans tags: trunk, main
09:38
Merge 2.9 Closed-Leaf check-in: a1b6d578a2 user: jan.nijtmans tags: trunk
09:35
Merge 2.8 check-in: a9b7d280e1 user: jan.nijtmans tags: thread-2-branch
06:34
Merge 2.9 check-in: f873180e9c user: jan.nijtmans tags: trunk

Changes to .fossil-settings/ignore-glob.
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24

25
26
27
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29







+









+



*.lo
*.o
*.obj
*.pdb
*.res
*.sl
*.so
*.gz
Makefile
autom4te.cache
config.cache
config.log
config.status
pkgIndex.tcl
*/versions.vc
*/version.vc
html
tclconfig
win/Debug*
win/Release*
win/nmhlp-out.txt
Added .github/workflows/linux-build.yml.































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
name: Linux
on: [push]
permissions:
  contents: read
defaults:
  run:
    shell: bash
jobs:
  build:
    runs-on: ubuntu-24.04
    strategy:
      matrix:
        compiler:
          - "gcc"
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Setup Environment
        run: |
          curl https://core.tcl-lang.org/tclconfig/tarball/main/tclconfig.tar.gz >tclconfig.tar.gz
          tar xfz tclconfig.tar.gz
      - name: Configure (not really, just enough to do a "make dist")
        run: |
          sed s/@srcdir@/\./ <Makefile.in | sed s/@abs_top_builddir@/./ | sed s/@SHELL@/bash/ | sed s/@PACKAGE_NAME@/thread/ | sed s/@PACKAGE_VERSION@/9.0a1/ | sed "s/@INSTALL@/tclconfig\/install-sh/" | sed "s/@INSTALL_DATA_DIR@/tclconfig\/install-sh -d -m 755/" >Makefile
          touch config.status
      - name: Create Distribution Package
        run: |
          make dist || {
            echo "::error::Failure during Distribute"
            exit 1
          }
Changes to ChangeLog.
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350


351
352

353
354
355
356
357
358
359


360
361
362
363
364
365
366
323
324
325
326
327
328
329

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348


349
350
351

352
353
354
355
356
357


358
359
360
361
362
363
364
365
366







-
+


















-
-
+
+

-
+





-
-
+
+








	* generic/threadSpCmd.c (ThreadMutexObjCmd, ThreadRWMutexObjCmd):
	[Bug 3007426]: Dropped trailing commas in enum definitions which
	choked the strictly C89 AIX compiler.

2010-04-01 Zoran Vasiljevic <[email protected]>

        * generic/tclXkeylist.c: Removed declaration of global TclX keylist
	* generic/tclXkeylist.c: Removed declaration of global TclX keylist
	commands.

2010-03-30 Zoran Vasiljevic <[email protected]>

	*** 2.6.6 TAGGED FOR RELEASE (thread-2-6-6) ***

	* configure:              Redo for TEA 3.7
	* configure.in:

	* generic/tclThread.h:    Cosmetic changes for the inclusion
	* generic/threadCmd.c:    in standard Tcl distribution.
	* generic/threadPoolCmd.c:
	* generic/threadSpCmd.c:
	* generic/threadSvCmd.c:
	* generic/threadSvCmd.h:

2010-03-19   Jan Nijtmans <[email protected]>

        * generic/threadSpCmd.c: Silence gcc warning: dereferencing
        * .cvsignore:            type-punned pointer will break
	* generic/threadSpCmd.c: Silence gcc warning: dereferencing
	* .cvsignore:            type-punned pointer will break
				 strict-aliasing rules.
        * configure:             Regenerated using latest TEA
	* configure:             Regenerated using latest TEA

2009-08-19 Zoran Vasiljevic <[email protected]>

	* generic/threadPoolCmd.c: Implemented [tpool::suspend]
	* doc/tpool.man:           and [tpool::resume] commands
	                           as per [RFE #2835615].
	                           Also fixed [Bug #2833864].
				   as per [RFE #2835615].
				   Also fixed [Bug #2833864].

2009-07-22   Jan Nijtmans <[email protected]>

	* generic/tclThread.h:   Remove unnecessary ';'s
	* generic/tclXkeylist.c: Constify remaining of thread extension,
	* generic/tclXkeylist.h: bringing it at the same level as Tcl 8.6
	* generic/threadCmd.c:
602
603
604
605
606
607
608
609

610
611
612
613
614
615

616
617
618
619
620
621
622
602
603
604
605
606
607
608

609
610
611
612
613
614

615
616
617
618
619
620
621
622







-
+





-
+








2005-09-23 Zoran Vasiljevic <[email protected]>

	* generic/threadCmd.c: ThreadDetach() sets the both
	  source and target thread ID's for the detached
	  channel to zero, thus signalizing the cleanup code
	  to leave the channel in the cleanup-list when the
 	  thread who detached it exits.
	  thread who detached it exits.

2005-08-24 Zoran Vasiljevic <[email protected]>

	* generic/tclXkeylist.c: made some calls static
	  so they do not interfere for static linking with
          certain extensions.
	  certain extensions.

2005-08-08 Zoran Vasiljevic <[email protected]>

	* generic/threadSvCmd.c: fixed traversing the list
	  of registered object types in Sv_DuplicateObj()
	  (thx to [email protected])

714
715
716
717
718
719
720
721

722
723
724
725
726
727
728
729
730
731
732
733
734

735
736
737
738
739
740
741
714
715
716
717
718
719
720

721
722
723
724
725
726
727
728
729
730
731
732
733

734
735
736
737
738
739
740
741







-
+












-
+







	We were wrongly tearing down workers on idle timer
	expiry *below* the number of workers set by the
	"-minworkers" option.

	* lib/ttrace.tcl: added [ttrace::config] to control
	some runtime options. The only option it allows now
	is "-doepochs". This is a boolean flag turning the
        epoch generation off/on.
	epoch generation off/on.
	Also, improved handling of XOTcl introspections in
	regard to namespaced objects/classes.

2005-01-03 Zoran Vasiljevic <[email protected]>

	* lib/ttrace.tcl: added [ttrace::isenabled] and modified
	the [ttrace::addtrace] to dynamically activate the tracer
	if the tracing is already enabled. This way we can dynamically
	load tracer scripts.

2005-01-03 Zoran Vasiljevic <[email protected]>

        **** RELEASE: 2.6.1 Tagged ****
	**** RELEASE: 2.6.1 Tagged ****

	* aolserver.m4:
	* configure.in:
	* configure: rebuild and include conditional compilation
	for AOLserver which was wrongly ommited since the switch
	to the TEA3 build system.
	Also, we will now revert to <major>.<minor>.<patch>
751
752
753
754
755
756
757
758

759
760
761
762
763
764
765
751
752
753
754
755
756
757

758
759
760
761
762
763
764
765







-
+







	* generic/threadSvCmd.h:
	* generic/tclThread.h: removed compat macros for 8.3 core

	* test/thread.test: added case for [thread::send -head]

2004-12-23 Zoran Vasiljevic <[email protected]>

        **** RELEASE: 2.6 Tagged ****
	**** RELEASE: 2.6 Tagged ****

	* tcl/cmdsrv/cmdsrv.tcl: example command server listens on
	loopback interface (127.0.0.1) only

	* README: removed stuff about (now unsupported) Tcl8.3 core
	* unix/README: clarified usage of the CONFIG file
	* win/vc: adjusted MSVC files for changes introduced by TEA3
793
794
795
796
797
798
799
800

801
802
803
804
805
806
807
793
794
795
796
797
798
799

800
801
802
803
804
805
806
807







-
+







	This fixes the Tcl Bug #933975.

2004-11-25 Zoran Vasiljevic <[email protected]>

	* tests/thread.tcl: Disabled all tests handling channel transfer
	for Windows ports until core is capable of handling this correctly.

        * generic/threadSpCmd.c: Fixed segmentation problems observed on
	* generic/threadSpCmd.c: Fixed segmentation problems observed on
	Windows ports and related to notification of an uninitialized
	condition variable(s). This closes Bug #1051068 (wrongly posted
	under Tcl Patches at SF).

	* doc/thread.man: Fixed mutex/condvar code example. Thanks to
	Gustaf Neumann of XOTcl for the tip.

908
909
910
911
912
913
914
915
916


917
918
919
920
921
922
923
908
909
910
911
912
913
914


915
916
917
918
919
920
921
922
923







-
-
+
+







	* pkgIndex.tcl.in: fixed Tcl Bug #918137
	* doc/format.tcl: fixed inclusion of man.macros in
	every *.n doc file

2004-01-31 Zoran Vasiljevic <[email protected]>

	* generic/threadCmd.c: fixed incorrect handling of return
        codes from the scripts passed to threads. We were wrongly
        triggering error for non-error return codes such as TCL_RETURN,
	codes from the scripts passed to threads. We were wrongly
	triggering error for non-error return codes such as TCL_RETURN,
	TCL_BREAK, TCL_CONTINUE etc. Now we trigger error only for
	TCL_ERROR and return other codes (as-is) to the caller.
	This also fixes the Tcl Bug #884549.

2003-12-22 Zoran Vasiljevic <[email protected]>

	* generic/threadSpCmd.c: added recursive and reader/writer locks
1012
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040

1041
1042
1043
1044
1045
1046



1047
1048
1049
1050
1051
1052
1053
1012
1013
1014
1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039

1040
1041
1042
1043



1044
1045
1046
1047
1048
1049
1050
1051
1052
1053







-
+




















-
+



-
-
-
+
+
+







	* generic/threadPoolCmd.c: fixed result list corruption
	in TpoolCancelObjCmd.

2003-07-27 Zoran Vasiljevic <[email protected]>

	* generic/threadPoolCmd.c: added "-nowait" option
	to the "tpool::post" commandi. This allows the
 	caller to post jobs to the threadpool queue without
	caller to post jobs to the threadpool queue without
	waiting for an idle thread. The implementation will
	start at least one worker thread if there is none
	available to satisfy the first request.
	Added "tpool::cancel" command. See docs for info.

2003-05-31 Zoran Vasiljevic <[email protected]>

	* generic/threadCmd.c: fixed ListRemoveInner for
	the Tcl Bug #746352

	* generic/threadSpCmd.c: modified Sp_Init to
	return a proper value for Tcl Bug #746352

2003-05-17 Zoran Vasiljevic <[email protected]>

	* generic/threadCmd.c: sets the name of the new thread
	to "-tclthread-" when compiled for AOLserver

2003-04-29 Zoran Vasiljevic <[email protected]>

        Tagged interim 2.5.2 release.
	Tagged interim 2.5.2 release.

	* configure.in
	* configure: Added quick fix for autoconf issues
        related to $srcdir and building of the package
        from the top-level dir instead of unix/win subdir.
        Thanks to Mo DeJong for the fix.
	related to $srcdir and building of the package
	from the top-level dir instead of unix/win subdir.
	Thanks to Mo DeJong for the fix.

2003-04-10 Zoran Vasiljevic <[email protected]>

	* generic/threadCmd.c: removed checking of stopped flag
	during walk of the list of active threads. This
	solves some subtle thread reservation problems
	with threads marked to unwind on error.
1146
1147
1148
1149
1150
1151
1152
1153
1154


1155
1156
1157
1158
1159
1160
1161
1146
1147
1148
1149
1150
1151
1152


1153
1154
1155
1156
1157
1158
1159
1160
1161







-
-
+
+








	* generic/threadSvCmd.c: the tsv::lock now allows
	for unsetting the shared array within the script argument.

	* generic/threadPoolCmd.c: fixed one missing mutex unlock
	in the ThreadRelease.

        * tcl/tpool/tpool.tcl: implemented missing API calls found
 	in the C-level implementation.
	* tcl/tpool/tpool.tcl: implemented missing API calls found
	in the C-level implementation.

	* tcl/phttpd/phttpd.tcl: simplified switching to Tcl-level
	threadpool implementation.

2002-12-04 Zoran Vasiljevic <[email protected]>

	* generic/threadPoolcmd.c: rewritten to use
1169
1170
1171
1172
1173
1174
1175
1176

1177
1178
1179
1180
1181
1182
1183
1169
1170
1171
1172
1173
1174
1175

1176
1177
1178
1179
1180
1181
1182
1183







-
+







	Fixed to include exports from threadPoolCmd.c

	* generic/threadSpCmd.c: does regular namespace handling
	over the NS variable instead of hard-coding the "thread"
	prefix for mutex/cond commands.

	* generic/threadCmd.c: rewritten to use SpliceIn/SpliceOut
        macros instead of hand-fiddling with linked lists.
	macros instead of hand-fiddling with linked lists.

	* generic/threadPoolCmd.c: new file

	* Makefile.in: added threadPoolCmd.c to list of source files.

2002-11-25 Zoran Vasiljevic <[email protected]>

1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283






1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299

1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318

1319
1320
1321
1322

1323
1324
1325
1326
1327
1328
1329
1271
1272
1273
1274
1275
1276
1277






1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317

1318
1319
1320
1321

1322
1323
1324
1325
1326
1327
1328
1329







-
-
-
-
-
-
+
+
+
+
+
+















-
+


















-
+



-
+








	* README: Fix typo.
	* doc/man/thread.n: Note that thread::join and
	thread::transfer are only available with Tcl 8.4.

2002-07-20  Mo DeJong  <[email protected]>

        * generic/threadSvCmd.c (Sv_tclEmptyStringRep, Sv_Init):
        Avoid linking to the tclEmptyStringRep variable defined
        in Tcl since this makes it very difficult to load
        the Thread package into an executable that has
        also loaded Tcl. The previous approach used a hack
        under Windows, we now use this same hack on all systems.
	* generic/threadSvCmd.c (Sv_tclEmptyStringRep, Sv_Init):
	Avoid linking to the tclEmptyStringRep variable defined
	in Tcl since this makes it very difficult to load
	the Thread package into an executable that has
	also loaded Tcl. The previous approach used a hack
	under Windows, we now use this same hack on all systems.
	[Tcl patch 584123]

2002-07-19  Zoran Vasiljevic <[email protected]>

	* threadCmd.c: added some macros to simplify
	adding and removing result structure in and
	out of the corresponding lists

2002-07-18  Zoran Vasiljevic <[email protected]>

	* threadCmd.c: modified thread::release to allow
	for optional "-wait" argument. This will result in
	the thread waiting until the target thread has really
	exited. Otherwise, the command exits immediately and
	target thread may exit asynchronously some time later.
 	This is not techically needed since one can always join
	This is not techically needed since one can always join
	the exiting thread, but the join command is not
	available for some older Tcl versions.

2002-07-13  Zoran Vasiljevic <[email protected]>

	* doc/man:
	* doc/html: added two directories with TMML generated files
	* doc/thread.tmml: fixed for the final 2.4 release
	* Makefile.in: updated install-doc target to look for man files
	under doc/man instead only under doc directory

2002-07-12  Zoran Vasiljevic <[email protected]>

	* generic/threadSvCmd.s: fixed handling of string rep
	in shared var object duplicator

2002-07-09  Zoran Vasiljevic <[email protected]>
	* README: added this file
 	* license.terms: added this file
	* license.terms: added this file

2002-07-05  Zoran Vasiljevic <[email protected]>

        * tclconfig/tcl.m4: fixed reference to MINGW so we can
	* tclconfig/tcl.m4: fixed reference to MINGW so we can
	compile w/o MSVC under windows.

2002-07-03  Zoran Vasiljevic <[email protected]>

	* generic/threadSvCmd.c: simplified object duplicator

2002-06-17  Zoran Vasiljevic <[email protected]>
1463
1464
1465
1466
1467
1468
1469
1470
1471


1472
1473
1474
1475
1476
1477
1478
1463
1464
1465
1466
1467
1468
1469


1470
1471
1472
1473
1474
1475
1476
1477
1478







-
-
+
+







2002-02-06  Zoran Vasiljevic <[email protected]>

	* generic/aolserv.cpp: (new) added for loading into the AOLserver.
	Still needs to fix the Makefile and friends to get it up and
	running.

	* generic/threadCmd.c: added conditional setup of the command
 	prefix. Now, the "NS" can be used to select the command prefix
 	for thread::* commands.
	prefix. Now, the "NS" can be used to select the command prefix
	for thread::* commands.

2002-01-26  David Gravereaux <[email protected]>

	* generic/threadSvCmd.c:  A small 'const' qualifier change to remove a
	warning.  It's a bit more wordy now, but reads a little clearer to me.
	Unscambling pointer math gives me a headache and combined with a cast
	tends to get dangerous.
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523























1524
1525
1526
1527
1528
1529
1530
1494
1495
1496
1497
1498
1499
1500























1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







2002-01-20  Zoran Vasiljevic <[email protected]>

	* generic/threadCmd.c: fixed multiple async reporting of error events
	(thanks Jean-Luc Fontaine for the tip)

2002-01-02  Zoran Vasiljevic <[email protected]>

        * generic/threadSvListCmd.* (new): added for the new implementation
        of the thread-shared-variable (tsv) interface.
        * generic/threadSvCmd.c: now uses shared Tcl objects instead of strings
        for storing data in shared arrays. This improves performance on large
        shared data structures.
        Added new tsv::* syntax, per request. This replaces older thread::sv_*
        interface. Older commands are still present but will be removed as
        soon we hit the 3.0 version.
        * generic/threadCmd.c: revamped to support asynchronous backfiring
        of scripts so we can vwait on the results of thread processing.
        This also corrected the bug #464340. Affected command is thread::send.
        * doc/thread.n: added docs for all thread::* and tsv::* commands.
        This fixes #416850 bug report. The html/tmml files are still out of date.
        * configure: built with autoconf 2.52
        * config/config.guess (new): needed for the new configure
        * config/config.sub (new): needed for the new configure
        * Makefile.in: added lines for new generic/threadSvListCmd.c
        * configure.in: moving to 2.4 version.
        * unix/threadUnix.c: removed traces of ThreadKill. It is still not clear
        wether we should implement this functionality or not.
        * win/threadWin.c: see above.
        * pkgIndex.tcl.in: fixed to correctly handle version for different Tcl core
        versions.
	* generic/threadSvListCmd.* (new): added for the new implementation
	of the thread-shared-variable (tsv) interface.
	* generic/threadSvCmd.c: now uses shared Tcl objects instead of strings
	for storing data in shared arrays. This improves performance on large
	shared data structures.
	Added new tsv::* syntax, per request. This replaces older thread::sv_*
	interface. Older commands are still present but will be removed as
	soon we hit the 3.0 version.
	* generic/threadCmd.c: revamped to support asynchronous backfiring
	of scripts so we can vwait on the results of thread processing.
	This also corrected the bug #464340. Affected command is thread::send.
	* doc/thread.n: added docs for all thread::* and tsv::* commands.
	This fixes #416850 bug report. The html/tmml files are still out of date.
	* configure: built with autoconf 2.52
	* config/config.guess (new): needed for the new configure
	* config/config.sub (new): needed for the new configure
	* Makefile.in: added lines for new generic/threadSvListCmd.c
	* configure.in: moving to 2.4 version.
	* unix/threadUnix.c: removed traces of ThreadKill. It is still not clear
	wether we should implement this functionality or not.
	* win/threadWin.c: see above.
	* pkgIndex.tcl.in: fixed to correctly handle version for different Tcl core
	versions.

2001-09-05  David Gravereaux <[email protected]>

	* generic/*:
	* win/threadWin.c (new): updated for a new threadWin.c and finished
	replacing use of thread.h with tclThread.h.  threadWin.c is an
	experiment to add a 'thread::kill' command.  Not done yet.
1684
1685
1686
1687
1688
1689
1690
1691
1692


1693
1694
1695
1696
1697
1698
1699
1684
1685
1686
1687
1688
1689
1690


1691
1692
1693
1694
1695
1696
1697
1698
1699







-
-
+
+







	against 8.3, thread::join and thread::transfer are non-existant and
	the package version is always "2.1.1" to maintain a consistent
	interface in all combinations (as per discussions with Don Porter).

2000-10-16  Zoran Vasiljevic <[email protected]>

	* generic/threadSvCmd.c ThreadSvUnsetObjCmd(): deadlocked.
        Forgot to release shared-array lock which resulted in
        deadlock after first successful unset of the variable.
	Forgot to release shared-array lock which resulted in
	deadlock after first successful unset of the variable.

2000-08-29  David Gravereaux <[email protected]>

	* generic/threadCmd.c (NewThread): Tcl_Init return value wasn't
	being verified.  Added a check and failure logic to fall-out.
	[Bug: 5301]

1779
1780
1781
1782
1783
1784
1785
1786

1787
1788
1789
1790
1791
1792
1793
1779
1780
1781
1782
1783
1784
1785

1786
1787
1788
1789
1790
1791
1792
1793







-
+








	* generic/threadSpCmd.c, generic/threadSvCmd.c:
	  added some comments in function headers.
	  docs/tests for above still pending.

2000-07-03 Zoran Vasiljevic <[email protected]>

   	Summary of changes:
	Summary of changes:

	* generic/threadSpCmd.c: new file with implementation of
	  "thread::mutex" and "thread::cond" commands. Documentation
	  and tests are still pending.

	* generic/threadSvCmd.c: new file with implementation of
	  "thread::sv_*" family of commands modeled after AOLserver
1801
1802
1803
1804
1805
1806
1807
1808

1809
1810
1811
1812
1813
1814
1815





1816
1817
1818
1819
1820

1821
1822
1823
1824
1825
1826
1827
1801
1802
1803
1804
1805
1806
1807

1808
1809
1810





1811
1812
1813
1814
1815
1816
1817
1818
1819

1820
1821
1822
1823
1824
1825
1826
1827







-
+


-
-
-
-
-
+
+
+
+
+




-
+







	* generic/thread.h added declarations for new commands (above)

	* generic/threadCmd.c:

	  Added "thread::exists" command.

	  Moved most of internal functions in threadCmd.c to statics,
          except the Thread*ObjCmd().
	  except the Thread*ObjCmd().

	  Changed behaviour of "thread::exit". It now simply flips the
          bit to signal thread stuck in thread::wait to gracefuly exit.
          Consequence: command now does not trigger error on thread exit.
          Also, thread event queue is now properly cleared.
          ThreadWait() and ThreadStop() are newly added to support this.
          Also the ThreadSpecificData has one more integer: "stopped"
	  bit to signal thread stuck in thread::wait to gracefuly exit.
	  Consequence: command now does not trigger error on thread exit.
	  Also, thread event queue is now properly cleared.
	  ThreadWait() and ThreadStop() are newly added to support this.
	  Also the ThreadSpecificData has one more integer: "stopped"

	  Replaced ref's to obsolete Tcl_GlobalEval() with Tcl_EvalEx().

	  Fixed broken 'thread::create -joinable script';
          was missing initialization of script variable
	  was missing initialization of script variable

	  Added calls to initialize new commands in threadSpCmd.c
	  and threadSvCmd.c files.

2000-05-18 Brent Welch <[email protected]>

	* Restored Andreas' changes for transferring sockets.
Changes to Makefile.in.
1
2
3

4
5
6
7
8
9
10
1
2

3
4
5
6
7
8
9
10


-
+







# Makefile.in --
#
#	This file is a Makefile for the Thread Extension.  If it has the name
#	This file is a Makefile for the thread Extension.  If it has the name
#	"Makefile.in" then it is a template for a Makefile;  to generate the
#	actual Makefile, run "./configure", which is a configuration script
#	generated by the "autoconf" program (constructs like "@foo@" will get
#	replaced in the actual Makefile.
#
# Copyright (c) 1999 Scriptics Corporation.
# Copyright (c) 2002-2005 ActiveState Corporation.
54
55
56
57
58
59
60


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85
86














87
88
89
90
91
92
93
94
95
96
97
98

99
100
101
102
103
104
105
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122







+
+















+










-
+
+
+
+
+
+
+
+
+
+
+
+
+
+












+








#========================================================================
# "PKG_LIB_FILE" refers to the library (dynamic or static as per
# configuration options) composed of the named objects.
#========================================================================

PKG_LIB_FILE	= @PKG_LIB_FILE@
PKG_LIB_FILE8	= @PKG_LIB_FILE8@
PKG_LIB_FILE9	= @PKG_LIB_FILE9@
PKG_STUB_LIB_FILE = @PKG_STUB_LIB_FILE@

lib_BINARIES	= $(PKG_LIB_FILE)
BINARIES	= $(lib_BINARIES)

SHELL		= @SHELL@

srcdir		= @srcdir@
prefix		= @prefix@
exec_prefix	= @exec_prefix@

bindir		= @bindir@
libdir		= @libdir@
includedir	= @includedir@
datarootdir	= @datarootdir@
runstatedir	= @runstatedir@
datadir		= @datadir@
mandir		= @mandir@

DESTDIR		=

PKG_DIR		= $(PACKAGE_NAME)$(PACKAGE_VERSION)
pkgdatadir	= $(datadir)/$(PKG_DIR)
pkglibdir	= $(libdir)/$(PKG_DIR)
pkgincludedir	= $(includedir)/$(PKG_DIR)

top_builddir	= .
top_builddir	= @abs_top_builddir@

###
# Tip 430 - ZipFS Modifications
###

THREAD_ZIP_FILE		= @THREAD_ZIP_FILE@
THREAD_VFS_ROOT		= libthread.vfs
THREAD_VFS_PATH		= ${THREAD_VFS_ROOT}/thread_library

ZIPFS_BUILD		= @ZIPFS_BUILD@
SHARED_BUILD		= @SHARED_BUILD@
INSTALL_LIBRARIES	= @INSTALL_LIBRARIES@
INSTALL_MSGS		= @INSTALL_MSGS@

INSTALL_OPTIONS	=
INSTALL		= @INSTALL@ $(INSTALL_OPTIONS)
INSTALL_DATA_DIR = @INSTALL_DATA_DIR@
INSTALL_DATA	= @INSTALL_DATA@
INSTALL_PROGRAM	= @INSTALL_PROGRAM@
INSTALL_SCRIPT	= @INSTALL_SCRIPT@
INSTALL_LIBRARY	= @INSTALL_LIBRARY@

PACKAGE_NAME	= @PACKAGE_NAME@
PACKAGE_VERSION	= @PACKAGE_VERSION@
CC		= @CC@
CCLD		= @CCLD@
CFLAGS_DEFAULT	= @CFLAGS_DEFAULT@
CFLAGS_WARNING	= @CFLAGS_WARNING@
EXEEXT		= @EXEEXT@
LDFLAGS_DEFAULT	= @LDFLAGS_DEFAULT@
MAKE_LIB	= @MAKE_LIB@
MAKE_STUB_LIB	= @MAKE_STUB_LIB@
OBJEXT		= @OBJEXT@
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170







-
+








#WISH_ENV	= TK_LIBRARY=`@CYGPATH@ $(TK_SRC_DIR)/library`
#WISH_PROG	= @WISH_PROG@
#WISH		= $(TCLSH_ENV) $(WISH_ENV) $(PKG_ENV) $(WISH_PROG)

SHARED_BUILD	= @SHARED_BUILD@

INCLUDES	= @PKG_INCLUDES@ @TCL_INCLUDES@
INCLUDES	= @PKG_INCLUDES@ @TCL_INCLUDES@ -I.
#INCLUDES	= @PKG_INCLUDES@ @TCL_INCLUDES@ @TK_INCLUDES@ @TK_XINCLUDES@

PKG_CFLAGS	= @PKG_CFLAGS@

# TCL_DEFS is not strictly need here, but if you remove it, then you
# must make sure that configure.ac checks for the necessary components
# that your library may use.  TCL_DEFS can actually be a problem if
196
197
198
199
200
201
202












203
204
205
206
207
208
209
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238







+
+
+
+
+
+
+
+
+
+
+
+







# The list of targets to build for "binaries:" is specified at the top
# of the Makefile, in the "BINARIES" variable.
#========================================================================

binaries: $(BINARIES)

libraries:

threadzipfile: ${THREAD_ZIP_FILE}

${THREAD_ZIP_FILE}: ${ZIP_INSTALL_OBJS}
	@rm -rf ${THREAD_VFS_ROOT}
	@mkdir -p ${THREAD_VFS_PATH}
	@echo "creating ${THREAD_VFS_PATH} (prepare compression)"
	@cp -a $(srcdir)/lib/* ${THREAD_VFS_PATH};
	@find ${THREAD_VFS_ROOT} -type d -empty -delete
	@echo "creating ${THREAD_ZIP_FILE} from ${THREAD_VFS_PATH}"
	@echo "zipfs mkzip ${THREAD_ZIP_FILE} ${THREAD_VFS_PATH} ${THREAD_VFS_PATH}" | $(TCLSH)


#========================================================================
# Your doc target should differentiate from doc builds (by the developer)
# and doc installs (see install-doc), which just install the docs on the
# end user machine when building from source.
#========================================================================

237
238
239
240
241
242
243
244
245


246
247
248
249
250
251
252
253
254
255
256
257
258


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279

280
281

282


283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305
306
307














308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
266
267
268
269
270
271
272


273
274
275
276
277
278
279
280
281
282
283
284
285


286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

308
309
310
311

312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369




370
371
372
373
374
375
376







-
-
+
+











-
-
+
+




















-
+


+
-
+
+














-
+










+
+
+
+
+
+
+
+
+
+
+
+
+
+

















-
-
-
-







	@list='$(srcdir)/doc/man/*.n'; for i in $$list; do \
	    echo "Installing $$i"; \
	    $(INSTALL_DATA) $$i "$(DESTDIR)$(mandir)/mann" ; \
	done

test: binaries libraries
	$(TCLSH) `@CYGPATH@ $(srcdir)/tests/all.tcl` $(TESTFLAGS) \
		-load "package ifneeded Thread $(PACKAGE_VERSION) \
			[list load `@CYGPATH@ $(PKG_LIB_FILE)` $(PACKAGE_NAME)]"
		-load "package ifneeded $(PACKAGE_NAME) $(PACKAGE_VERSION) \
			[list load `@CYGPATH@ $(PKG_LIB_FILE)` [string totitle $(PACKAGE_NAME)]]"

shell: binaries libraries
	@$(TCLSH) $(SCRIPT)

gdb:
	$(TCLSH_ENV) $(PKG_ENV) $(GDB) $(TCLSH_PROG) $(SCRIPT)

gdb-test: binaries libraries
	$(TCLSH_ENV) $(PKG_ENV) $(GDB) \
	    --args $(TCLSH_PROG) `@CYGPATH@ $(srcdir)/tests/all.tcl` \
	    $(TESTFLAGS) -singleproc 1 \
	    -load "package ifneeded $(PACKAGE_NAME) $(PACKAGE_VERSION) \
		[list load `@CYGPATH@ $(PKG_LIB_FILE)` $(PACKAGE_NAME)]"
	    -load "package ifneeded Thread $(PACKAGE_VERSION) \
		[list load `@CYGPATH@ $(PKG_LIB_FILE)` [string totitle $(PACKAGE_NAME)]]"

valgrind: binaries libraries
	$(TCLSH_ENV) $(PKG_ENV) $(VALGRIND) $(VALGRINDARGS) $(TCLSH_PROG) \
	    `@CYGPATH@ $(srcdir)/tests/all.tcl` $(TESTFLAGS)

valgrindshell: binaries libraries
	$(TCLSH_ENV) $(PKG_ENV) $(VALGRIND) $(VALGRINDARGS) $(TCLSH_PROG) $(SCRIPT)

depend:

#========================================================================
# $(PKG_LIB_FILE) should be listed as part of the BINARIES variable
# mentioned above.  That will ensure that this target is built when you
# run "make binaries".
#
# The $(PKG_OBJECTS) objects are created and linked into the final
# library.  In most cases these object files will correspond to the
# source files above.
#========================================================================

$(PKG_LIB_FILE): $(PKG_OBJECTS)
$(PKG_LIB_FILE): $(PKG_OBJECTS) ${THREAD_ZIP_FILE}
	-rm -f $(PKG_LIB_FILE)
	${MAKE_LIB}
	@if test "${ZIPFS_BUILD}" = "1" ; then \
	$(RANLIB) $(PKG_LIB_FILE)
	    cat ${THREAD_ZIP_FILE} >> ${PKG_LIB_FILE}; \
	fi

$(PKG_STUB_LIB_FILE): $(PKG_STUB_OBJECTS)
	-rm -f $(PKG_STUB_LIB_FILE)
	${MAKE_STUB_LIB}
	$(RANLIB_STUB) $(PKG_STUB_LIB_FILE)

#========================================================================
# We need to enumerate the list of .c to .o lines here.
#
# In the following lines, $(srcdir) refers to the toplevel directory
# containing your extension.  If your sources are in a subdirectory,
# you will have to modify the paths to reflect this:
#
# sample.$(OBJEXT): $(srcdir)/generic/sample.c
# 	$(COMPILE) -c `@CYGPATH@ $(srcdir)/generic/sample.c` -o $@
#	$(COMPILE) -c `@CYGPATH@ $(srcdir)/generic/sample.c` -o $@
#
# Setting the VPATH variable to a list of paths will cause the makefile
# to look into these paths when resolving .c to .obj dependencies.
# As necessary, add $(srcdir):$(srcdir)/compat:....
#========================================================================

VPATH = $(srcdir):$(srcdir)/generic:$(srcdir)/unix:$(srcdir)/win:$(srcdir)/macosx

.c.@OBJEXT@:
	$(COMPILE) -c `@CYGPATH@ $<` -o $@

threadCmd.@OBJEXT@:	threadUuid.h

$(srcdir)/manifest.uuid:
	printf "git-" >$(srcdir)/manifest.uuid
	(cd $(srcdir); git rev-parse HEAD >>$(srcdir)/manifest.uuid || \
	    (printf "svn-r" >$(srcdir)/manifest.uuid ; \
	    svn info --show-item last-changed-revision >>$(srcdir)/manifest.uuid) || \
	    printf "unknown" >$(srcdir)/manifest.uuid)

threadUuid.h:	$(srcdir)/manifest.uuid
	echo "#define THREAD_VERSION_UUID \\" >$@
	cat $(srcdir)/manifest.uuid >>$@
	echo "" >>$@

#========================================================================
# Distribution creation
# You may need to tweak this target to make it work correctly.
#========================================================================

#COMPRESS	= tar cvf $(PKG_DIR).tar $(PKG_DIR); compress $(PKG_DIR).tar
COMPRESS	= tar zcvf $(PKG_DIR).tar.gz $(PKG_DIR)
DIST_ROOT	= /tmp/dist
DIST_DIR	= $(DIST_ROOT)/$(PKG_DIR)

DIST_INSTALL_DATA	= CPPROG='cp -p' $(INSTALL) -m 644
DIST_INSTALL_SCRIPT	= CPPROG='cp -p' $(INSTALL) -m 755

dist-clean:
	rm -rf $(DIST_DIR) $(DIST_ROOT)/$(PKG_DIR).tar.*

$(srcdir)/manifest.uuid:
	printf "git." >$(srcdir)/manifest.uuid
	git rev-parse HEAD >>$(srcdir)/manifest.uuid

dist: dist-clean $(srcdir)/manifest.uuid
	$(INSTALL_DATA_DIR) $(DIST_DIR)
	$(DIST_INSTALL_DATA) $(srcdir)/license.terms \
		$(srcdir)/manifest.uuid \
		$(srcdir)/ChangeLog $(srcdir)/README \
		$(srcdir)/aclocal.m4 $(srcdir)/configure.ac \
		$(srcdir)/Makefile.in $(srcdir)/pkgIndex.tcl.in \
346
347
348
349
350
351
352
353
354


355
356
357
358
359
360
361
362
363
387
388
389
390
391
392
393


394
395


396
397
398
399
400
401
402







-
-
+
+
-
-







	$(DIST_INSTALL_DATA) $(srcdir)/unix/README $(srcdir)/unix/CONFIG \
		$(srcdir)/unix/threadUnix.c \
		$(DIST_DIR)/unix/

	$(INSTALL_DATA_DIR) $(DIST_DIR)/win
	$(DIST_INSTALL_DATA) \
		$(srcdir)/win/README.txt $(srcdir)/win/CONFIG $(srcdir)/win/thread.rc \
		$(srcdir)/win/makefile.vc \
		$(srcdir)/win/nmakehlp.c $(srcdir)/win/pkg.vc \
		$(srcdir)/win/*.vc $(srcdir)/win/*.in \
		$(srcdir)/win/nmakehlp.c $(srcdir)/win/thread_win.dsw \
		$(srcdir)/win/targets.vc $(srcdir)/win/rules-ext.vc \
		$(srcdir)/win/rules.vc $(srcdir)/win/thread_win.dsw \
		$(srcdir)/win/thread_win.dsp \
		$(DIST_DIR)/win/

	$(INSTALL_DATA_DIR) $(DIST_DIR)/tcl
	$(DIST_INSTALL_DATA) $(srcdir)/tcl/README $(DIST_DIR)/tcl/

	list='tests doc doc/man doc/html generic lib tcl/cmdsrv tcl/phttpd tcl/tpool';\
415
416
417
418
419
420
421
422

423
424
425
426

427
428
429
430
431
432
433








434
435
436
437
438
439
440
454
455
456
457
458
459
460

461
462
463
464
465
466







467
468
469
470
471
472
473
474
475
476
477
478
479
480
481







-
+




+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







		$(RANLIB) "$(DESTDIR)$(pkglibdir)/$$p"; \
	    fi; \
	    ext=`echo $$p|sed -e "s/.*\.//"`; \
	    if test "x$$ext" = "xdll"; then \
		lib=`basename $$p|sed -e 's/.[^.]*$$//'`.lib; \
		if test -f $$lib; then \
		    echo " $(INSTALL_DATA) $$lib $(DESTDIR)$(pkglibdir)/$$lib"; \
	            $(INSTALL_DATA) $$lib "$(DESTDIR)$(pkglibdir)/$$lib"; \
		    $(INSTALL_DATA) $$lib "$(DESTDIR)$(pkglibdir)/$$lib"; \
		fi; \
	    fi; \
	  fi; \
	done
	@if test "${ZIPFS_BUILD}" = "0" ; then \
	@list='$(PKG_TCL_SOURCES)'; for p in $$list; do \
	  if test -f $(srcdir)/$$p; then \
	    destp=`basename $$p`; \
	    echo " Install $$destp $(DESTDIR)$(pkglibdir)/$$destp"; \
	    $(INSTALL_DATA) $(srcdir)/$$p "$(DESTDIR)$(pkglibdir)/$$destp"; \
	  fi; \
	done
	  list='$(PKG_TCL_SOURCES)'; for p in $$list; do \
	    if test -f $(srcdir)/$$p; then \
	      destp=`basename $$p`; \
	      echo " Install $$destp $(DESTDIR)$(pkglibdir)/$$destp"; \
	      $(INSTALL_DATA) $(srcdir)/$$p "$(DESTDIR)$(pkglibdir)/$$destp"; \
	    fi; \
	  done; \
	fi;
	@if test "x$(SHARED_BUILD)" = "x1"; then \
	    echo " Install pkgIndex.tcl $(DESTDIR)$(pkglibdir)"; \
	    $(INSTALL_DATA) pkgIndex.tcl "$(DESTDIR)$(pkglibdir)"; \
	fi

#========================================================================
# Install binary executables (e.g. .exe files and dependent .dll files)
Changes to README.
1
2
3
4
5

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
1
2
3
4

5
6
7
8
9
10
11





12
13
14
15
16
17
18




-
+






-
-
-
-
-








WHAT IS THIS ?
==============

This is the source distribution of the Tcl Thread extension.
This is the source distribution of the Tcl thread extension.
You can use this extension to gain script-level access to Tcl
threading capabilities.
The extension can be used with Tcl cores starting from Tcl8.7 and later.
Also, this extension supports, i.e. can be used as a loadable module of,
AOLserver 4.x series of the highly-scalable web server from America Online.

You need to have your Tcl core compiled with "--enable-threads" in order
to turn on internal directives supporting thread-specific details of the
Tcl API. The extension will not load in an Tcl shell built w/o thread
support.

This extension is a freely available open source package. You can do
virtually anything you like with it, such as modifying it, redistributing
it, and selling it either in whole or in part.  See the "license.terms"
file in the top-level distribution directory for complete information.


HOW TO COMPILE ?
40
41
42
43
44
45
46
47

48
49

50
51
52
53
54
55
35
36
37
38
39
40
41

42
43

44
45
46
47
48
49
50







-
+

-
+






to jump in and help with the docs.


HOW TO GET SUPPORT ?
====================

The extension is maintained, enhanced, and distributed freely by the Tcl
community. The home for sources and bug/patch database is on SourceForge:
community. The home for sources and bug/patch database is on fossil:

        http://tcl.sourceforge.net/
	https://core.tcl-lang.org/thread

Alternatively, you are always welcome to post your questions, problems
and/or suggestions relating the extension (or any other Tcl issue)
to news:comp.lang.tcl newsgroup.

-EOF-
Changes to aclocal.m4.
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38








39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68




























69
70
71
72
73
74
75
24
25
26
27
28
29
30








31
32
33
34
35
36
37
38
39
40
41



























42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








    if test x"${with_gdbm}" != x -a "${with_gdbm}" != no; then

    AC_MSG_CHECKING([for GNU gdbm library])

    AC_CACHE_VAL(ac_cv_c_gdbm,[
    if test x"${with_gdbm}" != x -a "${with_gdbm}" != "yes"; then
        if test -f "${with_gdbm}/gdbm.h" -a x"`ls ${with_gdbm}/libgdbm* 2>/dev/null`" != x; then
            ac_cv_c_gdbm=`(cd ${with_gdbm}; pwd)`
            gincdir=$ac_cv_c_gdbm
            glibdir=$ac_cv_c_gdbm
            AC_MSG_RESULT([found in $glibdir])
        else
            AC_MSG_ERROR([${with_gdbm} directory doesn't contain gdbm library])
        fi
	if test -f "${with_gdbm}/gdbm.h" -a x"`ls ${with_gdbm}/libgdbm* 2>/dev/null`" != x; then
	    ac_cv_c_gdbm=`(cd ${with_gdbm}; pwd)`
	    gincdir=$ac_cv_c_gdbm
	    glibdir=$ac_cv_c_gdbm
	    AC_MSG_RESULT([found in $glibdir])
	else
	    AC_MSG_ERROR([${with_gdbm} directory doesn't contain gdbm library])
	fi
    fi
    ])
    if test x"${gincdir}" = x -o x"${glibdir}" = x; then
        for i in \
                `ls -d ${exec_prefix}/lib 2>/dev/null`\
                `ls -d ${prefix}/lib 2>/dev/null`\
                `ls -d /usr/local/lib 2>/dev/null`\
                `ls -d /usr/lib 2>/dev/null` ; do
            if test x"`ls $i/libgdbm* 2>/dev/null`" != x ; then
                glibdir=`(cd $i; pwd)`
                break
            fi
        done
        for i in \
                `ls -d ${prefix}/include 2>/dev/null`\
                `ls -d /usr/local/include 2>/dev/null`\
                `ls -d /usr/include 2>/dev/null` ; do
            if test -f "$i/gdbm.h" ; then
                gincdir=`(cd $i; pwd)`
                break
            fi
        done
        if test x"$glibdir" = x -o x"$gincdir" = x ; then
            AC_MSG_ERROR([none found])
        else
            AC_MSG_RESULT([found in $glibdir, includes in $gincdir])
            AC_DEFINE(HAVE_GDBM)
            GDBM_CFLAGS="-I\"$gincdir\""
            GDBM_LIBS="-L\"$glibdir\" -lgdbm"
        fi
	for i in \
		`ls -d ${exec_prefix}/lib 2>/dev/null`\
		`ls -d ${prefix}/lib 2>/dev/null`\
		`ls -d /usr/local/lib 2>/dev/null`\
		`ls -d /usr/lib 2>/dev/null`\
		`ls -d /usr/lib/x86_64-linux-gnu 2>/dev/null` ; do
	    if test x"`ls $i/libgdbm* 2>/dev/null`" != x ; then
		glibdir=`(cd $i; pwd)`
		break
	    fi
	done
	for i in \
		`ls -d ${prefix}/include 2>/dev/null`\
		`ls -d /usr/local/include 2>/dev/null`\
		`ls -d /usr/include 2>/dev/null` ; do
	    if test -f "$i/gdbm.h" ; then
		gincdir=`(cd $i; pwd)`
		break
	    fi
	done
	if test x"$glibdir" = x -o x"$gincdir" = x ; then
	    AC_MSG_ERROR([none found])
	else
	    AC_MSG_RESULT([found in $glibdir, includes in $gincdir])
	    AC_DEFINE(HAVE_GDBM)
	    GDBM_CFLAGS="-I\"$gincdir\""
	    GDBM_LIBS="-L\"$glibdir\" -lgdbm"
	fi
    fi
    fi
])


#
# Handle the "--with-lmdb" option for linking-in
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131











































132
133
134
135
84
85
86
87
88
89
90










































91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





AC_DEFUN(TCLTHREAD_WITH_LMDB, [
    AC_ARG_WITH(lmdb,
	[  --with-lmdb             link with optional LMDB support],
	with_lmdb=${withval})

    if test x"${with_lmdb}" != "x" -a "${with_lmdb}" != no; then
        AC_MSG_CHECKING([for LMDB library])
        AC_CACHE_VAL(ac_cv_c_lmdb,[
        if test x"${with_lmdb}" != x -a "${with_lmdb}" != "yes"; then
            if test -f "${with_lmdb}/lmdb.h" -a x"`ls ${with_lmdb}/liblmdb* 2>/dev/null`" != x; then
                ac_cv_c_lmdb=`(cd ${with_lmdb}; pwd)`
                lincdir=$ac_cv_c_lmdb
                llibdir=$ac_cv_c_lmdb
                AC_MSG_RESULT([found in $llibdir])
            else
                AC_MSG_ERROR([${with_lmdb} directory doesn't contain lmdb library])
            fi
        fi
        ])
        if test x"${lincdir}" = x -o x"${llibdir}" = x; then
            for i in \
                    `ls -d ${exec_prefix}/lib 2>/dev/null`\
                    `ls -d ${prefix}/lib 2>/dev/null`\
                    `ls -d /usr/local/lib 2>/dev/null`\
                    `ls -d /usr/lib 2>/dev/null` ; do
                if test x"`ls $i/liblmdb* 2>/dev/null`" != x ; then
                    llibdir=`(cd $i; pwd)`
                    break
                fi
            done
            for i in \
                    `ls -d ${prefix}/include 2>/dev/null`\
                    `ls -d /usr/local/include 2>/dev/null`\
                    `ls -d /usr/include 2>/dev/null` ; do
                if test -f "$i/lmdb.h" ; then
                    lincdir=`(cd $i; pwd)`
                    break
                fi
            done
            if test x"$llibdir" = x -o x"$lincdir" = x ; then
                AC_MSG_ERROR([none found])
            else
                AC_MSG_RESULT([found in $llibdir, includes in $lincdir])
                AC_DEFINE(HAVE_LMDB)
                LMDB_CFLAGS="-I\"$lincdir\""
                LMDB_LIBS="-L\"$llibdir\" -llmdb"
            fi
        fi
	AC_MSG_CHECKING([for LMDB library])
	AC_CACHE_VAL(ac_cv_c_lmdb,[
	if test x"${with_lmdb}" != x -a "${with_lmdb}" != "yes"; then
	    if test -f "${with_lmdb}/lmdb.h" -a x"`ls ${with_lmdb}/liblmdb* 2>/dev/null`" != x; then
		ac_cv_c_lmdb=`(cd ${with_lmdb}; pwd)`
		lincdir=$ac_cv_c_lmdb
		llibdir=$ac_cv_c_lmdb
		AC_MSG_RESULT([found in $llibdir])
	    else
		AC_MSG_ERROR([${with_lmdb} directory doesn't contain lmdb library])
	    fi
	fi
	])
	if test x"${lincdir}" = x -o x"${llibdir}" = x; then
	    for i in \
		    `ls -d ${exec_prefix}/lib 2>/dev/null`\
		    `ls -d ${prefix}/lib 2>/dev/null`\
		    `ls -d /usr/local/lib 2>/dev/null`\
		    `ls -d /usr/lib 2>/dev/null`\
		    `ls -d /usr/lib/x86_64-linux-gnu 2>/dev/null` ; do
		if test x"`ls $i/liblmdb* 2>/dev/null`" != x ; then
		    llibdir=`(cd $i; pwd)`
		    break
		fi
	    done
	    for i in \
		    `ls -d ${prefix}/include 2>/dev/null`\
		    `ls -d /usr/local/include 2>/dev/null`\
		    `ls -d /usr/include 2>/dev/null` ; do
		if test -f "$i/lmdb.h" ; then
		    lincdir=`(cd $i; pwd)`
		    break
		fi
	    done
	    if test x"$llibdir" = x -o x"$lincdir" = x ; then
		AC_MSG_ERROR([none found])
	    else
		AC_MSG_RESULT([found in $llibdir, includes in $lincdir])
		AC_DEFINE(HAVE_LMDB)
		LMDB_CFLAGS="-I\"$lincdir\""
		LMDB_LIBS="-L\"$llibdir\" -llmdb"
	    fi
	fi
    fi
])

# EOF
Changes to configure.
1
2
3

4
5
6


7
8
9
10
11
12
13
14
15
16
17


18
19
20
21
22
23
24
25


26
27
28
29

30
31
32
33








34
35
36
37
38
39
40
41
42
43
44
45
46


47
48
49


50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65




66
67
68
69
70

















71
72
73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98





99
100
101
102
103
104

105
106
107
108
109
110

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156



157
158
159
160
161


162
163
164
165
166
167
168
169


170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188


189
190
191



192
193


194
195
196
197
198
199
200


201
202
203



204
205


206
207
208


209
210
211
212

213




214
215
216
217
218
219

220
221


222
223


224
225
226
227
228
229
230





231
232



233


234

235
236
237
238


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256


257
258
259
260
261
262
263
264
265







266
267

268
269
270
271
272
273


274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292

293
294
295
296
297
298
299
1
2

3
4
5

6
7
8
9
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47










48
49



50
51







52









53
54
55
56





57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84







85
86
87
88
89
90
91
92
93


94
95
96
97
98
99
100
101
102
103

104
105
106
107
108
109

110
111
112
113




















114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133



134
135
136
137
138
139
140

141
142
143
144
145
146
147
148


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

170
171
172


173
174
175
176
177
178
179
180
181
182
183
184
185

186
187
188


189
190
191
192

193
194
195


196
197
198
199
200
201
202

203
204
205
206
207
208
209
210
211

212
213

214
215
216

217
218
219
220
221
222
223
224
225
226
227
228
229
230


231
232
233
234
235
236

237

238
239

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257


258
259
260
261
262






263
264
265
266
267
268
269
270

271
272
273
274
275
276

277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305


-
+


-
+
+










-
+
+






-
-
+
+




+




+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+








-
-
-
-
-
-
-








+
-
-
+
+
+
+
+





-
+





-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-




















-
-
-
+
+
+




-
+
+






-
-
+
+




+














-
+
+

-
-
+
+
+


+
+






-
+
+

-
-
+
+
+

-
+
+

-
-
+
+




+
-
+
+
+
+





-
+

-
+
+

-
+
+







+
+
+
+
+
-
-
+
+
+

+
+
-
+
-


-
+
+
















-
-
+
+



-
-
-
-
-
-
+
+
+
+
+
+
+

-
+





-
+
+



















+







#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for thread 3.0a2.
# Generated by GNU Autoconf 2.72 for thread 3.0.2.
#
#
# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
# Copyright (C) 1992-1996, 1998-2017, 2020-2023 Free Software Foundation,
# Inc.
#
#
# This configure script is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.
## -------------------- ##
## M4sh Initialization. ##
## -------------------- ##

# Be more Bourne compatible
DUALCASE=1; export DUALCASE # for MKS sh
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1
then :
  emulate sh
  NULLCMD=:
  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '${1+"$@"}'='"$@"'
  setopt NO_GLOB_SUBST
else
  case `(set -o) 2>/dev/null` in #(
else case e in #(
  e) case `(set -o) 2>/dev/null` in #(
  *posix*) :
    set -o posix ;; #(
  *) :
     ;;
esac ;;
esac
fi



# Reset variables that may have inherited troublesome values from
# the environment.

# IFS needs to be set, to space, tab, and newline, in precisely that order.
# (If _AS_PATH_WALK were called with IFS unset, it would have the
# side effect of setting IFS to empty, thus disabling word splitting.)
# Quoting is to prevent editors from complaining about space-tab.
as_nl='
'
export as_nl
# Printing a long string crashes Solaris 7 /usr/bin/printf.
as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
# Prefer a ksh shell builtin over an external printf program on Solaris,
# but without wasting forks for bash or zsh.
if test -z "$BASH_VERSION$ZSH_VERSION" \
    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
  as_echo='print -r --'
  as_echo_n='print -rn --'
IFS=" ""	$as_nl"

elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
  as_echo='printf %s\n'
  as_echo_n='printf %s'
PS1='$ '
PS2='> '
else
  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
    as_echo_n='/usr/ucb/echo -n'
  else
    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
    as_echo_n_body='eval
PS4='+ '
      arg=$1;
      case $arg in #(
      *"$as_nl"*)
	expr "X$arg" : "X\\(.*\\)$as_nl";
	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
      esac;
      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
    '
    export as_echo_n_body

# Ensure predictable behavior from utilities with locale-dependent output.
LC_ALL=C
export LC_ALL
    as_echo_n='sh -c $as_echo_n_body as_echo'
  fi
  export as_echo_body
  as_echo='sh -c $as_echo_body as_echo'
fi
LANGUAGE=C
export LANGUAGE

# We cannot yet rely on "unset" to work, but we need these variables
# to be unset--not just set to an empty or harmless value--now, to
# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh).  This construct
# also avoids known problems related to "unset" and subshell syntax
# in other old shells (e.g. bash 2.01 and pdksh 5.2.14).
for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH
do eval test \${$as_var+y} \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done

# Ensure that fds 0, 1, and 2 are open.
if (exec 3>&0) 2>/dev/null; then :; else exec 0</dev/null; fi
if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi
if (exec 3>&2)            ; then :; else exec 2>/dev/null; fi

# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
if ${PATH_SEPARATOR+false} :; then
  PATH_SEPARATOR=:
  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
      PATH_SEPARATOR=';'
  }
fi


# IFS
# We need space, tab and new line, in precisely that order.  Quoting is
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
IFS=" ""	$as_nl"

# Find who we are.  Look in the path if we contain no directory separator.
as_myself=
case $0 in #((
  *[\\/]* ) as_myself=$0 ;;
  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    test -r "$as_dir$0" && as_myself=$as_dir$0 && break
  done
IFS=$as_save_IFS

     ;;
esac
# We did not find ourselves, most probably we were run as `sh COMMAND'
# We did not find ourselves, most probably we were run as 'sh COMMAND'
# in which case we are not to be found in the path.
if test "x$as_myself" = x; then
  as_myself=$0
fi
if test ! -f "$as_myself"; then
  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  exit 1
fi

# Unset variables that we do not need and which cause bugs (e.g. in
# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
# suppresses any "Segmentation fault" message there.  '((' could
# trigger a bug in pdksh 5.2.14.
for as_var in BASH_ENV ENV MAIL MAILPATH
do eval test x\${$as_var+set} = xset \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done
PS1='$ '
PS2='> '
PS4='+ '

# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE

# CDPATH.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH

# Use a proper internal environment variable to ensure we don't fall
  # into an infinite loop, continuously re-executing ourselves.
  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
    _as_can_reexec=no; export _as_can_reexec;
    # We cannot yet assume a decent shell, so we have to provide a
# neutralization value for shells without unset; and this also
# works around shells that cannot unset nonexistent variables.
# Preserve -v and -x to the replacement shell.
BASH_ENV=/dev/null
ENV=/dev/null
(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
case $- in # ((((
  *v*x* | *x*v* ) as_opts=-vx ;;
  *v* ) as_opts=-v ;;
  *x* ) as_opts=-x ;;
  * ) as_opts= ;;
esac
exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
# Admittedly, this is quite paranoid, since all the known shells bail
# out after a failed `exec'.
$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
as_fn_exit 255
# out after a failed 'exec'.
printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2
exit 255
  fi
  # We don't want this to propagate to other subprocesses.
          { _as_can_reexec=; unset _as_can_reexec;}
if test "x$CONFIG_SHELL" = x; then
  as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
  as_bourne_compatible="if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1
then :
  emulate sh
  NULLCMD=:
  # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '\${1+\"\$@\"}'='\"\$@\"'
  setopt NO_GLOB_SUBST
else
  case \`(set -o) 2>/dev/null\` in #(
else case e in #(
  e) case \`(set -o) 2>/dev/null\` in #(
  *posix*) :
    set -o posix ;; #(
  *) :
     ;;
esac ;;
esac
fi
"
  as_required="as_fn_return () { (exit \$1); }
as_fn_success () { as_fn_return 0; }
as_fn_failure () { as_fn_return 1; }
as_fn_ret_success () { return 0; }
as_fn_ret_failure () { return 1; }

exitcode=0
as_fn_success || { exitcode=1; echo as_fn_success failed.; }
as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; }
as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; }
as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; }
if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
if ( set x; as_fn_ret_success y && test x = \"\$1\" )
then :

else
  exitcode=1; echo positional parameters were not saved.
else case e in #(
  e) exitcode=1; echo positional parameters were not saved. ;;
esac
fi
test x\$exitcode = x0 || exit 1
blah=\$(echo \$(echo blah))
test x\"\$blah\" = xblah || exit 1
test -x / || exit 1"
  as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
  as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
  eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
  test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1
test \$(( 1 + 1 )) = 2 || exit 1"
  if (eval "$as_required") 2>/dev/null; then :
  if (eval "$as_required") 2>/dev/null
then :
  as_have_required=yes
else
  as_have_required=no
else case e in #(
  e) as_have_required=no ;;
esac
fi
  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then :
  if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null
then :

else
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
else case e in #(
  e) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
as_found=false
for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
  as_found=:
  case $as_dir in #(
	 /*)
	   for as_base in sh bash ksh sh5; do
	     # Try only shells that exist, to save several forks.
	     as_shell=$as_dir/$as_base
	     as_shell=$as_dir$as_base
	     if { test -f "$as_shell" || test -f "$as_shell.exe"; } &&
		    { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then :
		    as_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 2>/dev/null
then :
  CONFIG_SHELL=$as_shell as_have_required=yes
		   if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then :
		   if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null
then :
  break 2
fi
fi
	   done;;
       esac
  as_found=false
done
IFS=$as_save_IFS
if $as_found
then :

else case e in #(
$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
	      { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then :
  e) if { test -f "$SHELL" || test -f "$SHELL.exe"; } &&
	      as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null
then :
  CONFIG_SHELL=$SHELL as_have_required=yes
fi ;;
esac
fi; }
fi
IFS=$as_save_IFS


      if test "x$CONFIG_SHELL" != x; then :
      if test "x$CONFIG_SHELL" != x
then :
  export CONFIG_SHELL
             # We cannot yet assume a decent shell, so we have to provide a
# neutralization value for shells without unset; and this also
# works around shells that cannot unset nonexistent variables.
# Preserve -v and -x to the replacement shell.
BASH_ENV=/dev/null
ENV=/dev/null
(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
case $- in # ((((
  *v*x* | *x*v* ) as_opts=-vx ;;
  *v* ) as_opts=-v ;;
  *x* ) as_opts=-x ;;
  * ) as_opts= ;;
esac
exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
# Admittedly, this is quite paranoid, since all the known shells bail
# out after a failed `exec'.
$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
# out after a failed 'exec'.
printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2
exit 255
fi

    if test x$as_have_required = xno; then :
  $as_echo "$0: This script requires a shell more modern than all"
  $as_echo "$0: the shells that I found on your system."
  if test x${ZSH_VERSION+set} = xset ; then
    $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should"
    $as_echo "$0: be upgraded to zsh 4.3.4 or later."
    if test x$as_have_required = xno
then :
  printf "%s\n" "$0: This script requires a shell more modern than all"
  printf "%s\n" "$0: the shells that I found on your system."
  if test ${ZSH_VERSION+y} ; then
    printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should"
    printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later."
  else
    $as_echo "$0: Please tell [email protected] about your system,
    printf "%s\n" "$0: Please tell [email protected] about your system,
$0: including any error possibly output before this
$0: message. Then install a modern shell, or manually run
$0: the script under such a shell if you do have one."
  fi
  exit 1
fi
fi ;;
esac
fi
fi
SHELL=${CONFIG_SHELL-/bin/sh}
export SHELL
# Unset more variables known to interfere with behavior of common tools.
CLICOLOR_FORCE= GREP_OPTIONS=
unset CLICOLOR_FORCE GREP_OPTIONS

## --------------------- ##
## M4sh Shell Functions. ##
## --------------------- ##
# as_fn_unset VAR
# ---------------
# Portably unset VAR.
as_fn_unset ()
{
  { eval $1=; unset $1;}
}
as_unset=as_fn_unset


# as_fn_set_status STATUS
# -----------------------
# Set $? to STATUS, without forking.
as_fn_set_status ()
{
  return $1
318
319
320
321
322
323
324
325

326
327
328
329
330
331
332
333
334

335
336
337
338
339
340
341
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338
339

340
341
342
343
344
345
346
347







-
+








-
+







  case $as_dir in #(
  -*) as_dir=./$as_dir;;
  esac
  test -d "$as_dir" || eval $as_mkdir_p || {
    as_dirs=
    while :; do
      case $as_dir in #(
      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *) as_qdir=$as_dir;;
      esac
      as_dirs="'$as_qdir' $as_dirs"
      as_dir=`$as_dirname -- "$as_dir" ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$as_dir" : 'X\(//\)[^/]' \| \
	 X"$as_dir" : 'X\(//\)$' \| \
	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$as_dir" |
printf "%s\n" X"$as_dir" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
366
367
368
369
370
371
372
373


374
375
376
377
378
379


380
381
382


383
384
385
386
387
388
389
390


391
392
393
394
395
396


397
398
399


400
401
402
403
404
405
406
407
408
409
410
411
412
413

414
415

416
417
418
419
420
421
422
372
373
374
375
376
377
378

379
380
381
382
383
384


385
386
387
388

389
390
391
392
393
394
395
396
397

398
399
400
401
402
403


404
405
406
407

408
409
410
411
412
413
414
415
416
417
418
419
420
421
422

423
424

425
426
427
428
429
430
431
432







-
+
+




-
-
+
+


-
+
+







-
+
+




-
-
+
+


-
+
+













-
+

-
+







} # as_fn_executable_p
# as_fn_append VAR VALUE
# ----------------------
# Append the text in VALUE to the end of the definition contained in VAR. Take
# advantage of any shell optimizations that allow amortized linear growth over
# repeated appends, instead of the typical quadratic growth present in naive
# implementations.
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null
then :
  eval 'as_fn_append ()
  {
    eval $1+=\$2
  }'
else
  as_fn_append ()
else case e in #(
  e) as_fn_append ()
  {
    eval $1=\$$1\$2
  }
  } ;;
esac
fi # as_fn_append

# as_fn_arith ARG...
# ------------------
# Perform arithmetic evaluation on the ARGs, and store the result in the
# global $as_val. Take advantage of shells that can avoid forks. The arguments
# must be portable across $(()) and expr.
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null
then :
  eval 'as_fn_arith ()
  {
    as_val=$(( $* ))
  }'
else
  as_fn_arith ()
else case e in #(
  e) as_fn_arith ()
  {
    as_val=`expr "$@" || test $? -eq 1`
  }
  } ;;
esac
fi # as_fn_arith


# as_fn_error STATUS ERROR [LINENO LOG_FD]
# ----------------------------------------
# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
# script with STATUS, using 1 if that was 0.
as_fn_error ()
{
  as_status=$1; test $as_status -eq 0 && as_status=1
  if test "$4"; then
    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
  fi
  $as_echo "$as_me: error: $2" >&2
  printf "%s\n" "$as_me: error: $2" >&2
  as_fn_exit $as_status
} # as_fn_error

if expr a : '\(a\)' >/dev/null 2>&1 &&
   test "X`expr 00001 : '.*\(...\)'`" = X001; then
  as_expr=expr
else
435
436
437
438
439
440
441
442

443
444
445
446
447
448
449
445
446
447
448
449
450
451

452
453
454
455
456
457
458
459







-
+







  as_dirname=false
fi

as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
	 X"$0" : 'X\(//\)$' \| \
	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X/"$0" |
printf "%s\n" X/"$0" |
    sed '/^.*\/\([^/][^/]*\)\/*$/{
	    s//\1/
	    q
	  }
	  /^X\/\(\/\/\)$/{
	    s//\1/
	    q
468
469
470
471
472
473
474


475
476
477
478
479
480
481
482
483
484
485
486

487
488
489
490
491
492
493
494
495
496
497
498
499




500
501
502
503
504
505
506
507
508
509
510
511






512
513
514
515
516
517
518
519
520
521
522
523
524
525
526



527
528
529
530
531
532
533
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497

498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545



546
547
548
549
550
551
552
553
554
555







+
+











-
+













+
+
+
+












+
+
+
+
+
+












-
-
-
+
+
+







  test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || {
  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
  sed -n '
    p
    /[$]LINENO/=
  ' <$as_myself |
    sed '
      t clear
      :clear
      s/[$]LINENO.*/&-/
      t lineno
      b
      :lineno
      N
      :loop
      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
      t loop
      s/-\n.*//
    ' >$as_me.lineno &&
  chmod +x "$as_me.lineno" ||
    { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
    { printf "%s\n" "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }

  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
  # already done that, so ensure we don't try to do so again and fall
  # in an infinite loop.  This has already happened in practice.
  _as_can_reexec=no; export _as_can_reexec
  # Don't try to exec as it changes $[0], causing all sort of problems
  # (the dirname of $[0] is not the place where we might find the
  # original and so on.  Autoconf is especially sensitive to this).
  . "./$as_me.lineno"
  # Exit status is that of the last command.
  exit
}


# Determine whether it's possible to make 'echo' print without a newline.
# These variables are no longer used directly by Autoconf, but are AC_SUBSTed
# for compatibility with existing Makefiles.
ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in #(((((
-n*)
  case `echo 'xy\c'` in
  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
  xy)  ECHO_C='\c';;
  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
       ECHO_T='	';;
  esac;;
*)
  ECHO_N='-n';;
esac

# For backward compatibility with old third-party macros, we provide
# the shell variables $as_echo and $as_echo_n.  New code should use
# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively.
as_echo='printf %s\n'
as_echo_n='printf %s'

rm -f conf$$ conf$$.exe conf$$.file
if test -d conf$$.dir; then
  rm -f conf$$.dir/conf$$.file
else
  rm -f conf$$.dir
  mkdir conf$$.dir 2>/dev/null
fi
if (echo >conf$$.file) 2>/dev/null; then
  if ln -s conf$$.file conf$$ 2>/dev/null; then
    as_ln_s='ln -s'
    # ... but there are two gotchas:
    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
    # In both cases, we have to default to `cp -pR'.
    # 1) On MSYS, both 'ln -s file dir' and 'ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; 'ln -s' creates a wrapper executable.
    # In both cases, we have to default to 'cp -pR'.
    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
      as_ln_s='cp -pR'
  elif ln conf$$.file conf$$ 2>/dev/null; then
    as_ln_s=ln
  else
    as_ln_s='cp -pR'
  fi
544
545
546
547
548
549
550
551


552
553
554


555
556
557
558
559
560
561
566
567
568
569
570
571
572

573
574
575
576

577
578
579
580
581
582
583
584
585







-
+
+


-
+
+







  as_mkdir_p=false
fi

as_test_x='test -x'
as_executable_p=as_fn_executable_p

# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
as_sed_cpp="y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g"
as_tr_cpp="eval sed '$as_sed_cpp'" # deprecated

# Sed expression to map a string onto a valid variable name.
as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
as_sed_sh="y%*+%pp%;s%[^_$as_cr_alnum]%_%g"
as_tr_sh="eval sed '$as_sed_sh'" # deprecated


test -n "$DJDIR" || exec 7<&0 </dev/null
exec 6>&1

# Name of the host.
# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status,
573
574
575
576
577
578
579
580
581


582
583
584
585
586
587
588
589



590
591

592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616









617
618
619
620

621




622
623
624
625

626
627
628
629
630
631
632
597
598
599
600
601
602
603


604
605
606
607
608
609
610



611
612
613
614

615



616





617
618



619
620



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657







-
-
+
+





-
-
-
+
+
+

-
+
-
-
-

-
-
-
-
-


-
-
-


-
-
-






+
+
+
+
+
+
+
+
+




+

+
+
+
+




+







subdirs=
MFLAGS=
MAKEFLAGS=

# Identity of this package.
PACKAGE_NAME='thread'
PACKAGE_TARNAME='thread'
PACKAGE_VERSION='3.0a2'
PACKAGE_STRING='thread 3.0a2'
PACKAGE_VERSION='3.0.2'
PACKAGE_STRING='thread 3.0.2'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''

# Factoring default headers for most tests.
ac_includes_default="\
#include <stdio.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#include <stddef.h>
#ifdef HAVE_STDIO_H
# include <stdio.h>
#endif
#ifdef HAVE_SYS_STAT_H
#ifdef HAVE_STDLIB_H
# include <sys/stat.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
#  include <stdlib.h>
# endif
#endif
#ifdef HAVE_STRING_H
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
#  include <memory.h>
# endif
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif"

ac_header_c_list=
ac_subst_vars='LTLIBOBJS
INSTALL_MSGS
INSTALL_LIBRARIES
THREAD_ZIP_FILE
ZIPFS_BUILD
TCLSH_PROG
VC_MANIFEST_EMBED_EXE
VC_MANIFEST_EMBED_DLL
RANLIB_STUB
PKG_STUB_LIB_FILE
MAKE_STUB_LIB
MAKE_STATIC_LIB
MAKE_SHARED_LIB
MAKE_LIB
LDFLAGS_DEFAULT
CFLAGS_DEFAULT
LD_LIBRARY_PATH_VAR
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
669
670
671
672
673
674
675


676
677
678
679
680
681
682







-
-







AR
STUBS_BUILD
SHARED_BUILD
TCL_THREADS
TCL_INCLUDES
PKG_OBJECTS
PKG_SOURCES
EGREP
GREP
RANLIB
SET_MAKE
CPP
TCL_SHLIB_LD_LIBS
TCL_LD_FLAGS
TCL_EXTRA_CFLAGS
TCL_DEFS
684
685
686
687
688
689
690
691


692
693
694
695
696
697
698
707
708
709
710
711
712
713

714
715
716
717
718
719
720
721
722







-
+
+







PKG_CFLAGS
PKG_LIBS
PKG_INCLUDES
PKG_HEADERS
PKG_TCL_SOURCES
PKG_STUB_OBJECTS
PKG_STUB_SOURCES
PKG_STUB_LIB_FILE
PKG_LIB_FILE9
PKG_LIB_FILE8
PKG_LIB_FILE
EXEEXT
CYGPATH
target_alias
host_alias
build_alias
LIBS
707
708
709
710
711
712
713

714
715
716
717
718
719
720
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745







+







pdfdir
dvidir
htmldir
infodir
docdir
oldincludedir
includedir
runstatedir
localstatedir
sharedstatedir
sysconfdir
datadir
datarootdir
libexecdir
sbindir
730
731
732
733
734
735
736

737
738
739
740
741
742
743
744
745
746
747

748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781







+











+







PACKAGE_NAME
PATH_SEPARATOR
SHELL'
ac_subst_files=''
ac_user_opts='
enable_option_checking
with_tcl
with_tcl8
with_gdbm
with_lmdb
with_naviserver
with_tclinclude
enable_threads
enable_shared
enable_stubs
enable_64bit
enable_64bit_vis
enable_rpath
enable_symbols
enable_zipfs
'
      ac_precious_vars='build_alias
host_alias
target_alias
CC
CFLAGS
LDFLAGS
789
790
791
792
793
794
795

796
797
798
799
800
801
802
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830







+







sbindir='${exec_prefix}/sbin'
libexecdir='${exec_prefix}/libexec'
datarootdir='${prefix}/share'
datadir='${datarootdir}'
sysconfdir='${prefix}/etc'
sharedstatedir='${prefix}/com'
localstatedir='${prefix}/var'
runstatedir='${localstatedir}/run'
includedir='${prefix}/include'
oldincludedir='/usr/include'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
infodir='${datarootdir}/info'
htmldir='${docdir}'
dvidir='${docdir}'
pdfdir='${docdir}'
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
846
847
848
849
850
851
852


853
854
855
856
857
858
859







-
-








  case $ac_option in
  *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;;
  *=)   ac_optarg= ;;
  *)    ac_optarg=yes ;;
  esac

  # Accept the important Cygnus configure options, so we can diagnose typos.

  case $ac_dashdash$ac_option in
  --)
    ac_dashdash=yes ;;

  -bindir | --bindir | --bindi | --bind | --bin | --bi)
    ac_prev=bindir ;;
  -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
860
861
862
863
864
865
866
867

868
869

870
871
872
873
874
875
876
886
887
888
889
890
891
892

893
894

895
896
897
898
899
900
901
902







-
+

-
+







  | --dataroot=* | --dataroo=* | --dataro=* | --datar=*)
    datarootdir=$ac_optarg ;;

  -disable-* | --disable-*)
    ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid feature name: $ac_useropt"
      as_fn_error $? "invalid feature name: '$ac_useropt'"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"enable_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
886
887
888
889
890
891
892
893

894
895

896
897
898
899
900
901
902
912
913
914
915
916
917
918

919
920

921
922
923
924
925
926
927
928







-
+

-
+







  -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*)
    dvidir=$ac_optarg ;;

  -enable-* | --enable-*)
    ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid feature name: $ac_useropt"
      as_fn_error $? "invalid feature name: '$ac_useropt'"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"enable_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
1040
1041
1042
1043
1044
1045
1046









1047
1048
1049
1050
1051
1052
1053
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088







+
+
+
+
+
+
+
+
+







    ac_prev=psdir ;;
  -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*)
    psdir=$ac_optarg ;;

  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
  | -silent | --silent | --silen | --sile | --sil)
    silent=yes ;;

  -runstatedir | --runstatedir | --runstatedi | --runstated \
  | --runstate | --runstat | --runsta | --runst | --runs \
  | --run | --ru | --r)
    ac_prev=runstatedir ;;
  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
  | --run=* | --ru=* | --r=*)
    runstatedir=$ac_optarg ;;

  -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
    ac_prev=sbindir ;;
  -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
  | --sbi=* | --sb=*)
    sbindir=$ac_optarg ;;

1090
1091
1092
1093
1094
1095
1096
1097

1098
1099

1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113

1114
1115

1116
1117
1118
1119
1120
1121
1122
1125
1126
1127
1128
1129
1130
1131

1132
1133

1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147

1148
1149

1150
1151
1152
1153
1154
1155
1156
1157







-
+

-
+













-
+

-
+







  -version | --version | --versio | --versi | --vers | -V)
    ac_init_version=: ;;

  -with-* | --with-*)
    ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid package name: $ac_useropt"
      as_fn_error $? "invalid package name: '$ac_useropt'"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"with_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
    eval with_$ac_useropt=\$ac_optarg ;;

  -without-* | --without-*)
    ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null &&
      as_fn_error $? "invalid package name: $ac_useropt"
      as_fn_error $? "invalid package name: '$ac_useropt'"
    ac_useropt_orig=$ac_useropt
    ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'`
    ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'`
    case $ac_user_opts in
      *"
"with_$ac_useropt"
"*) ;;
      *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig"
	 ac_unrecognized_sep=', ';;
    esac
1136
1137
1138
1139
1140
1141
1142
1143
1144


1145
1146
1147
1148
1149
1150
1151
1152

1153
1154
1155
1156
1157
1158
1159

1160
1161

1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177

1178
1179
1180
1181
1182
1183
1184
1185

1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202

1203
1204
1205
1206
1207
1208
1209
1171
1172
1173
1174
1175
1176
1177


1178
1179
1180
1181
1182
1183
1184
1185
1186

1187
1188
1189
1190
1191
1192
1193

1194
1195

1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211

1212
1213
1214
1215
1216
1217
1218
1219

1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236

1237
1238
1239
1240
1241
1242
1243
1244







-
-
+
+







-
+






-
+

-
+















-
+







-
+
















-
+







  -x-libraries | --x-libraries | --x-librarie | --x-librari \
  | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
    ac_prev=x_libraries ;;
  -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
  | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
    x_libraries=$ac_optarg ;;

  -*) as_fn_error $? "unrecognized option: \`$ac_option'
Try \`$0 --help' for more information"
  -*) as_fn_error $? "unrecognized option: '$ac_option'
Try '$0 --help' for more information"
    ;;

  *=*)
    ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
    # Reject names that are not valid shell variable names.
    case $ac_envvar in #(
      '' | [0-9]* | *[!_$as_cr_alnum]* )
      as_fn_error $? "invalid variable name: \`$ac_envvar'" ;;
      as_fn_error $? "invalid variable name: '$ac_envvar'" ;;
    esac
    eval $ac_envvar=\$ac_optarg
    export $ac_envvar ;;

  *)
    # FIXME: should be removed in autoconf 3.0.
    $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2
    printf "%s\n" "$as_me: WARNING: you should use --build, --host, --target" >&2
    expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
      $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2
      printf "%s\n" "$as_me: WARNING: invalid host type: $ac_option" >&2
    : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}"
    ;;

  esac
done

if test -n "$ac_prev"; then
  ac_option=--`echo $ac_prev | sed 's/_/-/g'`
  as_fn_error $? "missing argument to $ac_option"
fi

if test -n "$ac_unrecognized_opts"; then
  case $enable_option_checking in
    no) ;;
    fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;;
    *)     $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
    *)     printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;;
  esac
fi

# Check all directory arguments for consistency.
for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
		datadir sysconfdir sharedstatedir localstatedir includedir \
		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
		libdir localedir mandir
		libdir localedir mandir runstatedir
do
  eval ac_val=\$$ac_var
  # Remove trailing slashes.
  case $ac_val in
    */ )
      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
      eval $ac_var=\$ac_val;;
  esac
  # Be sure to have absolute directory names.
  case $ac_val in
    [\\/$]* | ?:[\\/]* )  continue;;
    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
  esac
  as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val"
done

# There might be people who depend on the old broken behavior: `$host'
# There might be people who depend on the old broken behavior: '$host'
# used to hold the argument of --host etc.
# FIXME: To remove some day.
build=$build_alias
host=$host_alias
target=$target_alias

# FIXME: To remove some day.
1234
1235
1236
1237
1238
1239
1240
1241

1242
1243
1244
1245
1246
1247
1248
1269
1270
1271
1272
1273
1274
1275

1276
1277
1278
1279
1280
1281
1282
1283







-
+







  ac_srcdir_defaulted=yes
  # Try the directory containing this script, then the parent directory.
  ac_confdir=`$as_dirname -- "$as_myself" ||
$as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$as_myself" : 'X\(//\)[^/]' \| \
	 X"$as_myself" : 'X\(//\)$' \| \
	 X"$as_myself" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$as_myself" |
printf "%s\n" X"$as_myself" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
1263
1264
1265
1266
1267
1268
1269
1270

1271
1272
1273
1274
1275
1276
1277
1298
1299
1300
1301
1302
1303
1304

1305
1306
1307
1308
1309
1310
1311
1312







-
+







else
  ac_srcdir_defaulted=no
fi
if test ! -r "$srcdir/$ac_unique_file"; then
  test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .."
  as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir"
fi
ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work"
ac_msg="sources are in $srcdir, but 'cd $srcdir' does not work"
ac_abs_confdir=`(
	cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg"
	pwd)`
# When building in place, set srcdir=.
if test "$ac_abs_confdir" = "$ac_pwd"; then
  srcdir=.
fi
1291
1292
1293
1294
1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312

1313
1314

1315
1316

1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327




1328
1329
1330
1331
1332
1333
1334
1335
1336
1337

1338
1339
1340
1341
1342
1343
1344
1326
1327
1328
1329
1330
1331
1332

1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346

1347
1348

1349
1350

1351
1352
1353
1354
1355
1356
1357
1358




1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380







-
+













-
+

-
+

-
+







-
-
-
-
+
+
+
+










+







#
# Report the --help message.
#
if test "$ac_init_help" = "long"; then
  # Omit some internal or obsolete options to make the list less imposing.
  # This message is too long to be a string in the A/UX 3.1 sh.
  cat <<_ACEOF
\`configure' configures thread 3.0a2 to adapt to many kinds of systems.
'configure' configures thread 3.0.2 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print \`checking ...' messages
  -q, --quiet, --silent   do not print 'checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for \`--cache-file=config.cache'
  -C, --config-cache      alias for '--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or \`..']
      --srcdir=DIR        find the sources in DIR [configure dir or '..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [$ac_default_prefix]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, \`make install' will install all the files in
\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc.  You can specify
an installation prefix other than \`$ac_default_prefix' using \`--prefix',
for instance \`--prefix=\$HOME'.
By default, 'make install' will install all the files in
'$ac_default_prefix/bin', '$ac_default_prefix/lib' etc.  You can specify
an installation prefix other than '$ac_default_prefix' using '--prefix',
for instance '--prefix=\$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
1352
1353
1354
1355
1356
1357
1358
1359

1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374

1375
1376
1377
1378
1379
1380

1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396

1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415

1416
1417

1418
1419
1420
1421
1422
1423
1424
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433

1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452

1453
1454

1455
1456
1457
1458
1459
1460
1461
1462







-
+















+






+















-
+


















-
+

-
+








  cat <<\_ACEOF
_ACEOF
fi

if test -n "$ac_init_help"; then
  case $ac_init_help in
     short | recursive ) echo "Configuration of thread 3.0a2:";;
     short | recursive ) echo "Configuration of thread 3.0.2:";;
   esac
  cat <<\_ACEOF

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-threads        build with threads (default: on)
  --enable-shared         build and link with shared libraries (default: on)
  --enable-stubs          build and link with stub libraries. Always true for
                          shared builds (default: on)
  --enable-64bit          enable 64bit support (default: off)
  --enable-64bit-vis      enable 64bit Sparc VIS support (default: off)
  --disable-rpath         disable rpath support (default: on)
  --enable-symbols        build with debugging symbols (default: off)
  --enable-zipfs          build with Zipfs support (default: on)

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-tcl              directory containing tcl configuration
                          (tclConfig.sh)
  --with-tcl8             Compile for Tcl8 in Tcl9 environment
  --with-gdbm             link with optional GDBM support
  --with-lmdb             link with optional LMDB support
  --with-naviserver       directory with NaviServer/AOLserver distribution
  --with-tclinclude       directory containing the public Tcl header files

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

Use these variables to override the choices made by `configure' or to help
Use these variables to override the choices made by 'configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to the package provider.
_ACEOF
ac_status=$?
fi

if test "$ac_init_help" = "recursive"; then
  # If there are subdirs, report their specific --help.
  for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
    test -d "$ac_dir" ||
      { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } ||
      continue
    ac_builddir=.

case "$ac_dir" in
.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
*)
  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
  ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'`
  # A ".." for each directory in $ac_dir_suffix.
  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  case $ac_top_builddir_sub in
  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
  esac ;;
esac
ac_abs_top_builddir=$ac_pwd
ac_abs_builddir=$ac_pwd$ac_dir_suffix
1438
1439
1440
1441
1442
1443
1444
1445


1446
1447
1448
1449
1450
1451
1452
1453

1454
1455
1456
1457
1458
1459
1460
1461
1462
1463


1464
1465

1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482

1483
1484
1485
1486
1487
1488
1489

1490
1491
1492
1493
1494
1495
1496
1497

1498
1499
1500
1501


1502
1503
1504


1505
1506
1507


1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526

1527
1528
1529
1530
1531
1532
1533
1534

1535
1536
1537

1538

1539
1540
1541


1542
1543
1544


1545
1546
1547
1548
1549
1550
















































1551
1552
1553
1554


1555
1556
1557
1558
1559
1560
1561
1562
1563
1564

1565
1566
1567

1568
1569
1570
1571
1572
1573
1574

1575
1576
1577
1578



1579
1580
1581
1582



1583
1584
1585


1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605







1606
1607
1608
1609
1610

1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678

1679
1680
1681
1682
1683
1684

1685
1686
1687

1688
1689
1690
1691
1692

1693
1694
1695
1696
1697
1698

1699
1700
1701

1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751


1752
1753
1754
1755

1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768







1769
1770
1771
1772
1773
1774
1775

1776
1777
1778
1779
1780

1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793

1794
1795
1796
1797
1798
1799
1800
1801
1802

1803
1804
1805
1806
1807
1808
1809


1810
1811
1812



1813
1814
1815



1816
1817
1818
1819


1820
1821
1822




















1823
1824
1825
1826
1827
1828


1829
1830

1831
1832
1833
1834
1835
1836
1837
1476
1477
1478
1479
1480
1481
1482

1483
1484
1485
1486
1487
1488
1489
1490
1491

1492
1493
1494
1495
1496
1497
1498
1499
1500


1501
1502
1503

1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520

1521
1522
1523
1524
1525
1526
1527

1528
1529
1530
1531
1532
1533
1534
1535

1536
1537
1538
1539

1540
1541
1542


1543
1544
1545
1546

1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566

1567
1568
1569
1570
1571
1572
1573
1574

1575
1576
1577
1578
1579

1580
1581


1582
1583
1584
1585

1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643


1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654

1655
1656
1657

1658
1659
1660
1661
1662
1663
1664

1665
1666
1667


1668
1669
1670
1671



1672
1673
1674
1675
1676

1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692






1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703

1704




































































1705






1706



1707





1708






1709

1710

1711







































1712






1713
1714


1715
1716

1717
1718

1719
1720
1721
1722
1723
1724
1725
1726






1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739

1740


1741


1742




1743
1744
1745
1746
1747
1748
1749
1750

1751
1752
1753
1754
1755
1756
1757
1758
1759

1760
1761
1762
1763
1764
1765
1766

1767
1768
1769


1770
1771
1772
1773


1774
1775
1776
1777
1778


1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807


1808
1809
1810

1811
1812
1813
1814
1815
1816
1817
1818







-
+
+







-
+








-
-
+
+

-
+
















-
+






-
+







-
+



-
+
+

-
-
+
+


-
+
+


















-
+







-
+



+
-
+

-
-
+
+


-
+
+






+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
+
+









-
+


-
+






-
+


-
-
+
+
+

-
-
-
+
+
+


-
+
+














-
-
-
-
-
-
+
+
+
+
+
+
+




-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
+
-

-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-


-
-
+
+
-


-
+







-
-
-
-
-
-
+
+
+
+
+
+
+






-
+
-
-

-
-
+
-
-
-
-








-
+








-
+






-
+
+

-
-
+
+
+

-
-
+
+
+


-
-
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
-
+
+

-
+







    ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix
    ac_top_srcdir=$ac_top_build_prefix$srcdir
    ac_abs_top_srcdir=$ac_pwd/$srcdir ;;
esac
ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix

    cd "$ac_dir" || { ac_status=$?; continue; }
    # Check for guested configure.
    # Check for configure.gnu first; this name is used for a wrapper for
    # Metaconfig's "Configure" on case-insensitive file systems.
    if test -f "$ac_srcdir/configure.gnu"; then
      echo &&
      $SHELL "$ac_srcdir/configure.gnu" --help=recursive
    elif test -f "$ac_srcdir/configure"; then
      echo &&
      $SHELL "$ac_srcdir/configure" --help=recursive
    else
      $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
      printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2
    fi || ac_status=$?
    cd "$ac_pwd" || { ac_status=$?; break; }
  done
fi

test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
  cat <<\_ACEOF
thread configure 3.0a2
generated by GNU Autoconf 2.69
thread configure 3.0.2
generated by GNU Autoconf 2.72

Copyright (C) 2012 Free Software Foundation, Inc.
Copyright (C) 2023 Free Software Foundation, Inc.
This configure script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it.
_ACEOF
  exit
fi

## ------------------------ ##
## Autoconf initialization. ##
## ------------------------ ##

# ac_fn_c_try_compile LINENO
# --------------------------
# Try to compile conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_compile ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  rm -f conftest.$ac_objext
  rm -f conftest.$ac_objext conftest.beam
  if { { ac_try="$ac_compile"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_compile") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && {
	 test -z "$ac_c_werror_flag" ||
	 test ! -s conftest.err
       } && test -s conftest.$ac_objext; then :
       } && test -s conftest.$ac_objext
then :
  ac_retval=0
else
  $as_echo "$as_me: failed program was:" >&5
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

	ac_retval=1
	ac_retval=1 ;;
esac
fi
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_compile

# ac_fn_c_try_cpp LINENO
# ----------------------
# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_cpp ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if { { ac_try="$ac_cpp conftest.$ac_ext"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } > conftest.i && {
	 test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
	 test ! -s conftest.err
       }
       }; then :
then :
  ac_retval=0
else
  $as_echo "$as_me: failed program was:" >&5
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

    ac_retval=1
    ac_retval=1 ;;
esac
fi
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_cpp

# ac_fn_c_try_link LINENO
# -----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_link ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext
  if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && {
	 test -z "$ac_c_werror_flag" ||
	 test ! -s conftest.err
       } && test -s conftest$ac_exeext && {
	 test "$cross_compiling" = yes ||
	 test -x conftest$ac_exeext
       }
then :
  ac_retval=0
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

	ac_retval=1 ;;
esac
fi
  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
  # interfere with the next link command; also delete a directory that is
  # left behind by Apple's compiler.  We do this before executing the actions.
  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_link

# ac_fn_c_try_run LINENO
# ----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
# that executables *can* be run.
# Try to run conftest.$ac_ext, and return whether this succeeded. Assumes that
# executables *can* be run.
ac_fn_c_try_run ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
  { { case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_try") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; }; then :
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; }
then :
  ac_retval=0
else
  $as_echo "$as_me: program exited with status $ac_status" >&5
       $as_echo "$as_me: failed program was:" >&5
else case e in #(
  e) printf "%s\n" "$as_me: program exited with status $ac_status" >&5
       printf "%s\n" "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

       ac_retval=$ac_status
       ac_retval=$ac_status ;;
esac
fi
  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_run

# ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES
# -------------------------------------------------------
# Tests whether HEADER exists and can be compiled using the include files in
# INCLUDES, setting the cache variable VAR accordingly.
ac_fn_c_check_header_compile ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
printf %s "checking for $2... " >&6; }
if eval test \${$3+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$4
#include <$2>
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
  eval "$3=yes"
else
  eval "$3=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$3
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_header_compile

# ac_fn_c_try_link LINENO
# -----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_link ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  rm -f conftest.$ac_objext conftest$ac_exeext
  if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    grep -v '^ *+' conftest.err >conftest.er1
    cat conftest.er1 >&5
    mv -f conftest.er1 conftest.err
  fi
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; } && {
	 test -z "$ac_c_werror_flag" ||
	 test ! -s conftest.err
       } && test -s conftest$ac_exeext && {
	 test "$cross_compiling" = yes ||
	 test -x conftest$ac_exeext
       }; then :
  ac_retval=0
else
  $as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

	ac_retval=1
fi
  # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information
  # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would
  # interfere with the next link command; also delete a directory that is
  # left behind by Apple's compiler.  We do this before executing the actions.
  rm -rf conftest.dSYM conftest_ipa8_conftest.oo
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_link

# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES
# -------------------------------------------------------
# Tests whether HEADER exists, giving a warning if it cannot be compiled using
# the include files in INCLUDES and setting the cache variable VAR
# accordingly.
ac_fn_c_check_header_mongrel ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  if eval \${$3+:} false; then :
then :
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
fi
eval ac_res=\$$3
  eval "$3=yes"
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
else
else case e in #(
  # Is the header compilable?
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5
$as_echo_n "checking $2 usability... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
  e) eval "$3=no" ;;
$4
#include <$2>
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  ac_header_compiler=yes
else
esac
  ac_header_compiler=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5
$as_echo "$ac_header_compiler" >&6; }

# Is the header present?
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5
$as_echo_n "checking $2 presence... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <$2>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
  ac_header_preproc=yes
else
  ac_header_preproc=no
fi
rm -f conftest.err conftest.i conftest.$ac_ext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5
$as_echo "$ac_header_preproc" >&6; }

# So?  What about this header?
case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #((
  yes:no: )
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5
$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
    ;;
  no:yes:* )
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5
$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     check for missing prerequisite headers?" >&5
$as_echo "$as_me: WARNING: $2:     check for missing prerequisite headers?" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5
$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&5
$as_echo "$as_me: WARNING: $2:     section \"Present But Cannot Be Compiled\"" >&2;}
    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5
$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;}
    ;;
esac
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
else
  eval "$3=\$ac_header_compiler"
fi
eval ac_res=\$$3
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
fi
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_header_mongrel
} # ac_fn_c_check_header_compile

# ac_fn_c_check_func LINENO FUNC VAR
# ----------------------------------
# Tests whether FUNC exists, setting the cache variable VAR accordingly
ac_fn_c_check_func ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
$as_echo_n "checking for $2... " >&6; }
if eval \${$3+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
printf %s "checking for $2... " >&6; }
if eval test \${$3+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
#define $2 innocuous_$2

/* System header to define __stub macros and hopefully few prototypes,
    which can conflict with char $2 (); below.
   which can conflict with char $2 (void); below.  */
    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
    <limits.h> exists even on freestanding compilers.  */

#ifdef __STDC__
# include <limits.h>
#include <limits.h>
#else
# include <assert.h>
#endif

#undef $2

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char $2 ();
char $2 (void);
/* The GNU C library defines this for functions which it implements
    to always fail with ENOSYS.  Some functions are actually named
    something starting with __ and the normal name is an alias.  */
#if defined __stub_$2 || defined __stub___$2
choke me
#endif

int
main ()
main (void)
{
return $2 ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  eval "$3=yes"
else
  eval "$3=no"
else case e in #(
  e) eval "$3=no" ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext ;;
esac
fi
eval ac_res=\$$3
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
	       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
printf "%s\n" "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_func
ac_configure_args_raw=
for ac_arg
do
  case $ac_arg in
  *\'*)
    ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
  esac
  as_fn_append ac_configure_args_raw " '$ac_arg'"
done

case $ac_configure_args_raw in
  *$as_nl*)
    ac_safe_unquote= ;;
  *)
    ac_unsafe_z='|&;<>()$`\\"*?[ ''	' # This string ends in space, tab.
    ac_unsafe_a="$ac_unsafe_z#~"
    ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g"
    ac_configure_args_raw=`      printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;;
esac

cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by thread $as_me 3.0a2, which was
generated by GNU Autoconf 2.69.  Invocation command line was
It was created by thread $as_me 3.0.2, which was
generated by GNU Autoconf 2.72.  Invocation command line was

  $ $0 $@
  $ $0$ac_configure_args_raw

_ACEOF
exec 5>>config.log
{
cat <<_ASUNAME
## --------- ##
## Platform. ##
1856
1857
1858
1859
1860
1861
1862

1863
1864





1865
1866
1867
1868
1869
1870
1871
1837
1838
1839
1840
1841
1842
1843
1844


1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856







+
-
-
+
+
+
+
+








_ASUNAME

as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    $as_echo "PATH: $as_dir"
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    printf "%s\n" "PATH: $as_dir"
  done
IFS=$as_save_IFS

} >&5

cat >&5 <<_ACEOF

1892
1893
1894
1895
1896
1897
1898
1899

1900
1901
1902
1903
1904
1905
1906
1877
1878
1879
1880
1881
1882
1883

1884
1885
1886
1887
1888
1889
1890
1891







-
+







  do
    case $ac_arg in
    -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
    -q | -quiet | --quiet | --quie | --qui | --qu | --q \
    | -silent | --silent | --silen | --sile | --sil)
      continue ;;
    *\'*)
      ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
      ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
    esac
    case $ac_pass in
    1) as_fn_append ac_configure_args0 " '$ac_arg'" ;;
    2)
      as_fn_append ac_configure_args1 " '$ac_arg'"
      if test $ac_must_keep_next = true; then
	ac_must_keep_next=false # Got value, back to normal.
1927
1928
1929
1930
1931
1932
1933


1934
1935
1936
1937
1938

1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950


1951
1952
1953
1954
1955
1956
1957
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924

1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935


1936
1937
1938
1939
1940
1941
1942
1943
1944







+
+




-
+










-
-
+
+








# When interrupted or exit'd, cleanup temporary files, and complete
# config.log.  We remove comments because anyway the quotes in there
# would cause problems or look ugly.
# WARNING: Use '\'' to represent an apostrophe within the trap.
# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug.
trap 'exit_status=$?
  # Sanitize IFS.
  IFS=" ""	$as_nl"
  # Save into config.log some information that might help in debugging.
  {
    echo

    $as_echo "## ---------------- ##
    printf "%s\n" "## ---------------- ##
## Cache variables. ##
## ---------------- ##"
    echo
    # The following way of writing the cache mishandles newlines in values,
(
  for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do
    eval ac_val=\$$ac_var
    case $ac_val in #(
    *${as_nl}*)
      case $ac_var in #(
      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      esac
      case $ac_var in #(
      _ | IFS | as_nl) ;; #(
      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
      *) { eval $ac_var=; unset $ac_var;} ;;
      esac ;;
    esac
1967
1968
1969
1970
1971
1972
1973
1974

1975
1976
1977
1978
1979
1980
1981
1982

1983
1984

1985
1986
1987
1988
1989

1990
1991
1992
1993
1994
1995
1996
1997

1998
1999

2000
2001
2002
2003
2004
2005

2006
2007
2008
2009
2010
2011
2012
2013
2014


2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028

2029
2030
2031
2032
2033

2034
2035
2036
2037

2038
2039
2040
2041

2042
2043
2044
2045

2046
2047
2048
2049

2050
2051
2052
2053

2054
2055
2056
2057
2058
2059
2060
2061
2062
2063

2064
2065
2066
2067
2068
2069

2070
2071
2072

2073
2074

2075

2076
2077
2078
2079
2080









2081
2082
2083
2084


2085
2086

2087
2088
2089
2090
2091
2092
2093
2094
2095


2096
2097
2098
2099
2100
2101
2102
2103


2104
2105
2106














































































































































































































































































































































2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118


2119
2120
2121
2122


2123
2124
2125
2126
2127
2128
2129
2130
2131
2132


2133
2134
2135
2136


2137
2138
2139
2140
2141
2142




2143
2144
2145
2146
2147
2148

2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162






2163
2164
2165
2166
2167
2168
2169
1954
1955
1956
1957
1958
1959
1960

1961
1962
1963
1964
1965
1966
1967
1968

1969
1970

1971
1972
1973
1974
1975

1976
1977
1978
1979
1980
1981
1982
1983

1984
1985

1986
1987
1988
1989
1990
1991

1992
1993
1994
1995
1996
1997
1998
1999


2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014

2015
2016
2017
2018


2019

2020


2021

2022


2023

2024


2025

2026


2027

2028


2029

2030
2031
2032
2033


2034


2035




2036

2037

2038

2039

2040
2041

2042
2043




2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054


2055
2056
2057

2058
2059
2060
2061
2062
2063
2064
2065


2066
2067
2068
2069
2070
2071
2072
2073


2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422


2423
2424
2425
2426


2427
2428
2429
2430
2431
2432
2433
2434
2435
2436


2437
2438
2439
2440


2441
2442
2443
2444




2445
2446
2447
2448
2449
2450
2451
2452
2453

2454
2455
2456
2457
2458
2459
2460
2461
2462
2463





2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476







-
+







-
+

-
+




-
+







-
+

-
+





-
+







-
-
+
+













-
+



-
-
+
-

-
-
+
-

-
-
+
-

-
-
+
-

-
-
+
-

-
-
+
-




-
-

-
-
+
-
-
-
-

-
+
-

-
+
-

+
-
+

-
-
-
-
+
+
+
+
+
+
+
+
+


-
-
+
+

-
+







-
-
+
+






-
-
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+










-
-
+
+


-
-
+
+








-
-
+
+


-
-
+
+


-
-
-
-
+
+
+
+





-
+









-
-
-
-
-
+
+
+
+
+
+







      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
      ;;
    esac |
    sort
)
    echo

    $as_echo "## ----------------- ##
    printf "%s\n" "## ----------------- ##
## Output variables. ##
## ----------------- ##"
    echo
    for ac_var in $ac_subst_vars
    do
      eval ac_val=\$$ac_var
      case $ac_val in
      *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
      *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
      esac
      $as_echo "$ac_var='\''$ac_val'\''"
      printf "%s\n" "$ac_var='\''$ac_val'\''"
    done | sort
    echo

    if test -n "$ac_subst_files"; then
      $as_echo "## ------------------- ##
      printf "%s\n" "## ------------------- ##
## File substitutions. ##
## ------------------- ##"
      echo
      for ac_var in $ac_subst_files
      do
	eval ac_val=\$$ac_var
	case $ac_val in
	*\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
	*\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;;
	esac
	$as_echo "$ac_var='\''$ac_val'\''"
	printf "%s\n" "$ac_var='\''$ac_val'\''"
      done | sort
      echo
    fi

    if test -s confdefs.h; then
      $as_echo "## ----------- ##
      printf "%s\n" "## ----------- ##
## confdefs.h. ##
## ----------- ##"
      echo
      cat confdefs.h
      echo
    fi
    test "$ac_signal" != 0 &&
      $as_echo "$as_me: caught signal $ac_signal"
    $as_echo "$as_me: exit $exit_status"
      printf "%s\n" "$as_me: caught signal $ac_signal"
    printf "%s\n" "$as_me: exit $exit_status"
  } >&5
  rm -f core *.core core.conftest.* &&
    rm -f -r conftest* confdefs* conf$$* $ac_clean_files &&
    exit $exit_status
' 0
for ac_signal in 1 2 13 15; do
  trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal
done
ac_signal=0

# confdefs.h avoids OS command line length limits that DEFS can exceed.
rm -f -r conftest* confdefs.h

$as_echo "/* confdefs.h */" > confdefs.h
printf "%s\n" "/* confdefs.h */" > confdefs.h

# Predefined preprocessor variables.

cat >>confdefs.h <<_ACEOF
#define PACKAGE_NAME "$PACKAGE_NAME"
printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h
_ACEOF

cat >>confdefs.h <<_ACEOF
#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h
_ACEOF

cat >>confdefs.h <<_ACEOF
#define PACKAGE_VERSION "$PACKAGE_VERSION"
printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h
_ACEOF

cat >>confdefs.h <<_ACEOF
#define PACKAGE_STRING "$PACKAGE_STRING"
printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h
_ACEOF

cat >>confdefs.h <<_ACEOF
#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h
_ACEOF

cat >>confdefs.h <<_ACEOF
#define PACKAGE_URL "$PACKAGE_URL"
printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h
_ACEOF


# Let the site file select an alternate cache file if it wants to.
# Prefer an explicitly selected file to automatically selected ones.
ac_site_file1=NONE
ac_site_file2=NONE
if test -n "$CONFIG_SITE"; then
  # We do not want a PATH search for config.site.
  case $CONFIG_SITE in #((
  ac_site_files="$CONFIG_SITE"
    -*)  ac_site_file1=./$CONFIG_SITE;;
    */*) ac_site_file1=$CONFIG_SITE;;
    *)   ac_site_file1=./$CONFIG_SITE;;
  esac
elif test "x$prefix" != xNONE; then
  ac_site_file1=$prefix/share/config.site
  ac_site_files="$prefix/share/config.site $prefix/etc/config.site"
  ac_site_file2=$prefix/etc/config.site
else
  ac_site_file1=$ac_default_prefix/share/config.site
  ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
  ac_site_file2=$ac_default_prefix/etc/config.site
fi

for ac_site_file in "$ac_site_file1" "$ac_site_file2"
for ac_site_file in $ac_site_files
do
  test "x$ac_site_file" = xNONE && continue
  if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then
    { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
$as_echo "$as_me: loading site script $ac_site_file" >&6;}
  case $ac_site_file in #(
  */*) :
     ;; #(
  *) :
    ac_site_file=./$ac_site_file ;;
esac
  if test -f "$ac_site_file" && test -r "$ac_site_file"; then
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5
printf "%s\n" "$as_me: loading site script $ac_site_file" >&6;}
    sed 's/^/| /' "$ac_site_file" >&5
    . "$ac_site_file" \
      || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
      || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error $? "failed to load site script $ac_site_file
See \`config.log' for more details" "$LINENO" 5; }
See 'config.log' for more details" "$LINENO" 5; }
  fi
done

if test -r "$cache_file"; then
  # Some versions of bash will fail to source /dev/null (special files
  # actually), so we avoid doing that.  DJGPP emulates it as a regular file.
  if test /dev/null != "$cache_file" && test -f "$cache_file"; then
    { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
$as_echo "$as_me: loading cache $cache_file" >&6;}
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5
printf "%s\n" "$as_me: loading cache $cache_file" >&6;}
    case $cache_file in
      [\\/]* | ?:[\\/]* ) . "$cache_file";;
      *)                      . "./$cache_file";;
    esac
  fi
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
$as_echo "$as_me: creating cache $cache_file" >&6;}
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5
printf "%s\n" "$as_me: creating cache $cache_file" >&6;}
  >$cache_file
fi

# Test code for whether the C compiler supports C89 (global declarations)
ac_c_conftest_c89_globals='
/* Does the compiler advertise C89 conformance?
   Do not test the value of __STDC__, because some compilers set it to 0
   while being otherwise adequately conformant. */
#if !defined __STDC__
# error "Compiler does not advertise C89 conformance"
#endif

#include <stddef.h>
#include <stdarg.h>
struct stat;
/* Most of the following tests are stolen from RCS 5.7 src/conf.sh.  */
struct buf { int x; };
struct buf * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (char **p, int i)
{
  return p[i];
}
static char *f (char * (*g) (char **, int), char **p, ...)
{
  char *s;
  va_list v;
  va_start (v,p);
  s = g (p, va_arg (v,int));
  va_end (v);
  return s;
}

/* C89 style stringification. */
#define noexpand_stringify(a) #a
const char *stringified = noexpand_stringify(arbitrary+token=sequence);

/* C89 style token pasting.  Exercises some of the corner cases that
   e.g. old MSVC gets wrong, but not very hard. */
#define noexpand_concat(a,b) a##b
#define expand_concat(a,b) noexpand_concat(a,b)
extern int vA;
extern int vbee;
#define aye A
#define bee B
int *pvA = &expand_concat(v,aye);
int *pvbee = &noexpand_concat(v,bee);

/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
   function prototypes and stuff, but not \xHH hex character constants.
   These do not provoke an error unfortunately, instead are silently treated
   as an "x".  The following induces an error, until -std is added to get
   proper ANSI mode.  Curiously \x00 != x always comes out true, for an
   array size at least.  It is necessary to write \x00 == 0 to get something
   that is true only with -std.  */
int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1];

/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
   inside strings and character constants.  */
#define FOO(x) '\''x'\''
int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1];

int test (int i, double x);
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int),
               int, int);'

# Test code for whether the C compiler supports C89 (body of main).
ac_c_conftest_c89_main='
ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]);
'

# Test code for whether the C compiler supports C99 (global declarations)
ac_c_conftest_c99_globals='
/* Does the compiler advertise C99 conformance? */
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L
# error "Compiler does not advertise C99 conformance"
#endif

// See if C++-style comments work.

#include <stdbool.h>
extern int puts (const char *);
extern int printf (const char *, ...);
extern int dprintf (int, const char *, ...);
extern void *malloc (size_t);
extern void free (void *);

// Check varargs macros.  These examples are taken from C99 6.10.3.5.
// dprintf is used instead of fprintf to avoid needing to declare
// FILE and stderr.
#define debug(...) dprintf (2, __VA_ARGS__)
#define showlist(...) puts (#__VA_ARGS__)
#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__))
static void
test_varargs_macros (void)
{
  int x = 1234;
  int y = 5678;
  debug ("Flag");
  debug ("X = %d\n", x);
  showlist (The first, second, and third items.);
  report (x>y, "x is %d but y is %d", x, y);
}

// Check long long types.
#define BIG64 18446744073709551615ull
#define BIG32 4294967295ul
#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0)
#if !BIG_OK
  #error "your preprocessor is broken"
#endif
#if BIG_OK
#else
  #error "your preprocessor is broken"
#endif
static long long int bignum = -9223372036854775807LL;
static unsigned long long int ubignum = BIG64;

struct incomplete_array
{
  int datasize;
  double data[];
};

struct named_init {
  int number;
  const wchar_t *name;
  double average;
};

typedef const char *ccp;

static inline int
test_restrict (ccp restrict text)
{
  // Iterate through items via the restricted pointer.
  // Also check for declarations in for loops.
  for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i)
    continue;
  return 0;
}

// Check varargs and va_copy.
static bool
test_varargs (const char *format, ...)
{
  va_list args;
  va_start (args, format);
  va_list args_copy;
  va_copy (args_copy, args);

  const char *str = "";
  int number = 0;
  float fnumber = 0;

  while (*format)
    {
      switch (*format++)
	{
	case '\''s'\'': // string
	  str = va_arg (args_copy, const char *);
	  break;
	case '\''d'\'': // int
	  number = va_arg (args_copy, int);
	  break;
	case '\''f'\'': // float
	  fnumber = va_arg (args_copy, double);
	  break;
	default:
	  break;
	}
    }
  va_end (args_copy);
  va_end (args);

  return *str && number && fnumber;
}
'

# Test code for whether the C compiler supports C99 (body of main).
ac_c_conftest_c99_main='
  // Check bool.
  _Bool success = false;
  success |= (argc != 0);

  // Check restrict.
  if (test_restrict ("String literal") == 0)
    success = true;
  char *restrict newvar = "Another string";

  // Check varargs.
  success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234);
  test_varargs_macros ();

  // Check flexible array members.
  struct incomplete_array *ia =
    malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
  ia->datasize = 10;
  for (int i = 0; i < ia->datasize; ++i)
    ia->data[i] = i * 1.234;
  // Work around memory leak warnings.
  free (ia);

  // Check named initializers.
  struct named_init ni = {
    .number = 34,
    .name = L"Test wide string",
    .average = 543.34343,
  };

  ni.number = 58;

  int dynamic_array[ni.number];
  dynamic_array[0] = argv[0][0];
  dynamic_array[ni.number - 1] = 543;

  // work around unused variable warnings
  ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\''
	 || dynamic_array[ni.number - 1] != 543);
'

# Test code for whether the C compiler supports C11 (global declarations)
ac_c_conftest_c11_globals='
/* Does the compiler advertise C11 conformance? */
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
# error "Compiler does not advertise C11 conformance"
#endif

// Check _Alignas.
char _Alignas (double) aligned_as_double;
char _Alignas (0) no_special_alignment;
extern char aligned_as_int;
char _Alignas (0) _Alignas (int) aligned_as_int;

// Check _Alignof.
enum
{
  int_alignment = _Alignof (int),
  int_array_alignment = _Alignof (int[100]),
  char_alignment = _Alignof (char)
};
_Static_assert (0 < -_Alignof (int), "_Alignof is signed");

// Check _Noreturn.
int _Noreturn does_not_return (void) { for (;;) continue; }

// Check _Static_assert.
struct test_static_assert
{
  int x;
  _Static_assert (sizeof (int) <= sizeof (long int),
                  "_Static_assert does not work in struct");
  long int y;
};

// Check UTF-8 literals.
#define u8 syntax error!
char const utf8_literal[] = u8"happens to be ASCII" "another string";

// Check duplicate typedefs.
typedef long *long_ptr;
typedef long int *long_ptr;
typedef long_ptr long_ptr;

// Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1.
struct anonymous
{
  union {
    struct { int i; int j; };
    struct { int k; long int l; } w;
  };
  int m;
} v1;
'

# Test code for whether the C compiler supports C11 (body of main).
ac_c_conftest_c11_main='
  _Static_assert ((offsetof (struct anonymous, i)
		   == offsetof (struct anonymous, w.k)),
		  "Anonymous union alignment botch");
  v1.i = 2;
  v1.w.k = 5;
  ok |= v1.i != 5;
'

# Test code for whether the C compiler supports C11 (complete).
ac_c_conftest_c11_program="${ac_c_conftest_c89_globals}
${ac_c_conftest_c99_globals}
${ac_c_conftest_c11_globals}

int
main (int argc, char **argv)
{
  int ok = 0;
  ${ac_c_conftest_c89_main}
  ${ac_c_conftest_c99_main}
  ${ac_c_conftest_c11_main}
  return ok;
}
"

# Test code for whether the C compiler supports C99 (complete).
ac_c_conftest_c99_program="${ac_c_conftest_c89_globals}
${ac_c_conftest_c99_globals}

int
main (int argc, char **argv)
{
  int ok = 0;
  ${ac_c_conftest_c89_main}
  ${ac_c_conftest_c99_main}
  return ok;
}
"

# Test code for whether the C compiler supports C89 (complete).
ac_c_conftest_c89_program="${ac_c_conftest_c89_globals}

int
main (int argc, char **argv)
{
  int ok = 0;
  ${ac_c_conftest_c89_main}
  return ok;
}
"

as_fn_append ac_header_c_list " stdio.h stdio_h HAVE_STDIO_H"
as_fn_append ac_header_c_list " stdlib.h stdlib_h HAVE_STDLIB_H"
as_fn_append ac_header_c_list " string.h string_h HAVE_STRING_H"
as_fn_append ac_header_c_list " inttypes.h inttypes_h HAVE_INTTYPES_H"
as_fn_append ac_header_c_list " stdint.h stdint_h HAVE_STDINT_H"
as_fn_append ac_header_c_list " strings.h strings_h HAVE_STRINGS_H"
as_fn_append ac_header_c_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H"
as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H"
as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H"
# Check that the precious variables saved in the cache have kept the same
# value.
ac_cache_corrupted=false
for ac_var in $ac_precious_vars; do
  eval ac_old_set=\$ac_cv_env_${ac_var}_set
  eval ac_new_set=\$ac_env_${ac_var}_set
  eval ac_old_val=\$ac_cv_env_${ac_var}_value
  eval ac_new_val=\$ac_env_${ac_var}_value
  case $ac_old_set,$ac_new_set in
    set,)
      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' was set to '$ac_old_val' in the previous run" >&5
printf "%s\n" "$as_me: error: '$ac_var' was set to '$ac_old_val' in the previous run" >&2;}
      ac_cache_corrupted=: ;;
    ,set)
      { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5
$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' was not set in the previous run" >&5
printf "%s\n" "$as_me: error: '$ac_var' was not set in the previous run" >&2;}
      ac_cache_corrupted=: ;;
    ,);;
    *)
      if test "x$ac_old_val" != "x$ac_new_val"; then
	# differences in whitespace do not lead to failure.
	ac_old_val_w=`echo x $ac_old_val`
	ac_new_val_w=`echo x $ac_new_val`
	if test "$ac_old_val_w" != "$ac_new_val_w"; then
	  { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5
$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
	  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' has changed since the previous run:" >&5
printf "%s\n" "$as_me: error: '$ac_var' has changed since the previous run:" >&2;}
	  ac_cache_corrupted=:
	else
	  { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5
$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;}
	  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in '$ac_var' since the previous run:" >&5
printf "%s\n" "$as_me: warning: ignoring whitespace changes in '$ac_var' since the previous run:" >&2;}
	  eval $ac_var=\$ac_old_val
	fi
	{ $as_echo "$as_me:${as_lineno-$LINENO}:   former value:  \`$ac_old_val'" >&5
$as_echo "$as_me:   former value:  \`$ac_old_val'" >&2;}
	{ $as_echo "$as_me:${as_lineno-$LINENO}:   current value: \`$ac_new_val'" >&5
$as_echo "$as_me:   current value: \`$ac_new_val'" >&2;}
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}:   former value:  '$ac_old_val'" >&5
printf "%s\n" "$as_me:   former value:  '$ac_old_val'" >&2;}
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}:   current value: '$ac_new_val'" >&5
printf "%s\n" "$as_me:   current value: '$ac_new_val'" >&2;}
      fi;;
  esac
  # Pass precious variables to config.status.
  if test "$ac_new_set" = set; then
    case $ac_new_val in
    *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
    *\'*) ac_arg=$ac_var=`printf "%s\n" "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
    *) ac_arg=$ac_var=$ac_new_val ;;
    esac
    case " $ac_configure_args " in
      *" '$ac_arg' "*) ;; # Avoid dups.  Use of quotes ensures accuracy.
      *) as_fn_append ac_configure_args " '$ac_arg'" ;;
    esac
  fi
done
if $ac_cache_corrupted; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
  { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;}
  as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5
printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;}
  as_fn_error $? "run '${MAKE-make} distclean' and/or 'rm $cache_file'
	    and start over" "$LINENO" 5
fi
## -------------------- ##
## Main body of script. ##
## -------------------- ##

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
2178
2179
2180
2181
2182
2183
2184
2185
2186


2187
2188
2189
2190
2191
2192


2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209







2210
2211
2212
2213
2214
2215

2216




2217
2218

2219
2220

2221
2222
2223
2224
2225
2226
2227
2228


2229
2230
2231
2232
2233


2234
2235
2236


2237
2238
2239
2240
2241
2242
2243
2485
2486
2487
2488
2489
2490
2491


2492
2493
2494
2495
2496
2497


2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510






2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524

2525
2526
2527
2528
2529

2530
2531

2532
2533
2534
2535
2536
2537
2538
2539

2540
2541
2542
2543
2544


2545
2546
2547


2548
2549
2550
2551
2552
2553
2554
2555
2556







-
-
+
+




-
-
+
+











-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+







-
+
+



-
-
+
+

-
-
+
+







# This will define a ${TEA_PLATFORM} variable == "unix" or "windows"
# as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE.
#--------------------------------------------------------------------


    TEA_VERSION="3.13"

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking TEA configuration" >&5
$as_echo_n "checking TEA configuration... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking TEA configuration" >&5
printf %s "checking TEA configuration... " >&6; }
    if test x"${PACKAGE_NAME}" = x ; then
	as_fn_error $? "
The PACKAGE_NAME variable must be defined by your TEA configure.ac" "$LINENO" 5
    fi
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok (TEA ${TEA_VERSION})" >&5
$as_echo "ok (TEA ${TEA_VERSION})" >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ok (TEA ${TEA_VERSION})" >&5
printf "%s\n" "ok (TEA ${TEA_VERSION})" >&6; }

    # If the user did not set CFLAGS, set it now to keep macros
    # like AC_PROG_CC and AC_TRY_COMPILE from adding "-g -O2".
    if test "${CFLAGS+set}" != "set" ; then
	CFLAGS=""
    fi

    case "`uname -s`" in
	*win32*|*WIN32*|*MINGW32_*|*MINGW64_*|*MSYS_*)
	    # Extract the first word of "cygpath", so it can be a program name with args.
set dummy cygpath; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CYGPATH+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$CYGPATH"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CYGPATH+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CYGPATH"; then
  ac_cv_prog_CYGPATH="$CYGPATH" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CYGPATH="cygpath -m"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

  test -z "$ac_cv_prog_CYGPATH" && ac_cv_prog_CYGPATH="echo"
fi
fi ;;
esac
fi
CYGPATH=$ac_cv_prog_CYGPATH
if test -n "$CYGPATH"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CYGPATH" >&5
$as_echo "$CYGPATH" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CYGPATH" >&5
printf "%s\n" "$CYGPATH" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


	    EXEEXT=".exe"
	    TEA_PLATFORM="windows"
	    ;;
	*CYGWIN_*)
2265
2266
2267
2268
2269
2270
2271
2272
2273


2274
2275
2276
2277
2278
2279
2280

2281
2282
2283
2284
2285
2286
2287
2578
2579
2580
2581
2582
2583
2584


2585
2586
2587
2588
2589
2590
2591
2592

2593
2594
2595
2596
2597
2598
2599
2600







-
-
+
+






-
+







    # This is needed for recursive configures, since autoconf propagates
    # $prefix, but not $exec_prefix (doh!).
    if test x$exec_prefix = xNONE ; then
	exec_prefix_default=yes
	exec_prefix=$prefix
    fi

    { $as_echo "$as_me:${as_lineno-$LINENO}: configuring ${PACKAGE_NAME} ${PACKAGE_VERSION}" >&5
$as_echo "$as_me: configuring ${PACKAGE_NAME} ${PACKAGE_VERSION}" >&6;}
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: configuring ${PACKAGE_NAME} ${PACKAGE_VERSION}" >&5
printf "%s\n" "$as_me: configuring ${PACKAGE_NAME} ${PACKAGE_VERSION}" >&6;}




    # This package name must be replaced statically for AC_SUBST to work

    # Substitute STUB_LIB_FILE in case package creates a stub library too.



    # We AC_SUBST these here to ensure they are subst'ed,
    # in case the user doesn't call TEA_ADD_...



2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307







2308
2309
2310
2311
2312
2313
2314
2315


2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326


2327
2328
2329


2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393


2394
2395
2396







2397
2398
2399
2400
2401
2402







2403
2404
2405
2406
2407
2408
2409
2410


2411
2412
2413
2414
2415
2416
2417
2608
2609
2610
2611
2612
2613
2614






2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627


2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639

2640
2641
2642


2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660




























2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679

2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691






2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704


2705
2706
2707
2708
2709
2710
2711
2712
2713







-
-
-
-
-
-
+
+
+
+
+
+
+






-
-
+
+










-
+
+

-
-
+
+
















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



















-
+
+



+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+






-
-
+
+







    INSTALL='$(SHELL) $(srcdir)/tclconfig/install-sh -c'
    INSTALL_DATA_DIR='${INSTALL} -d -m 755'
    INSTALL_DATA='${INSTALL} -m 644'
    INSTALL_PROGRAM='${INSTALL} -m 755'
    INSTALL_SCRIPT='${INSTALL} -m 755'


    { $as_echo "$as_me:${as_lineno-$LINENO}: checking system version" >&5
$as_echo_n "checking system version... " >&6; }
if ${tcl_cv_sys_version+:} false; then :
  $as_echo_n "(cached) " >&6
else

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking system version" >&5
printf %s "checking system version... " >&6; }
if test ${tcl_cv_sys_version+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	# TEA specific:
	if test "${TEA_PLATFORM}" = "windows" ; then
	    tcl_cv_sys_version=windows
	else
	    tcl_cv_sys_version=`uname -s`-`uname -r`
	    if test "$?" -ne 0 ; then
		{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: can't find uname command" >&5
$as_echo "$as_me: WARNING: can't find uname command" >&2;}
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: can't find uname command" >&5
printf "%s\n" "$as_me: WARNING: can't find uname command" >&2;}
		tcl_cv_sys_version=unknown
	    else
		if test "`uname -s`" = "AIX" ; then
		    tcl_cv_sys_version=AIX-`uname -v`.`uname -r`
		fi
		if test "`uname -s`" = "NetBSD" -a -f /etc/debian_version ; then
		    tcl_cv_sys_version=NetBSD-Debian
		fi
	    fi
	fi

     ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_sys_version" >&5
$as_echo "$tcl_cv_sys_version" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_sys_version" >&5
printf "%s\n" "$tcl_cv_sys_version" >&6; }
    system=$tcl_cv_sys_version

    case $system in
	HP-UX-*) INSTALL_LIBRARY='${INSTALL} -m 755' ;;
	      *) INSTALL_LIBRARY='${INSTALL} -m 644' ;;
    esac










ac_aux_dir=
for ac_dir in tclconfig "$srcdir"/tclconfig; do
  if test -f "$ac_dir/install-sh"; then
    ac_aux_dir=$ac_dir
    ac_install_sh="$ac_aux_dir/install-sh -c"
    break
  elif test -f "$ac_dir/install.sh"; then
    ac_aux_dir=$ac_dir
    ac_install_sh="$ac_aux_dir/install.sh -c"
    break
  elif test -f "$ac_dir/shtool"; then
    ac_aux_dir=$ac_dir
    ac_install_sh="$ac_aux_dir/shtool install -c"
    break
  fi
done
if test -z "$ac_aux_dir"; then
  as_fn_error $? "cannot find install-sh, install.sh, or shtool in tclconfig \"$srcdir\"/tclconfig" "$LINENO" 5
fi

# These three variables are undocumented and unsupported,
# and are intended to be withdrawn in a future Autoconf release.
# They can cause serious problems if a builder's source tree is in a directory
# whose full name contains unusual characters.
ac_config_guess="$SHELL $ac_aux_dir/config.guess"  # Please don't use this var.
ac_config_sub="$SHELL $ac_aux_dir/config.sub"  # Please don't use this var.
ac_configure="$SHELL $ac_aux_dir/configure"  # Please don't use this var.



#--------------------------------------------------------------------
# Load the tclConfig.sh file
#--------------------------------------------------------------------



    #
    # Ok, lets find the tcl configuration
    # First, look for one uninstalled.
    # the alternative search directory is invoked by --with-tcl
    #

    if test x"${no_tcl}" = x ; then
	# we reset no_tcl in case something fails here
	no_tcl=true

# Check whether --with-tcl was given.
if test "${with_tcl+set}" = set; then :
if test ${with_tcl+y}
then :
  withval=$with_tcl; with_tclconfig="${withval}"
fi


# Check whether --with-tcl8 was given.
if test ${with_tcl8+y}
then :
  withval=$with_tcl8; with_tcl8="${withval}"
fi

	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl configuration" >&5
$as_echo_n "checking for Tcl configuration... " >&6; }
	if ${ac_cv_c_tclconfig+:} false; then :
  $as_echo_n "(cached) " >&6
else

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Tcl configuration" >&5
printf %s "checking for Tcl configuration... " >&6; }
	if test ${ac_cv_c_tclconfig+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)

	    # First check to see if --with-tcl was specified.
	    if test x"${with_tclconfig}" != x ; then
		case "${with_tclconfig}" in
		    */tclConfig.sh )
			if test -f "${with_tclconfig}"; then
			    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&5
$as_echo "$as_me: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&2;}
			    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&5
printf "%s\n" "$as_me: WARNING: --with-tcl argument should refer to directory containing tclConfig.sh, not to tclConfig.sh itself" >&2;}
			    with_tclconfig="`echo "${with_tclconfig}" | sed 's!/tclConfig\.sh$!!'`"
			fi ;;
		esac
		if test -f "${with_tclconfig}/tclConfig.sh" ; then
		    ac_cv_c_tclconfig="`(cd "${with_tclconfig}"; pwd)`"
		else
		    as_fn_error $? "${with_tclconfig} directory doesn't contain tclConfig.sh" "$LINENO" 5
2480
2481
2482
2483
2484
2485
2486


2487
2488


2489
2490


2491
2492
2493
2494
2495
2496
2497
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799







+
+


+
+


+
+







			`ls -d ${exec_prefix}/lib 2>/dev/null` \
			`ls -d ${prefix}/lib 2>/dev/null` \
			`ls -d /usr/local/lib 2>/dev/null` \
			`ls -d /usr/contrib/lib 2>/dev/null` \
			`ls -d /usr/pkg/lib 2>/dev/null` \
			`ls -d /usr/lib 2>/dev/null` \
			`ls -d /usr/lib64 2>/dev/null` \
			`ls -d /usr/lib/tcl9.1 2>/dev/null` \
			`ls -d /usr/lib/tcl9.0 2>/dev/null` \
			`ls -d /usr/lib/tcl8.6 2>/dev/null` \
			`ls -d /usr/lib/tcl8.5 2>/dev/null` \
			`ls -d /usr/local/lib/tcl9.1 2>/dev/null` \
			`ls -d /usr/local/lib/tcl9.0 2>/dev/null` \
			`ls -d /usr/local/lib/tcl8.6 2>/dev/null` \
			`ls -d /usr/local/lib/tcl8.5 2>/dev/null` \
			`ls -d /usr/local/lib/tcl/tcl9.1 2>/dev/null` \
			`ls -d /usr/local/lib/tcl/tcl9.0 2>/dev/null` \
			`ls -d /usr/local/lib/tcl/tcl8.6 2>/dev/null` \
			`ls -d /usr/local/lib/tcl/tcl8.5 2>/dev/null` \
			; do
		    if test -f "$i/tclConfig.sh" ; then
			ac_cv_c_tclconfig="`(cd $i; pwd)`"
			break
		    fi
2512
2513
2514
2515
2516
2517
2518
2519


2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530


2531
2532














2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547







2548
2549
2550
2551
2552
2553

2554




2555
2556

2557
2558

2559
2560
2561
2562
2563
2564
2565


2566
2567
2568
2569
2570


2571
2572
2573


2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587







2588
2589
2590
2591
2592
2593

2594




2595
2596

2597
2598

2599
2600
2601
2602
2603
2604
2605


2606
2607
2608
2609
2610


2611
2612
2613


2614
2615
2616
2617
2618
2619
2620
2621
2622


2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640







2641
2642
2643
2644
2645
2646

2647




2648
2649

2650
2651

2652
2653
2654
2655
2656
2657
2658


2659
2660
2661
2662
2663


2664
2665
2666


2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680







2681
2682
2683
2684
2685
2686
2687

2688




2689
2690
2691


2692
2693
2694
2695
2696

2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712

2713
2714
2715


2716
2717
2718
2719
2720


2721
2722
2723


2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739







2740
2741
2742
2743
2744
2745

2746




2747
2748

2749
2750

2751
2752
2753
2754
2755
2756
2757


2758
2759
2760
2761
2762


2763
2764
2765


2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783







2784
2785
2786
2787
2788
2789

2790




2791
2792

2793
2794

2795
2796
2797
2798
2799
2800
2801


2802
2803
2804
2805
2806


2807
2808
2809


2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822


2823
2824
2825
2826










































































































2827
2828
2829
2830
2831
2832
2833


2834
2835

2836
2837
2838

2839
2840
2841

2842
2843
2844
2845
2846
2847
2848

2849
2850
2851
2852
2853
2854
2855
2856
2857
2858

2859
2860
2861
2862
2863
2864
2865
2866

2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880



2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901

2902
2903
2904
2905
2906
2907





2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922

2923
2924
2925
2926
2927

2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939



2940
2941
2942
2943
2944





2945
2946
2947
2948


2949
2950
2951
2952
2953





2954
2955
2956
2957
2958




2959
2960
2961
2962
2963
2964


2965
2966
2967
2968
2969
2970
2971

2972
2973
2974
2975
2976
2977
2978
2979







2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991



2992
2993


2994
2995
2996
2997


2998
2999
3000
3001
3002
3003
3004
3005
3006

3007
3008


3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019


3020
3021
3022
3023
3024
3025
3026
3027

3028
3029
3030

3031
3032
3033
3034
3035
3036
3037
3038

3039
3040
3041

3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052





3053
3054
3055
3056
3057


3058
3059


3060
3061
3062
3063
3064
3065
3066







3067
3068
3069
3070

3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084

3085
3086
3087
3088



3089
3090
3091
3092
3093
3094
3095
3096
3097
3098


3099
3100
3101
3102


3103
3104


3105
3106


3107
3108
3109


3110
3111
3112
3113
3114
3115
3116
3117







3118
3119
3120
3121

3122
3123
3124
3125
3126
3127
3128
3129
3130
3131


3132
3133
3134



3135
3136

3137
3138


3139
3140
3141




3142
3143
3144
3145
3146
3147

3148
3149
3150
3151
3152
3153
3154







3155
3156
3157
3158
3159
3160
3161
3162

3163
3164
3165
3166
3167
3168
3169


3170
3171
3172


3173
3174
3175
3176
3177

3178
3179
3180
3181
3182
3183
3184


3185
3186
3187


3188
3189
3190
3191
3192
3193

3194
3195
3196
3197
3198
3199
3200


3201
3202
3203


3204
3205


3206
3207
3208



3209
3210
3211
3212



3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226



3227
3228
3229
3230
3231
3232









































































































3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257

3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286

3287
3288
3289
3290


3291
3292
3293

3294
3295
3296
3297
3298


3299
3300
3301


3302
3303
3304
3305
3306
3307



3308
3309
3310
3311









3312

3313
3314




3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326


3327
3328
3329
3330


3331
3332
3333
3334


3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346



3347
3348
3349
3350
3351
3352
3353
2814
2815
2816
2817
2818
2819
2820

2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831


2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858






2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872

2873
2874
2875
2876
2877

2878
2879

2880
2881
2882
2883
2884
2885
2886

2887
2888
2889
2890
2891


2892
2893
2894


2895
2896
2897
2898
2899
2900
2901
2902
2903
2904






2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918

2919
2920
2921
2922
2923

2924
2925

2926
2927
2928
2929
2930
2931
2932

2933
2934
2935
2936
2937


2938
2939
2940


2941
2942
2943
2944
2945
2946
2947
2948
2949


2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963






2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977

2978
2979
2980
2981
2982

2983
2984

2985
2986
2987
2988
2989
2990
2991

2992
2993
2994
2995
2996


2997
2998
2999


3000
3001
3002
3003
3004
3005
3006
3007
3008
3009






3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024

3025
3026
3027
3028
3029


3030
3031
3032
3033
3034
3035

3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051

3052
3053
3054

3055
3056
3057
3058
3059


3060
3061
3062


3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074






3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088

3089
3090
3091
3092
3093

3094
3095

3096
3097
3098
3099
3100
3101
3102

3103
3104
3105
3106
3107


3108
3109
3110


3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124






3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138

3139
3140
3141
3142
3143

3144
3145

3146
3147
3148
3149
3150
3151
3152

3153
3154
3155
3156
3157


3158
3159
3160


3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173


3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290


3291
3292
3293

3294
3295
3296

3297
3298
3299

3300
3301
3302
3303
3304
3305
3306

3307
3308
3309
3310
3311
3312
3313
3314
3315
3316

3317
3318
3319
3320
3321
3322
3323
3324

3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336



3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359

3360
3361
3362




3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381

3382
3383
3384
3385
3386

3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397


3398
3399
3400
3401




3402
3403
3404
3405
3406
3407
3408


3409
3410
3411




3412
3413
3414
3415
3416
3417




3418
3419
3420
3421
3422
3423
3424
3425


3426
3427
3428
3429
3430
3431
3432
3433

3434
3435
3436






3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452



3453
3454
3455
3456

3457
3458
3459
3460


3461
3462
3463
3464
3465
3466
3467
3468
3469
3470

3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484


3485
3486
3487
3488
3489
3490
3491
3492
3493

3494
3495
3496

3497
3498
3499
3500
3501
3502
3503
3504

3505
3506
3507

3508
3509
3510
3511
3512
3513
3514





3515
3516
3517
3518
3519
3520
3521
3522


3523
3524
3525

3526
3527
3528






3529
3530
3531
3532
3533
3534
3535
3536
3537
3538

3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552

3553
3554
3555


3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566


3567
3568
3569
3570


3571
3572
3573

3574
3575
3576

3577
3578
3579


3580
3581
3582
3583






3584
3585
3586
3587
3588
3589
3590
3591
3592
3593

3594
3595
3596
3597
3598
3599
3600
3601
3602
3603

3604
3605
3606


3607
3608
3609
3610

3611
3612

3613
3614
3615


3616
3617
3618
3619
3620
3621
3622
3623
3624

3625
3626






3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640

3641
3642
3643
3644
3645
3646
3647

3648
3649
3650


3651
3652
3653
3654
3655
3656

3657
3658
3659
3660
3661
3662
3663

3664
3665
3666


3667
3668
3669
3670
3671
3672
3673

3674
3675
3676
3677
3678
3679
3680

3681
3682
3683
3684

3685
3686
3687

3688
3689
3690


3691
3692
3693
3694



3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714






3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822






















3823



























3824

3825

3826
3827

3828
3829
3830
3831

3832
3833
3834
3835


3836
3837
3838


3839
3840






3841
3842
3843




3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854


3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868


3869
3870
3871
3872


3873
3874
3875
3876


3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887



3888
3889
3890
3891
3892
3893
3894
3895
3896
3897







-
+
+









-
-
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+








-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+







-
-
+
+












-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+








-
-
-
-
-
-
+
+
+
+
+
+
+







+
-
+
+
+
+

-
-
+
+




-
+















-
+


-
+
+



-
-
+
+

-
-
+
+










-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+












-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+











-
-
+
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
+
+

-
+


-
+


-
+






-
+









-
+







-
+











-
-
-
+
+
+




















-
+


-
-
-
-
+
+
+
+
+














-
+




-
+










-
-
+
+
+

-
-
-
-
+
+
+
+
+


-
-
+
+

-
-
-
-
+
+
+
+
+

-
-
-
-
+
+
+
+




-
-
+
+






-
+


-
-
-
-
-
-
+
+
+
+
+
+
+









-
-
-
+
+
+

-
+
+


-
-
+
+








-
+


+
+









-
-
+
+







-
+


-
+







-
+


-
+






-
-
-
-
-
+
+
+
+
+



-
-
+
+

-
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+



-
+













-
+


-
-
+
+
+








-
-
+
+


-
-
+
+

-
+
+

-
+
+

-
-
+
+


-
-
-
-
-
-
+
+
+
+
+
+
+



-
+









-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
+
+
+
+





-
+

-
-
-
-
-
-
+
+
+
+
+
+
+







-
+






-
+
+

-
-
+
+




-
+






-
+
+

-
-
+
+





-
+






-
+
+


-
+
+

-
+
+

-
-
+
+
+

-
-
-
+
+
+














+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-


-
+
+


-
+



-
-
+
+

-
-
+
+
-
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+

+
-
-
+
+
+
+










-
-
+
+


-
-
+
+


-
-
+
+









-
-
-
+
+
+







		    fi
		    if test -f "$i/unix/tclConfig.sh" ; then
			ac_cv_c_tclconfig="`(cd $i/unix; pwd)`"
			break
		    fi
		done
	    fi

	 ;;
esac
fi


	if test x"${ac_cv_c_tclconfig}" = x ; then
	    TCL_BIN_DIR="# no Tcl configs found"
	    as_fn_error $? "Can't find Tcl configuration definitions. Use --with-tcl to specify a directory containing tclConfig.sh" "$LINENO" 5
	else
	    no_tcl=
	    TCL_BIN_DIR="${ac_cv_c_tclconfig}"
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: found ${TCL_BIN_DIR}/tclConfig.sh" >&5
$as_echo "found ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found ${TCL_BIN_DIR}/tclConfig.sh" >&5
printf "%s\n" "found ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
	fi
    fi

if test x"${with_tcl8}" != x; then
with_tcl8=""
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: --with-tcl8 option ignored" >&5
printf "%s\n" "$as_me: WARNING: --with-tcl8 option ignored" >&2;}
fi









ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
set dummy ${ac_tool_prefix}gcc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}gcc"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_CC"; then
  ac_ct_CC=$CC
  # Extract the first word of "gcc", so it can be a program name with args.
set dummy gcc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="gcc"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
$as_echo "$ac_ct_CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
else
  CC="$ac_cv_prog_CC"
fi

if test -z "$CC"; then
          if test -n "$ac_tool_prefix"; then
    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
set dummy ${ac_tool_prefix}cc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}cc"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


  fi
fi
if test -z "$CC"; then
  # Extract the first word of "cc", so it can be a program name with args.
set dummy cc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
  ac_prog_rejected=no
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    if test "$as_dir$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
       ac_prog_rejected=yes
       continue
     fi
    ac_cv_prog_CC="cc"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

if test $ac_prog_rejected = yes; then
  # We found a bogon in the path, so make sure we never use it.
  set dummy $ac_cv_prog_CC
  shift
  if test $# != 0; then
    # We chose a different compiler from the bogus one.
    # However, it has the same basename, so the bogon will be chosen
    # first if we set CC to just the basename; use the full file name.
    shift
    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
    ac_cv_prog_CC="$as_dir$ac_word${1+' '}$@"
  fi
fi
fi
fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$CC"; then
  if test -n "$ac_tool_prefix"; then
  for ac_prog in cl.exe
  do
    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
set dummy $ac_tool_prefix$ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


    test -n "$CC" && break
  done
fi
if test -z "$CC"; then
  ac_ct_CC=$CC
  for ac_prog in cl.exe
do
  # Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="$ac_prog"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
$as_echo "$ac_ct_CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


  test -n "$ac_ct_CC" && break
done

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
fi

fi
if test -z "$CC"; then
  if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args.
set dummy ${ac_tool_prefix}clang; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}clang"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_CC"; then
  ac_ct_CC=$CC
  # Extract the first word of "clang", so it can be a program name with args.
set dummy clang; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="clang"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
else
  CC="$ac_cv_prog_CC"
fi

fi


test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error $? "no acceptable C compiler found in \$PATH
See \`config.log' for more details" "$LINENO" 5; }
See 'config.log' for more details" "$LINENO" 5; }

# Provide some information about the compiler.
$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
set X $ac_compile
ac_compiler=$2
for ac_option in --version -v -V -qversion; do
for ac_option in --version -v -V -qversion -version; do
  { { ac_try="$ac_compiler $ac_option >&5"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    sed '10a\
... rest of stderr output deleted ...
         10q' conftest.err >conftest.er1
    cat conftest.er1 >&5
  fi
  rm -f conftest.er1 conftest.err
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
done

cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
ac_clean_files_save=$ac_clean_files
ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out"
# Try to create an executable without -o first, disregard a.out.
# It will help us diagnose broken compilers, and finding out an intuition
# of exeext.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
$as_echo_n "checking whether the C compiler works... " >&6; }
ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5
printf %s "checking whether the C compiler works... " >&6; }
ac_link_default=`printf "%s\n" "$ac_link" | sed 's/ -o *conftest[^ ]*//'`

# The possible output files:
ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*"

ac_rmfiles=
for ac_file in $ac_files
do
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
    * ) ac_rmfiles="$ac_rmfiles $ac_file";;
  esac
done
rm -f $ac_rmfiles

if { { ac_try="$ac_link_default"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_link_default") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; then :
  # Autoconf-2.13 could set the ac_cv_exeext variable to `no'.
# So ignore a value of `no', otherwise this would lead to `EXEEXT = no'
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
then :
  # Autoconf-2.13 could set the ac_cv_exeext variable to 'no'.
# So ignore a value of 'no', otherwise this would lead to 'EXEEXT = no'
# in a Makefile.  We should not override ac_cv_exeext if it was cached,
# so that the user can short-circuit this test for compilers unknown to
# Autoconf.
for ac_file in $ac_files ''
do
  test -f "$ac_file" || continue
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj )
	;;
    [ab].out )
	# We found the default executable, but exeext='' is most
	# certainly right.
	break;;
    *.* )
	if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no;
	if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no;
	then :; else
	   ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
	fi
	# We set ac_cv_exeext here because the later test for it is not
	# safe: cross compilers may not add the suffix if given an `-o'
	# safe: cross compilers may not add the suffix if given an '-o'
	# argument, so we may need to know it at that point already.
	# Even if this section looks crufty: it has the advantage of
	# actually working.
	break;;
    * )
	break;;
  esac
done
test "$ac_cv_exeext" = no && ac_cv_exeext=

else
  ac_file=''
else case e in #(
  e) ac_file='' ;;
esac
fi
if test -z "$ac_file"; then :
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
$as_echo "$as_me: failed program was:" >&5
if test -z "$ac_file"
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
printf "%s\n" "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error 77 "C compiler cannot create executables
See \`config.log' for more details" "$LINENO" 5; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
See 'config.log' for more details" "$LINENO" 5; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; } ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
$as_echo_n "checking for C compiler default output file name... " >&6; }
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
$as_echo "$ac_file" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5
printf %s "checking for C compiler default output file name... " >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5
printf "%s\n" "$ac_file" >&6; }
ac_exeext=$ac_cv_exeext

rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out
ac_clean_files=$ac_clean_files_save
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
$as_echo_n "checking for suffix of executables... " >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5
printf %s "checking for suffix of executables... " >&6; }
if { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; then :
  # If both `conftest.exe' and `conftest' are `present' (well, observable)
# catch `conftest.exe'.  For instance with Cygwin, `ls conftest' will
# work properly (i.e., refer to `conftest.exe'), while it won't with
# `rm'.
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
then :
  # If both 'conftest.exe' and 'conftest' are 'present' (well, observable)
# catch 'conftest.exe'.  For instance with Cygwin, 'ls conftest' will
# work properly (i.e., refer to 'conftest.exe'), while it won't with
# 'rm'.
for ac_file in conftest.exe conftest conftest.*; do
  test -f "$ac_file" || continue
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;;
    *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
	  break;;
    * ) break;;
  esac
done
else
  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
else case e in #(
  e) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error $? "cannot compute suffix of executables: cannot compile and link
See \`config.log' for more details" "$LINENO" 5; }
See 'config.log' for more details" "$LINENO" 5; } ;;
esac
fi
rm -f conftest conftest$ac_cv_exeext
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
$as_echo "$ac_cv_exeext" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5
printf "%s\n" "$ac_cv_exeext" >&6; }

rm -f conftest.$ac_ext
EXEEXT=$ac_cv_exeext
ac_exeext=$EXEEXT
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdio.h>
int
main ()
main (void)
{
FILE *f = fopen ("conftest.out", "w");
 if (!f)
  return 1;
 return ferror (f) || fclose (f) != 0;

  ;
  return 0;
}
_ACEOF
ac_clean_files="$ac_clean_files conftest.out"
# Check that the compiler produces executables we can run.  If not, either
# the compiler is broken, or we cross compile.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
$as_echo_n "checking whether we are cross compiling... " >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5
printf %s "checking whether we are cross compiling... " >&6; }
if test "$cross_compiling" != yes; then
  { { ac_try="$ac_link"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_link") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
  if { ac_try='./conftest$ac_cv_exeext'
  { { case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_try") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; }; then
    cross_compiling=no
  else
    if test "$cross_compiling" = maybe; then
	cross_compiling=yes
    else
	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot run C compiled programs.
If you meant to cross compile, use \`--host'.
See \`config.log' for more details" "$LINENO" 5; }
	{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error 77 "cannot run C compiled programs.
If you meant to cross compile, use '--host'.
See 'config.log' for more details" "$LINENO" 5; }
    fi
  fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
$as_echo "$cross_compiling" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5
printf "%s\n" "$cross_compiling" >&6; }

rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out
rm -f conftest.$ac_ext conftest$ac_cv_exeext \
  conftest.o conftest.obj conftest.out
ac_clean_files=$ac_clean_files_save
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
$as_echo_n "checking for suffix of object files... " >&6; }
if ${ac_cv_objext+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5
printf %s "checking for suffix of object files... " >&6; }
if test ${ac_cv_objext+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
rm -f conftest.o conftest.obj
if { { ac_try="$ac_compile"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_compile") 2>&5
  ac_status=$?
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }; then :
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
then :
  for ac_file in conftest.o conftest.obj conftest.*; do
  test -f "$ac_file" || continue;
  case $ac_file in
    *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;;
    *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
       break;;
  esac
done
else
  $as_echo "$as_me: failed program was:" >&5
else case e in #(
  e) printf "%s\n" "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5

{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error $? "cannot compute suffix of object files: cannot compile
See \`config.log' for more details" "$LINENO" 5; }
See 'config.log' for more details" "$LINENO" 5; } ;;
esac
fi
rm -f conftest.$ac_cv_objext conftest.$ac_ext
rm -f conftest.$ac_cv_objext conftest.$ac_ext ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
$as_echo "$ac_cv_objext" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5
printf "%s\n" "$ac_cv_objext" >&6; }
OBJEXT=$ac_cv_objext
ac_objext=$OBJEXT
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
if ${ac_cv_c_compiler_gnu+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5
printf %s "checking whether the compiler supports GNU C... " >&6; }
if test ${ac_cv_c_compiler_gnu+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{
#ifndef __GNUC__
       choke me
#endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  ac_compiler_gnu=yes
else
  ac_compiler_gnu=no
else case e in #(
  e) ac_compiler_gnu=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
ac_cv_c_compiler_gnu=$ac_compiler_gnu

 ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
$as_echo "$ac_cv_c_compiler_gnu" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; }
ac_compiler_gnu=$ac_cv_c_compiler_gnu

if test $ac_compiler_gnu = yes; then
  GCC=yes
else
  GCC=
fi
ac_test_CFLAGS=${CFLAGS+set}
ac_test_CFLAGS=${CFLAGS+y}
ac_save_CFLAGS=$CFLAGS
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
$as_echo_n "checking whether $CC accepts -g... " >&6; }
if ${ac_cv_prog_cc_g+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_save_c_werror_flag=$ac_c_werror_flag
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
printf %s "checking whether $CC accepts -g... " >&6; }
if test ${ac_cv_prog_cc_g+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_save_c_werror_flag=$ac_c_werror_flag
   ac_c_werror_flag=yes
   ac_cv_prog_cc_g=no
   CFLAGS="-g"
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_g=yes
else
  CFLAGS=""
else case e in #(
  e) CFLAGS=""
      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :

else
  ac_c_werror_flag=$ac_save_c_werror_flag
else case e in #(
  e) ac_c_werror_flag=$ac_save_c_werror_flag
	 CFLAGS="-g"
	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_g=yes
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   ac_c_werror_flag=$ac_save_c_werror_flag
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
   ac_c_werror_flag=$ac_save_c_werror_flag ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
$as_echo "$ac_cv_prog_cc_g" >&6; }
if test "$ac_test_CFLAGS" = set; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
printf "%s\n" "$ac_cv_prog_cc_g" >&6; }
if test $ac_test_CFLAGS; then
  CFLAGS=$ac_save_CFLAGS
elif test $ac_cv_prog_cc_g = yes; then
  if test "$GCC" = yes; then
    CFLAGS="-g -O2"
  else
    CFLAGS="-g"
  fi
else
  if test "$GCC" = yes; then
    CFLAGS="-O2"
  else
    CFLAGS=
  fi
fi
ac_prog_cc_stdc=no
if test x$ac_prog_cc_stdc = xno
then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
if ${ac_cv_prog_cc_c89+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_cv_prog_cc_c89=no
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5
printf %s "checking for $CC option to enable C11 features... " >&6; }
if test ${ac_cv_prog_cc_c11+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_prog_cc_c11=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_c_conftest_c11_program
_ACEOF
for ac_arg in '' -std=gnu11
do
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_c11=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c11" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC ;;
esac
fi

if test "x$ac_cv_prog_cc_c11" = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
else case e in #(
  e) if test "x$ac_cv_prog_cc_c11" = x
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5
printf "%s\n" "$ac_cv_prog_cc_c11" >&6; }
     CC="$CC $ac_cv_prog_cc_c11" ;;
esac
fi
  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11
  ac_prog_cc_stdc=c11 ;;
esac
fi
fi
if test x$ac_prog_cc_stdc = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5
printf %s "checking for $CC option to enable C99 features... " >&6; }
if test ${ac_cv_prog_cc_c99+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_prog_cc_c99=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_c_conftest_c99_program
_ACEOF
for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99=
do
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_c99=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c99" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC ;;
esac
fi

if test "x$ac_cv_prog_cc_c99" = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
else case e in #(
  e) if test "x$ac_cv_prog_cc_c99" = x
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5
printf "%s\n" "$ac_cv_prog_cc_c99" >&6; }
     CC="$CC $ac_cv_prog_cc_c99" ;;
esac
fi
  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99
  ac_prog_cc_stdc=c99 ;;
esac
fi
fi
if test x$ac_prog_cc_stdc = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5
printf %s "checking for $CC option to enable C89 features... " >&6; }
if test ${ac_cv_prog_cc_c89+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_prog_cc_c89=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdarg.h>
#include <stdio.h>
struct stat;
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (p, i)
     char **p;
     int i;
{
  return p[i];
}
static char *f (char * (*g) (char **, int), char **p, ...)
{
  char *s;
  va_list v;
  va_start (v,p);
  s = g (p, va_arg (v,int));
  va_end (v);
  return s;
}

$ac_c_conftest_c89_program
/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
   function prototypes and stuff, but not '\xHH' hex character constants.
   These don't provoke an error unfortunately, instead are silently treated
   as 'x'.  The following induces an error, until -std is added to get
   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
   array size at least.  It's necessary to write '\x00'==0 to get something
   that's true only with -std.  */
int osf4_cc_array ['\x00' == 0 ? 1 : -1];

/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
   inside strings and character constants.  */
#define FOO(x) 'x'
int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];

int test (int i, double x);
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
int argc;
char **argv;
int
main ()
{
return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
  ;
  return 0;
}
_ACEOF
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
do
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"; then :
  if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_c89=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c89" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC

CC=$ac_save_CC ;;
esac
fi
# AC_CACHE_VAL
case "x$ac_cv_prog_cc_c89" in

if test "x$ac_cv_prog_cc_c89" = xno
  x)
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
$as_echo "none needed" >&6; } ;;
  xno)
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
$as_echo "unsupported" >&6; } ;;
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
  *)
    CC="$CC $ac_cv_prog_cc_c89"
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
else case e in #(
  e) if test "x$ac_cv_prog_cc_c89" = x
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
printf "%s\n" "$ac_cv_prog_cc_c89" >&6; }
     CC="$CC $ac_cv_prog_cc_c89" ;;
esac
fi
if test "x$ac_cv_prog_cc_c89" != xno; then :

  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89
  ac_prog_cc_stdc=c89 ;;
esac
fi
fi

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu



    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for existence of ${TCL_BIN_DIR}/tclConfig.sh" >&5
$as_echo_n "checking for existence of ${TCL_BIN_DIR}/tclConfig.sh... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for existence of ${TCL_BIN_DIR}/tclConfig.sh" >&5
printf %s "checking for existence of ${TCL_BIN_DIR}/tclConfig.sh... " >&6; }

    if test -f "${TCL_BIN_DIR}/tclConfig.sh" ; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: loading" >&5
$as_echo "loading" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: loading" >&5
printf "%s\n" "loading" >&6; }
	. "${TCL_BIN_DIR}/tclConfig.sh"
    else
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: could not find ${TCL_BIN_DIR}/tclConfig.sh" >&5
$as_echo "could not find ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: could not find ${TCL_BIN_DIR}/tclConfig.sh" >&5
printf "%s\n" "could not find ${TCL_BIN_DIR}/tclConfig.sh" >&6; }
    fi

    # If the TCL_BIN_DIR is the build directory (not the install directory),
    # then set the common variable name to the value of the build variables.
    # For example, the variable TCL_LIB_SPEC will be set to the value
    # of TCL_BUILD_LIB_SPEC. An extension should make use of TCL_LIB_SPEC
    # instead of TCL_BUILD_LIB_SPEC since it will work with both an
    # installed and uninstalled version of Tcl.
    if test -f "${TCL_BIN_DIR}/Makefile" ; then
        TCL_LIB_SPEC="${TCL_BUILD_LIB_SPEC}"
        TCL_STUB_LIB_SPEC="${TCL_BUILD_STUB_LIB_SPEC}"
        TCL_STUB_LIB_PATH="${TCL_BUILD_STUB_LIB_PATH}"
	TCL_LIB_SPEC="${TCL_BUILD_LIB_SPEC}"
	TCL_STUB_LIB_SPEC="${TCL_BUILD_STUB_LIB_SPEC}"
	TCL_STUB_LIB_PATH="${TCL_BUILD_STUB_LIB_PATH}"
    elif test "`uname -s`" = "Darwin"; then
	# If Tcl was built as a framework, attempt to use the libraries
	# from the framework at the given location so that linking works
	# against Tcl.framework installed in an arbitrary location.
	case ${TCL_DEFS} in
	    *TCL_FRAMEWORK*)
		if test -f "${TCL_BIN_DIR}/${TCL_LIB_FILE}"; then
3376
3377
3378
3379
3380
3381
3382
3383
3384


3385
3386
3387
3388
3389
3390

3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401


3402
3403
3404
3405
3406
3407
3408


3409
3410
3411
3412
3413
3414
3415
3416
3417







3418
3419
3420
3421
3422
3423

3424




3425
3426

3427
3428

3429
3430
3431
3432
3433
3434
3435
3436


3437
3438
3439
3440
3441


3442
3443
3444


3445
3446
3447
3448


3449
3450

3451
3452
3453


3454
3455
3456
3457
3458
3459

3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477

3478
3479

3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501


3502
3503
3504
3505


3506
3507
3508
3509
3510
3511
3512
3513


3514
3515
3516
3517


3518
3519
3520
3521
3522
3523
3524
3920
3921
3922
3923
3924
3925
3926


3927
3928
3929
3930
3931
3932
3933

3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944

3945
3946
3947
3948
3949
3950
3951


3952
3953
3954
3955
3956






3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970

3971
3972
3973
3974
3975

3976
3977

3978
3979
3980
3981
3982
3983
3984
3985

3986
3987
3988
3989
3990


3991
3992
3993


3994
3995
3996
3997
3998

3999
4000
4001

4002
4003


4004
4005
4006
4007
4008
4009


4010

4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026

4027


4028
4029

4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047


4048
4049
4050
4051


4052
4053
4054
4055
4056
4057
4058
4059


4060
4061
4062
4063


4064
4065
4066
4067
4068
4069
4070
4071
4072







-
-
+
+





-
+










-
+
+





-
-
+
+



-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+







-
+
+



-
-
+
+

-
-
+
+



-
+
+

-
+

-
-
+
+




-
-
+
-
















-
+
-
-
+

-


















-
-
+
+


-
-
+
+






-
-
+
+


-
-
+
+














    { $as_echo "$as_me:${as_lineno-$LINENO}: checking platform" >&5
$as_echo_n "checking platform... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking platform" >&5
printf %s "checking platform... " >&6; }
    hold_cc=$CC; CC="$TCL_CC"
    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

	    #ifdef _WIN32
		#error win32
	    #endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :

	    # first test we've already retrieved platform (cross-compile), fallback to unix otherwise:
	    TEA_PLATFORM="${TEA_PLATFORM-unix}"
	    CYGPATH=echo

else

else case e in #(
  e)
	    TEA_PLATFORM="windows"
	    # Extract the first word of "cygpath", so it can be a program name with args.
set dummy cygpath; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CYGPATH+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$CYGPATH"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CYGPATH+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CYGPATH"; then
  ac_cv_prog_CYGPATH="$CYGPATH" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CYGPATH="cygpath -m"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

  test -z "$ac_cv_prog_CYGPATH" && ac_cv_prog_CYGPATH="echo"
fi
fi ;;
esac
fi
CYGPATH=$ac_cv_prog_CYGPATH
if test -n "$CYGPATH"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CYGPATH" >&5
$as_echo "$CYGPATH" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CYGPATH" >&5
printf "%s\n" "$CYGPATH" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi



     ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
    CC=$hold_cc
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $TEA_PLATFORM" >&5
$as_echo "$TEA_PLATFORM" >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $TEA_PLATFORM" >&5
printf "%s\n" "$TEA_PLATFORM" >&6; }

    # The BUILD_$pkg is to define the correct extern storage class
    # handling when making this package

cat >>confdefs.h <<_ACEOF
#define BUILD_${PACKAGE_NAME} /**/
printf "%s\n" "#define BUILD_${PACKAGE_NAME} /**/" >>confdefs.h
_ACEOF

    # Do this here as we have fully defined TEA_PLATFORM now
    if test "${TEA_PLATFORM}" = "windows" ; then
	EXEEXT=".exe"
	CLEANFILES="$CLEANFILES *.lib *.dll *.pdb *.exp"
    fi

    # TEA specific:








if test "${TCL_MAJOR_VERSION}" -eq 8 ; then
if test "${TCL_MAJOR_VERSION}" -eq 8; then
    if test "${TCL_MINOR_VERSION}" -lt 7 ; then
        as_fn_error $? "${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 9.0+
    as_fn_error $? "${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 9.0+
Found config for Tcl ${TCL_VERSION}" "$LINENO" 5
fi
fi

#--------------------------------------------------------------------
# Load the tkConfig.sh file if necessary (Tk extension)
#--------------------------------------------------------------------

#TEA_PATH_TKCONFIG
#TEA_LOAD_TKCONFIG

#-----------------------------------------------------------------------
# Handle the --prefix=... option by defaulting to what Tcl gave.
# Must be called after TEA_LOAD_TCLCONFIG and before TEA_SETUP_COMPILER.
#-----------------------------------------------------------------------


    if test "${prefix}" = "NONE"; then
	prefix_default=yes
	if test x"${TCL_PREFIX}" != x; then
	    { $as_echo "$as_me:${as_lineno-$LINENO}: --prefix defaulting to TCL_PREFIX ${TCL_PREFIX}" >&5
$as_echo "$as_me: --prefix defaulting to TCL_PREFIX ${TCL_PREFIX}" >&6;}
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: --prefix defaulting to TCL_PREFIX ${TCL_PREFIX}" >&5
printf "%s\n" "$as_me: --prefix defaulting to TCL_PREFIX ${TCL_PREFIX}" >&6;}
	    prefix=${TCL_PREFIX}
	else
	    { $as_echo "$as_me:${as_lineno-$LINENO}: --prefix defaulting to /usr/local" >&5
$as_echo "$as_me: --prefix defaulting to /usr/local" >&6;}
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: --prefix defaulting to /usr/local" >&5
printf "%s\n" "$as_me: --prefix defaulting to /usr/local" >&6;}
	    prefix=/usr/local
	fi
    fi
    if test "${exec_prefix}" = "NONE" -a x"${prefix_default}" = x"yes" \
	-o x"${exec_prefix_default}" = x"yes" ; then
	if test x"${TCL_EXEC_PREFIX}" != x; then
	    { $as_echo "$as_me:${as_lineno-$LINENO}: --exec-prefix defaulting to TCL_EXEC_PREFIX ${TCL_EXEC_PREFIX}" >&5
$as_echo "$as_me: --exec-prefix defaulting to TCL_EXEC_PREFIX ${TCL_EXEC_PREFIX}" >&6;}
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: --exec-prefix defaulting to TCL_EXEC_PREFIX ${TCL_EXEC_PREFIX}" >&5
printf "%s\n" "$as_me: --exec-prefix defaulting to TCL_EXEC_PREFIX ${TCL_EXEC_PREFIX}" >&6;}
	    exec_prefix=${TCL_EXEC_PREFIX}
	else
	    { $as_echo "$as_me:${as_lineno-$LINENO}: --exec-prefix defaulting to ${prefix}" >&5
$as_echo "$as_me: --exec-prefix defaulting to ${prefix}" >&6;}
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: --exec-prefix defaulting to ${prefix}" >&5
printf "%s\n" "$as_me: --exec-prefix defaulting to ${prefix}" >&6;}
	    exec_prefix=$prefix
	fi
    fi


#-----------------------------------------------------------------------
# Standard compiler checks.
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547







3548
3549
3550
3551
3552
3553

3554




3555
3556

3557
3558

3559
3560
3561
3562
3563
3564
3565


3566
3567
3568
3569
3570


3571
3572
3573


3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587







3588
3589
3590
3591
3592
3593

3594




3595
3596

3597
3598

3599
3600
3601
3602
3603
3604
3605


3606
3607
3608
3609
3610


3611
3612
3613


3614
3615
3616
3617
3618
3619
3620
3621
3622


3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640







3641
3642
3643
3644
3645
3646

3647




3648
3649

3650
3651

3652
3653
3654
3655
3656
3657
3658


3659
3660
3661
3662
3663


3664
3665
3666


3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680







3681
3682
3683
3684
3685
3686
3687

3688




3689
3690
3691


3692
3693
3694
3695
3696

3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712

3713
3714
3715


3716
3717
3718
3719
3720


3721
3722
3723


3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739







3740
3741
3742
3743
3744
3745

3746




3747
3748

3749
3750

3751
3752
3753
3754
3755
3756
3757


3758
3759
3760
3761
3762


3763
3764
3765


3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783







3784
3785
3786
3787
3788
3789

3790




3791
3792

3793
3794

3795
3796
3797
3798
3799
3800
3801


3802
3803
3804
3805
3806


3807
3808
3809


3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822


3823
3824
3825
3826










































































































3827
3828
3829
3830
3831
3832
3833


3834
3835

3836
3837
3838

3839
3840
3841

3842
3843
3844
3845
3846
3847
3848

3849
3850
3851
3852
3853
3854
3855
3856
3857
3858

3859
3860
3861
3862
3863
3864
3865
3866
3867







3868
3869
3870
3871

3872
3873
3874
3875
3876
3877
3878
3879
3880
3881


3882
3883
3884



3885
3886

3887
3888


3889
3890
3891




3892
3893
3894
3895
3896
3897

3898
3899
3900
3901
3902
3903
3904







3905
3906
3907
3908
3909
3910
3911
3912

3913
3914
3915
3916
3917
3918
3919


3920
3921
3922


3923
3924
3925
3926
3927

3928
3929
3930
3931
3932
3933
3934


3935
3936
3937


3938
3939
3940
3941
3942
3943

3944
3945
3946
3947
3948
3949
3950


3951
3952
3953


3954
3955


3956
3957
3958



3959
3960
3961
3962



3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976



3977
3978
3979
3980
3981
3982









































































































3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007

4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036

4037
4038
4039
4040


4041
4042
4043

4044
4045
4046
4047
4048


4049
4050
4051


4052
4053
4054
4055
4056
4057



4058
4059
4060
4061









4062

4063
4064




4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079


4080
4081
4082
4083
4084
4085
4086
4087
4088
4089






4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103

4104
4105
4106
4107
4108
4109


4110
4111
4112
4113




4114
4115
4116
4117
4118
4119
4120
4121
4122
4123


4124
4125
4126
4127


4128
4129


4130
4131
4132
4133
4134

4135
4136


4137
4138
4139
4140
4141
4142


4143
4144
4145
4146
4147
4148
4149


4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162

4163
4164
4165
4166
4167
4168


4169
4170
4171
4172




4173
4174
4175
4176
4177
4178
4179
4180
4181
4182


4183
4184
4185
4186


4187
4188


4189
4190
4191
4192
4193

4194
4195


4196
4197
4198
4199



4200
4201


4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216


4217
4218
4219
4220
4221
4222






4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234


4235
4236
4237
4238


4239
4240
4241
4242


4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259







4260
4261
4262
4263
4264
4265

4266




4267
4268

4269
4270

4271
4272
4273
4274
4275
4276
4277


4278
4279
4280
4281
4282


4283
4284
4285


4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299







4300
4301
4302
4303
4304
4305

4306




4307
4308

4309
4310

4311
4312
4313
4314
4315
4316
4317


4318
4319
4320
4321
4322


4323
4324
4325


4326
4327
4328
4329
4330
4331
4332
4333
4334


4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351

4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365

4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378

4379
4380
4381
4382
4383
4384
4385
4386

4387
4388
4389
4390
4391
4392
4393
4394
4395
4396

4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408

4409
4410
4411
4412
4413

4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462

4463
4464
4465
4466
4467
4468

4469
4470
4471


4472
4473
4474
4475


4476
4477
4478
4479
4480

4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496

4497
4498

4499
4500

4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546

4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578

4579
4580
4581
4582
4583

4584
4585
4586
4587
4588
4589
4590

4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626







4627
4628
4629
4630
4631
4632

4633
4634
4635
4636
4637
4638
4639


4640
4641
4642



4643
4644
4645



4646
4647
4648


4649
4650
4651
4652






4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663







4664
4665
4666
4667
4668
4669
4670
4671
4672
4673


4674
4675
4676
4677
4678
4679
4680
4083
4084
4085
4086
4087
4088
4089






4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103

4104
4105
4106
4107
4108

4109
4110

4111
4112
4113
4114
4115
4116
4117

4118
4119
4120
4121
4122


4123
4124
4125


4126
4127
4128
4129
4130
4131
4132
4133
4134
4135






4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149

4150
4151
4152
4153
4154

4155
4156

4157
4158
4159
4160
4161
4162
4163

4164
4165
4166
4167
4168


4169
4170
4171


4172
4173
4174
4175
4176
4177
4178
4179
4180


4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194






4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208

4209
4210
4211
4212
4213

4214
4215

4216
4217
4218
4219
4220
4221
4222

4223
4224
4225
4226
4227


4228
4229
4230


4231
4232
4233
4234
4235
4236
4237
4238
4239
4240






4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255

4256
4257
4258
4259
4260


4261
4262
4263
4264
4265
4266

4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282

4283
4284
4285

4286
4287
4288
4289
4290


4291
4292
4293


4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305






4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319

4320
4321
4322
4323
4324

4325
4326

4327
4328
4329
4330
4331
4332
4333

4334
4335
4336
4337
4338


4339
4340
4341


4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355






4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369

4370
4371
4372
4373
4374

4375
4376

4377
4378
4379
4380
4381
4382
4383

4384
4385
4386
4387
4388


4389
4390
4391


4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404


4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521


4522
4523
4524

4525
4526
4527

4528
4529
4530

4531
4532
4533
4534
4535
4536
4537

4538
4539
4540
4541
4542
4543
4544
4545
4546
4547

4548
4549
4550
4551






4552
4553
4554
4555
4556
4557
4558
4559
4560
4561

4562
4563
4564
4565
4566
4567
4568
4569
4570
4571

4572
4573
4574


4575
4576
4577
4578

4579
4580

4581
4582
4583


4584
4585
4586
4587
4588
4589
4590
4591
4592

4593
4594






4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608

4609
4610
4611
4612
4613
4614
4615

4616
4617
4618


4619
4620
4621
4622
4623
4624

4625
4626
4627
4628
4629
4630
4631

4632
4633
4634


4635
4636
4637
4638
4639
4640
4641

4642
4643
4644
4645
4646
4647
4648

4649
4650
4651
4652

4653
4654
4655

4656
4657
4658


4659
4660
4661
4662



4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682






4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790






















4791



























4792

4793

4794
4795

4796
4797
4798
4799

4800
4801
4802
4803


4804
4805
4806


4807
4808






4809
4810
4811




4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822


4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839


4840
4841
4842
4843
4844
4845
4846





4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858


4859
4860
4861
4862


4863



4864
4865

4866
4867
4868



4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881

4882
4883
4884
4885


4886
4887
4888

4889
4890
4891
4892
4893
4894

4895
4896

4897
4898
4899
4900
4901
4902
4903

4904
4905
4906
4907
4908
4909
4910


4911
4912
4913
4914
4915
4916
4917


4918
4919
4920
4921


4922



4923
4924

4925
4926
4927



4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940

4941
4942
4943
4944


4945
4946
4947

4948
4949
4950
4951
4952
4953

4954
4955

4956
4957
4958



4959
4960
4961
4962

4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977


4978
4979
4980





4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997

4998
4999
5000
5001


5002
5003
5004
5005


5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018






5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032

5033
5034
5035
5036
5037

5038
5039

5040
5041
5042
5043
5044
5045
5046

5047
5048
5049
5050
5051


5052
5053
5054


5055
5056
5057
5058
5059
5060
5061
5062
5063
5064






5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078

5079
5080
5081
5082
5083

5084
5085

5086
5087
5088
5089
5090
5091
5092

5093
5094
5095
5096
5097


5098
5099
5100


5101
5102
5103
5104
5105
5106
5107
5108
5109


5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127

5128














5129













5130








5131










5132












5133





5134










































5135






5136






5137



5138
5139




5140
5141





5142
5143











5144



5145
5146

5147


5148







5149






































5150
































5151





5152





5153

5154
5155
5156


















5157
5158
5159
5160
5161
5162
5163
5164
5165
5166






5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178

5179
5180
5181
5182
5183
5184
5185

5186
5187
5188


5189
5190
5191
5192


5193
5194
5195
5196


5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213






5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229

5230
5231
5232
5233
5234
5235
5236
5237
5238







-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+








-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+







-
-
+
+












-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+








-
-
-
-
-
-
+
+
+
+
+
+
+







+
-
+
+
+
+

-
-
+
+




-
+















-
+


-
+
+



-
-
+
+

-
-
+
+










-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+












-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+











-
-
+
+




+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
+
+

-
+


-
+


-
+






-
+









-
+



-
-
-
-
-
-
+
+
+
+
+
+
+



-
+









-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
+
+
+
+





-
+

-
-
-
-
-
-
+
+
+
+
+
+
+







-
+






-
+
+

-
-
+
+




-
+






-
+
+

-
-
+
+





-
+






-
+
+


-
+
+

-
+
+

-
-
+
+
+

-
-
-
+
+
+














+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
+
-


-
+
+


-
+



-
-
+
+

-
-
+
+
-
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+

+
-
-
+
+
+
+













-
-
+
+





-
-
-
-
-
+
+
+
+
+
+






-
-




-
-
+
-
-
-


-
+
+

-
-
-
+
+
+
+









-
+
+


-
-
+
+

-
+
+




-
+

-
+
+





-
+
+





-
-
+
+





-
-




-
-
+
-
-
-


-
+
+

-
-
-
+
+
+
+









-
+
+


-
-
+
+

-
+
+




-
+

-
+
+

-
-
-
+
+
+

-
+
+













-
-
+
+

-
-
-
-
-
+
+
+
+
+
+











-
+
+


-
-
+
+


-
-
+
+











-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+








-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+







-
-
+
+
















-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

-
-
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
+
+
-
-
-
-
+
+
-
-
-
-
-
+

-
-
-
-
-
-
-
-
-
-
-

-
-
-
+

-
+
-
-
+
-
-
-
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-

-
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-










-
-
-
-
-
-
+
+
+
+
+
+
+





-
+






-
+
+

-
-
+
+
+

-
-
+
+
+

-
-
+
+




+
+
+
+
+
+





-
-
-
-
-
-
+
+
+
+
+
+
+









-
+
+







ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
set dummy ${ac_tool_prefix}gcc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}gcc"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_CC"; then
  ac_ct_CC=$CC
  # Extract the first word of "gcc", so it can be a program name with args.
set dummy gcc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="gcc"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
$as_echo "$ac_ct_CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
else
  CC="$ac_cv_prog_CC"
fi

if test -z "$CC"; then
          if test -n "$ac_tool_prefix"; then
    # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
set dummy ${ac_tool_prefix}cc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}cc"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


  fi
fi
if test -z "$CC"; then
  # Extract the first word of "cc", so it can be a program name with args.
set dummy cc; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
  ac_prog_rejected=no
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
    if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    if test "$as_dir$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
       ac_prog_rejected=yes
       continue
     fi
    ac_cv_prog_CC="cc"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

if test $ac_prog_rejected = yes; then
  # We found a bogon in the path, so make sure we never use it.
  set dummy $ac_cv_prog_CC
  shift
  if test $# != 0; then
    # We chose a different compiler from the bogus one.
    # However, it has the same basename, so the bogon will be chosen
    # first if we set CC to just the basename; use the full file name.
    shift
    ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
    ac_cv_prog_CC="$as_dir$ac_word${1+' '}$@"
  fi
fi
fi
fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$CC"; then
  if test -n "$ac_tool_prefix"; then
  for ac_prog in cl.exe
  do
    # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
set dummy $ac_tool_prefix$ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
$as_echo "$CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


    test -n "$CC" && break
  done
fi
if test -z "$CC"; then
  ac_ct_CC=$CC
  for ac_prog in cl.exe
do
  # Extract the first word of "$ac_prog", so it can be a program name with args.
set dummy $ac_prog; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_CC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_CC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="$ac_prog"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
$as_echo "$ac_ct_CC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


  test -n "$ac_ct_CC" && break
done

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
fi

fi
if test -z "$CC"; then
  if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args.
set dummy ${ac_tool_prefix}clang; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$CC"; then
  ac_cv_prog_CC="$CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_CC="${ac_tool_prefix}clang"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
esac
fi
CC=$ac_cv_prog_CC
if test -n "$CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5
printf "%s\n" "$CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_CC"; then
  ac_ct_CC=$CC
  # Extract the first word of "clang", so it can be a program name with args.
set dummy clang; ac_word=$2
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_CC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_CC"; then
  ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_CC="clang"
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi ;;
esac
fi
ac_ct_CC=$ac_cv_prog_ac_ct_CC
if test -n "$ac_ct_CC"; then
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5
printf "%s\n" "$ac_ct_CC" >&6; }
else
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

  if test "x$ac_ct_CC" = x; then
    CC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    CC=$ac_ct_CC
  fi
else
  CC="$ac_cv_prog_CC"
fi

fi


test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error $? "no acceptable C compiler found in \$PATH
See \`config.log' for more details" "$LINENO" 5; }
See 'config.log' for more details" "$LINENO" 5; }

# Provide some information about the compiler.
$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5
set X $ac_compile
ac_compiler=$2
for ac_option in --version -v -V -qversion; do
for ac_option in --version -v -V -qversion -version; do
  { { ac_try="$ac_compiler $ac_option >&5"
case "(($ac_try" in
  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
  *) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
printf "%s\n" "$ac_try_echo"; } >&5
  (eval "$ac_compiler $ac_option >&5") 2>conftest.err
  ac_status=$?
  if test -s conftest.err; then
    sed '10a\
... rest of stderr output deleted ...
         10q' conftest.err >conftest.er1
    cat conftest.er1 >&5
  fi
  rm -f conftest.er1 conftest.err
  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
  test $ac_status = 0; }
done

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5
$as_echo_n "checking whether we are using the GNU C compiler... " >&6; }
if ${ac_cv_c_compiler_gnu+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5
printf %s "checking whether the compiler supports GNU C... " >&6; }
if test ${ac_cv_c_compiler_gnu+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{
#ifndef __GNUC__
       choke me
#endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  ac_compiler_gnu=yes
else
  ac_compiler_gnu=no
else case e in #(
  e) ac_compiler_gnu=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
ac_cv_c_compiler_gnu=$ac_compiler_gnu

 ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
$as_echo "$ac_cv_c_compiler_gnu" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5
printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; }
ac_compiler_gnu=$ac_cv_c_compiler_gnu

if test $ac_compiler_gnu = yes; then
  GCC=yes
else
  GCC=
fi
ac_test_CFLAGS=${CFLAGS+set}
ac_test_CFLAGS=${CFLAGS+y}
ac_save_CFLAGS=$CFLAGS
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
$as_echo_n "checking whether $CC accepts -g... " >&6; }
if ${ac_cv_prog_cc_g+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_save_c_werror_flag=$ac_c_werror_flag
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5
printf %s "checking whether $CC accepts -g... " >&6; }
if test ${ac_cv_prog_cc_g+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_save_c_werror_flag=$ac_c_werror_flag
   ac_c_werror_flag=yes
   ac_cv_prog_cc_g=no
   CFLAGS="-g"
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_g=yes
else
  CFLAGS=""
else case e in #(
  e) CFLAGS=""
      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :

else
  ac_c_werror_flag=$ac_save_c_werror_flag
else case e in #(
  e) ac_c_werror_flag=$ac_save_c_werror_flag
	 CFLAGS="-g"
	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_g=yes
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
   ac_c_werror_flag=$ac_save_c_werror_flag
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
   ac_c_werror_flag=$ac_save_c_werror_flag ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
$as_echo "$ac_cv_prog_cc_g" >&6; }
if test "$ac_test_CFLAGS" = set; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5
printf "%s\n" "$ac_cv_prog_cc_g" >&6; }
if test $ac_test_CFLAGS; then
  CFLAGS=$ac_save_CFLAGS
elif test $ac_cv_prog_cc_g = yes; then
  if test "$GCC" = yes; then
    CFLAGS="-g -O2"
  else
    CFLAGS="-g"
  fi
else
  if test "$GCC" = yes; then
    CFLAGS="-O2"
  else
    CFLAGS=
  fi
fi
ac_prog_cc_stdc=no
if test x$ac_prog_cc_stdc = xno
then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5
$as_echo_n "checking for $CC option to accept ISO C89... " >&6; }
if ${ac_cv_prog_cc_c89+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_cv_prog_cc_c89=no
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5
printf %s "checking for $CC option to enable C11 features... " >&6; }
if test ${ac_cv_prog_cc_c11+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_prog_cc_c11=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_c_conftest_c11_program
_ACEOF
for ac_arg in '' -std=gnu11
do
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_c11=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c11" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC ;;
esac
fi

if test "x$ac_cv_prog_cc_c11" = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
else case e in #(
  e) if test "x$ac_cv_prog_cc_c11" = x
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5
printf "%s\n" "$ac_cv_prog_cc_c11" >&6; }
     CC="$CC $ac_cv_prog_cc_c11" ;;
esac
fi
  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11
  ac_prog_cc_stdc=c11 ;;
esac
fi
fi
if test x$ac_prog_cc_stdc = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5
printf %s "checking for $CC option to enable C99 features... " >&6; }
if test ${ac_cv_prog_cc_c99+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_prog_cc_c99=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_c_conftest_c99_program
_ACEOF
for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99=
do
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_c99=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c99" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC ;;
esac
fi

if test "x$ac_cv_prog_cc_c99" = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
else case e in #(
  e) if test "x$ac_cv_prog_cc_c99" = x
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5
printf "%s\n" "$ac_cv_prog_cc_c99" >&6; }
     CC="$CC $ac_cv_prog_cc_c99" ;;
esac
fi
  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99
  ac_prog_cc_stdc=c99 ;;
esac
fi
fi
if test x$ac_prog_cc_stdc = xno
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5
printf %s "checking for $CC option to enable C89 features... " >&6; }
if test ${ac_cv_prog_cc_c89+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_prog_cc_c89=no
ac_save_CC=$CC
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdarg.h>
#include <stdio.h>
struct stat;
/* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
struct buf { int x; };
FILE * (*rcsopen) (struct buf *, struct stat *, int);
static char *e (p, i)
     char **p;
     int i;
{
  return p[i];
}
static char *f (char * (*g) (char **, int), char **p, ...)
{
  char *s;
  va_list v;
  va_start (v,p);
  s = g (p, va_arg (v,int));
  va_end (v);
  return s;
}

$ac_c_conftest_c89_program
/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default.  It has
   function prototypes and stuff, but not '\xHH' hex character constants.
   These don't provoke an error unfortunately, instead are silently treated
   as 'x'.  The following induces an error, until -std is added to get
   proper ANSI mode.  Curiously '\x00'!='x' always comes out true, for an
   array size at least.  It's necessary to write '\x00'==0 to get something
   that's true only with -std.  */
int osf4_cc_array ['\x00' == 0 ? 1 : -1];

/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters
   inside strings and character constants.  */
#define FOO(x) 'x'
int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1];

int test (int i, double x);
struct s1 {int (*f) (int a);};
struct s2 {int (*f) (double a);};
int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
int argc;
char **argv;
int
main ()
{
return f (e, argv, 0) != argv[0]  ||  f (e, argv, 1) != argv[1];
  ;
  return 0;
}
_ACEOF
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \
for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
	-Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
do
  CC="$ac_save_CC $ac_arg"
  if ac_fn_c_try_compile "$LINENO"; then :
  if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_prog_cc_c89=$ac_arg
fi
rm -f core conftest.err conftest.$ac_objext
rm -f core conftest.err conftest.$ac_objext conftest.beam
  test "x$ac_cv_prog_cc_c89" != "xno" && break
done
rm -f conftest.$ac_ext
CC=$ac_save_CC

CC=$ac_save_CC ;;
esac
fi
# AC_CACHE_VAL
case "x$ac_cv_prog_cc_c89" in

if test "x$ac_cv_prog_cc_c89" = xno
  x)
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
$as_echo "none needed" >&6; } ;;
  xno)
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
$as_echo "unsupported" >&6; } ;;
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5
printf "%s\n" "unsupported" >&6; }
  *)
    CC="$CC $ac_cv_prog_cc_c89"
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
$as_echo "$ac_cv_prog_cc_c89" >&6; } ;;
else case e in #(
  e) if test "x$ac_cv_prog_cc_c89" = x
then :
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5
printf "%s\n" "none needed" >&6; }
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5
printf "%s\n" "$ac_cv_prog_cc_c89" >&6; }
     CC="$CC $ac_cv_prog_cc_c89" ;;
esac
fi
if test "x$ac_cv_prog_cc_c89" != xno; then :

  ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89
  ac_prog_cc_stdc=c89 ;;
esac
fi
fi

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu

    ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
$as_echo_n "checking how to run the C preprocessor... " >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5
printf %s "checking how to run the C preprocessor... " >&6; }
# On Suns, sometimes $CPP names a directory.
if test -n "$CPP" && test -d "$CPP"; then
  CPP=
fi
if test -z "$CPP"; then
  if ${ac_cv_prog_CPP+:} false; then :
  $as_echo_n "(cached) " >&6
else
      # Double quotes because CPP needs to be expanded
    for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp"
  if test ${ac_cv_prog_CPP+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)     # Double quotes because $CC needs to be expanded
    for CPP in "$CC -E" "$CC -E -traditional-cpp" cpp /lib/cpp
    do
      ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
  # Use a header file that comes with gcc, so configuring glibc
  # with a fresh cross-compiler works.
  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
  # <limits.h> exists even on freestanding compilers.
  # On the NeXT, cc -E runs the code through the compiler's parser,
  # not just through cpp. "Syntax error" is here to catch this case.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#ifdef __STDC__
# include <limits.h>
#include <limits.h>
#else
# include <assert.h>
#endif
		     Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
if ac_fn_c_try_cpp "$LINENO"
then :

else
  # Broken: fails on valid input.
continue
else case e in #(
  e) # Broken: fails on valid input.
continue ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

  # OK, works on sane cases.  Now check whether nonexistent headers
  # can be detected and how.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ac_nonexistent.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
if ac_fn_c_try_cpp "$LINENO"
then :
  # Broken: success on invalid input.
continue
else
  # Passes both tests.
else case e in #(
  e) # Passes both tests.
ac_preproc_ok=:
break
break ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

done
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
# Because of 'break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok; then :
if $ac_preproc_ok
then :
  break
fi

    done
    ac_cv_prog_CPP=$CPP

   ;;
esac
fi
  CPP=$ac_cv_prog_CPP
else
  ac_cv_prog_CPP=$CPP
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
$as_echo "$CPP" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5
printf "%s\n" "$CPP" >&6; }
ac_preproc_ok=false
for ac_c_preproc_warn_flag in '' yes
do
  # Use a header file that comes with gcc, so configuring glibc
  # with a fresh cross-compiler works.
  # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
  # <limits.h> exists even on freestanding compilers.
  # On the NeXT, cc -E runs the code through the compiler's parser,
  # not just through cpp. "Syntax error" is here to catch this case.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#ifdef __STDC__
# include <limits.h>
#include <limits.h>
#else
# include <assert.h>
#endif
		     Syntax error
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
if ac_fn_c_try_cpp "$LINENO"
then :

else
  # Broken: fails on valid input.
continue
else case e in #(
  e) # Broken: fails on valid input.
continue ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

  # OK, works on sane cases.  Now check whether nonexistent headers
  # can be detected and how.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ac_nonexistent.h>
_ACEOF
if ac_fn_c_try_cpp "$LINENO"; then :
if ac_fn_c_try_cpp "$LINENO"
then :
  # Broken: success on invalid input.
continue
else
  # Passes both tests.
else case e in #(
  e) # Passes both tests.
ac_preproc_ok=:
break
break ;;
esac
fi
rm -f conftest.err conftest.i conftest.$ac_ext

done
# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped.
# Because of 'break', _AC_PREPROC_IFELSE's cleaning code was skipped.
rm -f conftest.i conftest.err conftest.$ac_ext
if $ac_preproc_ok; then :
if $ac_preproc_ok
then :

else
  { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
else case e in #(
  e) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5
printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;}
as_fn_error $? "C preprocessor \"$CPP\" fails sanity check
See \`config.log' for more details" "$LINENO" 5; }
See 'config.log' for more details" "$LINENO" 5; } ;;
esac
fi

ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu


    #--------------------------------------------------------------------
    # Checks to see if the make program sets the $MAKE variable.
    #--------------------------------------------------------------------

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
printf %s "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
set x ${MAKE-make}
ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat >conftest.make <<\_ACEOF
ac_make=`printf "%s\n" "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
if eval test \${ac_cv_prog_make_${ac_make}_set+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat >conftest.make <<\_ACEOF
SHELL = /bin/sh
all:
	@echo '@@@%%%=$(MAKE)=@@@%%%'
_ACEOF
# GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
case `${MAKE-make} -f conftest.make 2>/dev/null` in
  *@@@%%%=?*=@@@%%%*)
    eval ac_cv_prog_make_${ac_make}_set=yes;;
  *)
    eval ac_cv_prog_make_${ac_make}_set=no;;
esac
rm -f conftest.make
rm -f conftest.make ;;
esac
fi
if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
  SET_MAKE=
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
  SET_MAKE="MAKE=${MAKE-make}"
fi


    #--------------------------------------------------------------------
    # Find ranlib
    #--------------------------------------------------------------------

    if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
set dummy ${ac_tool_prefix}ranlib; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_RANLIB+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$RANLIB"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_RANLIB+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$RANLIB"; then
  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
RANLIB=$ac_cv_prog_RANLIB
if test -n "$RANLIB"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
$as_echo "$RANLIB" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
printf "%s\n" "$RANLIB" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_RANLIB"; then
  ac_ct_RANLIB=$RANLIB
  # Extract the first word of "ranlib", so it can be a program name with args.
set dummy ranlib; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_RANLIB"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_RANLIB+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_RANLIB"; then
  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_RANLIB="ranlib"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
if test -n "$ac_ct_RANLIB"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
$as_echo "$ac_ct_RANLIB" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
printf "%s\n" "$ac_ct_RANLIB" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

  if test "x$ac_ct_RANLIB" = x; then
    RANLIB=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    RANLIB=$ac_ct_RANLIB
  fi
else
  RANLIB="$ac_cv_prog_RANLIB"
fi


    #--------------------------------------------------------------------
    # Determines the correct binary file extension (.o, .obj, .exe etc.)
    #--------------------------------------------------------------------





ac_header= ac_cache=
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5
$as_echo_n "checking for grep that handles long lines and -e... " >&6; }
if ${ac_cv_path_GREP+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -z "$GREP"; then
  ac_path_GREP_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
    for ac_prog in grep ggrep; do
for ac_item in $ac_header_c_list
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_GREP" || continue
# Check for GNU ac_path_GREP and select it if it is found.
  # Check for GNU $ac_path_GREP
case `"$ac_path_GREP" --version 2>&1` in
*GNU*)
  ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;;
*)
  ac_count=0
  $as_echo_n 0123456789 >"conftest.in"
  while :
  do
do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    $as_echo 'GREP' >> "conftest.nl"
    "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_GREP_max-0}; then
  if test $ac_cache; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_GREP="$ac_path_GREP"
      ac_path_GREP_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

    ac_fn_c_check_header_compile "$LINENO" $ac_header ac_cv_header_$ac_cache "$ac_includes_default"
      $ac_path_GREP_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_GREP"; then
    as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
  fi
else
  ac_cv_path_GREP=$GREP
fi

    if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5
$as_echo "$ac_cv_path_GREP" >&6; }
 GREP="$ac_cv_path_GREP"

      printf "%s\n" "#define $ac_item 1" >> confdefs.h

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5
$as_echo_n "checking for egrep... " >&6; }
if ${ac_cv_path_EGREP+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if echo a | $GREP -E '(a|b)' >/dev/null 2>&1
   then ac_cv_path_EGREP="$GREP -E"
   else
     if test -z "$EGREP"; then
  ac_path_EGREP_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
    for ac_prog in egrep; do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_EGREP" || continue
# Check for GNU ac_path_EGREP and select it if it is found.
  # Check for GNU $ac_path_EGREP
case `"$ac_path_EGREP" --version 2>&1` in
*GNU*)
  ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;;
*)
  ac_count=0
  $as_echo_n 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    $as_echo 'EGREP' >> "conftest.nl"
    "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_EGREP_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_EGREP="$ac_path_EGREP"
      ac_path_EGREP_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

    ac_header= ac_cache=
      $ac_path_EGREP_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_EGREP"; then
  elif test $ac_header; then
    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
  fi
else
    ac_cache=$ac_item
  else
  ac_cv_path_EGREP=$EGREP
fi

   fi
    ac_header=$ac_item
  fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5
$as_echo "$ac_cv_path_EGREP" >&6; }
 EGREP="$ac_cv_path_EGREP"

done

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5
$as_echo_n "checking for ANSI C header files... " >&6; }
if ${ac_cv_header_stdc+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <float.h>

int
main ()
{


  ;

  return 0;
}

_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  ac_cv_header_stdc=yes
else
  ac_cv_header_stdc=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

if test $ac_cv_header_stdc = yes; then
  # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <string.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "memchr" >/dev/null 2>&1; then :

else
  ac_cv_header_stdc=no
fi
rm -f conftest*

fi

if test $ac_cv_header_stdc = yes; then
  # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "free" >/dev/null 2>&1; then :

else
  ac_cv_header_stdc=no
fi
rm -f conftest*

fi

if test $ac_cv_header_stdc = yes; then
  # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi.
  if test "$cross_compiling" = yes; then :
  :

else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <ctype.h>
#include <stdlib.h>
#if ((' ' & 0x0FF) == 0x020)
# define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c))
#else
# define ISLOWER(c) \
		   (('a' <= (c) && (c) <= 'i') \
		     || ('j' <= (c) && (c) <= 'r') \
		     || ('s' <= (c) && (c) <= 'z'))
# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c))
#endif

#define XOR(e, f) (((e) && !(f)) || (!(e) && (f)))
int
main ()
{
  int i;
  for (i = 0; i < 256; i++)
    if (XOR (islower (i), ISLOWER (i))
	|| toupper (i) != TOUPPER (i))
      return 2;
  return 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :

else
  ac_cv_header_stdc=no
if test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext
fi

then :
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5
$as_echo "$ac_cv_header_stdc" >&6; }
if test $ac_cv_header_stdc = yes; then

$as_echo "#define STDC_HEADERS 1" >>confdefs.h
printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h

fi

# On IRIX 5.3, sys/types and inttypes.h are conflicting.
for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \
		  inttypes.h stdint.h unistd.h
do :
  as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default
"
if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
  cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF

fi

done



    # Any macros that use the compiler (e.g. AC_TRY_COMPILE) have to go here.


    #------------------------------------------------------------------------
    # If we're using GCC, see if the compiler understands -pipe. If so, use it.
    # It makes compiling go faster.  (This is only a performance feature.)
    #------------------------------------------------------------------------

    if test -z "$no_pipe" -a -n "$GCC"; then
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the compiler understands -pipe" >&5
$as_echo_n "checking if the compiler understands -pipe... " >&6; }
if ${tcl_cv_cc_pipe+:} false; then :
  $as_echo_n "(cached) " >&6
else

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the compiler understands -pipe" >&5
printf %s "checking if the compiler understands -pipe... " >&6; }
if test ${tcl_cv_cc_pipe+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	    hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -pipe"
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_cc_pipe=yes
else
  tcl_cv_cc_pipe=no
else case e in #(
  e) tcl_cv_cc_pipe=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
	    CFLAGS=$hold_cflags
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	    CFLAGS=$hold_cflags ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_pipe" >&5
$as_echo "$tcl_cv_cc_pipe" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_pipe" >&5
printf "%s\n" "$tcl_cv_cc_pipe" >&6; }
	if test $tcl_cv_cc_pipe = yes; then
	    CFLAGS="$CFLAGS -pipe"
	fi
    fi

    if test "${TCL_MAJOR_VERSION}" -lt 9 -a "${TCL_MINOR_VERSION}" -lt 7; then

printf "%s\n" "#define Tcl_Size int" >>confdefs.h

	fi

    #--------------------------------------------------------------------
    # Common compiler flag setup
    #--------------------------------------------------------------------

     { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
$as_echo_n "checking whether byte ordering is bigendian... " >&6; }
if ${ac_cv_c_bigendian+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_cv_c_bigendian=unknown
     { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
printf %s "checking whether byte ordering is bigendian... " >&6; }
if test ${ac_cv_c_bigendian+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_cv_c_bigendian=unknown
    # See if we're dealing with a universal compiler.
    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#ifndef __APPLE_CC__
	       not a universal capable compiler
	     #endif
	     typedef int dummy;

_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :

	# Check for potential -arch flags.  It is not universal unless
	# there are at least two -arch flags with different values.
	ac_arch=
	ac_prev=
	for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
	 if test -n "$ac_prev"; then
4690
4691
4692
4693
4694
4695
4696
4697

4698
4699
4700
4701
4702
4703
4704
4705
4706

4707
4708
4709


4710
4711
4712
4713
4714
4715
4716
4717
4718


4719
4720
4721
4722
4723
4724
4725
4726

4727
4728
4729
4730
4731
4732
4733
4734
4735
4736


4737
4738
4739



4740
4741

4742
4743

4744
4745
4746
4747
4748
4749
4750
4751
4752

4753
4754
4755
4756
4757
4758
4759
4760
4761
4762


4763
4764
4765
4766
4767
4768
4769

4770
4771
4772
4773
4774
4775
4776
4777
4778
4779


4780
4781
4782



4783
4784

4785
4786

4787
4788
4789
4790


4791
4792
4793
4794

4795
4796

4797
4798
4799
4800
4801

4802
4803

4804
4805
4806
4807
4808
4809
4810
4811
4812
4813







4814
4815
4816



4817
4818
4819



4820
4821
4822

4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833




4834
4835
4836
4837

4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853


4854
4855
4856



4857
4858
4859


4860
4861
4862


4863
4864
4865


4866
4867
4868

4869
4870
4871
4872
4873

4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892


4893
4894
4895
4896
4897
4898
4899
4900
4901


4902
4903
4904
4905
4906





4907
4908
4909
4910
4911
4912
4913
4914
4915
4916









4917
4918


4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946


























4947
4948
4949
4950



4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963


4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986




















4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014



























5015
5016
5017
5018
5019




5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030


5031
5032
5033


5034
5035
5036
5037
5038
5039
5040
5041
5042





5043
5044
5045
5046
5047
5048





5049
5050


5051
5052
5053
5054
5055


5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067











5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092









5093
5094
5095
5096
5097
5098
5099
5248
5249
5250
5251
5252
5253
5254

5255
5256
5257
5258
5259
5260
5261
5262
5263

5264
5265


5266
5267
5268
5269
5270
5271
5272
5273
5274
5275

5276
5277
5278
5279
5280
5281
5282
5283
5284

5285
5286
5287
5288
5289
5290
5291
5292
5293
5294

5295
5296
5297


5298
5299
5300
5301

5302
5303

5304
5305
5306
5307
5308
5309
5310
5311
5312

5313
5314
5315
5316
5317
5318
5319
5320
5321
5322

5323
5324
5325
5326
5327
5328
5329
5330

5331
5332
5333
5334
5335
5336
5337
5338
5339
5340

5341
5342
5343


5344
5345
5346
5347

5348
5349

5350
5351
5352
5353

5354
5355
5356
5357
5358

5359
5360

5361
5362
5363
5364
5365

5366
5367

5368
5369
5370
5371
5372






5373
5374
5375
5376
5377
5378
5379



5380
5381
5382
5383


5384
5385
5386
5387
5388

5389
5390
5391
5392
5393
5394
5395
5396
5397



5398
5399
5400
5401
5402
5403
5404

5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420

5421
5422
5423


5424
5425
5426
5427
5428

5429
5430
5431
5432

5433
5434
5435


5436
5437
5438
5439

5440
5441
5442
5443
5444

5445


5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461

5462
5463
5464
5465
5466
5467
5468
5469
5470


5471
5472
5473




5474
5475
5476
5477
5478
5479









5480
5481
5482
5483
5484
5485
5486
5487
5488
5489

5490
5491
5492
5493
5494

























5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521



5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536

5537
5538
5539
5540
5541
5542
5543


















5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565


























5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593




5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606


5607
5608
5609
5610

5611
5612
5613
5614
5615
5616
5617




5618
5619
5620
5621
5622
5623





5624
5625
5626
5627
5628
5629

5630
5631
5632
5633
5634


5635
5636
5637











5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664









5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680







-
+








-
+

-
-
+
+








-
+
+







-
+









-
+
+

-
-
+
+
+

-
+

-
+








-
+









-
+
+






-
+









-
+
+

-
-
+
+
+

-
+

-
+



-
+
+



-
+

-
+




-
+

-
+




-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
+
+
+

-
-
+
+
+


-
+








-
-
-
+
+
+
+



-
+















-
+
+

-
-
+
+
+


-
+
+


-
+
+

-
-
+
+


-
+




-
+
-
-
















-
+
+







-
-
+
+

-
-
-
-
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+












-
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+









-
-
+
+


-
+
+





-
-
-
-
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
+
+



-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
















-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+







	   esac
	   ac_prev=
	 elif test "x$ac_word" = "x-arch"; then
	   ac_prev=arch
	 fi
       done
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
    if test $ac_cv_c_bigendian = unknown; then
      # See if sys/param.h defines the BYTE_ORDER macro.
      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
	     #include <sys/param.h>

int
main ()
main (void)
{
#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
		     && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \\
		     && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \\
		     && LITTLE_ENDIAN)
	      bogus endian macros
	     #endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  # It does; now see whether it defined to BIG_ENDIAN or not.
	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
		#include <sys/param.h>

int
main ()
main (void)
{
#if BYTE_ORDER != BIG_ENDIAN
		 not big endian
		#endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_c_bigendian=yes
else
  ac_cv_c_bigendian=no
else case e in #(
  e) ac_cv_c_bigendian=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
    fi
    if test $ac_cv_c_bigendian = unknown; then
      # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <limits.h>

int
main ()
main (void)
{
#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
	      bogus endian macros
	     #endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  # It does; now see whether it defined to _BIG_ENDIAN or not.
	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <limits.h>

int
main ()
main (void)
{
#ifndef _BIG_ENDIAN
		 not big endian
		#endif

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_c_bigendian=yes
else
  ac_cv_c_bigendian=no
else case e in #(
  e) ac_cv_c_bigendian=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
    fi
    if test $ac_cv_c_bigendian = unknown; then
      # Compile a test program.
      if test "$cross_compiling" = yes; then :
      if test "$cross_compiling" = yes
then :
  # Try to guess by grepping values from an object file.
	 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
short int ascii_mm[] =
unsigned short int ascii_mm[] =
		  { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
		short int ascii_ii[] =
		unsigned short int ascii_ii[] =
		  { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
		int use_ascii (int i) {
		  return ascii_mm[i] + ascii_ii[i];
		}
		short int ebcdic_ii[] =
		unsigned short int ebcdic_ii[] =
		  { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
		short int ebcdic_mm[] =
		unsigned short int ebcdic_mm[] =
		  { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
		int use_ebcdic (int i) {
		  return ebcdic_mm[i] + ebcdic_ii[i];
		}
		extern int foo;

int
main ()
{
return use_ascii (foo) == use_ebcdic (foo);
		int
		main (int argc, char **argv)
		{
		  /* Intimidate the compiler so that it does not
		     optimize the arrays away.  */
		  char *p = argv[0];
		  ascii_mm[1] = *p++; ebcdic_mm[1] = *p++;
  ;
  return 0;
}
		  ascii_ii[1] = *p++; ebcdic_ii[1] = *p++;
		  return use_ascii (argc) == use_ebcdic (*p);
		}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
if ac_fn_c_try_link "$LINENO"
then :
  if grep BIGenDianSyS conftest$ac_exeext >/dev/null; then
	      ac_cv_c_bigendian=yes
	    fi
	    if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
	    if grep LiTTleEnDian conftest$ac_exeext >/dev/null ; then
	      if test "$ac_cv_c_bigendian" = unknown; then
		ac_cv_c_bigendian=no
	      else
		# finding both strings is unlikely to happen, but who knows?
		ac_cv_c_bigendian=unknown
	      fi
	    fi
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$ac_includes_default
int
main ()
main (void)
{

	     /* Are we little or big endian?  From Harbison&Steele.  */
	     union
	     {
	       long int l;
	       char c[sizeof (long int)];
	     } u;
	     u.l = 1;
	     return u.c[sizeof (long int) - 1] == 1;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
if ac_fn_c_try_run "$LINENO"
then :
  ac_cv_c_bigendian=no
else
  ac_cv_c_bigendian=yes
else case e in #(
  e) ac_cv_c_bigendian=yes ;;
esac
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext
  conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi

    fi
    fi ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5
$as_echo "$ac_cv_c_bigendian" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5
printf "%s\n" "$ac_cv_c_bigendian" >&6; }
 case $ac_cv_c_bigendian in #(
   yes)
     $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h
     printf "%s\n" "#define WORDS_BIGENDIAN 1" >>confdefs.h
;; #(
   no)
      ;; #(
   universal)

     #
$as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h

     ;; #(
   *)
     as_fn_error $? "unknown endianness
 presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;;
 esac



#--------------------------------------------------------------------
# Check if building with optional Gdbm package. This will declare
# GDBM_CFLAGS and GDBM_LIBS variables.
#--------------------------------------------------------------------



# Check whether --with-gdbm was given.
if test "${with_gdbm+set}" = set; then :
if test ${with_gdbm+y}
then :
  withval=$with_gdbm; \
	with_gdbm=${withval}
fi


    if test x"${with_gdbm}" != x -a "${with_gdbm}" != no; then

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU gdbm library" >&5
$as_echo_n "checking for GNU gdbm library... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU gdbm library" >&5
printf %s "checking for GNU gdbm library... " >&6; }

    if ${ac_cv_c_gdbm+:} false; then :
  $as_echo_n "(cached) " >&6
else

    if test ${ac_cv_c_gdbm+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
    if test x"${with_gdbm}" != x -a "${with_gdbm}" != "yes"; then
        if test -f "${with_gdbm}/gdbm.h" -a x"`ls ${with_gdbm}/libgdbm* 2>/dev/null`" != x; then
            ac_cv_c_gdbm=`(cd ${with_gdbm}; pwd)`
            gincdir=$ac_cv_c_gdbm
            glibdir=$ac_cv_c_gdbm
            { $as_echo "$as_me:${as_lineno-$LINENO}: result: found in $glibdir" >&5
$as_echo "found in $glibdir" >&6; }
        else
            as_fn_error $? "${with_gdbm} directory doesn't contain gdbm library" "$LINENO" 5
        fi
	if test -f "${with_gdbm}/gdbm.h" -a x"`ls ${with_gdbm}/libgdbm* 2>/dev/null`" != x; then
	    ac_cv_c_gdbm=`(cd ${with_gdbm}; pwd)`
	    gincdir=$ac_cv_c_gdbm
	    glibdir=$ac_cv_c_gdbm
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found in $glibdir" >&5
printf "%s\n" "found in $glibdir" >&6; }
	else
	    as_fn_error $? "${with_gdbm} directory doesn't contain gdbm library" "$LINENO" 5
	fi
    fi

     ;;
esac
fi

    if test x"${gincdir}" = x -o x"${glibdir}" = x; then
        for i in \
                `ls -d ${exec_prefix}/lib 2>/dev/null`\
                `ls -d ${prefix}/lib 2>/dev/null`\
                `ls -d /usr/local/lib 2>/dev/null`\
                `ls -d /usr/lib 2>/dev/null` ; do
            if test x"`ls $i/libgdbm* 2>/dev/null`" != x ; then
                glibdir=`(cd $i; pwd)`
                break
            fi
        done
        for i in \
                `ls -d ${prefix}/include 2>/dev/null`\
                `ls -d /usr/local/include 2>/dev/null`\
                `ls -d /usr/include 2>/dev/null` ; do
            if test -f "$i/gdbm.h" ; then
                gincdir=`(cd $i; pwd)`
                break
            fi
        done
        if test x"$glibdir" = x -o x"$gincdir" = x ; then
            as_fn_error $? "none found" "$LINENO" 5
        else
            { $as_echo "$as_me:${as_lineno-$LINENO}: result: found in $glibdir, includes in $gincdir" >&5
$as_echo "found in $glibdir, includes in $gincdir" >&6; }
            $as_echo "#define HAVE_GDBM 1" >>confdefs.h
	for i in \
		`ls -d ${exec_prefix}/lib 2>/dev/null`\
		`ls -d ${prefix}/lib 2>/dev/null`\
		`ls -d /usr/local/lib 2>/dev/null`\
		`ls -d /usr/lib 2>/dev/null`\
		`ls -d /usr/lib/x86_64-linux-gnu 2>/dev/null` ; do
	    if test x"`ls $i/libgdbm* 2>/dev/null`" != x ; then
		glibdir=`(cd $i; pwd)`
		break
	    fi
	done
	for i in \
		`ls -d ${prefix}/include 2>/dev/null`\
		`ls -d /usr/local/include 2>/dev/null`\
		`ls -d /usr/include 2>/dev/null` ; do
	    if test -f "$i/gdbm.h" ; then
		gincdir=`(cd $i; pwd)`
		break
	    fi
	done
	if test x"$glibdir" = x -o x"$gincdir" = x ; then
	    as_fn_error $? "none found" "$LINENO" 5
	else
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found in $glibdir, includes in $gincdir" >&5
printf "%s\n" "found in $glibdir, includes in $gincdir" >&6; }
	    printf "%s\n" "#define HAVE_GDBM 1" >>confdefs.h

            GDBM_CFLAGS="-I\"$gincdir\""
            GDBM_LIBS="-L\"$glibdir\" -lgdbm"
        fi
	    GDBM_CFLAGS="-I\"$gincdir\""
	    GDBM_LIBS="-L\"$glibdir\" -lgdbm"
	fi
    fi
    fi


#--------------------------------------------------------------------
# Check if building with optional lmdb package. This will declare
# LMDB_CFLAGS and LMDB_LIBS variables.
#--------------------------------------------------------------------



# Check whether --with-lmdb was given.
if test "${with_lmdb+set}" = set; then :
if test ${with_lmdb+y}
then :
  withval=$with_lmdb; with_lmdb=${withval}
fi


    if test x"${with_lmdb}" != "x" -a "${with_lmdb}" != no; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for LMDB library" >&5
$as_echo_n "checking for LMDB library... " >&6; }
        if ${ac_cv_c_lmdb+:} false; then :
  $as_echo_n "(cached) " >&6
else

        if test x"${with_lmdb}" != x -a "${with_lmdb}" != "yes"; then
            if test -f "${with_lmdb}/lmdb.h" -a x"`ls ${with_lmdb}/liblmdb* 2>/dev/null`" != x; then
                ac_cv_c_lmdb=`(cd ${with_lmdb}; pwd)`
                lincdir=$ac_cv_c_lmdb
                llibdir=$ac_cv_c_lmdb
                { $as_echo "$as_me:${as_lineno-$LINENO}: result: found in $llibdir" >&5
$as_echo "found in $llibdir" >&6; }
            else
                as_fn_error $? "${with_lmdb} directory doesn't contain lmdb library" "$LINENO" 5
            fi
        fi

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for LMDB library" >&5
printf %s "checking for LMDB library... " >&6; }
	if test ${ac_cv_c_lmdb+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	if test x"${with_lmdb}" != x -a "${with_lmdb}" != "yes"; then
	    if test -f "${with_lmdb}/lmdb.h" -a x"`ls ${with_lmdb}/liblmdb* 2>/dev/null`" != x; then
		ac_cv_c_lmdb=`(cd ${with_lmdb}; pwd)`
		lincdir=$ac_cv_c_lmdb
		llibdir=$ac_cv_c_lmdb
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found in $llibdir" >&5
printf "%s\n" "found in $llibdir" >&6; }
	    else
		as_fn_error $? "${with_lmdb} directory doesn't contain lmdb library" "$LINENO" 5
	    fi
	fi
	 ;;
esac
fi

        if test x"${lincdir}" = x -o x"${llibdir}" = x; then
            for i in \
                    `ls -d ${exec_prefix}/lib 2>/dev/null`\
                    `ls -d ${prefix}/lib 2>/dev/null`\
                    `ls -d /usr/local/lib 2>/dev/null`\
                    `ls -d /usr/lib 2>/dev/null` ; do
                if test x"`ls $i/liblmdb* 2>/dev/null`" != x ; then
                    llibdir=`(cd $i; pwd)`
                    break
                fi
            done
            for i in \
                    `ls -d ${prefix}/include 2>/dev/null`\
                    `ls -d /usr/local/include 2>/dev/null`\
                    `ls -d /usr/include 2>/dev/null` ; do
                if test -f "$i/lmdb.h" ; then
                    lincdir=`(cd $i; pwd)`
                    break
                fi
            done
            if test x"$llibdir" = x -o x"$lincdir" = x ; then
                as_fn_error $? "none found" "$LINENO" 5
            else
                { $as_echo "$as_me:${as_lineno-$LINENO}: result: found in $llibdir, includes in $lincdir" >&5
$as_echo "found in $llibdir, includes in $lincdir" >&6; }
                $as_echo "#define HAVE_LMDB 1" >>confdefs.h
	if test x"${lincdir}" = x -o x"${llibdir}" = x; then
	    for i in \
		    `ls -d ${exec_prefix}/lib 2>/dev/null`\
		    `ls -d ${prefix}/lib 2>/dev/null`\
		    `ls -d /usr/local/lib 2>/dev/null`\
		    `ls -d /usr/lib 2>/dev/null`\
		    `ls -d /usr/lib/x86_64-linux-gnu 2>/dev/null` ; do
		if test x"`ls $i/liblmdb* 2>/dev/null`" != x ; then
		    llibdir=`(cd $i; pwd)`
		    break
		fi
	    done
	    for i in \
		    `ls -d ${prefix}/include 2>/dev/null`\
		    `ls -d /usr/local/include 2>/dev/null`\
		    `ls -d /usr/include 2>/dev/null` ; do
		if test -f "$i/lmdb.h" ; then
		    lincdir=`(cd $i; pwd)`
		    break
		fi
	    done
	    if test x"$llibdir" = x -o x"$lincdir" = x ; then
		as_fn_error $? "none found" "$LINENO" 5
	    else
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found in $llibdir, includes in $lincdir" >&5
printf "%s\n" "found in $llibdir, includes in $lincdir" >&6; }
		printf "%s\n" "#define HAVE_LMDB 1" >>confdefs.h

                LMDB_CFLAGS="-I\"$lincdir\""
                LMDB_LIBS="-L\"$llibdir\" -llmdb"
            fi
        fi
		LMDB_CFLAGS="-I\"$lincdir\""
		LMDB_LIBS="-L\"$llibdir\" -llmdb"
	    fi
	fi
    fi


#--------------------------------------------------------------------
# Locate the NaviServer/AOLserver dir for compilation as NaviServer/AOLserver module.
# This will declare NS_INCLUDES, NS_LIBS and define NS_AOLSERVER.
#--------------------------------------------------------------------


    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for NaviServer/AOLserver configuration" >&5
$as_echo_n "checking for NaviServer/AOLserver configuration... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for NaviServer/AOLserver configuration" >&5
printf %s "checking for NaviServer/AOLserver configuration... " >&6; }

# Check whether --with-naviserver was given.
if test "${with_naviserver+set}" = set; then :
if test ${with_naviserver+y}
then :
  withval=$with_naviserver; \
    with_naviserver=${withval}
fi


    if ${ac_cv_c_naviserver+:} false; then :
  $as_echo_n "(cached) " >&6
else

    if test ${ac_cv_c_naviserver+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
    if test x"${with_naviserver}" != x ; then
        if test -f "${with_naviserver}/include/ns.h" ; then
            ac_cv_c_naviserver=`(cd ${with_naviserver}; pwd)`
        else
            as_fn_error $? "${with_naviserver} directory doesn't contain ns.h" "$LINENO" 5
        fi
	if test -f "${with_naviserver}/include/ns.h" ; then
	    ac_cv_c_naviserver=`(cd ${with_naviserver}; pwd)`
	else
	    as_fn_error $? "${with_naviserver} directory doesn't contain ns.h" "$LINENO" 5
	fi
    fi

     ;;
esac
fi

    if test x"${ac_cv_c_naviserver}" = x ; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: none found" >&5
$as_echo "none found" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none found" >&5
printf "%s\n" "none found" >&6; }
    else
        NS_DIR=${ac_cv_c_naviserver}
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: found NaviServer/AOLserver in $NS_DIR" >&5
$as_echo "found NaviServer/AOLserver in $NS_DIR" >&6; }
        NS_INCLUDES="-I\"${NS_DIR}/include\""
        if test "`uname -s`" = Darwin ; then
            aollibs=`ls ${NS_DIR}/lib/libns* 2>/dev/null`
            if test x"$aollibs" != x ; then
                NS_LIBS="-L\"${NS_DIR}/lib\" -lnsd -lnsthread"
            fi
        fi
        $as_echo "#define NS_AOLSERVER 1" >>confdefs.h
	NS_DIR=${ac_cv_c_naviserver}
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: found NaviServer/AOLserver in $NS_DIR" >&5
printf "%s\n" "found NaviServer/AOLserver in $NS_DIR" >&6; }
	NS_INCLUDES="-I\"${NS_DIR}/include\""
	if test "`uname -s`" = Darwin ; then
	    aollibs=`ls ${NS_DIR}/lib/libns* 2>/dev/null`
	    if test x"$aollibs" != x ; then
		NS_LIBS="-L\"${NS_DIR}/lib\" -lnsd -lnsthread"
	    fi
	fi
	printf "%s\n" "#define NS_AOLSERVER 1" >>confdefs.h

    fi


#-----------------------------------------------------------------------
# __CHANGE__
# Specify the C source files to compile in TEA_ADD_SOURCES,
# public headers that need to be installed in TEA_ADD_HEADERS,
# stub library C source files to compile in TEA_ADD_STUB_SOURCES,
# and runtime Tcl library files in TEA_ADD_TCL_SOURCES.
# This defines PKG(_STUB)_SOURCES, PKG(_STUB)_OBJECTS, PKG_HEADERS
# and PKG_TCL_SOURCES.
#-----------------------------------------------------------------------


    vars="generic/threadNs.c           \
                 generic/threadCmd.c          \
                 generic/threadSvCmd.c        \
                 generic/threadSpCmd.c        \
                 generic/threadPoolCmd.c      \
                 generic/psGdbm.c             \
                 generic/psLmdb.c             \
                 generic/threadSvListCmd.c    \
                 generic/threadSvKeylistCmd.c \
                 generic/tclXkeylist.c        \
		 generic/threadCmd.c          \
		 generic/threadSvCmd.c        \
		 generic/threadSpCmd.c        \
		 generic/threadPoolCmd.c      \
		 generic/psGdbm.c             \
		 generic/psLmdb.c             \
		 generic/threadSvListCmd.c    \
		 generic/threadSvKeylistCmd.c \
		 generic/tclXkeylist.c        \
"
    for i in $vars; do
	case $i in
	    \$*)
		# allow $-var names
		PKG_SOURCES="$PKG_SOURCES $i"
		PKG_OBJECTS="$PKG_OBJECTS $i"
5260
5261
5262
5263
5264
5265
5266
5267
5268


5269
5270
5271
5272


5273
5274
5275
5276
5277
5278
5279
5280





5281
5282
5283
5284
5285
5286
5287
5841
5842
5843
5844
5845
5846
5847


5848
5849
5850
5851
5852

5853
5854
5855
5856
5857
5858




5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870







-
-
+
+



-
+
+




-
-
-
-
+
+
+
+
+







# hard to only rely on the Tcl public header files.  Internal headers
# contain private data structures and are subject to change without
# notice.
# This MUST be called after TEA_LOAD_TCLCONFIG / TEA_LOAD_TKCONFIG
#--------------------------------------------------------------------


    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl public headers" >&5
$as_echo_n "checking for Tcl public headers... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for Tcl public headers" >&5
printf %s "checking for Tcl public headers... " >&6; }


# Check whether --with-tclinclude was given.
if test "${with_tclinclude+set}" = set; then :
if test ${with_tclinclude+y}
then :
  withval=$with_tclinclude; with_tclinclude=${withval}
fi


    if ${ac_cv_c_tclh+:} false; then :
  $as_echo_n "(cached) " >&6
else

    if test ${ac_cv_c_tclh+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	# Use the value from --with-tclinclude, if it was given

	if test x"${with_tclinclude}" != x ; then
	    if test -f "${with_tclinclude}/tcl.h" ; then
		ac_cv_c_tclh=${with_tclinclude}
	    else
		as_fn_error $? "${with_tclinclude} directory does not contain tcl.h" "$LINENO" 5
5322
5323
5324
5325
5326
5327
5328
5329


5330
5331
5332
5333
5334
5335
5336
5337
5338
5339


5340
5341
5342
5343
5344
5345
5346
5905
5906
5907
5908
5909
5910
5911

5912
5913
5914
5915
5916
5917
5918
5919
5920
5921


5922
5923
5924
5925
5926
5927
5928
5929
5930







-
+
+








-
-
+
+







	    for i in $list ; do
		if test -f "$i/tcl.h" ; then
		    ac_cv_c_tclh=$i
		    break
		fi
	    done
	fi

     ;;
esac
fi


    # Print a message based on how we determined the include path

    if test x"${ac_cv_c_tclh}" = x ; then
	as_fn_error $? "tcl.h not found.  Please specify its location with --with-tclinclude" "$LINENO" 5
    else
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_cv_c_tclh}" >&5
$as_echo "${ac_cv_c_tclh}" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${ac_cv_c_tclh}" >&5
printf "%s\n" "${ac_cv_c_tclh}" >&6; }
    fi

    # Convert to a native path and substitute into the output files.

    INCLUDE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tclh}`

    TCL_INCLUDES=-I\"${INCLUDE_DIR_NATIVE}\"
5356
5357
5358
5359
5360
5361
5362
5363


5364
5365
5366



5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386

5387
5388
5389

5390
5391
5392
5393

5394
5395
5396
5397

5398
5399
5400
5401
5402
5403
5404







5405
5406
5407
5408
5409
5410
5411




5412
5413
5414
5415

5416
5417

5418
5419
5420
5421
5422
5423
5424


5425
5426
5427



5428
5429

5430
5431


5432
5433
5434
5435




5436
5437
5438



5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452







5453
5454
5455
5456
5457
5458
5459




5460
5461
5462
5463

5464
5465

5466
5467
5468
5469
5470
5471
5472


5473
5474
5475



5476
5477

5478
5479


5480
5481
5482
5483




5484
5485
5486



5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500







5501
5502
5503
5504
5505
5506
5507




5508
5509
5510
5511

5512
5513

5514
5515
5516
5517
5518
5519
5520


5521
5522
5523



5524
5525

5526
5527


5528
5529
5530
5531




5532
5533
5534



5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546







5547
5548
5549
5550
5551
5552
5553




5554
5555
5556
5557

5558
5559

5560
5561
5562
5563
5564
5565
5566


5567
5568
5569



5570
5571

5572
5573


5574
5575
5576
5577




5578
5579
5580



5581
5582
5583
5584
5585
5586
5587
5588
5589







5590
5591
5592
5593
5594
5595
5596




5597
5598
5599
5600

5601
5602

5603
5604
5605
5606
5607
5608
5609


5610
5611
5612



5613
5614

5615
5616


5617
5618
5619
5620




5621
5622
5623



5624
5625
5626
5627
5628
5629
5630
5631
5632


5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643


5644
5645
5646

5647
5648
5649


5650
5651
5652


5653
5654
5655
5656
5657
5658
5659

5660
5661
5662

5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678


5679
5680


5681
5682
5683



5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695


5696
5697
5698



5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712


5713
5714

5715
5716
5717


5718
5719
5720

5721
5722
5723
5724
5725
5726





5727
5728
5729
5730

5731
5732
5733

5734
5735
5736
5737

5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760







5761
5762
5763
5764
5765
5766

5767




5768
5769

5770
5771

5772
5773
5774
5775
5776
5777
5778


5779
5780
5781
5782
5783


5784
5785
5786


5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800







5801
5802
5803
5804
5805
5806

5807




5808
5809

5810
5811

5812
5813
5814
5815
5816
5817
5818


5819
5820
5821
5822
5823


5824
5825
5826


5827
5828
5829
5830
5831
5832
5833
5834
5835


5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850


5851
5852


5853
5854
5855



5856
5857
5858
5859


5860
5861
5862
5863
5864


5865
5866


5867
5868
5869



5870
5871
5872
5873


5874
5875


5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887







5888
5889
5890
5891
5892
5893
5894
5895

5896
5897
5898
5899
5900
5901
5902


5903
5904
5905



5906
5907

5908
5909


5910
5911
5912
5913




5914
5915
5916

5917
5918
5919

5920
5921
5922
5923
5924
5925
5926
5927


5928
5929


5930
5931
5932



5933
5934
5935
5936


5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947







5948
5949
5950
5951
5952
5953
5954
5955


5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966


5967
5968
5969


5970
5971
5972
5973
5974
5975
5976
5940
5941
5942
5943
5944
5945
5946

5947
5948
5949


5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971

5972
5973
5974

5975
5976
5977
5978

5979
5980
5981
5982

5983
5984






5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997

5998
5999
6000
6001
6002
6003
6004

6005
6006

6007
6008
6009
6010
6011
6012
6013

6014
6015
6016


6017
6018
6019
6020

6021
6022

6023
6024
6025



6026
6027
6028
6029
6030


6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041






6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054

6055
6056
6057
6058
6059
6060
6061

6062
6063

6064
6065
6066
6067
6068
6069
6070

6071
6072
6073


6074
6075
6076
6077

6078
6079

6080
6081
6082



6083
6084
6085
6086
6087


6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098






6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111

6112
6113
6114
6115
6116
6117
6118

6119
6120

6121
6122
6123
6124
6125
6126
6127

6128
6129
6130


6131
6132
6133
6134

6135
6136

6137
6138
6139



6140
6141
6142
6143
6144


6145
6146
6147
6148
6149
6150
6151
6152
6153






6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166

6167
6168
6169
6170
6171
6172
6173

6174
6175

6176
6177
6178
6179
6180
6181
6182

6183
6184
6185


6186
6187
6188
6189

6190
6191

6192
6193
6194



6195
6196
6197
6198
6199


6200
6201
6202
6203
6204
6205






6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218

6219
6220
6221
6222
6223
6224
6225

6226
6227

6228
6229
6230
6231
6232
6233
6234

6235
6236
6237


6238
6239
6240
6241

6242
6243

6244
6245
6246



6247
6248
6249
6250
6251


6252
6253
6254
6255
6256
6257
6258
6259
6260
6261


6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272


6273
6274
6275
6276

6277
6278


6279
6280
6281


6282
6283
6284
6285
6286
6287
6288
6289

6290
6291
6292

6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307


6308
6309
6310

6311
6312
6313


6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327

6328
6329
6330


6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345


6346
6347
6348

6349
6350


6351
6352
6353
6354

6355
6356





6357
6358
6359
6360
6361
6362
6363
6364

6365
6366
6367

6368
6369
6370
6371

6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389






6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403

6404
6405
6406
6407
6408

6409
6410

6411
6412
6413
6414
6415
6416
6417

6418
6419
6420
6421
6422


6423
6424
6425


6426
6427
6428
6429
6430
6431
6432
6433
6434
6435






6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449

6450
6451
6452
6453
6454

6455
6456

6457
6458
6459
6460
6461
6462
6463

6464
6465
6466
6467
6468


6469
6470
6471


6472
6473
6474
6475
6476
6477
6478
6479
6480


6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495


6496
6497
6498

6499
6500
6501


6502
6503
6504
6505
6506


6507
6508
6509
6510
6511


6512
6513
6514

6515
6516
6517


6518
6519
6520
6521
6522


6523
6524
6525

6526
6527
6528
6529
6530
6531
6532
6533






6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547

6548
6549
6550
6551
6552
6553
6554

6555
6556
6557


6558
6559
6560
6561

6562
6563

6564
6565
6566



6567
6568
6569
6570
6571
6572

6573
6574
6575

6576
6577
6578
6579
6580
6581
6582


6583
6584
6585

6586
6587
6588


6589
6590
6591
6592
6593


6594
6595
6596
6597
6598
6599
6600






6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613


6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625

6626
6627
6628


6629
6630
6631
6632
6633
6634
6635
6636
6637







-
+
+

-
-
+
+
+



















-
+


-
+



-
+



-
+

-
-
-
-
-
-
+
+
+
+
+
+
+






-
+
+
+
+



-
+

-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+

-
-
+
+
+








-
-
-
-
-
-
+
+
+
+
+
+
+






-
+
+
+
+



-
+

-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+

-
-
+
+
+








-
-
-
-
-
-
+
+
+
+
+
+
+






-
+
+
+
+



-
+

-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+

-
-
+
+
+






-
-
-
-
-
-
+
+
+
+
+
+
+






-
+
+
+
+



-
+

-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+

-
-
+
+
+



-
-
-
-
-
-
+
+
+
+
+
+
+






-
+
+
+
+



-
+

-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+

-
-
+
+
+







-
-
+
+









-
-
+
+


-
+

-
-
+
+

-
-
+
+






-
+


-
+














-
-
+
+

-
+
+

-
-
+
+
+











-
+
+

-
-
+
+
+












-
-
+
+

-
+

-
-
+
+


-
+

-
-
-
-
-
+
+
+
+
+



-
+


-
+



-
+

















-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+








-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+







-
-
+
+













-
-
+
+

-
+
+

-
-
+
+
+


-
-
+
+



-
-
+
+

-
+
+

-
-
+
+
+


-
-
+
+

-
+
+






-
-
-
-
-
-
+
+
+
+
+
+
+







-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+


-
+


-
+






-
-
+
+

-
+
+

-
-
+
+
+


-
-
+
+





-
-
-
-
-
-
+
+
+
+
+
+
+






-
-
+
+










-
+
+

-
-
+
+







#--------------------------------------------------------------------
# Check whether --enable-threads or --disable-threads was given.
# This auto-enables if Tcl was compiled threaded.
#--------------------------------------------------------------------


    # Check whether --enable-threads was given.
if test "${enable_threads+set}" = set; then :
if test ${enable_threads+y}
then :
  enableval=$enable_threads; tcl_ok=$enableval
else
  tcl_ok=yes
else case e in #(
  e) tcl_ok=yes ;;
esac
fi


    if test "${enable_threads+set}" = set; then
	enableval="$enable_threads"
	tcl_ok=$enableval
    else
	tcl_ok=yes
    fi

    if test "$tcl_ok" = "yes" -o "${TCL_THREADS}" = 1; then
	TCL_THREADS=1

	if test "${TEA_PLATFORM}" != "windows" ; then
	    # We are always OK on Windows, so check what this platform wants:

	    # USE_THREAD_ALLOC tells us to try the special thread-based
	    # allocator that significantly reduces lock contention

$as_echo "#define USE_THREAD_ALLOC 1" >>confdefs.h
printf "%s\n" "#define USE_THREAD_ALLOC 1" >>confdefs.h


$as_echo "#define _REENTRANT 1" >>confdefs.h
printf "%s\n" "#define _REENTRANT 1" >>confdefs.h

	    if test "`uname -s`" = "SunOS" ; then

$as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h
printf "%s\n" "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h

	    fi

$as_echo "#define _THREAD_SAFE 1" >>confdefs.h
printf "%s\n" "#define _THREAD_SAFE 1" >>confdefs.h

	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lpthread" >&5
$as_echo_n "checking for pthread_mutex_init in -lpthread... " >&6; }
if ${ac_cv_lib_pthread_pthread_mutex_init+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lpthread" >&5
printf %s "checking for pthread_mutex_init in -lpthread... " >&6; }
if test ${ac_cv_lib_pthread_pthread_mutex_init+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthread  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
   builtin and then its argument prototype would still apply.
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char pthread_mutex_init ();
char pthread_mutex_init (void);
int
main ()
main (void)
{
return pthread_mutex_init ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  ac_cv_lib_pthread_pthread_mutex_init=yes
else
  ac_cv_lib_pthread_pthread_mutex_init=no
else case e in #(
  e) ac_cv_lib_pthread_pthread_mutex_init=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
LIBS=$ac_check_lib_save_LIBS ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_pthread_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_pthread_pthread_mutex_init" = xyes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_mutex_init" >&5
printf "%s\n" "$ac_cv_lib_pthread_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_pthread_pthread_mutex_init" = xyes
then :
  tcl_ok=yes
else
  tcl_ok=no
else case e in #(
  e) tcl_ok=no ;;
esac
fi

	    if test "$tcl_ok" = "no"; then
		# Check a little harder for __pthread_mutex_init in the same
		# library, as some systems hide it there until pthread.h is
		# defined.  We could alternatively do an AC_TRY_COMPILE with
		# pthread.h, but that will work with libpthread really doesn't
		# exist, like AIX 4.2.  [Bug: 4359]
		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __pthread_mutex_init in -lpthread" >&5
$as_echo_n "checking for __pthread_mutex_init in -lpthread... " >&6; }
if ${ac_cv_lib_pthread___pthread_mutex_init+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __pthread_mutex_init in -lpthread" >&5
printf %s "checking for __pthread_mutex_init in -lpthread... " >&6; }
if test ${ac_cv_lib_pthread___pthread_mutex_init+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthread  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
   builtin and then its argument prototype would still apply.
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char __pthread_mutex_init ();
char __pthread_mutex_init (void);
int
main ()
main (void)
{
return __pthread_mutex_init ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  ac_cv_lib_pthread___pthread_mutex_init=yes
else
  ac_cv_lib_pthread___pthread_mutex_init=no
else case e in #(
  e) ac_cv_lib_pthread___pthread_mutex_init=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
LIBS=$ac_check_lib_save_LIBS ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread___pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_pthread___pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_pthread___pthread_mutex_init" = xyes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread___pthread_mutex_init" >&5
printf "%s\n" "$ac_cv_lib_pthread___pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_pthread___pthread_mutex_init" = xyes
then :
  tcl_ok=yes
else
  tcl_ok=no
else case e in #(
  e) tcl_ok=no ;;
esac
fi

	    fi

	    if test "$tcl_ok" = "yes"; then
		# The space is needed
		THREADS_LIBS=" -lpthread"
	    else
		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lpthreads" >&5
$as_echo_n "checking for pthread_mutex_init in -lpthreads... " >&6; }
if ${ac_cv_lib_pthreads_pthread_mutex_init+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lpthreads" >&5
printf %s "checking for pthread_mutex_init in -lpthreads... " >&6; }
if test ${ac_cv_lib_pthreads_pthread_mutex_init+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
LIBS="-lpthreads  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
   builtin and then its argument prototype would still apply.
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char pthread_mutex_init ();
char pthread_mutex_init (void);
int
main ()
main (void)
{
return pthread_mutex_init ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  ac_cv_lib_pthreads_pthread_mutex_init=yes
else
  ac_cv_lib_pthreads_pthread_mutex_init=no
else case e in #(
  e) ac_cv_lib_pthreads_pthread_mutex_init=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
LIBS=$ac_check_lib_save_LIBS ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthreads_pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_pthreads_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_pthreads_pthread_mutex_init" = xyes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthreads_pthread_mutex_init" >&5
printf "%s\n" "$ac_cv_lib_pthreads_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_pthreads_pthread_mutex_init" = xyes
then :
  tcl_ok=yes
else
  tcl_ok=no
else case e in #(
  e) tcl_ok=no ;;
esac
fi

		if test "$tcl_ok" = "yes"; then
		    # The space is needed
		    THREADS_LIBS=" -lpthreads"
		else
		    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lc" >&5
$as_echo_n "checking for pthread_mutex_init in -lc... " >&6; }
if ${ac_cv_lib_c_pthread_mutex_init+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
		    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lc" >&5
printf %s "checking for pthread_mutex_init in -lc... " >&6; }
if test ${ac_cv_lib_c_pthread_mutex_init+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
LIBS="-lc  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
   builtin and then its argument prototype would still apply.
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char pthread_mutex_init ();
char pthread_mutex_init (void);
int
main ()
main (void)
{
return pthread_mutex_init ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  ac_cv_lib_c_pthread_mutex_init=yes
else
  ac_cv_lib_c_pthread_mutex_init=no
else case e in #(
  e) ac_cv_lib_c_pthread_mutex_init=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
LIBS=$ac_check_lib_save_LIBS ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_c_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_c_pthread_mutex_init" = xyes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_pthread_mutex_init" >&5
printf "%s\n" "$ac_cv_lib_c_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_c_pthread_mutex_init" = xyes
then :
  tcl_ok=yes
else
  tcl_ok=no
else case e in #(
  e) tcl_ok=no ;;
esac
fi

		    if test "$tcl_ok" = "no"; then
			{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lc_r" >&5
$as_echo_n "checking for pthread_mutex_init in -lc_r... " >&6; }
if ${ac_cv_lib_c_r_pthread_mutex_init+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for pthread_mutex_init in -lc_r" >&5
printf %s "checking for pthread_mutex_init in -lc_r... " >&6; }
if test ${ac_cv_lib_c_r_pthread_mutex_init+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
LIBS="-lc_r  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
   builtin and then its argument prototype would still apply.
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char pthread_mutex_init ();
char pthread_mutex_init (void);
int
main ()
main (void)
{
return pthread_mutex_init ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  ac_cv_lib_c_r_pthread_mutex_init=yes
else
  ac_cv_lib_c_r_pthread_mutex_init=no
else case e in #(
  e) ac_cv_lib_c_r_pthread_mutex_init=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
LIBS=$ac_check_lib_save_LIBS ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_r_pthread_mutex_init" >&5
$as_echo "$ac_cv_lib_c_r_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_c_r_pthread_mutex_init" = xyes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_c_r_pthread_mutex_init" >&5
printf "%s\n" "$ac_cv_lib_c_r_pthread_mutex_init" >&6; }
if test "x$ac_cv_lib_c_r_pthread_mutex_init" = xyes
then :
  tcl_ok=yes
else
  tcl_ok=no
else case e in #(
  e) tcl_ok=no ;;
esac
fi

			if test "$tcl_ok" = "yes"; then
			    # The space is needed
			    THREADS_LIBS=" -pthread"
			else
			    TCL_THREADS=0
			    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Do not know how to find pthread lib on your system - thread support disabled" >&5
$as_echo "$as_me: WARNING: Do not know how to find pthread lib on your system - thread support disabled" >&2;}
			    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Do not know how to find pthread lib on your system - thread support disabled" >&5
printf "%s\n" "$as_me: WARNING: Do not know how to find pthread lib on your system - thread support disabled" >&2;}
			fi
		    fi
		fi
	    fi
	fi
    else
	TCL_THREADS=0
    fi
    # Do checking message here to not mess up interleaved configure output
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for building with threads" >&5
$as_echo_n "checking for building with threads... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for building with threads" >&5
printf %s "checking for building with threads... " >&6; }
    if test "${TCL_THREADS}" = 1; then

$as_echo "#define TCL_THREADS 1" >>confdefs.h
printf "%s\n" "#define TCL_THREADS 1" >>confdefs.h

	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (default)" >&5
$as_echo "yes (default)" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes (default)" >&5
printf "%s\n" "yes (default)" >&6; }
    else
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
    fi
    # TCL_THREADS sanity checking.  See if our request for building with
    # threads is the same as the way Tcl was built.  If not, warn the user.
    case ${TCL_DEFS} in
	*THREADS=1*)
	    if test "${TCL_THREADS}" = "0"; then
		{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING:
    Building ${PACKAGE_NAME} without threads enabled, but building against Tcl
    that IS thread-enabled.  It is recommended to use --enable-threads." >&5
$as_echo "$as_me: WARNING:
printf "%s\n" "$as_me: WARNING:
    Building ${PACKAGE_NAME} without threads enabled, but building against Tcl
    that IS thread-enabled.  It is recommended to use --enable-threads." >&2;}
	    fi
	    ;;
    esac



#--------------------------------------------------------------------
# The statement below defines a collection of symbols related to
# building as a shared library instead of a static library.
#--------------------------------------------------------------------


    { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to build libraries" >&5
$as_echo_n "checking how to build libraries... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to build libraries" >&5
printf %s "checking how to build libraries... " >&6; }
    # Check whether --enable-shared was given.
if test "${enable_shared+set}" = set; then :
if test ${enable_shared+y}
then :
  enableval=$enable_shared; shared_ok=$enableval
else
  shared_ok=yes
else case e in #(
  e) shared_ok=yes ;;
esac
fi


    if test "${enable_shared+set}" = set; then
	enableval="$enable_shared"
	shared_ok=$enableval
    else
	shared_ok=yes
    fi

    # Check whether --enable-stubs was given.
if test "${enable_stubs+set}" = set; then :
if test ${enable_stubs+y}
then :
  enableval=$enable_stubs; stubs_ok=$enableval
else
  stubs_ok=yes
else case e in #(
  e) stubs_ok=yes ;;
esac
fi


    if test "${enable_stubs+set}" = set; then
	enableval="$enable_stubs"
	stubs_ok=$enableval
    else
	stubs_ok=yes
    fi

    # Stubs are always enabled for shared builds
    if test "$shared_ok" = "yes" ; then
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: shared" >&5
$as_echo "shared" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: shared" >&5
printf "%s\n" "shared" >&6; }
	SHARED_BUILD=1
        STUBS_BUILD=1
	STUBS_BUILD=1
    else
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: static" >&5
$as_echo "static" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: static" >&5
printf "%s\n" "static" >&6; }
	SHARED_BUILD=0

$as_echo "#define STATIC_BUILD 1" >>confdefs.h
printf "%s\n" "#define STATIC_BUILD 1" >>confdefs.h

        if test "$stubs_ok" = "yes" ; then
          STUBS_BUILD=1
        else
          STUBS_BUILD=0
        fi
	if test "$stubs_ok" = "yes" ; then
	  STUBS_BUILD=1
	else
	  STUBS_BUILD=0
	fi
    fi
    if test "${STUBS_BUILD}" = "1" ; then

$as_echo "#define USE_TCL_STUBS 1" >>confdefs.h
printf "%s\n" "#define USE_TCL_STUBS 1" >>confdefs.h


$as_echo "#define USE_TCLOO_STUBS 1" >>confdefs.h
printf "%s\n" "#define USE_TCLOO_STUBS 1" >>confdefs.h

      if test "${TEA_WINDOWINGSYSTEM}" != ""; then

$as_echo "#define USE_TK_STUBS 1" >>confdefs.h
printf "%s\n" "#define USE_TK_STUBS 1" >>confdefs.h

      fi
    fi





#--------------------------------------------------------------------
# This macro figures out what flags to use with the compiler/linker
# when building shared/static debug/optimized objects.  This information
# can be taken from the tclConfig.sh file, but this figures it all out.
#--------------------------------------------------------------------

if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args.
set dummy ${ac_tool_prefix}ranlib; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_RANLIB+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$RANLIB"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_RANLIB+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$RANLIB"; then
  ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
RANLIB=$ac_cv_prog_RANLIB
if test -n "$RANLIB"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
$as_echo "$RANLIB" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5
printf "%s\n" "$RANLIB" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_RANLIB"; then
  ac_ct_RANLIB=$RANLIB
  # Extract the first word of "ranlib", so it can be a program name with args.
set dummy ranlib; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_RANLIB+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_RANLIB"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_RANLIB+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_RANLIB"; then
  ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_RANLIB="ranlib"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB
if test -n "$ac_ct_RANLIB"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
$as_echo "$ac_ct_RANLIB" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5
printf "%s\n" "$ac_ct_RANLIB" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

  if test "x$ac_ct_RANLIB" = x; then
    RANLIB=":"
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    RANLIB=$ac_ct_RANLIB
  fi
else
  RANLIB="$ac_cv_prog_RANLIB"
fi




    # Step 0.a: Enable 64 bit support?

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if 64bit support is requested" >&5
$as_echo_n "checking if 64bit support is requested... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if 64bit support is requested" >&5
printf %s "checking if 64bit support is requested... " >&6; }
    # Check whether --enable-64bit was given.
if test "${enable_64bit+set}" = set; then :
if test ${enable_64bit+y}
then :
  enableval=$enable_64bit; do64bit=$enableval
else
  do64bit=no
else case e in #(
  e) do64bit=no ;;
esac
fi

    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $do64bit" >&5
$as_echo "$do64bit" >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $do64bit" >&5
printf "%s\n" "$do64bit" >&6; }

    # Step 0.b: Enable Solaris 64 bit VIS support?

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if 64bit Sparc VIS support is requested" >&5
$as_echo_n "checking if 64bit Sparc VIS support is requested... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if 64bit Sparc VIS support is requested" >&5
printf %s "checking if 64bit Sparc VIS support is requested... " >&6; }
    # Check whether --enable-64bit-vis was given.
if test "${enable_64bit_vis+set}" = set; then :
if test ${enable_64bit_vis+y}
then :
  enableval=$enable_64bit_vis; do64bitVIS=$enableval
else
  do64bitVIS=no
else case e in #(
  e) do64bitVIS=no ;;
esac
fi

    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $do64bitVIS" >&5
$as_echo "$do64bitVIS" >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $do64bitVIS" >&5
printf "%s\n" "$do64bitVIS" >&6; }
    # Force 64bit on with VIS
    if test "$do64bitVIS" = "yes"; then :
    if test "$do64bitVIS" = "yes"
then :
  do64bit=yes
fi

    # Step 0.c: Check if visibility support is available. Do this here so
    # that platform specific alternatives can be used below if this fails.

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler supports visibility \"hidden\"" >&5
$as_echo_n "checking if compiler supports visibility \"hidden\"... " >&6; }
if ${tcl_cv_cc_visibility_hidden+:} false; then :
  $as_echo_n "(cached) " >&6
else

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler supports visibility \"hidden\"" >&5
printf %s "checking if compiler supports visibility \"hidden\"... " >&6; }
if test ${tcl_cv_cc_visibility_hidden+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	hold_cflags=$CFLAGS; CFLAGS="$CFLAGS -Werror"
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

	    extern __attribute__((__visibility__("hidden"))) void f(void);
	    void f(void) {}
int
main ()
main (void)
{
f();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  tcl_cv_cc_visibility_hidden=yes
else
  tcl_cv_cc_visibility_hidden=no
else case e in #(
  e) tcl_cv_cc_visibility_hidden=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
	CFLAGS=$hold_cflags
	CFLAGS=$hold_cflags ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_visibility_hidden" >&5
$as_echo "$tcl_cv_cc_visibility_hidden" >&6; }
    if test $tcl_cv_cc_visibility_hidden = yes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_visibility_hidden" >&5
printf "%s\n" "$tcl_cv_cc_visibility_hidden" >&6; }
    if test $tcl_cv_cc_visibility_hidden = yes
then :


$as_echo "#define MODULE_SCOPE extern __attribute__((__visibility__(\"hidden\")))" >>confdefs.h
printf "%s\n" "#define MODULE_SCOPE extern __attribute__((__visibility__(\"hidden\")))" >>confdefs.h


$as_echo "#define HAVE_HIDDEN 1" >>confdefs.h
printf "%s\n" "#define HAVE_HIDDEN 1" >>confdefs.h


fi

    # Step 0.d: Disable -rpath support?

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if rpath support is requested" >&5
$as_echo_n "checking if rpath support is requested... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if rpath support is requested" >&5
printf %s "checking if rpath support is requested... " >&6; }
    # Check whether --enable-rpath was given.
if test "${enable_rpath+set}" = set; then :
if test ${enable_rpath+y}
then :
  enableval=$enable_rpath; doRpath=$enableval
else
  doRpath=yes
else case e in #(
  e) doRpath=yes ;;
esac
fi

    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $doRpath" >&5
$as_echo "$doRpath" >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $doRpath" >&5
printf "%s\n" "$doRpath" >&6; }

    # Set the variable "system" to hold the name and version number
    # for the system.


    { $as_echo "$as_me:${as_lineno-$LINENO}: checking system version" >&5
$as_echo_n "checking system version... " >&6; }
if ${tcl_cv_sys_version+:} false; then :
  $as_echo_n "(cached) " >&6
else

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking system version" >&5
printf %s "checking system version... " >&6; }
if test ${tcl_cv_sys_version+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	# TEA specific:
	if test "${TEA_PLATFORM}" = "windows" ; then
	    tcl_cv_sys_version=windows
	else
	    tcl_cv_sys_version=`uname -s`-`uname -r`
	    if test "$?" -ne 0 ; then
		{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: can't find uname command" >&5
$as_echo "$as_me: WARNING: can't find uname command" >&2;}
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: can't find uname command" >&5
printf "%s\n" "$as_me: WARNING: can't find uname command" >&2;}
		tcl_cv_sys_version=unknown
	    else
		if test "`uname -s`" = "AIX" ; then
		    tcl_cv_sys_version=AIX-`uname -v`.`uname -r`
		fi
		if test "`uname -s`" = "NetBSD" -a -f /etc/debian_version ; then
		    tcl_cv_sys_version=NetBSD-Debian
		fi
	    fi
	fi

     ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_sys_version" >&5
$as_echo "$tcl_cv_sys_version" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_sys_version" >&5
printf "%s\n" "$tcl_cv_sys_version" >&6; }
    system=$tcl_cv_sys_version


    # Require ranlib early so we can override it in special cases below.



5987
5988
5989
5990
5991
5992
5993
5994


5995
5996
5997
5998
5999
6000


6001
6002
6003


6004
6005
6006
6007
6008
6009
6010
6011
6012
6013







6014
6015
6016
6017
6018
6019

6020




6021
6022

6023
6024

6025
6026
6027
6028
6029
6030
6031


6032
6033
6034
6035
6036


6037
6038
6039


6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053







6054
6055
6056
6057
6058
6059

6060




6061
6062

6063
6064

6065
6066
6067
6068
6069
6070
6071


6072
6073
6074
6075
6076


6077
6078
6079


6080
6081
6082
6083
6084
6085
6086
6087
6088


6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099


6100
6101
6102



6103
6104
6105
6106
6107
6108
6109
6110
6111
6112



6113
6114
6115
6116
6117
6118
6119
6120

6121
6122

6123
6124
6125
6126
6127




6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142




6143
6144

6145
6146
6147
6148
6149
6150
6151
6648
6649
6650
6651
6652
6653
6654

6655
6656
6657
6658
6659
6660


6661
6662
6663
6664

6665
6666
6667
6668
6669
6670






6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684

6685
6686
6687
6688
6689

6690
6691

6692
6693
6694
6695
6696
6697
6698

6699
6700
6701
6702
6703


6704
6705
6706


6707
6708
6709
6710
6711
6712
6713
6714
6715
6716






6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730

6731
6732
6733
6734
6735

6736
6737

6738
6739
6740
6741
6742
6743
6744

6745
6746
6747
6748
6749


6750
6751
6752


6753
6754
6755
6756
6757
6758
6759
6760
6761


6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773

6774
6775
6776


6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799

6800
6801

6802
6803




6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818




6819
6820
6821
6822
6823

6824
6825
6826
6827
6828
6829
6830
6831







-
+
+




-
-
+
+


-
+
+




-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+








-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+







-
-
+
+










-
+
+

-
-
+
+
+










+
+
+







-
+

-
+

-
-
-
-
+
+
+
+











-
-
-
-
+
+
+
+

-
+







    LDFLAGS_ARCH=""
    UNSHARED_LIB_SUFFIX=""
    # TEA specific: use PACKAGE_VERSION instead of VERSION
    TCL_TRIM_DOTS='`echo ${PACKAGE_VERSION} | tr -d .`'
    ECHO_VERSION='`echo ${PACKAGE_VERSION}`'
    TCL_LIB_VERSIONS_OK=ok
    CFLAGS_DEBUG=-g
    if test "$GCC" = yes; then :
    if test "$GCC" = yes
then :

	CFLAGS_OPTIMIZE=-O2
	CFLAGS_WARNING="-Wall"

else

else case e in #(
  e)
	CFLAGS_OPTIMIZE=-O
	CFLAGS_WARNING=""

     ;;
esac
fi
    if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}ar", so it can be a program name with args.
set dummy ${ac_tool_prefix}ar; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_AR+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$AR"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_AR+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$AR"; then
  ac_cv_prog_AR="$AR" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_AR="${ac_tool_prefix}ar"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
AR=$ac_cv_prog_AR
if test -n "$AR"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
$as_echo "$AR" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AR" >&5
printf "%s\n" "$AR" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_AR"; then
  ac_ct_AR=$AR
  # Extract the first word of "ar", so it can be a program name with args.
set dummy ar; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_AR+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_AR"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_AR+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_AR"; then
  ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_AR="ar"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
ac_ct_AR=$ac_cv_prog_ac_ct_AR
if test -n "$ac_ct_AR"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
$as_echo "$ac_ct_AR" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5
printf "%s\n" "$ac_ct_AR" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

  if test "x$ac_ct_AR" = x; then
    AR=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    AR=$ac_ct_AR
  fi
else
  AR="$ac_cv_prog_AR"
fi

    STLIB_LD='${AR} cr'
    LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH"
    if test "x$SHLIB_VERSION" = x; then :
    if test "x$SHLIB_VERSION" = x
then :
  SHLIB_VERSION=""
else
  SHLIB_VERSION=".$SHLIB_VERSION"
else case e in #(
  e) SHLIB_VERSION=".$SHLIB_VERSION" ;;
esac
fi
    case $system in
	# TEA specific:
	windows)
	    MACHINE="X86"
	    if test "$do64bit" != "no" ; then
		case "$do64bit" in
		    amd64|x64|yes)
			MACHINE="AMD64" ; # default to AMD64 64-bit build
			;;
		    arm64|aarch64)
			MACHINE="ARM64"
			;;
		    ia64)
			MACHINE="IA64"
			;;
		esac
	    fi

	    if test "$GCC" != "yes" ; then
	        if test "${SHARED_BUILD}" = "0" ; then
		if test "${SHARED_BUILD}" = "0" ; then
		    runtime=-MT
	        else
		else
		    runtime=-MD
	        fi
	        case "x`echo \${VisualStudioVersion}`" in
	            x1[4-9]*)
		        lflags="${lflags} -nodefaultlib:libucrt.lib"
		fi
		case "x`echo \${VisualStudioVersion}`" in
		    x1[4-9]*)
			lflags="${lflags} -nodefaultlib:ucrt.lib"

    vars="ucrt.lib"
    for i in $vars; do
	if test "${TEA_PLATFORM}" = "windows" -a "$GCC" = "yes" ; then
	    # Convert foo.lib to -lfoo for GCC.  No-op if not *.lib
	    i=`echo "$i" | sed -e 's/^\([^-].*\)\.[lL][iI][bB]$/-l\1/'`
	fi
	PKG_LIBS="$PKG_LIBS $i"
    done


	            ;;
	            *)
	            ;;
	        esac
		    ;;
		    *)
		    ;;
		esac

                if test "$do64bit" != "no" ; then
		if test "$do64bit" != "no" ; then
		    CC="cl.exe"
		    RC="rc.exe"
		    lflags="${lflags} -nologo -MACHINE:${MACHINE} "
		    LINKBIN="link.exe"
		    CFLAGS_DEBUG="-nologo -Zi -Od -W3 ${runtime}d"
		    CFLAGS_OPTIMIZE="-nologo -O2 -W2 ${runtime}"
		    # Avoid 'unresolved external symbol __security_cookie'
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183







6184
6185
6186
6187
6188
6189

6190




6191
6192

6193
6194

6195
6196
6197
6198
6199
6200
6201


6202
6203
6204
6205
6206


6207
6208
6209


6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223







6224
6225
6226
6227
6228
6229

6230




6231
6232

6233
6234

6235
6236
6237
6238
6239
6240
6241


6242
6243
6244
6245
6246


6247
6248
6249


6250
6251
6252
6253
6254
6255
6256
6257
6258


6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279







6280
6281
6282
6283
6284
6285
6286
6287

6288
6289
6290
6291
6292
6293
6294


6295
6296
6297



6298
6299
6300



6301
6302
6303


6304
6305
6306
6307
6308
6309
6310
6311
6312







6313
6314
6315
6316
6317
6318
6319
6851
6852
6853
6854
6855
6856
6857






6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871

6872
6873
6874
6875
6876

6877
6878

6879
6880
6881
6882
6883
6884
6885

6886
6887
6888
6889
6890


6891
6892
6893


6894
6895
6896
6897
6898
6899
6900
6901
6902
6903






6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917

6918
6919
6920
6921
6922

6923
6924

6925
6926
6927
6928
6929
6930
6931

6932
6933
6934
6935
6936


6937
6938
6939


6940
6941
6942
6943
6944
6945
6946
6947
6948


6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965






6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979

6980
6981
6982
6983
6984
6985
6986

6987
6988
6989


6990
6991
6992
6993


6994
6995
6996
6997


6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022







-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+








-
-
-
-
-
-
+
+
+
+
+
+
+






+
-
+
+
+
+

-
+

-
+






-
+
+



-
-
+
+

-
-
+
+







-
-
+
+















-
-
-
-
-
-
+
+
+
+
+
+
+







-
+






-
+
+

-
-
+
+
+

-
-
+
+
+

-
-
+
+









+
+
+
+
+
+
+







	    fi

	    if test "$GCC" = "yes"; then
		# mingw gcc mode
		if test -n "$ac_tool_prefix"; then
  # Extract the first word of "${ac_tool_prefix}windres", so it can be a program name with args.
set dummy ${ac_tool_prefix}windres; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_RC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$RC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_RC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$RC"; then
  ac_cv_prog_RC="$RC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_RC="${ac_tool_prefix}windres"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
RC=$ac_cv_prog_RC
if test -n "$RC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RC" >&5
$as_echo "$RC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RC" >&5
printf "%s\n" "$RC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi


fi
if test -z "$ac_cv_prog_RC"; then
  ac_ct_RC=$RC
  # Extract the first word of "windres", so it can be a program name with args.
set dummy windres; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_ac_ct_RC+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test -n "$ac_ct_RC"; then
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
printf %s "checking for $ac_word... " >&6; }
if test ${ac_cv_prog_ac_ct_RC+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -n "$ac_ct_RC"; then
  ac_cv_prog_ac_ct_RC="$ac_ct_RC" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_exec_ext in '' $ac_executable_extensions; do
  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
  if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then
    ac_cv_prog_ac_ct_RC="windres"
    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5
    break 2
  fi
done
  done
IFS=$as_save_IFS

fi
fi ;;
esac
fi
ac_ct_RC=$ac_cv_prog_ac_ct_RC
if test -n "$ac_ct_RC"; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RC" >&5
$as_echo "$ac_ct_RC" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RC" >&5
printf "%s\n" "$ac_ct_RC" >&6; }
else
  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
fi

  if test "x$ac_ct_RC" = x; then
    RC=""
  else
    case $cross_compiling:$ac_tool_warned in
yes:)
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
ac_tool_warned=yes ;;
esac
    RC=$ac_ct_RC
  fi
else
  RC="$ac_cv_prog_RC"
fi

		CFLAGS_DEBUG="-g"
		CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer"
		SHLIB_LD='${CC} -shared'
		UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.a'
		LDFLAGS_CONSOLE="-wl,--subsystem,console ${lflags}"
		LDFLAGS_WINDOW="-wl,--subsystem,windows ${lflags}"

		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for cross-compile version of gcc" >&5
$as_echo_n "checking for cross-compile version of gcc... " >&6; }
if ${ac_cv_cross+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cross-compile version of gcc" >&5
printf %s "checking for cross-compile version of gcc... " >&6; }
if test ${ac_cv_cross+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

			    #ifdef _WIN32
				#error cross-compiler
			    #endif

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  ac_cv_cross=yes
else
  ac_cv_cross=no
else case e in #(
  e) ac_cv_cross=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
		       ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cross" >&5
$as_echo "$ac_cv_cross" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cross" >&5
printf "%s\n" "$ac_cv_cross" >&6; }
		      if test "$ac_cv_cross" = "yes"; then
			case "$do64bit" in
			    amd64|x64|yes)
				CC="x86_64-w64-mingw32-${CC}"
				LD="x86_64-w64-mingw32-ld"
				AR="x86_64-w64-mingw32-ar"
				RANLIB="x86_64-w64-mingw32-ranlib"
				RC="x86_64-w64-mingw32-windres"
			    ;;
			    arm64|aarch64)
				CC="aarch64-w64-mingw32-clang"
				LD="aarch64-w64-mingw32-ld"
				AR="aarch64-w64-mingw32-ar"
				RANLIB="aarch64-w64-mingw32-ranlib"
				RC="aarch64-w64-mingw32-windres"
			    ;;
			    *)
				CC="i686-w64-mingw32-${CC}"
				LD="i686-w64-mingw32-ld"
				AR="i686-w64-mingw32-ar"
				RANLIB="i686-w64-mingw32-ranlib"
				RC="i686-w64-mingw32-windres"
			    ;;
6337
6338
6339
6340
6341
6342
6343
6344

6345
6346


6347
6348
6349
6350
6351
6352
6353
6354
6355

6356
6357
6358
6359


6360
6361
6362
6363
6364
6365
6366
6367
6368
6369


6370
6371


6372
6373
6374


6375
6376
6377


6378
6379
6380
6381
6382
6383
6384


6385
6386
6387
6388
6389


6390
6391
6392
6393


6394
6395
6396
6397
6398


6399
6400


6401
6402
6403
6404
6405
6406




6407
6408
6409
6410
6411


6412
6413
6414


6415
6416
6417
6418
6419


6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437







6438
6439
6440
6441
6442
6443
6444




6445
6446
6447
6448

6449
6450

6451
6452
6453
6454
6455
6456
6457


6458
6459
6460



6461
6462

6463
6464


6465
6466
6467
6468




6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488

6489
6490
6491



6492


6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516







6517
6518
6519
6520
6521
6522
6523




6524
6525
6526
6527

6528
6529

6530
6531
6532
6533
6534
6535
6536


6537
6538
6539



6540
6541

6542
6543


6544
6545
6546
6547




6548
6549
6550
6551
6552
6553
6554
6555

6556
6557
6558
6559
6560
6561


6562
6563
6564
6565
6566


6567
6568


6569
6570
6571
6572
6573
6574
6575







6576
6577
6578
6579
6580
6581
6582




6583
6584
6585
6586

6587
6588

6589
6590
6591
6592
6593
6594
6595


6596
6597
6598



6599
6600

6601
6602


6603
6604
6605
6606




6607
6608
6609



6610
6611
6612


6613
6614
6615
6616
6617
6618
6619
6620
6621
6622


6623
6624
6625
6626
6627
6628


6629
6630


6631
6632
6633
6634


6635
6636


6637
6638
6639
6640
6641
6642
6643


6644
6645
6646
6647
6648
6649
6650
6651


6652
6653
6654
6655
6656


6657
6658
6659
6660


6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671







6672
6673
6674
6675
6676
6677
6678




6679
6680
6681
6682

6683
6684

6685
6686
6687
6688
6689
6690
6691


6692
6693
6694



6695
6696

6697
6698


6699
6700
6701
6702




6703
6704
6705



6706
6707
6708


6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729


6730
6731
6732
6733
6734
6735
6736
6737
6738
6739


6740
6741
6742
6743
6744


6745
6746
6747
6748
6749
6750


6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761


6762
6763
6764
6765
6766
6767
6768


6769
6770
6771
6772
6773
6774
6775
6776


6777
6778


6779
6780
6781


6782
6783
6784
6785
6786
6787
6788
6789








6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807


6808
6809
6810
6811
6812
6813
6814
6815

6816
6817


6818
6819
6820
6821
6822


6823
6824
6825


6826
6827
6828
6829
6830
6831
6832







6833
6834
6835
6836
6837
6838
6839

6840
6841
6842
6843
6844
6845
6846


6847
6848
6849



6850
6851

6852
6853


6854
6855
6856
6857




6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872


6873
6874
6875
6876
6877
6878
6879
6880
6881
6882


6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900


6901
6902
6903
6904
6905
6906
6907
7040
7041
7042
7043
7044
7045
7046

7047
7048

7049
7050
7051
7052
7053
7054
7055
7056
7057
7058

7059
7060
7061


7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072

7073
7074
7075

7076
7077
7078


7079
7080
7081


7082
7083
7084
7085
7086
7087
7088
7089

7090
7091
7092
7093
7094
7095

7096
7097
7098
7099
7100

7101
7102
7103
7104
7105


7106
7107
7108

7109
7110
7111
7112
7113



7114
7115
7116
7117
7118
7119
7120


7121
7122
7123
7124

7125
7126
7127
7128
7129
7130

7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144






7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157

7158
7159
7160
7161
7162
7163
7164

7165
7166

7167
7168
7169
7170
7171
7172
7173

7174
7175
7176


7177
7178
7179
7180

7181
7182

7183
7184
7185



7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208

7209
7210
7211
7212
7213
7214
7215

7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235






7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248

7249
7250
7251
7252
7253
7254
7255

7256
7257

7258
7259
7260
7261
7262
7263
7264

7265
7266
7267


7268
7269
7270
7271

7272
7273

7274
7275
7276



7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287

7288
7289
7290
7291
7292
7293

7294
7295
7296
7297
7298


7299
7300
7301

7302
7303
7304






7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317

7318
7319
7320
7321
7322
7323
7324

7325
7326

7327
7328
7329
7330
7331
7332
7333

7334
7335
7336


7337
7338
7339
7340

7341
7342

7343
7344
7345



7346
7347
7348
7349
7350


7351
7352
7353
7354
7355

7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366

7367
7368
7369
7370
7371
7372


7373
7374
7375

7376
7377
7378
7379
7380

7381
7382
7383

7384
7385
7386
7387
7388
7389
7390
7391

7392
7393
7394
7395
7396
7397
7398
7399


7400
7401
7402
7403
7404


7405
7406
7407
7408
7409

7410
7411
7412
7413
7414
7415
7416






7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429

7430
7431
7432
7433
7434
7435
7436

7437
7438

7439
7440
7441
7442
7443
7444
7445

7446
7447
7448


7449
7450
7451
7452

7453
7454

7455
7456
7457



7458
7459
7460
7461
7462


7463
7464
7465
7466
7467

7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489

7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500

7501
7502
7503
7504
7505
7506

7507
7508
7509
7510
7511
7512


7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524

7525
7526
7527
7528
7529
7530
7531
7532

7533
7534
7535
7536
7537
7538
7539
7540
7541

7542
7543
7544

7545
7546
7547


7548
7549
7550







7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575

7576
7577
7578
7579
7580
7581
7582
7583
7584

7585
7586

7587
7588
7589
7590
7591
7592

7593
7594
7595
7596

7597
7598
7599






7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612

7613
7614
7615
7616
7617
7618
7619

7620
7621
7622


7623
7624
7625
7626

7627
7628

7629
7630
7631



7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649

7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660

7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679

7680
7681
7682
7683
7684
7685
7686
7687
7688







-
+

-
+
+








-
+


-
-
+
+









-
+
+

-
+
+

-
-
+
+

-
-
+
+






-
+
+




-
+
+



-
+
+



-
-
+
+

-
+
+



-
-
-
+
+
+
+



-
-
+
+


-
+
+




-
+
+












-
-
-
-
-
-
+
+
+
+
+
+
+






-
+
+
+
+



-
+

-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+



















-
+



+
+
+
-
+
+


















-
-
-
-
-
-
+
+
+
+
+
+
+






-
+
+
+
+



-
+

-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+







-
+





-
+
+



-
-
+
+

-
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+






-
+
+
+
+



-
+

-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+

-
-
+
+
+


-
+
+









-
+
+




-
-
+
+

-
+
+



-
+
+

-
+
+






-
+
+






-
-
+
+



-
-
+
+



-
+
+





-
-
-
-
-
-
+
+
+
+
+
+
+






-
+
+
+
+



-
+

-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+

-
-
+
+
+


-
+
+




















-
+
+









-
+
+




-
+
+




-
-
+
+










-
+
+






-
+
+







-
+
+

-
+
+

-
-
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

















-
+
+







-
+

-
+
+




-
+
+


-
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+






-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+














-
+
+









-
+
+

















-
+
+







		LDFLAGS_WINDOW="-link -subsystem:windows ${lflags}"
	    fi

	    SHLIB_SUFFIX=".dll"
	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.dll'

	    TCL_LIB_VERSIONS_OK=nodots
    	    ;;
	    ;;
	AIX-*)
	    if test "$GCC" != "yes"; then :
	    if test "$GCC" != "yes"
then :

		# AIX requires the _r compiler when gcc isn't being used
		case "${CC}" in
		    *_r|*_r\ *)
			# ok ...
			;;
		    *)
			# Make sure only first arg gets _r
		    	CC=`echo "$CC" | sed -e 's/^\([^ ]*\)/\1_r/'`
			CC=`echo "$CC" | sed -e 's/^\([^ ]*\)/\1_r/'`
			;;
		esac
		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Using $CC for compiling with threads" >&5
$as_echo "Using $CC for compiling with threads" >&6; }
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: Using $CC for compiling with threads" >&5
printf "%s\n" "Using $CC for compiling with threads" >&6; }

fi
	    LIBS="$LIBS -lc"
	    SHLIB_CFLAGS=""
	    SHLIB_SUFFIX=".so"

	    LD_LIBRARY_PATH_VAR="LIBPATH"

	    # Check to enable 64-bit flags for compiler/linker
	    if test "$do64bit" = yes; then :
	    if test "$do64bit" = yes
then :

		if test "$GCC" = yes; then :
		if test "$GCC" = yes
then :

		    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;}
		    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;}

else

else case e in #(
  e)
		    do64bit_ok=yes
		    CFLAGS="$CFLAGS -q64"
		    LDFLAGS_ARCH="-q64"
		    RANLIB="${RANLIB} -X64"
		    AR="${AR} -X64"
		    SHLIB_LD_FLAGS="-b64"

		 ;;
esac
fi

fi

	    if test "`uname -m`" = ia64; then :
	    if test "`uname -m`" = ia64
then :

		# AIX-5 uses ELF style dynamic libraries on IA-64, but not PPC
		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
		if test "$GCC" = yes; then :
		if test "$GCC" = yes
then :

		    CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"'

else

else case e in #(
  e)
		    CC_SEARCH_FLAGS='"-R${LIB_RUNTIME_DIR}"'

		 ;;
esac
fi
		LD_SEARCH_FLAGS='-R "${LIB_RUNTIME_DIR}"'

else

		if test "$GCC" = yes; then :
else case e in #(
  e)
		if test "$GCC" = yes
then :

		    SHLIB_LD='${CC} -shared -Wl,-bexpall'

else

else case e in #(
  e)
		    SHLIB_LD="/bin/ld -bhalt:4 -bM:SRE -bexpall -H512 -T512 -bnoentry"
		    LDFLAGS="$LDFLAGS -brtl"

		 ;;
esac
fi
		SHLIB_LD="${SHLIB_LD} ${SHLIB_LD_FLAGS}"
		CC_SEARCH_FLAGS='"-L${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}

	     ;;
esac
fi
	    ;;
	BeOS*)
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_LD='${CC} -nostart'
	    SHLIB_SUFFIX=".so"

	    #-----------------------------------------------------------
	    # Check for inet_ntoa in -lbind, for BeOS (which also needs
	    # -lsocket, even if the network functions are in -lnet which
	    # is always linked to, for compatibility.
	    #-----------------------------------------------------------
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lbind" >&5
$as_echo_n "checking for inet_ntoa in -lbind... " >&6; }
if ${ac_cv_lib_bind_inet_ntoa+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lbind" >&5
printf %s "checking for inet_ntoa in -lbind... " >&6; }
if test ${ac_cv_lib_bind_inet_ntoa+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
LIBS="-lbind  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
   builtin and then its argument prototype would still apply.
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char inet_ntoa ();
char inet_ntoa (void);
int
main ()
main (void)
{
return inet_ntoa ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  ac_cv_lib_bind_inet_ntoa=yes
else
  ac_cv_lib_bind_inet_ntoa=no
else case e in #(
  e) ac_cv_lib_bind_inet_ntoa=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
LIBS=$ac_check_lib_save_LIBS ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bind_inet_ntoa" >&5
$as_echo "$ac_cv_lib_bind_inet_ntoa" >&6; }
if test "x$ac_cv_lib_bind_inet_ntoa" = xyes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bind_inet_ntoa" >&5
printf "%s\n" "$ac_cv_lib_bind_inet_ntoa" >&6; }
if test "x$ac_cv_lib_bind_inet_ntoa" = xyes
then :
  LIBS="$LIBS -lbind -lsocket"
fi

	    ;;
	BSD/OS-2.1*|BSD/OS-3*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD="shlicc -r"
	    SHLIB_SUFFIX=".so"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	BSD/OS-4.*)
	    SHLIB_CFLAGS="-export-dynamic -fPIC"
	    SHLIB_LD='${CC} -shared'
	    SHLIB_SUFFIX=".so"
	    LDFLAGS="$LDFLAGS -export-dynamic"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	CYGWIN_*)
	CYGWIN_*|MINGW32_*|MINGW64_*|MSYS_*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD='${CC} -shared'
	    SHLIB_SUFFIX=".dll"
	    if test "${TEA_PLATFORM}" = "unix" -a  "${TCL_MAJOR_VERSION}" -gt 8 -a x"${with_tcl8}" = x; then
		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\$(patsubst cyg%.dll,lib%.dll,\$@).a"
	    else
	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\[email protected]"
		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -Wl,--out-implib,\[email protected]"
	    fi
	    EXEEXT=".exe"
	    do64bit_ok=yes
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	dgux*)
	    SHLIB_CFLAGS="-K PIC"
	    SHLIB_LD='${CC} -G'
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	Haiku*)
	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_SUFFIX=".so"
	    SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS} -shared'
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lnetwork" >&5
$as_echo_n "checking for inet_ntoa in -lnetwork... " >&6; }
if ${ac_cv_lib_network_inet_ntoa+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa in -lnetwork" >&5
printf %s "checking for inet_ntoa in -lnetwork... " >&6; }
if test ${ac_cv_lib_network_inet_ntoa+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
LIBS="-lnetwork  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
   builtin and then its argument prototype would still apply.
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char inet_ntoa ();
char inet_ntoa (void);
int
main ()
main (void)
{
return inet_ntoa ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  ac_cv_lib_network_inet_ntoa=yes
else
  ac_cv_lib_network_inet_ntoa=no
else case e in #(
  e) ac_cv_lib_network_inet_ntoa=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
LIBS=$ac_check_lib_save_LIBS ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_network_inet_ntoa" >&5
$as_echo "$ac_cv_lib_network_inet_ntoa" >&6; }
if test "x$ac_cv_lib_network_inet_ntoa" = xyes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_network_inet_ntoa" >&5
printf "%s\n" "$ac_cv_lib_network_inet_ntoa" >&6; }
if test "x$ac_cv_lib_network_inet_ntoa" = xyes
then :
  LIBS="$LIBS -lnetwork"
fi

	    ;;
	HP-UX-*.11.*)
	    # Use updated header definitions where possible

$as_echo "#define _XOPEN_SOURCE_EXTENDED 1" >>confdefs.h
printf "%s\n" "#define _XOPEN_SOURCE_EXTENDED 1" >>confdefs.h

	    # TEA specific: Needed by Tcl, but not most extensions
	    #AC_DEFINE(_XOPEN_SOURCE, 1, [Do we want to use the XOPEN network library?])
	    #LIBS="$LIBS -lxnet"               # Use the XOPEN network library

	    if test "`uname -m`" = ia64; then :
	    if test "`uname -m`" = ia64
then :

		SHLIB_SUFFIX=".so"

else

else case e in #(
  e)
		SHLIB_SUFFIX=".sl"

	     ;;
esac
fi
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
$as_echo_n "checking for shl_load in -ldld... " >&6; }
if ${ac_cv_lib_dld_shl_load+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
printf %s "checking for shl_load in -ldld... " >&6; }
if test ${ac_cv_lib_dld_shl_load+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
LIBS="-ldld  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
   builtin and then its argument prototype would still apply.
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char shl_load ();
char shl_load (void);
int
main ()
main (void)
{
return shl_load ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  ac_cv_lib_dld_shl_load=yes
else
  ac_cv_lib_dld_shl_load=no
else case e in #(
  e) ac_cv_lib_dld_shl_load=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
LIBS=$ac_check_lib_save_LIBS ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
$as_echo "$ac_cv_lib_dld_shl_load" >&6; }
if test "x$ac_cv_lib_dld_shl_load" = xyes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
printf "%s\n" "$ac_cv_lib_dld_shl_load" >&6; }
if test "x$ac_cv_lib_dld_shl_load" = xyes
then :
  tcl_ok=yes
else
  tcl_ok=no
else case e in #(
  e) tcl_ok=no ;;
esac
fi

	    if test "$tcl_ok" = yes; then :
	    if test "$tcl_ok" = yes
then :

		SHLIB_CFLAGS="+z"
		SHLIB_LD="ld -b"
		LDFLAGS="$LDFLAGS -Wl,-E"
		CC_SEARCH_FLAGS='"-Wl,+s,+b,${LIB_RUNTIME_DIR}:."'
		LD_SEARCH_FLAGS='+s +b "${LIB_RUNTIME_DIR}:."'
		LD_LIBRARY_PATH_VAR="SHLIB_PATH"

fi
	    if test "$GCC" = yes; then :
	    if test "$GCC" = yes
then :

		SHLIB_LD='${CC} -shared'
		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}

else

else case e in #(
  e)
		CFLAGS="$CFLAGS -z"

	     ;;
esac
fi

	    # Check to enable 64-bit flags for compiler/linker
	    if test "$do64bit" = "yes"; then :
	    if test "$do64bit" = "yes"
then :

		if test "$GCC" = yes; then :
		if test "$GCC" = yes
then :

		    case `${CC} -dumpmachine` in
			hppa64*)
			    # 64-bit gcc in use.  Fix flags for GNU ld.
			    do64bit_ok=yes
			    SHLIB_LD='${CC} -shared'
			    if test $doRpath = yes; then :
			    if test $doRpath = yes
then :

				CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
fi
			    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
			    ;;
			*)
			    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;}
			    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;}
			    ;;
		    esac

else

else case e in #(
  e)
		    do64bit_ok=yes
		    CFLAGS="$CFLAGS +DD64"
		    LDFLAGS_ARCH="+DD64"

		 ;;
esac
fi

fi ;;
	HP-UX-*.08.*|HP-UX-*.09.*|HP-UX-*.10.*)
	    SHLIB_SUFFIX=".sl"
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
$as_echo_n "checking for shl_load in -ldld... " >&6; }
if ${ac_cv_lib_dld_shl_load+:} false; then :
  $as_echo_n "(cached) " >&6
else
  ac_check_lib_save_LIBS=$LIBS
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5
printf %s "checking for shl_load in -ldld... " >&6; }
if test ${ac_cv_lib_dld_shl_load+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) ac_check_lib_save_LIBS=$LIBS
LIBS="-ldld  $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
   builtin and then its argument prototype would still apply.
   The 'extern "C"' is for builds by C++ compilers;
   although this is not generally supported in C code supporting it here
   has little cost and some practical benefit (sr 110532).  */
#ifdef __cplusplus
extern "C"
#endif
char shl_load ();
char shl_load (void);
int
main ()
main (void)
{
return shl_load ();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  ac_cv_lib_dld_shl_load=yes
else
  ac_cv_lib_dld_shl_load=no
else case e in #(
  e) ac_cv_lib_dld_shl_load=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
LIBS=$ac_check_lib_save_LIBS ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
$as_echo "$ac_cv_lib_dld_shl_load" >&6; }
if test "x$ac_cv_lib_dld_shl_load" = xyes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5
printf "%s\n" "$ac_cv_lib_dld_shl_load" >&6; }
if test "x$ac_cv_lib_dld_shl_load" = xyes
then :
  tcl_ok=yes
else
  tcl_ok=no
else case e in #(
  e) tcl_ok=no ;;
esac
fi

	    if test "$tcl_ok" = yes; then :
	    if test "$tcl_ok" = yes
then :

		SHLIB_CFLAGS="+z"
		SHLIB_LD="ld -b"
		SHLIB_LD_LIBS=""
		LDFLAGS="$LDFLAGS -Wl,-E"
		CC_SEARCH_FLAGS='"-Wl,+s,+b,${LIB_RUNTIME_DIR}:."'
		LD_SEARCH_FLAGS='+s +b "${LIB_RUNTIME_DIR}:."'
		LD_LIBRARY_PATH_VAR="SHLIB_PATH"

fi ;;
	IRIX-5.*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD="ld -shared -rdata_shared"
	    SHLIB_SUFFIX=".so"
	    case " $LIBOBJS " in
  *" mkstemp.$ac_objext "* ) ;;
  *) LIBOBJS="$LIBOBJS mkstemp.$ac_objext"
 ;;
esac

	    if test $doRpath = yes; then :
	    if test $doRpath = yes
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS='-rpath "${LIB_RUNTIME_DIR}"'
fi
	    ;;
	IRIX-6.*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD="ld -n32 -shared -rdata_shared"
	    SHLIB_SUFFIX=".so"
	    if test $doRpath = yes; then :
	    if test $doRpath = yes
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS='-rpath "${LIB_RUNTIME_DIR}"'
fi
	    if test "$GCC" = yes; then :
	    if test "$GCC" = yes
then :

		CFLAGS="$CFLAGS -mabi=n32"
		LDFLAGS="$LDFLAGS -mabi=n32"

else

else case e in #(
  e)
		case $system in
		    IRIX-6.3)
			# Use to build 6.2 compatible binaries on 6.3.
			CFLAGS="$CFLAGS -n32 -D_OLD_TERMIOS"
			;;
		    *)
			CFLAGS="$CFLAGS -n32"
			;;
		esac
		LDFLAGS="$LDFLAGS -n32"

	     ;;
esac
fi
	    ;;
	IRIX64-6.*)
	    SHLIB_CFLAGS=""
	    SHLIB_LD="ld -n32 -shared -rdata_shared"
	    SHLIB_SUFFIX=".so"
	    if test $doRpath = yes; then :
	    if test $doRpath = yes
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS='-rpath "${LIB_RUNTIME_DIR}"'
fi

	    # Check to enable 64-bit flags for compiler/linker

	    if test "$do64bit" = yes; then :
	    if test "$do64bit" = yes
then :

	        if test "$GCC" = yes; then :
		if test "$GCC" = yes
then :

	            { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported by gcc" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported by gcc" >&2;}
		    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported by gcc" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported by gcc" >&2;}

else

	            do64bit_ok=yes
	            SHLIB_LD="ld -64 -shared -rdata_shared"
	            CFLAGS="$CFLAGS -64"
	            LDFLAGS_ARCH="-64"

else case e in #(
  e)
		    do64bit_ok=yes
		    SHLIB_LD="ld -64 -shared -rdata_shared"
		    CFLAGS="$CFLAGS -64"
		    LDFLAGS_ARCH="-64"
		 ;;
esac
fi

fi
	    ;;
	Linux*|GNU*|NetBSD-Debian|DragonFly-*|FreeBSD-*)
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_SUFFIX=".so"

	    # TEA specific:
	    CFLAGS_OPTIMIZE="-O2 -fomit-frame-pointer"

	    # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS
	    SHLIB_LD='${CC} ${CFLAGS} ${LDFLAGS_DEFAULT} -shared'
	    LDFLAGS="$LDFLAGS -Wl,--export-dynamic"

	    case $system in
	    DragonFly-*|FreeBSD-*)
		if test "${TCL_THREADS}" = "1"; then :
		if test "${TCL_THREADS}" = "1"
then :

		    # The -pthread needs to go in the LDFLAGS, not LIBS
		    LIBS=`echo $LIBS | sed s/-pthread//`
		    CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
		    LDFLAGS="$LDFLAGS $PTHREAD_LIBS"
fi
	    ;;
            esac
	    esac

	    if test $doRpath = yes; then :
	    if test $doRpath = yes
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
fi
	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	    if test "`uname -m`" = "alpha"; then :
	    if test "`uname -m`" = "alpha"
then :
  CFLAGS="$CFLAGS -mieee"
fi
	    if test $do64bit = yes; then :
	    if test $do64bit = yes
then :

		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -m64 flag" >&5
$as_echo_n "checking if compiler accepts -m64 flag... " >&6; }
if ${tcl_cv_cc_m64+:} false; then :
  $as_echo_n "(cached) " >&6
else

		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -m64 flag" >&5
printf %s "checking if compiler accepts -m64 flag... " >&6; }
if test ${tcl_cv_cc_m64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
		    hold_cflags=$CFLAGS
		    CFLAGS="$CFLAGS -m64"
		    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  tcl_cv_cc_m64=yes
else
  tcl_cv_cc_m64=no
else case e in #(
  e) tcl_cv_cc_m64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
		    CFLAGS=$hold_cflags
		    CFLAGS=$hold_cflags ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_m64" >&5
$as_echo "$tcl_cv_cc_m64" >&6; }
		if test $tcl_cv_cc_m64 = yes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_m64" >&5
printf "%s\n" "$tcl_cv_cc_m64" >&6; }
		if test $tcl_cv_cc_m64 = yes
then :

		    CFLAGS="$CFLAGS -m64"
		    do64bit_ok=yes

fi

fi

	    # The combo of gcc + glibc has a bug related to inlining of
	    # functions like strtod(). The -fno-builtin flag should address
	    # this problem but it does not work. The -fno-inline flag is kind
	    # of overkill but it works. Disable inlining only when one of the
	    # files in compat/*.c is being linked in.

	    if test x"${USE_COMPAT}" != x; then :
	    if test x"${USE_COMPAT}" != x
then :
  CFLAGS="$CFLAGS -fno-inline"
fi
	    ;;
	Lynx*)
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_SUFFIX=".so"
	    CFLAGS_OPTIMIZE=-02
	    SHLIB_LD='${CC} -shared'
	    LD_FLAGS="-Wl,--export-dynamic"
	    if test $doRpath = yes; then :
	    if test $doRpath = yes
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
fi
	    ;;
	OpenBSD-*)
	    arch=`arch -s`
	    case "$arch" in
	    alpha|sparc64)
		SHLIB_CFLAGS="-fPIC"
		;;
	    *)
		SHLIB_CFLAGS="-fpic"
		;;
	    esac
	    SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared'
	    SHLIB_SUFFIX=".so"
	    if test $doRpath = yes; then :
	    if test $doRpath = yes
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
fi
	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}.so${SHLIB_VERSION}'
	    LDFLAGS="$LDFLAGS -Wl,-export-dynamic"
	    CFLAGS_OPTIMIZE="-O2"
6915
6916
6917
6918
6919
6920
6921
6922


6923
6924
6925
6926
6927
6928
6929
7696
7697
7698
7699
7700
7701
7702

7703
7704
7705
7706
7707
7708
7709
7710
7711







-
+
+







	    ;;
	NetBSD-*)
	    # NetBSD has ELF and can use 'cc -shared' to build shared libs
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_LD='${CC} ${SHLIB_CFLAGS} -shared'
	    SHLIB_SUFFIX=".so"
	    LDFLAGS="$LDFLAGS -export-dynamic"
	    if test $doRpath = yes; then :
	    if test $doRpath = yes
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
fi
	    LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
	    # The -pthread needs to go in the CFLAGS, not LIBS
	    LIBS=`echo $LIBS | sed s/-pthread//`
	    CFLAGS="$CFLAGS -pthread"
6937
6938
6939
6940
6941
6942
6943
6944


6945
6946
6947
6948
6949
6950
6951
6952
6953







6954
6955
6956
6957
6958
6959
6960

6961
6962
6963
6964
6965
6966
6967


6968
6969
6970



6971
6972

6973
6974


6975
6976
6977
6978




6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990







6991
6992
6993
6994
6995
6996
6997

6998
6999
7000
7001
7002
7003
7004


7005
7006
7007



7008
7009

7010
7011


7012
7013
7014
7015




7016
7017
7018
7019
7020
7021
7022
7023


7024
7025
7026
7027


7028
7029
7030


7031
7032
7033
7034


7035
7036
7037





7038
7039
7040
7041
7042
7043







7044
7045

7046
7047
7048
7049
7050

7051
7052
7053
7054
7055
7056
7057
7058
7059
7060






7061
7062

7063
7064

7065
7066
7067
7068
7069

7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080



7081
7082
7083

7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113


7114
7115
7116

7117
7118
7119
7120
7121
7122
7123
7124
7125
7126


7127
7128


7129
7130
7131
7132
7133
7134
7135







7136
7137
7138
7139
7140
7141
7142
7143
7144
7145

7146
7147
7148
7149
7150
7151
7152


7153
7154
7155



7156
7157

7158
7159
7160
7161


7162
7163
7164


7165
7166
7167


7168
7169
7170
7171
7172
7173
7174







7175
7176
7177
7178
7179
7180
7181
7182
7183
7184

7185
7186
7187
7188
7189
7190
7191


7192
7193
7194



7195
7196

7197
7198
7199
7200


7201
7202
7203


7204
7205
7206
7207
7208


7209
7210
7211


7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222

7223
7224
7225
7226
7227
7228


7229
7230

7231
7232
7233
7234
7235





7236
7237
7238


7239
7240
7241
7242
7243


7244
7245
7246
7247




7248
7249
7250
7251
7252
7253


7254
7255
7256
7257
7258


7259
7260
7261


7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275


7276
7277
7278
7279
7280
7281


7282
7283
7284


7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299

7300
7301
7302

7303
7304
7305
7306
7307


7308
7309
7310
7311
7312
7313
7314


7315
7316
7317
7318


7319
7320
7321
7322
7323
7324
7325
7326

7327
7328
7329

7330
7331
7332
7333
7334
7335


7336
7337
7338


7339
7340


7341
7342


7343
7344
7345


7346
7347
7348


7349
7350
7351
7352
7353


7354
7355
7356
7357


7358
7359


7360
7361
7362
7363
7364
7365


7366
7367
7368


7369
7370
7371
7372


7373
7374
7375
7376



7377
7378


7379
7380
7381
7382
7383
7384
7385
7386
7387


7388
7389
7390
7391


7392
7393
7394
7395
7396
7397
7398
7399
7400
7401


7402
7403
7404
7405
7406
7407






7408
7409
7410
7411
7412
7413


7414
7415
7416
7417
7418


7419
7420


7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433



7434
7435
7436
7437
7438
7439


7440
7441
7442
7443
7444
7445


7446
7447
7448
7449
7450
7451
7452
7453
7454
7455


7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470







7471
7472
7473
7474
7475
7476
7477

7478
7479
7480
7481
7482
7483
7484


7485
7486
7487



7488
7489

7490
7491


7492
7493
7494
7495




7496
7497
7498
7499
7500
7501
7502
7503
7504
7505


7506
7507
7508


7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522


7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537


7538
7539
7540

7541
7542
7543
7544
7545


7546
7547
7548
7549
7550


7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562








7563
7564
7565


7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584


7585
7586
7587



7588
7589
7590


7591
7592
7593


7594
7595
7596


7597
7598
7599

7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614







7615
7616
7617
7618
7619
7620
7621
7622

7623
7624
7625
7626
7627
7628
7629
7630
7631


7632
7633
7634



7635
7636
7637



7638
7639
7640


7641
7642
7643

7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656







7657
7658
7659
7660
7661
7662
7663
7664
7665

7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676


7677
7678
7679



7680
7681
7682



7683
7684
7685


7686
7687
7688

7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702







7703
7704
7705
7706

7707
7708
7709
7710
7711
7712
7713
7714
7715
7716


7717
7718
7719



7720
7721
7722



7723
7724
7725


7726
7727
7728

7729
7730
7731
7732
7733



7734
7735

7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759


7760
7761
7762
7763
7764
7765





7766
7767
7768
7769

7770
7771
7772
7773
7774
7775
7776


7777
7778
7779


7780
7781
7782
7783
7784

7785
7786
7787
7788
7789
7790
7791


7792
7793
7794



7795
7796


7797
7798


7799
7800
7801
7802
7803

7804
7805
7806
7807

7808
7809
7810
7811
7812





7813
7814
7815
7816

7817
7818
7819
7820

7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838

7839
7840
7841
7842
7843
7844
7845
7846
7847

7848
7849

7850
7851
7852
7853
7854
7855
7856
7857
7858
7859


7860

7861
7862
7863

7864
7865

7866
7867
7868
7869
7870
7871
7872




7873
7874
7875



7876
7877
7878


7879
7880


7881
7882
7883
7884
7885
7886
7887

7888
7889
7890
7891
7892
7893
7894
7895

7896
7897

7898
7899

7900
7901

7902
7903
7904


7905
7906
7907


7908
7909
7910
7911
7912
7913
7914
7915
7916







7917
7918
7919
7920
7921
7922
7923

7924
7925
7926
7927
7928
7929
7930


7931
7932
7933



7934
7935

7936
7937
7938
7939

7940
7941
7942
7943

7944
7945
7946
7947


7948
7949
7950
7951
7952


7953
7954
7955


7956
7957
7958
7959
7960

7961
7962
7963


7964
7965
7966
7967
7968
7969


7970
7971
7972
7973

7974
7975
7976
7977


7978
7979









































































7980
7981
7982
7983
7984
7985







7986
7987
7988
7989
7990
7991

7992
7993
7994
7995
7996
7997
7998


7999
8000
8001



8002
8003


8004
8005
8006


8007
8008
8009

8010
8011
8012
8013
8014
8015
8016
8017
8018







8019
8020
8021
8022
8023
8024

8025
8026
8027

8028
8029
8030
8031
8032


8033
8034
8035



8036
8037


8038
8039
8040


8041
8042
8043

8044
8045
8046
8047
8048
8049
8050
8051
8052







8053
8054
8055
8056
8057

8058
8059
8060
8061
8062
8063
8064
8065


8066
8067
8068



8069
8070


8071
8072
8073


8074
8075
8076

8077
8078
8079

8080
8081
8082
8083
8084
8085









8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097







8098
8099
8100
8101
8102

8103
8104
8105
8106
8107
8108
8109
8110


8111
8112
8113



8114
8115


8116
8117
8118
8119
8120


8121
8122

8123
8124
8125


8126
8127
8128


8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141


8142
8143


8144
8145
8146



8147
8148
8149
8150
8151
8152
8153





8154
8155
8156
8157
8158
8159


8160
8161
8162
8163
8164
8165
8166
8167

8168
8169
8170
8171
8172
8173
8174


8175
8176
8177


8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190

8191
8192
8193
8194
8195
8196
8197
8198







































































































































8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212


8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223

8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243






















8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254


8255
8256
8257
8258
8259

8260



8261
8262

8263




8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276


8277

8278
8279


8280

8281
8282



8283


8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295


8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312


8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327














8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
















8345
8346
8347


8348
8349
8350



















































8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371


8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388


8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401

8402
8403
8404
8405
8406
8407
8408

8409
8410
8411
8412
8413
8414
8415
8416
8417
8418

8419
8420
8421
8422
8423
8424
8425
8426


8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441


8442
8443
8444
8445
8446
8447
8448
7719
7720
7721
7722
7723
7724
7725

7726
7727
7728
7729
7730






7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743

7744
7745
7746
7747
7748
7749
7750

7751
7752
7753


7754
7755
7756
7757

7758
7759

7760
7761
7762



7763
7764
7765
7766
7767
7768
7769
7770
7771
7772






7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785

7786
7787
7788
7789
7790
7791
7792

7793
7794
7795


7796
7797
7798
7799

7800
7801

7802
7803
7804



7805
7806
7807
7808
7809
7810
7811
7812
7813
7814


7815
7816
7817
7818


7819
7820
7821
7822

7823
7824
7825
7826
7827

7828
7829
7830
7831
7832
7833
7834
7835
7836
7837






7838
7839
7840
7841
7842
7843
7844
7845

7846
7847
7848
7849
7850

7851
7852
7853
7854
7855
7856
7857




7858
7859
7860
7861
7862
7863
7864

7865
7866

7867





7868


7869








7870
7871
7872



7873




7874





















7875
7876
7877

7878
7879
7880
7881

7882
7883
7884
7885
7886
7887
7888
7889
7890
7891

7892
7893
7894

7895
7896
7897






7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913

7914
7915
7916
7917
7918
7919
7920

7921
7922
7923


7924
7925
7926
7927

7928
7929
7930
7931

7932
7933
7934


7935
7936
7937
7938

7939
7940
7941






7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957

7958
7959
7960
7961
7962
7963
7964

7965
7966
7967


7968
7969
7970
7971

7972
7973
7974
7975

7976
7977
7978


7979
7980
7981
7982
7983
7984

7985
7986
7987


7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999

8000
8001
8002
8003
8004
8005

8006
8007
8008

8009
8010




8011
8012
8013
8014
8015
8016
8017

8018
8019
8020
8021
8022
8023

8024
8025
8026



8027
8028
8029
8030
8031
8032
8033
8034
8035

8036
8037
8038
8039
8040


8041
8042
8043
8044

8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059

8060
8061
8062
8063
8064
8065


8066
8067
8068
8069

8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085

8086
8087
8088

8089
8090
8091
8092
8093

8094
8095
8096
8097
8098
8099
8100


8101
8102
8103
8104
8105

8106
8107
8108
8109
8110
8111
8112
8113
8114

8115
8116
8117

8118
8119
8120
8121
8122
8123

8124
8125
8126
8127

8128
8129
8130

8131
8132
8133

8134
8135
8136


8137
8138
8139


8140
8141
8142
8143
8144
8145

8146
8147
8148
8149


8150
8151
8152

8153
8154
8155
8156
8157
8158


8159
8160
8161
8162

8163
8164
8165
8166
8167

8168
8169
8170
8171


8172
8173
8174
8175

8176
8177
8178
8179
8180
8181
8182
8183
8184


8185
8186
8187
8188


8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199

8200
8201
8202
8203




8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214

8215
8216
8217
8218
8219
8220

8221
8222
8223

8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236


8237
8238
8239
8240
8241
8242
8243
8244

8245
8246
8247
8248
8249
8250


8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261

8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272






8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285

8286
8287
8288
8289
8290
8291
8292

8293
8294
8295


8296
8297
8298
8299

8300
8301

8302
8303
8304



8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317

8318
8319
8320


8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335

8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351

8352
8353
8354
8355

8356
8357
8358
8359
8360

8361
8362
8363
8364
8365
8366

8367
8368
8369
8370
8371
8372
8373
8374






8375
8376
8377
8378
8379
8380
8381
8382
8383


8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403

8404
8405
8406


8407
8408
8409
8410
8411

8412
8413
8414
8415

8416
8417
8418


8419
8420
8421
8422

8423
8424
8425
8426
8427
8428
8429
8430
8431
8432






8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446

8447
8448
8449
8450
8451
8452
8453
8454
8455

8456
8457
8458


8459
8460
8461
8462


8463
8464
8465
8466


8467
8468
8469
8470

8471
8472
8473
8474
8475
8476
8477
8478






8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493

8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504

8505
8506
8507


8508
8509
8510
8511


8512
8513
8514
8515


8516
8517
8518
8519

8520
8521
8522
8523
8524
8525
8526
8527
8528






8529
8530
8531
8532
8533
8534
8535
8536
8537
8538

8539
8540
8541
8542
8543
8544
8545
8546
8547
8548

8549
8550
8551


8552
8553
8554
8555


8556
8557
8558
8559


8560
8561
8562
8563

8564
8565
8566
8567


8568
8569
8570
8571

8572
8573
8574

8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593


8594
8595
8596
8597




8598
8599
8600
8601
8602
8603
8604
8605

8606
8607
8608
8609
8610
8611
8612

8613
8614
8615


8616
8617
8618
8619
8620
8621

8622
8623
8624
8625
8626
8627
8628

8629
8630
8631


8632
8633
8634
8635

8636
8637
8638

8639
8640
8641
8642
8643
8644

8645
8646
8647
8648
8649
8650
8651




8652
8653
8654
8655
8656
8657
8658
8659

8660
8661



8662













8663
8664
8665
8666

8667









8668


8669










8670
8671
8672
8673
8674
8675

8676
8677

8678
8679
8680
8681
8682



8683
8684
8685
8686



8687
8688
8689



8690
8691


8692
8693







8694

8695




8696

8697
8698

8699
8700

8701
8702
8703
8704
8705


8706
8707
8708


8709
8710
8711
8712
8713






8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726

8727
8728
8729
8730
8731
8732
8733

8734
8735
8736


8737
8738
8739
8740

8741
8742
8743
8744

8745
8746
8747
8748

8749
8750
8751


8752
8753
8754
8755
8756
8757

8758
8759
8760
8761

8762
8763
8764
8765
8766
8767

8768
8769


8770
8771
8772
8773
8774
8775


8776
8777
8778
8779


8780

8781


8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858






8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870

8871
8872
8873
8874
8875
8876
8877

8878
8879
8880


8881
8882
8883
8884

8885
8886
8887


8888
8889
8890
8891

8892
8893
8894
8895






8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907

8908
8909
8910

8911
8912
8913
8914
8915

8916
8917
8918


8919
8920
8921
8922

8923
8924
8925


8926
8927
8928
8929

8930
8931
8932
8933






8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944

8945
8946
8947
8948
8949
8950
8951
8952

8953
8954
8955


8956
8957
8958
8959

8960
8961
8962


8963
8964
8965
8966

8967
8968
8969
8970
8971






8972
8973
8974
8975
8976
8977
8978
8979
8980


8981
8982

8983






8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994

8995
8996
8997
8998
8999
9000
9001
9002

9003
9004
9005


9006
9007
9008
9009

9010
9011
9012
9013
9014


9015
9016
9017

9018
9019


9020
9021
9022


9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035


9036
9037
9038

9039
9040
9041


9042
9043
9044
9045
9046
9047
9048
9049


9050
9051
9052
9053
9054
9055
9056
9057
9058


9059
9060
9061
9062
9063
9064
9065
9066
9067

9068
9069
9070
9071
9072
9073


9074
9075
9076


9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090

9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247

9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259

9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317

9318

9319
9320
9321
9322
9323
9324
9325
9326

9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345

9346
9347
9348
9349
9350

9351
9352
9353
9354
9355
9356

9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387


9388
9389
9390














9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
















9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422


9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497


9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514


9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528

9529
9530
9531
9532
9533
9534
9535

9536
9537
9538
9539
9540
9541
9542
9543
9544
9545

9546
9547
9548
9549
9550
9551
9552


9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567


9568
9569
9570
9571
9572
9573
9574
9575
9576







-
+
+



-
-
-
-
-
-
+
+
+
+
+
+
+






-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+






-
-
-
-
-
-
+
+
+
+
+
+
+






-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+






-
-
+
+


-
-
+
+


-
+
+



-
+
+



+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+

-
+




-
+






-
-
-
-
+
+
+
+
+
+

-
+

-
+
-
-
-
-
-
+
-
-

-
-
-
-
-
-
-
-
+
+
+
-
-
-
+
-
-
-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-



-
+
+


-
+









-
+
+

-
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+









-
+






-
+
+

-
-
+
+
+

-
+



-
+
+

-
-
+
+


-
+
+

-
-
-
-
-
-
+
+
+
+
+
+
+









-
+






-
+
+

-
-
+
+
+

-
+



-
+
+

-
-
+
+




-
+
+

-
-
+
+










-
+





-
+
+

-
+

-
-
-
-
+
+
+
+
+


-
+
+




-
+
+

-
-
-
+
+
+
+





-
+
+



-
-
+
+


-
+
+













-
+
+




-
-
+
+


-
+
+














-
+


-
+




-
+
+





-
-
+
+



-
+
+







-
+


-
+





-
+
+


-
+
+

-
+
+

-
+
+

-
-
+
+

-
-
+
+




-
+
+


-
-
+
+

-
+
+




-
-
+
+


-
+
+



-
+
+


-
-
+
+
+

-
+
+







-
-
+
+


-
-
+
+









-
+
+


-
-
-
-
+
+
+
+
+
+





-
+
+




-
+
+

-
+
+











-
-
+
+
+





-
+
+




-
-
+
+









-
+
+









-
-
-
-
-
-
+
+
+
+
+
+
+






-
+






-
+
+

-
-
+
+
+

-
+

-
+
+

-
-
-
+
+
+
+









-
+
+

-
-
+
+













-
+
+














-
+
+


-
+




-
+
+




-
+
+






-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
-
+
+


















-
+
+

-
-
+
+
+


-
+
+


-
+
+

-
-
+
+


-
+









-
-
-
-
-
-
+
+
+
+
+
+
+







-
+








-
+
+

-
-
+
+
+

-
-
+
+
+

-
-
+
+


-
+







-
-
-
-
-
-
+
+
+
+
+
+
+








-
+










-
+
+

-
-
+
+
+

-
-
+
+
+

-
-
+
+


-
+








-
-
-
-
-
-
+
+
+
+
+
+
+



-
+









-
+
+

-
-
+
+
+

-
-
+
+
+

-
-
+
+


-
+



-
-
+
+
+

-
+


-



















-
-
+
+


-
-
-
-
+
+
+
+
+



-
+






-
+
+

-
-
+
+




-
+






-
+
+

-
-
+
+
+

-
+
+

-
+
+




-
+




+

-
-
-
-
+
+
+
+
+



-
+

-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-




-
+
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+

+


-
+

-
+




-
-
-
+
+
+
+
-
-
-
+
+
+
-
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
+
-

-
-
-
-

-
+

-
+

-
+


+

-
-
+
+

-
-
+
+



-
-
-
-
-
-
+
+
+
+
+
+
+






-
+






-
+
+

-
-
+
+
+

-
+



-
+



-
+


-
-
+
+




-
+
+


-
+
+




-
+

-
-
+
+




-
-
+
+


-
-
+
-

-
-
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+





-
+






-
+
+

-
-
+
+
+

-
+
+

-
-
+
+


-
+



-
-
-
-
-
-
+
+
+
+
+
+
+





-
+


-
+




-
+
+

-
-
+
+
+

-
+
+

-
-
+
+


-
+



-
-
-
-
-
-
+
+
+
+
+
+
+




-
+







-
+
+

-
-
+
+
+

-
+
+

-
-
+
+


-
+



+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-


-

-
-
-
-
-
-
+
+
+
+
+
+
+




-
+







-
+
+

-
-
+
+
+

-
+
+



-
-
+
+

-
+

-
-
+
+

-
-
+
+











-
-
+
+

-
+
+

-
-
+
+
+





-
-
+
+
+
+
+




-
-
+
+







-
+





-
-
+
+

-
-
+
+












-
+








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+













-
+
+










-
+




















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+











+
+


-

-
+

+
+
+


+
-
+
+
+
+













+
+
-
+


+
+
-
+


+
+
+
-
+
+












+
+















-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



















-
-
+
+















-
-
+
+












-
+






-
+









-
+






-
-
+
+













-
-
+
+







	    # -mmacosx-version-min flags from CFLAGS to CPPFLAGS:
	    CPPFLAGS="${CPPFLAGS} `echo " ${CFLAGS}" | \
		awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \
		if ($i~/^(isysroot|mmacosx-version-min)/) print "-"$i}'`"
	    CFLAGS="`echo " ${CFLAGS}" | \
		awk 'BEGIN {FS=" +-";ORS=" "}; {for (i=2;i<=NF;i++) \
		if (!($i~/^(isysroot|mmacosx-version-min)/)) print "-"$i}'`"
	    if test $do64bit = yes; then :
	    if test $do64bit = yes
then :

		case `arch` in
		    ppc)
			{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch ppc64 flag" >&5
$as_echo_n "checking if compiler accepts -arch ppc64 flag... " >&6; }
if ${tcl_cv_cc_arch_ppc64+:} false; then :
  $as_echo_n "(cached) " >&6
else

			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch ppc64 flag" >&5
printf %s "checking if compiler accepts -arch ppc64 flag... " >&6; }
if test ${tcl_cv_cc_arch_ppc64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
			    hold_cflags=$CFLAGS
			    CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
			    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  tcl_cv_cc_arch_ppc64=yes
else
  tcl_cv_cc_arch_ppc64=no
else case e in #(
  e) tcl_cv_cc_arch_ppc64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
			    CFLAGS=$hold_cflags
			    CFLAGS=$hold_cflags ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_ppc64" >&5
$as_echo "$tcl_cv_cc_arch_ppc64" >&6; }
			if test $tcl_cv_cc_arch_ppc64 = yes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_ppc64" >&5
printf "%s\n" "$tcl_cv_cc_arch_ppc64" >&6; }
			if test $tcl_cv_cc_arch_ppc64 = yes
then :

			    CFLAGS="$CFLAGS -arch ppc64 -mpowerpc64 -mcpu=G5"
			    do64bit_ok=yes

fi;;
		    i386)
			{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch x86_64 flag" >&5
$as_echo_n "checking if compiler accepts -arch x86_64 flag... " >&6; }
if ${tcl_cv_cc_arch_x86_64+:} false; then :
  $as_echo_n "(cached) " >&6
else

			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiler accepts -arch x86_64 flag" >&5
printf %s "checking if compiler accepts -arch x86_64 flag... " >&6; }
if test ${tcl_cv_cc_arch_x86_64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
			    hold_cflags=$CFLAGS
			    CFLAGS="$CFLAGS -arch x86_64"
			    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  tcl_cv_cc_arch_x86_64=yes
else
  tcl_cv_cc_arch_x86_64=no
else case e in #(
  e) tcl_cv_cc_arch_x86_64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
			    CFLAGS=$hold_cflags
			    CFLAGS=$hold_cflags ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_x86_64" >&5
$as_echo "$tcl_cv_cc_arch_x86_64" >&6; }
			if test $tcl_cv_cc_arch_x86_64 = yes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cc_arch_x86_64" >&5
printf "%s\n" "$tcl_cv_cc_arch_x86_64" >&6; }
			if test $tcl_cv_cc_arch_x86_64 = yes
then :

			    CFLAGS="$CFLAGS -arch x86_64"
			    do64bit_ok=yes

fi;;
		    *)
			{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Don't know how enable 64-bit on architecture \`arch\`" >&5
$as_echo "$as_me: WARNING: Don't know how enable 64-bit on architecture \`arch\`" >&2;};;
			{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Don't know how enable 64-bit on architecture \`arch\`" >&5
printf "%s\n" "$as_me: WARNING: Don't know how enable 64-bit on architecture \`arch\`" >&2;};;
		esac

else

else case e in #(
  e)
		# Check for combined 32-bit and 64-bit fat build
		if echo "$CFLAGS " |grep -E -q -- '-arch (ppc64|x86_64) ' \
		    && echo "$CFLAGS " |grep -E -q -- '-arch (ppc|i386) '; then :
		    && echo "$CFLAGS " |grep -E -q -- '-arch (ppc|i386) '
then :

		    fat_32_64=yes
fi

	     ;;
esac
fi
	    # TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS
	    SHLIB_LD='${CC} -dynamiclib ${CFLAGS} ${LDFLAGS_DEFAULT}'
	    # TEA specific: link shlib with current and compatibility version flags
	    vers=`echo ${PACKAGE_VERSION} | sed -e 's/^\([0-9]\{1,5\}\)\(\(\.[0-9]\{1,3\}\)\{0,2\}\).*$/\1\2/p' -e d`
	    SHLIB_LD="${SHLIB_LD} -current_version ${vers:-0} -compatibility_version ${vers:-0}"
	    SHLIB_SUFFIX=".dylib"
	    LDFLAGS="$LDFLAGS -headerpad_max_install_names"
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if ld accepts -single_module flag" >&5
$as_echo_n "checking if ld accepts -single_module flag... " >&6; }
if ${tcl_cv_ld_single_module+:} false; then :
  $as_echo_n "(cached) " >&6
else

	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if ld accepts -search_paths_first flag" >&5
printf %s "checking if ld accepts -search_paths_first flag... " >&6; }
if test ${tcl_cv_ld_search_paths_first+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
		hold_ldflags=$LDFLAGS
		LDFLAGS="$LDFLAGS -dynamiclib -Wl,-single_module"
		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{
int i;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  tcl_cv_ld_single_module=yes
else
  tcl_cv_ld_single_module=no
if ac_fn_c_try_link "$LINENO"
then :
  tcl_cv_ld_search_paths_first=yes
else case e in #(
  e) tcl_cv_ld_search_paths_first=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
		LDFLAGS=$hold_ldflags
		LDFLAGS=$hold_ldflags ;;
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_single_module" >&5
$as_echo "$tcl_cv_ld_single_module" >&6; }
	    if test $tcl_cv_ld_single_module = yes; then :

esac
		SHLIB_LD="${SHLIB_LD} -Wl,-single_module"

fi
	    # TEA specific: link shlib with current and compatibility version flags
	    vers=`echo ${PACKAGE_VERSION} | sed -e 's/^\([0-9]\{1,5\}\)\(\(\.[0-9]\{1,3\}\)\{0,2\}\).*$/\1\2/p' -e d`
	    SHLIB_LD="${SHLIB_LD} -current_version ${vers:-0} -compatibility_version ${vers:-0}"
	    SHLIB_SUFFIX=".dylib"
	    LDFLAGS="$LDFLAGS -headerpad_max_install_names"
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking if ld accepts -search_paths_first flag" >&5
$as_echo_n "checking if ld accepts -search_paths_first flag... " >&6; }
if ${tcl_cv_ld_search_paths_first+:} false; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_search_paths_first" >&5
printf "%s\n" "$tcl_cv_ld_search_paths_first" >&6; }
	    if test $tcl_cv_ld_search_paths_first = yes
  $as_echo_n "(cached) " >&6
else

then :
		hold_ldflags=$LDFLAGS
		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"
		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
{
int i;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
  tcl_cv_ld_search_paths_first=yes
else
  tcl_cv_ld_search_paths_first=no
fi
rm -f core conftest.err conftest.$ac_objext \
    conftest$ac_exeext conftest.$ac_ext
		LDFLAGS=$hold_ldflags
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_search_paths_first" >&5
$as_echo "$tcl_cv_ld_search_paths_first" >&6; }
	    if test $tcl_cv_ld_search_paths_first = yes; then :

		LDFLAGS="$LDFLAGS -Wl,-search_paths_first"

fi
	    if test "$tcl_cv_cc_visibility_hidden" != yes; then :
	    if test "$tcl_cv_cc_visibility_hidden" != yes
then :


$as_echo "#define MODULE_SCOPE __private_extern__" >>confdefs.h
printf "%s\n" "#define MODULE_SCOPE __private_extern__" >>confdefs.h

		tcl_cv_cc_visibility_hidden=yes

fi
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    LD_LIBRARY_PATH_VAR="DYLD_LIBRARY_PATH"
	    # TEA specific: for combined 32 & 64 bit fat builds of Tk
	    # extensions, verify that 64-bit build is possible.
	    if test "$fat_32_64" = yes && test -n "${TK_BIN_DIR}"; then :
	    if test "$fat_32_64" = yes && test -n "${TK_BIN_DIR}"
then :

		if test "${TEA_WINDOWINGSYSTEM}" = x11; then :
		if test "${TEA_WINDOWINGSYSTEM}" = x11
then :

		    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit X11" >&5
$as_echo_n "checking for 64-bit X11... " >&6; }
if ${tcl_cv_lib_x11_64+:} false; then :
  $as_echo_n "(cached) " >&6
else

		    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for 64-bit X11" >&5
printf %s "checking for 64-bit X11... " >&6; }
if test ${tcl_cv_lib_x11_64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"'
			done
			CPPFLAGS="$CPPFLAGS -I/usr/X11R6/include"
			LDFLAGS="$LDFLAGS -L/usr/X11R6/lib -lX11"
			cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <X11/Xlib.h>
int
main ()
main (void)
{
XrmInitialize();
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  tcl_cv_lib_x11_64=yes
else
  tcl_cv_lib_x11_64=no
else case e in #(
  e) tcl_cv_lib_x11_64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    eval $v'="$hold_'$v'"'
			done
			done ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_x11_64" >&5
$as_echo "$tcl_cv_lib_x11_64" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_x11_64" >&5
printf "%s\n" "$tcl_cv_lib_x11_64" >&6; }

fi
		if test "${TEA_WINDOWINGSYSTEM}" = aqua; then :
		if test "${TEA_WINDOWINGSYSTEM}" = aqua
then :

		    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit Tk" >&5
$as_echo_n "checking for 64-bit Tk... " >&6; }
if ${tcl_cv_lib_tk_64+:} false; then :
  $as_echo_n "(cached) " >&6
else

		    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for 64-bit Tk" >&5
printf %s "checking for 64-bit Tk... " >&6; }
if test ${tcl_cv_lib_tk_64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    eval 'hold_'$v'="$'$v'";'$v'="`echo "$'$v' "|sed -e "s/-arch ppc / /g" -e "s/-arch i386 / /g"`"'
			done
			CPPFLAGS="$CPPFLAGS -DUSE_TCL_STUBS=1 -DUSE_TK_STUBS=1 ${TCL_INCLUDES} ${TK_INCLUDES}"
			LDFLAGS="$LDFLAGS ${TCL_STUB_LIB_SPEC} ${TK_STUB_LIB_SPEC}"
			cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <tk.h>
int
main ()
main (void)
{
Tk_InitStubs(NULL, "", 0);
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  tcl_cv_lib_tk_64=yes
else
  tcl_cv_lib_tk_64=no
else case e in #(
  e) tcl_cv_lib_tk_64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
			for v in CFLAGS CPPFLAGS LDFLAGS; do
			    eval $v'="$hold_'$v'"'
			done
			done ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_tk_64" >&5
$as_echo "$tcl_cv_lib_tk_64" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_lib_tk_64" >&5
printf "%s\n" "$tcl_cv_lib_tk_64" >&6; }

fi
		# remove 64-bit arch flags from CFLAGS et al. if configuration
		# does not support 64-bit.
		if test "$tcl_cv_lib_tk_64" = no -o "$tcl_cv_lib_x11_64" = no; then :
		if test "$tcl_cv_lib_tk_64" = no -o "$tcl_cv_lib_x11_64" = no
then :

		    { $as_echo "$as_me:${as_lineno-$LINENO}: Removing 64-bit architectures from compiler & linker flags" >&5
$as_echo "$as_me: Removing 64-bit architectures from compiler & linker flags" >&6;}
		    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: Removing 64-bit architectures from compiler & linker flags" >&5
printf "%s\n" "$as_me: Removing 64-bit architectures from compiler & linker flags" >&6;}
		    for v in CFLAGS CPPFLAGS LDFLAGS; do
			eval $v'="`echo "$'$v' "|sed -e "s/-arch ppc64 / /g" -e "s/-arch x86_64 / /g"`"'
		    done
fi

fi
	    ;;
	OS/390-*)
	    CFLAGS_OPTIMIZE=""		# Optimizer is buggy

$as_echo "#define _OE_SOCKETS 1" >>confdefs.h
printf "%s\n" "#define _OE_SOCKETS 1" >>confdefs.h

	    ;;
	OSF1-V*)
	    # Digital OSF/1
	    SHLIB_CFLAGS=""
	    if test "$SHARED_BUILD" = 1; then :
	    if test "$SHARED_BUILD" = 1
then :

	        SHLIB_LD='ld -shared -expect_unresolved "*"'
		SHLIB_LD='ld -shared -expect_unresolved "*"'

else

	        SHLIB_LD='ld -non_shared -expect_unresolved "*"'

else case e in #(
  e)
		SHLIB_LD='ld -non_shared -expect_unresolved "*"'
	     ;;
esac
fi
	    SHLIB_SUFFIX=".so"
	    if test $doRpath = yes; then :
	    if test $doRpath = yes
then :

		CC_SEARCH_FLAGS='"-Wl,-rpath,${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS='-rpath ${LIB_RUNTIME_DIR}'
fi
	    if test "$GCC" = yes; then :
	    if test "$GCC" = yes
then :
  CFLAGS="$CFLAGS -mieee"
else

		CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee"
else case e in #(
  e)
		CFLAGS="$CFLAGS -DHAVE_TZSET -std1 -ieee" ;;
esac
fi
	    # see pthread_intro(3) for pthread support on osf1, k.furukawa
	    CFLAGS="$CFLAGS -DHAVE_PTHREAD_ATTR_SETSTACKSIZE"
	    CFLAGS="$CFLAGS -DTCL_THREAD_STACK_MIN=PTHREAD_STACK_MIN*64"
	    LIBS=`echo $LIBS | sed s/-lpthreads//`
	    if test "$GCC" = yes; then :
	    if test "$GCC" = yes
then :

		LIBS="$LIBS -lpthread -lmach -lexc"

else

else case e in #(
  e)
		CFLAGS="$CFLAGS -pthread"
		LDFLAGS="$LDFLAGS -pthread"

	     ;;
esac
fi
	    ;;
	QNX-6*)
	    # QNX RTP
	    # This may work for all QNX, but it was only reported for v6.
	    SHLIB_CFLAGS="-fPIC"
	    SHLIB_LD="ld -Bshareable -x"
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	SCO_SV-3.2*)
	    if test "$GCC" = yes; then :
	    if test "$GCC" = yes
then :

		SHLIB_CFLAGS="-fPIC -melf"
		LDFLAGS="$LDFLAGS -melf -Wl,-Bexport"

else

else case e in #(
  e)
		SHLIB_CFLAGS="-Kpic -belf"
		LDFLAGS="$LDFLAGS -belf -Wl,-Bexport"

	     ;;
esac
fi
	    SHLIB_LD="ld -G"
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
	SunOS-5.[0-6])
	    # Careful to not let 5.10+ fall into this case

	    # Note: If _REENTRANT isn't defined, then Solaris
	    # won't define thread-safe library routines.


$as_echo "#define _REENTRANT 1" >>confdefs.h
printf "%s\n" "#define _REENTRANT 1" >>confdefs.h


$as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h
printf "%s\n" "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h


	    SHLIB_CFLAGS="-KPIC"
	    SHLIB_SUFFIX=".so"
	    if test "$GCC" = yes; then :
	    if test "$GCC" = yes
then :

		SHLIB_LD='${CC} -shared'
		CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}

else

else case e in #(
  e)
		SHLIB_LD="/usr/ccs/bin/ld -G -z text"
		CC_SEARCH_FLAGS='-R "${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}

	     ;;
esac
fi
	    ;;
	SunOS-5*)
	    # Note: If _REENTRANT isn't defined, then Solaris
	    # won't define thread-safe library routines.


$as_echo "#define _REENTRANT 1" >>confdefs.h
printf "%s\n" "#define _REENTRANT 1" >>confdefs.h


$as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h
printf "%s\n" "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h


	    SHLIB_CFLAGS="-KPIC"

	    # Check to enable 64-bit flags for compiler/linker
	    if test "$do64bit" = yes; then :
	    if test "$do64bit" = yes
then :

		arch=`isainfo`
		if test "$arch" = "sparcv9 sparc"; then :
		if test "$arch" = "sparcv9 sparc"
then :

		    if test "$GCC" = yes; then :
		    if test "$GCC" = yes
then :

			if test "`${CC} -dumpversion | awk -F. '{print $1}'`" -lt 3; then :
			if test "`${CC} -dumpversion | awk -F. '{print $1}'`" -lt 3
then :

			    { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC < 3.2 on $system" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported with GCC < 3.2 on $system" >&2;}
			    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC < 3.2 on $system" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported with GCC < 3.2 on $system" >&2;}

else

else case e in #(
  e)
			    do64bit_ok=yes
			    CFLAGS="$CFLAGS -m64 -mcpu=v9"
			    LDFLAGS="$LDFLAGS -m64 -mcpu=v9"
			    SHLIB_CFLAGS="-fPIC"

			 ;;
esac
fi

else

else case e in #(
  e)
			do64bit_ok=yes
			if test "$do64bitVIS" = yes; then :
			if test "$do64bitVIS" = yes
then :

			    CFLAGS="$CFLAGS -xarch=v9a"
			    LDFLAGS_ARCH="-xarch=v9a"

else

else case e in #(
  e)
			    CFLAGS="$CFLAGS -xarch=v9"
			    LDFLAGS_ARCH="-xarch=v9"

			 ;;
esac
fi
			# Solaris 64 uses this as well
			#LD_LIBRARY_PATH_VAR="LD_LIBRARY_PATH_64"

		     ;;
esac
fi

else
  if test "$arch" = "amd64 i386"; then :
else case e in #(
  e) if test "$arch" = "amd64 i386"
then :

		    if test "$GCC" = yes; then :
		    if test "$GCC" = yes
then :

			case $system in
			    SunOS-5.1[1-9]*|SunOS-5.[2-9][0-9]*)
				do64bit_ok=yes
				CFLAGS="$CFLAGS -m64"
				LDFLAGS="$LDFLAGS -m64";;
			    *)
				{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;};;
				{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported with GCC on $system" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported with GCC on $system" >&2;};;
			esac

else

else case e in #(
  e)
			do64bit_ok=yes
			case $system in
			    SunOS-5.1[1-9]*|SunOS-5.[2-9][0-9]*)
				CFLAGS="$CFLAGS -m64"
				LDFLAGS="$LDFLAGS -m64";;
			    *)
				CFLAGS="$CFLAGS -xarch=amd64"
				LDFLAGS="$LDFLAGS -xarch=amd64";;
			esac

		     ;;
esac
fi

else
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported for $arch" >&5
$as_echo "$as_me: WARNING: 64bit mode not supported for $arch" >&2;}
fi
else case e in #(
  e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit mode not supported for $arch" >&5
printf "%s\n" "$as_me: WARNING: 64bit mode not supported for $arch" >&2;} ;;
esac
fi ;;
esac
fi

fi

	    SHLIB_SUFFIX=".so"
	    if test "$GCC" = yes; then :
	    if test "$GCC" = yes
then :

		SHLIB_LD='${CC} -shared'
		CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS=${CC_SEARCH_FLAGS}
		if test "$do64bit_ok" = yes; then :
		if test "$do64bit_ok" = yes
then :

		    if test "$arch" = "sparcv9 sparc"; then :
		    if test "$arch" = "sparcv9 sparc"
then :

			# We need to specify -static-libgcc or we need to
			# add the path to the sparv9 libgcc.
			# JH: static-libgcc is necessary for core Tcl, but may
			# not be necessary for extensions.
			SHLIB_LD="$SHLIB_LD -m64 -mcpu=v9 -static-libgcc"
			# for finding sparcv9 libgcc, get the regular libgcc
			# path, remove so name and append 'sparcv9'
			#v9gcclibdir="`gcc -print-file-name=libgcc_s.so` | ..."
			#CC_SEARCH_FLAGS="${CC_SEARCH_FLAGS},-R,$v9gcclibdir"

else
  if test "$arch" = "amd64 i386"; then :
else case e in #(
  e) if test "$arch" = "amd64 i386"
then :

			# JH: static-libgcc is necessary for core Tcl, but may
			# not be necessary for extensions.
			SHLIB_LD="$SHLIB_LD -m64 -static-libgcc"

fi
fi ;;
esac
fi

fi

else

else case e in #(
  e)
		case $system in
		    SunOS-5.[1-9][0-9]*)
			# TEA specific: use LDFLAGS_DEFAULT instead of LDFLAGS
			SHLIB_LD='${CC} -G -z text ${LDFLAGS_DEFAULT}';;
		    *)
			SHLIB_LD='/usr/ccs/bin/ld -G -z text';;
		esac
		CC_SEARCH_FLAGS='"-Wl,-R,${LIB_RUNTIME_DIR}"'
		LD_SEARCH_FLAGS='-R "${LIB_RUNTIME_DIR}"'

	     ;;
esac
fi
	    ;;
	UNIX_SV* | UnixWare-5*)
	    SHLIB_CFLAGS="-KPIC"
	    SHLIB_LD='${CC} -G'
	    SHLIB_LD_LIBS=""
	    SHLIB_SUFFIX=".so"
	    # Some UNIX_SV* systems (unixware 1.1.2 for example) have linkers
	    # that don't grok the -Bexport option.  Test that it does.
	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld accepts -Bexport flag" >&5
$as_echo_n "checking for ld accepts -Bexport flag... " >&6; }
if ${tcl_cv_ld_Bexport+:} false; then :
  $as_echo_n "(cached) " >&6
else

	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld accepts -Bexport flag" >&5
printf %s "checking for ld accepts -Bexport flag... " >&6; }
if test ${tcl_cv_ld_Bexport+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
		hold_ldflags=$LDFLAGS
		LDFLAGS="$LDFLAGS -Wl,-Bexport"
		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{
int i;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
if ac_fn_c_try_link "$LINENO"
then :
  tcl_cv_ld_Bexport=yes
else
  tcl_cv_ld_Bexport=no
else case e in #(
  e) tcl_cv_ld_Bexport=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext \
rm -f core conftest.err conftest.$ac_objext conftest.beam \
    conftest$ac_exeext conftest.$ac_ext
	        LDFLAGS=$hold_ldflags
		LDFLAGS=$hold_ldflags ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_Bexport" >&5
$as_echo "$tcl_cv_ld_Bexport" >&6; }
	    if test $tcl_cv_ld_Bexport = yes; then :
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_ld_Bexport" >&5
printf "%s\n" "$tcl_cv_ld_Bexport" >&6; }
	    if test $tcl_cv_ld_Bexport = yes
then :

		LDFLAGS="$LDFLAGS -Wl,-Bexport"

fi
	    CC_SEARCH_FLAGS=""
	    LD_SEARCH_FLAGS=""
	    ;;
    esac

    if test "$do64bit" = yes -a "$do64bit_ok" = no; then :
    if test "$do64bit" = yes -a "$do64bit_ok" = no
then :

	{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 64bit support being disabled -- don't know magic for this platform" >&5
$as_echo "$as_me: WARNING: 64bit support being disabled -- don't know magic for this platform" >&2;}
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 64bit support being disabled -- don't know magic for this platform" >&5
printf "%s\n" "$as_me: WARNING: 64bit support being disabled -- don't know magic for this platform" >&2;}

fi



    # Add in the arch flags late to ensure it wasn't removed.
    # Not necessary in TEA, but this is aligned with core
    LDFLAGS="$LDFLAGS $LDFLAGS_ARCH"

    # If we're running gcc, then change the C flags for compiling shared
    # libraries to the right flags for gcc, instead of those for the
    # standard manufacturer compiler.

    if test "$GCC" = yes; then :
    if test "$GCC" = yes
then :

	case $system in
	    AIX-*) ;;
	    BSD/OS*) ;;
	    CYGWIN_*|MINGW32_*|MINGW64_*|MSYS_*) ;;
	    IRIX*) ;;
	    NetBSD-*|DragonFly-*|FreeBSD-*|OpenBSD-*) ;;
	    Darwin-*) ;;
	    SCO_SV-3.2*) ;;
	    windows) ;;
	    *) SHLIB_CFLAGS="-fPIC" ;;
	esac
fi

    if test "$tcl_cv_cc_visibility_hidden" != yes; then :
    if test "$tcl_cv_cc_visibility_hidden" != yes
then :


$as_echo "#define MODULE_SCOPE extern" >>confdefs.h
printf "%s\n" "#define MODULE_SCOPE extern" >>confdefs.h


fi

    if test "$SHARED_LIB_SUFFIX" = ""; then :
    if test "$SHARED_LIB_SUFFIX" = ""
then :

    # TEA specific: use PACKAGE_VERSION instead of VERSION
    SHARED_LIB_SUFFIX='${PACKAGE_VERSION}${SHLIB_SUFFIX}'
fi
    if test "$UNSHARED_LIB_SUFFIX" = ""; then :
    if test "$UNSHARED_LIB_SUFFIX" = ""
then :

    # TEA specific: use PACKAGE_VERSION instead of VERSION
    UNSHARED_LIB_SUFFIX='${PACKAGE_VERSION}.a'
fi

    if test "${GCC}" = "yes" -a ${SHLIB_SUFFIX} = ".dll"; then
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SEH support in compiler" >&5
$as_echo_n "checking for SEH support in compiler... " >&6; }
if ${tcl_cv_seh+:} false; then :
  $as_echo_n "(cached) " >&6
else
  if test "$cross_compiling" = yes; then :
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for SEH support in compiler" >&5
printf %s "checking for SEH support in compiler... " >&6; }
if test ${tcl_cv_seh+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test "$cross_compiling" = yes
then :
  tcl_cv_seh=no
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN

	    int main(int argc, char** argv) {
		int a, b = 0;
		__try {
		    a = 666 / b;
		}
		__except (EXCEPTION_EXECUTE_HANDLER) {
		    return 0;
		}
		return 1;
	    }

_ACEOF
if ac_fn_c_try_run "$LINENO"; then :
if ac_fn_c_try_run "$LINENO"
then :
  tcl_cv_seh=yes
else
  tcl_cv_seh=no
else case e in #(
  e) tcl_cv_seh=no ;;
esac
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
  conftest.$ac_objext conftest.beam conftest.$ac_ext
  conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi


	 ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_seh" >&5
$as_echo "$tcl_cv_seh" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_seh" >&5
printf "%s\n" "$tcl_cv_seh" >&6; }
	if test "$tcl_cv_seh" = "no" ; then

$as_echo "#define HAVE_NO_SEH 1" >>confdefs.h
printf "%s\n" "#define HAVE_NO_SEH 1" >>confdefs.h

	fi

	#
	# Check to see if the excpt.h include file provided contains the
	# definition for EXCEPTION_DISPOSITION; if not, which is the case
	# with Cygwin's version as of 2002-04-10, define it to be int,
	# sufficient for getting the current code to work.
	#
	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for EXCEPTION_DISPOSITION support in include files" >&5
$as_echo_n "checking for EXCEPTION_DISPOSITION support in include files... " >&6; }
if ${tcl_cv_eh_disposition+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for EXCEPTION_DISPOSITION support in include files" >&5
printf %s "checking for EXCEPTION_DISPOSITION support in include files... " >&6; }
if test ${tcl_cv_eh_disposition+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

#	    define WIN32_LEAN_AND_MEAN
#	    include <windows.h>
#	    undef WIN32_LEAN_AND_MEAN

int
main ()
main (void)
{

		EXCEPTION_DISPOSITION x;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_eh_disposition=yes
else
  tcl_cv_eh_disposition=no
else case e in #(
  e) tcl_cv_eh_disposition=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	 ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_eh_disposition" >&5
$as_echo "$tcl_cv_eh_disposition" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_eh_disposition" >&5
printf "%s\n" "$tcl_cv_eh_disposition" >&6; }
	if test "$tcl_cv_eh_disposition" = "no" ; then

$as_echo "#define EXCEPTION_DISPOSITION int" >>confdefs.h
printf "%s\n" "#define EXCEPTION_DISPOSITION int" >>confdefs.h

	fi

	# Check to see if winnt.h defines CHAR, SHORT, and LONG
	# even if VOID has already been #defined. The win32api
	# used by mingw and cygwin is known to do this.

	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for winnt.h that ignores VOID define" >&5
$as_echo_n "checking for winnt.h that ignores VOID define... " >&6; }
if ${tcl_cv_winnt_ignore_void+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for winnt.h that ignores VOID define" >&5
printf %s "checking for winnt.h that ignores VOID define... " >&6; }
if test ${tcl_cv_winnt_ignore_void+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

#define VOID void
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN

int
main ()
main (void)
{

		CHAR c;
		SHORT s;
		LONG l;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_winnt_ignore_void=yes
else
  tcl_cv_winnt_ignore_void=no
else case e in #(
  e) tcl_cv_winnt_ignore_void=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	 ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_winnt_ignore_void" >&5
$as_echo "$tcl_cv_winnt_ignore_void" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_winnt_ignore_void" >&5
printf "%s\n" "$tcl_cv_winnt_ignore_void" >&6; }
	if test "$tcl_cv_winnt_ignore_void" = "yes" ; then

$as_echo "#define HAVE_WINNT_IGNORE_VOID 1" >>confdefs.h
printf "%s\n" "#define HAVE_WINNT_IGNORE_VOID 1" >>confdefs.h

	fi
    fi

	# See if the compiler supports casting to a union type.
	# This is used to stop gcc from printing a compiler
	# warning when initializing a union member.

	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for cast to union support" >&5
$as_echo_n "checking for cast to union support... " >&6; }
if ${tcl_cv_cast_to_union+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cast to union support" >&5
printf %s "checking for cast to union support... " >&6; }
if test ${tcl_cv_cast_to_union+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{

		  union foo { int i; double d; };
		  union foo f = (union foo) (int) 0;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_cast_to_union=yes
else
  tcl_cv_cast_to_union=no
else case e in #(
  e) tcl_cv_cast_to_union=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	 ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cast_to_union" >&5
$as_echo "$tcl_cv_cast_to_union" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_cast_to_union" >&5
printf "%s\n" "$tcl_cv_cast_to_union" >&6; }
	if test "$tcl_cv_cast_to_union" = "yes"; then

$as_echo "#define HAVE_CAST_TO_UNION 1" >>confdefs.h
printf "%s\n" "#define HAVE_CAST_TO_UNION 1" >>confdefs.h

	fi

	ac_fn_c_check_header_mongrel "$LINENO" "stdbool.h" "ac_cv_header_stdbool_h" "$ac_includes_default"
if test "x$ac_cv_header_stdbool_h" = xyes; then :
	ac_fn_c_check_header_compile "$LINENO" "stdbool.h" "ac_cv_header_stdbool_h" "$ac_includes_default"
if test "x$ac_cv_header_stdbool_h" = xyes
then :

$as_echo "#define HAVE_STDBOOL_H 1" >>confdefs.h
printf "%s\n" "#define HAVE_STDBOOL_H 1" >>confdefs.h

fi

















    # These must be called after we do the basic CFLAGS checks and
    # verify any possible 64-bit or similar switches are necessary

    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for required early compiler flags" >&5
$as_echo_n "checking for required early compiler flags... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for required early compiler flags" >&5
printf %s "checking for required early compiler flags... " >&6; }
    tcl_flags=""

    if ${tcl_cv_flag__isoc99_source+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    if test ${tcl_cv_flag__isoc99_source+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <stdlib.h>
int
main ()
main (void)
{
char *p = (char *)strtoll; char *q = (char *)strtoull;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_flag__isoc99_source=no
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _ISOC99_SOURCE 1
#include <stdlib.h>
int
main ()
main (void)
{
char *p = (char *)strtoll; char *q = (char *)strtoull;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_flag__isoc99_source=yes
else
  tcl_cv_flag__isoc99_source=no
else case e in #(
  e) tcl_cv_flag__isoc99_source=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi

    if test "x${tcl_cv_flag__isoc99_source}" = "xyes" ; then

$as_echo "#define _ISOC99_SOURCE 1" >>confdefs.h
printf "%s\n" "#define _ISOC99_SOURCE 1" >>confdefs.h

	tcl_flags="$tcl_flags _ISOC99_SOURCE"
    fi

    if test "${TCL_MAJOR_VERSION}" -ne 8 ; then

    if ${tcl_cv_flag__largefile64_source+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    if test ${tcl_cv_flag__file_offset_bits+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/stat.h>
int
main ()
main (void)
{
struct stat64 buf; int i = stat64("/", &buf);
  ;
  return 0;
switch (0) { case 0: case (sizeof(off_t)==sizeof(long long)): ; }
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  tcl_cv_flag__largefile64_source=no
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _LARGEFILE64_SOURCE 1
#include <sys/stat.h>
int
main ()
{
struct stat64 buf; int i = stat64("/", &buf);
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
  tcl_cv_flag__largefile64_source=yes
else
  tcl_cv_flag__largefile64_source=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi

then :
    if test "x${tcl_cv_flag__largefile64_source}" = "xyes" ; then

  tcl_cv_flag__file_offset_bits=no
$as_echo "#define _LARGEFILE64_SOURCE 1" >>confdefs.h

	tcl_flags="$tcl_flags _LARGEFILE64_SOURCE"
    fi


    if ${tcl_cv_flag__largefile_source64+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
else case e in #(
  e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _FILE_OFFSET_BITS 64
#include <sys/stat.h>
int
main ()
main (void)
{
char *p = (char *)open64;
switch (0) { case 0: case (sizeof(off_t)==sizeof(long long)): ; }
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  tcl_cv_flag__largefile_source64=no
else
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_flag__file_offset_bits=yes
else case e in #(
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _LARGEFILE_SOURCE64 1
  e) tcl_cv_flag__file_offset_bits=no ;;
esac
fi
#include <sys/stat.h>
int
main ()
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
{
char *p = (char *)open64;
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  tcl_cv_flag__largefile_source64=yes
else
esac
  tcl_cv_flag__largefile_source64=no
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi

    if test "x${tcl_cv_flag__largefile_source64}" = "xyes" ; then
    if test "x${tcl_cv_flag__file_offset_bits}" = "xyes" ; then

$as_echo "#define _LARGEFILE_SOURCE64 1" >>confdefs.h
printf "%s\n" "#define _FILE_OFFSET_BITS 64" >>confdefs.h

	tcl_flags="$tcl_flags _LARGEFILE_SOURCE64"
	tcl_flags="$tcl_flags _FILE_OFFSET_BITS"
    fi

    fi
    if test "x${tcl_flags}" = "x" ; then
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5
$as_echo "none" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none" >&5
printf "%s\n" "none" >&6; }
    else
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${tcl_flags}" >&5
$as_echo "${tcl_flags}" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${tcl_flags}" >&5
printf "%s\n" "${tcl_flags}" >&6; }
    fi


    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for 64-bit integer type" >&5
$as_echo_n "checking for 64-bit integer type... " >&6; }
    if ${tcl_cv_type_64bit+:} false; then :
  $as_echo_n "(cached) " >&6
else

    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for 64-bit integer type" >&5
printf %s "checking for 64-bit integer type... " >&6; }
    if test ${tcl_cv_type_64bit+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	tcl_cv_type_64bit=none
	# See if the compiler knows natively about __int64
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{
__int64 value = (__int64) 0;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_type_64bit=__int64
else
  tcl_type_64bit="long long"
else case e in #(
  e) tcl_type_64bit="long long" ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext
	# See if we could use long anyway  Note that we substitute in the
	# type that is our current guess for a 64-bit type inside this check
	# program, so it should be modified only carefully...
        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

int
main ()
main (void)
{
switch (0) {
            case 1: case (sizeof(${tcl_type_64bit})==sizeof(long)): ;
        }
	    case 1: case (sizeof(${tcl_type_64bit})==sizeof(long)): ;
	}
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_type_64bit=${tcl_type_64bit}
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi

    if test "${tcl_cv_type_64bit}" = none ; then

$as_echo "#define TCL_WIDE_INT_IS_LONG 1" >>confdefs.h
printf "%s\n" "#define TCL_WIDE_INT_IS_LONG 1" >>confdefs.h

	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
    elif test "${tcl_cv_type_64bit}" = "__int64" \
		-a "${TEA_PLATFORM}" = "windows" ; then
	# TEA specific: We actually want to use the default tcl.h checks in
	# this case to handle both TCL_WIDE_INT_TYPE and TCL_LL_MODIFIER*
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: using Tcl header defaults" >&5
$as_echo "using Tcl header defaults" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: using Tcl header defaults" >&5
printf "%s\n" "using Tcl header defaults" >&6; }
    else

cat >>confdefs.h <<_ACEOF
#define TCL_WIDE_INT_TYPE ${tcl_cv_type_64bit}
printf "%s\n" "#define TCL_WIDE_INT_TYPE ${tcl_cv_type_64bit}" >>confdefs.h
_ACEOF

	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${tcl_cv_type_64bit}" >&5
$as_echo "${tcl_cv_type_64bit}" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${tcl_cv_type_64bit}" >&5
printf "%s\n" "${tcl_cv_type_64bit}" >&6; }

	# Now check for auxiliary declarations
    if test "${TCL_MAJOR_VERSION}" -ne 8 ; then
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for 64-bit time_t" >&5
printf %s "checking for 64-bit time_t... " >&6; }
if test ${tcl_cv_time_t_64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
int
main (void)
{
switch (0) {case 0: case (sizeof(time_t)==sizeof(long long)): ;}
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_time_t_64=yes
else case e in #(
  e) tcl_cv_time_t_64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_time_t_64" >&5
printf "%s\n" "$tcl_cv_time_t_64" >&6; }
	    if test "x${tcl_cv_time_t_64}" = "xno" ; then
		# Note that _TIME_BITS=64 requires _FILE_OFFSET_BITS=64
		# which SC_TCL_EARLY_FLAGS has defined if necessary.
		{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if _TIME_BITS=64 enables 64-bit time_t" >&5
printf %s "checking if _TIME_BITS=64 enables 64-bit time_t... " >&6; }
if test ${tcl_cv__time_bits+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
		    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#define _TIME_BITS 64
#include <sys/types.h>
int
main (void)
{
switch (0) {case 0: case (sizeof(time_t)==sizeof(long long)): ;}
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv__time_bits=yes
else case e in #(
  e) tcl_cv__time_bits=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv__time_bits" >&5
printf "%s\n" "$tcl_cv__time_bits" >&6; }
		if test "x${tcl_cv__time_bits}" = "xyes" ; then

printf "%s\n" "#define _TIME_BITS 64" >>confdefs.h

		fi
	    fi
	fi

	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct dirent64" >&5
$as_echo_n "checking for struct dirent64... " >&6; }
if ${tcl_cv_struct_dirent64+:} false; then :
  $as_echo_n "(cached) " >&6
else

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for struct dirent64" >&5
printf %s "checking for struct dirent64... " >&6; }
if test ${tcl_cv_struct_dirent64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
#include <dirent.h>
int
main ()
main (void)
{
struct dirent64 p;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_struct_dirent64=yes
else
  tcl_cv_struct_dirent64=no
else case e in #(
  e) tcl_cv_struct_dirent64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_struct_dirent64" >&5
$as_echo "$tcl_cv_struct_dirent64" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_struct_dirent64" >&5
printf "%s\n" "$tcl_cv_struct_dirent64" >&6; }
	if test "x${tcl_cv_struct_dirent64}" = "xyes" ; then

$as_echo "#define HAVE_STRUCT_DIRENT64 1" >>confdefs.h
printf "%s\n" "#define HAVE_STRUCT_DIRENT64 1" >>confdefs.h

	fi

	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for DIR64" >&5
$as_echo_n "checking for DIR64... " >&6; }
if ${tcl_cv_DIR64+:} false; then :
  $as_echo_n "(cached) " >&6
else

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for DIR64" >&5
printf %s "checking for DIR64... " >&6; }
if test ${tcl_cv_DIR64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
#include <dirent.h>
int
main ()
main (void)
{
struct dirent64 *p; DIR64 d = opendir64(".");
            p = readdir64(d); rewinddir64(d); closedir64(d);
	    p = readdir64(d); rewinddir64(d); closedir64(d);
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_DIR64=yes
else
  tcl_cv_DIR64=no
else case e in #(
  e) tcl_cv_DIR64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_DIR64" >&5
$as_echo "$tcl_cv_DIR64" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_DIR64" >&5
printf "%s\n" "$tcl_cv_DIR64" >&6; }
	if test "x${tcl_cv_DIR64}" = "xyes" ; then

$as_echo "#define HAVE_DIR64 1" >>confdefs.h
printf "%s\n" "#define HAVE_DIR64 1" >>confdefs.h

	fi

	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct stat64" >&5
$as_echo_n "checking for struct stat64... " >&6; }
if ${tcl_cv_struct_stat64+:} false; then :
  $as_echo_n "(cached) " >&6
else

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for struct stat64" >&5
printf %s "checking for struct stat64... " >&6; }
if test ${tcl_cv_struct_stat64+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/stat.h>
int
main ()
main (void)
{
struct stat64 p;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_struct_stat64=yes
else
  tcl_cv_struct_stat64=no
else case e in #(
  e) tcl_cv_struct_stat64=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_struct_stat64" >&5
$as_echo "$tcl_cv_struct_stat64" >&6; }
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $tcl_cv_struct_stat64" >&5
printf "%s\n" "$tcl_cv_struct_stat64" >&6; }
	if test "x${tcl_cv_struct_stat64}" = "xyes" ; then

$as_echo "#define HAVE_STRUCT_STAT64 1" >>confdefs.h
printf "%s\n" "#define HAVE_STRUCT_STAT64 1" >>confdefs.h

	fi

	ac_fn_c_check_func "$LINENO" "open64" "ac_cv_func_open64"
	for ac_func in open64 lseek64
do :
  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
  cat >>confdefs.h <<_ACEOF
if test "x$ac_cv_func_open64" = xyes
then :
  printf "%s\n" "#define HAVE_OPEN64 1" >>confdefs.h

fi
ac_fn_c_check_func "$LINENO" "lseek64" "ac_cv_func_lseek64"
if test "x$ac_cv_func_lseek64" = xyes
then :
  printf "%s\n" "#define HAVE_LSEEK64 1" >>confdefs.h
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF

fi
done

	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for off64_t" >&5
$as_echo_n "checking for off64_t... " >&6; }
	if ${tcl_cv_type_off64_t+:} false; then :
  $as_echo_n "(cached) " >&6
else

	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for off64_t" >&5
printf %s "checking for off64_t... " >&6; }
	if test ${tcl_cv_type_off64_t+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e)
	    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
#include <sys/types.h>
int
main ()
main (void)
{
off64_t offset;

  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
if ac_fn_c_try_compile "$LINENO"
then :
  tcl_cv_type_off64_t=yes
else
  tcl_cv_type_off64_t=no
else case e in #(
  e) tcl_cv_type_off64_t=no ;;
esac
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;;
esac
fi

			if test "x${tcl_cv_type_off64_t}" = "xyes" && \
	        test "x${ac_cv_func_lseek64}" = "xyes" && \
	        test "x${ac_cv_func_open64}" = "xyes" ; then
		test "x${ac_cv_func_lseek64}" = "xyes" && \
		test "x${ac_cv_func_open64}" = "xyes" ; then

$as_echo "#define HAVE_TYPE_OFF64_T 1" >>confdefs.h
printf "%s\n" "#define HAVE_TYPE_OFF64_T 1" >>confdefs.h

	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
	else
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
	fi
    fi



#--------------------------------------------------------------------
# Set the default compiler switches based on the --enable-symbols option.
#--------------------------------------------------------------------



    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for build with symbols" >&5
$as_echo_n "checking for build with symbols... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for build with symbols" >&5
printf %s "checking for build with symbols... " >&6; }
    # Check whether --enable-symbols was given.
if test "${enable_symbols+set}" = set; then :
if test ${enable_symbols+y}
then :
  enableval=$enable_symbols; tcl_ok=$enableval
else
  tcl_ok=no
else case e in #(
  e) tcl_ok=no ;;
esac
fi

    if test "$tcl_ok" = "no"; then
	CFLAGS_DEFAULT="${CFLAGS_OPTIMIZE} -DNDEBUG"
	LDFLAGS_DEFAULT="${LDFLAGS_OPTIMIZE}"
	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
	{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }

printf "%s\n" "#define TCL_CFG_OPTIMIZED 1" >>confdefs.h

    else
	CFLAGS_DEFAULT="${CFLAGS_DEBUG}"
	LDFLAGS_DEFAULT="${LDFLAGS_DEBUG}"
	if test "$tcl_ok" = "yes"; then
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes (standard debugging)" >&5
$as_echo "yes (standard debugging)" >&6; }
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes (standard debugging)" >&5
printf "%s\n" "yes (standard debugging)" >&6; }
	fi
    fi



    if test "$tcl_ok" = "mem" -o "$tcl_ok" = "all"; then

$as_echo "#define TCL_MEM_DEBUG 1" >>confdefs.h
printf "%s\n" "#define TCL_MEM_DEBUG 1" >>confdefs.h

    fi

    if test "$tcl_ok" != "yes" -a "$tcl_ok" != "no"; then
	if test "$tcl_ok" = "all"; then
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled symbols mem debugging" >&5
$as_echo "enabled symbols mem debugging" >&6; }
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: enabled symbols mem debugging" >&5
printf "%s\n" "enabled symbols mem debugging" >&6; }
	else
	    { $as_echo "$as_me:${as_lineno-$LINENO}: result: enabled $tcl_ok debugging" >&5
$as_echo "enabled $tcl_ok debugging" >&6; }
	    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: enabled $tcl_ok debugging" >&5
printf "%s\n" "enabled $tcl_ok debugging" >&6; }
	fi
    fi


#--------------------------------------------------------------------
# Everyone should be linking against the Tcl stub library.  If you
# can't for some reason, remove this definition.  If you aren't using
# stubs, you also need to modify the SHLIB_LD_LIBS setting below to
# link against the non-stubbed Tcl library.  Add Tk too if necessary.
#--------------------------------------------------------------------


$as_echo "#define USE_TCL_STUBS 1" >>confdefs.h
printf "%s\n" "#define USE_TCL_STUBS 1" >>confdefs.h


#--------------------------------------------------------------------
# This macro generates a line to use when building a library.  It
# depends on values set by the TEA_ENABLE_SHARED, TEA_ENABLE_SYMBOLS,
# and TEA_LOAD_TCLCONFIG macros above.
#--------------------------------------------------------------------


{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep -e" >&5
printf %s "checking for egrep -e... " >&6; }
if test ${ac_cv_path_EGREP_TRADITIONAL+y}
then :
  printf %s "(cached) " >&6
else case e in #(
  e) if test -z "$EGREP_TRADITIONAL"; then
  ac_path_EGREP_TRADITIONAL_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_prog in grep ggrep
   do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_EGREP_TRADITIONAL="$as_dir$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_EGREP_TRADITIONAL" || continue
# Check for GNU ac_path_EGREP_TRADITIONAL and select it if it is found.
  # Check for GNU $ac_path_EGREP_TRADITIONAL
case `"$ac_path_EGREP_TRADITIONAL" --version 2>&1` in #(
*GNU*)
  ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL" ac_path_EGREP_TRADITIONAL_found=:;;
#(
*)
  ac_count=0
  printf %s 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    printf "%s\n" 'EGREP_TRADITIONAL' >> "conftest.nl"
    "$ac_path_EGREP_TRADITIONAL" -E 'EGR(EP|AC)_TRADITIONAL$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_EGREP_TRADITIONAL_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL"
      ac_path_EGREP_TRADITIONAL_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

      $ac_path_EGREP_TRADITIONAL_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_EGREP_TRADITIONAL"; then
    :
  fi
else
  ac_cv_path_EGREP_TRADITIONAL=$EGREP_TRADITIONAL
fi

    if test "$ac_cv_path_EGREP_TRADITIONAL"
then :
  ac_cv_path_EGREP_TRADITIONAL="$ac_cv_path_EGREP_TRADITIONAL -E"
else case e in #(
  e) if test -z "$EGREP_TRADITIONAL"; then
  ac_path_EGREP_TRADITIONAL_found=false
  # Loop through the user's path and test for each of PROGNAME-LIST
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin
do
  IFS=$as_save_IFS
  case $as_dir in #(((
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    for ac_prog in egrep
   do
    for ac_exec_ext in '' $ac_executable_extensions; do
      ac_path_EGREP_TRADITIONAL="$as_dir$ac_prog$ac_exec_ext"
      as_fn_executable_p "$ac_path_EGREP_TRADITIONAL" || continue
# Check for GNU ac_path_EGREP_TRADITIONAL and select it if it is found.
  # Check for GNU $ac_path_EGREP_TRADITIONAL
case `"$ac_path_EGREP_TRADITIONAL" --version 2>&1` in #(
*GNU*)
  ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL" ac_path_EGREP_TRADITIONAL_found=:;;
#(
*)
  ac_count=0
  printf %s 0123456789 >"conftest.in"
  while :
  do
    cat "conftest.in" "conftest.in" >"conftest.tmp"
    mv "conftest.tmp" "conftest.in"
    cp "conftest.in" "conftest.nl"
    printf "%s\n" 'EGREP_TRADITIONAL' >> "conftest.nl"
    "$ac_path_EGREP_TRADITIONAL" 'EGR(EP|AC)_TRADITIONAL$' < "conftest.nl" >"conftest.out" 2>/dev/null || break
    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
    as_fn_arith $ac_count + 1 && ac_count=$as_val
    if test $ac_count -gt ${ac_path_EGREP_TRADITIONAL_max-0}; then
      # Best one so far, save it but keep looking for a better one
      ac_cv_path_EGREP_TRADITIONAL="$ac_path_EGREP_TRADITIONAL"
      ac_path_EGREP_TRADITIONAL_max=$ac_count
    fi
    # 10*(2^10) chars as input seems more than enough
    test $ac_count -gt 10 && break
  done
  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
esac

      $ac_path_EGREP_TRADITIONAL_found && break 3
    done
  done
  done
IFS=$as_save_IFS
  if test -z "$ac_cv_path_EGREP_TRADITIONAL"; then
    as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5
  fi
else
  ac_cv_path_EGREP_TRADITIONAL=$EGREP_TRADITIONAL
fi
 ;;
esac
fi ;;
esac
fi
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP_TRADITIONAL" >&5
printf "%s\n" "$ac_cv_path_EGREP_TRADITIONAL" >&6; }
 EGREP_TRADITIONAL=$ac_cv_path_EGREP_TRADITIONAL


    if test "${TEA_PLATFORM}" = "windows" -a "$GCC" != "yes"; then
	MAKE_STATIC_LIB="\${STLIB_LD} -out:\$@ \$(PKG_OBJECTS)"
	MAKE_SHARED_LIB="\${SHLIB_LD} \${LDFLAGS} \${LDFLAGS_DEFAULT} -out:\$@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}"
	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */

#if defined(_MSC_VER) && _MSC_VER >= 1400
print("manifest needed")
#endif

_ACEOF
if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
  $EGREP "manifest needed" >/dev/null 2>&1; then :
  $EGREP_TRADITIONAL "manifest needed" >/dev/null 2>&1
then :

	# Could do a CHECK_PROG for mt, but should always be with MSVC8+
	VC_MANIFEST_EMBED_DLL="if test -f \[email protected] ; then mt.exe -nologo -manifest \[email protected] -outputresource:\$@\;2 ; fi"
	VC_MANIFEST_EMBED_EXE="if test -f \[email protected] ; then mt.exe -nologo -manifest \[email protected] -outputresource:\$@\;1 ; fi"
	MAKE_SHARED_LIB="${MAKE_SHARED_LIB} ; ${VC_MANIFEST_EMBED_DLL}"

    CLEANFILES="$CLEANFILES *.manifest"


fi
rm -f conftest*
rm -rf conftest*

	MAKE_STUB_LIB="\${STLIB_LD} -nodefaultlib -out:\$@ \$(PKG_STUB_OBJECTS)"
    else
	MAKE_STATIC_LIB="\${STLIB_LD} \$@ \$(PKG_OBJECTS)"
	MAKE_SHARED_LIB="\${SHLIB_LD} \${LDFLAGS} \${LDFLAGS_DEFAULT} -o \$@ \$(PKG_OBJECTS) \${SHLIB_LD_LIBS}"
	MAKE_STUB_LIB="\${STLIB_LD} \$@ \$(PKG_STUB_OBJECTS)"
    fi

    if test "${SHARED_BUILD}" = "1" ; then
	MAKE_LIB="${MAKE_SHARED_LIB} "
    else
	MAKE_LIB="${MAKE_STATIC_LIB} "
    fi

    #--------------------------------------------------------------------
    # Shared libraries and static libraries have different names.
    # Use the double eval to make sure any variables in the suffix is
    # substituted. (@@@ Might not be necessary anymore)
    #--------------------------------------------------------------------

    if test "$TEA_PLATFORM" = "unix"; then
	PACKAGE_LIB_PREFIX8="lib"
	if test "$EXEEXT" = ".exe" -a "$SHARED_BUILD" != "0"; then
	    PACKAGE_LIB_PREFIX9="cygtcl9"
	else
	    PACKAGE_LIB_PREFIX9="libtcl9"
	fi
    else
	PACKAGE_LIB_PREFIX8=""
	PACKAGE_LIB_PREFIX9="tcl9"
    fi
    if test "${TCL_MAJOR_VERSION}" -gt 8 -a x"${with_tcl8}" = x; then
	PACKAGE_LIB_PREFIX="${PACKAGE_LIB_PREFIX9}"
    else
	PACKAGE_LIB_PREFIX="${PACKAGE_LIB_PREFIX8}"

printf "%s\n" "#define TCL_MAJOR_VERSION 8" >>confdefs.h


printf "%s\n" "#define TK_MAJOR_VERSION 8" >>confdefs.h

    fi
    if test "${TEA_PLATFORM}" = "windows" ; then
	if test "${SHARED_BUILD}" = "1" ; then
	    # We force the unresolved linking of symbols that are really in
	    # the private libraries of Tcl and Tk.
	    if test x"${TK_BIN_DIR}" != x ; then
		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \"`${CYGPATH} ${TK_BIN_DIR}/${TK_STUB_LIB_FILE}`\""
	    fi
	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} \"`${CYGPATH} ${TCL_BIN_DIR}/${TCL_STUB_LIB_FILE}`\""
	    if test "$GCC" = "yes"; then
		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} -static-libgcc"
	    fi
	    eval eval "PKG_LIB_FILE8=${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
	    eval eval "PKG_LIB_FILE9=${PACKAGE_LIB_PREFIX9}${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
	    eval eval "PKG_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
	else
	    eval eval "PKG_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
	    if test "$GCC" = "yes"; then
		PKG_LIB_FILE=lib${PKG_LIB_FILE}
		PACKAGE_LIB_PREFIX=lib${PACKAGE_LIB_PREFIX}
	    fi
	    eval eval "PKG_LIB_FILE8=${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
	    eval eval "PKG_LIB_FILE9=${PACKAGE_LIB_PREFIX9}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
	    eval eval "PKG_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
	fi
	# Some packages build their own stubs libraries
	if test "${TCL_MAJOR_VERSION}" -gt 8 -a x"${with_tcl8}" = x; then
	eval eval "PKG_STUB_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}"
	    eval eval "PKG_STUB_LIB_FILE=${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}stub.a"
	else
	    eval eval "PKG_STUB_LIB_FILE=${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}"
	fi
	if test "$GCC" = "yes"; then
	    PKG_STUB_LIB_FILE=lib${PKG_STUB_LIB_FILE}
	fi
	# These aren't needed on Windows (either MSVC or gcc)
	RANLIB=:
	RANLIB_STUB=:
    else
	RANLIB_STUB="${RANLIB}"
	if test "${SHARED_BUILD}" = "1" ; then
	    SHLIB_LD_LIBS="${SHLIB_LD_LIBS} ${TCL_STUB_LIB_SPEC}"
	    if test x"${TK_BIN_DIR}" != x ; then
		SHLIB_LD_LIBS="${SHLIB_LD_LIBS} ${TK_STUB_LIB_SPEC}"
	    fi
	    eval eval "PKG_LIB_FILE8=${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
	    eval eval "PKG_LIB_FILE9=${PACKAGE_LIB_PREFIX9}${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
	    eval eval "PKG_LIB_FILE=lib${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
	    eval eval "PKG_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${SHARED_LIB_SUFFIX}"
	    RANLIB=:
	else
	    eval eval "PKG_LIB_FILE8=${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
	    eval eval "PKG_LIB_FILE9=${PACKAGE_LIB_PREFIX9}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
	    eval eval "PKG_LIB_FILE=lib${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
	    eval eval "PKG_LIB_FILE=${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}${UNSHARED_LIB_SUFFIX}"
	fi
	# Some packages build their own stubs libraries
	if test "${TCL_MAJOR_VERSION}" -gt 8 -a x"${with_tcl8}" = x; then
	    eval eval "PKG_STUB_LIB_FILE=${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}stub.a"
	else
	eval eval "PKG_STUB_LIB_FILE=lib${PACKAGE_LIB_PREFIX}${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}"
	    eval eval "PKG_STUB_LIB_FILE=${PACKAGE_LIB_PREFIX8}${PACKAGE_NAME}stub${UNSHARED_LIB_SUFFIX}"
	fi
    fi

    # These are escaped so that only CFLAGS is picked up at configure time.
    # The other values will be substituted at make time.
    CFLAGS="${CFLAGS} \${CFLAGS_DEFAULT} \${CFLAGS_WARNING}"
    if test "${SHARED_BUILD}" = "1" ; then
	CFLAGS="${CFLAGS} \${SHLIB_CFLAGS}"
    fi





    # Substitute STUB_LIB_FILE in case package creates a stub library too.






#--------------------------------------------------------------------
# Determine the name of the tclsh and/or wish executables in the
# Tcl and Tk build directories or the location they were installed
# into. These paths are used to support running test cases only,
# the Makefile should not be making use of these paths to generate
# a pkgIndex.tcl file or anything else at extension build time.
#--------------------------------------------------------------------


    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for tclsh" >&5
$as_echo_n "checking for tclsh... " >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for tclsh" >&5
printf %s "checking for tclsh... " >&6; }
    if test -f "${TCL_BIN_DIR}/Makefile" ; then
        # tclConfig.sh is in Tcl build directory
        if test "${TEA_PLATFORM}" = "windows"; then
          if test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}" ; then
            TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}"
          elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}s${EXEEXT}" ; then
            TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}s${EXEEXT}"
          elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}t${EXEEXT}" ; then
            TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}t${EXEEXT}"
          elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}st${EXEEXT}" ; then
            TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}st${EXEEXT}"
          fi
        else
            TCLSH_PROG="${TCL_BIN_DIR}/tclsh"
        fi
	# tclConfig.sh is in Tcl build directory
	if test "${TEA_PLATFORM}" = "windows"; then
	  if test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}" ; then
	    TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}"
	  elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}s${EXEEXT}" ; then
	    TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}s${EXEEXT}"
	  elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}t${EXEEXT}" ; then
	    TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}t${EXEEXT}"
	  elif test -f "${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}st${EXEEXT}" ; then
	    TCLSH_PROG="${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}st${EXEEXT}"
	  fi
	else
	    TCLSH_PROG="${TCL_BIN_DIR}/tclsh"
	fi
    else
        # tclConfig.sh is in install location
        if test "${TEA_PLATFORM}" = "windows"; then
            TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}"
        else
            TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}"
        fi
        list="`ls -d ${TCL_BIN_DIR}/../bin 2>/dev/null` \
              `ls -d ${TCL_BIN_DIR}/..     2>/dev/null` \
              `ls -d ${TCL_PREFIX}/bin     2>/dev/null`"
        for i in $list ; do
            if test -f "$i/${TCLSH_PROG}" ; then
                REAL_TCL_BIN_DIR="`cd "$i"; pwd`/"
                break
            fi
        done
        TCLSH_PROG="${REAL_TCL_BIN_DIR}${TCLSH_PROG}"
	# tclConfig.sh is in install location
	if test "${TEA_PLATFORM}" = "windows"; then
	    TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${EXEEXT}"
	else
	    TCLSH_PROG="tclsh${TCL_MAJOR_VERSION}.${TCL_MINOR_VERSION}"
	fi
	list="`ls -d ${TCL_BIN_DIR}/../bin 2>/dev/null` \
	      `ls -d ${TCL_BIN_DIR}/..     2>/dev/null` \
	      `ls -d ${TCL_PREFIX}/bin     2>/dev/null`"
	for i in $list ; do
	    if test -f "$i/${TCLSH_PROG}" ; then
		REAL_TCL_BIN_DIR="`cd "$i"; pwd`/"
		break
	    fi
	done
	TCLSH_PROG="${REAL_TCL_BIN_DIR}${TCLSH_PROG}"
    fi
    { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${TCLSH_PROG}" >&5
$as_echo "${TCLSH_PROG}" >&6; }
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${TCLSH_PROG}" >&5
printf "%s\n" "${TCLSH_PROG}" >&6; }


#TEA_PROG_WISH

#--------------------------------------------------------------------
#	Zipfs support - Tip 430
#--------------------------------------------------------------------
# Check whether --enable-zipfs was given.
if test ${enable_zipfs+y}
then :
  enableval=$enable_zipfs; tcl_ok=$enableval
else case e in #(
  e) tcl_ok=yes ;;
esac
fi

if test "$tcl_ok" = "yes" -a "x$enable_framework" != "xyes"; then
    ZIPFS_BUILD=1
    THREAD_ZIP_FILE=lib${PACKAGE_NAME}${PACKAGE_VERSION}.zip
else
    ZIPFS_BUILD=0
    THREAD_ZIP_FILE=
fi
# Do checking message here to not mess up interleaved configure output
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for building with zipfs" >&5
printf %s "checking for building with zipfs... " >&6; }
if test "${ZIPFS_BUILD}" = 1; then
    if test "${SHARED_BUILD}" = 0; then
       ZIPFS_BUILD=2;

printf "%s\n" "#define ZIPFS_BUILD 2" >>confdefs.h

       INSTALL_LIBRARIES=install-demos
       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
     else

printf "%s\n" "#define ZIPFS_BUILD 1" >>confdefs.h
\
       INSTALL_LIBRARIES=install-demos
       { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
printf "%s\n" "yes" >&6; }
    fi
else
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5
printf "%s\n" "no" >&6; }
INSTALL_LIBRARIES=install-libraries
INSTALL_MSGS=install-msgs
fi






#--------------------------------------------------------------------
# Finally, substitute all of the various values into the Makefile.
# You may alternatively have a special pkgIndex.tcl.in or other files
# which require substituting th AC variables in.  Include these here.
#--------------------------------------------------------------------

ac_config_files="$ac_config_files Makefile pkgIndex.tcl"

cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
# tests run on this system so they can be shared between configure
# scripts and configure runs, see configure's option --config-cache.
# It is not useful on other systems.  If it contains results you don't
# want to keep, you may remove or edit it.
#
# config.status only pays attention to the cache file if you give it
# the --recheck option to rerun configure.
#
# `ac_cv_env_foo' variables (set or unset) will be overridden when
# loading this file, other *unset* `ac_cv_foo' will be assigned the
# 'ac_cv_env_foo' variables (set or unset) will be overridden when
# loading this file, other *unset* 'ac_cv_foo' will be assigned the
# following values.

_ACEOF

# The following way of writing the cache mishandles newlines in values,
# but we know of no workaround that is simple, portable, and efficient.
# So, we kill variables containing newlines.
# Ultrix sh set writes to stderr and can't be redirected directly,
# and sets the high bit in the cache file unless we assign to the vars.
(
  for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do
    eval ac_val=\$$ac_var
    case $ac_val in #(
    *${as_nl}*)
      case $ac_var in #(
      *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5
printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      esac
      case $ac_var in #(
      _ | IFS | as_nl) ;; #(
      BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #(
      *) { eval $ac_var=; unset $ac_var;} ;;
      esac ;;
    esac
  done

  (set) 2>&1 |
    case $as_nl`(ac_space=' '; set) 2>&1` in #(
    *${as_nl}ac_space=\ *)
      # `set' does not quote correctly, so add quotes: double-quote
      # 'set' does not quote correctly, so add quotes: double-quote
      # substitution turns \\\\ into \\, and sed turns \\ into \.
      sed -n \
	"s/'/'\\\\''/g;
	  s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
      ;; #(
    *)
      # `set' quotes correctly as required by POSIX, so do not add quotes.
      # 'set' quotes correctly as required by POSIX, so do not add quotes.
      sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p"
      ;;
    esac |
    sort
) |
  sed '
     /^ac_cv_env_/b end
     t clear
     :clear
     s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
     s/^\([^=]*\)=\(.*[{}].*\)$/test ${\1+y} || &/
     t end
     s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
     :end' >>confcache
if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
  if test -w "$cache_file"; then
    if test "x$cache_file" != "x/dev/null"; then
      { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
$as_echo "$as_me: updating cache $cache_file" >&6;}
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
printf "%s\n" "$as_me: updating cache $cache_file" >&6;}
      if test ! -f "$cache_file" || test -h "$cache_file"; then
	cat confcache >"$cache_file"
      else
        case $cache_file in #(
        */* | ?:*)
	  mv -f confcache "$cache_file"$$ &&
	  mv -f "$cache_file"$$ "$cache_file" ;; #(
        *)
	  mv -f confcache "$cache_file" ;;
	esac
      fi
    fi
  else
    { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
    { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
printf "%s\n" "$as_me: not updating unwritable cache $cache_file" >&6;}
  fi
fi
rm -f confcache

test "x$prefix" = xNONE && prefix=$ac_default_prefix
# Let make expand exec_prefix.
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
8465
8466
8467
8468
8469
8470
8471
8472

8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494

8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513


8514
8515
8516
8517
8518
8519
8520
9593
9594
9595
9596
9597
9598
9599

9600


9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619

9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630

9631
9632
9633
9634
9635
9636


9637
9638
9639
9640
9641
9642
9643
9644
9645







-
+
-
-



















-
+










-






-
-
+
+







:clear
s/^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 (][^	 (]*([^)]*)\)[	 ]*\(.*\)/-D\1=\2/g
t quote
s/^[	 ]*#[	 ]*define[	 ][	 ]*\([^	 ][^	 ]*\)[	 ]*\(.*\)/-D\1=\2/g
t quote
b any
:quote
s/[	 `~#$^&*(){}\\|;'\''"<>?]/\\&/g
s/[][	 `~#$^&*(){}\\|;'\''"<>?]/\\&/g
s/\[/\\&/g
s/\]/\\&/g
s/\$/$$/g
H
:any
${
	g
	s/^\n//
	s/\n/ /g
	p
}
'
DEFS=`sed -n "$ac_script" confdefs.h`


ac_libobjs=
ac_ltlibobjs=
U=
for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
  # 1. Remove the extension, and $U if already installed.
  ac_script='s/\$U\././;s/\.o$//;s/\.obj$//'
  ac_i=`$as_echo "$ac_i" | sed "$ac_script"`
  ac_i=`printf "%s\n" "$ac_i" | sed "$ac_script"`
  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
  #    will be set to the directory where LIBOBJS objects are built.
  as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext"
  as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo'
done
LIBOBJS=$ac_libobjs

LTLIBOBJS=$ac_ltlibobjs



CFLAGS="${CFLAGS} ${CPPFLAGS}"; CPPFLAGS=""

: "${CONFIG_STATUS=./config.status}"
ac_write_fail=0
ac_clean_files_save=$ac_clean_files
ac_clean_files="$ac_clean_files $CONFIG_STATUS"
{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
$as_echo "$as_me: creating $CONFIG_STATUS" >&6;}
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5
printf "%s\n" "$as_me: creating $CONFIG_STATUS" >&6;}
as_write_fail=0
cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1
#! $SHELL
# Generated by $as_me.
# Run this file to recreate the current configuration.
# Compiler output produced by configure, useful for debugging
# configure, is in config.log if it exists.
8529
8530
8531
8532
8533
8534
8535
8536


8537
8538
8539
8540
8541
8542
8543
8544


8545
8546
8547
8548

8549
8550
8551
8552








8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565


8566
8567
8568


8569
8570
8571
8572
8573
8574
8575

8576
8577
8578
8579
8580
8581
8582
8583
8584




8585
8586
8587
8588
8589

















8590
8591
8592

8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615

8616
8617





8618
8619
8620
8621
8622
8623

8624
8625
8626
8627
8628
8629

8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665

8666
8667

8668
8669
8670
8671
8672
8673
8674
9654
9655
9656
9657
9658
9659
9660

9661
9662
9663
9664
9665
9666
9667
9668


9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690










9691
9692



9693
9694







9695









9696
9697
9698
9699





9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718

9719
9720
9721
9722
9723
9724
9725
9726
9727







9728
9729
9730
9731
9732
9733
9734
9735
9736


9737
9738
9739
9740
9741
9742
9743
9744
9745
9746

9747
9748
9749
9750
9751
9752

9753
9754
9755
9756




















9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768

9769
9770

9771
9772
9773
9774
9775
9776
9777
9778







-
+
+






-
-
+
+




+




+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+








-
-
-
-
-
-
-








+
-
-
+
+
+
+
+





-
+





-
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












-
+

-
+







cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1
## -------------------- ##
## M4sh Initialization. ##
## -------------------- ##

# Be more Bourne compatible
DUALCASE=1; export DUALCASE # for MKS sh
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then :
if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1
then :
  emulate sh
  NULLCMD=:
  # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '${1+"$@"}'='"$@"'
  setopt NO_GLOB_SUBST
else
  case `(set -o) 2>/dev/null` in #(
else case e in #(
  e) case `(set -o) 2>/dev/null` in #(
  *posix*) :
    set -o posix ;; #(
  *) :
     ;;
esac ;;
esac
fi



# Reset variables that may have inherited troublesome values from
# the environment.

# IFS needs to be set, to space, tab, and newline, in precisely that order.
# (If _AS_PATH_WALK were called with IFS unset, it would have the
# side effect of setting IFS to empty, thus disabling word splitting.)
# Quoting is to prevent editors from complaining about space-tab.
as_nl='
'
export as_nl
# Printing a long string crashes Solaris 7 /usr/bin/printf.
as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo
as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo
# Prefer a ksh shell builtin over an external printf program on Solaris,
# but without wasting forks for bash or zsh.
if test -z "$BASH_VERSION$ZSH_VERSION" \
    && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then
  as_echo='print -r --'
  as_echo_n='print -rn --'
IFS=" ""	$as_nl"

elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then
  as_echo='printf %s\n'
  as_echo_n='printf %s'
PS1='$ '
PS2='> '
else
  if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then
    as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"'
    as_echo_n='/usr/ucb/echo -n'
  else
    as_echo_body='eval expr "X$1" : "X\\(.*\\)"'
    as_echo_n_body='eval
PS4='+ '
      arg=$1;
      case $arg in #(
      *"$as_nl"*)
	expr "X$arg" : "X\\(.*\\)$as_nl";
	arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;;
      esac;
      expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl"
    '
    export as_echo_n_body

# Ensure predictable behavior from utilities with locale-dependent output.
LC_ALL=C
export LC_ALL
    as_echo_n='sh -c $as_echo_n_body as_echo'
  fi
  export as_echo_body
  as_echo='sh -c $as_echo_body as_echo'
fi
LANGUAGE=C
export LANGUAGE

# We cannot yet rely on "unset" to work, but we need these variables
# to be unset--not just set to an empty or harmless value--now, to
# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh).  This construct
# also avoids known problems related to "unset" and subshell syntax
# in other old shells (e.g. bash 2.01 and pdksh 5.2.14).
for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH
do eval test \${$as_var+y} \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done

# Ensure that fds 0, 1, and 2 are open.
if (exec 3>&0) 2>/dev/null; then :; else exec 0</dev/null; fi
if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi
if (exec 3>&2)            ; then :; else exec 2>/dev/null; fi

# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
if ${PATH_SEPARATOR+false} :; then
  PATH_SEPARATOR=:
  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {
    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||
      PATH_SEPARATOR=';'
  }
fi


# IFS
# We need space, tab and new line, in precisely that order.  Quoting is
# there to prevent editors from complaining about space-tab.
# (If _AS_PATH_WALK were called with IFS unset, it would disable word
# splitting by setting IFS to empty value.)
IFS=" ""	$as_nl"

# Find who we are.  Look in the path if we contain no directory separator.
as_myself=
case $0 in #((
  *[\\/]* ) as_myself=$0 ;;
  *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  case $as_dir in #(((
  test -z "$as_dir" && as_dir=.
    test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
    '') as_dir=./ ;;
    */) ;;
    *) as_dir=$as_dir/ ;;
  esac
    test -r "$as_dir$0" && as_myself=$as_dir$0 && break
  done
IFS=$as_save_IFS

     ;;
esac
# We did not find ourselves, most probably we were run as `sh COMMAND'
# We did not find ourselves, most probably we were run as 'sh COMMAND'
# in which case we are not to be found in the path.
if test "x$as_myself" = x; then
  as_myself=$0
fi
if test ! -f "$as_myself"; then
  $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2
  exit 1
fi

# Unset variables that we do not need and which cause bugs (e.g. in
# pre-3.0 UWIN ksh).  But do not cause bugs in bash 2.01; the "|| exit 1"
# suppresses any "Segmentation fault" message there.  '((' could
# trigger a bug in pdksh 5.2.14.
for as_var in BASH_ENV ENV MAIL MAILPATH
do eval test x\${$as_var+set} = xset \
  && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || :
done
PS1='$ '
PS2='> '
PS4='+ '

# NLS nuisances.
LC_ALL=C
export LC_ALL
LANGUAGE=C
export LANGUAGE

# CDPATH.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH


# as_fn_error STATUS ERROR [LINENO LOG_FD]
# ----------------------------------------
# Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are
# provided, also output the error to LOG_FD, referencing LINENO. Then exit the
# script with STATUS, using 1 if that was 0.
as_fn_error ()
{
  as_status=$1; test $as_status -eq 0 && as_status=1
  if test "$4"; then
    as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
    $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
    printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4
  fi
  $as_echo "$as_me: error: $2" >&2
  printf "%s\n" "$as_me: error: $2" >&2
  as_fn_exit $as_status
} # as_fn_error


# as_fn_set_status STATUS
# -----------------------
# Set $? to STATUS, without forking.
8691
8692
8693
8694
8695
8696
8697

8698
8699
8700
8701
8702
8703
8704


8705
8706
8707
8708
8709
8710


8711
8712
8713


8714
8715
8716
8717
8718
8719
8720
8721


8722
8723
8724
8725
8726
8727


8728
8729
8730


8731
8732
8733
8734
8735
8736
8737
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808

9809
9810
9811
9812
9813
9814


9815
9816
9817
9818

9819
9820
9821
9822
9823
9824
9825
9826
9827

9828
9829
9830
9831
9832
9833


9834
9835
9836
9837

9838
9839
9840
9841
9842
9843
9844
9845
9846







+






-
+
+




-
-
+
+


-
+
+







-
+
+




-
-
+
+


-
+
+







# ---------------
# Portably unset VAR.
as_fn_unset ()
{
  { eval $1=; unset $1;}
}
as_unset=as_fn_unset

# as_fn_append VAR VALUE
# ----------------------
# Append the text in VALUE to the end of the definition contained in VAR. Take
# advantage of any shell optimizations that allow amortized linear growth over
# repeated appends, instead of the typical quadratic growth present in naive
# implementations.
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then :
if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null
then :
  eval 'as_fn_append ()
  {
    eval $1+=\$2
  }'
else
  as_fn_append ()
else case e in #(
  e) as_fn_append ()
  {
    eval $1=\$$1\$2
  }
  } ;;
esac
fi # as_fn_append

# as_fn_arith ARG...
# ------------------
# Perform arithmetic evaluation on the ARGs, and store the result in the
# global $as_val. Take advantage of shells that can avoid forks. The arguments
# must be portable across $(()) and expr.
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then :
if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null
then :
  eval 'as_fn_arith ()
  {
    as_val=$(( $* ))
  }'
else
  as_fn_arith ()
else case e in #(
  e) as_fn_arith ()
  {
    as_val=`expr "$@" || test $? -eq 1`
  }
  } ;;
esac
fi # as_fn_arith


if expr a : '\(a\)' >/dev/null 2>&1 &&
   test "X`expr 00001 : '.*\(...\)'`" = X001; then
  as_expr=expr
else
8750
8751
8752
8753
8754
8755
8756
8757

8758
8759
8760
8761
8762
8763
8764
9859
9860
9861
9862
9863
9864
9865

9866
9867
9868
9869
9870
9871
9872
9873







-
+







  as_dirname=false
fi

as_me=`$as_basename -- "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
	 X"$0" : 'X\(//\)$' \| \
	 X"$0" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X/"$0" |
printf "%s\n" X/"$0" |
    sed '/^.*\/\([^/][^/]*\)\/*$/{
	    s//\1/
	    q
	  }
	  /^X\/\(\/\/\)$/{
	    s//\1/
	    q
8772
8773
8774
8775
8776
8777
8778




8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790






8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805



8806
8807
8808
8809
8810
8811
8812
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921



9922
9923
9924
9925
9926
9927
9928
9929
9930
9931







+
+
+
+












+
+
+
+
+
+












-
-
-
+
+
+







# Avoid depending upon Character Ranges.
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
as_cr_Letters=$as_cr_letters$as_cr_LETTERS
as_cr_digits='0123456789'
as_cr_alnum=$as_cr_Letters$as_cr_digits


# Determine whether it's possible to make 'echo' print without a newline.
# These variables are no longer used directly by Autoconf, but are AC_SUBSTed
# for compatibility with existing Makefiles.
ECHO_C= ECHO_N= ECHO_T=
case `echo -n x` in #(((((
-n*)
  case `echo 'xy\c'` in
  *c*) ECHO_T='	';;	# ECHO_T is single tab character.
  xy)  ECHO_C='\c';;
  *)   echo `echo ksh88 bug on AIX 6.1` > /dev/null
       ECHO_T='	';;
  esac;;
*)
  ECHO_N='-n';;
esac

# For backward compatibility with old third-party macros, we provide
# the shell variables $as_echo and $as_echo_n.  New code should use
# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively.
as_echo='printf %s\n'
as_echo_n='printf %s'

rm -f conf$$ conf$$.exe conf$$.file
if test -d conf$$.dir; then
  rm -f conf$$.dir/conf$$.file
else
  rm -f conf$$.dir
  mkdir conf$$.dir 2>/dev/null
fi
if (echo >conf$$.file) 2>/dev/null; then
  if ln -s conf$$.file conf$$ 2>/dev/null; then
    as_ln_s='ln -s'
    # ... but there are two gotchas:
    # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
    # In both cases, we have to default to `cp -pR'.
    # 1) On MSYS, both 'ln -s file dir' and 'ln file dir' fail.
    # 2) DJGPP < 2.04 has no symlinks; 'ln -s' creates a wrapper executable.
    # In both cases, we have to default to 'cp -pR'.
    ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
      as_ln_s='cp -pR'
  elif ln conf$$.file conf$$ 2>/dev/null; then
    as_ln_s=ln
  else
    as_ln_s='cp -pR'
  fi
8826
8827
8828
8829
8830
8831
8832
8833

8834
8835
8836
8837
8838
8839
8840
8841
8842

8843
8844
8845
8846
8847
8848
8849
9945
9946
9947
9948
9949
9950
9951

9952
9953
9954
9955
9956
9957
9958
9959
9960

9961
9962
9963
9964
9965
9966
9967
9968







-
+








-
+







  case $as_dir in #(
  -*) as_dir=./$as_dir;;
  esac
  test -d "$as_dir" || eval $as_mkdir_p || {
    as_dirs=
    while :; do
      case $as_dir in #(
      *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'(
      *) as_qdir=$as_dir;;
      esac
      as_dirs="'$as_qdir' $as_dirs"
      as_dir=`$as_dirname -- "$as_dir" ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$as_dir" : 'X\(//\)[^/]' \| \
	 X"$as_dir" : 'X\(//\)$' \| \
	 X"$as_dir" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$as_dir" |
printf "%s\n" X"$as_dir" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
8879
8880
8881
8882
8883
8884
8885
8886


8887
8888
8889


8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905


8906
8907
8908
8909
8910
8911
8912
9998
9999
10000
10001
10002
10003
10004

10005
10006
10007
10008

10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024


10025
10026
10027
10028
10029
10030
10031
10032
10033







-
+
+


-
+
+














-
-
+
+







{
  test -f "$1" && test -x "$1"
} # as_fn_executable_p
as_test_x='test -x'
as_executable_p=as_fn_executable_p

# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
as_sed_cpp="y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g"
as_tr_cpp="eval sed '$as_sed_cpp'" # deprecated

# Sed expression to map a string onto a valid variable name.
as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
as_sed_sh="y%*+%pp%;s%[^_$as_cr_alnum]%_%g"
as_tr_sh="eval sed '$as_sed_sh'" # deprecated


exec 6>&1
## ----------------------------------- ##
## Main body of $CONFIG_STATUS script. ##
## ----------------------------------- ##
_ASEOF
test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# Save the log message, to keep $0 and so on meaningful, and to
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by thread $as_me 3.0a2, which was
generated by GNU Autoconf 2.69.  Invocation command line was
This file was extended by thread $as_me 3.0.2, which was
generated by GNU Autoconf 2.72.  Invocation command line was

  CONFIG_FILES    = $CONFIG_FILES
  CONFIG_HEADERS  = $CONFIG_HEADERS
  CONFIG_LINKS    = $CONFIG_LINKS
  CONFIG_COMMANDS = $CONFIG_COMMANDS
  $ $0 $@

8925
8926
8927
8928
8929
8930
8931
8932

8933
8934
8935
8936
8937
8938
8939
10046
10047
10048
10049
10050
10051
10052

10053
10054
10055
10056
10057
10058
10059
10060







-
+







# Files that config.status was made for.
config_files="$ac_config_files"

_ACEOF

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
ac_cs_usage="\
\`$as_me' instantiates files and other configuration actions
'$as_me' instantiates files and other configuration actions
from templates according to the current configuration.  Unless the files
and actions are specified as TAGs, all are instantiated by default.

Usage: $0 [OPTION]... [TAG]...

  -h, --help       print this help, then exit
  -V, --version    print version number and configuration settings, then exit
8947
8948
8949
8950
8951
8952
8953


8954
8955

8956
8957
8958


8959
8960
8961

8962
8963
8964
8965
8966
8967
8968
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077

10078
10079


10080
10081
10082
10083

10084
10085
10086
10087
10088
10089
10090
10091







+
+

-
+

-
-
+
+


-
+








Configuration files:
$config_files

Report bugs to the package provider."

_ACEOF
ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"`
ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"`
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
thread config.status 3.0a2
configured by $0, generated by GNU Autoconf 2.69,
thread config.status 3.0.2
configured by $0, generated by GNU Autoconf 2.72,
  with options \\"\$ac_cs_config\\"

Copyright (C) 2012 Free Software Foundation, Inc.
Copyright (C) 2023 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."

ac_pwd='$ac_pwd'
srcdir='$srcdir'
test -n "\$AWK" || AWK=awk
_ACEOF
8991
8992
8993
8994
8995
8996
8997
8998

8999
9000

9001
9002
9003
9004
9005
9006

9007
9008
9009
9010
9011
9012

9013
9014
9015
9016
9017
9018
9019


9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040

9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054

9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070

9071
9072
9073
9074
9075
9076
9077
9078
9079
9080

9081
9082
9083
9084
9085
9086
9087
9088

9089
9090
9091
9092
9093
9094
9095
10114
10115
10116
10117
10118
10119
10120

10121
10122

10123
10124
10125
10126
10127
10128

10129
10130
10131
10132
10133
10134

10135
10136
10137
10138
10139
10140


10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162

10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176

10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192

10193
10194
10195
10196
10197
10198
10199
10200
10201
10202

10203
10204
10205
10206
10207
10208
10209
10210

10211
10212
10213
10214
10215
10216
10217
10218







-
+

-
+





-
+





-
+





-
-
+
+




















-
+













-
+















-
+









-
+







-
+







  esac

  case $ac_option in
  # Handling of the options.
  -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
    ac_cs_recheck=: ;;
  --version | --versio | --versi | --vers | --ver | --ve | --v | -V )
    $as_echo "$ac_cs_version"; exit ;;
    printf "%s\n" "$ac_cs_version"; exit ;;
  --config | --confi | --conf | --con | --co | --c )
    $as_echo "$ac_cs_config"; exit ;;
    printf "%s\n" "$ac_cs_config"; exit ;;
  --debug | --debu | --deb | --de | --d | -d )
    debug=: ;;
  --file | --fil | --fi | --f )
    $ac_shift
    case $ac_optarg in
    *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
    *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;;
    '') as_fn_error $? "missing file argument" ;;
    esac
    as_fn_append CONFIG_FILES " '$ac_optarg'"
    ac_need_defaults=false;;
  --he | --h |  --help | --hel | -h )
    $as_echo "$ac_cs_usage"; exit ;;
    printf "%s\n" "$ac_cs_usage"; exit ;;
  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
  | -silent | --silent | --silen | --sile | --sil | --si | --s)
    ac_cs_silent=: ;;

  # This is an error.
  -*) as_fn_error $? "unrecognized option: \`$1'
Try \`$0 --help' for more information." ;;
  -*) as_fn_error $? "unrecognized option: '$1'
Try '$0 --help' for more information." ;;

  *) as_fn_append ac_config_targets " $1"
     ac_need_defaults=false ;;

  esac
  shift
done

ac_configure_extra_args=

if $ac_cs_silent; then
  exec 6>/dev/null
  ac_configure_extra_args="$ac_configure_extra_args --silent"
fi

_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
if \$ac_cs_recheck; then
  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
  shift
  \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
  \printf "%s\n" "running CONFIG_SHELL=$SHELL \$*" >&6
  CONFIG_SHELL='$SHELL'
  export CONFIG_SHELL
  exec "\$@"
fi

_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
exec 5>>config.log
{
  echo
  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## Running $as_me. ##
_ASBOX
  $as_echo "$ac_log"
  printf "%s\n" "$ac_log"
} >&5

_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
_ACEOF

cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1

# Handling of arguments.
for ac_config_target in $ac_config_targets
do
  case $ac_config_target in
    "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
    "pkgIndex.tcl") CONFIG_FILES="$CONFIG_FILES pkgIndex.tcl" ;;

  *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
  *) as_fn_error $? "invalid argument: '$ac_config_target'" "$LINENO" 5;;
  esac
done


# If the user did not use the arguments to specify the items to instantiate,
# then the envvar interface is used.  Set only those that are not.
# We use the long form for the default assignment because of an extremely
# bizarre bug on SunOS 4.1.3.
if $ac_need_defaults; then
  test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
  test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files
fi

# Have a temporary directory for convenience.  Make it in the build tree
# simply because there is no reason against having it here, and in addition,
# creating and moving files from /tmp can sometimes cause problems.
# Hook for its removal unless debugging.
# Note that there is a small window in which the directory will not be cleaned:
# after its creation but before its name has been assigned to `$tmp'.
# after its creation but before its name has been assigned to '$tmp'.
$debug ||
{
  tmp= ac_tmp=
  trap 'exit_status=$?
  : "${ac_tmp:=$tmp}"
  { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status
' 0
9105
9106
9107
9108
9109
9110
9111
9112

9113
9114
9115
9116
9117
9118
9119
10228
10229
10230
10231
10232
10233
10234

10235
10236
10237
10238
10239
10240
10241
10242







-
+







  tmp=./conf$$-$RANDOM
  (umask 077 && mkdir "$tmp")
} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
ac_tmp=$tmp

# Set up the scripts for CONFIG_FILES section.
# No need to generate them if there are no CONFIG_FILES.
# This happens for instance with `./config.status config.h'.
# This happens for instance with './config.status config.h'.
if test -n "$CONFIG_FILES"; then


ac_cr=`echo X | tr X '\015'`
# On cygwin, bash can eat \r inside `` if the user requested igncr.
# But we know of no other shell where ac_cr would be empty at this
# point, so we can use a bashism as a fallback.
9271
9272
9273
9274
9275
9276
9277
9278

9279
9280
9281
9282
9283
9284
9285
10394
10395
10396
10397
10398
10399
10400

10401
10402
10403
10404
10405
10406
10407
10408







-
+







for ac_tag
do
  case $ac_tag in
  :[FHLC]) ac_mode=$ac_tag; continue;;
  esac
  case $ac_mode$ac_tag in
  :[FHL]*:*);;
  :L* | :C*:*) as_fn_error $? "invalid tag \`$ac_tag'" "$LINENO" 5;;
  :L* | :C*:*) as_fn_error $? "invalid tag '$ac_tag'" "$LINENO" 5;;
  :[FH]-) ac_tag=-:-;;
  :[FH]*) ac_tag=$ac_tag:$ac_tag.in;;
  esac
  ac_save_IFS=$IFS
  IFS=:
  set x $ac_tag
  IFS=$ac_save_IFS
9293
9294
9295
9296
9297
9298
9299
9300

9301
9302
9303
9304
9305
9306

9307
9308

9309
9310
9311
9312

9313
9314
9315
9316

9317
9318
9319
9320
9321


9322
9323
9324
9325
9326

9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343

9344
9345
9346
9347
9348
9349
9350
10416
10417
10418
10419
10420
10421
10422

10423
10424
10425
10426
10427
10428

10429
10430

10431
10432
10433
10434

10435
10436
10437
10438

10439
10440
10441
10442


10443
10444
10445
10446
10447
10448

10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465

10466
10467
10468
10469
10470
10471
10472
10473







-
+





-
+

-
+



-
+



-
+



-
-
+
+




-
+
















-
+







    ac_file_inputs=
    for ac_f
    do
      case $ac_f in
      -) ac_f="$ac_tmp/stdin";;
      *) # Look for the file first in the build tree, then in the source tree
	 # (if the path is not absolute).  The absolute path cannot be DOS-style,
	 # because $ac_f cannot contain `:'.
	 # because $ac_f cannot contain ':'.
	 test -f "$ac_f" ||
	   case $ac_f in
	   [\\/$]*) false;;
	   *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";;
	   esac ||
	   as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;;
	   as_fn_error 1 "cannot find input file: '$ac_f'" "$LINENO" 5;;
      esac
      case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
      case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac
      as_fn_append ac_file_inputs " '$ac_f'"
    done

    # Let's still pretend it is `configure' which instantiates (i.e., don't
    # Let's still pretend it is 'configure' which instantiates (i.e., don't
    # use $as_me), people would be surprised to read:
    #    /* config.h.  Generated by config.status.  */
    configure_input='Generated from '`
	  $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
	  printf "%s\n" "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g'
	`' by configure.'
    if test x"$ac_file" != x-; then
      configure_input="$ac_file.  $configure_input"
      { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
$as_echo "$as_me: creating $ac_file" >&6;}
      { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5
printf "%s\n" "$as_me: creating $ac_file" >&6;}
    fi
    # Neutralize special characters interpreted by sed in replacement strings.
    case $configure_input in #(
    *\&* | *\|* | *\\* )
       ac_sed_conf_input=`$as_echo "$configure_input" |
       ac_sed_conf_input=`printf "%s\n" "$configure_input" |
       sed 's/[\\\\&|]/\\\\&/g'`;; #(
    *) ac_sed_conf_input=$configure_input;;
    esac

    case $ac_tag in
    *:-:* | *:-) cat >"$ac_tmp/stdin" \
      || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;;
    esac
    ;;
  esac

  ac_dir=`$as_dirname -- "$ac_file" ||
$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
	 X"$ac_file" : 'X\(//\)[^/]' \| \
	 X"$ac_file" : 'X\(//\)$' \| \
	 X"$ac_file" : 'X\(/\)' \| . 2>/dev/null ||
$as_echo X"$ac_file" |
printf "%s\n" X"$ac_file" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
	    s//\1/
	    q
	  }
	  /^X\(\/\/\)[^/].*/{
	    s//\1/
	    q
9360
9361
9362
9363
9364
9365
9366
9367

9368
9369

9370
9371
9372
9373
9374
9375
9376
10483
10484
10485
10486
10487
10488
10489

10490
10491

10492
10493
10494
10495
10496
10497
10498
10499







-
+

-
+







	  s/.*/./; q'`
  as_dir="$ac_dir"; as_fn_mkdir_p
  ac_builddir=.

case "$ac_dir" in
.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;;
*)
  ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'`
  ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'`
  # A ".." for each directory in $ac_dir_suffix.
  ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'`
  case $ac_top_builddir_sub in
  "") ac_top_builddir_sub=. ac_top_build_prefix= ;;
  *)  ac_top_build_prefix=$ac_top_builddir_sub/ ;;
  esac ;;
esac
ac_abs_top_builddir=$ac_pwd
ac_abs_builddir=$ac_pwd$ac_dir_suffix
9415
9416
9417
9418
9419
9420
9421
9422
9423


9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436

9437
9438
9439
9440
9441
9442
9443
10538
10539
10540
10541
10542
10543
10544


10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558

10559
10560
10561
10562
10563
10564
10565
10566







-
-
+
+












-
+







/@docdir@/p
/@infodir@/p
/@localedir@/p
/@mandir@/p'
case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in
*datarootdir*) ac_datarootdir_seen=yes;;
*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*)
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5
printf "%s\n" "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;}
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
  ac_datarootdir_hack='
  s&@datadir@&$datadir&g
  s&@docdir@&$docdir&g
  s&@infodir@&$infodir&g
  s&@localedir@&$localedir&g
  s&@mandir@&$mandir&g
  s&\\\${datarootdir}&$datarootdir&g' ;;
esac
_ACEOF

# Neutralize VPATH when `$srcdir' = `.'.
# Neutralize VPATH when '$srcdir' = '.'.
# Shell code in configure.ac might set extrasub.
# FIXME: do we really want to maintain this feature?
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_sed_extra="$ac_vpsub
$extrasub
_ACEOF
cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
9458
9459
9460
9461
9462
9463
9464
9465

9466
9467

9468
9469
9470
9471
9472
9473
9474
10581
10582
10583
10584
10585
10586
10587

10588
10589

10590
10591
10592
10593
10594
10595
10596
10597







-
+

-
+







eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \
  >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5

test -z "$ac_datarootdir_hack$ac_datarootdir_seen" &&
  { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } &&
  { ac_out=`sed -n '/^[	 ]*datarootdir[	 ]*:*=/p' \
      "$ac_tmp/out"`; test -z "$ac_out"; } &&
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir'
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable 'datarootdir'
which seems to be undefined.  Please make sure it is defined" >&5
$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir'
printf "%s\n" "$as_me: WARNING: $ac_file contains a reference to the variable 'datarootdir'
which seems to be undefined.  Please make sure it is defined" >&2;}

  rm -f "$ac_tmp/stdin"
  case $ac_file in
  -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";;
  *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";;
  esac \
9507
9508
9509
9510
9511
9512
9513
9514
9515


9516
9517

10630
10631
10632
10633
10634
10635
10636


10637
10638
10639
10640
10641







-
-
+
+


+
  $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
  exec 5>>config.log
  # Use ||, not &&, to avoid exiting from the if with $? = 1, which
  # would make configure fail if this is the last instruction.
  $ac_cs_success || as_fn_exit 1
fi
if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
  { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
  { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5
printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
fi


Changes to configure.ac.
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36




37
38
39

40
41

42
43
44
45
46
47
48
49
50
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

43


44
45

46
47
48
49
50
51
52







-
+
















+
+
+
+


-
+
-
-
+

-







# Set your package name and version numbers here.
#
# This initializes the environment with PACKAGE_NAME and PACKAGE_VERSION
# set as provided.  These will also be added as -D defs in your Makefile
# so you can encode the package version directly into the source files.
#-----------------------------------------------------------------------

AC_INIT([thread], [3.0a2])
AC_INIT([thread],[3.0.2])

#--------------------------------------------------------------------
# Call TEA_INIT as the first TEA_ macro to set up initial vars.
# This will define a ${TEA_PLATFORM} variable == "unix" or "windows"
# as well as PKG_LIB_FILE and PKG_STUB_LIB_FILE.
#--------------------------------------------------------------------

TEA_INIT()

AC_CONFIG_AUX_DIR(tclconfig)

#--------------------------------------------------------------------
# Load the tclConfig.sh file
#--------------------------------------------------------------------

TEA_PATH_TCLCONFIG
if test x"${with_tcl8}" != x; then
with_tcl8=""
AC_MSG_WARN([--with-tcl8 option ignored])
fi
TEA_LOAD_TCLCONFIG

if test "${TCL_MAJOR_VERSION}" -eq 8 ; then
if test "${TCL_MAJOR_VERSION}" -eq 8; then
    if test "${TCL_MINOR_VERSION}" -lt 7 ; then
        AC_MSG_ERROR([${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 9.0+
    AC_MSG_ERROR([${PACKAGE_NAME} ${PACKAGE_VERSION} requires Tcl 9.0+
Found config for Tcl ${TCL_VERSION}])
fi
fi

#--------------------------------------------------------------------
# Load the tkConfig.sh file if necessary (Tk extension)
#--------------------------------------------------------------------

#TEA_PATH_TKCONFIG
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109









110
111
112
113
114
115
116
96
97
98
99
100
101
102









103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118







-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+







# stub library C source files to compile in TEA_ADD_STUB_SOURCES,
# and runtime Tcl library files in TEA_ADD_TCL_SOURCES.
# This defines PKG(_STUB)_SOURCES, PKG(_STUB)_OBJECTS, PKG_HEADERS
# and PKG_TCL_SOURCES.
#-----------------------------------------------------------------------

TEA_ADD_SOURCES([generic/threadNs.c           \
                 generic/threadCmd.c          \
                 generic/threadSvCmd.c        \
                 generic/threadSpCmd.c        \
                 generic/threadPoolCmd.c      \
                 generic/psGdbm.c             \
                 generic/psLmdb.c             \
                 generic/threadSvListCmd.c    \
                 generic/threadSvKeylistCmd.c \
                 generic/tclXkeylist.c        \
		 generic/threadCmd.c          \
		 generic/threadSvCmd.c        \
		 generic/threadSpCmd.c        \
		 generic/threadPoolCmd.c      \
		 generic/psGdbm.c             \
		 generic/psLmdb.c             \
		 generic/threadSvListCmd.c    \
		 generic/threadSvKeylistCmd.c \
		 generic/tclXkeylist.c        \
])

TEA_ADD_HEADERS([generic/tclThread.h])
TEA_ADD_INCLUDES([${NS_INCLUDES}])
TEA_ADD_LIBS([${GDBM_LIBS} ${LMDB_LIBS} ${NS_LIBS}])
TEA_ADD_CFLAGS([${GDBM_CFLAGS} ${LMDB_CFLAGS}])
TEA_ADD_STUB_SOURCES([])
203
204
205
206
207
208
209





































210
211
212
213
214
215
216
217


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

256
257







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+
+
# into. These paths are used to support running test cases only,
# the Makefile should not be making use of these paths to generate
# a pkgIndex.tcl file or anything else at extension build time.
#--------------------------------------------------------------------

TEA_PROG_TCLSH
#TEA_PROG_WISH

#--------------------------------------------------------------------
#	Zipfs support - Tip 430
#--------------------------------------------------------------------
AC_ARG_ENABLE(zipfs,
    AS_HELP_STRING([--enable-zipfs],[build with Zipfs support (default: on)]),
    [tcl_ok=$enableval], [tcl_ok=yes])
if test "$tcl_ok" = "yes" -a "x$enable_framework" != "xyes"; then
    ZIPFS_BUILD=1
    THREAD_ZIP_FILE=lib${PACKAGE_NAME}${PACKAGE_VERSION}.zip
else
    ZIPFS_BUILD=0
    THREAD_ZIP_FILE=
fi
# Do checking message here to not mess up interleaved configure output
AC_MSG_CHECKING([for building with zipfs])
if test "${ZIPFS_BUILD}" = 1; then
    if test "${SHARED_BUILD}" = 0; then
       ZIPFS_BUILD=2;
       AC_DEFINE(ZIPFS_BUILD, 2, [Are we building with zipfs enabled?])
       INSTALL_LIBRARIES=install-demos
       AC_MSG_RESULT([yes])
     else
       AC_DEFINE(ZIPFS_BUILD, 1, [Are we building with zipfs enabled?])\
       INSTALL_LIBRARIES=install-demos
       AC_MSG_RESULT([yes])
    fi
else
AC_MSG_RESULT([no])
INSTALL_LIBRARIES=install-libraries
INSTALL_MSGS=install-msgs
fi
AC_SUBST(ZIPFS_BUILD)
AC_SUBST(THREAD_ZIP_FILE)
AC_SUBST(INSTALL_LIBRARIES)
AC_SUBST(INSTALL_MSGS)


#--------------------------------------------------------------------
# Finally, substitute all of the various values into the Makefile.
# You may alternatively have a special pkgIndex.tcl.in or other files
# which require substituting th AC variables in.  Include these here.
#--------------------------------------------------------------------

AC_OUTPUT([Makefile pkgIndex.tcl])
AC_CONFIG_FILES([Makefile pkgIndex.tcl])
AC_OUTPUT
Changes to doc/format.tcl.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27














28
29
30
31
32
33
34
1
2
3
4
5
6
7
8
9
10
11
12
13














14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34













-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+







#!/usr/local/bin/tclsh
set mydir [file dirname [info script]]
lappend auto_path /usr/local/lib
package req doctools
doctools::new dt
set wd [pwd]
cd $mydir
file rename html htm
set code [catch {
    set f [open man.macros]
    set m [read $f]
    close $f
    foreach file [glob -nocomplain *.man] {
        set xx [file root $file]
        set f [open $xx.man]
        set t [read $f]
        close $f
        foreach {fmt ext dir} {nroff n man html html htm} {
            dt configure -format $fmt
            set o [dt format $t]
            set f [open $dir/$xx.$ext w]
            if {$fmt == "nroff"} {
                set o [string map [list {.so man.macros} $m] $o]
            }
            puts $f $o
            close $f
        }
	set xx [file root $file]
	set f [open $xx.man]
	set t [read $f]
	close $f
	foreach {fmt ext dir} {nroff n man html html htm} {
	    dt configure -format $fmt
	    set o [dt format $t]
	    set f [open $dir/$xx.$ext w]
	    if {$fmt == "nroff"} {
		set o [string map [list {.so man.macros} $m] $o]
	    }
	    puts $f $o
	    close $f
	}
    }
} err]
file rename htm html
cd $wd
if {$code} {
    error $err
}
Changes to doc/html/thread.html.
1
2


3
4
5
6
7
8
9

1
2
3
4
5
6
7
8
9
10
-

+
+








<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>thread - Tcl Threading</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119


120
121
122
123
124
125
126
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118


119
120
121
122
123
124
125
126
127







-
+

















-
-
+
+







--></style>
</head>
<!-- Generated from file '' by tcllib/doctools with format 'html'
   -->
<!-- thread.n
   -->
<body><div class="doctools">
<h1 class="doctools_title">thread(n) 2.8  &quot;Tcl Threading&quot;</h1>
<h1 class="doctools_title">thread(n) 3.0  &quot;Tcl Threading&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>thread - Extension for script access to Tcl threading</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">COMMANDS</a></li>
<li class="doctools_section"><a href="#section3">DISCUSSION</a></li>
<li class="doctools_section"><a href="#see-also">See Also</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.7</b></li>
<li>package require <b class="pkgname">Thread <span class="opt">?2.8?</span></b></li>
<li>package require <b class="pkgname">Tcl 9.0</b></li>
<li>package require <b class="pkgname">thread <span class="opt">?3.0?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">thread::create</b> <span class="opt">?-joinable?</span> <span class="opt">?-preserved?</span> <span class="opt">?script?</span></a></li>
<li><a href="#2"><b class="cmd">thread::preserve</b> <span class="opt">?id?</span></a></li>
<li><a href="#3"><b class="cmd">thread::release</b> <span class="opt">?-wait?</span> <span class="opt">?id?</span></a></li>
<li><a href="#4"><b class="cmd">thread::id</b></a></li>
<li><a href="#5"><b class="cmd">thread::errorproc</b> <span class="opt">?procname?</span></a></li>
359
360
361
362
363
364
365
366






367
368
369
370
371
372
373
360
361
362
363
364
365
366

367
368
369
370
371
372
373
374
375
376
377
378
379







-
+
+
+
+
+
+







events pending in the event queue of the target thread.
Using the optional <span class="opt">?-head?</span> switch, scripts posted to the thread's
event queue can be placed on the head, instead on the tail of the queue,
thus being executed in the LIFO fashion.</p></dd>
<dt><a name="12"><b class="cmd">thread::broadcast</b> <i class="arg">script</i></a></dt>
<dd><p>This command passes a <i class="arg">script</i> to all threads created by the
package for execution. It does not wait for response from any of
the threads.</p></dd>
the threads.</p>
<p>The sending thread (the one executing the thread::broadcast command) does
not send the script to itself.</p>
<p>Each receiving thread is directed to place evaluation of the send script
at the head of its event queue, stepping in front of any other events
awaiting processing.</p></dd>
<dt><a name="13"><b class="cmd">thread::wait</b></a></dt>
<dd><p>This enters the event loop so a thread can receive messages from
the <b class="cmd">thread::send</b> command. This command should only be used
within the script passed to the <b class="cmd">thread::create</b>. It should
be the very last command in the script. If this is not the case,
the exiting thread will continue executing the script lines past
the <b class="cmd">thread::wait</b> which is usually not what you want and/or
Changes to doc/html/tpool.html.
1
2


3
4
5
6
7
8
9

1
2
3
4
5
6
7
8
9
10
-

+
+








<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>tpool - Tcl Threading</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119


120
121
122
123
124
125
126
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118


119
120
121
122
123
124
125
126
127







-
+

















-
-
+
+







--></style>
</head>
<!-- Generated from file '' by tcllib/doctools with format 'html'
   -->
<!-- tpool.n
   -->
<body><div class="doctools">
<h1 class="doctools_title">tpool(n) 2.8  &quot;Tcl Threading&quot;</h1>
<h1 class="doctools_title">tpool(n) 3.0  &quot;Tcl Threading&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>tpool - Part of the Tcl threading extension implementing pools of worker threads.</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">COMMANDS</a></li>
<li class="doctools_section"><a href="#section3">DISCUSSION</a></li>
<li class="doctools_section"><a href="#see-also">See Also</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.7</b></li>
<li>package require <b class="pkgname">Thread <span class="opt">?2.8?</span></b></li>
<li>package require <b class="pkgname">Tcl 9.0</b></li>
<li>package require <b class="pkgname">thread <span class="opt">?3.0?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">tpool::create</b> <span class="opt">?options?</span></a></li>
<li><a href="#2"><b class="cmd">tpool::names</b></a></li>
<li><a href="#3"><b class="cmd">tpool::post</b> <span class="opt">?-detached?</span> <span class="opt">?-nowait?</span> <i class="arg">tpool</i> <i class="arg">script</i></a></li>
<li><a href="#4"><b class="cmd">tpool::wait</b> <i class="arg">tpool</i> <i class="arg">joblist</i> <span class="opt">?varname?</span></a></li>
<li><a href="#5"><b class="cmd">tpool::cancel</b> <i class="arg">tpool</i> <i class="arg">joblist</i> <span class="opt">?varname?</span></a></li>
210
211
212
213
214
215
216
217
218
219



220
221
222
223
224
225
226
211
212
213
214
215
216
217



218
219
220
221
222
223
224
225
226
227







-
-
-
+
+
+







for execution. The script will be executed in the first available idle
worker thread. If there are no idle worker threads available, the command
will create new one, enter the event loop and service events until the
newly created thread is initialized. If the current number of worker
threads is equal to the maximum number of worker threads, as defined
during the threadpool creation, the command will enter the event loop and
service events while waiting for one of the worker threads to become idle.
If the optional <span class="opt">?-nowait?</span> argument is given, the command will not wait
for one idle worker. It will just place the job in the pool's job queue
and return immediately.</p>
If the optional <span class="opt">?-nowait?</span> argument is given, the command just places the
job in the pool's job queue without waiting for an idle worker or creating a
new one, even if the pool would still have room for additional threads.</p>
<p>The command returns the ID of the posted job. This ID is used for subsequent
<b class="cmd">tpool::wait</b>, <b class="cmd">tpool::get</b> and <b class="cmd">tpool::cancel</b> commands to wait
for and retrieve result of the posted script, or cancel the posted job
respectively. If the optional <span class="opt">?-detached?</span> argument is specified, the
command will post a detached job. A detached job can not be cancelled or
waited upon and is not identified by the job ID.</p>
<p>If the threadpool <i class="arg">tpool</i> is not found in the list of active
Changes to doc/html/tsv.html.
1
2


3
4
5
6
7
8
9

1
2
3
4
5
6
7
8
9
10
-

+
+








<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>tsv - Tcl Threading</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108







-
+







--></style>
</head>
<!-- Generated from file '' by tcllib/doctools with format 'html'
   -->
<!-- tsv.n
   -->
<body><div class="doctools">
<h1 class="doctools_title">tsv(n) 2.8  &quot;Tcl Threading&quot;</h1>
<h1 class="doctools_title">tsv(n) 3.0  &quot;Tcl Threading&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>tsv - Part of the Tcl threading extension allowing script level manipulation of data shared between threads.</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
115
116
117
118
119
120
121
122
123


124
125
126
127
128
129
130
116
117
118
119
120
121
122


123
124
125
126
127
128
129
130
131







-
-
+
+







<li class="doctools_section"><a href="#see-also">See Also</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.7</b></li>
<li>package require <b class="pkgname">Thread <span class="opt">?2.8?</span></b></li>
<li>package require <b class="pkgname">Tcl 9.0</b></li>
<li>package require <b class="pkgname">thread <span class="opt">?3.0?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">tsv::names</b> <span class="opt">?pattern?</span></a></li>
<li><a href="#2"><b class="cmd">tsv::object</b> <i class="arg">varname</i> <i class="arg">element</i></a></li>
<li><a href="#3"><b class="cmd">tsv::set</b> <i class="arg">varname</i> <i class="arg">element</i> <span class="opt">?value?</span></a></li>
<li><a href="#4"><b class="cmd">tsv::get</b> <i class="arg">varname</i> <i class="arg">element</i> <span class="opt">?namedvar?</span></a></li>
<li><a href="#5"><b class="cmd">tsv::unset</b> <i class="arg">varname</i> <span class="opt">?element?</span></a></li>
Changes to doc/html/ttrace.html.
1
2


3
4
5
6
7
8
9

1
2
3
4
5
6
7
8
9
10
-

+
+








<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>ttrace - Tcl Threading</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120


121
122
123
124
125
126
127
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119


120
121
122
123
124
125
126
127
128







-
+


















-
-
+
+







--></style>
</head>
<!-- Generated from file '' by tcllib/doctools with format 'html'
   -->
<!-- ttrace.n
   -->
<body><div class="doctools">
<h1 class="doctools_title">ttrace(n) 2.8  &quot;Tcl Threading&quot;</h1>
<h1 class="doctools_title">ttrace(n) 3.0  &quot;Tcl Threading&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>ttrace - Trace-based interpreter initialization</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">USER COMMANDS</a></li>
<li class="doctools_section"><a href="#section3">CALLBACK COMMANDS</a></li>
<li class="doctools_section"><a href="#section4">DISCUSSION</a></li>
<li class="doctools_section"><a href="#see-also">See Also</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.7</b></li>
<li>package require <b class="pkgname">Thread <span class="opt">?2.8?</span></b></li>
<li>package require <b class="pkgname">Tcl 9.0</b></li>
<li>package require <b class="pkgname">thread <span class="opt">?3.0?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">ttrace::eval</b> <i class="arg">arg</i> <span class="opt">?arg ...?</span></a></li>
<li><a href="#2"><b class="cmd">ttrace::enable</b></a></li>
<li><a href="#3"><b class="cmd">ttrace::disable</b></a></li>
<li><a href="#4"><b class="cmd">ttrace::cleanup</b></a></li>
<li><a href="#5"><b class="cmd">ttrace::update</b> <span class="opt">?epoch?</span></a></li>
147
148
149
150
151
152
153
154
155
156



157
158
159
160
161

162
163
164
165
166
167
168
148
149
150
151
152
153
154



155
156
157
158
159
160
161

162
163
164
165
166
167
168
169







-
-
-
+
+
+




-
+







<b class="cmd">unknown</b> command and mechanism.</p>
<p>The package requires Tcl threading extension but can be alternatively
used stand-alone within the AOLserver, a scalable webserver from
America Online.</p>
<p>In a nutshell, a short sample illustrating the usage of the ttrace
with the Tcl threading extension:</p>
<pre class="doctools_example">
    % package require Ttrace
    2.8.1
    % set t1 [thread::create {package require Ttrace; thread::wait}]
    % package require ttrace
    3.0.2
    % set t1 [thread::create {package require ttrace; thread::wait}]
    tid0x1802800
    % ttrace::eval {proc test args {return test-[thread::id]}}
    % thread::send $t1 test
    test-tid0x1802800
    % set t2 [thread::create {package require Ttrace; thread::wait}]
    % set t2 [thread::create {package require ttrace; thread::wait}]
    tid0x1804000
    % thread::send $t2 test
    test-tid0x1804000
</pre>
<p>As seen from above, the <b class="cmd">ttrace::eval</b> and <b class="cmd">ttrace::update</b>
commands are used to create a thread-wide definition of a simple
Tcl procedure and replicate that definition to all, already existing
Changes to doc/man/thread.n.
1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







'\"
'\" Generated from file '' by tcllib/doctools with format 'nroff'
'\"
.TH "thread" n 2\&.8  "Tcl Threading"
.TH "thread" n 3\&.0  "Tcl Threading"
.\" The -*- nroff -*- definitions below are for supplemental macros used
.\" in Tcl/Tk manual entries.
.\"
.\" .AP type name in/out ?indent?
.\"	Start paragraph describing an argument to a library procedure.
.\"	type is type of argument (int, etc.), in/out is either "in", "out",
.\"	or "in/out" to describe whether procedure reads or modifies arg,
269
270
271
272
273
274
275
276

277
278

279
280
281
282
283
284
285
269
270
271
272
273
274
275

276
277

278
279
280
281
282
283
284
285







-
+

-
+







.de MT
.QW ""
..
.BS
.SH NAME
thread \- Extension for script access to Tcl threading
.SH SYNOPSIS
package require \fBTcl  8\&.4\fR
package require \fBTcl 9\&.0\fR
.sp
package require \fBThread  ?2\&.8?\fR
package require \fBthread ?3\&.0?\fR
.sp
\fBthread::create\fR ?-joinable? ?-preserved? ?script?
.sp
\fBthread::preserve\fR ?id?
.sp
\fBthread::release\fR ?-wait? ?id?
.sp
358
359
360
361
362
363
364
365

366
367
368

369
370
371
372
373
374
375
358
359
360
361
362
363
364

365



366
367
368
369
370
371
372
373







-
+
-
-
-
+







This section describes commands for creating and destroying threads
and sending scripts to threads for evaluation\&.
.TP
\fBthread::create\fR ?-joinable? ?-preserved? ?script?
This command creates a thread that contains a Tcl interpreter\&.
The Tcl interpreter either evaluates the optional \fBscript\fR, if
specified, or it waits in the event loop for scripts that arrive via
the \fBthread::send\fR command\&. Both of them would take place simultaneously
the \fBthread::send\fR command\&. The result, if any, of the
with the return of command \fBthread::create\fR to the caller thread\&.
Neither the caller is waiting for the finishing of optional \fBscript\fR,
nor the result, if any, of the \fBscript\fR is returned to the caller\&.
optional \fBscript\fR is never returned to the caller\&.
The result of \fBthread::create\fR is the ID of the thread\&. This is
the opaque handle which identifies the newly created thread for
all other package commands\&. The handle of the thread goes out of scope
automatically when thread is marked for exit
(see the \fBthread::release\fR command below)\&.
.sp
If the optional \fBscript\fR argument contains the \fBthread::wait\fR
585
586
587
588
589
590
591







592
593
594
595
596
597
598
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603







+
+
+
+
+
+
+







event queue can be placed on the head, instead on the tail of the queue,
thus being executed in the LIFO fashion\&.
.TP
\fBthread::broadcast\fR \fIscript\fR
This command passes a \fIscript\fR to all threads created by the
package for execution\&. It does not wait for response from any of
the threads\&.
.sp
The sending thread (the one executing the thread::broadcast command) does
not send the script to itself\&.
.sp
Each receiving thread is directed to place evaluation of the send script
at the head of its event queue, stepping in front of any other events
awaiting processing\&.
.TP
\fBthread::wait\fR
This enters the event loop so a thread can receive messages from
the \fBthread::send\fR command\&. This command should only be used
within the script passed to the \fBthread::create\fR\&. It should
be the very last command in the script\&. If this is not the case,
the exiting thread will continue executing the script lines past
857
858
859
860
861
862
863

862
863
864
865
866
867
868
869







+
For advanced multithreading scripts, script-level access to two
basic synchronization primitives, mutex and condition variables,
is also supported\&.
.SH "SEE ALSO"
\fIhttp://www\&.tcl\&.tk/doc/howto/thread_model\&.html\fR, tpool, tsv, ttrace
.SH KEYWORDS
events, message passing, mutex, synchronization, thread

Changes to doc/man/tpool.n.
1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







'\"
'\" Generated from file '' by tcllib/doctools with format 'nroff'
'\"
.TH "tpool" n 2\&.8  "Tcl Threading"
.TH "tpool" n 3\&.0  "Tcl Threading"
.\" The -*- nroff -*- definitions below are for supplemental macros used
.\" in Tcl/Tk manual entries.
.\"
.\" .AP type name in/out ?indent?
.\"	Start paragraph describing an argument to a library procedure.
.\"	type is type of argument (int, etc.), in/out is either "in", "out",
.\"	or "in/out" to describe whether procedure reads or modifies arg,
269
270
271
272
273
274
275
276

277
278

279
280
281
282
283
284
285
269
270
271
272
273
274
275

276
277

278
279
280
281
282
283
284
285







-
+

-
+







.de MT
.QW ""
..
.BS
.SH NAME
tpool \- Part of the Tcl threading extension implementing pools of worker threads\&.
.SH SYNOPSIS
package require \fBTcl  8\&.4\fR
package require \fBTcl 9\&.0\fR
.sp
package require \fBThread  ?2\&.8?\fR
package require \fBthread ?3\&.0?\fR
.sp
\fBtpool::create\fR ?options?
.sp
\fBtpool::names\fR
.sp
\fBtpool::post\fR ?-detached? ?-nowait? \fItpool\fR \fIscript\fR
.sp
385
386
387
388
389
390
391
392
393
394



395
396
397
398
399
400
401
385
386
387
388
389
390
391



392
393
394
395
396
397
398
399
400
401







-
-
-
+
+
+







for execution\&. The script will be executed in the first available idle
worker thread\&. If there are no idle worker threads available, the command
will create new one, enter the event loop and service events until the
newly created thread is initialized\&. If the current number of worker
threads is equal to the maximum number of worker threads, as defined
during the threadpool creation, the command will enter the event loop and
service events while waiting for one of the worker threads to become idle\&.
If the optional ?-nowait? argument is given, the command will not wait
for one idle worker\&. It will just place the job in the pool's job queue
and return immediately\&.
If the optional ?-nowait? argument is given, the command just places the
job in the pool's job queue without waiting for an idle worker or creating a
new one, even if the pool would still have room for additional threads\&.
.sp
The command returns the ID of the posted job\&. This ID is used for subsequent
\fBtpool::wait\fR, \fBtpool::get\fR and \fBtpool::cancel\fR commands to wait
for and retrieve result of the posted script, or cancel the posted job
respectively\&. If the optional ?-detached? argument is specified, the
command will post a detached job\&. A detached job can not be cancelled or
waited upon and is not identified by the job ID\&.
490
491
492
493
494
495
496

490
491
492
493
494
495
496
497







+
can be serviced immediately\&. Furthermore, by properly tuning the number
of threads in the thread pool, resource thrashing may also be eliminated
by forcing any request to wait until a thread is available to process it\&.
.SH "SEE ALSO"
thread, tsv, ttrace
.SH KEYWORDS
thread, threadpool

Changes to doc/man/tsv.n.
1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







'\"
'\" Generated from file '' by tcllib/doctools with format 'nroff'
'\"
.TH "tsv" n 2\&.8  "Tcl Threading"
.TH "tsv" n 3\&.0  "Tcl Threading"
.\" The -*- nroff -*- definitions below are for supplemental macros used
.\" in Tcl/Tk manual entries.
.\"
.\" .AP type name in/out ?indent?
.\"	Start paragraph describing an argument to a library procedure.
.\"	type is type of argument (int, etc.), in/out is either "in", "out",
.\"	or "in/out" to describe whether procedure reads or modifies arg,
269
270
271
272
273
274
275
276

277
278

279
280
281
282
283
284
285
269
270
271
272
273
274
275

276
277

278
279
280
281
282
283
284
285







-
+

-
+







.de MT
.QW ""
..
.BS
.SH NAME
tsv \- Part of the Tcl threading extension allowing script level manipulation of data shared between threads\&.
.SH SYNOPSIS
package require \fBTcl  8\&.4\fR
package require \fBTcl 9\&.0\fR
.sp
package require \fBThread  ?2\&.8?\fR
package require \fBthread ?3\&.0?\fR
.sp
\fBtsv::names\fR ?pattern?
.sp
\fBtsv::object\fR \fIvarname\fR \fIelement\fR
.sp
\fBtsv::set\fR \fIvarname\fR \fIelement\fR ?value?
.sp
622
623
624
625
626
627
628

622
623
624
625
626
627
628
629







+
.SH CREDITS
Thread shared variables are inspired by the nsv interface found in
AOLserver, a highly scalable Web server from America Online\&.
.SH "SEE ALSO"
thread, tpool, ttrace
.SH KEYWORDS
locking, synchronization, thread shared data, threads

Changes to doc/man/ttrace.n.
1
2
3
4

5
6
7
8
9
10
11
1
2
3

4
5
6
7
8
9
10
11



-
+







'\"
'\" Generated from file '' by tcllib/doctools with format 'nroff'
'\"
.TH "ttrace" n 2\&.8  "Tcl Threading"
.TH "ttrace" n 3\&.0  "Tcl Threading"
.\" The -*- nroff -*- definitions below are for supplemental macros used
.\" in Tcl/Tk manual entries.
.\"
.\" .AP type name in/out ?indent?
.\"	Start paragraph describing an argument to a library procedure.
.\"	type is type of argument (int, etc.), in/out is either "in", "out",
.\"	or "in/out" to describe whether procedure reads or modifies arg,
269
270
271
272
273
274
275
276

277
278

279
280
281
282
283
284
285
269
270
271
272
273
274
275

276
277

278
279
280
281
282
283
284
285







-
+

-
+







.de MT
.QW ""
..
.BS
.SH NAME
ttrace \- Trace-based interpreter initialization
.SH SYNOPSIS
package require \fBTcl  8\&.4\fR
package require \fBTcl 9\&.0\fR
.sp
package require \fBThread  ?2\&.8?\fR
package require \fBthread ?3\&.0?\fR
.sp
\fBttrace::eval\fR \fIarg\fR ?arg \&.\&.\&.?
.sp
\fBttrace::enable\fR
.sp
\fBttrace::disable\fR
.sp
324
325
326
327
328
329
330
331
332


333
334

335
336
337
338
339
340
341

342
343
344
345
346
347
348
324
325
326
327
328
329
330


331
332
333

334
335
336
337
338
339
340

341
342
343
344
345
346
347
348







-
-
+
+

-
+






-
+







.PP
In a nutshell, a short sample illustrating the usage of the ttrace
with the Tcl threading extension:
.CS



    % package require Ttrace
    2\&.8\&.2
    % package require ttrace
    3\&.0\&.1

    % set t1 [thread::create {package require Ttrace; thread::wait}]
    % set t1 [thread::create {package require ttrace; thread::wait}]
    tid0x1802800

    % ttrace::eval {proc test args {return test-[thread::id]}}
    % thread::send $t1 test
    test-tid0x1802800

    % set t2 [thread::create {package require Ttrace; thread::wait}]
    % set t2 [thread::create {package require ttrace; thread::wait}]
    tid0x1804000

    % thread::send $t2 test
    test-tid0x1804000


.CE
500
501
502
503
504
505
506

500
501
502
503
504
505
506
507







+
about 50 times\&. Note that your mileage may vary\&.
Other benefits include much finer control about what (and when) gets
replicated from the master to other Tcl thread/interpreters\&.
.SH "SEE ALSO"
thread, tpool, tsv
.SH KEYWORDS
command tracing, introspection

Changes to doc/thread.man.
1
2

3
4
5
6


7
8
9
10
11
12
13
1

2
3
4


5
6
7
8
9
10
11
12
13

-
+


-
-
+
+







[comment {-*- tcl -*- doctools manpage}]
[manpage_begin thread n 2.8]
[manpage_begin thread n 3.0]
[moddesc {Tcl Threading}]
[titledesc {Extension for script access to Tcl threading}]
[require Tcl 8.7]
[require Thread [opt 2.8]]
[require Tcl 9.0]
[require thread [opt 3.0]]

[description]
The [package thread] extension creates threads that contain Tcl
interpreters, and it lets you send scripts to those threads for
evaluation.

Additionally, it provides script-level access to basic thread
279
280
281
282
283
284
285











286
287
288
289
290
291
292
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303







+
+
+
+
+
+
+
+
+
+
+








[call [cmd thread::broadcast] [arg script]]

This command passes a [arg script] to all threads created by the
package for execution. It does not wait for response from any of
the threads.

[para]

The sending thread (the one executing the thread::broadcast command) does
not send the script to itself.

[para]

Each receiving thread is directed to place evaluation of the send script
at the head of its event queue, stepping in front of any other events
awaiting processing.

[call [cmd thread::wait]]

This enters the event loop so a thread can receive messages from
the [cmd thread::send] command. This command should only be used
within the script passed to the [cmd thread::create]. It should
be the very last command in the script. If this is not the case,
the exiting thread will continue executing the script lines past
Changes to doc/tpool.man.
1
2

3
4
5
6


7
8
9
10
11
12
13
1

2
3
4


5
6
7
8
9
10
11
12
13

-
+


-
-
+
+







[comment {-*- tcl -*- doctools manpage}]
[manpage_begin tpool n 2.8]
[manpage_begin tpool n 3.0]
[moddesc {Tcl Threading}]
[titledesc {Part of the Tcl threading extension implementing pools of worker threads.}]
[require Tcl 8.7]
[require Thread [opt 2.8]]
[require Tcl 9.0]
[require thread [opt 3.0]]

[description]
This package creates and manages pools of worker threads. It allows you
to post jobs to worker threads and wait for their completion. The
threadpool implementation is Tcl event-loop aware. That means that any
time a caller is forced to wait for an event (job being completed or
a worker thread becoming idle or initialized), the implementation will
101
102
103
104
105
106
107
108
109
110



111
112
113
114
115
116
117
101
102
103
104
105
106
107



108
109
110
111
112
113
114
115
116
117







-
-
-
+
+
+







for execution. The script will be executed in the first available idle
worker thread. If there are no idle worker threads available, the command
will create new one, enter the event loop and service events until the
newly created thread is initialized. If the current number of worker
threads is equal to the maximum number of worker threads, as defined
during the threadpool creation, the command will enter the event loop and
service events while waiting for one of the worker threads to become idle.
If the optional [opt -nowait] argument is given, the command will not wait
for one idle worker. It will just place the job in the pool's job queue
and return immediately.
If the optional [opt -nowait] argument is given, the command just places the
job in the pool's job queue without waiting for an idle worker or creating a
new one, even if the pool would still have room for additional threads.
[para]
The command returns the ID of the posted job. This ID is used for subsequent
[cmd tpool::wait], [cmd tpool::get] and [cmd tpool::cancel] commands to wait
for and retrieve result of the posted script, or cancel the posted job
respectively. If the optional [opt -detached] argument is specified, the
command will post a detached job. A detached job can not be cancelled or
waited upon and is not identified by the job ID.
Changes to doc/tsv.man.
1
2

3
4
5
6


7
8
9
10
11
12
13
1

2
3
4


5
6
7
8
9
10
11
12
13

-
+


-
-
+
+







[comment {-*- tcl -*- doctools manpage}]
[manpage_begin tsv n 2.8]
[manpage_begin tsv n 3.0]
[moddesc {Tcl Threading}]
[titledesc {Part of the Tcl threading extension allowing script level manipulation of data shared between threads.}]
[require Tcl 8.7]
[require Thread [opt 2.8]]
[require Tcl 9.0]
[require thread [opt 3.0]]

[description]
This section describes commands implementing thread shared variables.
A thread shared variable is very similar to a Tcl array but in
contrast to a Tcl array it is created in shared memory and can
be accessed from many threads at the same time. Important feature of
thread shared variable is that each access to the variable is internally
Changes to doc/ttrace.man.
1
2

3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24


25
26

27
28
29
30
31
32
33

34
35
36
37
38
39
40
1

2
3
4


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


23
24
25

26
27
28
29
30
31
32

33
34
35
36
37
38
39
40

-
+


-
-
+
+
















-
-
+
+

-
+






-
+







[comment {-*- tcl -*- doctools manpage}]
[manpage_begin ttrace n 2.8]
[manpage_begin ttrace n 3.0]
[moddesc {Tcl Threading}]
[titledesc {Trace-based interpreter initialization}]
[require Tcl 8.7]
[require Thread [opt 2.8]]
[require Tcl 9.0]
[require thread [opt 3.0]]

[description]
This package creates a framework for on-demand replication of the
interpreter state across threads in an multithreading application.
It relies on the mechanics of Tcl command tracing and the Tcl
[cmd unknown] command and mechanism.
[para]
The package requires Tcl threading extension but can be alternatively
used stand-alone within the AOLserver, a scalable webserver from
America Online.
[para]
In a nutshell, a short sample illustrating the usage of the ttrace
with the Tcl threading extension:

[example {

    % package require Ttrace
    2.8.1
    % package require ttrace
    3.0.2

    % set t1 [thread::create {package require Ttrace; thread::wait}]
    % set t1 [thread::create {package require ttrace; thread::wait}]
    tid0x1802800

    % ttrace::eval {proc test args {return test-[thread::id]}}
    % thread::send $t1 test
    test-tid0x1802800

    % set t2 [thread::create {package require Ttrace; thread::wait}]
    % set t2 [thread::create {package require ttrace; thread::wait}]
    tid0x1804000

    % thread::send $t2 test
    test-tid0x1804000

}]
[para]
Changes to generic/psGdbm.c.
140
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156

157
158
159
160
161
162
163
164







-
+









-
+







 *-----------------------------------------------------------------------------
 */
static int
ps_gdbm_get(
     void *handle,
     const char   *key,
     char **dataptrptr,
     size_t    *lenptr)
     Tcl_Size *lenptr)
{
    GDBM_FILE dbf = (GDBM_FILE)handle;
    datum drec, dkey;

    dkey.dptr  = (char*)key;
    dkey.dsize = strlen(key) + 1;

    drec = gdbm_fetch(dbf, dkey);
    if (drec.dptr == NULL) {
        return 1;
	return 1;
    }

    *dataptrptr = drec.dptr;
    *lenptr = drec.dsize;

    return 0;
}
180
181
182
183
184
185
186
187

188
189
190
191
192
193
194

195
196
197
198

199
200
201
202
203
204
205
180
181
182
183
184
185
186

187
188
189
190
191
192
193

194
195
196
197

198
199
200
201
202
203
204
205







-
+






-
+



-
+







 *-----------------------------------------------------------------------------
 */
static int
ps_gdbm_first(
    void *handle,
    char   **keyptrptr,
    char  **dataptrptr,
    size_t     *lenptr)
    Tcl_Size *lenptr)
{
    GDBM_FILE dbf = (GDBM_FILE)handle;
    datum drec, dkey;

    dkey = gdbm_firstkey(dbf);
    if (dkey.dptr == NULL) {
        return 1;
	return 1;
    }
    drec = gdbm_fetch(dbf, dkey);
    if (drec.dptr == NULL) {
        return 1;
	return 1;
    }

    *dataptrptr = drec.dptr;
    *lenptr = drec.dsize;
    *keyptrptr = dkey.dptr;

    return 0;
221
222
223
224
225
226
227
228

229
230
231
232
233
234
235
236
237
238
239
240

241
242
243
244

245
246
247
248
249
250
251
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235
236
237
238
239

240
241
242
243

244
245
246
247
248
249
250
251







-
+











-
+



-
+







 *
 *-----------------------------------------------------------------------------
 */
static int ps_gdbm_next(
    void *handle,
    char   **keyptrptr,
    char  **dataptrptr,
    size_t     *lenptr)
    Tcl_Size *lenptr)
{
    GDBM_FILE dbf = (GDBM_FILE)handle;
    datum drec, dkey, dnext;

    dkey.dptr  = *keyptrptr;
    dkey.dsize = strlen(*keyptrptr) + 1;

    dnext = gdbm_nextkey(dbf, dkey);
    free(*keyptrptr), *keyptrptr = NULL;

    if (dnext.dptr == NULL) {
        return 1;
	return 1;
    }
    drec = gdbm_fetch(dbf, dnext);
    if (drec.dptr == NULL) {
        return 1;
	return 1;
    }

    *dataptrptr = drec.dptr;
    *lenptr = drec.dsize;
    *keyptrptr = dnext.dptr;

    return 0;
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284
285
286
287
288
289
290

291
292
293
294
295
296
297
269
270
271
272
273
274
275

276
277
278
279
280
281
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
297







-
+













-
+







 *-----------------------------------------------------------------------------
 */
static int
ps_gdbm_put(
    void *handle,
    const char   *key,
    char     *dataptr,
    size_t        len)
    Tcl_Size len)
{
    GDBM_FILE dbf = (GDBM_FILE)handle;
    datum drec, dkey;
    int ret;

    dkey.dptr  = (char*)key;
    dkey.dsize = strlen(key) + 1;

    drec.dptr  = dataptr;
    drec.dsize = len;

    ret = gdbm_store(dbf, dkey, drec, GDBM_REPLACE);
    if (ret == -1) {
        return -1;
	return -1;
    }

    return 0;
}

/*
 *-----------------------------------------------------------------------------
320
321
322
323
324
325
326
327

328
329
330
331
332
333
334
320
321
322
323
324
325
326

327
328
329
330
331
332
333
334







-
+







    int ret;

    dkey.dptr  = (char*)key;
    dkey.dsize = strlen(key) + 1;

    ret = gdbm_delete(dbf, dkey);
    if (ret == -1) {
        return -1;
	return -1;
    }

    return 0;
}

/*
 *-----------------------------------------------------------------------------
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
358
359
360
343
344
345
346
347
348
349

350
351
352

353
354
355
356
357
358
359







-
+


-







 * Side effects:
 *      Memory gets reclaimed.
 *
 *-----------------------------------------------------------------------------
 */
static void
ps_gdbm_free(
    void *handle,
    TCL_UNUSED(void *),
    void        *data)
{
    (void)handle;
    free(data);
}

/*
 *-----------------------------------------------------------------------------
 *
 * ps_gdbm_geterr --
368
369
370
371
372
373
374
375

376
377
378
379
380
381
382
383
384
367
368
369
370
371
372
373

374
375

376
377
378
379
380
381
382







-
+

-







 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */
static const char*
ps_gdbm_geterr(
    void *handle)
    TCL_UNUSED(void *))
{
    (void)handle;
    /*
     * The problem with gdbm interface is that it uses the global
     * gdbm_errno variable which is not per-thread nor mutex
     * protected. This variable is used to reference array of gdbm
     * error text strings. It is very dangerous to use this in the
     * MT-program without proper locking. For this kind of app
     * we should not be concerned with that, since all ps_gdbm_xxx
Changes to generic/psLmdb.c.
38
39
40
41
42
43
44
45
46
47
48
49





50
51
52
53

54
55
56
57
58

59
60
61
62
63
64


65
66
67
68
69
70
71
38
39
40
41
42
43
44





45
46
47
48
49
50
51
52

53
54
55
56
57

58
59
60
61
62


63
64
65
66
67
68
69
70
71







-
-
-
-
-
+
+
+
+
+



-
+




-
+




-
-
+
+







static void LmdbTxnAbort(LmdbCtx ctx);

void LmdbTxnGet(LmdbCtx ctx, enum LmdbOpenMode mode)
{
    // Read transactions are reused, if possible
    if (ctx->txn && mode == LmdbRead)
    {
        ctx->err = mdb_txn_renew(ctx->txn);
        if (ctx->err)
        {
            ctx->txn = NULL;
        }
	ctx->err = mdb_txn_renew(ctx->txn);
	if (ctx->err)
	{
	    ctx->txn = NULL;
	}
    }
    else if (ctx->txn && mode == LmdbWrite)
    {
        LmdbTxnAbort(ctx);
	LmdbTxnAbort(ctx);
    }

    if (ctx->txn == NULL)
    {
        ctx->err = mdb_txn_begin(ctx->env, NULL, 0, &ctx->txn);
	ctx->err = mdb_txn_begin(ctx->env, NULL, 0, &ctx->txn);
    }

    if (ctx->err)
    {
        ctx->txn = NULL;
        return;
	ctx->txn = NULL;
	return;
    }

    // Given the setup above, and the arguments given, this won't fail.
    mdb_dbi_open(ctx->txn, NULL, 0, &ctx->dbi);
}

void LmdbTxnCommit(LmdbCtx ctx)
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173
174
175
176
177


178
179
180
181
182
183
184
185

186
187
188


189
190
191
192
193
194
195
158
159
160
161
162
163
164

165
166
167
168
169
170
171
172
173
174
175


176
177
178
179
180
181
182
183
184

185



186
187
188
189
190
191
192
193
194







-
+










-
-
+
+







-
+
-
-
-
+
+








    char *ext;
    Tcl_DString toext;

    ctx = (LmdbCtx)Tcl_Alloc(sizeof(*ctx));
    if (ctx == NULL)
    {
        return NULL;
	return NULL;
    }

    ctx->env = NULL;
    ctx->txn = NULL;
    ctx->cur = NULL;
    ctx->dbi = 0;

    ctx->err = mdb_env_create(&ctx->env);
    if (ctx->err)
    {
        Tcl_Free(ctx);
        return NULL;
	Tcl_Free(ctx);
	return NULL;
    }

    Tcl_DStringInit(&toext);
    ext = Tcl_UtfToExternalDString(NULL, path, strlen(path), &toext);
    ctx->err = mdb_env_open(ctx->env, ext, MDB_NOSUBDIR|MDB_NOLOCK, 0666);
    Tcl_DStringFree(&toext);

    if (ctx->err)
    if (ctx->err) {
    {
    	Tcl_Free(ctx);
        return NULL;
	Tcl_Free(ctx);
	return NULL;
    }

    return ctx;
}

/*
 *-----------------------------------------------------------------------------
209
210
211
212
213
214
215
216

217
218
219
220

221
222
223
224
225
226
227
208
209
210
211
212
213
214

215
216
217
218

219
220
221
222
223
224
225
226







-
+



-
+







static int
ps_lmdb_close(
    void *handle)
{
    LmdbCtx ctx = (LmdbCtx)handle;
    if (ctx->cur)
    {
        mdb_cursor_close(ctx->cur);
	mdb_cursor_close(ctx->cur);
    }
    if (ctx->txn)
    {
        LmdbTxnAbort(ctx);
	LmdbTxnAbort(ctx);
    }

    mdb_env_close(ctx->env);
    Tcl_Free(ctx);

    return 0;
}
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
258

259
260
261
262
263
264
265
266
267
268


269
270
271
272
273
274
275
242
243
244
245
246
247
248

249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
264
265


266
267
268
269
270
271
272
273
274







-
+







-
+








-
-
+
+







 *-----------------------------------------------------------------------------
 */
static int
ps_lmdb_get(
     void *handle,
     const char *keyptr,
     char  **dataptrptr,
     size_t     *lenptr)
     Tcl_Size *lenptr)
{
    LmdbCtx ctx = (LmdbCtx)handle;
    MDB_val key, data;

    LmdbTxnGet(ctx, LmdbRead);
    if (ctx->err)
    {
        return 1;
	return 1;
    }

    key.mv_data = (void *)keyptr;
    key.mv_size = strlen(keyptr) + 1;

    ctx->err = mdb_get(ctx->txn, ctx->dbi, &key, &data);
    if (ctx->err)
    {
        mdb_txn_reset(ctx->txn);
        return 1;
	mdb_txn_reset(ctx->txn);
	return 1;
    }

    *dataptrptr = (char *)data.mv_data;
    *lenptr = data.mv_size;

    /*
     * Transaction is left open at this point, so that the caller can get ahold
298
299
300
301
302
303
304
305

306
307
308
309
310
311
312
313

314
315
316
317
318
319

320
321
322
323
324
325
326
327
328




329
330
331
332
333
334
335
297
298
299
300
301
302
303

304
305
306
307
308
309
310
311

312
313
314
315
316
317

318
319
320
321
322
323




324
325
326
327
328
329
330
331
332
333
334







-
+







-
+





-
+





-
-
-
-
+
+
+
+







 *-----------------------------------------------------------------------------
 */
static int
ps_lmdb_first(
    void *handle,
    char   **keyptrptr,
    char  **dataptrptr,
    size_t     *lenptr)
    Tcl_Size *lenptr)
{
    LmdbCtx ctx = (LmdbCtx)handle;
    MDB_val key, data;

    LmdbTxnGet(ctx, LmdbRead);
    if (ctx->err)
    {
        return 1;
	return 1;
    }

    ctx->err = mdb_cursor_open(ctx->txn, ctx->dbi, &ctx->cur);
    if (ctx->err)
    {
        return 1;
	return 1;
    }

    ctx->err = mdb_cursor_get(ctx->cur, &key, &data, MDB_FIRST);
    if (ctx->err)
    {
        mdb_txn_reset(ctx->txn);
        mdb_cursor_close(ctx->cur);
        ctx->cur = NULL;
        return 1;
	mdb_txn_reset(ctx->txn);
	mdb_cursor_close(ctx->cur);
	ctx->cur = NULL;
	return 1;
    }

    *dataptrptr = (char *)data.mv_data;
    *lenptr = data.mv_size;
    *keyptrptr = (char *)key.mv_data;

    return 0;
351
352
353
354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369




370
371
372
373
374
375
376
350
351
352
353
354
355
356

357
358
359
360
361
362
363
364




365
366
367
368
369
370
371
372
373
374
375







-
+







-
-
-
-
+
+
+
+







 *
 *-----------------------------------------------------------------------------
 */
static int ps_lmdb_next(
    void *handle,
    char   **keyptrptr,
    char  **dataptrptr,
    size_t     *lenptr)
    Tcl_Size *lenptr)
{
    LmdbCtx ctx = (LmdbCtx)handle;
    MDB_val key, data;

    ctx->err = mdb_cursor_get(ctx->cur, &key, &data, MDB_NEXT);
    if (ctx->err)
    {
        mdb_txn_reset(ctx->txn);
        mdb_cursor_close(ctx->cur);
        ctx->cur = NULL;
        return 1;
	mdb_txn_reset(ctx->txn);
	mdb_cursor_close(ctx->cur);
	ctx->cur = NULL;
	return 1;
    }

    *dataptrptr = (char *)data.mv_data;
    *lenptr = data.mv_size;
    *keyptrptr = (char *)key.mv_data;

    return 0;
394
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409

410
411
412
413
414
415
416
417
418
419
420
421

422
423
424
425

426
427
428
429
430
431
432
393
394
395
396
397
398
399

400
401
402
403
404
405
406
407

408
409
410
411
412
413
414
415
416
417
418
419

420
421
422
423

424
425
426
427
428
429
430
431







-
+







-
+











-
+



-
+







 *-----------------------------------------------------------------------------
 */
static int
ps_lmdb_put(
    void *handle,
    const char *keyptr,
    char      *dataptr,
    size_t         len)
    Tcl_Size len)
{
    LmdbCtx ctx = (LmdbCtx)handle;
    MDB_val key, data;

    LmdbTxnGet(ctx, LmdbWrite);
    if (ctx->err)
    {
        return -1;
	return -1;
    }

    key.mv_data = (void*)keyptr;
    key.mv_size = strlen(keyptr) + 1;

    data.mv_data = dataptr;
    data.mv_size = len;

    ctx->err = mdb_put(ctx->txn, ctx->dbi, &key, &data, 0);
    if (ctx->err)
    {
        LmdbTxnAbort(ctx);
	LmdbTxnAbort(ctx);
    }
    else
    {
        LmdbTxnCommit(ctx);
	LmdbTxnCommit(ctx);
    }

    return ctx->err ? -1 : 0;
}

/*
 *-----------------------------------------------------------------------------
452
453
454
455
456
457
458
459

460
461
462
463
464
465
466
467
468

469
470
471
472

473
474
475
476
477
478
479
451
452
453
454
455
456
457

458
459
460
461
462
463
464
465
466

467
468
469
470

471
472
473
474
475
476
477
478







-
+








-
+



-
+







{
    LmdbCtx ctx = (LmdbCtx)handle;
    MDB_val key;

    LmdbTxnGet(ctx, LmdbWrite);
    if (ctx->err)
    {
        return -1;
	return -1;
    }

    key.mv_data = (void*)keyptr;
    key.mv_size = strlen(keyptr) + 1;

    ctx->err = mdb_del(ctx->txn, ctx->dbi, &key, NULL);
    if (ctx->err)
    {
        LmdbTxnAbort(ctx);
	LmdbTxnAbort(ctx);
    }
    else
    {
        LmdbTxnCommit(ctx);
	LmdbTxnCommit(ctx);
    }

    ctx->txn = NULL;
    return ctx->err ? -1 : 0;
}

/*
494
495
496
497
498
499
500
501

502
503
504
505
506
507
508

509
510
511
512
513
514
515
493
494
495
496
497
498
499

500
501
502

503
504
505

506
507
508
509
510
511
512
513







-
+


-



-
+







 *      Memory gets reclaimed.
 *
 *-----------------------------------------------------------------------------
 */
static void
ps_lmdb_free(
    void *handle,
    void        *data)
    TCL_UNUSED(void *))
{
    LmdbCtx ctx = (LmdbCtx)handle;
    (void)data;

    if (ctx->cur == NULL)
    {
        mdb_txn_reset(ctx->txn);
	mdb_txn_reset(ctx->txn);
    }
}

/*
 *-----------------------------------------------------------------------------
 *
 * ps_lmdb_geterr --
Changes to generic/tclThreadInt.h.
22
23
24
25
26
27
28


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48




49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65















66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84
85
86
87

88
89
90
91
92
93

94
95
96
97
98
99
100
101
102

103
104
105
106
107

108
109

110
111

112
113
114
115
116
117
118
119


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101

102
103
104
105
106
107

108
109
110
111
112
113

114
115
116
117
118
119
120
121
122

123
124
125
126
127

128
129

130
131

132
133
134
135
136
137
138


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159






160







+
+




















+
+
+
+











-
+





+
+
+
+
+
+
+
+
+
+
+
+
+
+
+















-
+





-
+





-
+








-
+




-
+

-
+

-
+






-
-
+
+



















-
-
-
-
-
-


/*
 * MSVC 8.0 started to mark many standard C library functions depreciated
 * including the *printf family and others. Tell it to shut up.
 * (_MSC_VER is 1200 for VC6, 1300 or 1310 for vc7.net, 1400 for 8.0)
 */
#if defined(_MSC_VER)
#   pragma warning(disable:4090) /* see: https://developercommunity.visualstudio.com/t/c-compiler-incorrect-propagation-of-const-qualifie/390711 */
#   pragma warning(disable:4146)
#   pragma warning(disable:4244)
#   if _MSC_VER >= 1400
#	pragma warning(disable:4267)
#	pragma warning(disable:4996)
#   endif
#endif

/*
 * Used to tag functions that are only to be visible within the module being
 * built and not outside it (where this is supported by the linker).
 */

#ifndef MODULE_SCOPE
#   ifdef __cplusplus
#       define MODULE_SCOPE extern "C"
#   else
#       define MODULE_SCOPE extern
#   endif
#endif

#if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1900
#  define snprintf _snprintf
#endif

/*
 * For linking against NaviServer/AOLserver require V4 at least
 */

#ifdef NS_AOLSERVER
# include <ns.h>
# if !defined(NS_MAJOR_VERSION) || NS_MAJOR_VERSION < 4
#  error "unsupported NaviServer/AOLserver version"
# endif
#endif

#if (TCL_MAJOR_VERSION < 9) && defined(USE_TCL_STUBS)
#if (TCL_MAJOR_VERSION == 8) && defined(USE_TCL_STUBS)
#undef Tcl_Free
#define Tcl_Free(p) tclStubsPtr->tcl_Free((void *)(p))
#undef Tcl_Realloc
#define Tcl_Realloc(p,m) tclStubsPtr->tcl_Realloc((void *)(p),(m))
#endif

#ifndef JOIN
#  define JOIN(a,b) JOIN1(a,b)
#  define JOIN1(a,b) a##b
#endif

#ifndef TCL_UNUSED
#   if defined(__cplusplus)
#	define TCL_UNUSED(T) T
#   elif defined(__GNUC__) && (__GNUC__ > 2)
#	define TCL_UNUSED(T) T JOIN(dummy, __LINE__) __attribute__((unused))
#   else
#	define TCL_UNUSED(T) T JOIN(dummy, __LINE__)
#   endif
#endif

/*
 * Allow for some command names customization.
 * Only thread:: and tpool:: are handled here.
 * Shared variable commands are more complicated.
 * Look into the threadSvCmd.h for more info.
 */

#define THREAD_CMD_PREFIX "thread::"
#define TPOOL_CMD_PREFIX  "tpool::"

/*
 * Exported from threadSvCmd.c file.
 */

MODULE_SCOPE int Sv_Init(Tcl_Interp *interp);
MODULE_SCOPE const char *SvInit(Tcl_Interp *interp);

/*
 * Exported from threadSpCmd.c file.
 */

MODULE_SCOPE int Sp_Init(Tcl_Interp *interp);
MODULE_SCOPE const char *SpInit(Tcl_Interp *interp);

/*
 * Exported from threadPoolCmd.c file.
 */

MODULE_SCOPE int Tpool_Init(Tcl_Interp *interp);
MODULE_SCOPE const char *TpoolInit(Tcl_Interp *interp);

/*
 * Macros for splicing in/out of linked lists
 */

#define SpliceIn(a,b)                          \
    (a)->nextPtr = (b);                        \
    if ((b) != NULL)                           \
        (b)->prevPtr = (a);                    \
	(b)->prevPtr = (a);                    \
    (a)->prevPtr = NULL, (b) = (a)

#define SpliceOut(a,b)                         \
    if ((a)->prevPtr != NULL)                  \
        (a)->prevPtr->nextPtr = (a)->nextPtr;  \
	(a)->prevPtr->nextPtr = (a)->nextPtr;  \
    else                                       \
        (b) = (a)->nextPtr;                    \
	(b) = (a)->nextPtr;                    \
    if ((a)->nextPtr != NULL)                  \
        (a)->nextPtr->prevPtr = (a)->prevPtr
	(a)->nextPtr->prevPtr = (a)->prevPtr

/*
 * Utility macros
 */

#define TCL_CMD(a,b,c) \
  if (Tcl_CreateObjCommand((a),(b),(c),NULL, NULL) == NULL) \
    return TCL_ERROR
  if (Tcl_CreateObjCommand2((a),(b),(c),NULL, NULL) == NULL) \
    return NULL;

#define OPT_CMP(a,b) \
  ((a) && (b) && ((a)[0]==(b)[0]) && ((a)[1]==(b)[1]) && (!strcmp((a),(b))))

#ifndef TCL_TSD_INIT
#define TCL_TSD_INIT(keyPtr) \
  (ThreadSpecificData*)Tcl_GetThreadData((keyPtr),sizeof(ThreadSpecificData))
#endif

/*
 * Structure to pass to NsThread_Init. This holds the module
 * and virtual server name for proper interp initializations.
 */

typedef struct {
    char *modname;
    char *server;
} NsThreadInterpData;

#if defined(USE_TCL_STUBS)
# undef Tcl_GetUnicodeFromObj
# define Tcl_GetUnicodeFromObj ((((&(tclStubsPtr->tcl_PkgProvideEx))[378]) != ((&(tclStubsPtr->tcl_PkgProvideEx))[434])) ? \
  ((void (*)(Tcl_Obj *, int *))((&(tclStubsPtr->tcl_PkgProvideEx))[434])) : ((void (*)(Tcl_Obj *, int *)) NULL))
#endif

#endif /* _TCL_THREAD_INT_H_ */
Changes to generic/tclXkeylist.c.
38
39
40
41
42
43
44
45
46


47
48
49
50
51
52
53
38
39
40
41
42
43
44


45
46
47
48
49
50
51
52
53







-
-
+
+







/*
 * Assert macro for use in TclX.  Some GCCs libraries are missing a function
 * used by their macro, so we define out own.
 */

#ifdef TCLX_DEBUG
# define TclX_Assert(expr) ((expr) ? NULL : \
                            panic("TclX assertion failure: %s:%d \"%s\"\n",\
                            __FILE__, __LINE__, "expr"))
			    panic("TclX assertion failure: %s:%d \"%s\"\n",\
			    __FILE__, __LINE__, "expr"))
#else
# define TclX_Assert(expr)
#endif

/*
 * Macro that behaves like strdup, only uses Tcl_Alloc.  Also macro that does the
 * same with a string that might contain zero bytes,
79
80
81
82
83
84
85
86

87
88
89
90



91
92
93
94
95
96
97
79
80
81
82
83
84
85

86
87



88
89
90
91
92
93
94
95
96
97







-
+

-
-
-
+
+
+







 *-----------------------------------------------------------------------------
 */
static int
TclX_IsNullObj (
    Tcl_Obj *objPtr
) {
    if (objPtr->typePtr == NULL) {
        return (objPtr->length == 0);
	return (objPtr->length == 0);
    } else if (objPtr->typePtr == listType) {
        int length;
        Tcl_ListObjLength(NULL, objPtr, &length);
        return (length == 0);
	Tcl_Size length;
	Tcl_ListObjLength(NULL, objPtr, &length);
	return (length == 0);
    }
    (void)Tcl_GetString(objPtr);
    return (objPtr->length == 0);
}

/*-----------------------------------------------------------------------------
 * TclX_AppendObjResult --
112
113
114
115
116
117
118
119
120


121
122
123
124
125
126
127
128





129
130
131
132
133
134
135
112
113
114
115
116
117
118


119
120
121
122
123





124
125
126
127
128
129
130
131
132
133
134
135







-
-
+
+



-
-
-
-
-
+
+
+
+
+







    va_list argList;
    char *string;

    va_start(argList, interp);
    resultPtr = Tcl_GetObjResult (interp);

    if (Tcl_IsShared(resultPtr)) {
        resultPtr = Tcl_NewStringObj(NULL, 0);
        Tcl_SetObjResult(interp, resultPtr);
	resultPtr = Tcl_NewStringObj(NULL, 0);
	Tcl_SetObjResult(interp, resultPtr);
    }

    while (1) {
        string = va_arg(argList, char *);
        if (string == NULL) {
            break;
        }
        Tcl_AppendToObj (resultPtr, string, -1);
	string = va_arg(argList, char *);
	if (string == NULL) {
	    break;
	}
	Tcl_AppendToObj (resultPtr, string, TCL_INDEX_NONE);
    }
    va_end(argList);
}

/*-----------------------------------------------------------------------------
 * TclX_WrongArgs --
 *
149
150
151
152
153
154
155
156
157
158



159
160
161

162
163
164
165
166
167
168
149
150
151
152
153
154
155



156
157
158
159
160

161
162
163
164
165
166
167
168







-
-
-
+
+
+


-
+







    const char  *string
) {
    const char *commandName = Tcl_GetString(commandNameObj);
    Tcl_Obj *resultPtr = Tcl_GetObjResult(interp);

    Tcl_ResetResult(interp);
    Tcl_AppendStringsToObj (resultPtr,
                            tclXWrongArgs,
                            commandName,
                            NULL);
			    tclXWrongArgs,
			    commandName,
			    NULL);

    if (*string != '\0') {
        Tcl_AppendStringsToObj (resultPtr, " ", string, NULL);
	Tcl_AppendStringsToObj (resultPtr, " ", string, (void *)NULL);
    }
    return TCL_ERROR;
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*                    Here is where the original file begins                 */
186
187
188
189
190
191
192
193
194


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211



212
213
214
215
216
217
218
219
220


221
222
223

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241



242
243
244
245
246
247
248
249
250
251

252
253
254
255

256
257

258
259
260
261



262
263
264
265
266


267
268
269
270

271
272
273
274
275
276
277

278
279
280
281
282
283
284
285
286



287
288
289
290
291
292



293
294
295
296
297
298



299
300
301
302
303
304



305
306
307
308
309
310
311
312
313
314


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330

331
332
333
334
335
336

337
338

339
340
341
342
343
344
345
346






347
348
349
350
351
352
353
186
187
188
189
190
191
192


193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208



209
210
211
212
213
214
215
216
217
218


219
220
221
222

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238



239
240
241
242
243
244
245
246
247
248
249
250

251
252
253
254

255
256

257
258



259
260
261
262
263
264


265
266
267
268
269

270
271
272
273
274
275
276

277
278
279
280
281
282
283



284
285
286
287
288
289



290
291
292
293
294
295



296
297
298
299
300
301



302
303
304
305
306
307
308
309
310
311
312
313

314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330

331
332
333


334

335
336

337
338
339






340
341
342
343
344
345
346
347
348
349
350
351
352







-
-
+
+














-
-
-
+
+
+







-
-
+
+


-
+















-
-
-
+
+
+









-
+



-
+

-
+

-
-
-
+
+
+



-
-
+
+



-
+






-
+






-
-
-
+
+
+



-
-
-
+
+
+



-
-
-
+
+
+



-
-
-
+
+
+









-
+
+















-
+


-
-

-
+

-
+


-
-
-
-
-
-
+
+
+
+
+
+







    Tcl_Obj *valuePtr;
} keylEntry_t;

/*
 * Internal representation of a keyed list object.
 */
typedef struct {
    int          arraySize;   /* Current slots available in the array.  */
    int          numEntries;  /* Number of actual entries in the array. */
    size_t     arraySize;   /* Current slots available in the array.  */
    size_t     numEntries;  /* Number of actual entries in the array. */
    keylEntry_t *entries;     /* Array of keyed list entries.           */
} keylIntObj_t;

/*
 * Amount to increment array size by when it needs to grow.
 */
#define KEYEDLIST_ARRAY_INCR_SIZE 16

/*
 * Macro to duplicate a child entry of a keyed list if it is share by more
 * than the parent.
 */
#define DupSharedKeyListChild(keylIntPtr, idx) \
    if (Tcl_IsShared (keylIntPtr->entries [idx].valuePtr)) { \
        keylIntPtr->entries [idx].valuePtr = \
            Tcl_DuplicateObj (keylIntPtr->entries [idx].valuePtr); \
        Tcl_IncrRefCount (keylIntPtr->entries [idx].valuePtr); \
	keylIntPtr->entries [idx].valuePtr = \
	    Tcl_DuplicateObj (keylIntPtr->entries [idx].valuePtr); \
	Tcl_IncrRefCount (keylIntPtr->entries [idx].valuePtr); \
    }

/*
 * Macros to validate an keyed list object or internal representation
 */
#ifdef TCLX_DEBUG
#   define KEYL_OBJ_ASSERT(keylAPtr) {\
        TclX_Assert (keylAPtr->typePtr == &keyedListType); \
        ValidateKeyedList (keylAIntPtr); \
	TclX_Assert (keylAPtr->typePtr == &keyedListType); \
	ValidateKeyedList (keylAIntPtr); \
    }
#   define KEYL_REP_ASSERT(keylAIntPtr) \
        ValidateKeyedList (keylAIntPtr)
	ValidateKeyedList (keylAIntPtr)
#else
#  define KEYL_REP_ASSERT(keylAIntPtr)
#endif


/*
 * Prototypes of internal functions.
 */
#ifdef TCLX_DEBUG
static void
ValidateKeyedList(keylIntObj_t *keylIntPtr);
#endif

static int
ValidateKey(Tcl_Interp *interp,
                         const char *key,
                         size_t keyLen,
                         int isPath);
			 const char *key,
			 Tcl_Size keyLen,
			 int isPath);

static keylIntObj_t *
AllocKeyedListIntRep(void);

static void
FreeKeyedListData(keylIntObj_t *keylIntPtr);

static void
EnsureKeyedListSpace(keylIntObj_t *keylIntPtr,
                                  int           newNumEntries);
				  size_t newNumEntries);

static void
DeleteKeyedListEntry(keylIntObj_t *keylIntPtr,
                                  int           entryIdx);
				  size_t entryIdx);

static int
static size_t
FindKeyedListEntry(keylIntObj_t *keylIntPtr,
                                const char   *key,
                                size_t       *keyLenPtr,
                                const char   **nextSubKeyPtr);
				const char   *key,
				size_t       *keyLenPtr,
				const char   **nextSubKeyPtr);

static int
ObjToKeyedListEntry(Tcl_Interp  *interp,
                                 Tcl_Obj     *objPtr,
                                 keylEntry_t *entryPtr);
				 Tcl_Obj     *objPtr,
				 keylEntry_t *entryPtr);

static void
DupKeyedListInternalRep(Tcl_Obj *srcPtr,
                                     Tcl_Obj *copyPtr);
				     Tcl_Obj *copyPtr);

static void
FreeKeyedListInternalRep(Tcl_Obj *keylPtr);

static int
SetKeyedListFromAny(Tcl_Interp *interp,
                                 Tcl_Obj    *objPtr);
				 Tcl_Obj    *objPtr);

static void
UpdateStringOfKeyedList(Tcl_Obj *keylPtr);

static int
Tcl_KeylgetObjCmd(void        *clientData,
                               Tcl_Interp  *interp,
                               int          objc,
                               Tcl_Obj     *const objv[]);
			       Tcl_Interp  *interp,
			       Tcl_Size objc,
			       Tcl_Obj     *const objv[]);

static int
Tcl_KeylsetObjCmd(void        *clientData,
                               Tcl_Interp  *interp,
                               int  objc,
                               Tcl_Obj     *const objv[]);
			       Tcl_Interp  *interp,
			       Tcl_Size objc,
			       Tcl_Obj     *const objv[]);

static int
Tcl_KeyldelObjCmd(void        *clientData,
                               Tcl_Interp  *interp,
                               int  objc,
                               Tcl_Obj     *const objv[]);
			       Tcl_Interp  *interp,
			       Tcl_Size objc,
			       Tcl_Obj     *const objv[]);

static int
Tcl_KeylkeysObjCmd(void        *clientData,
                                Tcl_Interp  *interp,
                                int  objc,
                                Tcl_Obj     *const objv[]);
				Tcl_Interp  *interp,
				Tcl_Size objc,
				Tcl_Obj     *const objv[]);

/*
 * Type definition.
 */
const Tcl_ObjType keyedListType = {
    "keyedList",              /* name */
    FreeKeyedListInternalRep, /* freeIntRepProc */
    DupKeyedListInternalRep,  /* dupIntRepProc */
    UpdateStringOfKeyedList,  /* updateStringProc */
    NULL                      /* setFromAnyProc */
    NULL,                     /* setFromAnyProc */
    TCL_OBJTYPE_V0
};


/*-----------------------------------------------------------------------------
 * ValidateKeyedList --
 *   Validate a keyed list (only when TCLX_DEBUG is enabled).
 * Parameters:
 *   o keylIntPtr - Keyed list internal representation.
 *-----------------------------------------------------------------------------
 */
#ifdef TCLX_DEBUG
static void
ValidateKeyedList (keylIntPtr)
    keylIntObj_t *keylIntPtr;
{
    int idx;
    size_t idx;

    TclX_Assert (keylIntPtr->arraySize >= keylIntPtr->numEntries);
    TclX_Assert (keylIntPtr->arraySize >= 0);
    TclX_Assert (keylIntPtr->numEntries >= 0);
    TclX_Assert ((keylIntPtr->arraySize > 0) ?
                 (keylIntPtr->entries != NULL) : 1);
		 (keylIntPtr->entries != NULL) : 1);
    TclX_Assert ((keylIntPtr->numEntries > 0) ?
                 (keylIntPtr->entries != NULL) : 1);
		 (keylIntPtr->entries != NULL) : 1);

    for (idx = 0; idx < keylIntPtr->numEntries; idx++) {
        keylEntry_t *entryPtr = &(keylIntPtr->entries [idx]);
        TclX_Assert (entryPtr->key != NULL);
        TclX_Assert (entryPtr->valuePtr->refCount >= 1);
        if (entryPtr->valuePtr->typePtr == &keyedListType) {
            ValidateKeyedList (entryPtr->valuePtr->internalRep.twoPtrValue.ptr1);
        }
	keylEntry_t *entryPtr = &(keylIntPtr->entries [idx]);
	TclX_Assert (entryPtr->key != NULL);
	TclX_Assert (entryPtr->valuePtr->refCount >= 1);
	if (entryPtr->valuePtr->typePtr == &keyedListType) {
	    ValidateKeyedList (entryPtr->valuePtr->internalRep.twoPtrValue.ptr1);
	}
    }
}
#endif

/*-----------------------------------------------------------------------------
 * ValidateKey --
 *   Check that a key or keypath string is a valid value.
362
363
364
365
366
367
368
369

370
371
372
373
374
375
376
377
378
379






380
381
382
383
384
385
386





387
388
389
390
391
392
393
394
395
396








397
398
399
400
401
402
403
361
362
363
364
365
366
367

368
369
370
371
372






373
374
375
376
377
378
379
380





381
382
383
384
385
386
387








388
389
390
391
392
393
394
395
396
397
398
399
400
401
402







-
+




-
-
-
-
-
-
+
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







 *    TCL_OK or TCL_ERROR.
 *-----------------------------------------------------------------------------
 */
static int
ValidateKey(
    Tcl_Interp *interp,
    const char *key,
    size_t keyLen,
    Tcl_Size keyLen,
    int isPath
) {
    const char *keyp;

    if (strlen(key) != keyLen) {
        Tcl_ResetResult(interp);
        Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
                                "keyed list key may not be a ",
                                "binary string", (char *) NULL);
        return TCL_ERROR;
    if (strlen(key) != (size_t)keyLen) {
	Tcl_ResetResult(interp);
	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
				"keyed list key may not be a ",
				"binary string", (char *) NULL);
	return TCL_ERROR;
    }
    if (key[0] == '\0') {
        Tcl_ResetResult(interp);
        Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
                                "keyed list key may not be an ",
                                "empty string", (char *) NULL);
        return TCL_ERROR;
	Tcl_ResetResult(interp);
	Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
				"keyed list key may not be an ",
				"empty string", (char *) NULL);
	return TCL_ERROR;
    }
    for (keyp = key; *keyp != '\0'; keyp++) {
        if ((!isPath) && (*keyp == '.')) {
            Tcl_ResetResult(interp);
            Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
                                    "keyed list key may not contain a \".\"; ",
                                    "it is used as a separator in key paths",
                                    (char *) NULL);
            return TCL_ERROR;
        }
	if ((!isPath) && (*keyp == '.')) {
	    Tcl_ResetResult(interp);
	    Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
				    "keyed list key may not contain a \".\"; ",
				    "it is used as a separator in key paths",
				    (char *) NULL);
	    return TCL_ERROR;
	}
    }
    return TCL_OK;
}


/*-----------------------------------------------------------------------------
 * AllocKeyedListIntRep --
429
430
431
432
433
434
435
436

437
438
439
440


441
442
443

444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461

462
463
464
465
466
467
468
469
470
471
472
473
474
475
476












477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494

495
496

497
498
499
500
501
502

503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520

521
522
523

524
525
526
527
528
529
530
531
532

533
534
535
536

537
538

539
540
541
542
543
544



545
546
547
548
549
550
551
552





553
554
555

556
557
558
559

560
561
562
563
564
565
566
428
429
430
431
432
433
434

435
436
437


438
439
440
441

442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459

460
461
462
463












464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492

493
494

495
496
497
498
499
500

501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518

519
520
521

522
523
524
525
526
527
528
529
530

531
532
533
534

535
536

537
538
539
540



541
542
543
544
545
546





547
548
549
550
551
552
553

554
555
556
557

558
559
560
561
562
563
564
565







-
+


-
-
+
+


-
+

















-
+



-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

















-
+

-
+





-
+

















-
+


-
+








-
+



-
+

-
+



-
-
-
+
+
+



-
-
-
-
-
+
+
+
+
+


-
+



-
+







 *   o keylIntPtr - Keyed list internal structure to free.
 *-----------------------------------------------------------------------------
 */
static void
FreeKeyedListData(
    keylIntObj_t *keylIntPtr
) {
    int idx;
    size_t idx;

    for (idx = 0; idx < keylIntPtr->numEntries ; idx++) {
        Tcl_Free(keylIntPtr->entries[idx].key);
        Tcl_DecrRefCount (keylIntPtr->entries[idx].valuePtr);
	Tcl_Free(keylIntPtr->entries[idx].key);
	Tcl_DecrRefCount (keylIntPtr->entries[idx].valuePtr);
    }
    if (keylIntPtr->entries != NULL)
        Tcl_Free(keylIntPtr->entries);
	Tcl_Free(keylIntPtr->entries);
    Tcl_Free(keylIntPtr);
}

/*-----------------------------------------------------------------------------
 * EnsureKeyedListSpace --
 *   Ensure there is enough room in a keyed list array for a certain number
 * of entries, expanding if necessary.
 *
 * Parameters:
 *   o keylIntPtr - Keyed list internal representation.
 *   o newNumEntries - The number of entries that are going to be added to
 *     the keyed list.
 *-----------------------------------------------------------------------------
 */
static void
EnsureKeyedListSpace(
    keylIntObj_t *keylIntPtr,
    int           newNumEntries
    size_t newNumEntries
) {
    KEYL_REP_ASSERT (keylIntPtr);

    if ((keylIntPtr->arraySize - keylIntPtr->numEntries) < newNumEntries) {
        int newSize = keylIntPtr->arraySize + newNumEntries +
            KEYEDLIST_ARRAY_INCR_SIZE;
        if (keylIntPtr->entries == NULL) {
            keylIntPtr->entries = (keylEntry_t *)
                Tcl_Alloc(newSize * sizeof(keylEntry_t));
        } else {
            keylIntPtr->entries = (keylEntry_t *)
                Tcl_Realloc(keylIntPtr->entries,
                           newSize * sizeof(keylEntry_t));
        }
        keylIntPtr->arraySize = newSize;
    if ((keylIntPtr->arraySize) < newNumEntries + keylIntPtr->numEntries) {
	size_t newSize = keylIntPtr->arraySize + newNumEntries +
	    KEYEDLIST_ARRAY_INCR_SIZE;
	if (keylIntPtr->entries == NULL) {
	    keylIntPtr->entries = (keylEntry_t *)
		Tcl_Alloc(newSize * sizeof(keylEntry_t));
	} else {
	    keylIntPtr->entries = (keylEntry_t *)
		Tcl_Realloc(keylIntPtr->entries,
			   newSize * sizeof(keylEntry_t));
	}
	keylIntPtr->arraySize = newSize;
    }

    KEYL_REP_ASSERT (keylIntPtr);
}

/*-----------------------------------------------------------------------------
 * DeleteKeyedListEntry --
 *   Delete an entry from a keyed list.
 *
 * Parameters:
 *   o keylIntPtr - Keyed list internal representation.
 *   o entryIdx - Index of entry to delete.
 *-----------------------------------------------------------------------------
 */
static void
DeleteKeyedListEntry (
    keylIntObj_t *keylIntPtr,
    int           entryIdx
    size_t entryIdx
) {
    int idx;
    size_t idx;

    Tcl_Free(keylIntPtr->entries [entryIdx].key);
    Tcl_DecrRefCount (keylIntPtr->entries [entryIdx].valuePtr);

    for (idx = entryIdx; idx < keylIntPtr->numEntries - 1; idx++)
        keylIntPtr->entries [idx] = keylIntPtr->entries [idx + 1];
	keylIntPtr->entries [idx] = keylIntPtr->entries [idx + 1];
    keylIntPtr->numEntries--;

    KEYL_REP_ASSERT (keylIntPtr);
}

/*-----------------------------------------------------------------------------
 * FindKeyedListEntry --
 *   Find an entry in keyed list.
 *
 * Parameters:
 *   o keylIntPtr - Keyed list internal representation.
 *   o key - Name of key to search for.
 *   o keyLenPtr - In not NULL, the length of the key for this
 *     level is returned here.  This excludes subkeys and the `.' delimiters.
 *   o nextSubKeyPtr - If not NULL, the start of the name of the next
 *     sub-key within key is returned.
 * Returns:
 *   Index of the entry or -1 if not found.
 *   Index of the entry or TCL_INDEX_NONE if not found.
 *-----------------------------------------------------------------------------
 */
static int
static size_t
FindKeyedListEntry(
    keylIntObj_t *keylIntPtr,
    const char   *key,
    size_t       *keyLenPtr,
    const char   **nextSubKeyPtr
) {
    const char *keySeparPtr;
    size_t keyLen;
    int findIdx;
    size_t findIdx;

    keySeparPtr = strchr(key, '.');
    if (keySeparPtr != NULL) {
        keyLen = keySeparPtr - key;
	keyLen = (size_t)(keySeparPtr - key);
    } else {
        keyLen = strlen (key);
	keyLen = strlen (key);
    }

    for (findIdx = 0; findIdx < keylIntPtr->numEntries; findIdx++) {
        if ((strncmp (keylIntPtr->entries [findIdx].key, key, keyLen) == 0) &&
            (keylIntPtr->entries [findIdx].key [keyLen] == '\0'))
            break;
	if ((strncmp (keylIntPtr->entries [findIdx].key, key, keyLen) == 0) &&
	    (keylIntPtr->entries [findIdx].key [keyLen] == '\0'))
	    break;
    }

    if (nextSubKeyPtr != NULL) {
        if (keySeparPtr == NULL) {
            *nextSubKeyPtr = NULL;
        } else {
            *nextSubKeyPtr = keySeparPtr + 1;
        }
	if (keySeparPtr == NULL) {
	    *nextSubKeyPtr = NULL;
	} else {
	    *nextSubKeyPtr = keySeparPtr + 1;
	}
    }
    if (keyLenPtr != NULL) {
        *keyLenPtr = keyLen;
	*keyLenPtr = keyLen;
    }

    if (findIdx >= keylIntPtr->numEntries) {
        return -1;
	return TCL_INDEX_NONE;
    }

    return findIdx;
}

/*-----------------------------------------------------------------------------
 * ObjToKeyedListEntry --
578
579
580
581
582
583
584
585

586
587
588
589
590
591
592
593
594
595
596







597
598
599
600
601
602
603
604
605






606
607
608
609
610

611
612
613
614
615
616
617
577
578
579
580
581
582
583

584
585
586
587
588







589
590
591
592
593
594
595
596
597
598






599
600
601
602
603
604
605
606
607
608

609
610
611
612
613
614
615
616







-
+




-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
-
-
-
-
+
+
+
+
+
+




-
+







 */
static int
ObjToKeyedListEntry(
    Tcl_Interp  *interp,
    Tcl_Obj     *objPtr,
    keylEntry_t *entryPtr
) {
    int objc;
    Tcl_Size objc;
    Tcl_Obj **objv;
    const char *key;

    if (Tcl_ListObjGetElements(interp, objPtr, &objc, &objv) != TCL_OK) {
        Tcl_ResetResult (interp);
        Tcl_AppendStringsToObj(Tcl_GetObjResult (interp),
                                "keyed list entry not a valid list, ",
                                "found \"",
                                Tcl_GetString(objPtr),
                                "\"", (char *) NULL);
        return TCL_ERROR;
	Tcl_ResetResult (interp);
	Tcl_AppendStringsToObj(Tcl_GetObjResult (interp),
				"keyed list entry not a valid list, ",
				"found \"",
				Tcl_GetString(objPtr),
				"\"", (char *) NULL);
	return TCL_ERROR;
    }

    if (objc != 2) {
        Tcl_AppendStringsToObj(Tcl_GetObjResult (interp),
                                "keyed list entry must be a two ",
                                "element list, found \"",
                                Tcl_GetString(objPtr),
                                "\"", (char *) NULL);
        return TCL_ERROR;
	Tcl_AppendStringsToObj(Tcl_GetObjResult (interp),
				"keyed list entry must be a two ",
				"element list, found \"",
				Tcl_GetString(objPtr),
				"\"", (char *) NULL);
	return TCL_ERROR;
    }

    key = Tcl_GetString(objv[0]);
    if (ValidateKey(interp, key, objv[0]->length, 0) == TCL_ERROR) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    entryPtr->key = ckstrdup(key);
    entryPtr->valuePtr = Tcl_DuplicateObj(objv [1]);
    Tcl_IncrRefCount(entryPtr->valuePtr);

    return TCL_OK;
643
644
645
646
647
648
649
650

651
652

653
654
655
656
657
658
659
660

661
662
663
664
665
666




667
668
669
670
671
672
673
642
643
644
645
646
647
648

649
650

651
652
653
654
655
656
657
658

659
660
661




662
663
664
665
666
667
668
669
670
671
672







-
+

-
+







-
+


-
-
-
-
+
+
+
+







 */
static void
DupKeyedListInternalRep(
    Tcl_Obj *srcPtr,
    Tcl_Obj *copyPtr
) {
    keylIntObj_t *srcIntPtr = (keylIntObj_t *)
        srcPtr->internalRep.twoPtrValue.ptr1;
	srcPtr->internalRep.twoPtrValue.ptr1;
    keylIntObj_t *copyIntPtr;
    int idx;
    size_t idx;

    KEYL_REP_ASSERT (srcIntPtr);

    copyIntPtr = (keylIntObj_t *)Tcl_Alloc(sizeof(keylIntObj_t));
    copyIntPtr->arraySize = srcIntPtr->arraySize;
    copyIntPtr->numEntries = srcIntPtr->numEntries;
    copyIntPtr->entries = (keylEntry_t *)
        Tcl_Alloc(copyIntPtr->arraySize * sizeof(keylEntry_t));
	Tcl_Alloc(copyIntPtr->arraySize * sizeof(keylEntry_t));

    for (idx = 0; idx < srcIntPtr->numEntries ; idx++) {
        copyIntPtr->entries [idx].key =
            ckstrdup (srcIntPtr->entries [idx].key);
        copyIntPtr->entries [idx].valuePtr = srcIntPtr->entries [idx].valuePtr;
        Tcl_IncrRefCount (copyIntPtr->entries [idx].valuePtr);
	copyIntPtr->entries [idx].key =
	    ckstrdup (srcIntPtr->entries [idx].key);
	copyIntPtr->entries [idx].valuePtr = srcIntPtr->entries [idx].valuePtr;
	Tcl_IncrRefCount (copyIntPtr->entries [idx].valuePtr);
    }

    copyPtr->internalRep.twoPtrValue.ptr1 = copyIntPtr;
    copyPtr->typePtr = &keyedListType;

    KEYL_REP_ASSERT (copyIntPtr);
}
685
686
687
688
689
690
691
692

693
694

695
696
697
698
699
700
701
702

703
704
705
706
707
708
709





710
711
712
713
714
715
716
684
685
686
687
688
689
690

691
692

693
694
695
696
697
698
699
700

701
702
703





704
705
706
707
708
709
710
711
712
713
714
715







-
+

-
+







-
+


-
-
-
-
-
+
+
+
+
+







 */
void
DupKeyedListInternalRepShared (
    Tcl_Obj *srcPtr,
    Tcl_Obj *copyPtr
) {
    keylIntObj_t *srcIntPtr = (keylIntObj_t *)
        srcPtr->internalRep.twoPtrValue.ptr1;
	srcPtr->internalRep.twoPtrValue.ptr1;
    keylIntObj_t *copyIntPtr;
    int idx;
    size_t idx;

    KEYL_REP_ASSERT (srcIntPtr);

    copyIntPtr = (keylIntObj_t *)Tcl_Alloc(sizeof(keylIntObj_t));
    copyIntPtr->arraySize = srcIntPtr->arraySize;
    copyIntPtr->numEntries = srcIntPtr->numEntries;
    copyIntPtr->entries = (keylEntry_t *)
        Tcl_Alloc(copyIntPtr->arraySize * sizeof(keylEntry_t));
	Tcl_Alloc(copyIntPtr->arraySize * sizeof(keylEntry_t));

    for (idx = 0; idx < srcIntPtr->numEntries ; idx++) {
        copyIntPtr->entries [idx].key =
            ckstrdup (srcIntPtr->entries [idx].key);
        copyIntPtr->entries [idx].valuePtr =
            Sv_DuplicateObj (srcIntPtr->entries [idx].valuePtr);
        Tcl_IncrRefCount(copyIntPtr->entries [idx].valuePtr);
	copyIntPtr->entries[idx].key =
	    ckstrdup (srcIntPtr->entries [idx].key);
	copyIntPtr->entries[idx].valuePtr =
	    Sv_DuplicateObj (srcIntPtr->entries [idx].valuePtr);
	Tcl_IncrRefCount(copyIntPtr->entries [idx].valuePtr);
    }

    copyPtr->internalRep.twoPtrValue.ptr1 = copyIntPtr;
    copyPtr->typePtr = &keyedListType;

    KEYL_REP_ASSERT (copyIntPtr);
}
727
728
729
730
731
732
733
734
735


736
737
738
739

740
741
742
743
744
745
746
747
748
749




750
751
752
753
754


755
756
757
758
759
760
761
726
727
728
729
730
731
732


733
734
735
736
737

738
739
740
741
742
743
744




745
746
747
748
749
750
751


752
753
754
755
756
757
758
759
760







-
-
+
+



-
+






-
-
-
-
+
+
+
+



-
-
+
+







 */
static int
SetKeyedListFromAny(
    Tcl_Interp *interp,
    Tcl_Obj    *objPtr
) {
    keylIntObj_t *keylIntPtr;
    int idx;
    int objc;
    Tcl_Size idx;
    Tcl_Size objc;
    Tcl_Obj **objv;

    if (Tcl_ListObjGetElements (interp, objPtr, &objc, &objv) != TCL_OK)
        return TCL_ERROR;
	return TCL_ERROR;

    keylIntPtr = AllocKeyedListIntRep ();

    EnsureKeyedListSpace (keylIntPtr, objc);

    for (idx = 0; idx < objc; idx++) {
        if (ObjToKeyedListEntry (interp, objv [idx],
                &(keylIntPtr->entries [keylIntPtr->numEntries])) != TCL_OK)
            goto errorExit;
        keylIntPtr->numEntries++;
	if (ObjToKeyedListEntry (interp, objv [idx],
		&(keylIntPtr->entries [keylIntPtr->numEntries])) != TCL_OK)
	    goto errorExit;
	keylIntPtr->numEntries++;
    }

    if ((objPtr->typePtr != NULL) &&
        (objPtr->typePtr->freeIntRepProc != NULL)) {
        (*objPtr->typePtr->freeIntRepProc) (objPtr);
	(objPtr->typePtr->freeIntRepProc != NULL)) {
	(*objPtr->typePtr->freeIntRepProc) (objPtr);
    }
    objPtr->internalRep.twoPtrValue.ptr1 = keylIntPtr;
    objPtr->typePtr = &keyedListType;

    KEYL_REP_ASSERT (keylIntPtr);
    return TCL_OK;

773
774
775
776
777
778
779
780

781
782
783
784
785

786
787
788
789
790
791
792


793
794

795
796
797
798
799
800
801
802
803
804
805
806
807





808
809
810
811
812
813
814
815
816
817

818
819
820
821
822
823
824
772
773
774
775
776
777
778

779
780
781
782
783

784
785
786
787
788
789


790
791
792

793
794
795
796
797
798
799
800
801





802
803
804
805
806
807
808
809
810
811
812
813
814
815

816
817
818
819
820
821
822
823







-
+




-
+





-
-
+
+

-
+








-
-
-
-
-
+
+
+
+
+









-
+







 *-----------------------------------------------------------------------------
 */
static void
UpdateStringOfKeyedList(
    Tcl_Obj  *keylPtr
) {
#define UPDATE_STATIC_SIZE 32
    int idx;
    size_t idx;
    Tcl_Obj **listObjv, *entryObjv [2], *tmpListObj;
    Tcl_Obj *staticListObjv [UPDATE_STATIC_SIZE];
    char *listStr;
    keylIntObj_t *keylIntPtr = (keylIntObj_t *)
        keylPtr->internalRep.twoPtrValue.ptr1;
	keylPtr->internalRep.twoPtrValue.ptr1;

    /*
     * Conversion to strings is done via list objects to support binary data.
     */
    if (keylIntPtr->numEntries > UPDATE_STATIC_SIZE) {
        listObjv = (Tcl_Obj **)
            Tcl_Alloc(keylIntPtr->numEntries * sizeof(Tcl_Obj *));
	listObjv = (Tcl_Obj **)
	    Tcl_Alloc(keylIntPtr->numEntries * sizeof(Tcl_Obj *));
    } else {
        listObjv = staticListObjv;
	listObjv = staticListObjv;
    }

    /*
     * Convert each keyed list entry to a two element list object.  No
     * need to incr/decr ref counts, the list objects will take care of that.
     * FIX: Keeping key as string object will speed this up.
     */
    for (idx = 0; idx < keylIntPtr->numEntries; idx++) {
        entryObjv [0] =
            Tcl_NewStringObj(keylIntPtr->entries [idx].key,
                              strlen (keylIntPtr->entries [idx].key));
        entryObjv [1] = keylIntPtr->entries [idx].valuePtr;
        listObjv [idx] = Tcl_NewListObj (2, entryObjv);
	entryObjv [0] =
	    Tcl_NewStringObj(keylIntPtr->entries [idx].key,
			      strlen (keylIntPtr->entries [idx].key));
	entryObjv [1] = keylIntPtr->entries [idx].valuePtr;
	listObjv [idx] = Tcl_NewListObj (2, entryObjv);
    }

    tmpListObj = Tcl_NewListObj (keylIntPtr->numEntries, listObjv);
    listStr = Tcl_GetString(tmpListObj);
    keylPtr->bytes = ckbinstrdup(listStr, tmpListObj->length);
    keylPtr->length = tmpListObj->length;

    Tcl_DecrRefCount (tmpListObj);
    if (listObjv != staticListObjv)
        Tcl_Free(listObjv);
	Tcl_Free(listObjv);
}

/*-----------------------------------------------------------------------------
 * TclX_NewKeyedListObj --
 *   Create and initialize a new keyed list object.
 *
 * Returns:
858
859
860
861
862
863
864
865

866
867
868
869
870



871
872
873
874
875
876
877
878
879
880
881
882



883
884
885
886
887
888
889
890
891


892
893
894
895
896




897
898
899
900
901
902
903
857
858
859
860
861
862
863

864
865
866



867
868
869
870
871
872
873
874
875
876
877
878



879
880
881
882
883
884
885
886
887
888


889
890
891




892
893
894
895
896
897
898
899
900
901
902







-
+


-
-
-
+
+
+









-
-
-
+
+
+







-
-
+
+

-
-
-
-
+
+
+
+







    Tcl_Interp *interp,
    Tcl_Obj    *keylPtr,
    const char *key,
    Tcl_Obj   **valuePtrPtr
) {
    keylIntObj_t *keylIntPtr;
    const char *nextSubKey;
    int findIdx;
    size_t findIdx;

    if (keylPtr->typePtr != &keyedListType) {
        if (SetKeyedListFromAny(interp, keylPtr) != TCL_OK) {
            return TCL_ERROR;
        }
	if (SetKeyedListFromAny(interp, keylPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
    }
    keylIntPtr = (keylIntObj_t *)keylPtr->internalRep.twoPtrValue.ptr1;
    KEYL_REP_ASSERT (keylIntPtr);

    findIdx = FindKeyedListEntry (keylIntPtr, key, NULL, &nextSubKey);

    /*
     * If not found, return status.
     */
    if (findIdx < 0) {
        *valuePtrPtr = NULL;
        return TCL_BREAK;
    if (findIdx == TCL_INDEX_NONE) {
	*valuePtrPtr = NULL;
	return TCL_BREAK;
    }

    /*
     * If we are at the last subkey, return the entry, otherwise recurse
     * down looking for the entry.
     */
    if (nextSubKey == NULL) {
        *valuePtrPtr = keylIntPtr->entries [findIdx].valuePtr;
        return TCL_OK;
	*valuePtrPtr = keylIntPtr->entries [findIdx].valuePtr;
	return TCL_OK;
    } else {
        return TclX_KeyedListGet (interp,
                                  keylIntPtr->entries [findIdx].valuePtr,
                                  nextSubKey,
                                  valuePtrPtr);
	return TclX_KeyedListGet (interp,
				  keylIntPtr->entries [findIdx].valuePtr,
				  nextSubKey,
				  valuePtrPtr);
    }
}

/*-----------------------------------------------------------------------------
 * TclX_KeyedListSet --
 *   Set a key value in keyed list object.
 *
916
917
918
919
920
921
922
923


924
925
926
927
928
929
930



931
932
933
934
935
936

937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956















957
958
959


960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976









977
978
979


980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995















996
997
998


999
1000
1001
1002
1003
1004
1005
915
916
917
918
919
920
921

922
923
924
925
926
927



928
929
930
931
932
933
934
935

936
937
938
939
940
941















942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957


958
959
960
961
962
963
964
965
966
967









968
969
970
971
972
973
974
975
976
977


978
979
980















981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996


997
998
999
1000
1001
1002
1003
1004
1005







-
+
+




-
-
-
+
+
+





-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+








-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+







    Tcl_Interp *interp,
    Tcl_Obj    *keylPtr,
    const char *key,
    Tcl_Obj    *valuePtr
) {
    keylIntObj_t *keylIntPtr;
    const char *nextSubKey;
    int findIdx, status;
    size_t findIdx;
    int status;
    size_t keyLen;
    Tcl_Obj *newKeylPtr;

    if (keylPtr->typePtr != &keyedListType) {
        if (SetKeyedListFromAny(interp, keylPtr) != TCL_OK) {
            return TCL_ERROR;
        }
	if (SetKeyedListFromAny(interp, keylPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
    }
    keylIntPtr = (keylIntObj_t *)keylPtr->internalRep.twoPtrValue.ptr1;
    KEYL_REP_ASSERT (keylIntPtr);

    findIdx = FindKeyedListEntry (keylIntPtr, key,
                                  &keyLen, &nextSubKey);
				  &keyLen, &nextSubKey);

    /*
     * If we are at the last subkey, either update or add an entry.
     */
    if (nextSubKey == NULL) {
        if (findIdx < 0) {
            EnsureKeyedListSpace (keylIntPtr, 1);
            findIdx = keylIntPtr->numEntries;
            keylIntPtr->numEntries++;
        } else {
            Tcl_Free(keylIntPtr->entries [findIdx].key);
            Tcl_DecrRefCount (keylIntPtr->entries [findIdx].valuePtr);
        }
        keylIntPtr->entries [findIdx].key = (char *)
            Tcl_Alloc(keyLen + 1);
        strncpy (keylIntPtr->entries [findIdx].key, key, keyLen);
        keylIntPtr->entries [findIdx].key [keyLen] = '\0';
        keylIntPtr->entries [findIdx].valuePtr = valuePtr;
        Tcl_IncrRefCount (valuePtr);
        Tcl_InvalidateStringRep (keylPtr);
	if (findIdx == TCL_INDEX_NONE) {
	    EnsureKeyedListSpace (keylIntPtr, 1);
	    findIdx = keylIntPtr->numEntries;
	    keylIntPtr->numEntries++;
	} else {
	    Tcl_Free(keylIntPtr->entries [findIdx].key);
	    Tcl_DecrRefCount (keylIntPtr->entries [findIdx].valuePtr);
	}
	keylIntPtr->entries [findIdx].key = (char *)
	    Tcl_Alloc(keyLen + 1);
	strncpy (keylIntPtr->entries [findIdx].key, key, keyLen);
	keylIntPtr->entries [findIdx].key [keyLen] = '\0';
	keylIntPtr->entries [findIdx].valuePtr = valuePtr;
	Tcl_IncrRefCount (valuePtr);
	Tcl_InvalidateStringRep (keylPtr);

        KEYL_REP_ASSERT (keylIntPtr);
        return TCL_OK;
	KEYL_REP_ASSERT (keylIntPtr);
	return TCL_OK;
    }

    /*
     * If we are not at the last subkey, recurse down, creating new
     * entries if neccessary.  If this level key was not found, it
     * means we must build new subtree. Don't insert the new tree until we
     * come back without error.
     */
    if (findIdx >= 0) {
        DupSharedKeyListChild (keylIntPtr, findIdx);
        status =
            TclX_KeyedListSet (interp,
                               keylIntPtr->entries [findIdx].valuePtr,
                               nextSubKey, valuePtr);
        if (status == TCL_OK) {
            Tcl_InvalidateStringRep (keylPtr);
        }
    if (findIdx != TCL_INDEX_NONE) {
	DupSharedKeyListChild (keylIntPtr, findIdx);
	status =
	    TclX_KeyedListSet (interp,
			       keylIntPtr->entries [findIdx].valuePtr,
			       nextSubKey, valuePtr);
	if (status == TCL_OK) {
	    Tcl_InvalidateStringRep (keylPtr);
	}

        KEYL_REP_ASSERT (keylIntPtr);
        return status;
	KEYL_REP_ASSERT (keylIntPtr);
	return status;
    } else {
        newKeylPtr = TclX_NewKeyedListObj ();
        if (TclX_KeyedListSet (interp, newKeylPtr,
                               nextSubKey, valuePtr) != TCL_OK) {
            Tcl_DecrRefCount (newKeylPtr);
            return TCL_ERROR;
        }
        EnsureKeyedListSpace (keylIntPtr, 1);
        findIdx = keylIntPtr->numEntries++;
        keylIntPtr->entries [findIdx].key = (char *)
            Tcl_Alloc(keyLen + 1);
        strncpy (keylIntPtr->entries [findIdx].key, key, keyLen);
        keylIntPtr->entries [findIdx].key [keyLen] = '\0';
        keylIntPtr->entries [findIdx].valuePtr = newKeylPtr;
        Tcl_IncrRefCount (newKeylPtr);
        Tcl_InvalidateStringRep (keylPtr);
	newKeylPtr = TclX_NewKeyedListObj ();
	if (TclX_KeyedListSet (interp, newKeylPtr,
			       nextSubKey, valuePtr) != TCL_OK) {
	    Tcl_DecrRefCount (newKeylPtr);
	    return TCL_ERROR;
	}
	EnsureKeyedListSpace (keylIntPtr, 1);
	findIdx = keylIntPtr->numEntries++;
	keylIntPtr->entries [findIdx].key = (char *)
	    Tcl_Alloc(keyLen + 1);
	strncpy (keylIntPtr->entries [findIdx].key, key, keyLen);
	keylIntPtr->entries [findIdx].key [keyLen] = '\0';
	keylIntPtr->entries [findIdx].valuePtr = newKeylPtr;
	Tcl_IncrRefCount (newKeylPtr);
	Tcl_InvalidateStringRep (keylPtr);

        KEYL_REP_ASSERT (keylIntPtr);
        return TCL_OK;
	KEYL_REP_ASSERT (keylIntPtr);
	return TCL_OK;
    }
}

/*-----------------------------------------------------------------------------
 * TclX_KeyedListDelete --
 *   Delete a key value from keyed list.
 *
1018
1019
1020
1021
1022
1023
1024
1025


1026
1027
1028
1029
1030



1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041



1042
1043
1044
1045
1046
1047
1048
1049


1050
1051
1052


1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064


1065
1066
1067
1068
1069
1070
1071






1072
1073
1074
1075
1076
1077
1078
1018
1019
1020
1021
1022
1023
1024

1025
1026
1027
1028



1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039



1040
1041
1042
1043
1044
1045
1046
1047
1048


1049
1050
1051


1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063


1064
1065
1066






1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079







-
+
+


-
-
-
+
+
+








-
-
-
+
+
+






-
-
+
+

-
-
+
+










-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+







TclX_KeyedListDelete(
    Tcl_Interp *interp,
    Tcl_Obj    *keylPtr,
    const char *key
) {
    keylIntObj_t *keylIntPtr, *subKeylIntPtr;
    const char *nextSubKey;
    int findIdx, status;
    size_t findIdx;
    int status;

    if (keylPtr->typePtr != &keyedListType) {
        if (SetKeyedListFromAny(interp, keylPtr) != TCL_OK) {
            return TCL_ERROR;
        }
	if (SetKeyedListFromAny(interp, keylPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
    }
    keylIntPtr = (keylIntObj_t *)keylPtr->internalRep.twoPtrValue.ptr1;

    findIdx = FindKeyedListEntry (keylIntPtr, key, NULL, &nextSubKey);

    /*
     * If not found, return status.
     */
    if (findIdx < 0) {
        KEYL_REP_ASSERT (keylIntPtr);
        return TCL_BREAK;
    if (findIdx == TCL_INDEX_NONE) {
	KEYL_REP_ASSERT (keylIntPtr);
	return TCL_BREAK;
    }

    /*
     * If we are at the last subkey, delete the entry.
     */
    if (nextSubKey == NULL) {
        DeleteKeyedListEntry (keylIntPtr, findIdx);
        Tcl_InvalidateStringRep (keylPtr);
	DeleteKeyedListEntry (keylIntPtr, findIdx);
	Tcl_InvalidateStringRep (keylPtr);

        KEYL_REP_ASSERT (keylIntPtr);
        return TCL_OK;
	KEYL_REP_ASSERT (keylIntPtr);
	return TCL_OK;
    }

    /*
     * If we are not at the last subkey, recurse down.  If the entry is
     * deleted and the sub-keyed list is empty, delete it as well.  Must
     * invalidate string, as it caches all representations below it.
     */
    DupSharedKeyListChild (keylIntPtr, findIdx);

    status = TclX_KeyedListDelete (interp,
                                   keylIntPtr->entries [findIdx].valuePtr,
                                   nextSubKey);
				   keylIntPtr->entries [findIdx].valuePtr,
				   nextSubKey);
    if (status == TCL_OK) {
        subKeylIntPtr = (keylIntObj_t *)
            keylIntPtr->entries [findIdx].valuePtr->internalRep.twoPtrValue.ptr1;
        if (subKeylIntPtr->numEntries == 0) {
            DeleteKeyedListEntry (keylIntPtr, findIdx);
        }
        Tcl_InvalidateStringRep (keylPtr);
	subKeylIntPtr = (keylIntObj_t *)
	    keylIntPtr->entries [findIdx].valuePtr->internalRep.twoPtrValue.ptr1;
	if (subKeylIntPtr->numEntries == 0) {
	    DeleteKeyedListEntry (keylIntPtr, findIdx);
	}
	Tcl_InvalidateStringRep (keylPtr);
    }

    KEYL_REP_ASSERT (keylIntPtr);
    return status;
}

/*-----------------------------------------------------------------------------
1097
1098
1099
1100
1101
1102
1103
1104

1105
1106
1107
1108
1109



1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127










1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142








1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162
1163
1164
1165
1166
1167
1168


1169
1170
1171
1172
1173
1174

1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185
1186

1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206










1207
1208
1209
1210
1211
1212
1213
1214


1215
1216
1217
1218
1219
1220
1221
1222
1223



1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240

1241
1242
1243
1244
1245

1246
1247
1248
1249
1250


1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265






1266
1267

1268
1269
1270
1271
1272
1273
1274
1275
1276
1277







1278
1279
1280
1281
1282


1283
1284
1285
1286
1287
1288
1289

1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304

1305
1306
1307
1308

1309

1310
1311
1312
1313

1314
1315
1316
1317
1318
1319
1320
1321
1322

1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333









1334
1335
1336
1337
1338
1339
1340
1341




1342
1343
1344
1345
1346
1347
1348
1349
1350
1351









1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367

1368
1369
1370
1371
1372
1373
1374
1375
1376

1377
1378
1379
1380
1381

1382
1383
1384
1385
1386
1387
1388
1389

1390
1391
1392
1393
1394




1395
1396
1397
1398
1399
1400
1401
1402



1403
1404

1405
1406
1407
1408
1409
1410
1411
1098
1099
1100
1101
1102
1103
1104

1105
1106
1107



1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118










1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135








1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159

1160
1161
1162
1163
1164
1165
1166
1167


1168
1169
1170
1171
1172
1173
1174

1175
1176
1177
1178

1179
1180
1181
1182
1183
1184
1185
1186

1187
1188
1189
1190
1191

1192
1193
1194
1195
1196
1197










1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213


1214
1215
1216
1217
1218
1219
1220
1221



1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240

1241
1242
1243
1244
1245

1246
1247
1248
1249


1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260






1261
1262
1263
1264
1265
1266
1267

1268
1269
1270
1271







1272
1273
1274
1275
1276
1277
1278
1279
1280
1281


1282
1283
1284
1285
1286
1287
1288
1289

1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304

1305
1306
1307
1308
1309
1310

1311
1312
1313
1314

1315
1316
1317
1318
1319
1320
1321
1322
1323

1324
1325
1326









1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339




1340
1341
1342
1343
1344









1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368

1369
1370
1371
1372
1373
1374
1375
1376
1377

1378
1379
1380
1381
1382

1383
1384
1385
1386
1387
1388
1389
1390

1391
1392




1393
1394
1395
1396
1397
1398
1399
1400
1401



1402
1403
1404
1405

1406
1407
1408
1409
1410
1411
1412
1413







-
+


-
-
-
+
+
+








-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
















-
+







-
-
+
+





-
+



-
+







-
+




-
+





-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+






-
-
+
+






-
-
-
+
+
+
















-
+




-
+



-
-
+
+









-
-
-
-
-
-
+
+
+
+
+
+

-
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
+
+






-
+














-
+




+
-
+



-
+








-
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+




-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+















-
+








-
+




-
+







-
+

-
-
-
-
+
+
+
+





-
-
-
+
+
+

-
+







    Tcl_Obj    *keylPtr,
    const char *key,
    Tcl_Obj   **listObjPtrPtr
) {
    keylIntObj_t *keylIntPtr;
    Tcl_Obj *nameObjPtr, *listObjPtr;
    const char *nextSubKey;
    int idx, findIdx;
    size_t idx, findIdx;

    if (keylPtr->typePtr != &keyedListType) {
        if (SetKeyedListFromAny(interp, keylPtr) != TCL_OK) {
            return TCL_ERROR;
        }
	if (SetKeyedListFromAny(interp, keylPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
    }
    keylIntPtr = (keylIntObj_t *)keylPtr->internalRep.twoPtrValue.ptr1;

    /*
     * If key is not NULL or empty, then recurse down until we go past
     * the end of all of the elements of the key.
     */
    if ((key != NULL) && (key [0] != '\0')) {
        findIdx = FindKeyedListEntry (keylIntPtr, key, NULL, &nextSubKey);
        if (findIdx < 0) {
            TclX_Assert (keylIntPtr->arraySize >= keylIntPtr->numEntries);
            return TCL_BREAK;
        }
        TclX_Assert (keylIntPtr->arraySize >= keylIntPtr->numEntries);
        return TclX_KeyedListGetKeys (interp,
                                      keylIntPtr->entries [findIdx].valuePtr,
                                      nextSubKey,
                                      listObjPtrPtr);
	findIdx = FindKeyedListEntry (keylIntPtr, key, NULL, &nextSubKey);
	if (findIdx == TCL_INDEX_NONE) {
	    TclX_Assert (keylIntPtr->arraySize >= keylIntPtr->numEntries);
	    return TCL_BREAK;
	}
	TclX_Assert (keylIntPtr->arraySize >= keylIntPtr->numEntries);
	return TclX_KeyedListGetKeys (interp,
				      keylIntPtr->entries [findIdx].valuePtr,
				      nextSubKey,
				      listObjPtrPtr);
    }

    /*
     * Reached the end of the full key, return all keys at this level.
     */
    listObjPtr = Tcl_NewListObj (0, NULL);
    for (idx = 0; idx < keylIntPtr->numEntries; idx++) {
        nameObjPtr = Tcl_NewStringObj (keylIntPtr->entries [idx].key,
                                       -1);
        if (Tcl_ListObjAppendElement (interp, listObjPtr,
                                      nameObjPtr) != TCL_OK) {
            Tcl_DecrRefCount (nameObjPtr);
            Tcl_DecrRefCount (listObjPtr);
            return TCL_ERROR;
        }
	nameObjPtr = Tcl_NewStringObj (keylIntPtr->entries [idx].key,
				       TCL_INDEX_NONE);
	if (Tcl_ListObjAppendElement (interp, listObjPtr,
				      nameObjPtr) != TCL_OK) {
	    Tcl_DecrRefCount (nameObjPtr);
	    Tcl_DecrRefCount (listObjPtr);
	    return TCL_ERROR;
	}
    }
    *listObjPtrPtr = listObjPtr;
    TclX_Assert (keylIntPtr->arraySize >= keylIntPtr->numEntries);
    return TCL_OK;
}

/*-----------------------------------------------------------------------------
 * Tcl_KeylgetObjCmd --
 *     Implements the TCL keylget command:
 *         keylget listvar ?key? ?retvar | {}?
 *-----------------------------------------------------------------------------
 */
static int
Tcl_KeylgetObjCmd(
    void        *clientData,
    Tcl_Interp  *interp,
    int          objc,
    Tcl_Size       objc,
    Tcl_Obj     *const objv[]
) {
    Tcl_Obj *keylPtr, *valuePtr;
    const char *key;
    int status;

    if ((objc < 2) || (objc > 4)) {
        return TclX_WrongArgs (interp, objv [0],
                               "listvar ?key? ?retvar | {}?");
	return TclX_WrongArgs (interp, objv [0],
			       "listvar ?key? ?retvar | {}?");
    }
    /*
     * Handle request for list of keys, use keylkeys command.
     */
    if (objc == 2)
        return Tcl_KeylkeysObjCmd (clientData, interp, objc, objv);
	return Tcl_KeylkeysObjCmd (clientData, interp, objc, objv);

    keylPtr = Tcl_ObjGetVar2(interp, objv[1], NULL, TCL_LEAVE_ERR_MSG);
    if (keylPtr == NULL) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    /*
     * Handle retrieving a value for a specified key.
     */
    key = Tcl_GetString(objv[2]);
    if (ValidateKey(interp, key, objv[2]->length, 1) == TCL_ERROR) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    status = TclX_KeyedListGet (interp, keylPtr, key, &valuePtr);
    if (status == TCL_ERROR)
        return TCL_ERROR;
	return TCL_ERROR;

    /*
     * Handle key not found.
     */
    if (status == TCL_BREAK) {
        if (objc == 3) {
            TclX_AppendObjResult (interp, "key \"",  key,
                                  "\" not found in keyed list",
                                  (char *) NULL);
            return TCL_ERROR;
        } else {
            Tcl_ResetResult(interp);
            Tcl_SetIntObj(Tcl_GetObjResult (interp), 0);
            return TCL_OK;
        }
	if (objc == 3) {
	    TclX_AppendObjResult (interp, "key \"",  key,
				  "\" not found in keyed list",
				  (char *) NULL);
	    return TCL_ERROR;
	} else {
	    Tcl_ResetResult(interp);
	    Tcl_SetIntObj(Tcl_GetObjResult (interp), 0);
	    return TCL_OK;
	}
    }

    /*
     * No variable specified, so return value in the result.
     */
    if (objc == 3) {
        Tcl_SetObjResult (interp, valuePtr);
        return TCL_OK;
	Tcl_SetObjResult (interp, valuePtr);
	return TCL_OK;
    }

    /*
     * Variable (or empty variable name) specified.
     */
    if (!TclX_IsNullObj(objv [3])) {
        if (Tcl_ObjSetVar2(interp, objv[3], NULL,
                          valuePtr, TCL_LEAVE_ERR_MSG) == NULL)
            return TCL_ERROR;
	if (Tcl_ObjSetVar2(interp, objv[3], NULL,
			  valuePtr, TCL_LEAVE_ERR_MSG) == NULL)
	    return TCL_ERROR;
    }
    Tcl_ResetResult(interp);
    Tcl_SetIntObj(Tcl_GetObjResult (interp), 1);
    return TCL_OK;
}

/*-----------------------------------------------------------------------------
 * Tcl_KeylsetObjCmd --
 *     Implements the TCL keylset command:
 *         keylset listvar key value ?key value...?
 *-----------------------------------------------------------------------------
 */
static int
Tcl_KeylsetObjCmd(
    void        *dummy,
    Tcl_Interp  *interp,
    int          objc,
    Tcl_Size       objc,
    Tcl_Obj     *const objv[]
) {
    Tcl_Obj *keylVarPtr, *newVarObj;
    const char *key;
    int idx;
    Tcl_Size idx;
    (void)dummy;

    if ((objc < 4) || ((objc % 2) != 0)) {
        return TclX_WrongArgs (interp, objv [0],
                               "listvar key value ?key value...?");
	return TclX_WrongArgs (interp, objv [0],
			       "listvar key value ?key value...?");
    }

    /*
     * Get the variable that we are going to update.  If the var doesn't exist,
     * create it.  If it is shared by more than being a variable, duplicated
     * it.
     */
    keylVarPtr = Tcl_ObjGetVar2(interp, objv[1], NULL, 0);
    if ((keylVarPtr == NULL) || (Tcl_IsShared (keylVarPtr))) {
        if (keylVarPtr == NULL) {
            keylVarPtr = TclX_NewKeyedListObj ();
        } else {
            keylVarPtr = Tcl_DuplicateObj (keylVarPtr);
        }
        newVarObj = keylVarPtr;
	if (keylVarPtr == NULL) {
	    keylVarPtr = TclX_NewKeyedListObj ();
	} else {
	    keylVarPtr = Tcl_DuplicateObj (keylVarPtr);
	}
	newVarObj = keylVarPtr;
    } else {
        newVarObj = NULL;
	newVarObj = NULL;
    }

    for (idx = 2; idx < objc; idx += 2) {
        key = Tcl_GetString(objv[idx]);
        if (ValidateKey(interp, key, objv[idx]->length, 1) == TCL_ERROR) {
            goto errorExit;
        }
        if (TclX_KeyedListSet (interp, keylVarPtr, key, objv [idx+1]) != TCL_OK) {
            goto errorExit;
        }
	key = Tcl_GetString(objv[idx]);
	if (ValidateKey(interp, key, objv[idx]->length, 1) == TCL_ERROR) {
	    goto errorExit;
	}
	if (TclX_KeyedListSet (interp, keylVarPtr, key, objv [idx+1]) != TCL_OK) {
	    goto errorExit;
	}
    }

    if (Tcl_ObjSetVar2(interp, objv[1], NULL, keylVarPtr,
                      TCL_LEAVE_ERR_MSG) == NULL) {
        goto errorExit;
		      TCL_LEAVE_ERR_MSG) == NULL) {
	goto errorExit;
    }

    return TCL_OK;

  errorExit:
    if (newVarObj != NULL) {
        Tcl_DecrRefCount (newVarObj);
	Tcl_DecrRefCount (newVarObj);
    }
    return TCL_ERROR;
}

/*-----------------------------------------------------------------------------
 * Tcl_KeyldelObjCmd --
 *     Implements the TCL keyldel command:
 *         keyldel listvar key ?key ...?
 *----------------------------------------------------------------------------
 */
static int
Tcl_KeyldelObjCmd(
    void        *dummy,
    Tcl_Interp  *interp,
    int          objc,
    Tcl_Size       objc,
    Tcl_Obj     *const objv[]
) {
    Tcl_Obj *keylVarPtr, *keylPtr;
    const char *key;
    Tcl_Size idx;
    int idx, status;
    int status;
    (void)dummy;

    if (objc < 3) {
        return TclX_WrongArgs (interp, objv [0], "listvar key ?key ...?");
	return TclX_WrongArgs (interp, objv [0], "listvar key ?key ...?");
    }

    /*
     * Get the variable that we are going to update.  If it is shared by more
     * than being a variable, duplicated it.
     */
    keylVarPtr = Tcl_ObjGetVar2(interp, objv[1], NULL, TCL_LEAVE_ERR_MSG);
    if (keylVarPtr == NULL) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if (Tcl_IsShared (keylVarPtr)) {
        keylPtr = Tcl_DuplicateObj (keylVarPtr);
        keylVarPtr = Tcl_ObjSetVar2(interp, objv[1], NULL, keylPtr, TCL_LEAVE_ERR_MSG);
        if (keylVarPtr == NULL) {
            Tcl_DecrRefCount (keylPtr);
            return TCL_ERROR;
        }
        if (keylVarPtr != keylPtr) {
            Tcl_DecrRefCount (keylPtr);
        }
	keylPtr = Tcl_DuplicateObj (keylVarPtr);
	keylVarPtr = Tcl_ObjSetVar2(interp, objv[1], NULL, keylPtr, TCL_LEAVE_ERR_MSG);
	if (keylVarPtr == NULL) {
	    Tcl_DecrRefCount (keylPtr);
	    return TCL_ERROR;
	}
	if (keylVarPtr != keylPtr) {
	    Tcl_DecrRefCount (keylPtr);
	}
    }
    keylPtr = keylVarPtr;

    for (idx = 2; idx < objc; idx++) {
        key = Tcl_GetString(objv[idx]);
        if (ValidateKey(interp, key, objv[idx]->length, 1) == TCL_ERROR) {
            return TCL_ERROR;
        }
	key = Tcl_GetString(objv[idx]);
	if (ValidateKey(interp, key, objv[idx]->length, 1) == TCL_ERROR) {
	    return TCL_ERROR;
	}

        status = TclX_KeyedListDelete (interp, keylPtr, key);
        switch (status) {
          case TCL_BREAK:
            TclX_AppendObjResult (interp, "key not found: \"",
                                  key, "\"", (char *) NULL);
            return TCL_ERROR;
          case TCL_ERROR:
            return TCL_ERROR;
        }
	status = TclX_KeyedListDelete (interp, keylPtr, key);
	switch (status) {
	  case TCL_BREAK:
	    TclX_AppendObjResult (interp, "key not found: \"",
				  key, "\"", (char *) NULL);
	    return TCL_ERROR;
	  case TCL_ERROR:
	    return TCL_ERROR;
	}
    }

    return TCL_OK;
}

/*-----------------------------------------------------------------------------
 * Tcl_KeylkeysObjCmd --
 *     Implements the TCL keylkeys command:
 *         keylkeys listvar ?key?
 *-----------------------------------------------------------------------------
 */
static int
Tcl_KeylkeysObjCmd(
    void        *dummy,
    Tcl_Interp  *interp,
    int          objc,
    Tcl_Size       objc,
    Tcl_Obj     *const objv[]
) {
    Tcl_Obj *keylPtr, *listObjPtr;
    const char *key;
    int status;
    (void)dummy;

    if ((objc < 2) || (objc > 3)) {
        return TclX_WrongArgs(interp, objv [0], "listvar ?key?");
	return TclX_WrongArgs(interp, objv [0], "listvar ?key?");
    }

    keylPtr = Tcl_ObjGetVar2(interp, objv[1], NULL, TCL_LEAVE_ERR_MSG);
    if (keylPtr == NULL) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    /*
     * If key argument is not specified, then objv [2] is NULL or empty,
     * meaning get top level keys.
     */
    if (objc < 3) {
        key = NULL;
	key = NULL;
    } else {
        key = Tcl_GetString(objv[2]);
        if (ValidateKey(interp, key, objv[2]->length, 1) == TCL_ERROR) {
            return TCL_ERROR;
        }
	key = Tcl_GetString(objv[2]);
	if (ValidateKey(interp, key, objv[2]->length, 1) == TCL_ERROR) {
	    return TCL_ERROR;
	}
    }

    status = TclX_KeyedListGetKeys (interp, keylPtr, key, &listObjPtr);
    switch (status) {
      case TCL_BREAK:
        TclX_AppendObjResult (interp, "key not found: \"", key, "\"",
                              (char *) NULL);
        return TCL_ERROR;
	TclX_AppendObjResult (interp, "key not found: \"", key, "\"",
			      (char *) NULL);
	return TCL_ERROR;
      case TCL_ERROR:
        return TCL_ERROR;
	return TCL_ERROR;
    }

    Tcl_SetObjResult (interp, listObjPtr);

    return TCL_OK;
}

1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436





1437
1438
1439
1440
1441
1442





1443
1444
1445
1446
1447
1448





1449
1450
1451
1452
1453
1454





1455
1456
1457
1458
1427
1428
1429
1430
1431
1432
1433





1434
1435
1436
1437
1438
1439





1440
1441
1442
1443
1444
1445





1446
1447
1448
1449
1450
1451





1452
1453
1454
1455
1456
1457
1458
1459
1460







-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+





    listobj = Tcl_NewObj();
    listobj = Tcl_NewListObj(1, &listobj);
    listType = listobj->typePtr;
    Tcl_DecrRefCount(listobj);

    if (0) {
    Tcl_CreateObjCommand (interp,
                          "keylget",
                          Tcl_KeylgetObjCmd,
                          NULL,
                          NULL);
    Tcl_CreateObjCommand2(interp,
			  "keylget",
			  Tcl_KeylgetObjCmd,
			  NULL,
			  NULL);

    Tcl_CreateObjCommand (interp,
                          "keylset",
                          Tcl_KeylsetObjCmd,
                          NULL,
                          NULL);
    Tcl_CreateObjCommand2(interp,
			  "keylset",
			  Tcl_KeylsetObjCmd,
			  NULL,
			  NULL);

    Tcl_CreateObjCommand (interp,
                          "keyldel",
                          Tcl_KeyldelObjCmd,
                          NULL,
                          NULL);
    Tcl_CreateObjCommand2(interp,
			  "keyldel",
			  Tcl_KeyldelObjCmd,
			  NULL,
			  NULL);

    Tcl_CreateObjCommand (interp,
                          "keylkeys",
                          Tcl_KeylkeysObjCmd,
                          NULL,
                          NULL);
    Tcl_CreateObjCommand2(interp,
			  "keylkeys",
			  Tcl_KeylkeysObjCmd,
			  NULL,
			  NULL);
    }
}


Changes to generic/threadCmd.c.
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39







+







-
+







 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * ----------------------------------------------------------------------------
 */

#include "tclThreadInt.h"
#include "threadSvCmd.h"
#include "threadUuid.h"

/*
 * Provide package version in build contexts which do not provide
 * -DPACKAGE_VERSION, like building a shell with the Thread object
 * files built as part of that shell. Example: basekits.
 */
#ifndef PACKAGE_VERSION
#define PACKAGE_VERSION "3.0a2"
#define PACKAGE_VERSION "3.0.2"
#endif

/*
 * Access to the list of threads and to the thread send results
 * (defined below) is guarded by this mutex.
 */

49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64







-
+







 * signal the thread to which interpreter the result should be delivered.
 */

typedef struct ThreadSpecificData {
    Tcl_ThreadId threadId;                /* The real ID of this thread */
    Tcl_Interp *interp;                   /* Main interp for this thread */
    Tcl_Condition doOneEvent;             /* Signalled just before running
                                             an event from the event loop */
					     an event from the event loop */
    int flags;                            /* One of the ThreadFlags below */
    size_t refCount;                      /* Used for thread reservation */
    int eventsPending;                    /* # of unprocessed events */
    int maxEventsCount;                   /* Maximum # of pending events */
    struct ThreadEventResult  *result;
    struct ThreadSpecificData *nextPtr;
    struct ThreadSpecificData *prevPtr;
97
98
99
100
101
102
103
104

105
106
107


108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
98
99
100
101
102
103
104

105
106


107
108
109
110
111
112
113
114
115
116
117

118
119
120
121
122
123
124
125







-
+

-
-
+
+









-
+







 * passed into a new thread when the thread is created using either the
 * "thread create" Tcl command or the ThreadCreate() C function.
 */

typedef struct ThreadCtrl {
    char *script;                         /* Script to execute */
    int flags;                            /* Initial value of the "flags"
                                           * field in ThreadSpecificData */
					   * field in ThreadSpecificData */
    Tcl_Condition condWait;               /* Condition variable used to
                                           * sync parent and child threads */
    void *cd;                        /* Opaque ptr to pass to thread */
					   * sync parent and child threads */
    void *cd;                             /* Opaque ptr to pass to thread */
} ThreadCtrl;

/*
 * Structure holding result of the command executed in target thread.
 */

typedef struct ThreadEventResult {
    Tcl_Condition done;                   /* Set when the script completes */
    int code;                             /* Return value of the function */
    Tcl_Obj *result;                      /* Result from the function */
    char *result;                         /* Result from the function */
    char *errorInfo;                      /* Copy of errorInfo variable */
    char *errorCode;                      /* Copy of errorCode variable */
    Tcl_ThreadId srcThreadId;             /* Id of sender, if it dies */
    Tcl_ThreadId dstThreadId;             /* Id of target, if it dies */
    struct ThreadEvent *eventPtr;         /* Back pointer */
    struct ThreadEventResult *nextPtr;    /* List for cleanup */
    struct ThreadEventResult *prevPtr;
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152







-
+







 */

typedef struct ThreadEvent {
    Tcl_Event event;                      /* Must be first */
    struct ThreadSendData *sendData;      /* See below */
    struct ThreadClbkData *clbkData;      /* See below */
    struct ThreadEventResult *resultPtr;  /* To communicate the result back.
                                           * NULL if we don't care about it */
					   * NULL if we don't care about it */
} ThreadEvent;

typedef int  (ThreadSendProc) (Tcl_Interp*, void *);
typedef void (ThreadSendFree) (void *);

static ThreadSendProc ThreadSendEval;     /* Does a regular Tcl_Eval */
static ThreadSendProc ThreadClbkSetVar;   /* Sets the named variable */
185
186
187
188
189
190
191
192

193
194
195


196
197
198
199
200
201
202
186
187
188
189
190
191
192

193
194


195
196
197
198
199
200
201
202
203







-
+

-
-
+
+







    Tcl_Channel chan;                     /* The channel to transfer */
    struct TransferResult *resultPtr;     /* To communicate the result */
} TransferEvent;

typedef struct TransferResult {
    Tcl_Condition done;                   /* Set when transfer is done */
    int resultCode;                       /* Set to TCL_OK or TCL_ERROR when
                                             the transfer is done. Def = -1 */
					     the transfer is done. Def = -1 */
    char *resultMsg;                      /* Initialized to NULL. Set to a
                                             allocated string by the target
                                             thread in case of an error  */
					     allocated string by the target
					     thread in case of an error  */
    Tcl_ThreadId srcThreadId;             /* Id of src thread, if it dies */
    Tcl_ThreadId dstThreadId;             /* Id of tgt thread, if it dies */
    struct TransferEvent *eventPtr;       /* Back pointer */
    struct TransferResult *nextPtr;       /* Next in the linked list */
    struct TransferResult *prevPtr;       /* Previous in the linked list */
} TransferResult;

230
231
232
233
234
235
236
237

238
239
240
241
242
243
244
245




246
247
248
249
250
251




252
253
254
255


256
257
258
259
260



261
262
263
264
265



266
267
268
269
270



271
272
273

274
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
231
232
233
234
235
236
237

238
239
240
241
242




243
244
245
246
247
248




249
250
251
252
253
254


255
256
257
258



259
260
261
262
263



264
265
266
267
268



269
270
271
272
273

274
275
276
277
278
279
280
281
282

283
284
285
286
287
288
289
290







-
+




-
-
-
-
+
+
+
+


-
-
-
-
+
+
+
+


-
-
+
+


-
-
-
+
+
+


-
-
-
+
+
+


-
-
-
+
+
+


-
+








-
+








static Tcl_ThreadCreateType
NewThread(void *clientData);

static ThreadSpecificData*
ThreadExistsInner(Tcl_ThreadId id);

static int
static const char *
ThreadInit(Tcl_Interp *interp);

static int
ThreadCreate(Tcl_Interp *interp,
                               const char *script,
                               int stacksize,
                               int flags,
                               int preserve);
			       const char *script,
			       TCL_HASH_TYPE stacksize,
			       int flags,
			       int preserve);
static int
ThreadSend(Tcl_Interp *interp,
                               Tcl_ThreadId id,
                               ThreadSendData *sendPtr,
                               ThreadClbkData *clbkPtr,
                               int flags);
			       Tcl_ThreadId id,
			       ThreadSendData *sendPtr,
			       ThreadClbkData *clbkPtr,
			       int flags);
static void
ThreadSetResult(Tcl_Interp *interp,
                               int code,
                               ThreadEventResult *resultPtr);
			       int code,
			       ThreadEventResult *resultPtr);
static int
ThreadGetOption(Tcl_Interp *interp,
                               Tcl_ThreadId id,
                               char *option,
                               Tcl_DString *ds);
			       Tcl_ThreadId id,
			       char *option,
			       Tcl_DString *ds);
static int
ThreadSetOption(Tcl_Interp *interp,
                               Tcl_ThreadId id,
                               char *option,
                               char *value);
			       Tcl_ThreadId id,
			       char *option,
			       char *value);
static int
ThreadReserve(Tcl_Interp *interp,
                               Tcl_ThreadId id,
                               int operation,
                               int wait);
			       Tcl_ThreadId id,
			       int operation,
			       int wait);
static int
ThreadEventProc(Tcl_Event *evPtr,
                               int mask);
			       int mask);
static int
ThreadWait(Tcl_Interp *interp);

static int
ThreadExists(Tcl_ThreadId id);

static int
ThreadList(Tcl_Interp *interp,
                               Tcl_ThreadId **thrIdArray);
			       Tcl_ThreadId **thrIdArray);
static void
ThreadErrorProc(Tcl_Interp *interp);

static void
ThreadFreeProc(void *clientData);

static void
302
303
304
305
306
307
308
309

310
311
312
313


314
315
316

317
318
319

320
321
322

323
324
325
326

327
328
329
330
331


332
333
334

335
336
337

338
339
340
341
342
343



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366


















367





368

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389

390
391
392
393
394
395
396
397
398
399


400
401
402
403
404
405
406
303
304
305
306
307
308
309

310
311
312


313
314
315
316

317
318
319

320
321
322

323
324
325
326

327
328
329
330


331
332
333
334

335
336
337

338
339
340
341



342
343
344
345
346
347
348
349


















350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373

374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402
403


404
405
406
407
408
409
410
411
412







-
+


-
-
+
+


-
+


-
+


-
+



-
+



-
-
+
+


-
+


-
+



-
-
-
+
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
-
+




















-
+








-
-
+
+







ListUpdate(ThreadSpecificData *tsdPtr);

static void
ListUpdateInner(ThreadSpecificData *tsdPtr);

static int
ThreadJoin(Tcl_Interp *interp,
                               Tcl_ThreadId id);
			       Tcl_ThreadId id);
static int
ThreadTransfer(Tcl_Interp *interp,
                               Tcl_ThreadId id,
                               Tcl_Channel chan);
			       Tcl_ThreadId id,
			       Tcl_Channel chan);
static int
ThreadDetach(Tcl_Interp *interp,
                               Tcl_Channel chan);
			       Tcl_Channel chan);
static int
ThreadAttach(Tcl_Interp *interp,
                               char *chanName);
			       char *chanName);
static int
TransferEventProc(Tcl_Event *evPtr,
                               int mask);
			       int mask);

static void
ThreadGetHandle(Tcl_ThreadId,
                               char *handlePtr);
			       char *handlePtr);

static int
ThreadGetId(Tcl_Interp *interp,
                               Tcl_Obj *handleObj,
                               Tcl_ThreadId *thrIdPtr);
			       Tcl_Obj *handleObj,
			       Tcl_ThreadId *thrIdPtr);
static void
ErrorNoSuchThread(Tcl_Interp *interp,
                               Tcl_ThreadId thrId);
			       Tcl_ThreadId thrId);
static void
ThreadCutChannel(Tcl_Interp *interp,
                               Tcl_Channel channel);
			       Tcl_Channel channel);

static int
ThreadCancel(Tcl_Interp *interp,
                               Tcl_ThreadId thrId,
                               const char *result,
                               int flags);
			       Tcl_ThreadId thrId,
			       const char *result,
			       int flags);

/*
 * Functions implementing Tcl commands
 */

static Tcl_ObjCmdProc ThreadCreateObjCmd;
static Tcl_ObjCmdProc ThreadReserveObjCmd;
static Tcl_ObjCmdProc ThreadReleaseObjCmd;
static Tcl_ObjCmdProc ThreadSendObjCmd;
static Tcl_ObjCmdProc ThreadBroadcastObjCmd;
static Tcl_ObjCmdProc ThreadUnwindObjCmd;
static Tcl_ObjCmdProc ThreadExitObjCmd;
static Tcl_ObjCmdProc ThreadIdObjCmd;
static Tcl_ObjCmdProc ThreadNamesObjCmd;
static Tcl_ObjCmdProc ThreadWaitObjCmd;
static Tcl_ObjCmdProc ThreadExistsObjCmd;
static Tcl_ObjCmdProc ThreadConfigureObjCmd;
static Tcl_ObjCmdProc ThreadErrorProcObjCmd;
static Tcl_ObjCmdProc ThreadJoinObjCmd;
static Tcl_ObjCmdProc ThreadTransferObjCmd;
static Tcl_ObjCmdProc ThreadDetachObjCmd;
static Tcl_ObjCmdProc ThreadAttachObjCmd;
static Tcl_ObjCmdProc ThreadCancelObjCmd;
static Tcl_ObjCmdProc2 ThreadCreateObjCmd;
static Tcl_ObjCmdProc2 ThreadReserveObjCmd;
static Tcl_ObjCmdProc2 ThreadReleaseObjCmd;
static Tcl_ObjCmdProc2 ThreadSendObjCmd;
static Tcl_ObjCmdProc2 ThreadBroadcastObjCmd;
static Tcl_ObjCmdProc2 ThreadUnwindObjCmd;
static Tcl_ObjCmdProc2 ThreadExitObjCmd;
static Tcl_ObjCmdProc2 ThreadIdObjCmd;
static Tcl_ObjCmdProc2 ThreadNamesObjCmd;
static Tcl_ObjCmdProc2 ThreadWaitObjCmd;
static Tcl_ObjCmdProc2 ThreadExistsObjCmd;
static Tcl_ObjCmdProc2 ThreadConfigureObjCmd;
static Tcl_ObjCmdProc2 ThreadErrorProcObjCmd;
static Tcl_ObjCmdProc2 ThreadJoinObjCmd;
static Tcl_ObjCmdProc2 ThreadTransferObjCmd;
static Tcl_ObjCmdProc2 ThreadDetachObjCmd;
static Tcl_ObjCmdProc2 ThreadAttachObjCmd;
static Tcl_ObjCmdProc2 ThreadCancelObjCmd;

#ifndef STRINGIFY
#  define STRINGIFY(x) STRINGIFY1(x)
#  define STRINGIFY1(x) #x
#endif

static int
static const char *
ThreadInit(
    Tcl_Interp *interp /* The current Tcl interpreter */
) {
    /* Tcl 8.7 interps are only supported on 32-bit machines.
     * Lower than that is never supported. Bye!
     */
#if defined(TCL_WIDE_INT_IS_LONG) && TCL_MAJOR_VERSION < 9
#   error "Thread 3.0 is only supported with Tcl 9.0 and higher."
#	error "Please use Thread 2.8 (branch thread-2-8-branch)"
#endif

	/* Even though it's not supported, Thread 3.0 works with Tcl 8.7
	 * on 32-bit platforms, so allow that for now. It could be that
	 * Tcl 9.0 introduces a further binary incompatibility in the
	 * future, so this is not guaranteed to stay like it is now!
	 */
    const char *ver = (sizeof(size_t) == sizeof(int))? "8.7-": "9.0";

    if (!((Tcl_InitStubs)(interp, ver, (TCL_MAJOR_VERSION<<8)|(TCL_MINOR_VERSION<<16),
	    TCL_STUB_MAGIC))) {
	return TCL_ERROR;
	return NULL;
    }

    if (threadMutex == NULL){
	Tcl_MutexLock(&threadMutex);
	if (threadMutex == NULL){
	    /* If threadMutex==NULL here, it means that Tcl_MutexLock() is
	     * a dummy function, which is the case in unthreaded Tcl */
	    const char *msg = "Tcl core wasn't compiled for threading";
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, -1));
	    return TCL_ERROR;
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(msg, TCL_INDEX_NONE));
	    return NULL;
	}
	Tcl_MutexUnlock(&threadMutex);
    }

    TCL_CMD(interp, THREAD_CMD_PREFIX"create",    ThreadCreateObjCmd);
    TCL_CMD(interp, THREAD_CMD_PREFIX"send",      ThreadSendObjCmd);
    TCL_CMD(interp, THREAD_CMD_PREFIX"broadcast", ThreadBroadcastObjCmd);
420
421
422
423
424
425
426
427

428
429
430
431
432
433
434

435
436
437
438
439
440

441
442



























































443
444
445
446
447
448
449
426
427
428
429
430
431
432

433
434
435
436
437
438
439

440
441
442
443
444
445

446
447

448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513







-
+






-
+





-
+

-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    TCL_CMD(interp, THREAD_CMD_PREFIX"attach",    ThreadAttachObjCmd);
    TCL_CMD(interp, THREAD_CMD_PREFIX"cancel",    ThreadCancelObjCmd);

    /*
     * Add shared variable commands
     */

    Sv_Init(interp);
    SvInit(interp);

    /*
     * Add commands to access thread
     * synchronization primitives.
     */

    Sp_Init(interp);
    SpInit(interp);

    /*
     * Add threadpool commands.
     */

    Tpool_Init(interp);
    TpoolInit(interp);

    return TCL_OK;
    return PACKAGE_VERSION
	    "+" STRINGIFY(THREAD_VERSION_UUID)
#if defined(__clang__) && defined(__clang_major__)
	    ".clang-" STRINGIFY(__clang_major__)
#if __clang_minor__ < 10
	    "0"
#endif
	    STRINGIFY(__clang_minor__)
#endif
#if defined(__cplusplus) && !defined(__OBJC__)
	    ".cplusplus"
#endif
#ifndef NDEBUG
	    ".debug"
#endif
#if !defined(__clang__) && !defined(__INTEL_COMPILER) && defined(__GNUC__)
	    ".gcc-" STRINGIFY(__GNUC__)
#if __GNUC_MINOR__ < 10
	    "0"
#endif
	    STRINGIFY(__GNUC_MINOR__)
#endif
#ifdef __INTEL_COMPILER
	    ".icc-" STRINGIFY(__INTEL_COMPILER)
#endif
#ifdef HAVE_GDBM
	    ".gdbm"
#endif
#ifdef HAVE_LMDB
	    ".lmdb"
#endif
#ifdef TCL_MEM_DEBUG
	    ".memdebug"
#endif
#if defined(_MSC_VER)
	    ".msvc-" STRINGIFY(_MSC_VER)
#endif
#ifdef USE_NMAKE
	    ".nmake"
#endif
#ifndef TCL_CFG_OPTIMIZED
	    ".no-optimize"
#endif
#ifdef __OBJC__
	    ".objective-c"
#if defined(__cplusplus)
	    "plusplus"
#endif
#endif
#ifdef TCL_CFG_PROFILED
	    ".profile"
#endif
#ifdef PURIFY
	    ".purify"
#endif
#ifdef STATIC_BUILD
	    ".static"
#endif
	    ;
}


/*
 *----------------------------------------------------------------------
 *
 * Thread_Init --
459
460
461
462
463
464
465
466


467
468
469


470
471










472


473
474
475
476
477
478
479
523
524
525
526
527
528
529

530
531
532


533
534
535
536
537
538
539
540
541
542
543
544
545
546

547
548
549
550
551
552
553
554
555







-
+
+

-
-
+
+


+
+
+
+
+
+
+
+
+
+
-
+
+







 *----------------------------------------------------------------------
 */

DLLEXPORT int
Thread_Init(
    Tcl_Interp *interp /* The current Tcl interpreter */
) {
    int status = ThreadInit(interp);
    const char *version = ThreadInit(interp);
    Tcl_CmdInfo info;

    if (status != TCL_OK) {
        return status;
    if (version == NULL) {
	return TCL_ERROR;
    }

    if (Tcl_GetCommandInfo(interp, "::tcl::build-info", &info)) {
#if TCL_MAJOR_VERSION > 8
	if (info.isNativeObjectProc == 2) {
	    Tcl_CreateObjCommand2(interp, "::thread::build-info",
		    info.objProc2, (void *)version, NULL);
	} else
#endif
	Tcl_CreateObjCommand(interp, "::thread::build-info",
		info.objProc, (void *)version, NULL);
    }
    return Tcl_PkgProvideEx(interp, "Thread", PACKAGE_VERSION, NULL);
    Tcl_PkgProvideEx(interp, "Thread", PACKAGE_VERSION, NULL);
    return Tcl_PkgProvideEx(interp, "thread", PACKAGE_VERSION, NULL);
}

/*
 *----------------------------------------------------------------------
 *
 * Init --
 *
491
492
493
494
495
496
497

498
499
500
501
502













503
504
505
506
507
508
509
567
568
569
570
571
572
573
574





575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594







+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+







static void
Init(
    Tcl_Interp *interp         /* Current interpreter. */
) {
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);

    if (tsdPtr->interp == NULL) {
	Tcl_Interp *tmpInterp, *mainInterp = interp;
        memset(tsdPtr, 0, sizeof(ThreadSpecificData));
        tsdPtr->interp = interp;
        ListUpdate(tsdPtr);
        Tcl_CreateThreadExitHandler(ThreadExitProc,
                                    threadEmptyResult);
	memset(tsdPtr, 0, sizeof(ThreadSpecificData));
	/*
	 * Retrieve main interpreter of the thread, only
	 * main interpreter used as default thread-interpreter,
	 * so no childs here, see bug [d4ba38d00d06ebba]
	 */
	while (mainInterp && (tmpInterp = Tcl_GetMaster(mainInterp))) {
	    mainInterp = tmpInterp;
	}
	tsdPtr->interp = mainInterp;
	ListUpdate(tsdPtr);
	Tcl_CreateThreadExitHandler(ThreadExitProc,
				    threadEmptyResult);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ThreadCreateObjCmd --
518
519
520
521
522
523
524
525

526
527

528
529

530

531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561


















562
563
564
565
566
567
568
603
604
605
606
607
608
609

610
611

612
613
614
615

616
617
618

619
620
621
622
623
624
625
626
627
628


















629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653







-
+

-
+


+
-
+


-










-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *  See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadCreateObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    Tcl_Size argc;
    int argc, rsrv = 0;
    int rsrv = 0;
    const char *arg, *script;
    int flags = TCL_THREAD_NOFLAGS;
    (void)dummy;

    Init(interp);

    /*
     * Syntax: thread::create ?-joinable? ?-preserved? ?script?
     */

    script = THREAD_CMD_PREFIX"wait";

    for (argc = 1; argc < objc; argc++) {
        arg = Tcl_GetString(objv[argc]);
        if (OPT_CMP(arg, "--")) {
            argc++;
            if ((argc + 1) == objc) {
                script = Tcl_GetString(objv[argc]);
            } else {
                goto usage;
            }
            break;
        } else if (OPT_CMP(arg, "-joinable")) {
            flags |= TCL_THREAD_JOINABLE;
        } else if (OPT_CMP(arg, "-preserved")) {
            rsrv = 1;
        } else if ((argc + 1) == objc) {
            script = Tcl_GetString(objv[argc]);
        } else {
            goto usage;
        }
	arg = Tcl_GetString(objv[argc]);
	if (OPT_CMP(arg, "--")) {
	    argc++;
	    if ((argc + 1) == objc) {
		script = Tcl_GetString(objv[argc]);
	    } else {
		goto usage;
	    }
	    break;
	} else if (OPT_CMP(arg, "-joinable")) {
	    flags |= TCL_THREAD_JOINABLE;
	} else if (OPT_CMP(arg, "-preserved")) {
	    rsrv = 1;
	} else if ((argc + 1) == objc) {
	    script = Tcl_GetString(objv[argc]);
	} else {
	    goto usage;
	}
    }

    return ThreadCreate(interp, script, TCL_THREAD_STACK_DEFAULT, flags, rsrv);

 usage:
    Tcl_WrongNumArgs(interp, 1, objv, "?-joinable? ?script?");
    return TCL_ERROR;
584
585
586
587
588
589
590
591

592
593

594
595
596
597
598
599
600
601
602
603


604
605
606
607
608



609
610
611
612
613
614
615
669
670
671
672
673
674
675

676
677

678
679
680
681

682
683
684
685


686
687
688
689



690
691
692
693
694
695
696
697
698
699







-
+

-
+



-




-
-
+
+


-
-
-
+
+
+







 *  See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadReserveObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    Tcl_ThreadId thrId = NULL;
    (void)dummy;

    Init(interp);

    if (objc > 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "?threadId?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "?threadId?");
	return TCL_ERROR;
    }
    if (objc == 2) {
        if (ThreadGetId(interp, objv[1], &thrId) != TCL_OK) {
            return TCL_ERROR;
        }
	if (ThreadGetId(interp, objv[1], &thrId) != TCL_OK) {
	    return TCL_ERROR;
	}
    }

    return ThreadReserve(interp, thrId, THREAD_RESERVE, 0);
}

/*
 *----------------------------------------------------------------------
627
628
629
630
631
632
633
634

635
636

637
638
639
640
641
642
643
644
645
646
647


648
649
650
651
652
653
654
655
656
657
658
659










660
661
662
663
664
665
666
711
712
713
714
715
716
717

718
719

720
721
722
723
724

725
726
727
728


729
730
731
732










733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749







-
+

-
+




-




-
-
+
+


-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







 *  See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadReleaseObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    int wait = 0;
    Tcl_ThreadId thrId = NULL;
    (void)dummy;

    Init(interp);

    if (objc > 3) {
        Tcl_WrongNumArgs(interp, 1, objv, "?-wait? ?threadId?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "?-wait? ?threadId?");
	return TCL_ERROR;
    }
    if (objc > 1) {
        if (OPT_CMP(Tcl_GetString(objv[1]), "-wait")) {
            wait = 1;
            if (objc > 2) {
                if (ThreadGetId(interp, objv[2], &thrId) != TCL_OK) {
                    return TCL_ERROR;
                }
            }
        } else if (ThreadGetId(interp, objv[1], &thrId) != TCL_OK) {
            return TCL_ERROR;
        }
	if (OPT_CMP(Tcl_GetString(objv[1]), "-wait")) {
	    wait = 1;
	    if (objc > 2) {
		if (ThreadGetId(interp, objv[2], &thrId) != TCL_OK) {
		    return TCL_ERROR;
		}
	    }
	} else if (ThreadGetId(interp, objv[1], &thrId) != TCL_OK) {
	    return TCL_ERROR;
	}
    }

    return ThreadReserve(interp, thrId, THREAD_RELEASE, wait);
}

/*
 *----------------------------------------------------------------------
677
678
679
680
681
682
683
684

685
686

687
688
689
690
691
692
693
694
695


696
697
698
699
700
701
702
760
761
762
763
764
765
766

767
768

769
770
771


772
773
774


775
776
777
778
779
780
781
782
783







-
+

-
+


-
-



-
-
+
+







 *  See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadUnwindObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    (void)dummy;

    Init(interp);

    if (objc > 1) {
        Tcl_WrongNumArgs(interp, 1, objv, NULL);
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }

    return ThreadReserve(interp, 0, THREAD_RELEASE, 0);
}

/*
 *----------------------------------------------------------------------
714
715
716
717
718
719
720
721

722
723

724
725
726
727
728
729
730
731
732
733


734
735
736
737
738
739



740
741
742
743
744
745
746
795
796
797
798
799
800
801

802
803

804
805
806
807

808
809
810
811


812
813
814
815
816



817
818
819
820
821
822
823
824
825
826







-
+

-
+



-




-
-
+
+



-
-
-
+
+
+







 *  Lots.  improper clean up of resources.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadExitObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    int status = 666;
    (void)dummy;

    Init(interp);

    if (objc > 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "?status?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "?status?");
	return TCL_ERROR;
    }

    if (objc == 2) {
        if (Tcl_GetIntFromObj(interp, objv[1], &status) != TCL_OK) {
            return TCL_ERROR;
        }
	if (Tcl_GetIntFromObj(interp, objv[1], &status) != TCL_OK) {
	    return TCL_ERROR;
	}
    }

    ListRemove(NULL);

    Tcl_ExitThread(status);

    return TCL_OK; /* NOT REACHED */
761
762
763
764
765
766
767
768

769
770

771
772
773
774
775
776
777
778
779
780


781
782
783
784

785
786
787
788
789
790
791
841
842
843
844
845
846
847

848
849

850
851
852
853

854
855
856
857


858
859
860
861
862

863
864
865
866
867
868
869
870







-
+

-
+



-




-
-
+
+



-
+







 *  None.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadIdObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    char thrHandle[THREAD_HNDLMAXLEN];
    (void)dummy;

    Init(interp);

    if (objc > 1) {
        Tcl_WrongNumArgs(interp, 1, objv, NULL);
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }

    ThreadGetHandle(Tcl_GetCurrentThread(), thrHandle);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(thrHandle, TCL_AUTO_LENGTH));
    Tcl_SetObjResult(interp, Tcl_NewStringObj(thrHandle, TCL_INDEX_NONE));

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
803
804
805
806
807
808
809
810

811
812

813
814
815

816
817
818
819
820
821
822
823
824
825


826
827
828
829
830
831

832
833
834
835
836
837
838


839
840
841
842
843
844
845
882
883
884
885
886
887
888

889
890

891
892
893

894
895
896
897

898
899
900
901


902
903
904
905
906
907
908

909
910
911
912
913
914


915
916
917
918
919
920
921
922
923







-
+

-
+


-
+



-




-
-
+
+





-
+





-
-
+
+







 *  None.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadNamesObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    int ii, length;
    Tcl_Size ii, length;
    char *result, thrHandle[THREAD_HNDLMAXLEN];
    Tcl_ThreadId *thrIdArray;
    Tcl_DString threadNames;
    (void)dummy;

    Init(interp);

    if (objc > 1) {
        Tcl_WrongNumArgs(interp, 1, objv, NULL);
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }

    length = ThreadList(interp, &thrIdArray);

    if (length == 0) {
        return TCL_OK;
	return TCL_OK;
    }

    Tcl_DStringInit(&threadNames);

    for (ii = 0; ii < length; ii++) {
        ThreadGetHandle(thrIdArray[ii], thrHandle);
        Tcl_DStringAppendElement(&threadNames, thrHandle);
	ThreadGetHandle(thrIdArray[ii], thrHandle);
	Tcl_DStringAppendElement(&threadNames, thrHandle);
    }

    length = Tcl_DStringLength(&threadNames);
    result = Tcl_DStringValue(&threadNames);

    Tcl_SetObjResult(interp, Tcl_NewStringObj(result, length));

876
877
878
879
880
881
882
883

884
885

886
887
888
889


890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905

906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921











922
923
924

925
926
927

928
929
930

931
932
933
934


935
936

937
938
939
940
941
942
943
944
945
946







947
948
949
950
951
952





953
954
955
956
957
958
959
960
961
962
963
964











965
966
967
968
969
970
971
972
973
974
975

976
977
978
979
980
981
982
983
984




985
986
987
988
989
990
991






992
993
994
995
996
997
998
954
955
956
957
958
959
960

961
962

963
964
965


966
967
968
969
970


971
972
973
974
975
976
977
978
979
980

981
982
983
984
985
986











987
988
989
990
991
992
993
994
995
996
997
998
999

1000
1001
1002

1003
1004
1005

1006
1007
1008


1009
1010
1011

1012
1013
1014
1015







1016
1017
1018
1019
1020
1021
1022
1023





1024
1025
1026
1027
1028
1029











1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050

1051
1052
1053
1054
1055
1056




1057
1058
1059
1060
1061






1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074







-
+

-
+


-
-
+
+



-
-










-
+





-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+


-
+


-
+


-
+


-
-
+
+

-
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+










-
+





-
-
-
-
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+







threadSendObjFree(void *ptr)
{
    Tcl_DecrRefCount((Tcl_Obj *)ptr);
}

static int
ThreadSendObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    size_t size;
    int cmd = 0, ret, ii = 0, flags = 0;
    Tcl_Size size, ii = 0;
    int cmd = 0, ret, flags = 0;
    Tcl_ThreadId thrId;
    const char *script, *arg;
    Tcl_Obj *var = NULL;
    (void)dummy;

    ThreadClbkData *clbkPtr = NULL;
    ThreadSendData *sendPtr = NULL;

    Init(interp);

    /*
     * Syntax: thread::send ?-async? ?-head? threadId script ?varName?
     */

    if (objc < 3 || objc > 6) {
        goto usage;
	goto usage;
    }

    flags = THREAD_SEND_WAIT;

    for (ii = 1; ii < objc; ii++) {
        arg = Tcl_GetString(objv[ii]);
        if (OPT_CMP(arg, "-async")) {
            flags &= ~THREAD_SEND_WAIT;
        } else if (OPT_CMP(arg, "-head")) {
            flags |= THREAD_SEND_HEAD;
        } else if (OPT_CMP(arg, "-command")) {
            flags &= ~THREAD_SEND_WAIT;
            cmd = 1;
        } else {
            break;
        }
	arg = Tcl_GetString(objv[ii]);
	if (OPT_CMP(arg, "-async")) {
	    flags &= ~THREAD_SEND_WAIT;
	} else if (OPT_CMP(arg, "-head")) {
	    flags |= THREAD_SEND_HEAD;
	} else if (OPT_CMP(arg, "-command")) {
	    flags &= ~THREAD_SEND_WAIT;
	    cmd = 1;
	} else {
	    break;
	}
    }
    if (ii >= objc) {
        goto usage;
	goto usage;
    }
    if (ThreadGetId(interp, objv[ii], &thrId) != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if (++ii >= objc) {
        goto usage;
	goto usage;
    }

    script = Tcl_GetString(objv[ii]);
    size = objv[ii]->length+1;
    script = Tcl_GetStringFromObj(objv[ii], &size);
    size++;
    if (++ii < objc) {
        var = objv[ii];
	var = objv[ii];
    }
    if (var && (flags & THREAD_SEND_WAIT) == 0) {

        if (thrId == Tcl_GetCurrentThread()) {
            /*
             * FIXME: Do something for callbacks to self
             */
            Tcl_SetObjResult(interp, Tcl_NewStringObj("can't notify self", TCL_AUTO_LENGTH));
            return TCL_ERROR;
        }
	if (thrId == Tcl_GetCurrentThread()) {
	    /*
	     * FIXME: Do something for callbacks to self
	     */
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("can't notify self", TCL_INDEX_NONE));
	    return TCL_ERROR;
	}

        /*
         * Prepare record for the callback. This is asynchronously
         * posted back to us when the target thread finishes processing.
         * We should do a vwait on the "var" to get notified.
         */
	/*
	 * Prepare record for the callback. This is asynchronously
	 * posted back to us when the target thread finishes processing.
	 * We should do a vwait on the "var" to get notified.
	 */

        clbkPtr = (ThreadClbkData *)Tcl_Alloc(sizeof(ThreadClbkData));
        if (cmd) {
            clbkPtr->execProc   = ThreadClbkCommand;
        } else {
            clbkPtr->execProc   = ThreadClbkSetVar;
        }
        clbkPtr->freeProc   = threadSendObjFree;
        clbkPtr->interp     = interp;
        clbkPtr->threadId   = Tcl_GetCurrentThread();
        clbkPtr->clientData = Sv_DuplicateObj(var);
        Tcl_IncrRefCount((Tcl_Obj *)clbkPtr->clientData);
	clbkPtr = (ThreadClbkData *)Tcl_Alloc(sizeof(ThreadClbkData));
	if (cmd) {
	    clbkPtr->execProc   = ThreadClbkCommand;
	} else {
	    clbkPtr->execProc   = ThreadClbkSetVar;
	}
	clbkPtr->freeProc   = threadSendObjFree;
	clbkPtr->interp     = interp;
	clbkPtr->threadId   = Tcl_GetCurrentThread();
	clbkPtr->clientData = Sv_DuplicateObj(var);
	Tcl_IncrRefCount((Tcl_Obj *)clbkPtr->clientData);
    }

    /*
     * Prepare job record for the target thread
     */

    sendPtr = (ThreadSendData *)Tcl_Alloc(sizeof(ThreadSendData));
    sendPtr->interp     = NULL; /* Signal to use thread main interp */
    sendPtr->execProc   = ThreadSendEval;
    sendPtr->freeProc   = threadSendFree;
    sendPtr->clientData = memcpy(Tcl_Alloc(size), script, size);
    sendPtr->clientData = memcpy(Tcl_Alloc(size), script, (size_t)size);

    ret = ThreadSend(interp, thrId, sendPtr, clbkPtr, flags);

    if (var && (flags & THREAD_SEND_WAIT)) {

        /*
         * Leave job's result in passed variable
         * and return the code, like "catch" does.
         */
	/*
	 * Leave job's result in passed variable
	 * and return the code, like "catch" does.
	 */

        Tcl_Obj *resultObj = Tcl_GetObjResult(interp);
        if (!Tcl_ObjSetVar2(interp, var, NULL, resultObj, TCL_LEAVE_ERR_MSG)) {
            return TCL_ERROR;
        }
        Tcl_SetObjResult(interp, Tcl_NewIntObj(ret));
        return TCL_OK;
	Tcl_Obj *resultObj = Tcl_GetObjResult(interp);
	if (!Tcl_ObjSetVar2(interp, var, NULL, resultObj, TCL_LEAVE_ERR_MSG)) {
	    return TCL_ERROR;
	}
	Tcl_SetObjResult(interp, Tcl_NewIntObj(ret));
	return TCL_OK;
    }

    return ret;

usage:
    Tcl_WrongNumArgs(interp,1,objv,"?-async? ?-head? id script ?varName?");
    return TCL_ERROR;
1013
1014
1015
1016
1017
1018
1019
1020

1021
1022

1023
1024
1025
1026

1027
1028
1029
1030
1031
1032
1033
1034
1035
1036


1037
1038
1039
1040


1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053

1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080







1081
1082
1083
1084
1085
1086
1087
1089
1090
1091
1092
1093
1094
1095

1096
1097

1098
1099
1100
1101

1102
1103
1104
1105

1106
1107
1108
1109


1110
1111
1112
1113


1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127

1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148







1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162







-
+

-
+



-
+



-




-
-
+
+


-
-
+
+












-
+




















-
-
-
-
-
-
-
+
+
+
+
+
+
+







 *  Script is sent to all known threads except the caller thread.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadBroadcastObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    int ii, nthreads;
    size_t size;
    Tcl_Size size;
    const char *script;
    Tcl_ThreadId *thrIdArray;
    ThreadSendData *sendPtr, job;
    (void)dummy;

    Init(interp);

    if (objc != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "script");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "script");
	return TCL_ERROR;
    }

    script = Tcl_GetString(objv[1]);
    size = objv[1]->length + 1;
    script = Tcl_GetStringFromObj(objv[1], &size);
    ++size;

    /*
     * Get the list of known threads. Note that this one may
     * actually change (thread may exit or otherwise cease to
     * exist) while we circle in the loop below. We really do
     * not care about that here since we don't return any
     * script results to the caller.
     */

    nthreads = ThreadList(interp, &thrIdArray);

    if (nthreads == 0) {
        return TCL_OK;
	return TCL_OK;
    }

    /*
     * Prepare the structure with the job description
     * to be sent asynchronously to each known thread.
     */

    job.interp     = NULL; /* Signal to use thread's main interp */
    job.execProc   = ThreadSendEval;
    job.freeProc   = threadSendFree;
    job.clientData = NULL;

    /*
     * Now, circle this list and send each thread the script.
     * This is sent asynchronously, since we do not care what
     * are they going to do with it. Also, the event is queued
     * to the head of the event queue (as out-of-band message).
     */

    for (ii = 0; ii < nthreads; ii++) {
        if (thrIdArray[ii] == Tcl_GetCurrentThread()) {
            continue; /* Do not broadcast self */
        }
        sendPtr  = (ThreadSendData *)Tcl_Alloc(sizeof(ThreadSendData));
        *sendPtr = job;
        sendPtr->clientData = memcpy(Tcl_Alloc(size), script, size);
        ThreadSend(interp, thrIdArray[ii], sendPtr, NULL, THREAD_SEND_HEAD);
	if (thrIdArray[ii] == Tcl_GetCurrentThread()) {
	    continue; /* Do not broadcast self */
	}
	sendPtr  = (ThreadSendData *)Tcl_Alloc(sizeof(ThreadSendData));
	*sendPtr = job;
	sendPtr->clientData = memcpy(Tcl_Alloc(size), script, (size_t)size);
	ThreadSend(interp, thrIdArray[ii], sendPtr, NULL, THREAD_SEND_HEAD);
    }

    Tcl_Free(thrIdArray);
    Tcl_ResetResult(interp);

    return TCL_OK;
}
1101
1102
1103
1104
1105
1106
1107
1108

1109
1110

1111
1112
1113
1114
1115
1116
1117
1118
1119


1120
1121
1122
1123
1124
1125
1126
1176
1177
1178
1179
1180
1181
1182

1183
1184

1185
1186
1187


1188
1189
1190


1191
1192
1193
1194
1195
1196
1197
1198
1199







-
+

-
+


-
-



-
-
+
+







 *  Enters the event loop.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadWaitObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    (void)dummy;

    Init(interp);

    if (objc > 1) {
        Tcl_WrongNumArgs(interp, 1, objv, NULL);
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }

    return ThreadWait(interp);
}

/*
 *----------------------------------------------------------------------
1139
1140
1141
1142
1143
1144
1145
1146

1147
1148

1149
1150
1151

1152
1153
1154
1155
1156
1157
1158
1159


1160
1161
1162
1163
1164
1165



1166
1167
1168
1169
1170




1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181










1182
1183
1184
1185
1186
1187
1188
1189
1190

1191
1192
1193
1194
1195
1196
1197


1198
1199
1200
1201
1202
1203
1204
1212
1213
1214
1215
1216
1217
1218

1219
1220

1221
1222
1223

1224
1225

1226
1227
1228
1229


1230
1231
1232
1233
1234



1235
1236
1237
1238




1239
1240
1241
1242











1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260

1261
1262


1263
1264


1265
1266
1267
1268
1269
1270
1271
1272
1273







-
+

-
+


-
+

-




-
-
+
+



-
-
-
+
+
+

-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+








-
+

-
-


-
-
+
+







 *  Registers an errorproc.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadErrorProcObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    size_t len;
    Tcl_Size len;
    char *proc;
    (void)dummy;

    Init(interp);

    if (objc > 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "?proc?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "?proc?");
	return TCL_ERROR;
    }
    Tcl_MutexLock(&threadMutex);
    if (objc == 1) {
        if (errorProcString) {
        	Tcl_SetObjResult(interp, Tcl_NewStringObj(errorProcString, TCL_AUTO_LENGTH));
        }
	if (errorProcString) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(errorProcString, TCL_INDEX_NONE));
	}
    } else {
        if (errorProcString) {
            Tcl_Free(errorProcString);
        }
        proc = Tcl_GetString(objv[1]);
	if (errorProcString) {
	    Tcl_Free(errorProcString);
	}
	proc = Tcl_GetStringFromObj(objv[1], &len);
        len = objv[1]->length;
        if (len == 0) {
            errorThreadId = NULL;
            errorProcString = NULL;
        } else {
            errorThreadId = Tcl_GetCurrentThread();
            errorProcString = (char *)Tcl_Alloc(1+strlen(proc));
            strcpy(errorProcString, proc);
            Tcl_DeleteThreadExitHandler(ThreadFreeError, NULL);
            Tcl_CreateThreadExitHandler(ThreadFreeError, NULL);
        }
	if (len == 0) {
	    errorThreadId = NULL;
	    errorProcString = NULL;
	} else {
	    errorThreadId = Tcl_GetCurrentThread();
	    errorProcString = (char *)Tcl_Alloc(1+strlen(proc));
	    strcpy(errorProcString, proc);
	    Tcl_DeleteThreadExitHandler(ThreadFreeError, NULL);
	    Tcl_CreateThreadExitHandler(ThreadFreeError, NULL);
	}
    }
    Tcl_MutexUnlock(&threadMutex);

    return TCL_OK;
}

static void
ThreadFreeError(
    void *dummy
    TCL_UNUSED(void *)
) {
    (void)dummy;

    Tcl_MutexLock(&threadMutex);
    if (errorThreadId != Tcl_GetCurrentThread()) {
        Tcl_MutexUnlock(&threadMutex);
        return;
	Tcl_MutexUnlock(&threadMutex);
	return;
    }
    Tcl_Free(errorProcString);
    errorThreadId = NULL;
    errorProcString = NULL;
    Tcl_MutexUnlock(&threadMutex);
}

1217
1218
1219
1220
1221
1222
1223
1224

1225
1226

1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240


1241
1242
1243
1244

1245
1246
1247
1248
1249
1250
1251
1286
1287
1288
1289
1290
1291
1292

1293
1294

1295
1296
1297
1298

1299
1300
1301
1302
1303
1304
1305
1306


1307
1308
1309
1310
1311

1312
1313
1314
1315
1316
1317
1318
1319







-
+

-
+



-








-
-
+
+



-
+







 *  See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadJoinObjCmd(
    void *dummy,                /* Not used. */
    TCL_UNUSED(void *),         /* Not used. */
    Tcl_Interp *interp,         /* Current interpreter. */
    int         objc,           /* Number of arguments. */
    Tcl_Size    objc,           /* Number of arguments. */
    Tcl_Obj    *const objv[]    /* Argument objects. */
) {
    Tcl_ThreadId thrId;
    (void)dummy;

    Init(interp);

    /*
     * Syntax of 'join': id
     */

    if (objc != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "id");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "id");
	return TCL_ERROR;
    }

    if (ThreadGetId(interp, objv[1], &thrId) != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    return ThreadJoin(interp, thrId);
}

/*
 *----------------------------------------------------------------------
1262
1263
1264
1265
1266
1267
1268
1269

1270
1271

1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287


1288
1289
1290

1291
1292
1293
1294
1295

1296
1297
1298
1299
1300
1301
1302
1330
1331
1332
1333
1334
1335
1336

1337
1338

1339
1340
1341


1342
1343
1344
1345
1346
1347
1348
1349
1350
1351


1352
1353
1354
1355

1356
1357
1358
1359
1360

1361
1362
1363
1364
1365
1366
1367
1368







-
+

-
+


-
-










-
-
+
+


-
+




-
+







 *  See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadTransferObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    (void)dummy;

    Tcl_ThreadId thrId;
    Tcl_Channel chan;

    Init(interp);

    /*
     * Syntax of 'transfer': id channel
     */

    if (objc != 3) {
        Tcl_WrongNumArgs(interp, 1, objv, "id channel");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "id channel");
	return TCL_ERROR;
    }
    if (ThreadGetId(interp, objv[1], &thrId) != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    chan = Tcl_GetChannel(interp, Tcl_GetString(objv[2]), NULL);
    if (chan == NULL) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    return ThreadTransfer(interp, thrId, Tcl_GetTopChannel(chan));
}

/*
 *----------------------------------------------------------------------
1313
1314
1315
1316
1317
1318
1319
1320

1321
1322

1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336


1337
1338
1339
1340
1341

1342
1343
1344
1345
1346
1347
1348
1379
1380
1381
1382
1383
1384
1385

1386
1387

1388
1389
1390
1391

1392
1393
1394
1395
1396
1397
1398
1399


1400
1401
1402
1403
1404
1405

1406
1407
1408
1409
1410
1411
1412
1413







-
+

-
+



-








-
-
+
+




-
+







 *  See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadDetachObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    Tcl_Channel chan;
    (void)dummy;

    Init(interp);

    /*
     * Syntax: thread::detach channel
     */

    if (objc != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "channel");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "channel");
	return TCL_ERROR;
    }

    chan = Tcl_GetChannel(interp, Tcl_GetString(objv[1]), NULL);
    if (chan == NULL) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    return ThreadDetach(interp, Tcl_GetTopChannel(chan));
}

/*
 *----------------------------------------------------------------------
1359
1360
1361
1362
1363
1364
1365
1366

1367
1368

1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382


1383
1384
1385
1386
1387

1388
1389
1390
1391
1392
1393
1394
1424
1425
1426
1427
1428
1429
1430

1431
1432

1433
1434
1435
1436

1437
1438
1439
1440
1441
1442
1443
1444


1445
1446
1447
1448
1449
1450

1451
1452
1453
1454
1455
1456
1457
1458







-
+

-
+



-








-
-
+
+




-
+







 *  See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadAttachObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    char *chanName;
    (void)dummy;

    Init(interp);

    /*
     * Syntax: thread::attach channel
     */

    if (objc != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "channel");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "channel");
	return TCL_ERROR;
    }

    chanName = Tcl_GetString(objv[1]);
    if (Tcl_IsChannelExisting(chanName)) {
        return TCL_OK;
	return TCL_OK;
    }

    return ThreadAttach(interp, chanName);
}

/*
 *----------------------------------------------------------------------
1405
1406
1407
1408
1409
1410
1411
1412

1413
1414

1415
1416
1417
1418
1419
1420
1421
1422
1423
1424


1425
1426
1427
1428

1429
1430
1431
1432
1433
1434
1435
1469
1470
1471
1472
1473
1474
1475

1476
1477

1478
1479
1480
1481

1482
1483
1484
1485


1486
1487
1488
1489
1490

1491
1492
1493
1494
1495
1496
1497
1498







-
+

-
+



-




-
-
+
+



-
+







 *  See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadExistsObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    Tcl_ThreadId thrId;
    (void)dummy;

    Init(interp);

    if (objc != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "id");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "id");
	return TCL_ERROR;
    }

    if (ThreadGetId(interp, objv[1], &thrId) != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    Tcl_SetIntObj(Tcl_GetObjResult(interp), ThreadExists(thrId)!=0);

    return TCL_OK;
}

1446
1447
1448
1449
1450
1451
1452
1453

1454
1455

1456
1457
1458
1459
1460
1461
1462

1463
1464
1465
1466
1467
1468



1469
1470
1471
1472
1473
1474

1475
1476
1477
1478
1479
1480
1481
1482
1483







1484
1485
1486
1487
1488
1489
1490
1491
1492
1493








1494
1495
1496
1497
1498
1499
1500





1501
1502
1503
1504
1505
1506
1507
1509
1510
1511
1512
1513
1514
1515

1516
1517

1518
1519
1520
1521
1522
1523
1524

1525

1526
1527



1528
1529
1530
1531
1532
1533
1534
1535

1536
1537
1538







1539
1540
1541
1542
1543
1544
1545
1546
1547








1548
1549
1550
1551
1552
1553
1554
1555
1556
1557





1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569







-
+

-
+






-
+
-


-
-
-
+
+
+





-
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+







 *
 * Side effects:
 *  None.
 *----------------------------------------------------------------------
 */
static int
ThreadConfigureObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    char *option, *value;
    Tcl_ThreadId thrId;         /* Id of the thread to configure */
    int i;                      /* Iterate over arg-value pairs. */
    Tcl_DString ds;             /* DString to hold result of
                                 * calling GetThreadOption. */
				 * calling GetThreadOption. */
    (void)dummy;

    if (objc < 2 || (objc % 2 == 1 && objc != 3)) {
        Tcl_WrongNumArgs(interp, 1, objv, "threadlId ?optionName? "
                         "?value? ?optionName value?...");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "threadlId ?optionName? "
		"?value? ?optionName value?...");
	return TCL_ERROR;
    }

    Init(interp);

    if (ThreadGetId(interp, objv[1], &thrId) != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if (objc == 2) {
        Tcl_DStringInit(&ds);
        if (ThreadGetOption(interp, thrId, NULL, &ds) != TCL_OK) {
            Tcl_DStringFree(&ds);
            return TCL_ERROR;
        }
        Tcl_DStringResult(interp, &ds);
        return TCL_OK;
	Tcl_DStringInit(&ds);
	if (ThreadGetOption(interp, thrId, NULL, &ds) != TCL_OK) {
	    Tcl_DStringFree(&ds);
	    return TCL_ERROR;
	}
	Tcl_DStringResult(interp, &ds);
	return TCL_OK;
    }
    if (objc == 3) {
        Tcl_DStringInit(&ds);
        option = Tcl_GetString(objv[2]);
        if (ThreadGetOption(interp, thrId, option, &ds) != TCL_OK) {
            Tcl_DStringFree(&ds);
            return TCL_ERROR;
        }
        Tcl_DStringResult(interp, &ds);
        return TCL_OK;
	Tcl_DStringInit(&ds);
	option = Tcl_GetString(objv[2]);
	if (ThreadGetOption(interp, thrId, option, &ds) != TCL_OK) {
	    Tcl_DStringFree(&ds);
	    return TCL_ERROR;
	}
	Tcl_DStringResult(interp, &ds);
	return TCL_OK;
    }
    for (i = 3; i < objc; i += 2) {
        option = Tcl_GetString(objv[i-1]);
        value  = Tcl_GetString(objv[i]);
        if (ThreadSetOption(interp, thrId, option, value) != TCL_OK) {
            return TCL_ERROR;
        }
	option = Tcl_GetString(objv[i-1]);
	value  = Tcl_GetString(objv[i]);
	if (ThreadSetOption(interp, thrId, option, value) != TCL_OK) {
	    return TCL_ERROR;
	}
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
1518
1519
1520
1521
1522
1523
1524
1525

1526
1527

1528
1529
1530
1531
1532
1533
1534
1535
1536
1537


1538
1539
1540
1541
1542
1543
1544
1545
1546




1547
1548
1549
1550

1551
1552
1553
1554
1555

1556
1557

1558
1559
1560
1561
1562
1563
1564
1580
1581
1582
1583
1584
1585
1586

1587
1588

1589
1590
1591
1592
1593
1594

1595
1596


1597
1598
1599
1600
1601
1602
1603




1604
1605
1606
1607
1608
1609
1610

1611
1612
1613
1614
1615

1616
1617

1618
1619
1620
1621
1622
1623
1624
1625







-
+

-
+





-


-
-
+
+





-
-
-
-
+
+
+
+



-
+




-
+

-
+







 *  See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadCancelObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size    objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    Tcl_ThreadId thrId;
    int ii, flags;
    const char *result;
    (void)dummy;

    if ((objc < 2) || (objc > 4)) {
        Tcl_WrongNumArgs(interp, 1, objv, "?-unwind? id ?result?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "?-unwind? id ?result?");
	return TCL_ERROR;
    }

    flags = 0;
    ii = 1;
    if ((objc == 3) || (objc == 4)) {
        if (OPT_CMP(Tcl_GetString(objv[ii]), "-unwind")) {
            flags |= TCL_CANCEL_UNWIND;
            ii++;
        }
	if (OPT_CMP(Tcl_GetString(objv[ii]), "-unwind")) {
	    flags |= TCL_CANCEL_UNWIND;
	    ii++;
	}
    }

    if (ThreadGetId(interp, objv[ii], &thrId) != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    ii++;
    if (ii < objc) {
        result = Tcl_GetString(objv[ii]);
	result = Tcl_GetString(objv[ii]);
    } else {
        result = NULL;
	result = NULL;
    }

    return ThreadCancel(interp, thrId, result, flags);
}

/*
 *----------------------------------------------------------------------
1579
1580
1581
1582
1583
1584
1585
1586

1587
1588
1589
1590
1591
1592
1593
1640
1641
1642
1643
1644
1645
1646

1647
1648
1649
1650
1651
1652
1653
1654







-
+







ThreadSendEval(
    Tcl_Interp *interp,
    void *clientData
) {
    ThreadSendData *sendPtr = (ThreadSendData *)clientData;
    char *script = (char*)sendPtr->clientData;

    return Tcl_EvalEx(interp, script, TCL_AUTO_LENGTH, TCL_EVAL_GLOBAL);
    return Tcl_EvalEx(interp, script, TCL_INDEX_NONE, TCL_EVAL_GLOBAL);
}

/*
 *----------------------------------------------------------------------
 *
 * ThreadClbkSetVar --
 *
1615
1616
1617
1618
1619
1620
1621




1622


1623
1624
1625
1626
1627
1628
1629
1630
1631



1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651













1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670



1671
1672
1673
1674
1675


1676
1677
1678
1679
1680

1681
1682
1683
1684
1685
1686
1687
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686

1687
1688
1689
1690
1691
1692
1693
1694



1695
1696
1697
1698
1699
1700
1701
1702
1703
1704













1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733



1734
1735
1736
1737
1738
1739


1740
1741
1742
1743
1744
1745

1746
1747
1748
1749
1750
1751
1752
1753







+
+
+
+
-
+
+






-
-
-
+
+
+







-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
















-
-
-
+
+
+



-
-
+
+




-
+







    int rc = TCL_OK;

    /*
     * Get the result of the posted command.
     * We will use it to fill-in the result variable.
     */

    valObj = Tcl_NewStringObj(resultPtr->result, -1);
    Tcl_IncrRefCount(valObj);

    if (resultPtr->result != threadEmptyResult) {
    valObj = resultPtr->result;
	Tcl_Free(resultPtr->result);
    }

    /*
     * Set the result variable
     */

    if (Tcl_ObjSetVar2(interp, var, NULL, valObj,
                      TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG) == NULL) {
        rc = TCL_ERROR;
        goto cleanup;
	    TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG) == NULL) {
	rc = TCL_ERROR;
	goto cleanup;
    }

    /*
     * In case of error, trigger the bgerror mechansim
     */

    if (resultPtr->code == TCL_ERROR) {
        if (resultPtr->errorCode) {
            Tcl_SetVar2Ex(interp, "errorCode", NULL,
                Tcl_NewStringObj(resultPtr->errorCode, -1), TCL_GLOBAL_ONLY);
            Tcl_Free(resultPtr->errorCode);
        }
        if (resultPtr->errorInfo) {
            Tcl_SetVar2Ex(interp, "errorInfo", NULL,
                Tcl_NewStringObj(resultPtr->errorInfo, -1), TCL_GLOBAL_ONLY);
            Tcl_Free(resultPtr->errorInfo);
        }
        Tcl_SetObjResult(interp, valObj);
        Tcl_BackgroundException(interp, TCL_ERROR);
        return TCL_ERROR;
	if (resultPtr->errorCode) {
	    Tcl_SetVar2Ex(interp, "errorCode", NULL,
		Tcl_NewStringObj(resultPtr->errorCode, TCL_INDEX_NONE), TCL_GLOBAL_ONLY);
	    Tcl_Free(resultPtr->errorCode);
	}
	if (resultPtr->errorInfo) {
	    Tcl_SetVar2Ex(interp, "errorInfo", NULL,
		Tcl_NewStringObj(resultPtr->errorInfo, TCL_INDEX_NONE), TCL_GLOBAL_ONLY);
	    Tcl_Free(resultPtr->errorInfo);
	}
	Tcl_SetObjResult(interp, valObj);
	Tcl_BackgroundException(interp, TCL_ERROR);
	return TCL_ERROR;
    }
    return TCL_OK;

cleanup:
    Tcl_DecrRefCount(valObj);
    return rc;
}

static int ThreadClbkCommand(Tcl_Interp *interp, void *clientData)
{
    int status = TCL_OK;
    ThreadClbkData *clbkPtr = (ThreadClbkData*)clientData;
    Tcl_Obj *script = (Tcl_Obj *)clbkPtr->clientData;
    ThreadEventResult *resultPtr = &clbkPtr->result;

    if (resultPtr->code == TCL_ERROR) {
        Tcl_SetObjResult(interp, resultPtr->result);
        Tcl_BackgroundError(interp);
        goto cleanup;
	Tcl_SetObjResult(interp, Tcl_NewStringObj(resultPtr->result, TCL_INDEX_NONE));
	Tcl_BackgroundError(interp);
	goto cleanup;
    }

    if ((status = Tcl_ListObjAppendElement(
        interp, script, resultPtr->result)) != TCL_OK) {
        goto cleanup;
	interp, script, Tcl_NewStringObj(resultPtr->result, TCL_INDEX_NONE))) != TCL_OK) {
	goto cleanup;
    }
    status = Tcl_GlobalEvalObj(interp, script);

cleanup:
    Tcl_DecrRefCount(resultPtr->result);
    Tcl_Free(resultPtr->result);
    return status;
}

/*
 *----------------------------------------------------------------------
 *
 * ThreadCreate --
1699
1700
1701
1702
1703
1704
1705
1706

1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724




1725
1726
1727
1728
1729
1730
1731
1732
1733

1734
1735
1736
1737
1738
1739
1740
1741
1742
1743








1744
1745
1746
1747
1748
1749
1750

1751
1752
1753
1754
1755
1756
1757
1765
1766
1767
1768
1769
1770
1771

1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786




1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798

1799
1800
1801








1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815

1816
1817
1818
1819
1820
1821
1822
1823







-
+














-
-
-
-
+
+
+
+








-
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+






-
+







 *----------------------------------------------------------------------
 */

static int
ThreadCreate(
    Tcl_Interp *interp,        /* Current interpreter. */
    const char *script,        /* Script to evaluate */
    int         stacksize,     /* Zero for default size */
    TCL_HASH_TYPE stacksize,   /* Zero for default size */
    int         flags,         /* Zero for no flags */
    int         preserve       /* If true, reserve the thread */
) {
    char thrHandle[THREAD_HNDLMAXLEN];
    ThreadCtrl ctrl;
    Tcl_ThreadId thrId;

    ctrl.cd = Tcl_GetAssocData(interp, "thread:nsd", NULL);
    ctrl.script   = (char *)script;
    ctrl.condWait = NULL;
    ctrl.flags    = 0;

    Tcl_MutexLock(&threadMutex);
    if (Tcl_CreateThread(&thrId, NewThread, &ctrl,
            stacksize, flags) != TCL_OK) {
        Tcl_MutexUnlock(&threadMutex);
        Tcl_SetObjResult(interp, Tcl_NewStringObj("can't create a new thread", TCL_AUTO_LENGTH));
        return TCL_ERROR;
	    stacksize, flags) != TCL_OK) {
	Tcl_MutexUnlock(&threadMutex);
	Tcl_SetObjResult(interp, Tcl_NewStringObj("can't create a new thread", TCL_INDEX_NONE));
	return TCL_ERROR;
    }

    /*
     * Wait for the thread to start because it is using
     * the ThreadCtrl argument which is on our stack.
     */

    while (ctrl.script != NULL) {
        Tcl_ConditionWait(&ctrl.condWait, &threadMutex, NULL);
	Tcl_ConditionWait(&ctrl.condWait, &threadMutex, NULL);
    }
    if (preserve) {
        ThreadSpecificData *tsdPtr = ThreadExistsInner(thrId);
        if (tsdPtr == NULL) {
            Tcl_MutexUnlock(&threadMutex);
            Tcl_ConditionFinalize(&ctrl.condWait);
            ErrorNoSuchThread(interp, thrId);
            return TCL_ERROR;
        }
        tsdPtr->refCount++;
	ThreadSpecificData *tsdPtr = ThreadExistsInner(thrId);
	if (tsdPtr == NULL) {
	    Tcl_MutexUnlock(&threadMutex);
	    Tcl_ConditionFinalize(&ctrl.condWait);
	    ErrorNoSuchThread(interp, thrId);
	    return TCL_ERROR;
	}
	tsdPtr->refCount++;
    }

    Tcl_MutexUnlock(&threadMutex);
    Tcl_ConditionFinalize(&ctrl.condWait);

    ThreadGetHandle(thrId, thrHandle);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(thrHandle, TCL_AUTO_LENGTH));
    Tcl_SetObjResult(interp, Tcl_NewStringObj(thrHandle, TCL_INDEX_NONE));

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
1844
1845
1846
1847
1848
1849
1850
1851

1852
1853
1854
1855
1856
1857
1858
1859

1860
1861
1862
1863
1864
1865
1866
1910
1911
1912
1913
1914
1915
1916

1917
1918
1919
1920
1921
1922
1923
1924

1925
1926
1927
1928
1929
1930
1931
1932







-
+







-
+







    /*
     * Run the script.
     */

    Tcl_Preserve(tsdPtr->interp);
    result = Tcl_EvalEx(tsdPtr->interp, evalScript,scriptLen,TCL_EVAL_GLOBAL);
    if (result != TCL_OK) {
        ThreadErrorProc(tsdPtr->interp);
	ThreadErrorProc(tsdPtr->interp);
    }

    /*
     * Clean up. Note: add something like TlistRemove for the transfer list.
     */

    if (tsdPtr->doOneEvent) {
        Tcl_ConditionFinalize(&tsdPtr->doOneEvent);
	Tcl_ConditionFinalize(&tsdPtr->doOneEvent);
    }

    ListRemove(tsdPtr);

    /*
     * It is up to all other extensions, including Tk, to be responsible
     * for their own events when they receive their Tcl_CallWhenDeleted
1911
1912
1913
1914
1915
1916
1917
1918

1919
1920
1921
1922
1923

1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936












1937
1938
1939
1940
1941
1942




1943
1944
1945
1946
1947
1948





1949
1950

1951
1952
1953
1954
1955
1956
1957
1977
1978
1979
1980
1981
1982
1983

1984
1985
1986
1987
1988

1989
1990












1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004




2005
2006
2007
2008
2009





2010
2011
2012
2013
2014
2015

2016
2017
2018
2019
2020
2021
2022
2023







-
+




-
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
+







    ThreadSendData *sendPtr;
    const char *argv[3];
    char buf[THREAD_HNDLMAXLEN];
    const char *errorInfo;

    errorInfo = Tcl_GetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY);
    if (errorInfo == NULL) {
        errorInfo = "";
	errorInfo = "";
    }

    if (errorProcString == NULL) {
#ifdef NS_AOLSERVER
        Ns_Log(Error, "%s\n%s", Tcl_GetString(Tcl_GetObjResult(interp)), errorInfo);
	Ns_Log(Error, "%s\n%s", Tcl_GetString(Tcl_GetObjResult(interp)), errorInfo);
#else
        Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR);
        if (errChannel == NULL) {
            /* Fixes the [#634845] bug; credits to
             * Wojciech Kocjan <[email protected]> */
            return;
        }
        ThreadGetHandle(Tcl_GetCurrentThread(), buf);
        Tcl_WriteChars(errChannel, "Error from thread ", TCL_AUTO_LENGTH);
        Tcl_WriteChars(errChannel, buf, TCL_AUTO_LENGTH);
        Tcl_WriteChars(errChannel, "\n", 1);
        Tcl_WriteChars(errChannel, errorInfo, TCL_AUTO_LENGTH);
        Tcl_WriteChars(errChannel, "\n", 1);
	Tcl_Channel errChannel = Tcl_GetStdChannel(TCL_STDERR);
	if (errChannel == NULL) {
	    /* Fixes the [#634845] bug; credits to
	     * Wojciech Kocjan <[email protected]> */
	    return;
	}
	ThreadGetHandle(Tcl_GetCurrentThread(), buf);
	Tcl_WriteChars(errChannel, "Error from thread ", TCL_INDEX_NONE);
	Tcl_WriteChars(errChannel, buf, TCL_INDEX_NONE);
	Tcl_WriteChars(errChannel, "\n", 1);
	Tcl_WriteChars(errChannel, errorInfo, TCL_INDEX_NONE);
	Tcl_WriteChars(errChannel, "\n", 1);
#endif
    } else {
        ThreadGetHandle(Tcl_GetCurrentThread(), buf);
        argv[0] = errorProcString;
        argv[1] = buf;
        argv[2] = errorInfo;
	ThreadGetHandle(Tcl_GetCurrentThread(), buf);
	argv[0] = errorProcString;
	argv[1] = buf;
	argv[2] = errorInfo;

        sendPtr = (ThreadSendData *)Tcl_Alloc(sizeof(ThreadSendData));
        sendPtr->execProc   = ThreadSendEval;
        sendPtr->freeProc   = threadSendFree;
        sendPtr->clientData = Tcl_Merge(3, argv);
        sendPtr->interp     = NULL;
	sendPtr = (ThreadSendData *)Tcl_Alloc(sizeof(ThreadSendData));
	sendPtr->execProc   = ThreadSendEval;
	sendPtr->freeProc   = threadSendFree;
	sendPtr->clientData = Tcl_Merge(3, argv);
	sendPtr->interp     = NULL;

        ThreadSend(interp, errorThreadId, sendPtr, NULL, 0);
	ThreadSend(interp, errorThreadId, sendPtr, NULL, 0);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ListUpdate --
1969
1970
1971
1972
1973
1974
1975
1976

1977
1978
1979
1980
1981
1982
1983
2035
2036
2037
2038
2039
2040
2041

2042
2043
2044
2045
2046
2047
2048
2049







-
+







 */

static void
ListUpdate(
    ThreadSpecificData *tsdPtr
) {
    if (tsdPtr == NULL) {
        tsdPtr = TCL_TSD_INIT(&dataKey);
	tsdPtr = TCL_TSD_INIT(&dataKey);
    }

    Tcl_MutexLock(&threadMutex);
    ListUpdateInner(tsdPtr);
    Tcl_MutexUnlock(&threadMutex);
}

1999
2000
2001
2002
2003
2004
2005
2006

2007
2008
2009
2010
2011
2012
2013
2065
2066
2067
2068
2069
2070
2071

2072
2073
2074
2075
2076
2077
2078
2079







-
+







 */

static void
ListUpdateInner(
    ThreadSpecificData *tsdPtr
) {
    if (threadList) {
        threadList->prevPtr = tsdPtr;
	threadList->prevPtr = tsdPtr;
    }

    tsdPtr->nextPtr  = threadList;
    tsdPtr->prevPtr  = NULL;
    tsdPtr->threadId = Tcl_GetCurrentThread();

    threadList = tsdPtr;
2031
2032
2033
2034
2035
2036
2037
2038

2039
2040
2041
2042
2043
2044
2045
2097
2098
2099
2100
2101
2102
2103

2104
2105
2106
2107
2108
2109
2110
2111







-
+







 */

static void
ListRemove(
    ThreadSpecificData *tsdPtr
) {
    if (tsdPtr == NULL) {
        tsdPtr = TCL_TSD_INIT(&dataKey);
	tsdPtr = TCL_TSD_INIT(&dataKey);
    }

    Tcl_MutexLock(&threadMutex);
    ListRemoveInner(tsdPtr);
    Tcl_MutexUnlock(&threadMutex);
}

2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076










2077
2078

2079
2080
2081
2082
2083
2084
2085
2126
2127
2128
2129
2130
2131
2132










2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143

2144
2145
2146
2147
2148
2149
2150
2151







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
+







 */

static void
ListRemoveInner(
    ThreadSpecificData *tsdPtr
) {
    if (tsdPtr->prevPtr || tsdPtr->nextPtr) {
        if (tsdPtr->prevPtr) {
            tsdPtr->prevPtr->nextPtr = tsdPtr->nextPtr;
        } else {
            threadList = tsdPtr->nextPtr;
        }
        if (tsdPtr->nextPtr) {
            tsdPtr->nextPtr->prevPtr = tsdPtr->prevPtr;
        }
        tsdPtr->nextPtr = NULL;
        tsdPtr->prevPtr = NULL;
	if (tsdPtr->prevPtr) {
	    tsdPtr->prevPtr->nextPtr = tsdPtr->nextPtr;
	} else {
	    threadList = tsdPtr->nextPtr;
	}
	if (tsdPtr->nextPtr) {
	    tsdPtr->nextPtr->prevPtr = tsdPtr->prevPtr;
	}
	tsdPtr->nextPtr = NULL;
	tsdPtr->prevPtr = NULL;
    } else if (tsdPtr == threadList) {
        threadList = NULL;
	threadList = NULL;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ThreadList --
2093
2094
2095
2096
2097
2098
2099
2100

2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116

2117
2118
2119
2120
2121


2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135

2136
2137
2138
2139
2140
2141
2142
2159
2160
2161
2162
2163
2164
2165

2166
2167
2168
2169
2170

2171
2172
2173
2174
2175
2176
2177
2178
2179
2180

2181
2182
2183
2184


2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199

2200
2201
2202
2203
2204
2205
2206
2207







-
+




-










-
+



-
-
+
+













-
+







 *  None.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadList(
    Tcl_Interp *dummy,
    TCL_UNUSED(Tcl_Interp *),
    Tcl_ThreadId **thrIdArray
) {
    int ii, count = 0;
    ThreadSpecificData *tsdPtr;
    (void)dummy;

    Tcl_MutexLock(&threadMutex);

    /*
     * First walk; find out how many threads are registered.
     * We may avoid this and gain some speed by maintaining
     * the counter of allocated structs in the threadList.
     */

    for (tsdPtr = threadList; tsdPtr; tsdPtr = tsdPtr->nextPtr) {
        count++;
	count++;
    }

    if (count == 0) {
        Tcl_MutexUnlock(&threadMutex);
        return 0;
	Tcl_MutexUnlock(&threadMutex);
	return 0;
    }

    /*
     * Allocate storage for passing thread id's to caller
     */

    *thrIdArray = (Tcl_ThreadId *)Tcl_Alloc(count * sizeof(Tcl_ThreadId));

    /*
     * Second walk; fill-in the array with thread ID's
     */

    for (tsdPtr = threadList, ii = 0; tsdPtr; tsdPtr = tsdPtr->nextPtr, ii++) {
        (*thrIdArray)[ii] = tsdPtr->threadId;
	(*thrIdArray)[ii] = tsdPtr->threadId;
    }

    Tcl_MutexUnlock(&threadMutex);

    return count;
}

2191
2192
2193
2194
2195
2196
2197
2198
2199
2200



2201
2202
2203
2204
2205
2206
2207
2256
2257
2258
2259
2260
2261
2262



2263
2264
2265
2266
2267
2268
2269
2270
2271
2272







-
-
-
+
+
+







static ThreadSpecificData *
ThreadExistsInner(
    Tcl_ThreadId thrId              /* Thread id to look for. */
) {
    ThreadSpecificData *tsdPtr;

    for (tsdPtr = threadList; tsdPtr; tsdPtr = tsdPtr->nextPtr) {
        if (tsdPtr->threadId == thrId) {
            return tsdPtr;
        }
	if (tsdPtr->threadId == thrId) {
	    return tsdPtr;
	}
    }

    return NULL;
}

/*
 *----------------------------------------------------------------------
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239



2240
2241
2242
2243

2244
2245
2246
2247
2248
2249
2250
2295
2296
2297
2298
2299
2300
2301



2302
2303
2304
2305
2306
2307

2308
2309
2310
2311
2312
2313
2314
2315







-
-
-
+
+
+



-
+







    Tcl_Obj *resultObj = NULL;
    ThreadSpecificData *tsdPtr; /* ... of the target thread */

    Tcl_MutexLock(&threadMutex);

    tsdPtr = ThreadExistsInner(thrId);
    if (tsdPtr == NULL) {
        Tcl_MutexUnlock(&threadMutex);
        ErrorNoSuchThread(interp, thrId);
        return TCL_ERROR;
	Tcl_MutexUnlock(&threadMutex);
	ErrorNoSuchThread(interp, thrId);
	return TCL_ERROR;
    }

    if (result != NULL) {
        resultObj = Tcl_NewStringObj(result, TCL_AUTO_LENGTH);
	resultObj = Tcl_NewStringObj(result, TCL_INDEX_NONE);
    }

    code = Tcl_CancelEval(tsdPtr->interp, resultObj, NULL, flags);

    Tcl_MutexUnlock(&threadMutex);
    return code;
}
2272
2273
2274
2275
2276
2277
2278
2279

2280
2281
2282
2283



2284
2285
2286
2287
2288
2289
2290
2337
2338
2339
2340
2341
2342
2343

2344
2345



2346
2347
2348
2349
2350
2351
2352
2353
2354
2355







-
+

-
-
-
+
+
+







    Tcl_ThreadId thrId         /* Thread ID of other interpreter. */
) {
    int ret, state;

    ret = Tcl_JoinThread(thrId, &state);

    if (ret == TCL_OK) {
        Tcl_SetIntObj(Tcl_GetObjResult (interp), state);
	Tcl_SetIntObj(Tcl_GetObjResult (interp), state);
    } else {
        char thrHandle[THREAD_HNDLMAXLEN];
        ThreadGetHandle(thrId, thrHandle);
        Tcl_AppendResult(interp, "cannot join thread ", thrHandle, NULL);
	char thrHandle[THREAD_HNDLMAXLEN];
	ThreadGetHandle(thrId, thrHandle);
	Tcl_AppendResult(interp, "cannot join thread ", thrHandle, (void *)NULL);
    }

    return ret;
}

/*
 *----------------------------------------------------------------------
2334
2335
2336
2337
2338
2339
2340
2341

2342
2343
2344
2345


2346
2347
2348
2349
2350
2351
2352
2353

2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365



2366
2367
2368
2369
2370
2371
2372
2399
2400
2401
2402
2403
2404
2405

2406
2407
2408


2409
2410
2411
2412
2413
2414
2415
2416
2417

2418
2419
2420
2421
2422
2423
2424
2425
2426
2427



2428
2429
2430
2431
2432
2433
2434
2435
2436
2437







-
+


-
-
+
+







-
+









-
-
-
+
+
+







     *      transfer. This allows this thread then to proceed.
     */

    TransferEvent *evPtr;
    TransferResult *resultPtr;

    if (!Tcl_IsChannelRegistered(interp, chan)) {
    	Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is not registered here", TCL_AUTO_LENGTH));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is not registered here", TCL_INDEX_NONE));
    }
    if (Tcl_IsChannelShared(chan)) {
    	Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is shared", TCL_AUTO_LENGTH));
        return TCL_ERROR;
	Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is shared", TCL_INDEX_NONE));
	return TCL_ERROR;
    }

    /*
     * Short circuit transfers to ourself.  Nothing to do.
     */

    if (thrId == Tcl_GetCurrentThread()) {
        return TCL_OK;
	return TCL_OK;
    }

    Tcl_MutexLock(&threadMutex);

    /*
     * Verify the thread exists.
     */

    if (ThreadExistsInner(thrId) == NULL) {
        Tcl_MutexUnlock(&threadMutex);
        ErrorNoSuchThread(interp, thrId);
        return TCL_ERROR;
	Tcl_MutexUnlock(&threadMutex);
	ErrorNoSuchThread(interp, thrId);
	return TCL_ERROR;
    }

    /*
     * Cut the channel out of the interp/thread
     */

    ThreadCutChannel(interp, chan);
2400
2401
2402
2403
2404
2405
2406
2407

2408
2409
2410
2411
2412
2413
2414
2415
2416

2417
2418
2419
2420
2421
2422
2423
2465
2466
2467
2468
2469
2470
2471

2472

2473
2474
2475
2476
2477
2478
2479

2480
2481
2482
2483
2484
2485
2486
2487







-
+
-







-
+








    SpliceIn(resultPtr, transferList);

    /*
     * Queue the event and poke the other thread's notifier.
     */

    Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)evPtr, TCL_QUEUE_TAIL);
    Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)evPtr, TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY);
    Tcl_ThreadAlert(thrId);

    /*
     * (*) Block until the other thread has either processed the transfer
     * or rejected it.
     */

    while (resultPtr->resultCode < 0) {
        Tcl_ConditionWait(&resultPtr->done, &threadMutex, NULL);
	Tcl_ConditionWait(&resultPtr->done, &threadMutex, NULL);
    }

    /*
     * Unlink result from the result list.
     */

    SpliceOut(resultPtr, transferList);
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442




2443
2444
2445
2446
2447




2448
2449
2450
2451
2452
2453
2454
2455







2456
2457

2458
2459
2460
2461

2462
2463
2464
2465
2466
2467
2468
2496
2497
2498
2499
2500
2501
2502




2503
2504
2505
2506
2507




2508
2509
2510
2511
2512







2513
2514
2515
2516
2517
2518
2519
2520

2521
2522
2523
2524

2525
2526
2527
2528
2529
2530
2531
2532







-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
+



-
+








    /*
     * Process the result now.
     */

    if (resultPtr->resultCode != TCL_OK) {

        /*
         * Transfer failed, restore old state of channel with respect
         * to current thread and specified interp.
         */
	/*
	 * Transfer failed, restore old state of channel with respect
	 * to current thread and specified interp.
	 */

        Tcl_SpliceChannel(chan);
        Tcl_RegisterChannel(interp, chan);
        Tcl_UnregisterChannel((Tcl_Interp *) NULL, chan);
        Tcl_AppendResult(interp, "transfer failed: ", NULL);
	Tcl_SpliceChannel(chan);
	Tcl_RegisterChannel(interp, chan);
	Tcl_UnregisterChannel((Tcl_Interp *) NULL, chan);
	Tcl_AppendResult(interp, "transfer failed: ", (void *)NULL);

        if (resultPtr->resultMsg) {
            Tcl_AppendResult(interp, resultPtr->resultMsg, NULL);
            Tcl_Free(resultPtr->resultMsg);
        } else {
            Tcl_AppendResult(interp, "for reasons unknown", NULL);
        }
        Tcl_Free(resultPtr);
	if (resultPtr->resultMsg) {
	    Tcl_AppendResult(interp, resultPtr->resultMsg, (void *)NULL);
	    Tcl_Free(resultPtr->resultMsg);
	} else {
	    Tcl_AppendResult(interp, "for reasons unknown", (void *)NULL);
	}
	Tcl_Free(resultPtr);

        return TCL_ERROR;
	return TCL_ERROR;
    }

    if (resultPtr->resultMsg) {
        Tcl_Free(resultPtr->resultMsg);
	Tcl_Free(resultPtr->resultMsg);
    }
    Tcl_Free(resultPtr);

    return TCL_OK;
}

/*
2490
2491
2492
2493
2494
2495
2496
2497

2498
2499
2500
2501


2502
2503
2504
2505
2506
2507
2508
2554
2555
2556
2557
2558
2559
2560

2561
2562
2563


2564
2565
2566
2567
2568
2569
2570
2571
2572







-
+


-
-
+
+







    Tcl_Interp *interp,        /* The current interpreter. */
    Tcl_Channel chan           /* The channel to detach */
) {
    TransferEvent *evPtr;
    TransferResult *resultPtr;

    if (!Tcl_IsChannelRegistered(interp, chan)) {
    	Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is not registered here", TCL_AUTO_LENGTH));
	Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is not registered here", TCL_INDEX_NONE));
    }
    if (Tcl_IsChannelShared(chan)) {
    	Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is shared", TCL_AUTO_LENGTH));
        return TCL_ERROR;
	Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is shared", TCL_INDEX_NONE));
	return TCL_ERROR;
    }

    /*
     * Cut the channel out of the interp/thread
     */

    ThreadCutChannel(interp, chan);
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604














2605
2606
2607
2608
2609
2610


2611
2612
2613
2614
2615
2616
2617
2648
2649
2650
2651
2652
2653
2654














2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672


2673
2674
2675
2676
2677
2678
2679
2680
2681







-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
-
+
+







     * Locate the channel to attach by looking up its name in
     * the list of transfered channels. Watch that we don't
     * hit the regular channel transfer event.
     */

    Tcl_MutexLock(&threadMutex);
    for (resPtr = transferList; resPtr; resPtr = resPtr->nextPtr) {
        chan = resPtr->eventPtr->chan;
        if (!strcmp(Tcl_GetChannelName(chan),chanName)
                && !resPtr->dstThreadId) {
            if (Tcl_IsChannelExisting(chanName)) {
                Tcl_MutexUnlock(&threadMutex);
                Tcl_AppendResult(interp, "channel already exists", NULL);
                return TCL_ERROR;
            }
            SpliceOut(resPtr, transferList);
            Tcl_Free(resPtr->eventPtr);
            Tcl_Free(resPtr);
            found = 1;
            break;
        }
	chan = resPtr->eventPtr->chan;
	if (!strcmp(Tcl_GetChannelName(chan),chanName)
		&& !resPtr->dstThreadId) {
	    if (Tcl_IsChannelExisting(chanName)) {
		Tcl_MutexUnlock(&threadMutex);
		Tcl_AppendResult(interp, "channel already exists", (void *)NULL);
		return TCL_ERROR;
	    }
	    SpliceOut(resPtr, transferList);
	    Tcl_Free(resPtr->eventPtr);
	    Tcl_Free(resPtr);
	    found = 1;
	    break;
	}
    }
    Tcl_MutexUnlock(&threadMutex);

    if (found == 0) {
        Tcl_AppendResult(interp, "channel not detached", NULL);
        return TCL_ERROR;
	Tcl_AppendResult(interp, "channel not detached", (void *)NULL);
	return TCL_ERROR;
    }

    /*
     * Splice channel into the current interpreter
     */

    Tcl_SpliceChannel(chan);
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678













2679
2680
2681
2682
2683
2684
2685
2686

2687
2688
2689

2690
2691
2692
2693
2694
2695

2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714

2715
2716
2717
2718
2719
2720
2721
2722
2723

2724
2725
2726
2727


2728
2729
2730
2731
2732
2733
2734
2735
2736








2737
2738

2739
2740

2741
2742
2743
2744
2745
2746
2747
2748
2749

2750
2751

2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767












2768
2769
2770
2771
2772
2773
2774
2775
2776
2777

2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796








2797
2798
2799
2800

2801
2802
2803
2804
2805
2806

2807


2808
2809
2810
2811
2812
2813
2814
2723
2724
2725
2726
2727
2728
2729













2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749

2750
2751
2752

2753
2754
2755
2756
2757
2758

2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777

2778
2779
2780
2781
2782
2783
2784
2785
2786

2787
2788
2789


2790
2791
2792








2793
2794
2795
2796
2797
2798
2799
2800
2801

2802
2803

2804
2805
2806
2807
2808
2809
2810
2811
2812

2813
2814

2815
2816

2817
2818












2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839

2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851








2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862

2863
2864
2865
2866
2867
2868
2869
2870

2871
2872
2873
2874
2875
2876
2877
2878
2879







-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+


-
+





-
+


















-
+








-
+


-
-
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+

-
+

-
+








-
+

-
+

-


-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+









-
+











-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+



-
+






+
-
+
+







     */

    Tcl_MutexLock(&threadMutex);

    tsdPtr = ThreadExistsInner(thrId);

    if (tsdPtr == NULL
            || (tsdPtr->flags & THREAD_FLAGS_INERROR)) {
        int inerror = tsdPtr && (tsdPtr->flags & THREAD_FLAGS_INERROR);
        Tcl_MutexUnlock(&threadMutex);
        ThreadFreeProc(send);
        if (clbk) {
            ThreadFreeProc(clbk);
        }
        if (inerror) {
        	Tcl_SetObjResult(interp, Tcl_NewStringObj("thread is in error", TCL_AUTO_LENGTH));
        } else {
            ErrorNoSuchThread(interp, thrId);
        }
        return TCL_ERROR;
	    || (tsdPtr->flags & THREAD_FLAGS_INERROR)) {
	int inerror = tsdPtr && (tsdPtr->flags & THREAD_FLAGS_INERROR);
	Tcl_MutexUnlock(&threadMutex);
	ThreadFreeProc(send);
	if (clbk) {
	    ThreadFreeProc(clbk);
	}
	if (inerror) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("thread is in error", TCL_INDEX_NONE));
	} else {
	    ErrorNoSuchThread(interp, thrId);
	}
	return TCL_ERROR;
    }

    /*
     * Short circuit sends to ourself (synchronously only).
     */

    if (thrId == Tcl_GetCurrentThread() && (flags & THREAD_SEND_WAIT)) {
        Tcl_MutexUnlock(&threadMutex);
	Tcl_MutexUnlock(&threadMutex);

	if (!(flags & THREAD_SEND_HEAD)) {
	    /* 
	    /*
	     * Be sure all already queued events are processed before this event
	     */
	    while ( Tcl_DoOneEvent((TCL_ALL_EVENTS & ~TCL_IDLE_EVENTS)|TCL_DONT_WAIT) ) {};
	}
	/* call it synchronously right now */
	int code = (*send->execProc)(interp, send);
	code = (*send->execProc)(interp, send);
	ThreadFreeProc(send);
	return code;
    }

    /*
     * Create the event for target thread event queue.
     */

    eventPtr = (ThreadEvent *)Tcl_Alloc(sizeof(ThreadEvent));
    eventPtr->sendData = send;
    eventPtr->clbkData = clbk;

    /*
     * Target thread about to service
     * another event
     */

    if (tsdPtr->maxEventsCount) {
        tsdPtr->eventsPending++;
	tsdPtr->eventsPending++;
    }

    /*
     * Caller wants to be notified, so we must take care
     * it's interpreter stays alive until we've finished.
     */

    if (eventPtr->clbkData) {
        Tcl_Preserve(eventPtr->clbkData->interp);
	Tcl_Preserve(eventPtr->clbkData->interp);
    }
    if ((flags & THREAD_SEND_WAIT) == 0) {
        resultPtr              = NULL;
        eventPtr->resultPtr    = NULL;
	resultPtr              = NULL;
	eventPtr->resultPtr    = NULL;
    } else {
        resultPtr = (ThreadEventResult *)Tcl_Alloc(sizeof(ThreadEventResult));
        resultPtr->done        = NULL;
        resultPtr->result      = NULL;
        resultPtr->errorCode   = NULL;
        resultPtr->errorInfo   = NULL;
        resultPtr->dstThreadId = thrId;
        resultPtr->srcThreadId = Tcl_GetCurrentThread();
        resultPtr->eventPtr    = eventPtr;
	resultPtr = (ThreadEventResult *)Tcl_Alloc(sizeof(ThreadEventResult));
	resultPtr->done        = NULL;
	resultPtr->result      = NULL;
	resultPtr->errorCode   = NULL;
	resultPtr->errorInfo   = NULL;
	resultPtr->dstThreadId = thrId;
	resultPtr->srcThreadId = Tcl_GetCurrentThread();
	resultPtr->eventPtr    = eventPtr;

        eventPtr->resultPtr    = resultPtr;
	eventPtr->resultPtr    = resultPtr;

        SpliceIn(resultPtr, resultList);
	SpliceIn(resultPtr, resultList);
    }

    /*
     * Queue the event and poke the other thread's notifier.
     */

    eventPtr->event.proc = ThreadEventProc;
    if ((flags & THREAD_SEND_HEAD)) {
        Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)eventPtr, TCL_QUEUE_HEAD);
	Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)eventPtr, TCL_QUEUE_HEAD|TCL_QUEUE_ALERT_IF_EMPTY);
    } else {
        Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)eventPtr, TCL_QUEUE_TAIL);
	Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)eventPtr, TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY);
    }
    Tcl_ThreadAlert(thrId);

    if ((flags & THREAD_SEND_WAIT) == 0) {
        /*
         * Might potentially spend some time here, until the
         * worker thread cleans up its queue a little bit.
         */
        if ((flags & THREAD_SEND_CLBK) == 0) {
            while (tsdPtr->maxEventsCount &&
                   tsdPtr->eventsPending > tsdPtr->maxEventsCount) {
                Tcl_ConditionWait(&tsdPtr->doOneEvent, &threadMutex, NULL);
            }
        }
        Tcl_MutexUnlock(&threadMutex);
        return TCL_OK;
	/*
	 * Might potentially spend some time here, until the
	 * worker thread cleans up its queue a little bit.
	 */
	if ((flags & THREAD_SEND_CLBK) == 0) {
	    while (tsdPtr->maxEventsCount &&
		   tsdPtr->eventsPending > tsdPtr->maxEventsCount) {
		Tcl_ConditionWait(&tsdPtr->doOneEvent, &threadMutex, NULL);
	    }
	}
	Tcl_MutexUnlock(&threadMutex);
	return TCL_OK;
    }

    /*
     * Block on the result indefinitely.
     */

    Tcl_ResetResult(interp);

    while (resultPtr->result == NULL) {
        Tcl_ConditionWait(&resultPtr->done, &threadMutex, NULL);
	Tcl_ConditionWait(&resultPtr->done, &threadMutex, NULL);
    }

    SpliceOut(resultPtr, resultList);

    Tcl_MutexUnlock(&threadMutex);

    /*
     * Return result to caller
     */

    if (resultPtr->code == TCL_ERROR) {
        if (resultPtr->errorCode) {
            Tcl_SetErrorCode(interp, resultPtr->errorCode, NULL);
            Tcl_Free(resultPtr->errorCode);
        }
        if (resultPtr->errorInfo) {
        	Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(resultPtr->errorInfo, TCL_AUTO_LENGTH));
            Tcl_Free(resultPtr->errorInfo);
        }
	if (resultPtr->errorCode) {
	    Tcl_SetErrorCode(interp, resultPtr->errorCode, NULL);
	    Tcl_Free(resultPtr->errorCode);
	}
	if (resultPtr->errorInfo) {
		Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(resultPtr->errorInfo, TCL_INDEX_NONE));
	    Tcl_Free(resultPtr->errorInfo);
	}
    }

    code = resultPtr->code;
    Tcl_SetObjResult(interp, resultPtr->result);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(resultPtr->result, -1));

    /*
     * Cleanup
     */

    Tcl_ConditionFinalize(&resultPtr->done);
    if (resultPtr->result != threadEmptyResult) {
    Tcl_DecrRefCount(resultPtr->result);
	Tcl_Free(resultPtr->result);
    }
    Tcl_Free(resultPtr);

    return code;
}

/*
 *----------------------------------------------------------------------
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846




2847
2848
2849
2850
2851
2852
2853






2854
2855
2856
2857
2858
2859
2860
2861







2862
2863

2864
2865
2866
2867
2868
2869
2870
2871
2872
2873









2874
2875
2876
2877
2878
2879
2880
2881
2882
2883









2884
2885
2886
2887
2888




2889
2890
2891
2892



2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903


2904
2905
2906
2907
2908




2909
2910
2911
2912



2913
2914
2915
2916
2917
2918
2919
2901
2902
2903
2904
2905
2906
2907




2908
2909
2910
2911
2912






2913
2914
2915
2916
2917
2918
2919







2920
2921
2922
2923
2924
2925
2926
2927

2928
2929









2930
2931
2932
2933
2934
2935
2936
2937
2938
2939









2940
2941
2942
2943
2944
2945
2946
2947
2948
2949




2950
2951
2952
2953
2954



2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966


2967
2968
2969




2970
2971
2972
2973
2974



2975
2976
2977
2978
2979
2980
2981
2982
2983
2984







-
-
-
-
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+









-
-
+
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+








    /*
     * Process events until signaled to stop.
     */

    while (canrun) {

        /*
         * About to service another event.
         * Wake-up eventual sleepers.
         */
	/*
	 * About to service another event.
	 * Wake-up eventual sleepers.
	 */

        if (tsdPtr->maxEventsCount) {
            Tcl_MutexLock(&threadMutex);
            tsdPtr->eventsPending--;
            Tcl_ConditionNotify(&tsdPtr->doOneEvent);
            Tcl_MutexUnlock(&threadMutex);
        }
	if (tsdPtr->maxEventsCount) {
	    Tcl_MutexLock(&threadMutex);
	    tsdPtr->eventsPending--;
	    Tcl_ConditionNotify(&tsdPtr->doOneEvent);
	    Tcl_MutexUnlock(&threadMutex);
	}

        /*
         * Attempt to process one event, blocking forever until an
         * event is actually received.  The event processed may cause
         * a script in progress to be canceled or exceed its limit;
         * therefore, check for these conditions if we are able to
         * (i.e. we are running in a high enough version of Tcl).
         */
	/*
	 * Attempt to process one event, blocking forever until an
	 * event is actually received.  The event processed may cause
	 * a script in progress to be canceled or exceed its limit;
	 * therefore, check for these conditions if we are able to
	 * (i.e. we are running in a high enough version of Tcl).
	 */

        Tcl_DoOneEvent(TCL_ALL_EVENTS);
	Tcl_DoOneEvent(TCL_ALL_EVENTS);

        /*
         * If the script has been unwound, bail out immediately. This does
         * not follow the recommended guidelines for how extensions should
         * handle the script cancellation functionality because this is
         * not a "normal" extension. Most extensions do not have a command
         * that simply enters an infinite Tcl event loop. Normal extensions
         * should not specify the TCL_CANCEL_UNWIND when calling the
         * Tcl_Canceled function to check if the command has been canceled.
         */
	/*
	 * If the script has been unwound, bail out immediately. This does
	 * not follow the recommended guidelines for how extensions should
	 * handle the script cancellation functionality because this is
	 * not a "normal" extension. Most extensions do not have a command
	 * that simply enters an infinite Tcl event loop. Normal extensions
	 * should not specify the TCL_CANCEL_UNWIND when calling the
	 * Tcl_Canceled function to check if the command has been canceled.
	 */

        if (Tcl_Canceled(tsdPtr->interp,
                TCL_LEAVE_ERR_MSG | TCL_CANCEL_UNWIND) == TCL_ERROR) {
            code = TCL_ERROR;
            break;
        }
        if (Tcl_LimitExceeded(tsdPtr->interp)) {
            code = TCL_ERROR;
            break;
        }
	if (Tcl_Canceled(tsdPtr->interp,
		TCL_LEAVE_ERR_MSG | TCL_CANCEL_UNWIND) == TCL_ERROR) {
	    code = TCL_ERROR;
	    break;
	}
	if (Tcl_LimitExceeded(tsdPtr->interp)) {
	    code = TCL_ERROR;
	    break;
	}

        /*
         * Test stop condition under mutex since
         * some other thread may flip our flags.
         */
	/*
	 * Test stop condition under mutex since
	 * some other thread may flip our flags.
	 */

        Tcl_MutexLock(&threadMutex);
        canrun = (tsdPtr->flags & THREAD_FLAGS_STOPPED) == 0;
        Tcl_MutexUnlock(&threadMutex);
	Tcl_MutexLock(&threadMutex);
	canrun = (tsdPtr->flags & THREAD_FLAGS_STOPPED) == 0;
	Tcl_MutexUnlock(&threadMutex);
    }

    /*
     * If the event processing loop above was terminated due to a
     * script in progress being canceled or exceeding its limits,
     * transfer the error to the current interpreter.
     */

    if (code != TCL_OK) {
        char buf[THREAD_HNDLMAXLEN];
        const char *errorInfo;
	char buf[THREAD_HNDLMAXLEN];
	const char *errorInfo;

        errorInfo = Tcl_GetVar2(tsdPtr->interp, "errorInfo", NULL, TCL_GLOBAL_ONLY);
        if (errorInfo == NULL) {
            errorInfo = Tcl_GetString(Tcl_GetObjResult(tsdPtr->interp));
        }
	errorInfo = Tcl_GetVar2(tsdPtr->interp, "errorInfo", NULL, TCL_GLOBAL_ONLY);
	if (errorInfo == NULL) {
	    errorInfo = Tcl_GetString(Tcl_GetObjResult(tsdPtr->interp));
	}

        ThreadGetHandle(Tcl_GetCurrentThread(), buf);
        Tcl_AppendResult(interp, "Error from thread ", buf, "\n",
                errorInfo, NULL);
	ThreadGetHandle(Tcl_GetCurrentThread(), buf);
	Tcl_AppendResult(interp, "Error from thread ", buf, "\n",
		errorInfo, (void *)NULL);
    }

    /*
     * Remove from the list of active threads, so nobody can post
     * work to this thread, since it is just about to terminate.
     */

2957
2958
2959
2960
2961
2962
2963
2964

2965
2966
2967
2968
2969
2970
2971






2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985



2986
2987

2988
2989
2990


2991
2992
2993
2994
2995




2996
2997

2998
2999
3000
3001
3002
3003
3004






3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017












3018
3019
3020
3021
3022
3023





3024
3025

3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037












3038
3039
3040
3041
3042
3043
3044
3022
3023
3024
3025
3026
3027
3028

3029
3030






3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047



3048
3049
3050
3051

3052
3053


3054
3055
3056




3057
3058
3059
3060
3061

3062
3063






3064
3065
3066
3067
3068
3069
3070












3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083





3084
3085
3086
3087
3088
3089

3090

3091










3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110







-
+

-
-
-
-
-
-
+
+
+
+
+
+











-
-
-
+
+
+

-
+

-
-
+
+

-
-
-
-
+
+
+
+

-
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
+
-

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+







    Tcl_MutexLock(&threadMutex);

    /*
     * Check the given thread
     */

    if (thrId == NULL) {
        tsdPtr = TCL_TSD_INIT(&dataKey);
	tsdPtr = TCL_TSD_INIT(&dataKey);
    } else {
        tsdPtr = ThreadExistsInner(thrId);
        if (tsdPtr == NULL) {
            Tcl_MutexUnlock(&threadMutex);
            ErrorNoSuchThread(interp, thrId);
            return TCL_ERROR;
        }
	tsdPtr = ThreadExistsInner(thrId);
	if (tsdPtr == NULL) {
	    Tcl_MutexUnlock(&threadMutex);
	    ErrorNoSuchThread(interp, thrId);
	    return TCL_ERROR;
	}
    }

    switch (operation) {
    case THREAD_RESERVE: ++tsdPtr->refCount;                break;
    case THREAD_RELEASE: --tsdPtr->refCount; dowait = wait; break;
    }

    users = tsdPtr->refCount;

    if (users <= 0) {

        /*
         * We're last attached user, so tear down the *target* thread
         */
	/*
	 * We're last attached user, so tear down the *target* thread
	 */

        tsdPtr->flags |= THREAD_FLAGS_STOPPED;
	tsdPtr->flags |= THREAD_FLAGS_STOPPED;

        if (thrId && thrId != Tcl_GetCurrentThread() /* Not current! */) {
            ThreadEventResult *resultPtr = NULL;
	if (thrId && thrId != Tcl_GetCurrentThread() /* Not current! */) {
	    ThreadEventResult *resultPtr = NULL;

            /*
             * Remove from the list of active threads, so nobody can post
             * work to this thread, since it is just about to terminate.
             */
	    /*
	     * Remove from the list of active threads, so nobody can post
	     * work to this thread, since it is just about to terminate.
	     */

            ListRemoveInner(tsdPtr);
	    ListRemoveInner(tsdPtr);

            /*
             * Send an dummy event, just to wake-up target thread.
             * It should immediately exit thereafter. We might get
             * stuck here for long time if user really wants to
             * be absolutely sure that the thread has exited.
             */
	    /*
	     * Send an dummy event, just to wake-up target thread.
	     * It should immediately exit thereafter. We might get
	     * stuck here for long time if user really wants to
	     * be absolutely sure that the thread has exited.
	     */

            if (dowait) {
                resultPtr = (ThreadEventResult*)
                    Tcl_Alloc(sizeof(ThreadEventResult));
                resultPtr->done        = NULL;
                resultPtr->result      = NULL;
                resultPtr->code        = TCL_OK;
                resultPtr->errorCode   = NULL;
                resultPtr->errorInfo   = NULL;
                resultPtr->dstThreadId = thrId;
                resultPtr->srcThreadId = Tcl_GetCurrentThread();
                SpliceIn(resultPtr, resultList);
            }
	    if (dowait) {
		resultPtr = (ThreadEventResult*)
		    Tcl_Alloc(sizeof(ThreadEventResult));
		resultPtr->done        = NULL;
		resultPtr->result      = NULL;
		resultPtr->code        = TCL_OK;
		resultPtr->errorCode   = NULL;
		resultPtr->errorInfo   = NULL;
		resultPtr->dstThreadId = thrId;
		resultPtr->srcThreadId = Tcl_GetCurrentThread();
		SpliceIn(resultPtr, resultList);
	    }

            evPtr = (ThreadEvent *)Tcl_Alloc(sizeof(ThreadEvent));
            evPtr->event.proc = ThreadEventProc;
            evPtr->sendData   = NULL;
            evPtr->clbkData   = NULL;
            evPtr->resultPtr  = resultPtr;
	    evPtr = (ThreadEvent *)Tcl_Alloc(sizeof(ThreadEvent));
	    evPtr->event.proc = ThreadEventProc;
	    evPtr->sendData   = NULL;
	    evPtr->clbkData   = NULL;
	    evPtr->resultPtr  = resultPtr;

            Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)evPtr, TCL_QUEUE_TAIL);
	    Tcl_ThreadQueueEvent(thrId, (Tcl_Event*)evPtr, TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY);
            Tcl_ThreadAlert(thrId);

            if (dowait) {
                while (resultPtr->result == NULL) {
                    Tcl_ConditionWait(&resultPtr->done, &threadMutex, NULL);
                }
                SpliceOut(resultPtr, resultList);
                Tcl_ConditionFinalize(&resultPtr->done);
                Tcl_DecrRefCount(resultPtr->result);
                Tcl_Free(resultPtr);
            }
        }
	    if (dowait) {
		while (resultPtr->result == NULL) {
		    Tcl_ConditionWait(&resultPtr->done, &threadMutex, NULL);
		}
		SpliceOut(resultPtr, resultList);
		Tcl_ConditionFinalize(&resultPtr->done);
		if (resultPtr->result != threadEmptyResult) {
		    Tcl_Free(resultPtr->result); /* Will be ignored anyway */
		}
		Tcl_Free(resultPtr);
	    }
	}
    }

    Tcl_MutexUnlock(&threadMutex);
    Tcl_SetIntObj(Tcl_GetObjResult(interp), (users > 0) ? users : 0);

    return TCL_OK;
}
3057
3058
3059
3060
3061
3062
3063
3064

3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091

3092
3093
3094
3095
3096
3097
3098






3099
3100

3101
3102
3103
3104
3105




3106
3107
3108
3109
3110
3111





3112
3113
3114
3115
3116




3117
3118
3119
3120
3121


3122
3123
3124
3125
3126
3127
3128



3129
3130
3131
3132
3133




3134
3135
3136
3137
3138
3139





3140
3141
3142
3143



3144
3145
3146

3147
3148
3149
3150
3151




3152
3153
3154
3155



3156
3157
3158


3159
3160
3161
3162
3163
3164
3165





3166
3167
3168
3169
3170
3171





3172
3173
3174
3175



3176
3177
3178
3179
3180
3181





3182
3183
3184
3185



3186
3187
3188
3189

3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207








3208
3209
3210
3211
3212
3213
3214
3123
3124
3125
3126
3127
3128
3129

3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141

3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155

3156
3157






3158
3159
3160
3161
3162
3163
3164

3165
3166




3167
3168
3169
3170






3171
3172
3173
3174
3175





3176
3177
3178
3179
3180
3181
3182


3183
3184
3185
3186
3187
3188



3189
3190
3191
3192




3193
3194
3195
3196
3197





3198
3199
3200
3201
3202
3203



3204
3205
3206
3207
3208

3209
3210




3211
3212
3213
3214
3215



3216
3217
3218
3219


3220
3221
3222
3223





3224
3225
3226
3227
3228
3229





3230
3231
3232
3233
3234
3235



3236
3237
3238
3239





3240
3241
3242
3243
3244
3245



3246
3247
3248
3249
3250
3251

3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262








3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277







-
+











-














-
+

-
-
-
-
-
-
+
+
+
+
+
+

-
+

-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+



-
-
+
+




-
-
-
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+


-
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
-
+
+


-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+



-
+










-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







 *  Fills out the ThreadEventResult struct.
 *
 *----------------------------------------------------------------------
 */
static int
ThreadEventProc(
    Tcl_Event *evPtr,          /* Really ThreadEvent */
    int mask
    TCL_UNUSED(int)
) {
    ThreadSpecificData* tsdPtr = TCL_TSD_INIT(&dataKey);

    Tcl_Interp           *interp = NULL;
    Tcl_ThreadId           thrId = Tcl_GetCurrentThread();
    ThreadEvent        *eventPtr = (ThreadEvent*)evPtr;
    ThreadSendData      *sendPtr = eventPtr->sendData;
    ThreadClbkData      *clbkPtr = eventPtr->clbkData;
    ThreadEventResult* resultPtr = eventPtr->resultPtr;

    int code = TCL_ERROR; /* Pessimistic assumption */
    (void)mask;

    /*
     * See whether user has any preferences about which interpreter
     * to use for running this job. The job structure might identify
     * one. If not, just use the thread's main interpreter which is
     * stored in the thread specific data structure.
     * Note that later on we might discover that we're running the
     * async callback script. In this case, interpreter will be
     * changed to one given in the callback.
     */

    interp = (sendPtr && sendPtr->interp) ? sendPtr->interp : tsdPtr->interp;

    if (interp != NULL) {
        Tcl_Preserve(interp);
	Tcl_Preserve(interp);

        if (clbkPtr && clbkPtr->threadId == thrId) {
            Tcl_Release(interp);
            /* Watch: this thread evaluates its own callback. */
            interp = clbkPtr->interp;
            Tcl_Preserve(interp);
        }
	if (clbkPtr && clbkPtr->threadId == thrId) {
	    Tcl_Release(interp);
	    /* Watch: this thread evaluates its own callback. */
	    interp = clbkPtr->interp;
	    Tcl_Preserve(interp);
	}

        Tcl_ResetResult(interp);
	Tcl_ResetResult(interp);

        if (sendPtr) {
            Tcl_CreateThreadExitHandler(ThreadFreeProc, sendPtr);
            if (clbkPtr) {
                Tcl_CreateThreadExitHandler(ThreadFreeProc,
	if (sendPtr) {
	    Tcl_CreateThreadExitHandler(ThreadFreeProc, sendPtr);
	    if (clbkPtr) {
		Tcl_CreateThreadExitHandler(ThreadFreeProc, clbkPtr);
                                            clbkPtr);
            }
            code = (*sendPtr->execProc)(interp, sendPtr);
            Tcl_DeleteThreadExitHandler(ThreadFreeProc, sendPtr);
            if (clbkPtr) {
                Tcl_DeleteThreadExitHandler(ThreadFreeProc,
	    }
	    code = (*sendPtr->execProc)(interp, sendPtr);
	    Tcl_DeleteThreadExitHandler(ThreadFreeProc, sendPtr);
	    if (clbkPtr) {
		Tcl_DeleteThreadExitHandler(ThreadFreeProc, clbkPtr);
                                            clbkPtr);
            }
        } else {
            code = TCL_OK;
        }
	    }
	} else {
	    code = TCL_OK;
	}
    }

    if (sendPtr) {
        ThreadFreeProc(sendPtr);
        eventPtr->sendData = NULL;
	ThreadFreeProc(sendPtr);
	eventPtr->sendData = NULL;
    }

    if (resultPtr) {

        /*
         * Report job result synchronously to waiting caller
         */
	/*
	 * Report job result synchronously to waiting caller
	 */

        Tcl_MutexLock(&threadMutex);
        ThreadSetResult(interp, code, resultPtr);
        Tcl_ConditionNotify(&resultPtr->done);
        Tcl_MutexUnlock(&threadMutex);
	Tcl_MutexLock(&threadMutex);
	ThreadSetResult(interp, code, resultPtr);
	Tcl_ConditionNotify(&resultPtr->done);
	Tcl_MutexUnlock(&threadMutex);

        /*
         * We still need to release the reference to the Tcl
         * interpreter added by ThreadSend whenever the callback
         * data is not NULL.
         */
	/*
	 * We still need to release the reference to the Tcl
	 * interpreter added by ThreadSend whenever the callback
	 * data is not NULL.
	 */

        if (clbkPtr) {
            Tcl_Release(clbkPtr->interp);
        }
	if (clbkPtr) {
	    Tcl_Release(clbkPtr->interp);
	}
    } else if (clbkPtr && clbkPtr->threadId != thrId) {

        ThreadSendData *tmpPtr = (ThreadSendData*)clbkPtr;
	ThreadSendData *tmpPtr = (ThreadSendData*)clbkPtr;

        /*
         * Route the callback back to it's originator.
         * Do not wait for the result.
         */
	/*
	 * Route the callback back to it's originator.
	 * Do not wait for the result.
	 */

        if (code != TCL_OK) {
            ThreadErrorProc(interp);
        }
	if (code != TCL_OK) {
	    ThreadErrorProc(interp);
	}

        ThreadSetResult(interp, code, &clbkPtr->result);
        ThreadSend(interp, clbkPtr->threadId, tmpPtr, NULL, THREAD_SEND_CLBK);
	ThreadSetResult(interp, code, &clbkPtr->result);
	ThreadSend(interp, clbkPtr->threadId, tmpPtr, NULL, THREAD_SEND_CLBK);

    } else if (code != TCL_OK) {
        /*
         * Only pass errors onto the registered error handler
         * when we don't have a result target for this event.
         */
        ThreadErrorProc(interp);
	/*
	 * Only pass errors onto the registered error handler
	 * when we don't have a result target for this event.
	 */
	ThreadErrorProc(interp);

        /*
         * We still need to release the reference to the Tcl
         * interpreter added by ThreadSend whenever the callback
         * data is not NULL.
         */
	/*
	 * We still need to release the reference to the Tcl
	 * interpreter added by ThreadSend whenever the callback
	 * data is not NULL.
	 */

        if (clbkPtr) {
            Tcl_Release(clbkPtr->interp);
        }
	if (clbkPtr) {
	    Tcl_Release(clbkPtr->interp);
	}
    } else {
        /*
         * We still need to release the reference to the Tcl
         * interpreter added by ThreadSend whenever the callback
         * data is not NULL.
         */
	/*
	 * We still need to release the reference to the Tcl
	 * interpreter added by ThreadSend whenever the callback
	 * data is not NULL.
	 */

        if (clbkPtr) {
            Tcl_Release(clbkPtr->interp);
        }
	if (clbkPtr) {
	    Tcl_Release(clbkPtr->interp);
	}
    }

    if (interp != NULL) {
        Tcl_Release(interp);
	Tcl_Release(interp);
    }

    /*
     * Mark unwind scenario for this thread if the script resulted
     * in error condition and thread has been marked to unwind.
     * This will cause thread to disappear from the list of active
     * threads, clean-up its event queue and exit.
     */

    if (code != TCL_OK) {
        Tcl_MutexLock(&threadMutex);
        if (tsdPtr->flags & THREAD_FLAGS_UNWINDONERROR) {
            tsdPtr->flags |= THREAD_FLAGS_INERROR;
            if (tsdPtr->refCount == 0) {
                tsdPtr->flags |= THREAD_FLAGS_STOPPED;
            }
        }
        Tcl_MutexUnlock(&threadMutex);
	Tcl_MutexLock(&threadMutex);
	if (tsdPtr->flags & THREAD_FLAGS_UNWINDONERROR) {
	    tsdPtr->flags |= THREAD_FLAGS_INERROR;
	    if (tsdPtr->refCount == 0) {
		tsdPtr->flags |= THREAD_FLAGS_STOPPED;
	    }
	}
	Tcl_MutexUnlock(&threadMutex);
    }

    return 1;
}

/*
 *----------------------------------------------------------------------
3224
3225
3226
3227
3228
3229
3230
3231

3232
3233
3234
3235
3236
3237
3238







3239


3240
3241
3242
3243
3244
3245
3246
3247









3248
3249
3250
3251
3252
3253
3254
3255


3256
3257

3258
3259
3260
3261


3262
3263

3264
3265
3266
3267
3268
3269
3270
3287
3288
3289
3290
3291
3292
3293

3294
3295
3296
3297




3298
3299
3300
3301
3302
3303
3304
3305
3306
3307








3308
3309
3310
3311
3312
3313
3314
3315
3316
3317

3318
3319
3320
3321


3322
3323
3324

3325
3326
3327


3328
3329
3330

3331
3332
3333
3334
3335
3336
3337
3338







-
+



-
-
-
-
+
+
+
+
+
+
+

+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-




-
-
+
+

-
+


-
-
+
+

-
+








static void
ThreadSetResult(
    Tcl_Interp *interp,
    int code,
    ThreadEventResult *resultPtr
) {
    const char *errorCode, *errorInfo;
    const char *errorCode, *errorInfo, *result;
    size_t size;

    if (interp == NULL) {
        code      = TCL_ERROR;
        errorInfo = "";
        errorCode = "THREAD";
        resultPtr->result = Tcl_NewStringObj("no target interp", -1);
	code      = TCL_ERROR;
	errorInfo = "";
	errorCode = "THREAD";
	result    = "no target interp!";
	size    = strlen(result);
	resultPtr->result = (size) ?
	    memcpy(Tcl_Alloc(1+size), result, 1+size) : threadEmptyResult;
    } else {
	result = Tcl_GetString(Tcl_GetObjResult(interp));
	size = Tcl_GetObjResult(interp)->length;
        resultPtr->result = Sv_DuplicateObj(Tcl_GetObjResult(interp));
        if (code == TCL_ERROR) {
            errorCode = Tcl_GetVar2(interp, "errorCode", NULL, TCL_GLOBAL_ONLY);
            errorInfo = Tcl_GetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY);
        } else {
            errorCode = NULL;
            errorInfo = NULL;
        }
	resultPtr->result = (size) ?
		memcpy(Tcl_Alloc(1+size), result, 1+size) : threadEmptyResult;
	if (code == TCL_ERROR) {
	    errorCode = Tcl_GetVar2(interp, "errorCode", NULL, TCL_GLOBAL_ONLY);
	    errorInfo = Tcl_GetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY);
	} else {
	    errorCode = NULL;
	    errorInfo = NULL;
	}
    }
    Tcl_IncrRefCount(resultPtr->result);

    resultPtr->code = code;

    if (errorCode != NULL) {
        size = strlen(errorCode) + 1;
        resultPtr->errorCode = (char *)memcpy(Tcl_Alloc(size), errorCode, size);
	size = strlen(errorCode) + 1;
	resultPtr->errorCode = (char *)memcpy(Tcl_Alloc(size), errorCode, size);
    } else {
        resultPtr->errorCode = NULL;
	resultPtr->errorCode = NULL;
    }
    if (errorInfo != NULL) {
        size = strlen(errorInfo) + 1;
        resultPtr->errorInfo = (char *)memcpy(Tcl_Alloc(size), errorInfo, size);
	size = strlen(errorInfo) + 1;
	resultPtr->errorInfo = (char *)memcpy(Tcl_Alloc(size), errorInfo, size);
    } else {
        resultPtr->errorInfo = NULL;
	resultPtr->errorInfo = NULL;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ThreadGetOption --
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303



3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317











3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330










3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343










3344
3345
3346
3347
3348
3349
3350
3351





3352
3353
3354
3355
3356
3357
3358
3362
3363
3364
3365
3366
3367
3368



3369
3370
3371
3372
3373
3374











3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388










3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401










3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414





3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426







-
-
-
+
+
+



-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
+
+
+
+
+







    len = (option == NULL) ? 0 : strlen(option);

    Tcl_MutexLock(&threadMutex);

    tsdPtr = ThreadExistsInner(thrId);

    if (tsdPtr == NULL) {
        Tcl_MutexUnlock(&threadMutex);
        ErrorNoSuchThread(interp, thrId);
        return TCL_ERROR;
	Tcl_MutexUnlock(&threadMutex);
	ErrorNoSuchThread(interp, thrId);
	return TCL_ERROR;
    }

    if (len == 0 || (len > 3 && option[1] == 'e' && option[2] == 'v'
                     && !strncmp(option,"-eventmark", len))) {
        char buf[16];
        if (len == 0) {
            Tcl_DStringAppendElement(dsPtr, "-eventmark");
        }
        sprintf(buf, "%d", tsdPtr->maxEventsCount);
        Tcl_DStringAppendElement(dsPtr, buf);
        if (len != 0) {
            Tcl_MutexUnlock(&threadMutex);
            return TCL_OK;
        }
	    && !strncmp(option,"-eventmark", len))) {
	char buf[16];
	if (len == 0) {
	    Tcl_DStringAppendElement(dsPtr, "-eventmark");
	}
	snprintf(buf, sizeof(buf), "%d", tsdPtr->maxEventsCount);
	Tcl_DStringAppendElement(dsPtr, buf);
	if (len != 0) {
	    Tcl_MutexUnlock(&threadMutex);
	    return TCL_OK;
	}
    }

    if (len == 0 || (len > 2 && option[1] == 'u'
                     && !strncmp(option,"-unwindonerror", len))) {
        int flag = tsdPtr->flags & THREAD_FLAGS_UNWINDONERROR;
        if (len == 0) {
            Tcl_DStringAppendElement(dsPtr, "-unwindonerror");
        }
        Tcl_DStringAppendElement(dsPtr, flag ? "1" : "0");
        if (len != 0) {
            Tcl_MutexUnlock(&threadMutex);
            return TCL_OK;
        }
	    && !strncmp(option,"-unwindonerror", len))) {
	int flag = tsdPtr->flags & THREAD_FLAGS_UNWINDONERROR;
	if (len == 0) {
	    Tcl_DStringAppendElement(dsPtr, "-unwindonerror");
	}
	Tcl_DStringAppendElement(dsPtr, flag ? "1" : "0");
	if (len != 0) {
	    Tcl_MutexUnlock(&threadMutex);
	    return TCL_OK;
	}
    }

    if (len == 0 || (len > 3 && option[1] == 'e' && option[2] == 'r'
                     && !strncmp(option,"-errorstate", len))) {
        int flag = tsdPtr->flags & THREAD_FLAGS_INERROR;
        if (len == 0) {
            Tcl_DStringAppendElement(dsPtr, "-errorstate");
        }
        Tcl_DStringAppendElement(dsPtr, flag ? "1" : "0");
        if (len != 0) {
            Tcl_MutexUnlock(&threadMutex);
            return TCL_OK;
        }
	    && !strncmp(option,"-errorstate", len))) {
	int flag = tsdPtr->flags & THREAD_FLAGS_INERROR;
	if (len == 0) {
	    Tcl_DStringAppendElement(dsPtr, "-errorstate");
	}
	Tcl_DStringAppendElement(dsPtr, flag ? "1" : "0");
	if (len != 0) {
	    Tcl_MutexUnlock(&threadMutex);
	    return TCL_OK;
	}
    }

    if (len != 0) {
        Tcl_AppendResult(interp, "bad option \"", option,
                         "\", should be one of -eventmark, "
                         "-unwindonerror or -errorstate", NULL);
        Tcl_MutexUnlock(&threadMutex);
        return TCL_ERROR;
	Tcl_AppendResult(interp, "bad option \"", option,
			 "\", should be one of -eventmark, "
			 "-unwindonerror or -errorstate", (void *)NULL);
	Tcl_MutexUnlock(&threadMutex);
	return TCL_ERROR;
    }

    Tcl_MutexUnlock(&threadMutex);

    return TCL_OK;
}

3379
3380
3381
3382
3383
3384
3385
3386
3387
3388



3389
3390
3391
3392
3393
3394
3395
3396
3397







3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409











3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421











3422
3423
3424
3425
3426
3427
3428
3447
3448
3449
3450
3451
3452
3453



3454
3455
3456
3457
3458







3459
3460
3461
3462
3463
3464
3465
3466











3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478











3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496







-
-
-
+
+
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







    ThreadSpecificData *tsdPtr = NULL;

    Tcl_MutexLock(&threadMutex);

    tsdPtr = ThreadExistsInner(thrId);

    if (tsdPtr == NULL) {
        Tcl_MutexUnlock(&threadMutex);
        ErrorNoSuchThread(interp, thrId);
        return TCL_ERROR;
	Tcl_MutexUnlock(&threadMutex);
	ErrorNoSuchThread(interp, thrId);
	return TCL_ERROR;
    }
    if (len > 3 && option[1] == 'e' && option[2] == 'v'
        && !strncmp(option,"-eventmark", len)) {
        if (sscanf(value, "%d", &tsdPtr->maxEventsCount) != 1) {
            Tcl_AppendResult(interp, "expected integer but got \"",
                             value, "\"", NULL);
            Tcl_MutexUnlock(&threadMutex);
            return TCL_ERROR;
        }
	&& !strncmp(option,"-eventmark", len)) {
	if (sscanf(value, "%d", &tsdPtr->maxEventsCount) != 1) {
	    Tcl_AppendResult(interp, "expected integer but got \"",
			     value, "\"", (void *)NULL);
	    Tcl_MutexUnlock(&threadMutex);
	    return TCL_ERROR;
	}
    } else if (len > 2 && option[1] == 'u'
               && !strncmp(option,"-unwindonerror", len)) {
        int flag = 0;
        if (Tcl_GetBoolean(interp, value, &flag) != TCL_OK) {
            Tcl_MutexUnlock(&threadMutex);
            return TCL_ERROR;
        }
        if (flag) {
            tsdPtr->flags |=  THREAD_FLAGS_UNWINDONERROR;
        } else {
            tsdPtr->flags &= ~THREAD_FLAGS_UNWINDONERROR;
        }
	       && !strncmp(option,"-unwindonerror", len)) {
	int flag = 0;
	if (Tcl_GetBoolean(interp, value, &flag) != TCL_OK) {
	    Tcl_MutexUnlock(&threadMutex);
	    return TCL_ERROR;
	}
	if (flag) {
	    tsdPtr->flags |=  THREAD_FLAGS_UNWINDONERROR;
	} else {
	    tsdPtr->flags &= ~THREAD_FLAGS_UNWINDONERROR;
	}
    } else if (len > 3 && option[1] == 'e' && option[2] == 'r'
               && !strncmp(option,"-errorstate", len)) {
        int flag = 0;
        if (Tcl_GetBoolean(interp, value, &flag) != TCL_OK) {
            Tcl_MutexUnlock(&threadMutex);
            return TCL_ERROR;
        }
        if (flag) {
            tsdPtr->flags |=  THREAD_FLAGS_INERROR;
        } else {
            tsdPtr->flags &= ~THREAD_FLAGS_INERROR;
        }
	       && !strncmp(option,"-errorstate", len)) {
	int flag = 0;
	if (Tcl_GetBoolean(interp, value, &flag) != TCL_OK) {
	    Tcl_MutexUnlock(&threadMutex);
	    return TCL_ERROR;
	}
	if (flag) {
	    tsdPtr->flags |=  THREAD_FLAGS_INERROR;
	} else {
	    tsdPtr->flags &= ~THREAD_FLAGS_INERROR;
	}
    }

    Tcl_MutexUnlock(&threadMutex);

    return TCL_OK;
}

3441
3442
3443
3444
3445
3446
3447
3448

3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463





3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
















3481
3482
3483
3484
3485
3486
3487
3488
3489
3490








3491
3492
3493
3494
3495
3496
3497
3509
3510
3511
3512
3513
3514
3515

3516
3517
3518
3519
3520
3521
3522
3523

3524
3525





3526
3527
3528
3529
3530
3531
















3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549








3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564







-
+







-


-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







 *
 *----------------------------------------------------------------------
 */

static int
TransferEventProc(
    Tcl_Event *evPtr,          /* Really ThreadEvent */
    int mask
    TCL_UNUSED(int)
) {
    ThreadSpecificData    *tsdPtr = TCL_TSD_INIT(&dataKey);
    TransferEvent       *eventPtr = (TransferEvent *)evPtr;
    TransferResult     *resultPtr = eventPtr->resultPtr;
    Tcl_Interp            *interp = tsdPtr->interp;
    int code;
    const char* msg = NULL;
    (void)mask;

    if (interp == NULL) {
        /*
         * Reject transfer in case of a missing target.
         */
        code = TCL_ERROR;
        msg  = "target interp missing";
	/*
	 * Reject transfer in case of a missing target.
	 */
	code = TCL_ERROR;
	msg  = "target interp missing";
    } else {
        /*
         * Add channel to current thread and interp.
         * See ThreadTransfer for more explanations.
         */
        if (Tcl_IsChannelExisting(Tcl_GetChannelName(eventPtr->chan))) {
            /*
             * Reject transfer. Channel of same name already exists in target.
             */
            code = TCL_ERROR;
            msg  = "channel already exists in target";
        } else {
            Tcl_SpliceChannel(eventPtr->chan);
            Tcl_RegisterChannel(interp, eventPtr->chan);
            Tcl_UnregisterChannel((Tcl_Interp *) NULL, eventPtr->chan);
            code = TCL_OK; /* Return success. */
        }
	/*
	 * Add channel to current thread and interp.
	 * See ThreadTransfer for more explanations.
	 */
	if (Tcl_IsChannelExisting(Tcl_GetChannelName(eventPtr->chan))) {
	    /*
	     * Reject transfer. Channel of same name already exists in target.
	     */
	    code = TCL_ERROR;
	    msg  = "channel already exists in target";
	} else {
	    Tcl_SpliceChannel(eventPtr->chan);
	    Tcl_RegisterChannel(interp, eventPtr->chan);
	    Tcl_UnregisterChannel((Tcl_Interp *) NULL, eventPtr->chan);
	    code = TCL_OK; /* Return success. */
	}
    }
    if (resultPtr) {
        Tcl_MutexLock(&threadMutex);
        resultPtr->resultCode = code;
        if (msg != NULL) {
            size_t size = strlen(msg)+1;
            resultPtr->resultMsg = (char *)memcpy(Tcl_Alloc(size), msg, size);
        }
        Tcl_ConditionNotify(&resultPtr->done);
        Tcl_MutexUnlock(&threadMutex);
	Tcl_MutexLock(&threadMutex);
	resultPtr->resultCode = code;
	if (msg != NULL) {
	    size_t size = strlen(msg)+1;
	    resultPtr->resultMsg = (char *)memcpy(Tcl_Alloc(size), msg, size);
	}
	Tcl_ConditionNotify(&resultPtr->done);
	Tcl_MutexUnlock(&threadMutex);
    }

    return 1;
}

/*
 *----------------------------------------------------------------------
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526




3527
3528
3529
3530
3531
3532
3533
3583
3584
3585
3586
3587
3588
3589




3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600







-
-
-
-
+
+
+
+







     * This will free send and/or callback structures
     * since both are the same in the beginning.
     */

    ThreadSendData *anyPtr = (ThreadSendData *)clientData;

    if (anyPtr) {
        if (anyPtr->clientData) {
            (*anyPtr->freeProc)(anyPtr->clientData);
        }
        Tcl_Free(anyPtr);
	if (anyPtr->clientData) {
	    (*anyPtr->freeProc)(anyPtr->clientData);
	}
	Tcl_Free(anyPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ThreadDeleteEvent --
3542
3543
3544
3545
3546
3547
3548
3549

3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566













3567
3568
3569
3570
3571
3572
3573
3574






3575
3576
3577
3578
3579
3580
3581






3582
3583
3584
3585
3586




3587
3588
3589


3590
3591

3592
3593
3594
3595
3596
3597
3598
3609
3610
3611
3612
3613
3614
3615

3616
3617


3618













3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633






3634
3635
3636
3637
3638
3639
3640






3641
3642
3643
3644
3645
3646
3647




3648
3649
3650
3651
3652


3653
3654
3655

3656
3657
3658
3659
3660
3661
3662
3663







-
+

-
-

-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
+
+

-
+







 *  It cleans up our events in the event queue for this thread.
 *
 *----------------------------------------------------------------------
 */
static int
ThreadDeleteEvent(
    Tcl_Event *eventPtr,       /* Really ThreadEvent */
    void *dummy           /* dummy */
    TCL_UNUSED(void *)         /* dummy */
) {
    (void)dummy;

    if (eventPtr->proc == ThreadEventProc) {
        /*
         * Regular script event. Just dispose memory
         */
        ThreadEvent *evPtr = (ThreadEvent*)eventPtr;
        if (evPtr->sendData) {
            ThreadFreeProc(evPtr->sendData);
            evPtr->sendData = NULL;
        }
        if (evPtr->clbkData) {
            ThreadFreeProc(evPtr->clbkData);
            evPtr->clbkData = NULL;
        }
        return 1;
	/*
	 * Regular script event. Just dispose memory
	 */
	ThreadEvent *evPtr = (ThreadEvent*)eventPtr;
	if (evPtr->sendData) {
	    ThreadFreeProc(evPtr->sendData);
	    evPtr->sendData = NULL;
	}
	if (evPtr->clbkData) {
	    ThreadFreeProc(evPtr->clbkData);
	    evPtr->clbkData = NULL;
	}
	return 1;
    }
    if (eventPtr->proc == TransferEventProc) {
        /*
         * A channel is in flight toward the thread just exiting.
         * Pass it back to the originator, if possible.
         * Else kill it.
         */
        TransferEvent* evPtr = (TransferEvent *) eventPtr;
	/*
	 * A channel is in flight toward the thread just exiting.
	 * Pass it back to the originator, if possible.
	 * Else kill it.
	 */
	TransferEvent* evPtr = (TransferEvent *) eventPtr;

        if (evPtr->resultPtr == (TransferResult *) NULL) {
            /* No thread to pass the channel back to. Kill it.
             * This requires to splice it temporarily into our channel
             * list and then forcing the ref.counter down to the real
             * value of zero. This destroys the channel.
             */
	if (evPtr->resultPtr == (TransferResult *) NULL) {
	    /* No thread to pass the channel back to. Kill it.
	     * This requires to splice it temporarily into our channel
	     * list and then forcing the ref.counter down to the real
	     * value of zero. This destroys the channel.
	     */

            Tcl_SpliceChannel(evPtr->chan);
            Tcl_UnregisterChannel((Tcl_Interp *) NULL, evPtr->chan);
            return 1;
        }
	    Tcl_SpliceChannel(evPtr->chan);
	    Tcl_UnregisterChannel((Tcl_Interp *) NULL, evPtr->chan);
	    return 1;
	}

        /* Our caller (ThreadExitProc) will pass the channel back.
         */
	/* Our caller (ThreadExitProc) will pass the channel back.
	 */

        return 1;
	return 1;
    }

    /*
     * If it was NULL, we were in the middle of servicing the event
     * and it should be removed
     */

3624
3625
3626
3627
3628
3629
3630
3631

3632
3633
3634
3635
3636
3637
3638
3689
3690
3691
3692
3693
3694
3695

3696
3697
3698
3699
3700
3701
3702
3703







-
+







    ThreadEventResult *resultPtr, *nextPtr;
    Tcl_ThreadId self = Tcl_GetCurrentThread();
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);

    TransferResult *tResultPtr, *tNextPtr;

    if (threadEvalScript && threadEvalScript != threadEmptyResult) {
        Tcl_Free(threadEvalScript);
	Tcl_Free(threadEvalScript);
    }

    Tcl_MutexLock(&threadMutex);

    /*
     * NaviServer/AOLserver and threadpool threads get started/stopped
     * out of the control of this interface so this is
3655
3656
3657
3658
3659
3660
3661
3662
3663


3664
3665
3666
3667
3668




3669
3670
3671


3672
3673

3674
3675
3676
3677
3678
3679





3680
3681

3682
3683
3684
3685
3686




3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697









3698
3699
3700


3701
3702
3703
3704
3705
3706
3707






3708
3709
3710
3711
3712
3713





3714
3715
3716
3717
3718
3719
3720
3720
3721
3722
3723
3724
3725
3726


3727
3728
3729




3730
3731
3732
3733
3734


3735
3736
3737

3738
3739





3740
3741
3742
3743
3744
3745

3746





3747
3748
3749
3750
3751
3752









3753
3754
3755
3756
3757
3758
3759
3760
3761
3762


3763
3764
3765






3766
3767
3768
3769
3770
3771
3772





3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784







-
-
+
+

-
-
-
-
+
+
+
+

-
-
+
+

-
+

-
-
-
-
-
+
+
+
+
+

-
+
-
-
-
-
-
+
+
+
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+








    /*
     * Walk the list of threads waiting for result from us
     * and inform them that we're about to exit.
     */

    for (resultPtr = resultList; resultPtr; resultPtr = nextPtr) {
        nextPtr = resultPtr->nextPtr;
        if (resultPtr->srcThreadId == self) {
	nextPtr = resultPtr->nextPtr;
	if (resultPtr->srcThreadId == self) {

            /*
             * We are going away. By freeing up the result we signal
             * to the other thread we don't care about the result.
             */
	    /*
	     * We are going away. By freeing up the result we signal
	     * to the other thread we don't care about the result.
	     */

            SpliceOut(resultPtr, resultList);
            Tcl_Free(resultPtr);
	    SpliceOut(resultPtr, resultList);
	    Tcl_Free(resultPtr);

        } else if (resultPtr->dstThreadId == self) {
	} else if (resultPtr->dstThreadId == self) {

            /*
             * Dang. The target is going away. Unblock the caller.
             * The result string must be dynamically allocated
             * because the main thread is going to call free on it.
             */
	    /*
	     * Dang. The target is going away. Unblock the caller.
	     * The result string must be dynamically allocated
	     * because the main thread is going to call free on it.
	     */

            resultPtr->result = Tcl_NewStringObj(diemsg, -1);
	    resultPtr->result = strcpy(Tcl_Alloc(1+strlen(diemsg)), diemsg);
            Tcl_IncrRefCount(resultPtr->result);
            resultPtr->code = TCL_ERROR;
            resultPtr->errorCode = resultPtr->errorInfo = NULL;
            Tcl_ConditionNotify(&resultPtr->done);
        }
	    resultPtr->code = TCL_ERROR;
	    resultPtr->errorCode = resultPtr->errorInfo = NULL;
	    Tcl_ConditionNotify(&resultPtr->done);
	}
    }
    for (tResultPtr = transferList; tResultPtr; tResultPtr = tNextPtr) {
        tNextPtr = tResultPtr->nextPtr;
        if (tResultPtr->srcThreadId == self) {
            /*
             * We are going away. By freeing up the result we signal
             * to the other thread we don't care about the result.
             *
             * This should not happen, as this thread should be in
             * ThreadTransfer at location (*).
             */
	tNextPtr = tResultPtr->nextPtr;
	if (tResultPtr->srcThreadId == self) {
	    /*
	     * We are going away. By freeing up the result we signal
	     * to the other thread we don't care about the result.
	     *
	     * This should not happen, as this thread should be in
	     * ThreadTransfer at location (*).
	     */

            SpliceOut(tResultPtr, transferList);
            Tcl_Free(tResultPtr);
	    SpliceOut(tResultPtr, transferList);
	    Tcl_Free(tResultPtr);

        } else if (tResultPtr->dstThreadId == self) {
            /*
             * Dang. The target is going away. Unblock the caller.
             * The result string must be dynamically allocated
             * because the main thread is going to call free on it.
             */
	} else if (tResultPtr->dstThreadId == self) {
	    /*
	     * Dang. The target is going away. Unblock the caller.
	     * The result string must be dynamically allocated
	     * because the main thread is going to call free on it.
	     */

            tResultPtr->resultMsg = strcpy((char *)Tcl_Alloc(1+strlen(diemsg)),
                                           diemsg);
            tResultPtr->resultCode = TCL_ERROR;
            Tcl_ConditionNotify(&tResultPtr->done);
        }
	    tResultPtr->resultMsg = strcpy((char *)Tcl_Alloc(1+strlen(diemsg)),
					   diemsg);
	    tResultPtr->resultCode = TCL_ERROR;
	    Tcl_ConditionNotify(&tResultPtr->done);
	}
    }
    Tcl_MutexUnlock(&threadMutex);
}

/*
 *----------------------------------------------------------------------
 *
3733
3734
3735
3736
3737
3738
3739
3740

3741
3742
3743
3744
3745
3746
3747
3797
3798
3799
3800
3801
3802
3803

3804
3805
3806
3807
3808
3809
3810
3811







-
+







 */

static void
ThreadGetHandle(
    Tcl_ThreadId thrId,
    char *handlePtr
) {
    sprintf(handlePtr, THREAD_HNDLPREFIX "%p", thrId);
    snprintf(handlePtr, THREAD_HNDLMAXLEN, THREAD_HNDLPREFIX "%p", thrId);
}

/*
 *----------------------------------------------------------------------
 *
 * ThreadGetId --
 *
3761
3762
3763
3764
3765
3766
3767
3768

3769
3770
3771
3772

3773
3774
3775
3776
3777
3778
3779
3825
3826
3827
3828
3829
3830
3831

3832
3833
3834
3835

3836
3837
3838
3839
3840
3841
3842
3843







-
+



-
+







     Tcl_Interp *interp,
     Tcl_Obj *handleObj,
     Tcl_ThreadId *thrIdPtr
) {
    const char *thrHandle = Tcl_GetString(handleObj);

    if (sscanf(thrHandle, THREAD_HNDLPREFIX "%p", thrIdPtr) == 1) {
        return TCL_OK;
	return TCL_OK;
    }

    Tcl_AppendResult(interp, "invalid thread handle \"",
                     thrHandle, "\"", NULL);
		     thrHandle, "\"", (void *)NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 *  ErrorNoSuchThread --
3795
3796
3797
3798
3799
3800
3801
3802

3803
3804
3805
3806
3807
3808
3809
3859
3860
3861
3862
3863
3864
3865

3866
3867
3868
3869
3870
3871
3872
3873







-
+







    Tcl_Interp *interp,
    Tcl_ThreadId thrId
) {
    char thrHandle[THREAD_HNDLMAXLEN];

    ThreadGetHandle(thrId, thrHandle);
    Tcl_AppendResult(interp, "thread \"", thrHandle,
                     "\" does not exist", NULL);
		     "\" does not exist", (void *)NULL);
}

/*
 *----------------------------------------------------------------------
 *
 *  ThreadCutChannel --
 *
3836
3837
3838
3839
3840
3841
3842
3843

3844
3845
3846
3847
3848
3849
3850
3900
3901
3902
3903
3904
3905
3906

3907
3908
3909
3910
3911
3912
3913
3914







-
+







     * channel. If we do not do this, events will hit
     * the detached channel which is potentially being
     * owned by some other thread. This will wreck havoc
     * on our memory and eventually badly hurt us...
     */

    if (watchProc) {
        (*watchProc)(Tcl_GetChannelInstanceData(chan), 0);
	(*watchProc)(Tcl_GetChannelInstanceData(chan), 0);
    }

    /*
     * Artificially bump the channel reference count
     * which protects us from channel being closed
     * during the Tcl_UnregisterChannel().
     */
Changes to generic/threadNs.c.
29
30
31
32
33
34
35
36

37
38

39
40
41
42
43
44



45
46
47
48
49
50
51
29
30
31
32
33
34
35

36
37

38
39
40
41



42
43
44
45
46
47
48
49
50
51







-
+

-
+



-
-
-
+
+
+







 * Side effects:
 *    Package initialized. Tcl commands created.
 *
 *----------------------------------------------------------------------------
 */

static int
NsThread_Init (Tcl_Interp *interp, void *cd)
NsThread_Init(Tcl_Interp *interp, const void *cd)
{
    NsThreadInterpData *md = (NsThreadInterpData*)cd;
    NsThreadInterpData *md = (NsThreadInterpData *)cd;
    int ret = Thread_Init(interp);

    if (ret != TCL_OK) {
        Ns_Log(Warning, "can't load module %s: %s", md->modname,
                Tcl_GetString(Tcl_GetObjResult(interp)));
        return TCL_ERROR;
	Ns_Log(Warning, "can't load module %s: %s", md->modname,
		Tcl_GetString(Tcl_GetObjResult(interp)));
	return TCL_ERROR;
    }
    Tcl_SetAssocData(interp, "thread:nsd", NULL, md);

    return TCL_OK;
}

/*
65
66
67
68
69
70
71
72
73
74



75
76

77
78
79
80
81
82
83
84
85
86
87
88
65
66
67
68
69
70
71



72
73
74
75

76
77
78
79
80
81
82
83
84
85
86
87
88







-
-
-
+
+
+

-
+












 */

int
Ns_ModuleInit(char *srv, char *mod)
{
    NsThreadInterpData *md = NULL;

    md = (NsThreadInterpData*)ns_malloc(sizeof(NsThreadInterpData));
    md->modname = strcpy(ns_malloc(strlen(mod)+1), mod);
    md->server  = strcpy(ns_malloc(strlen(srv)+1), srv);
    md = (NsThreadInterpData *)ns_malloc(sizeof(NsThreadInterpData));
    md->modname = strcpy(ns_malloc(strlen(mod) + 1), mod);
    md->server  = strcpy(ns_malloc(strlen(srv) + 1), srv);

    return Ns_TclRegisterTrace(srv, NsThread_Init, (void*)md, NS_TCL_TRACE_CREATE);
    return Ns_TclRegisterTrace(srv, NsThread_Init, md, NS_TCL_TRACE_CREATE);
}

#endif /* NS_AOLSERVER */

/* EOF $RCSfile: aolstub.cpp,v $ */

/* Emacs Setup Variables */
/* Local Variables:      */
/* mode: C               */
/* indent-tabs-mode: nil */
/* c-basic-offset: 4     */
/* End:                  */
Changes to generic/threadPoolCmd.c.
29
30
31
32
33
34
35
36
37
38
39




40
41
42
43
44
45
46
29
30
31
32
33
34
35




36
37
38
39
40
41
42
43
44
45
46







-
-
-
-
+
+
+
+







typedef struct ThreadPool {
    Tcl_WideInt jobId;              /* Job counter */
    int idleTime;                   /* Time in secs a worker thread idles */
    int tearDown;                   /* Set to 1 to tear down the pool */
    int suspend;                    /* Set to 1 to suspend pool processing */
    char *initScript;               /* Script to initialize worker thread */
    char *exitScript;               /* Script to cleanup the worker */
    int minWorkers;                 /* Minimum number or worker threads */
    int maxWorkers;                 /* Maximum number of worker threads */
    int numWorkers;                 /* Current number of worker threads */
    int idleWorkers;                /* Number of idle workers */
    Tcl_WideInt minWorkers;         /* Minimum number or worker threads */
    Tcl_WideInt maxWorkers;         /* Maximum number of worker threads */
    Tcl_WideInt numWorkers;         /* Current number of worker threads */
    Tcl_WideInt idleWorkers;        /* Number of idle workers */
    size_t refCount;                /* Reference counter for reserve/release */
    Tcl_Mutex mutex;                /* Pool mutex */
    Tcl_Condition cond;             /* Pool condition variable */
    Tcl_HashTable jobsDone;         /* Stores processed job results */
    struct TpoolResult *workTail;   /* Tail of the list with jobs pending*/
    struct TpoolResult *workHead;   /* Head of the list with jobs pending*/
    struct TpoolWaiter *waitTail;   /* Tail of the thread waiters list */
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114










115
116
117
118
119
120
121
98
99
100
101
102
103
104










105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+








static char *threadEmptyResult = (char *)"";

/*
 * Functions implementing Tcl commands
 */

static Tcl_ObjCmdProc TpoolCreateObjCmd;
static Tcl_ObjCmdProc TpoolPostObjCmd;
static Tcl_ObjCmdProc TpoolWaitObjCmd;
static Tcl_ObjCmdProc TpoolCancelObjCmd;
static Tcl_ObjCmdProc TpoolGetObjCmd;
static Tcl_ObjCmdProc TpoolReserveObjCmd;
static Tcl_ObjCmdProc TpoolReleaseObjCmd;
static Tcl_ObjCmdProc TpoolSuspendObjCmd;
static Tcl_ObjCmdProc TpoolResumeObjCmd;
static Tcl_ObjCmdProc TpoolNamesObjCmd;
static Tcl_ObjCmdProc2 TpoolCreateObjCmd;
static Tcl_ObjCmdProc2 TpoolPostObjCmd;
static Tcl_ObjCmdProc2 TpoolWaitObjCmd;
static Tcl_ObjCmdProc2 TpoolCancelObjCmd;
static Tcl_ObjCmdProc2 TpoolGetObjCmd;
static Tcl_ObjCmdProc2 TpoolReserveObjCmd;
static Tcl_ObjCmdProc2 TpoolReleaseObjCmd;
static Tcl_ObjCmdProc2 TpoolSuspendObjCmd;
static Tcl_ObjCmdProc2 TpoolResumeObjCmd;
static Tcl_ObjCmdProc2 TpoolNamesObjCmd;

/*
 * Miscelaneous functions used within this file
 */

static int
CreateWorker(Tcl_Interp *interp, ThreadPool *tpoolPtr);
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
139
140
141
142
143
144
145

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169







-
+















-
+







PopWaiter(ThreadPool *tpoolPtr);

static void
SignalWaiter(ThreadPool *tpoolPtr);

static int
TpoolEval(Tcl_Interp *interp, char *script, size_t scriptLen,
                            TpoolResult *rPtr);
			    TpoolResult *rPtr);
static void
SetResult(Tcl_Interp *interp, TpoolResult *rPtr);

static ThreadPool*
GetTpool(const char *tpoolName);

static ThreadPool*
GetTpoolUnl(const char *tpoolName);

static void
ThrExitHandler(void *clientData);

static void
AppExitHandler(void *clientData);

static int
static size_t
TpoolReserve(ThreadPool *tpoolPtr);

static size_t
TpoolRelease(ThreadPool *tpoolPtr);

static void
TpoolSuspend(ThreadPool *tpoolPtr);
190
191
192
193
194
195
196
197

198
199

200
201

202


203
204
205
206
207
208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249






















250
251
252
253
254
255
256
257

258
259
260

261
262
263

264
265
266
267
268
269
270
190
191
192
193
194
195
196

197
198

199
200
201
202

203
204
205
206

207
208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
224
225
226
227
228






















229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

258
259
260

261
262
263

264
265
266
267
268
269
270
271







-
+

-
+


+
-
+
+


-










-
+











-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+


-
+


-
+







 *  None.
 *
 *----------------------------------------------------------------------
 */

static int
TpoolCreateObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size      objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    Tcl_WideInt ii;
    int ii, minw, maxw, idle;
    Tcl_WideInt minw, maxw;
    int idle;
    char buf[64], *exs = NULL, *cmd = NULL;
    ThreadPool *tpoolPtr;
    (void)dummy;

    /*
     * Syntax:  tpool::create ?-minworkers count?
     *                        ?-maxworkers count?
     *                        ?-initcmd script?
     *                        ?-exitcmd script?
     *                        ?-idletime seconds?
     */

    if (((objc-1) % 2)) {
        goto usage;
	goto usage;
    }

    minw = TPOOL_MINWORKERS;
    maxw = TPOOL_MAXWORKERS;
    idle = TPOOL_IDLETIMER;

    /*
     * Parse the optional arguments
     */

    for (ii = 1; ii < objc; ii += 2) {
        char *opt = Tcl_GetString(objv[ii]);
        if (OPT_CMP(opt, "-minworkers")) {
            if (Tcl_GetIntFromObj(interp, objv[ii+1], &minw) != TCL_OK) {
                return TCL_ERROR;
            }
        } else if (OPT_CMP(opt, "-maxworkers")) {
            if (Tcl_GetIntFromObj(interp, objv[ii+1], &maxw) != TCL_OK) {
                return TCL_ERROR;
            }
        } else if (OPT_CMP(opt, "-idletime")) {
            if (Tcl_GetIntFromObj(interp, objv[ii+1], &idle) != TCL_OK) {
                return TCL_ERROR;
            }
        } else if (OPT_CMP(opt, "-initcmd")) {
            const char *val = Tcl_GetString(objv[ii+1]);
            cmd  = strcpy((char *)Tcl_Alloc(objv[ii+1]->length+1), val);
        } else if (OPT_CMP(opt, "-exitcmd")) {
            const char *val = Tcl_GetString(objv[ii+1]);
            exs  = strcpy((char *)Tcl_Alloc(objv[ii+1]->length+1), val);
        } else {
            goto usage;
        }
	char *opt = Tcl_GetString(objv[ii]);
	if (OPT_CMP(opt, "-minworkers")) {
	    if (Tcl_GetWideIntFromObj(interp, objv[ii+1], &minw) != TCL_OK) {
		return TCL_ERROR;
	    }
	} else if (OPT_CMP(opt, "-maxworkers")) {
	    if (Tcl_GetWideIntFromObj(interp, objv[ii+1], &maxw) != TCL_OK) {
		return TCL_ERROR;
	    }
	} else if (OPT_CMP(opt, "-idletime")) {
	    if (Tcl_GetIntFromObj(interp, objv[ii+1], &idle) != TCL_OK) {
		return TCL_ERROR;
	    }
	} else if (OPT_CMP(opt, "-initcmd")) {
	    const char *val = Tcl_GetString(objv[ii+1]);
	    cmd  = strcpy((char *)Tcl_Alloc(objv[ii+1]->length+1), val);
	} else if (OPT_CMP(opt, "-exitcmd")) {
	    const char *val = Tcl_GetString(objv[ii+1]);
	    exs  = strcpy((char *)Tcl_Alloc(objv[ii+1]->length+1), val);
	} else {
	    goto usage;
	}
    }

    /*
     * Do some consistency checking
     */

    if (minw < 0) {
        minw = 0;
	minw = 0;
    }
    if (maxw < 0) {
        maxw = TPOOL_MAXWORKERS;
	maxw = TPOOL_MAXWORKERS;
    }
    if (minw > maxw) {
        maxw = minw;
	maxw = minw;
    }

    /*
     * Allocate and initialize thread pool structure
     */

    tpoolPtr = (ThreadPool *)Tcl_Alloc(sizeof(ThreadPool));
285
286
287
288
289
290
291
292
293
294
295
296
297
298







299
300
301
302
303


304
305
306
307
308
309
310
311



312
313
314
315
316
317
318
286
287
288
289
290
291
292







293
294
295
296
297
298
299
300
301
302


303
304
305
306
307
308
309



310
311
312
313
314
315
316
317
318
319







-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
+
+





-
-
-
+
+
+







     * Start the required number of worker threads.
     * On failure to start any of them, tear-down
     * partially initialized pool.
     */

    Tcl_MutexLock(&tpoolPtr->mutex);
    for (ii = 0; ii < tpoolPtr->minWorkers; ii++) {
        if (CreateWorker(interp, tpoolPtr) != TCL_OK) {
            Tcl_MutexUnlock(&tpoolPtr->mutex);
            Tcl_MutexLock(&listMutex);
            TpoolRelease(tpoolPtr);
            Tcl_MutexUnlock(&listMutex);
            return TCL_ERROR;
        }
	if (CreateWorker(interp, tpoolPtr) != TCL_OK) {
	    Tcl_MutexUnlock(&tpoolPtr->mutex);
	    Tcl_MutexLock(&listMutex);
	    TpoolRelease(tpoolPtr);
	    Tcl_MutexUnlock(&listMutex);
	    return TCL_ERROR;
	}
    }
    Tcl_MutexUnlock(&tpoolPtr->mutex);

    sprintf(buf, "%s%p", TPOOL_HNDLPREFIX, tpoolPtr);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_AUTO_LENGTH));
    snprintf(buf, sizeof(buf), "%s%p", TPOOL_HNDLPREFIX, tpoolPtr);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_INDEX_NONE));

    return TCL_OK;

 usage:
    Tcl_WrongNumArgs(interp, 1, objv,
                     "?-minworkers count? ?-maxworkers count? "
                     "?-initcmd script? ?-exitcmd script? "
                     "?-idletime seconds?");
		     "?-minworkers count? ?-maxworkers count? "
		     "?-initcmd script? ?-exitcmd script? "
		     "?-idletime seconds?");
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * TpoolPostObjCmd --
327
328
329
330
331
332
333
334

335
336

337
338
339
340
341


342
343
344
345
346
347
348
349
350
351
352
353
354

355
356
357
358
359
360
361
362
363
364
365
366










367
368
369
370
371
372

373
374

375
376
377
378

379
380
381
382
383
384



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399

400
401
402
403



404
405
406
407
408
409





410
411
412
413



414
415
416
417
418
419
420
421







422
423
424
425
426
427
428





429
430
431
432



433
434
435
436



437
438
439
440
441
442





443
444
445
446



447
448
449
450
451
452
453
454







455
456
457
458
459
460
461
462
463
464
465
466


467
468
469
470
471
472
473
474
475
476
477
478
479

480
481
482
483
484
485
486
328
329
330
331
332
333
334

335
336

337
338
339
340


341
342
343
344
345
346
347

348
349
350
351
352
353

354
355
356










357
358
359
360
361
362
363
364
365
366
367
368
369
370
371

372
373

374
375
376
377

378

379
380



381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397

398
399



400
401
402
403





404
405
406
407
408
409



410
411
412
413







414
415
416
417
418
419
420
421
422





423
424
425
426
427
428



429
430
431
432



433
434
435
436





437
438
439
440
441
442



443
444
445
446







447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463


464
465
466
467
468
469
470
471
472
473
474
475
476
477

478
479
480
481
482
483
484
485







-
+

-
+



-
-
+
+





-






-
+


-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+





-
+

-
+



-
+
-


-
-
-
+
+
+














-
+

-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+

-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+










-
-
+
+












-
+







 *  None.
 *
 *----------------------------------------------------------------------
 */

static int
TpoolPostObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size      objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    Tcl_WideInt jobId = 0;
    int ii, detached = 0, nowait = 0;
    size_t len;
    int detached = 0, nowait = 0;
    Tcl_Size ii, len;
    const char *tpoolName, *script;
    TpoolResult *rPtr;
    ThreadPool *tpoolPtr;

    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
    (void)dummy;

    /*
     * Syntax: tpool::post ?-detached? ?-nowait? tpoolId script
     */

    if (objc < 3 || objc > 5) {
        goto usage;
	goto usage;
    }
    for (ii = 1; ii < objc; ii++) {
        char *opt = Tcl_GetString(objv[ii]);
        if (*opt != '-') {
            break;
        } else if (OPT_CMP(opt, "-detached")) {
            detached  = 1;
        } else if (OPT_CMP(opt, "-nowait")) {
            nowait = 1;
        } else {
            goto usage;
        }
	char *opt = Tcl_GetString(objv[ii]);
	if (*opt != '-') {
	    break;
	} else if (OPT_CMP(opt, "-detached")) {
	    detached  = 1;
	} else if (OPT_CMP(opt, "-nowait")) {
	    nowait = 1;
	} else {
	    goto usage;
	}
    }

    /*
     * We expect exactly two arguments remaining after options
     */
    if (objc - ii != 2)
    if (objc != 2 + ii)
    {
        goto usage;
	goto usage;
    }

    tpoolName = Tcl_GetString(objv[ii]);
    script    = Tcl_GetString(objv[ii+1]);
    script    = Tcl_GetStringFromObj(objv[ii+1], &len);
    len = objv[ii+1]->length;
    tpoolPtr  = GetTpool(tpoolName);
    if (tpoolPtr == NULL) {
        Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
                         "\"", NULL);
        return TCL_ERROR;
	Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
			 "\"", (void *)NULL);
	return TCL_ERROR;
    }

    /*
     * Initialize per-thread private data for this caller
     */

    InitWaiter();

    /*
     * See if any worker available to run the job.
     */

    Tcl_MutexLock(&tpoolPtr->mutex);
    if (nowait) {
        if (tpoolPtr->numWorkers == 0) {
	if (tpoolPtr->numWorkers == 0) {

            /*
             * Assure there is at least one worker running.
             */
	    /*
	     * Assure there is at least one worker running.
	     */

            PushWaiter(tpoolPtr);
            if (CreateWorker(interp, tpoolPtr) != TCL_OK) {
                Tcl_MutexUnlock(&tpoolPtr->mutex);
                return TCL_ERROR;
            }
	    PushWaiter(tpoolPtr);
	    if (CreateWorker(interp, tpoolPtr) != TCL_OK) {
		Tcl_MutexUnlock(&tpoolPtr->mutex);
		return TCL_ERROR;
	    }

            /*
             * Wait for worker to start while servicing the event loop
             */
	    /*
	     * Wait for worker to start while servicing the event loop
	     */

            Tcl_MutexUnlock(&tpoolPtr->mutex);
            tsdPtr->stop = -1;
            while(tsdPtr->stop == -1) {
                Tcl_DoOneEvent(TCL_ALL_EVENTS);
            }
            Tcl_MutexLock(&tpoolPtr->mutex);
        }
	    Tcl_MutexUnlock(&tpoolPtr->mutex);
	    tsdPtr->stop = -1;
	    while(tsdPtr->stop == -1) {
		Tcl_DoOneEvent(TCL_ALL_EVENTS);
	    }
	    Tcl_MutexLock(&tpoolPtr->mutex);
	}
    } else {

        /*
         * If there are no idle worker threads, start some new
         * unless we are already running max number of workers.
         * In that case wait for the next one to become idle.
         */
	/*
	 * If there are no idle worker threads, start some new
	 * unless we are already running max number of workers.
	 * In that case wait for the next one to become idle.
	 */

        while (tpoolPtr->idleWorkers == 0) {
            PushWaiter(tpoolPtr);
            if (tpoolPtr->numWorkers < tpoolPtr->maxWorkers) {
	while (tpoolPtr->idleWorkers == 0) {
	    PushWaiter(tpoolPtr);
	    if (tpoolPtr->numWorkers < tpoolPtr->maxWorkers) {

                /*
                 * No more free workers; start new one
                 */
		/*
		 * No more free workers; start new one
		 */

                if (CreateWorker(interp, tpoolPtr) != TCL_OK) {
                    Tcl_MutexUnlock(&tpoolPtr->mutex);
                    return TCL_ERROR;
                }
            }
		if (CreateWorker(interp, tpoolPtr) != TCL_OK) {
		    Tcl_MutexUnlock(&tpoolPtr->mutex);
		    return TCL_ERROR;
		}
	    }

            /*
             * Wait for worker to start while servicing the event loop
             */
	    /*
	     * Wait for worker to start while servicing the event loop
	     */

            Tcl_MutexUnlock(&tpoolPtr->mutex);
            tsdPtr->stop = -1;
            while(tsdPtr->stop == -1) {
                Tcl_DoOneEvent(TCL_ALL_EVENTS);
            }
            Tcl_MutexLock(&tpoolPtr->mutex);
        }
	    Tcl_MutexUnlock(&tpoolPtr->mutex);
	    tsdPtr->stop = -1;
	    while(tsdPtr->stop == -1) {
		Tcl_DoOneEvent(TCL_ALL_EVENTS);
	    }
	    Tcl_MutexLock(&tpoolPtr->mutex);
	}
    }

    /*
     * Create new job ticket and put it on the list.
     */

    rPtr = (TpoolResult *)Tcl_Alloc(sizeof(TpoolResult));
    memset(rPtr, 0, sizeof(TpoolResult));

    if (detached == 0) {
        jobId = ++tpoolPtr->jobId;
        rPtr->jobId = jobId;
	jobId = ++tpoolPtr->jobId;
	rPtr->jobId = jobId;
    }

    rPtr->script    = strcpy((char *)Tcl_Alloc(len+1), script);
    rPtr->scriptLen = len;
    rPtr->detached  = detached;
    rPtr->threadId  = Tcl_GetCurrentThread();

    PushWork(rPtr, tpoolPtr);
    Tcl_ConditionNotify(&tpoolPtr->cond);
    Tcl_MutexUnlock(&tpoolPtr->mutex);

    if (detached == 0) {
        Tcl_SetObjResult(interp, Tcl_NewWideIntObj(jobId));
	Tcl_SetObjResult(interp, Tcl_NewWideIntObj(jobId));
    }

    return TCL_OK;

  usage:
    Tcl_WrongNumArgs(interp, 1, objv, "?-detached? ?-nowait? tpoolId script");
    return TCL_ERROR;
500
501
502
503
504
505
506
507

508
509

510
511
512
513


514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531


532
533
534

535
536
537

538
539
540
541
542
543
544



545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578


























579
580
581
582
583




584
585
586


587
588
589
590
591
592
593






594
595
596
597
598

599
600
601
602
603
604
605
499
500
501
502
503
504
505

506
507

508
509
510


511
512
513
514
515
516
517
518
519
520
521

522
523
524
525
526
527


528
529
530
531

532
533
534

535
536
537
538
539



540
541
542
543
544
545
546
547
548
549
550


























551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577




578
579
580
581
582


583
584
585






586
587
588
589
590
591
592
593
594
595

596
597
598
599
600
601
602
603







-
+

-
+


-
-
+
+









-






-
-
+
+


-
+


-
+




-
-
-
+
+
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
+
+

-
-
-
-
-
-
+
+
+
+
+
+




-
+







 * Side effects:
 *  None.
 *
 *----------------------------------------------------------------------
 */
static int
TpoolWaitObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size      objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    int ii, done;
    int wObjc;
    int done;
    Tcl_Size ii, wObjc;
    Tcl_WideInt jobId;
    char *tpoolName;
    Tcl_Obj *listVar = NULL;
    Tcl_Obj *waitList, *doneList, **wObjv;
    ThreadPool *tpoolPtr;
    TpoolResult *rPtr;
    Tcl_HashEntry *hPtr;

    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
    (void)dummy;

    /*
     * Syntax: tpool::wait tpoolId jobIdList ?listVar?
     */

    if (objc < 3 || objc > 4) {
        Tcl_WrongNumArgs(interp, 1, objv, "tpoolId jobIdList ?listVar");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "tpoolId jobIdList ?listVar");
	return TCL_ERROR;
    }
    if (objc == 4) {
        listVar = objv[3];
	listVar = objv[3];
    }
    if (Tcl_ListObjGetElements(interp, objv[2], &wObjc, &wObjv) != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    tpoolName = Tcl_GetString(objv[1]);
    tpoolPtr  = GetTpool(tpoolName);
    if (tpoolPtr == NULL) {
        Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
                         "\"", NULL);
        return TCL_ERROR;
	Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
			 "\"", (void *)NULL);
	return TCL_ERROR;
    }

    InitWaiter();
    done = 0; /* Number of elements in the done list */
    doneList = Tcl_NewListObj(0, NULL);

    Tcl_MutexLock(&tpoolPtr->mutex);
    while (1) {
        waitList = Tcl_NewListObj(0, NULL);
        for (ii = 0; ii < wObjc; ii++) {
            if (Tcl_GetWideIntFromObj(interp, wObjv[ii], &jobId) != TCL_OK) {
                Tcl_MutexUnlock(&tpoolPtr->mutex);
                return TCL_ERROR;
            }
            hPtr = Tcl_FindHashEntry(&tpoolPtr->jobsDone, (void *)(size_t)jobId);
            if (hPtr) {
                rPtr = (TpoolResult*)Tcl_GetHashValue(hPtr);
            } else {
                rPtr = NULL;
            }
            if (rPtr == NULL) {
                if (listVar) {
                    Tcl_ListObjAppendElement(interp, waitList, wObjv[ii]);
                }
            } else if (!rPtr->detached && rPtr->result) {
                done++;
                Tcl_ListObjAppendElement(interp, doneList, wObjv[ii]);
            } else if (listVar) {
                Tcl_ListObjAppendElement(interp, waitList, wObjv[ii]);
            }
        }
        if (done) {
            break;
        }
	waitList = Tcl_NewListObj(0, NULL);
	for (ii = 0; ii < wObjc; ii++) {
	    if (Tcl_GetWideIntFromObj(interp, wObjv[ii], &jobId) != TCL_OK) {
		Tcl_MutexUnlock(&tpoolPtr->mutex);
		return TCL_ERROR;
	    }
	    hPtr = Tcl_FindHashEntry(&tpoolPtr->jobsDone, (void *)(size_t)jobId);
	    if (hPtr) {
		rPtr = (TpoolResult*)Tcl_GetHashValue(hPtr);
	    } else {
		rPtr = NULL;
	    }
	    if (rPtr == NULL) {
		if (listVar) {
		    Tcl_ListObjAppendElement(interp, waitList, wObjv[ii]);
		}
	    } else if (!rPtr->detached && rPtr->result) {
		done++;
		Tcl_ListObjAppendElement(interp, doneList, wObjv[ii]);
	    } else if (listVar) {
		Tcl_ListObjAppendElement(interp, waitList, wObjv[ii]);
	    }
	}
	if (done) {
	    break;
	}

        /*
         * None of the jobs done, wait for completion
         * of the next job and try again.
         */
	/*
	 * None of the jobs done, wait for completion
	 * of the next job and try again.
	 */

        Tcl_DecrRefCount(waitList);
        PushWaiter(tpoolPtr);
	Tcl_DecrRefCount(waitList);
	PushWaiter(tpoolPtr);

        Tcl_MutexUnlock(&tpoolPtr->mutex);
        tsdPtr->stop = -1;
        while (tsdPtr->stop == -1) {
            Tcl_DoOneEvent(TCL_ALL_EVENTS);
        }
        Tcl_MutexLock(&tpoolPtr->mutex);
	Tcl_MutexUnlock(&tpoolPtr->mutex);
	tsdPtr->stop = -1;
	while (tsdPtr->stop == -1) {
	    Tcl_DoOneEvent(TCL_ALL_EVENTS);
	}
	Tcl_MutexLock(&tpoolPtr->mutex);
    }
    Tcl_MutexUnlock(&tpoolPtr->mutex);

    if (listVar) {
        Tcl_ObjSetVar2(interp, listVar, NULL, waitList, 0);
	Tcl_ObjSetVar2(interp, listVar, NULL, waitList, 0);
    }

    Tcl_SetObjResult(interp, doneList);

    return TCL_OK;
}

617
618
619
620
621
622
623
624

625
626

627
628
629
630

631
632
633
634
635
636
637
638
639
640
641
642
643
644
645


646
647
648

649
650
651

652
653
654
655
656
657
658



659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691



























692
693
694
695
696

697
698
699
700
701
702
703
615
616
617
618
619
620
621

622
623

624
625
626


627
628
629
630
631
632
633

634
635
636
637
638
639


640
641
642
643

644
645
646

647
648
649
650
651



652
653
654
655
656
657
658
659
660
661
662

























663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693

694
695
696
697
698
699
700
701







-
+

-
+


-
-
+






-






-
-
+
+


-
+


-
+




-
-
-
+
+
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




-
+







 * Side effects:
 *  None.
 *
 *----------------------------------------------------------------------
 */
static int
TpoolCancelObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size      objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    int ii;
    int wObjc;
    Tcl_Size ii, wObjc;
    Tcl_WideInt jobId;
    char *tpoolName;
    Tcl_Obj *listVar = NULL;
    Tcl_Obj *doneList, *waitList, **wObjv;
    ThreadPool *tpoolPtr;
    TpoolResult *rPtr;
    (void)dummy;

    /*
     * Syntax: tpool::cancel tpoolId jobIdList ?listVar?
     */

    if (objc < 3 || objc > 4) {
        Tcl_WrongNumArgs(interp, 1, objv, "tpoolId jobIdList ?listVar");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "tpoolId jobIdList ?listVar");
	return TCL_ERROR;
    }
    if (objc == 4) {
        listVar = objv[3];
	listVar = objv[3];
    }
    if (Tcl_ListObjGetElements(interp, objv[2], &wObjc, &wObjv) != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    tpoolName = Tcl_GetString(objv[1]);
    tpoolPtr  = GetTpool(tpoolName);
    if (tpoolPtr == NULL) {
        Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
                         "\"", NULL);
        return TCL_ERROR;
	Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
			 "\"", (void *)NULL);
	return TCL_ERROR;
    }

    InitWaiter();
    doneList = Tcl_NewListObj(0, NULL);
    waitList = Tcl_NewListObj(0, NULL);

    Tcl_MutexLock(&tpoolPtr->mutex);
    for (ii = 0; ii < wObjc; ii++) {
        if (Tcl_GetWideIntFromObj(interp, wObjv[ii], &jobId) != TCL_OK) {
            return TCL_ERROR;
        }
        for (rPtr = tpoolPtr->workHead; rPtr; rPtr = rPtr->nextPtr) {
            if (rPtr->jobId == jobId) {
                if (rPtr->prevPtr != NULL) {
                    rPtr->prevPtr->nextPtr = rPtr->nextPtr;
                } else {
                    tpoolPtr->workHead = rPtr->nextPtr;
                }
                if (rPtr->nextPtr != NULL) {
                    rPtr->nextPtr->prevPtr = rPtr->prevPtr;
                } else {
                    tpoolPtr->workTail = rPtr->prevPtr;
                }
                SetResult(NULL, rPtr); /* Just to free the result */
                Tcl_Free(rPtr->script);
                Tcl_Free(rPtr);
                Tcl_ListObjAppendElement(interp, doneList, wObjv[ii]);
                break;
            }
        }
        if (rPtr == NULL && listVar) {
            Tcl_ListObjAppendElement(interp, waitList, wObjv[ii]);
        }
	if (Tcl_GetWideIntFromObj(interp, wObjv[ii], &jobId) != TCL_OK) {
	    return TCL_ERROR;
	}
	for (rPtr = tpoolPtr->workHead; rPtr; rPtr = rPtr->nextPtr) {
	    if (rPtr->jobId == jobId) {
		if (rPtr->prevPtr != NULL) {
		    rPtr->prevPtr->nextPtr = rPtr->nextPtr;
		} else {
		    tpoolPtr->workHead = rPtr->nextPtr;
		}
		if (rPtr->nextPtr != NULL) {
		    rPtr->nextPtr->prevPtr = rPtr->prevPtr;
		} else {
		    tpoolPtr->workTail = rPtr->prevPtr;
		}
		SetResult(NULL, rPtr); /* Just to free the result */
		if (rPtr->script) {
		    Tcl_Free(rPtr->script);
		}
		Tcl_Free(rPtr);
		Tcl_ListObjAppendElement(interp, doneList, wObjv[ii]);
		break;
	    }
	}
	if (rPtr == NULL && listVar) {
	    Tcl_ListObjAppendElement(interp, waitList, wObjv[ii]);
	}
    }
    Tcl_MutexUnlock(&tpoolPtr->mutex);

    if (listVar) {
        Tcl_ObjSetVar2(interp, listVar, NULL, waitList, 0);
	Tcl_ObjSetVar2(interp, listVar, NULL, waitList, 0);
    }

    Tcl_SetObjResult(interp, doneList);

    return TCL_OK;
}

715
716
717
718
719
720
721
722

723
724

725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742


743
744
745

746
747
748

749
750
751
752
753
754
755
756
757
758
759
760



761
762
763
764
765
766
767
768
769
770
771
772
773
774



775
776
777
778
779
780



781
782
783
784
785
786
787
788
789
790
791
792
793



794
795
796
797
798
799
800
713
714
715
716
717
718
719

720
721

722
723
724
725
726
727
728
729
730
731

732
733
734
735
736
737


738
739
740
741

742
743
744

745
746
747
748
749
750
751
752
753
754



755
756
757
758
759
760
761
762
763
764
765
766
767
768



769
770
771
772
773
774



775
776
777
778
779
780
781
782
783
784
785
786
787



788
789
790
791
792
793
794
795
796
797







-
+

-
+









-






-
-
+
+


-
+


-
+









-
-
-
+
+
+











-
-
-
+
+
+



-
-
-
+
+
+










-
-
-
+
+
+







 * Side effects:
 *  None.
 *
 *----------------------------------------------------------------------
 */
static int
TpoolGetObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size      objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    int ret;
    Tcl_WideInt jobId;
    char *tpoolName;
    Tcl_Obj *resVar = NULL;
    ThreadPool *tpoolPtr;
    TpoolResult *rPtr;
    Tcl_HashEntry *hPtr;
    (void)dummy;

    /*
     * Syntax: tpool::get tpoolId jobId ?result?
     */

    if (objc < 3 || objc > 4) {
        Tcl_WrongNumArgs(interp, 1, objv, "tpoolId jobId ?result?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "tpoolId jobId ?result?");
	return TCL_ERROR;
    }
    if (Tcl_GetWideIntFromObj(interp, objv[2], &jobId) != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if (objc == 4) {
        resVar = objv[3];
	resVar = objv[3];
    }

    /*
     * Locate the threadpool
     */

    tpoolName = Tcl_GetString(objv[1]);
    tpoolPtr  = GetTpool(tpoolName);
    if (tpoolPtr == NULL) {
        Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
                         "\"", NULL);
        return TCL_ERROR;
	Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
			 "\"", (void *)NULL);
	return TCL_ERROR;
    }

    /*
     * Locate the job in question. It is an error to
     * do a "get" on bogus job handle or on the job
     * which did not complete yet.
     */

    Tcl_MutexLock(&tpoolPtr->mutex);
    hPtr = Tcl_FindHashEntry(&tpoolPtr->jobsDone, (void *)(size_t)jobId);
    if (hPtr == NULL) {
        Tcl_MutexUnlock(&tpoolPtr->mutex);
        Tcl_AppendResult(interp, "no such job", NULL);
        return TCL_ERROR;
	Tcl_MutexUnlock(&tpoolPtr->mutex);
	Tcl_AppendResult(interp, "no such job", (void *)NULL);
	return TCL_ERROR;
    }
    rPtr = (TpoolResult*)Tcl_GetHashValue(hPtr);
    if (rPtr->result == NULL) {
        Tcl_MutexUnlock(&tpoolPtr->mutex);
        Tcl_AppendResult(interp, "job not completed", NULL);
        return TCL_ERROR;
	Tcl_MutexUnlock(&tpoolPtr->mutex);
	Tcl_AppendResult(interp, "job not completed", (void *)NULL);
	return TCL_ERROR;
    }

    Tcl_DeleteHashEntry(hPtr);
    Tcl_MutexUnlock(&tpoolPtr->mutex);

    ret = rPtr->retcode;
    SetResult(interp, rPtr);
    Tcl_Free(rPtr);

    if (resVar) {
        Tcl_ObjSetVar2(interp, resVar, NULL, Tcl_GetObjResult(interp), 0);
        Tcl_SetObjResult(interp, Tcl_NewIntObj(ret));
        ret = TCL_OK;
	Tcl_ObjSetVar2(interp, resVar, NULL, Tcl_GetObjResult(interp), 0);
	Tcl_SetObjResult(interp, Tcl_NewIntObj(ret));
	ret = TCL_OK;
    }

    return ret;
}

/*
 *----------------------------------------------------------------------
811
812
813
814
815
816
817
818

819
820

821
822
823

824
825
826
827
828
829
830
831
832
833
834


835
836
837
838
839
840
841
842
843
844
845




846
847
848
849
850

851
852
853
854
855
856
857
808
809
810
811
812
813
814

815
816

817
818
819

820
821
822

823
824
825
826
827
828


829
830
831
832
833
834
835
836
837




838
839
840
841
842
843
844
845

846
847
848
849
850
851
852
853







-
+

-
+


-
+


-






-
-
+
+







-
-
-
-
+
+
+
+




-
+







 *  None.
 *
 *----------------------------------------------------------------------
 */

static int
TpoolReserveObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size      objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    int ret;
    size_t ret;
    char *tpoolName;
    ThreadPool *tpoolPtr;
    (void)dummy;

    /*
     * Syntax: tpool::preserve tpoolId
     */

    if (objc != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "tpoolId");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "tpoolId");
	return TCL_ERROR;
    }

    tpoolName = Tcl_GetString(objv[1]);

    Tcl_MutexLock(&listMutex);
    tpoolPtr  = GetTpoolUnl(tpoolName);
    if (tpoolPtr == NULL) {
        Tcl_MutexUnlock(&listMutex);
        Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
                         "\"", NULL);
        return TCL_ERROR;
	Tcl_MutexUnlock(&listMutex);
	Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
			 "\"", (void *)NULL);
	return TCL_ERROR;
    }

    ret = TpoolReserve(tpoolPtr);
    Tcl_MutexUnlock(&listMutex);
    Tcl_SetObjResult(interp, Tcl_NewIntObj(ret));
    Tcl_SetObjResult(interp, Tcl_NewIntObj((Tcl_WideInt)ret));

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
867
868
869
870
871
872
873
874

875
876

877
878
879
880
881
882
883
884
885
886
887
888
889
890


891
892
893
894
895
896
897
898
899
900
901




902
903
904
905
906

907
908
909
910
911
912
913
863
864
865
866
867
868
869

870
871

872
873
874
875
876
877

878
879
880
881
882
883


884
885
886
887
888
889
890
891
892




893
894
895
896
897
898
899
900

901
902
903
904
905
906
907
908







-
+

-
+





-






-
-
+
+







-
-
-
-
+
+
+
+




-
+







 *  None.
 *
 *----------------------------------------------------------------------
 */

static int
TpoolReleaseObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size      objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    size_t ret;
    char *tpoolName;
    ThreadPool *tpoolPtr;
    (void)dummy;

    /*
     * Syntax: tpool::release tpoolId
     */

    if (objc != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "tpoolId");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "tpoolId");
	return TCL_ERROR;
    }

    tpoolName = Tcl_GetString(objv[1]);

    Tcl_MutexLock(&listMutex);
    tpoolPtr  = GetTpoolUnl(tpoolName);
    if (tpoolPtr == NULL) {
        Tcl_MutexUnlock(&listMutex);
        Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
                         "\"", NULL);
        return TCL_ERROR;
	Tcl_MutexUnlock(&listMutex);
	Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
			 "\"", (void *)NULL);
	return TCL_ERROR;
    }

    ret = TpoolRelease(tpoolPtr);
    Tcl_MutexUnlock(&listMutex);
    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(ret));
    Tcl_SetObjResult(interp, Tcl_NewWideIntObj((Tcl_WideInt)ret));

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
923
924
925
926
927
928
929
930

931
932

933
934
935
936
937
938
939
940
941
942
943
944
945


946
947
948
949
950
951
952
953
954



955
956
957
958
959
960
961
918
919
920
921
922
923
924

925
926

927
928
929
930
931

932
933
934
935
936
937


938
939
940
941
942
943
944
945



946
947
948
949
950
951
952
953
954
955







-
+

-
+




-






-
-
+
+






-
-
-
+
+
+







 *  None.
 *
 *----------------------------------------------------------------------
 */

static int
TpoolSuspendObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size      objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    char *tpoolName;
    ThreadPool *tpoolPtr;
    (void)dummy;

    /*
     * Syntax: tpool::suspend tpoolId
     */

    if (objc != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "tpoolId");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "tpoolId");
	return TCL_ERROR;
    }

    tpoolName = Tcl_GetString(objv[1]);
    tpoolPtr  = GetTpool(tpoolName);

    if (tpoolPtr == NULL) {
        Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
                         "\"", NULL);
        return TCL_ERROR;
	Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
			 "\"", (void *)NULL);
	return TCL_ERROR;
    }

    TpoolSuspend(tpoolPtr);

    return TCL_OK;
}

974
975
976
977
978
979
980
981

982
983

984
985
986
987
988
989
990
991
992
993
994
995
996


997
998
999
1000
1001
1002
1003
1004
1005



1006
1007
1008
1009
1010
1011
1012
968
969
970
971
972
973
974

975
976

977
978
979
980
981

982
983
984
985
986
987


988
989
990
991
992
993
994
995



996
997
998
999
1000
1001
1002
1003
1004
1005







-
+

-
+




-






-
-
+
+






-
-
-
+
+
+







 *  None.
 *
 *----------------------------------------------------------------------
 */

static int
TpoolResumeObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size      objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    char *tpoolName;
    ThreadPool *tpoolPtr;
    (void)dummy;

    /*
     * Syntax: tpool::resume tpoolId
     */

    if (objc != 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "tpoolId");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "tpoolId");
	return TCL_ERROR;
    }

    tpoolName = Tcl_GetString(objv[1]);
    tpoolPtr  = GetTpool(tpoolName);

    if (tpoolPtr == NULL) {
        Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
                         "\"", NULL);
        return TCL_ERROR;
	Tcl_AppendResult(interp, "can not find threadpool \"", tpoolName,
			 "\"", (void *)NULL);
	return TCL_ERROR;
    }

    TpoolResume(tpoolPtr);

    return TCL_OK;
}

1025
1026
1027
1028
1029
1030
1031
1032

1033
1034

1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047



1048
1049
1050
1051
1052
1053
1054
1018
1019
1020
1021
1022
1023
1024

1025
1026

1027
1028
1029
1030
1031

1032
1033
1034
1035
1036



1037
1038
1039
1040
1041
1042
1043
1044
1045
1046







-
+

-
+




-





-
-
-
+
+
+







 *  None.
 *
 *----------------------------------------------------------------------
 */

static int
TpoolNamesObjCmd(
    void *dummy,               /* Not used. */
    TCL_UNUSED(void *),        /* Not used. */
    Tcl_Interp *interp,        /* Current interpreter. */
    int         objc,          /* Number of arguments. */
    Tcl_Size      objc,          /* Number of arguments. */
    Tcl_Obj    *const objv[]   /* Argument objects. */
) {
    ThreadPool *tpoolPtr;
    Tcl_Obj *listObj = Tcl_NewListObj(0, NULL);
    (void)dummy;
    (void)objc;
    (void)objv;

    Tcl_MutexLock(&listMutex);
    for (tpoolPtr = tpoolList; tpoolPtr; tpoolPtr = tpoolPtr->nextPtr) {
        char buf[32];
        sprintf(buf, "%s%p", TPOOL_HNDLPREFIX, tpoolPtr);
        Tcl_ListObjAppendElement(interp, listObj, Tcl_NewStringObj(buf, TCL_AUTO_LENGTH));
	char buf[32];
	snprintf(buf, sizeof(buf), "%s%p", TPOOL_HNDLPREFIX, tpoolPtr);
	Tcl_ListObjAppendElement(interp, listObj, Tcl_NewStringObj(buf, TCL_INDEX_NONE));
    }
    Tcl_MutexUnlock(&listMutex);
    Tcl_SetObjResult(interp, listObj);

    return TCL_OK;
}

1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099




1100
1101
1102

1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114



1115
1116
1117
1118
1119
1120
1121
1081
1082
1083
1084
1085
1086
1087




1088
1089
1090
1091
1092
1093

1094
1095
1096
1097
1098
1099
1100
1101
1102
1103



1104
1105
1106
1107
1108
1109
1110
1111
1112
1113







-
-
-
-
+
+
+
+


-
+









-
-
-
+
+
+







    /*
     * Create new worker thread here. Wait for the thread to start
     * because it's using the ThreadResult arg which is on our stack.
     */

    Tcl_MutexLock(&startMutex);
    if (Tcl_CreateThread(&id, TpoolWorker, &result,
                         TCL_THREAD_STACK_DEFAULT, 0) != TCL_OK) {
    	Tcl_SetObjResult(interp, Tcl_NewStringObj("can't create a new thread", TCL_AUTO_LENGTH));
        Tcl_MutexUnlock(&startMutex);
        return TCL_ERROR;
			 TCL_THREAD_STACK_DEFAULT, 0) != TCL_OK) {
	Tcl_SetObjResult(interp, Tcl_NewStringObj("can't create a new thread", TCL_INDEX_NONE));
	Tcl_MutexUnlock(&startMutex);
	return TCL_ERROR;
    }
    while(result.retcode == -1) {
        Tcl_ConditionWait(&tpoolPtr->cond, &startMutex, NULL);
	Tcl_ConditionWait(&tpoolPtr->cond, &startMutex, NULL);
    }
    Tcl_MutexUnlock(&startMutex);

    /*
     * Set error-related information if the thread
     * failed to initialize correctly.
     */

    if (result.retcode == 1) {
        result.retcode = TCL_ERROR;
        SetResult(interp, &result);
        return TCL_ERROR;
	result.retcode = TCL_ERROR;
	SetResult(interp, &result);
	return TCL_ERROR;
    }

    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
1153
1154
1155
1156
1157
1158
1159
1160

1161
1162

1163
1164

1165
1166
1167
1168
1169
1170
1171
1172
1173





1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189









1190
1191
1192
1193
1194
1195
1196
1197

1198
1199
1200
1201



1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263












































1264
1265
1266
1267
1268
1269
1270
1271

1272
1273
1274
1275
1276
1277
1278
1145
1146
1147
1148
1149
1150
1151

1152
1153

1154
1155

1156
1157
1158
1159
1160





1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172









1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188

1189
1190



1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212











































1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263

1264
1265
1266
1267
1268
1269
1270
1271







-
+

-
+

-
+




-
-
-
-
-
+
+
+
+
+







-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+







-
+

-
-
-
+
+
+



















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+








#ifdef NS_AOLSERVER
    interp = (Tcl_Interp*)Ns_TclAllocateInterp(NULL);
    rPtr->retcode = 0;
#else
    interp = Tcl_CreateInterp();
    if (Tcl_Init(interp) != TCL_OK) {
        rPtr->retcode = 1;
	rPtr->retcode = 1;
    } else if (Thread_Init(interp) != TCL_OK) {
        rPtr->retcode = 1;
	rPtr->retcode = 1;
    } else {
        rPtr->retcode = 0;
	rPtr->retcode = 0;
    }
#endif

    if (rPtr->retcode == 1) {
        errMsg = Tcl_GetString(Tcl_GetObjResult(interp));
        rPtr->result = strcpy((char *)Tcl_Alloc(strlen(errMsg)+1), errMsg);
        Tcl_ConditionNotify(&tpoolPtr->cond);
        Tcl_MutexUnlock(&startMutex);
        goto out;
	errMsg = Tcl_GetString(Tcl_GetObjResult(interp));
	rPtr->result = strcpy((char *)Tcl_Alloc(strlen(errMsg)+1), errMsg);
	Tcl_ConditionNotify(&tpoolPtr->cond);
	Tcl_MutexUnlock(&startMutex);
	goto out;
    }

    /*
     * Initialize the interpreter
     */

    if (tpoolPtr->initScript) {
        TpoolEval(interp, tpoolPtr->initScript, TCL_AUTO_LENGTH, rPtr);
        if (rPtr->retcode != TCL_OK) {
            rPtr->retcode = 1;
            errMsg = Tcl_GetString(Tcl_GetObjResult(interp));
            rPtr->result  = strcpy((char *)Tcl_Alloc(strlen(errMsg)+1), errMsg);
            Tcl_ConditionNotify(&tpoolPtr->cond);
            Tcl_MutexUnlock(&startMutex);
            goto out;
        }
	TpoolEval(interp, tpoolPtr->initScript, TCL_INDEX_NONE, rPtr);
	if (rPtr->retcode != TCL_OK) {
	    rPtr->retcode = 1;
	    errMsg = Tcl_GetString(Tcl_GetObjResult(interp));
	    rPtr->result  = strcpy((char *)Tcl_Alloc(strlen(errMsg)+1), errMsg);
	    Tcl_ConditionNotify(&tpoolPtr->cond);
	    Tcl_MutexUnlock(&startMutex);
	    goto out;
	}
    }

    /*
     * Setup idle timer
     */

    if (tpoolPtr->idleTime == 0) {
        idlePtr = NULL;
	idlePtr = NULL;
    } else {
        waitTime.sec  = tpoolPtr->idleTime;
        waitTime.usec = 0;
        idlePtr = &waitTime;
	waitTime.sec  = tpoolPtr->idleTime;
	waitTime.usec = 0;
	idlePtr = &waitTime;
    }

    /*
     * Tell caller we've started
     */

    tpoolPtr->numWorkers++;
    Tcl_ConditionNotify(&tpoolPtr->cond);
    Tcl_MutexUnlock(&startMutex);

    /*
     * Wait for jobs to arrive. Note the handcrafted time test.
     * Tcl API misses the return value of the Tcl_ConditionWait().
     * Hence, we do not know why the call returned. Was it someone
     * signalled the variable or has the idle timer expired?
     */

    Tcl_MutexLock(&tpoolPtr->mutex);
    while (!tpoolPtr->tearDown) {
        SignalWaiter(tpoolPtr);
        tpoolPtr->idleWorkers++;
        rPtr = NULL;
        tout = 0;
        while (tpoolPtr->suspend
               || (!tpoolPtr->tearDown && !tout
                   && (rPtr = PopWork(tpoolPtr)) == NULL)) {
            if (tpoolPtr->suspend && rPtr == NULL) {
                Tcl_ConditionWait(&tpoolPtr->cond, &tpoolPtr->mutex, NULL);
            } else if (rPtr == NULL) {
                Tcl_Time t1, t2;
                Tcl_GetTime(&t1);
                Tcl_ConditionWait(&tpoolPtr->cond, &tpoolPtr->mutex, idlePtr);
                Tcl_GetTime(&t2);
                if (tpoolPtr->idleTime > 0) {
                    tout = (t2.sec - t1.sec) >= tpoolPtr->idleTime;
                }
            }
        }
        tpoolPtr->idleWorkers--;
        if (rPtr == NULL) {
            if (tpoolPtr->numWorkers > tpoolPtr->minWorkers) {
                break; /* Enough workers, can safely kill this one */
            } else {
                continue; /* Worker count at min, leave this one alive */
            }
        } else if (tpoolPtr->tearDown) {
            PushWork(rPtr, tpoolPtr);
            break; /* Kill worker because pool is going down */
        }
        Tcl_MutexUnlock(&tpoolPtr->mutex);
        TpoolEval(interp, rPtr->script, rPtr->scriptLen, rPtr);
        Tcl_Free(rPtr->script);
        Tcl_MutexLock(&tpoolPtr->mutex);
        if (!rPtr->detached) {
            int isNew;
            Tcl_SetHashValue(Tcl_CreateHashEntry(&tpoolPtr->jobsDone,
                                                 (void *)(size_t)rPtr->jobId, &isNew),
                             rPtr);
            SignalWaiter(tpoolPtr);
        } else {
            Tcl_Free(rPtr);
        }
	SignalWaiter(tpoolPtr);
	tpoolPtr->idleWorkers++;
	rPtr = NULL;
	tout = 0;
	while (tpoolPtr->suspend
	       || (!tpoolPtr->tearDown && !tout
		   && (rPtr = PopWork(tpoolPtr)) == NULL)) {
	    if (tpoolPtr->suspend && rPtr == NULL) {
		Tcl_ConditionWait(&tpoolPtr->cond, &tpoolPtr->mutex, NULL);
	    } else if (rPtr == NULL) {
		Tcl_Time t1, t2;
		Tcl_GetTime(&t1);
		Tcl_ConditionWait(&tpoolPtr->cond, &tpoolPtr->mutex, idlePtr);
		Tcl_GetTime(&t2);
		if (tpoolPtr->idleTime > 0) {
		    tout = (t2.sec - t1.sec) >= tpoolPtr->idleTime;
		}
	    }
	}
	tpoolPtr->idleWorkers--;
	if (rPtr == NULL) {
	    if (tpoolPtr->numWorkers > tpoolPtr->minWorkers) {
		break; /* Enough workers, can safely kill this one */
	    } else {
		continue; /* Worker count at min, leave this one alive */
	    }
	} else if (tpoolPtr->tearDown) {
	    PushWork(rPtr, tpoolPtr);
	    break; /* Kill worker because pool is going down */
	}
	Tcl_MutexUnlock(&tpoolPtr->mutex);
	TpoolEval(interp, rPtr->script, rPtr->scriptLen, rPtr);
	Tcl_Free(rPtr->script);
	rPtr->script = NULL;
	Tcl_MutexLock(&tpoolPtr->mutex);
	if (!rPtr->detached) {
	    int isNew;
	    Tcl_SetHashValue(Tcl_CreateHashEntry(&tpoolPtr->jobsDone,
						 (void *)(size_t)rPtr->jobId, &isNew),
			     rPtr);
	    SignalWaiter(tpoolPtr);
	} else {
	    Tcl_Free(rPtr);
	}
    }

    /*
     * Tear down the worker
     */

    if (tpoolPtr->exitScript) {
        TpoolEval(interp, tpoolPtr->exitScript, TCL_AUTO_LENGTH, NULL);
	TpoolEval(interp, tpoolPtr->exitScript, TCL_INDEX_NONE, NULL);
    }

    tpoolPtr->numWorkers--;
    SignalWaiter(tpoolPtr);
    Tcl_MutexUnlock(&tpoolPtr->mutex);

 out:
1301
1302
1303
1304
1305
1306
1307
1308
1309


1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1294
1295
1296
1297
1298
1299
1300


1301
1302
1303
1304


1305
1306
1307
1308
1309
1310
1311







-
-
+
+


-
-







 * Side effects:
 *  None.
 *
 *----------------------------------------------------------------------
 */
static int
RunStopEvent(
    Tcl_Event *dummy,
    int mask
    TCL_UNUSED(Tcl_Event *),
    TCL_UNUSED(int)
) {
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
    (void)dummy;
    (void)mask;

    tsdPtr->stop = 1;
    return 1;
}

/*
 *----------------------------------------------------------------------
1335
1336
1337
1338
1339
1340
1341
1342

1343
1344
1345
1346
1347
1348
1349
1326
1327
1328
1329
1330
1331
1332

1333
1334
1335
1336
1337
1338
1339
1340







-
+







static void
PushWork(
    TpoolResult *rPtr,
    ThreadPool *tpoolPtr
) {
    SpliceIn(rPtr, tpoolPtr->workHead);
    if (tpoolPtr->workTail == NULL) {
        tpoolPtr->workTail = rPtr;
	tpoolPtr->workTail = rPtr;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * PopWork --
1362
1363
1364
1365
1366
1367
1368
1369

1370
1371
1372
1373
1374
1375
1376
1353
1354
1355
1356
1357
1358
1359

1360
1361
1362
1363
1364
1365
1366
1367







-
+







static TpoolResult *
PopWork(
    ThreadPool *tpoolPtr
) {
    TpoolResult *rPtr = tpoolPtr->workTail;

    if (rPtr == NULL) {
        return NULL;
	return NULL;
    }

    tpoolPtr->workTail = rPtr->prevPtr;
    SpliceOut(rPtr, tpoolPtr->workHead);

    rPtr->nextPtr = rPtr->prevPtr = NULL;

1397
1398
1399
1400
1401
1402
1403
1404

1405
1406
1407
1408
1409
1410
1411
1388
1389
1390
1391
1392
1393
1394

1395
1396
1397
1398
1399
1400
1401
1402







-
+







PushWaiter(
    ThreadPool *tpoolPtr
) {
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);

    SpliceIn(tsdPtr->waitPtr, tpoolPtr->waitHead);
    if (tpoolPtr->waitTail == NULL) {
        tpoolPtr->waitTail = tsdPtr->waitPtr;
	tpoolPtr->waitTail = tsdPtr->waitPtr;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * PopWaiter --
1424
1425
1426
1427
1428
1429
1430
1431

1432
1433
1434
1435
1436
1437
1438
1415
1416
1417
1418
1419
1420
1421

1422
1423
1424
1425
1426
1427
1428
1429







-
+







static TpoolWaiter*
PopWaiter(
    ThreadPool *tpoolPtr
) {
    TpoolWaiter *waitPtr =  tpoolPtr->waitTail;

    if (waitPtr == NULL) {
        return NULL;
	return NULL;
    }

    tpoolPtr->waitTail = waitPtr->prevPtr;
    SpliceOut(waitPtr, tpoolPtr->waitHead);

    waitPtr->prevPtr = waitPtr->nextPtr = NULL;

1490
1491
1492
1493
1494
1495
1496
1497

1498
1499
1500
1501
1502



1503
1504
1505
1506
1507
1508
1509
1481
1482
1483
1484
1485
1486
1487

1488
1489
1490



1491
1492
1493
1494
1495
1496
1497
1498
1499
1500







-
+


-
-
-
+
+
+







GetTpoolUnl (
    const char *tpoolName
) {
    ThreadPool *tpool;
    ThreadPool *tpoolPtr = NULL;

    if (sscanf(tpoolName, TPOOL_HNDLPREFIX"%p", &tpool) != 1) {
        return NULL;
	return NULL;
    }
    for (tpoolPtr = tpoolList; tpoolPtr; tpoolPtr = tpoolPtr->nextPtr) {
        if (tpoolPtr == tpool) {
            break;
        }
	if (tpoolPtr == tpool) {
	    break;
	}
    }

    return tpoolPtr;
}

/*
 *----------------------------------------------------------------------
1524
1525
1526
1527
1528
1529
1530
1531

1532
1533
1534
1535
1536
1537

1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550










1551
1552
1553

1554
1555
1556
1557

1558
1559

1560
1561
1562
1563
1564
1565
1566
1515
1516
1517
1518
1519
1520
1521

1522
1523
1524
1525
1526
1527

1528
1529
1530
1531










1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543

1544

1545
1546

1547
1548

1549
1550
1551
1552
1553
1554
1555
1556







-
+





-
+



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+


-
+
-


-
+

-
+







TpoolEval(
    Tcl_Interp *interp,
    char *script,
    size_t scriptLen,
    TpoolResult *rPtr
) {
    int ret;
    size_t reslen;
    Tcl_Size reslen;
    const char *result;
    const char *errorCode, *errorInfo;

    ret = Tcl_EvalEx(interp, script, scriptLen, TCL_EVAL_GLOBAL);
    if (rPtr == NULL || rPtr->detached) {
        return ret;
	return ret;
    }
    rPtr->retcode = ret;
    if (ret == TCL_ERROR) {
        errorCode = Tcl_GetVar2(interp, "errorCode", NULL, TCL_GLOBAL_ONLY);
        errorInfo = Tcl_GetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY);
        if (errorCode != NULL) {
            rPtr->errorCode = (char *)Tcl_Alloc(1 + strlen(errorCode));
            strcpy(rPtr->errorCode, errorCode);
        }
        if (errorInfo != NULL) {
            rPtr->errorInfo = (char *)Tcl_Alloc(1 + strlen(errorInfo));
            strcpy(rPtr->errorInfo, errorInfo);
        }
	errorCode = Tcl_GetVar2(interp, "errorCode", NULL, TCL_GLOBAL_ONLY);
	errorInfo = Tcl_GetVar2(interp, "errorInfo", NULL, TCL_GLOBAL_ONLY);
	if (errorCode != NULL) {
	    rPtr->errorCode = (char *)Tcl_Alloc(1 + strlen(errorCode));
	    strcpy(rPtr->errorCode, errorCode);
	}
	if (errorInfo != NULL) {
	    rPtr->errorInfo = (char *)Tcl_Alloc(1 + strlen(errorInfo));
	    strcpy(rPtr->errorInfo, errorInfo);
	}
    }

    result = Tcl_GetString(Tcl_GetObjResult(interp));
    result = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &reslen);
    reslen = Tcl_GetObjResult(interp)->length;

    if (reslen == 0) {
        rPtr->result = threadEmptyResult;
	rPtr->result = threadEmptyResult;
    } else {
        rPtr->result = strcpy((char *)Tcl_Alloc(1 + reslen), result);
	rPtr->result = strcpy((char *)Tcl_Alloc(1 + reslen), result);
    }

    return ret;
}

/*
 *----------------------------------------------------------------------
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599














1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612











1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632

1633
1634
1635
1636
1637
1638
1639
1569
1570
1571
1572
1573
1574
1575














1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591











1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621

1622
1623
1624
1625
1626
1627
1628
1629







-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+



















-
+







 */
static void
SetResult(
    Tcl_Interp *interp,
    TpoolResult *rPtr
) {
    if (rPtr->retcode == TCL_ERROR) {
        if (rPtr->errorCode) {
            if (interp) {
                Tcl_SetObjErrorCode(interp,Tcl_NewStringObj(rPtr->errorCode, TCL_AUTO_LENGTH));
            }
            Tcl_Free(rPtr->errorCode);
            rPtr->errorCode = NULL;
        }
        if (rPtr->errorInfo) {
            if (interp) {
            	Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(rPtr->errorInfo, TCL_AUTO_LENGTH));
            }
            Tcl_Free(rPtr->errorInfo);
            rPtr->errorInfo = NULL;
        }
	if (rPtr->errorCode) {
	    if (interp) {
		Tcl_SetObjErrorCode(interp,Tcl_NewStringObj(rPtr->errorCode, TCL_INDEX_NONE));
	    }
	    Tcl_Free(rPtr->errorCode);
	    rPtr->errorCode = NULL;
	}
	if (rPtr->errorInfo) {
	    if (interp) {
		Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(rPtr->errorInfo, TCL_INDEX_NONE));
	    }
	    Tcl_Free(rPtr->errorInfo);
	    rPtr->errorInfo = NULL;
	}
    }
    if (rPtr->result) {
        if (rPtr->result == threadEmptyResult) {
            if (interp) {
                Tcl_ResetResult(interp);
            }
        } else {
            if (interp) {
                Tcl_SetObjResult(interp, Tcl_NewStringObj(rPtr->result, TCL_AUTO_LENGTH));
            }
            Tcl_Free(rPtr->result);
            rPtr->result = NULL;
        }
	if (rPtr->result == threadEmptyResult) {
	    if (interp) {
		Tcl_ResetResult(interp);
	    }
	} else {
	    if (interp) {
		Tcl_SetObjResult(interp, Tcl_NewStringObj(rPtr->result, TCL_INDEX_NONE));
	    }
	    Tcl_Free(rPtr->result);
	    rPtr->result = NULL;
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TpoolReserve --
 *
 *  Does the pool preserve and/or release. Assumes caller holds
 *  the listMutex.
 *
 * Results:
 *  None.
 *
 * Side effects:
 *  May tear-down the threadpool if refcount drops to 0 or below.
 *
 *----------------------------------------------------------------------
 */
static int
static size_t
TpoolReserve(
    ThreadPool *tpoolPtr
) {
    return ++tpoolPtr->refCount;
}

/*
1658
1659
1660
1661
1662
1663
1664
1665

1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689








1690
1691
1692
1693
1694
1695
1696
1697
1698

1699
1700
1701

1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724















1725
1726
1727
1728
1729
1730
1731
1732
1733
1734






1735
1736
1737
1738
1739
1740
1741
1648
1649
1650
1651
1652
1653
1654

1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671








1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687

1688
1689
1690

1691
1692
1693
1694
1695
1696
1697
1698
1699















1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721



1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734







-
+
















-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+








-
+


-
+








-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
-
-
+
+
+
+
+
+







) {
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
    TpoolResult *rPtr;
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;

    if (tpoolPtr->refCount-- > 1) {
        return tpoolPtr->refCount;
	return tpoolPtr->refCount;
    }

    /*
     * Pool is going away; remove from the list of pools,
     */

    SpliceOut(tpoolPtr, tpoolList);
    InitWaiter();

    /*
     * Signal and wait for all workers to die.
     */

    Tcl_MutexLock(&tpoolPtr->mutex);
    tpoolPtr->tearDown = 1;
    while (tpoolPtr->numWorkers > 0) {
        PushWaiter(tpoolPtr);
        Tcl_ConditionNotify(&tpoolPtr->cond);
        Tcl_MutexUnlock(&tpoolPtr->mutex);
        tsdPtr->stop = -1;
        while(tsdPtr->stop == -1) {
            Tcl_DoOneEvent(TCL_ALL_EVENTS);
        }
        Tcl_MutexLock(&tpoolPtr->mutex);
	PushWaiter(tpoolPtr);
	Tcl_ConditionNotify(&tpoolPtr->cond);
	Tcl_MutexUnlock(&tpoolPtr->mutex);
	tsdPtr->stop = -1;
	while(tsdPtr->stop == -1) {
	    Tcl_DoOneEvent(TCL_ALL_EVENTS);
	}
	Tcl_MutexLock(&tpoolPtr->mutex);
    }
    Tcl_MutexUnlock(&tpoolPtr->mutex);

    /*
     * Tear down the pool structure
     */

    if (tpoolPtr->initScript) {
        Tcl_Free(tpoolPtr->initScript);
	Tcl_Free(tpoolPtr->initScript);
    }
    if (tpoolPtr->exitScript) {
        Tcl_Free(tpoolPtr->exitScript);
	Tcl_Free(tpoolPtr->exitScript);
    }

    /*
     * Cleanup completed but not collected jobs
     */

    hPtr = Tcl_FirstHashEntry(&tpoolPtr->jobsDone, &search);
    while (hPtr != NULL) {
        rPtr = (TpoolResult*)Tcl_GetHashValue(hPtr);
        if (rPtr->result && rPtr->result != threadEmptyResult) {
            Tcl_Free(rPtr->result);
        }
        if (rPtr->retcode == TCL_ERROR) {
            if (rPtr->errorInfo) {
                Tcl_Free(rPtr->errorInfo);
            }
            if (rPtr->errorCode) {
                Tcl_Free(rPtr->errorCode);
            }
        }
        Tcl_Free(rPtr);
        Tcl_DeleteHashEntry(hPtr);
        hPtr = Tcl_NextHashEntry(&search);
	rPtr = (TpoolResult*)Tcl_GetHashValue(hPtr);
	if (rPtr->result && rPtr->result != threadEmptyResult) {
	    Tcl_Free(rPtr->result);
	}
	if (rPtr->retcode == TCL_ERROR) {
	    if (rPtr->errorInfo) {
		Tcl_Free(rPtr->errorInfo);
	    }
	    if (rPtr->errorCode) {
		Tcl_Free(rPtr->errorCode);
	    }
	}
	Tcl_Free(rPtr);
	Tcl_DeleteHashEntry(hPtr);
	hPtr = Tcl_NextHashEntry(&search);
    }
    Tcl_DeleteHashTable(&tpoolPtr->jobsDone);

    /*
     * Cleanup jobs posted but never completed.
     */

    for (rPtr = tpoolPtr->workHead; rPtr; rPtr = rPtr->nextPtr) {
        Tcl_Free(rPtr->script);
        Tcl_Free(rPtr);
    for (rPtr = tpoolPtr->workHead; rPtr; rPtr = tpoolPtr->workHead) {
	tpoolPtr->workHead = rPtr->nextPtr;
	if (rPtr->script) {
	    Tcl_Free(rPtr->script);
	}
	Tcl_Free(rPtr);
    }
    Tcl_MutexFinalize(&tpoolPtr->mutex);
    Tcl_ConditionFinalize(&tpoolPtr->cond);
    Tcl_Free(tpoolPtr);

    return 0;
}
1812
1813
1814
1815
1816
1817
1818
1819

1820
1821
1822
1823
1824
1825

1826
1827
1828
1829
1830
1831
1832
1833
1805
1806
1807
1808
1809
1810
1811

1812
1813
1814
1815
1816
1817

1818

1819
1820
1821
1822
1823
1824
1825







-
+





-
+
-







    ThreadPool *tpoolPtr
) {
    TpoolWaiter *waitPtr;
    Tcl_Event *evPtr;

    waitPtr = PopWaiter(tpoolPtr);
    if (waitPtr == NULL) {
        return;
	return;
    }

    evPtr = (Tcl_Event *)Tcl_Alloc(sizeof(Tcl_Event));
    evPtr->proc = RunStopEvent;

    Tcl_ThreadQueueEvent(waitPtr->threadId,(Tcl_Event*)evPtr,TCL_QUEUE_TAIL);
    Tcl_ThreadQueueEvent(waitPtr->threadId,(Tcl_Event*)evPtr,TCL_QUEUE_TAIL|TCL_QUEUE_ALERT_IF_EMPTY);
    Tcl_ThreadAlert(waitPtr->threadId);
}

/*
 *----------------------------------------------------------------------
 *
 * InitWaiter --
 *
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854





1855
1856
1857
1858
1859
1860
1861
1835
1836
1837
1838
1839
1840
1841





1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853







-
-
-
-
-
+
+
+
+
+







 */
static void
InitWaiter ()
{
    ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);

    if (tsdPtr->waitPtr == NULL) {
        tsdPtr->waitPtr = (TpoolWaiter *)Tcl_Alloc(sizeof(TpoolWaiter));
        tsdPtr->waitPtr->prevPtr  = NULL;
        tsdPtr->waitPtr->nextPtr  = NULL;
        tsdPtr->waitPtr->threadId = Tcl_GetCurrentThread();
        Tcl_CreateThreadExitHandler(ThrExitHandler, tsdPtr);
	tsdPtr->waitPtr = (TpoolWaiter *)Tcl_Alloc(sizeof(TpoolWaiter));
	tsdPtr->waitPtr->prevPtr  = NULL;
	tsdPtr->waitPtr->nextPtr  = NULL;
	tsdPtr->waitPtr->threadId = Tcl_GetCurrentThread();
	Tcl_CreateThreadExitHandler(ThrExitHandler, tsdPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * ThrExitHandler --
1892
1893
1894
1895
1896
1897
1898
1899

1900
1901
1902
1903
1904
1905
1906
1907
1908
1909

1910
1911
1912
1913
1914
1915
1916
1917

1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932


1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954






1955
1956

1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1884
1885
1886
1887
1888
1889
1890

1891
1892
1893

1894
1895
1896
1897
1898
1899

1900
1901
1902
1903
1904
1905
1906
1907

1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921


1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939






1940
1941
1942
1943
1944
1945
1946

1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957







-
+


-






-
+







-
+













-
-
+
+
















-
-
-
-
-
-
+
+
+
+
+
+

-
+










 * Side effects:
 *  None.
 *
 *----------------------------------------------------------------------
 */
static void
AppExitHandler(
    void *dummy
    TCL_UNUSED(void *)
) {
    ThreadPool *tpoolPtr;
    (void)dummy;

    Tcl_MutexLock(&listMutex);
    /*
     * Restart with head of list each time until empty. [Bug 1427570]
     */
    for (tpoolPtr = tpoolList; tpoolPtr; tpoolPtr = tpoolList) {
        TpoolRelease(tpoolPtr);
	TpoolRelease(tpoolPtr);
    }
    Tcl_MutexUnlock(&listMutex);
}

/*
 *----------------------------------------------------------------------
 *
 * Tpool_Init --
 * TpoolInit --
 *
 *  Create commands in current interpreter.
 *
 * Results:
 *  None.
 *
 * Side effects:
 *  On first load, creates application exit handler to clean up
 *  any threadpools left.
 *
 *----------------------------------------------------------------------
 */

int
Tpool_Init (
const char *
TpoolInit (
    Tcl_Interp *interp                 /* Interp where to create cmds */
) {
    static int initialized;

    TCL_CMD(interp, TPOOL_CMD_PREFIX"create",   TpoolCreateObjCmd);
    TCL_CMD(interp, TPOOL_CMD_PREFIX"names",    TpoolNamesObjCmd);
    TCL_CMD(interp, TPOOL_CMD_PREFIX"post",     TpoolPostObjCmd);
    TCL_CMD(interp, TPOOL_CMD_PREFIX"wait",     TpoolWaitObjCmd);
    TCL_CMD(interp, TPOOL_CMD_PREFIX"cancel",   TpoolCancelObjCmd);
    TCL_CMD(interp, TPOOL_CMD_PREFIX"get",      TpoolGetObjCmd);
    TCL_CMD(interp, TPOOL_CMD_PREFIX"preserve", TpoolReserveObjCmd);
    TCL_CMD(interp, TPOOL_CMD_PREFIX"release",  TpoolReleaseObjCmd);
    TCL_CMD(interp, TPOOL_CMD_PREFIX"suspend",  TpoolSuspendObjCmd);
    TCL_CMD(interp, TPOOL_CMD_PREFIX"resume",   TpoolResumeObjCmd);

    if (initialized == 0) {
        Tcl_MutexLock(&listMutex);
        if (initialized == 0) {
            Tcl_CreateExitHandler(AppExitHandler, (void *)-1);
            initialized = 1;
        }
        Tcl_MutexUnlock(&listMutex);
	Tcl_MutexLock(&listMutex);
	if (initialized == 0) {
	    Tcl_CreateExitHandler(AppExitHandler, (void *)-1);
	    initialized = 1;
	}
	Tcl_MutexUnlock(&listMutex);
    }
    return TCL_OK;
    return NULL;
}

/* EOF $RCSfile: threadPoolCmd.c,v $ */

/* Emacs Setup Variables */
/* Local Variables:      */
/* mode: C               */
/* indent-tabs-mode: nil */
/* c-basic-offset: 4     */
/* End:                  */
Changes to generic/threadSpCmd.c.
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108




109
110
111
112
113
114
115
92
93
94
95
96
97
98

99
100
101
102
103
104




105
106
107
108
109
110
111
112
113
114
115







-
+





-
-
-
-
+
+
+
+







 * to pointers of their corresponding synchronization objects.
 */

static int        initOnce;    /* Flag for initializing tables below */
static Tcl_Mutex  initMutex;   /* Controls initialization of primitives */
static SpBucket  muxBuckets[NUMSPBUCKETS];  /* Maps mutex names/handles */
static SpBucket  varBuckets[NUMSPBUCKETS];  /* Maps condition variable
                                             * names/handles */
					     * names/handles */

/*
 * Functions implementing Tcl commands
 */

static Tcl_ObjCmdProc ThreadMutexObjCmd;
static Tcl_ObjCmdProc ThreadRWMutexObjCmd;
static Tcl_ObjCmdProc ThreadCondObjCmd;
static Tcl_ObjCmdProc ThreadEvalObjCmd;
static Tcl_ObjCmdProc2 ThreadMutexObjCmd;
static Tcl_ObjCmdProc2 ThreadRWMutexObjCmd;
static Tcl_ObjCmdProc2 ThreadCondObjCmd;
static Tcl_ObjCmdProc2 ThreadEvalObjCmd;

/*
 * Forward declaration of functions used only within this file
 */

static int       SpMutexLock       (SpMutex *);
static int       SpMutexUnlock     (SpMutex *);
173
174
175
176
177
178
179
180

181
182

183
184
185
186


187
188
189
190
191
192
193

194
195
196
197


198
199
200
201
202
203
204
205
206
207
208
209
210


211
212
213
214

215
216
217
218
219
220
221
222
223


224
225
226
227



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242














243
244
245
246



247
248
249
250
251
252





253
254
255
256



257
258
259


260
261
262
263



264
265
266
267
268
269
270
271
272


273
274
275

276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295














296
297
298
299
300
301
302
303
304

305
306
307
308
309
310




311
312
313

314
315
316
317
318
319
320
321







322
323
324
325
326
327
328






329
330

331
332
333
334
335
336
337
173
174
175
176
177
178
179

180
181

182
183
184


185
186
187
188
189


190

191
192
193


194
195
196
197
198
199
200
201
202
203
204
205
206


207
208
209
210
211

212
213
214
215
216
217
218
219


220
221
222



223
224
225
226














227
228
229
230
231
232
233
234
235
236
237
238
239
240
241



242
243
244
245





246
247
248
249
250
251



252
253
254
255


256
257




258
259
260
261
262
263
264
265
266
267


268
269
270
271

272

273
274
275
276
277














278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299

300
301
302




303
304
305
306
307
308

309
310







311
312
313
314
315
316
317
318






319
320
321
322
323
324
325

326
327
328
329
330
331
332
333







-
+

-
+


-
-
+
+



-
-

-
+


-
-
+
+











-
-
+
+



-
+







-
-
+
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+

-
-
+
+
-
-
-
-
+
+
+







-
-
+
+


-
+
-





-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
+


-
-
-
-
+
+
+
+


-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
+







 *    See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadMutexObjCmd(
    void *dummy,                  /* Not used. */
    TCL_UNUSED(void *),                /* Not used. */
    Tcl_Interp *interp,                /* Current interpreter. */
    int objc,                          /* Number of arguments. */
    Tcl_Size objc,                          /* Number of arguments. */
    Tcl_Obj *const objv[]              /* Argument objects. */
) {
    int opt, ret;
    size_t nameLen;
    int ret;
    Tcl_Size nameLen;
    const char *mutexName;
    char type;
    SpMutex *mutexPtr;
    (void)dummy;

    static const char *const cmdOpts[] = {
        "create", "destroy", "lock", "unlock", NULL
	"create", "destroy", "lock", "unlock", NULL
    };
    enum options {
        m_CREATE, m_DESTROY, m_LOCK, m_UNLOCK
    };
	m_CREATE, m_DESTROY, m_LOCK, m_UNLOCK
    } opt;

    /*
     * Syntax:
     *
     *     thread::mutex create ?-recursive?
     *     thread::mutex destroy <mutexHandle>
     *     thread::mutex lock <mutexHandle>
     *     thread::mutex unlock <mutexHandle>
     */

    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "option ?args?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "option ?args?");
	return TCL_ERROR;
    }
    ret = Tcl_GetIndexFromObjStruct(interp, objv[1], cmdOpts, sizeof(char *), "option", 0, &opt);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    /*
     * Cover the "create" option first. It needs no existing handle.
     */

    if (opt == (int)m_CREATE) {
        Tcl_Obj *nameObj;
        const char *arg;
	Tcl_Obj *nameObj;
	const char *arg;

        /*
         * Parse out which type of mutex to create
         */
	/*
	 * Parse out which type of mutex to create
	 */

        if (objc == 2) {
            type = EMUTEXID;
        } else if (objc > 3) {
            Tcl_WrongNumArgs(interp, 2, objv, "?-recursive?");
            return TCL_ERROR;
        } else {
            arg = Tcl_GetString(objv[2]);
            if (OPT_CMP(arg, "-recursive")) {
                type = RMUTEXID;
            } else {
                Tcl_WrongNumArgs(interp, 2, objv, "?-recursive?");
                return TCL_ERROR;
            }
        }
	if (objc == 2) {
	    type = EMUTEXID;
	} else if (objc > 3) {
	    Tcl_WrongNumArgs(interp, 2, objv, "?-recursive?");
	    return TCL_ERROR;
	} else {
	    arg = Tcl_GetString(objv[2]);
	    if (OPT_CMP(arg, "-recursive")) {
		type = RMUTEXID;
	    } else {
		Tcl_WrongNumArgs(interp, 2, objv, "?-recursive?");
		return TCL_ERROR;
	    }
	}

        /*
         * Create the requested mutex
         */
	/*
	 * Create the requested mutex
	 */

        mutexPtr = (SpMutex *)Tcl_Alloc(sizeof(SpMutex));
        mutexPtr->type   = type;
        mutexPtr->bucket = NULL;
        mutexPtr->hentry = NULL;
        mutexPtr->lock   = NULL; /* Will be auto-initialized */
	mutexPtr = (SpMutex *)Tcl_Alloc(sizeof(SpMutex));
	mutexPtr->type   = type;
	mutexPtr->bucket = NULL;
	mutexPtr->hentry = NULL;
	mutexPtr->lock   = NULL; /* Will be auto-initialized */

        /*
         * Generate Tcl name for this mutex
         */
	/*
	 * Generate Tcl name for this mutex
	 */

        nameObj = GetName(mutexPtr->type, (void*)mutexPtr);
        mutexName = Tcl_GetString(nameObj);
	nameObj = GetName(mutexPtr->type, (void*)mutexPtr);
	mutexName = Tcl_GetStringFromObj(nameObj, &nameLen);
        nameLen = nameObj->length;
        AddMutex(mutexName, nameLen, mutexPtr);
        Tcl_SetObjResult(interp, nameObj);
        return TCL_OK;
	AddMutex(mutexName, nameLen, mutexPtr);
	Tcl_SetObjResult(interp, nameObj);
	return TCL_OK;
    }

    /*
     * All other options require a valid name.
     */

    if (objc != 3) {
        Tcl_WrongNumArgs(interp, 2, objv, "mutexHandle");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 2, objv, "mutexHandle");
	return TCL_ERROR;
    }

    mutexName = Tcl_GetString(objv[2]);
    mutexName = Tcl_GetStringFromObj(objv[2], &nameLen);
    nameLen = objv[2]->length;

    /*
     * Try mutex destroy
     */

    if (opt == (int)m_DESTROY) {
        ret = RemoveMutex(mutexName, nameLen);
        if (ret <= 0) {
            if (ret == -1) {
            notfound:
                Tcl_AppendResult(interp, "no such mutex \"", mutexName,
                                 "\"", NULL);
                return TCL_ERROR;
            } else {
                Tcl_AppendResult(interp, "mutex is in use", NULL);
                return TCL_ERROR;
            }
        }
        return TCL_OK;
    if (opt == m_DESTROY) {
	ret = RemoveMutex(mutexName, nameLen);
	if (ret <= 0) {
	    if (ret == -1) {
	    notfound:
		Tcl_AppendResult(interp, "no such mutex \"", mutexName,
				 "\"", (void *)NULL);
		return TCL_ERROR;
	    } else {
		Tcl_AppendResult(interp, "mutex is in use", (void *)NULL);
		return TCL_ERROR;
	    }
	}
	return TCL_OK;
    }

    /*
     * Try all other options
     */

    mutexPtr = GetMutex(mutexName, nameLen);
    if (mutexPtr == NULL) {
        goto notfound;
	goto notfound;
    }
    if (!IsExclusive(mutexPtr) && !IsRecursive(mutexPtr)) {
        PutMutex(mutexPtr);
        Tcl_AppendResult(interp, "wrong mutex type, must be either"
                         " exclusive or recursive", NULL);
        return TCL_ERROR;
	PutMutex(mutexPtr);
	Tcl_AppendResult(interp, "wrong mutex type, must be either"
			 " exclusive or recursive", (void *)NULL);
	return TCL_ERROR;
    }

    switch ((enum options)opt) {
    switch (opt) {
    case m_LOCK:
        if (!SpMutexLock(mutexPtr)) {
            PutMutex(mutexPtr);
            Tcl_AppendResult(interp, "locking the same exclusive mutex "
                             "twice from the same thread", NULL);
            return TCL_ERROR;
        }
        break;
	if (!SpMutexLock(mutexPtr)) {
	    PutMutex(mutexPtr);
	    Tcl_AppendResult(interp, "locking the same exclusive mutex "
			     "twice from the same thread", (void *)NULL);
	    return TCL_ERROR;
	}
	break;
    case m_UNLOCK:
        if (!SpMutexUnlock(mutexPtr)) {
            PutMutex(mutexPtr);
            Tcl_AppendResult(interp, "mutex is not locked", NULL);
            return TCL_ERROR;
        }
        break;
	if (!SpMutexUnlock(mutexPtr)) {
	    PutMutex(mutexPtr);
	    Tcl_AppendResult(interp, "mutex is not locked", (void *)NULL);
	    return TCL_ERROR;
	}
	break;
    default:
        break;
	break;
    }

    PutMutex(mutexPtr);

    return TCL_OK;
}

350
351
352
353
354
355
356
357

358
359

360
361
362
363


364
365
366
367
368
369
370

371
372
373
374


375
376
377
378
379
380
381
382
383
384
385
386
387
388
389


390
391
392
393

394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411












412
413
414
415
416
417





418
419
420
421
422
423
424
425
426


427
428
429

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449














450
451
452
453
454
455
456
457
458

459
460
461
462
463



464
465
466
467
468
469

470
471
472
473
474
475
476
477







478
479
480
481
482
483
484
485







486
487
488
489
490
491
492






493
494

495
496
497
498
499
500
501
346
347
348
349
350
351
352

353
354

355
356
357


358
359
360
361
362
363
364
365

366
367
368


369
370

371
372
373
374
375
376
377
378
379
380
381
382


383
384
385
386
387

388
389
390
391
392
393
394












395
396
397
398
399
400
401
402
403
404
405
406
407





408
409
410
411
412
413
414
415
416
417
418
419


420
421
422
423

424

425
426
427
428
429














430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451

452
453
454



455
456
457
458
459
460
461
462

463
464







465
466
467
468
469
470
471
472







473
474
475
476
477
478
479
480






481
482
483
484
485
486
487

488
489
490
491
492
493
494
495







-
+

-
+


-
-
+
+






-
+


-
-
+
+
-












-
-
+
+



-
+






-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+







-
-
+
+


-
+
-





-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
+


-
-
-
+
+
+





-
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
+







 *    See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadRWMutexObjCmd(
    void *dummy,                  /* Not used. */
    TCL_UNUSED(void *),                /* Not used. */
    Tcl_Interp *interp,                /* Current interpreter. */
    int objc,                          /* Number of arguments. */
    Tcl_Size objc,                          /* Number of arguments. */
    Tcl_Obj *const objv[]              /* Argument objects. */
) {
    int opt, ret;
    size_t nameLen;
    int ret;
    Tcl_Size nameLen;
    const char *mutexName;
    SpMutex *mutexPtr;
    Sp_ReadWriteMutex *rwPtr;
    Sp_AnyMutex **lockPtr;

    static const char *const cmdOpts[] = {
        "create", "destroy", "rlock", "wlock", "unlock", NULL
	"create", "destroy", "rlock", "wlock", "unlock", NULL
    };
    enum options {
        w_CREATE, w_DESTROY, w_RLOCK, w_WLOCK, w_UNLOCK
    };
	w_CREATE, w_DESTROY, w_RLOCK, w_WLOCK, w_UNLOCK
    } opt;
    (void)dummy;

    /*
     * Syntax:
     *
     *     thread::rwmutex create
     *     thread::rwmutex destroy <mutexHandle>
     *     thread::rwmutex rlock <mutexHandle>
     *     thread::rwmutex wlock <mutexHandle>
     *     thread::rwmutex unlock <mutexHandle>
     */

    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "option ?args?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "option ?args?");
	return TCL_ERROR;
    }
    ret = Tcl_GetIndexFromObjStruct(interp, objv[1], cmdOpts, sizeof(char *), "option", 0, &opt);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    /*
     * Cover the "create" option first, since it needs no existing name.
     */

    if (opt == (int)w_CREATE) {
        Tcl_Obj *nameObj;
        if (objc > 2) {
            Tcl_WrongNumArgs(interp, 1, objv, "create");
            return TCL_ERROR;
        }
        mutexPtr = (SpMutex *)Tcl_Alloc(sizeof(SpMutex));
        mutexPtr->type   = WMUTEXID;
        mutexPtr->refcnt = 0;
        mutexPtr->bucket = NULL;
        mutexPtr->hentry = NULL;
        mutexPtr->lock   = NULL; /* Will be auto-initialized */
    if (opt == w_CREATE) {
	Tcl_Obj *nameObj;
	if (objc > 2) {
	    Tcl_WrongNumArgs(interp, 1, objv, "create");
	    return TCL_ERROR;
	}
	mutexPtr = (SpMutex *)Tcl_Alloc(sizeof(SpMutex));
	mutexPtr->type   = WMUTEXID;
	mutexPtr->refcnt = 0;
	mutexPtr->bucket = NULL;
	mutexPtr->hentry = NULL;
	mutexPtr->lock   = NULL; /* Will be auto-initialized */

        nameObj = GetName(mutexPtr->type, (void*)mutexPtr);
        mutexName = Tcl_GetString(nameObj);
        AddMutex(mutexName, nameObj->length, mutexPtr);
        Tcl_SetObjResult(interp, nameObj);
        return TCL_OK;
	nameObj = GetName(mutexPtr->type, (void*)mutexPtr);
	mutexName = Tcl_GetStringFromObj(nameObj, &nameLen);
	AddMutex(mutexName, nameLen, mutexPtr);
	Tcl_SetObjResult(interp, nameObj);
	return TCL_OK;
    }

    /*
     * All other options require a valid name.
     */

    if (objc != 3) {
        Tcl_WrongNumArgs(interp, 2, objv, "mutexHandle");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 2, objv, "mutexHandle");
	return TCL_ERROR;
    }

    mutexName = Tcl_GetString(objv[2]);
    mutexName = Tcl_GetStringFromObj(objv[2], &nameLen);
    nameLen = objv[2]->length;

    /*
     * Try mutex destroy
     */

    if (opt == (int)w_DESTROY) {
        ret = RemoveMutex(mutexName, nameLen);
        if (ret <= 0) {
            if (ret == -1) {
            notfound:
                Tcl_AppendResult(interp, "no such mutex \"", mutexName,
                                 "\"", NULL);
                return TCL_ERROR;
            } else {
                Tcl_AppendResult(interp, "mutex is in use", NULL);
                return TCL_ERROR;
            }
        }
        return TCL_OK;
    if (opt == w_DESTROY) {
	ret = RemoveMutex(mutexName, nameLen);
	if (ret <= 0) {
	    if (ret == -1) {
	    notfound:
		Tcl_AppendResult(interp, "no such mutex \"", mutexName,
				 "\"", (void *)NULL);
		return TCL_ERROR;
	    } else {
		Tcl_AppendResult(interp, "mutex is in use", (void *)NULL);
		return TCL_ERROR;
	    }
	}
	return TCL_OK;
    }

    /*
     * Try all other options
     */

    mutexPtr = GetMutex(mutexName, nameLen);
    if (mutexPtr == NULL) {
        goto notfound;
	goto notfound;
    }
    if (!IsReadWrite(mutexPtr)) {
        PutMutex(mutexPtr);
        Tcl_AppendResult(interp, "wrong mutex type, must be readwrite", NULL);
        return TCL_ERROR;
	PutMutex(mutexPtr);
	Tcl_AppendResult(interp, "wrong mutex type, must be readwrite", (void *)NULL);
	return TCL_ERROR;
    }

    lockPtr = &mutexPtr->lock;
    rwPtr = (Sp_ReadWriteMutex*) lockPtr;

    switch ((enum options)opt) {
    switch (opt) {
    case w_RLOCK:
        if (!Sp_ReadWriteMutexRLock(rwPtr)) {
            PutMutex(mutexPtr);
            Tcl_AppendResult(interp, "read-locking already write-locked mutex ",
                             "from the same thread", NULL);
            return TCL_ERROR;
        }
        break;
	if (!Sp_ReadWriteMutexRLock(rwPtr)) {
	    PutMutex(mutexPtr);
	    Tcl_AppendResult(interp, "read-locking already write-locked mutex ",
			     "from the same thread", (void *)NULL);
	    return TCL_ERROR;
	}
	break;
    case w_WLOCK:
        if (!Sp_ReadWriteMutexWLock(rwPtr)) {
            PutMutex(mutexPtr);
            Tcl_AppendResult(interp, "write-locking the same read-write "
                             "mutex twice from the same thread", NULL);
            return TCL_ERROR;
        }
        break;
	if (!Sp_ReadWriteMutexWLock(rwPtr)) {
	    PutMutex(mutexPtr);
	    Tcl_AppendResult(interp, "write-locking the same read-write "
			     "mutex twice from the same thread", (void *)NULL);
	    return TCL_ERROR;
	}
	break;
    case w_UNLOCK:
        if (!Sp_ReadWriteMutexUnlock(rwPtr)) {
            PutMutex(mutexPtr);
            Tcl_AppendResult(interp, "mutex is not locked", NULL);
            return TCL_ERROR;
        }
        break;
	if (!Sp_ReadWriteMutexUnlock(rwPtr)) {
	    PutMutex(mutexPtr);
	    Tcl_AppendResult(interp, "mutex is not locked", (void *)NULL);
	    return TCL_ERROR;
	}
	break;
    default:
        break;
	break;
    }

    PutMutex(mutexPtr);

    return TCL_OK;
}

515
516
517
518
519
520
521
522

523
524

525
526
527
528


529
530
531
532
533
534

535
536
537
538


539
540
541
542
543
544
545
546
547
548
549
550
551
552


553
554
555
556

557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574












575
576
577
578
579
580





581
582
583
584
585
586
587
588
589


590
591
592

593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612














613
614
615
616
617
618
619
620
621

622
623
624

625
626
627
628
629
630
631
632






633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660



























661
662
663


664
665

666
667
668
669
670
671
672
509
510
511
512
513
514
515

516
517

518
519
520


521
522
523
524
525
526
527

528
529
530


531
532

533
534
535
536
537
538
539
540
541
542
543


544
545
546
547
548

549
550
551
552
553
554
555












556
557
558
559
560
561
562
563
564
565
566
567
568





569
570
571
572
573
574
575
576
577
578
579
580


581
582
583
584

585

586
587
588
589
590














591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612

613
614
615

616
617
618






619
620
621
622
623
624
625



























626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653


654
655
656

657
658
659
660
661
662
663
664







-
+

-
+


-
-
+
+





-
+


-
-
+
+
-











-
-
+
+



-
+






-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+







-
-
+
+


-
+
-





-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+








-
+


-
+


-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
+
+

-
+







 *    See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadCondObjCmd(
    void *dummy,                       /* Not used. */
    TCL_UNUSED(void *),                /* Not used. */
    Tcl_Interp *interp,                /* Current interpreter. */
    int objc,                          /* Number of arguments. */
    Tcl_Size objc,                          /* Number of arguments. */
    Tcl_Obj *const objv[]              /* Argument objects. */
) {
    int opt, ret, timeMsec = 0;
    size_t nameLen;
    int ret, timeMsec = 0;
    Tcl_Size nameLen;
    const char *condvName, *mutexName;
    SpMutex *mutexPtr;
    SpCondv *condvPtr;

    static const char *const cmdOpts[] = {
        "create", "destroy", "notify", "wait", NULL
	"create", "destroy", "notify", "wait", NULL
    };
    enum options {
        c_CREATE, c_DESTROY, c_NOTIFY, c_WAIT
    };
	c_CREATE, c_DESTROY, c_NOTIFY, c_WAIT
    } opt;
    (void)dummy;

    /*
     * Syntax:
     *
     *    thread::cond create
     *    thread::cond destroy <condHandle>
     *    thread::cond notify <condHandle>
     *    thread::cond wait <condHandle> <mutexHandle> ?timeout?
     */

    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "option ?args?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "option ?args?");
	return TCL_ERROR;
    }
    ret = Tcl_GetIndexFromObjStruct(interp, objv[1], cmdOpts, sizeof(char *), "option", 0, &opt);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    /*
     * Cover the "create" option since it needs no existing name.
     */

    if (opt == (int)c_CREATE) {
        Tcl_Obj *nameObj;
        if (objc > 2) {
            Tcl_WrongNumArgs(interp, 1, objv, "create");
            return TCL_ERROR;
        }
        condvPtr = (SpCondv *)Tcl_Alloc(sizeof(SpCondv));
        condvPtr->refcnt = 0;
        condvPtr->bucket = NULL;
        condvPtr->hentry = NULL;
        condvPtr->mutex  = NULL;
        condvPtr->cond   = NULL; /* Will be auto-initialized */
    if (opt == c_CREATE) {
	Tcl_Obj *nameObj;
	if (objc > 2) {
	    Tcl_WrongNumArgs(interp, 1, objv, "create");
	    return TCL_ERROR;
	}
	condvPtr = (SpCondv *)Tcl_Alloc(sizeof(SpCondv));
	condvPtr->refcnt = 0;
	condvPtr->bucket = NULL;
	condvPtr->hentry = NULL;
	condvPtr->mutex  = NULL;
	condvPtr->cond   = NULL; /* Will be auto-initialized */

        nameObj = GetName(CONDVID, (void*)condvPtr);
        condvName = Tcl_GetString(nameObj);
        AddCondv(condvName, nameObj->length, condvPtr);
        Tcl_SetObjResult(interp, nameObj);
        return TCL_OK;
	nameObj = GetName(CONDVID, (void*)condvPtr);
	condvName = Tcl_GetString(nameObj);
	AddCondv(condvName, nameObj->length, condvPtr);
	Tcl_SetObjResult(interp, nameObj);
	return TCL_OK;
    }

    /*
     * All others require at least a valid handle.
     */

    if (objc < 3) {
        Tcl_WrongNumArgs(interp, 2, objv, "condHandle ?args?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 2, objv, "condHandle ?args?");
	return TCL_ERROR;
    }

    condvName = Tcl_GetString(objv[2]);
    condvName = Tcl_GetStringFromObj(objv[2], &nameLen);
    nameLen = objv[2]->length;

    /*
     * Try variable destroy.
     */

    if (opt == (int)c_DESTROY) {
        ret = RemoveCondv(condvName, nameLen);
        if (ret <= 0) {
            if (ret == -1) {
            notfound:
                Tcl_AppendResult(interp, "no such condition variable \"",
                                 condvName, "\"", NULL);
                return TCL_ERROR;
            } else {
                Tcl_AppendResult(interp, "condition variable is in use", NULL);
                return TCL_ERROR;
            }
        }
        return TCL_OK;
    if (opt == c_DESTROY) {
	ret = RemoveCondv(condvName, nameLen);
	if (ret <= 0) {
	    if (ret == -1) {
	    notfound:
		Tcl_AppendResult(interp, "no such condition variable \"",
				 condvName, "\"", (void *)NULL);
		return TCL_ERROR;
	    } else {
		Tcl_AppendResult(interp, "condition variable is in use", (void *)NULL);
		return TCL_ERROR;
	    }
	}
	return TCL_OK;
    }

    /*
     * Try all other options
     */

    condvPtr = GetCondv(condvName, nameLen);
    if (condvPtr == NULL) {
        goto notfound;
	goto notfound;
    }

    switch ((enum options)opt) {
    switch (opt) {
    case c_WAIT:

        /*
         * May improve the Tcl_ConditionWait() to report timeouts so we can
         * inform script programmer about this interesting fact. I think
         * there is still a place for something like Tcl_ConditionWaitEx()
         * or similar in the core.
         */
	/*
	 * May improve the Tcl_ConditionWait() to report timeouts so we can
	 * inform script programmer about this interesting fact. I think
	 * there is still a place for something like Tcl_ConditionWaitEx()
	 * or similar in the core.
	 */

        if (objc < 4 || objc > 5) {
            PutCondv(condvPtr);
            Tcl_WrongNumArgs(interp, 2, objv, "condHandle mutexHandle ?timeout?");
            return TCL_ERROR;
        }
        if (objc == 5) {
            if (Tcl_GetIntFromObj(interp, objv[4], &timeMsec) != TCL_OK) {
                PutCondv(condvPtr);
                return TCL_ERROR;
            }
        }
        mutexName = Tcl_GetString(objv[3]);
        mutexPtr  = GetMutex(mutexName, objv[3]->length);
        if (mutexPtr == NULL) {
            PutCondv(condvPtr);
            Tcl_AppendResult(interp, "no such mutex \"",mutexName,"\"", NULL);
            return TCL_ERROR;
        }
        if (!IsExclusive(mutexPtr)
            || SpCondvWait(condvPtr, mutexPtr, timeMsec) == 0) {
            PutCondv(condvPtr);
            PutMutex(mutexPtr);
            Tcl_AppendResult(interp, "mutex not locked or wrong type", NULL);
            return TCL_ERROR;
        }
        PutMutex(mutexPtr);
        break;
	if (objc < 4 || objc > 5) {
	    PutCondv(condvPtr);
	    Tcl_WrongNumArgs(interp, 2, objv, "condHandle mutexHandle ?timeout?");
	    return TCL_ERROR;
	}
	if (objc == 5) {
	    if (Tcl_GetIntFromObj(interp, objv[4], &timeMsec) != TCL_OK) {
		PutCondv(condvPtr);
		return TCL_ERROR;
	    }
	}
	mutexName = Tcl_GetString(objv[3]);
	mutexPtr  = GetMutex(mutexName, objv[3]->length);
	if (mutexPtr == NULL) {
	    PutCondv(condvPtr);
	    Tcl_AppendResult(interp, "no such mutex \"",mutexName,"\"", (void *)NULL);
	    return TCL_ERROR;
	}
	if (!IsExclusive(mutexPtr)
	    || SpCondvWait(condvPtr, mutexPtr, timeMsec) == 0) {
	    PutCondv(condvPtr);
	    PutMutex(mutexPtr);
	    Tcl_AppendResult(interp, "mutex not locked or wrong type", (void *)NULL);
	    return TCL_ERROR;
	}
	PutMutex(mutexPtr);
	break;
    case c_NOTIFY:
        SpCondvNotify(condvPtr);
        break;
	SpCondvNotify(condvPtr);
	break;
    default:
        break;
	break;
    }

    PutCondv(condvPtr);

    return TCL_OK;
}
/*
684
685
686
687
688
689
690
691

692
693

694
695
696


697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713



714
715
716
717

718
719
720
721
722
723
724
725
726
727
728
729
730



731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752























753
754
755
756
757
758
759
760
761
762
763
764
765

766
767

768
769
770
771
772
773
774
775

776
777
778
779


780
781
782
783
784
785
786
787

788
789


790
791
792
793
794
795
796
676
677
678
679
680
681
682

683
684

685
686
687

688
689
690
691
692
693

694
695
696
697
698
699
700
701
702



703
704
705
706
707
708

709
710
711
712
713
714
715
716
717
718
719



720
721
722
723





















724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758

759
760

761
762
763
764
765
766
767
768

769




770
771
772
773
774
775
776
777
778

779
780

781
782
783
784
785
786
787
788
789







-
+

-
+


-
+
+




-









-
-
-
+
+
+



-
+










-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+












-
+

-
+







-
+
-
-
-
-
+
+







-
+

-
+
+







 *    See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
ThreadEvalObjCmd(
    void *dummy,                       /* Not used. */
    TCL_UNUSED(void *),                /* Not used. */
    Tcl_Interp *interp,                /* Current interpreter. */
    int objc,                          /* Number of arguments. */
    Tcl_Size objc,                          /* Number of arguments. */
    Tcl_Obj *const objv[]              /* Argument objects. */
) {
    int ret, optx, internal;
    int ret, internal;
    Tcl_Size optx;
    const char *mutexName;
    Tcl_Obj *scriptObj;
    SpMutex *mutexPtr = NULL;
    static Sp_RecursiveMutex evalMutex;
    (void)dummy;

    /*
     * Syntax:
     *
     *     thread::eval ?-lock <mutexHandle>? arg ?arg ...?
     */

    if (objc < 2) {
      syntax:
        Tcl_WrongNumArgs(interp, 1, objv,
                         "?-lock <mutexHandle>? arg ?arg...?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv,
			 "?-lock <mutexHandle>? arg ?arg...?");
	return TCL_ERROR;
    }

    /*
     * Find out wether to use the internal (recursive) mutex
     * Find out whether to use the internal (recursive) mutex
     * or external mutex given on the command line, and lock
     * the corresponding mutex immediately.
     *
     * We are using recursive internal mutex so we can easily
     * support the recursion w/o danger of deadlocking. If
     * however, user gives us an exclusive mutex, we will
     * throw error on attempt to recursively call us.
     */

    if (OPT_CMP(Tcl_GetString(objv[1]), "-lock") == 0) {
        internal = 1;
        optx = 1;
        Sp_RecursiveMutexLock(&evalMutex);
	internal = 1;
	optx = 1;
	Sp_RecursiveMutexLock(&evalMutex);
    } else {
        internal = 0;
        optx = 3;
        if ((objc - optx) < 1) {
            goto syntax;
        }
        mutexName = Tcl_GetString(objv[2]);
        mutexPtr  = GetMutex(mutexName, objv[2]->length);
        if (mutexPtr == NULL) {
            Tcl_AppendResult(interp, "no such mutex \"",mutexName,"\"", NULL);
            return TCL_ERROR;
        }
        if (IsReadWrite(mutexPtr)) {
            Tcl_AppendResult(interp, "wrong mutex type, must be exclusive "
                             "or recursive", NULL);
            return TCL_ERROR;
        }
        if (!SpMutexLock(mutexPtr)) {
            Tcl_AppendResult(interp, "locking the same exclusive mutex "
                             "twice from the same thread", NULL);
            return TCL_ERROR;
        }
	internal = 0;
	optx = 3;
	if (objc < 1 + optx) {
	    goto syntax;
	}
	mutexName = Tcl_GetString(objv[2]);
	mutexPtr  = GetMutex(mutexName, objv[2]->length);
	if (mutexPtr == NULL) {
	    Tcl_AppendResult(interp, "no such mutex \"",mutexName,"\"", (void *)NULL);
	    return TCL_ERROR;
	}
	if (IsReadWrite(mutexPtr)) {
            PutMutex(mutexPtr);
	    Tcl_AppendResult(interp, "wrong mutex type, must be exclusive "
			     "or recursive", (void *)NULL);
	    return TCL_ERROR;
	}
	if (!SpMutexLock(mutexPtr)) {
            PutMutex(mutexPtr);
	    Tcl_AppendResult(interp, "locking the same exclusive mutex "
			     "twice from the same thread", (void *)NULL);
	    return TCL_ERROR;
	}
    }

    objc -= optx;

    /*
     * Evaluate passed arguments as Tcl script. Note that
     * Tcl_EvalObjEx throws away the passed object by
     * doing an decrement reference count on it. This also
     * means we need not build object bytecode rep.
     */

    if (objc == 1) {
        scriptObj = Tcl_DuplicateObj(objv[optx]);
	scriptObj = Tcl_DuplicateObj(objv[optx]);
    } else {
        scriptObj = Tcl_ConcatObj(objc, objv + optx);
	scriptObj = Tcl_ConcatObj(objc, objv + optx);
    }

    Tcl_IncrRefCount(scriptObj);
    ret = Tcl_EvalObjEx(interp, scriptObj, TCL_EVAL_DIRECT);
    Tcl_DecrRefCount(scriptObj);

    if (ret == TCL_ERROR) {
        char msg[32 + TCL_INTEGER_SPACE];
	char msg[32 + TCL_INTEGER_SPACE];
        /* Next line generates a Deprecation warning when compiled with Tcl 8.6.
         * See Tcl bug #3562640 */
        sprintf(msg, "\n    (\"eval\" body line %d)", Tcl_GetErrorLine(interp));
        Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(msg, TCL_AUTO_LENGTH));
	snprintf(msg, sizeof(msg), "\n    (\"eval\" body line %d)", Tcl_GetErrorLine(interp));
	Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(msg, TCL_INDEX_NONE));
    }

    /*
     * Unlock the mutex.
     */

    if (internal) {
        Sp_RecursiveMutexUnlock(&evalMutex);
	Sp_RecursiveMutexUnlock(&evalMutex);
    } else {
        SpMutexUnlock(mutexPtr);
	SpMutexUnlock(mutexPtr);
        PutMutex(mutexPtr);
    }

    return ret;
}

/*
 *----------------------------------------------------------------------
808
809
810
811
812
813
814
815



816
817
818
819


820
821
822
823
824
825
826

827
828

829
830
831
832
833
834
835
801
802
803
804
805
806
807

808
809
810
811
812


813
814

815
816
817
818
819

820
821

822
823
824
825
826
827
828
829







-
+
+
+


-
-
+
+
-





-
+

-
+







 * Side effects:
 *      None.
 *
 *----------------------------------------------------------------------
 */

static Tcl_Obj*
GetName(int type, void *dummy)
GetName(
    int type,
    TCL_UNUSED(void *))
{
    char name[32];
    unsigned int id;
    static unsigned int idcounter;
    size_t id;
    static size_t idcounter;
    (void)dummy;

    Tcl_MutexLock(&initMutex);
    id = idcounter++;
    Tcl_MutexUnlock(&initMutex);

    sprintf(name, "%cid%d", type, id);
    snprintf(name, sizeof(name), "%cid%" TCL_Z_MODIFIER "u", type, id);

    return Tcl_NewStringObj(name, -1);
    return Tcl_NewStringObj(name, TCL_INDEX_NONE);
}

/*
 *----------------------------------------------------------------------
 *
 * GetBucket --
 *
877
878
879
880
881
882
883
884
885


886
887
888
889
890
891
892
871
872
873
874
875
876
877


878
879
880
881
882
883
884
885
886







-
-
+
+







    SpItem *itemPtr = NULL;
    SpBucket *bucketPtr = GetBucket(type, name, len);
    Tcl_HashEntry *hashEntryPtr = NULL;

    Tcl_MutexLock(&bucketPtr->lock);
    hashEntryPtr = Tcl_FindHashEntry(&bucketPtr->handles, name);
    if (hashEntryPtr != NULL) {
        itemPtr = (SpItem*)Tcl_GetHashValue(hashEntryPtr);
        itemPtr->refcnt++;
	itemPtr = (SpItem*)Tcl_GetHashValue(hashEntryPtr);
	itemPtr->refcnt++;
    }
    Tcl_MutexUnlock(&bucketPtr->lock);

    return itemPtr;
}

/*
972
973
974
975
976
977
978
979
980


981
982
983
984
985

986
987
988
989
990
991
992
966
967
968
969
970
971
972


973
974
975
976
977
978

979
980
981
982
983
984
985
986







-
-
+
+




-
+







    SpItem *itemPtr = NULL;
    SpBucket *bucketPtr = GetBucket(type, name, len);
    Tcl_HashEntry *hashEntryPtr = NULL;

    Tcl_MutexLock(&bucketPtr->lock);
    hashEntryPtr = Tcl_FindHashEntry(&bucketPtr->handles, name);
    if (hashEntryPtr == NULL) {
        Tcl_MutexUnlock(&bucketPtr->lock);
        return NULL;
	Tcl_MutexUnlock(&bucketPtr->lock);
	return NULL;
    }
    itemPtr = (SpItem*)Tcl_GetHashValue(hashEntryPtr);
    Tcl_DeleteHashEntry(hashEntryPtr);
    while (itemPtr->refcnt > 0) {
        Tcl_ConditionWait(&bucketPtr->cond, &bucketPtr->lock, NULL);
	Tcl_ConditionWait(&bucketPtr->cond, &bucketPtr->lock, NULL);
    }
    Tcl_MutexUnlock(&bucketPtr->lock);

    return itemPtr;
}

/*
1008
1009
1010
1011
1012
1013
1014
1015

1016
1017
1018
1019


1020
1021
1022
1023
1024
1025
1026
1002
1003
1004
1005
1006
1007
1008

1009
1010
1011


1012
1013
1014
1015
1016
1017
1018
1019
1020







-
+


-
-
+
+







 */

static int
RemoveMutex(const char *name, size_t len)
{
    SpMutex *mutexPtr = GetMutex(name, len);
    if (mutexPtr == NULL) {
        return -1;
	return -1;
    }
    if (!SpMutexFinalize(mutexPtr)) {
        PutMutex(mutexPtr);
        return 0;
	PutMutex(mutexPtr);
	return 0;
    }
    PutMutex(mutexPtr);
    RemoveAnyItem(SP_MUTEX, name, len);
    Tcl_Free(mutexPtr);

    return 1;
}
1044
1045
1046
1047
1048
1049
1050
1051

1052
1053
1054
1055


1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067

1068
1069
1070
1071
1072

1073
1074
1075
1076
1077
1078
1079
1080
1081
1082


1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
















1104
1105
1106
1107
1108
1109
1110
1111

1112
1113
1114
1115
1116
1117
1118
1038
1039
1040
1041
1042
1043
1044

1045
1046
1047


1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060

1061
1062
1063
1064
1065

1066
1067
1068
1069
1070
1071
1072
1073
1074


1075
1076
1077
1078
1079
1080
1081
















1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104

1105
1106
1107
1108
1109
1110
1111
1112







-
+


-
-
+
+











-
+




-
+








-
-
+
+





-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+







 */

static int
RemoveCondv(const char *name, size_t len)
{
    SpCondv *condvPtr = GetCondv(name, len);
    if (condvPtr == NULL) {
        return -1;
	return -1;
    }
    if (!SpCondvFinalize(condvPtr)) {
        PutCondv(condvPtr);
        return 0;
	PutCondv(condvPtr);
	return 0;
    }
    PutCondv(condvPtr);
    RemoveAnyItem(SP_CONDV, name, len);
    Tcl_Free(condvPtr);

    return 1;
}

/*
 *----------------------------------------------------------------------
 *
 * Sp_Init --
 * SpInit --
 *
 *      Create commands in current interpreter.
 *
 * Results:
 *      Standard Tcl result.
 *      NULL
 *
 * Side effects:
 *      Initializes shared hash table for storing sync primitive
 *      handles and pointers.
 *
 *----------------------------------------------------------------------
 */

int
Sp_Init (
const char *
SpInit (
    Tcl_Interp *interp                 /* Interp where to create cmds */
) {
    SpBucket *bucketPtr;

    if (!initOnce) {
        Tcl_MutexLock(&initMutex);
        if (!initOnce) {
            int ii;
            for (ii = 0; ii < NUMSPBUCKETS; ii++) {
                bucketPtr = &muxBuckets[ii];
                memset(bucketPtr, 0, sizeof(SpBucket));
                Tcl_InitHashTable(&bucketPtr->handles, TCL_STRING_KEYS);
            }
            for (ii = 0; ii < NUMSPBUCKETS; ii++) {
                bucketPtr = &varBuckets[ii];
                memset(bucketPtr, 0, sizeof(SpBucket));
                Tcl_InitHashTable(&bucketPtr->handles, TCL_STRING_KEYS);
            }
            initOnce = 1;
        }
        Tcl_MutexUnlock(&initMutex);
	Tcl_MutexLock(&initMutex);
	if (!initOnce) {
	    int ii;
	    for (ii = 0; ii < NUMSPBUCKETS; ii++) {
		bucketPtr = &muxBuckets[ii];
		memset(bucketPtr, 0, sizeof(SpBucket));
		Tcl_InitHashTable(&bucketPtr->handles, TCL_STRING_KEYS);
	    }
	    for (ii = 0; ii < NUMSPBUCKETS; ii++) {
		bucketPtr = &varBuckets[ii];
		memset(bucketPtr, 0, sizeof(SpBucket));
		Tcl_InitHashTable(&bucketPtr->handles, TCL_STRING_KEYS);
	    }
	    initOnce = 1;
	}
	Tcl_MutexUnlock(&initMutex);
    }

    TCL_CMD(interp, THREAD_CMD_PREFIX"::mutex",   ThreadMutexObjCmd);
    TCL_CMD(interp, THREAD_CMD_PREFIX"::rwmutex", ThreadRWMutexObjCmd);
    TCL_CMD(interp, THREAD_CMD_PREFIX"::cond",    ThreadCondObjCmd);
    TCL_CMD(interp, THREAD_CMD_PREFIX"::eval",    ThreadEvalObjCmd);

    return TCL_OK;
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
 * SpMutexLock --
 *
1131
1132
1133
1134
1135
1136
1137
1138
1139


1140
1141
1142


1143
1144
1145
1146
1147
1148
1149
1125
1126
1127
1128
1129
1130
1131


1132
1133
1134


1135
1136
1137
1138
1139
1140
1141
1142
1143







-
-
+
+

-
-
+
+







static int
SpMutexLock(SpMutex *mutexPtr)
{
    Sp_AnyMutex **lockPtr = &mutexPtr->lock;

    switch (mutexPtr->type) {
    case EMUTEXID:
        return Sp_ExclusiveMutexLock((Sp_ExclusiveMutex*)lockPtr);
        break;
	return Sp_ExclusiveMutexLock((Sp_ExclusiveMutex*)lockPtr);
	break;
    case RMUTEXID:
        return Sp_RecursiveMutexLock((Sp_RecursiveMutex*)lockPtr);
        break;
	return Sp_RecursiveMutexLock((Sp_RecursiveMutex*)lockPtr);
	break;
    }

    return 0;
}

/*
 *----------------------------------------------------------------------
1165
1166
1167
1168
1169
1170
1171
1172
1173


1174
1175
1176


1177
1178
1179
1180
1181
1182
1183
1159
1160
1161
1162
1163
1164
1165


1166
1167
1168


1169
1170
1171
1172
1173
1174
1175
1176
1177







-
-
+
+

-
-
+
+







static int
SpMutexUnlock(SpMutex *mutexPtr)
{
    Sp_AnyMutex **lockPtr = &mutexPtr->lock;

    switch (mutexPtr->type) {
    case EMUTEXID:
        return Sp_ExclusiveMutexUnlock((Sp_ExclusiveMutex*)lockPtr);
        break;
	return Sp_ExclusiveMutexUnlock((Sp_ExclusiveMutex*)lockPtr);
	break;
    case RMUTEXID:
        return Sp_RecursiveMutexUnlock((Sp_RecursiveMutex*)lockPtr);
        break;
	return Sp_RecursiveMutexUnlock((Sp_RecursiveMutex*)lockPtr);
	break;
    }

    return 0;
}

/*
 *----------------------------------------------------------------------
1199
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217


1218
1219
1220


1221
1222
1223


1224
1225

1226
1227
1228
1229
1230
1231
1232
1193
1194
1195
1196
1197
1198
1199

1200
1201
1202
1203
1204
1205
1206
1207
1208
1209


1210
1211
1212


1213
1214
1215


1216
1217
1218

1219
1220
1221
1222
1223
1224
1225
1226







-
+









-
-
+
+

-
-
+
+

-
-
+
+

-
+








static int
SpMutexFinalize(SpMutex *mutexPtr)
{
    Sp_AnyMutex **lockPtr = &mutexPtr->lock;

    if (AnyMutexIsLocked((Sp_AnyMutex*)mutexPtr->lock, NULL)) {
        return 0;
	return 0;
    }

    /*
     * At this point, the mutex could be locked again, hence it
     * is important never to call this function unprotected.
     */

    switch (mutexPtr->type) {
    case EMUTEXID:
        Sp_ExclusiveMutexFinalize((Sp_ExclusiveMutex*)lockPtr);
        break;
	Sp_ExclusiveMutexFinalize((Sp_ExclusiveMutex*)lockPtr);
	break;
    case RMUTEXID:
        Sp_RecursiveMutexFinalize((Sp_RecursiveMutex*)lockPtr);
        break;
	Sp_RecursiveMutexFinalize((Sp_RecursiveMutex*)lockPtr);
	break;
    case WMUTEXID:
        Sp_ReadWriteMutexFinalize((Sp_ReadWriteMutex*)lockPtr);
        break;
	Sp_ReadWriteMutexFinalize((Sp_ReadWriteMutex*)lockPtr);
	break;
    default:
        break;
	break;
    }

    return 1;
}

/*
 *----------------------------------------------------------------------
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259



1260
1261
1262

1263
1264
1265
1266
1267
1268
1269
1244
1245
1246
1247
1248
1249
1250



1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262
1263







-
-
-
+
+
+


-
+







{
    Sp_AnyMutex **lock = &mutexPtr->lock;
    Sp_ExclusiveMutex_ *emPtr = *(Sp_ExclusiveMutex_**)lock;
    Tcl_Time waitTime, *wt = NULL;
    Tcl_ThreadId threadId = Tcl_GetCurrentThread();

    if (msec > 0) {
        wt = &waitTime;
        wt->sec  = (msec/1000);
        wt->usec = (msec%1000) * 1000;
	wt = &waitTime;
	wt->sec  = (msec/1000);
	wt->usec = (msec%1000) * 1000;
    }
    if (!AnyMutexIsLocked((Sp_AnyMutex*)mutexPtr->lock, threadId)) {
        return 0; /* Mutex not locked by the current thread */
	return 0; /* Mutex not locked by the current thread */
    }

    /*
     * It is safe to operate on mutex struct because caller
     * is holding the emPtr->mutex locked before we enter
     * the Tcl_ConditionWait and after we return out of it.
     */
1299
1300
1301
1302
1303
1304
1305
1306

1307
1308
1309
1310
1311
1312
1313
1293
1294
1295
1296
1297
1298
1299

1300
1301
1302
1303
1304
1305
1306
1307







-
+







 *----------------------------------------------------------------------
 */

static void
SpCondvNotify(SpCondv *condvPtr)
{
    if (condvPtr->cond) {
        Tcl_ConditionNotify(&condvPtr->cond);
	Tcl_ConditionNotify(&condvPtr->cond);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * SpCondvFinalize --
1324
1325
1326
1327
1328
1329
1330
1331

1332
1333
1334
1335

1336
1337
1338
1339
1340
1341
1342
1318
1319
1320
1321
1322
1323
1324

1325
1326
1327
1328

1329
1330
1331
1332
1333
1334
1335
1336







-
+



-
+







 *----------------------------------------------------------------------
 */

static int
SpCondvFinalize(SpCondv *condvPtr)
{
    if (condvPtr->mutex != NULL) {
        return 0; /* Somebody is waiting on the variable */
	return 0; /* Somebody is waiting on the variable */
    }

    if (condvPtr->cond) {
        Tcl_ConditionFinalize(&condvPtr->cond);
	Tcl_ConditionFinalize(&condvPtr->cond);
    }

    return 1;
}

/*
 *----------------------------------------------------------------------
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374






1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385


1386
1387
1388
1389
1390
1391
1392
1356
1357
1358
1359
1360
1361
1362






1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377


1378
1379
1380
1381
1382
1383
1384
1385
1386







-
-
-
-
-
-
+
+
+
+
+
+









-
-
+
+







    Tcl_ThreadId thisThread = Tcl_GetCurrentThread();

    /*
     * Allocate the mutex structure on first access
     */

    if (*muxPtr == NULL) {
        Tcl_MutexLock(&initMutex);
        if (*muxPtr == NULL) {
            *muxPtr = (Sp_ExclusiveMutex_ *)Tcl_Alloc(sizeof(Sp_ExclusiveMutex_));
            memset(*muxPtr, 0, sizeof(Sp_ExclusiveMutex_));
        }
        Tcl_MutexUnlock(&initMutex);
	Tcl_MutexLock(&initMutex);
	if (*muxPtr == NULL) {
	    *muxPtr = (Sp_ExclusiveMutex_ *)Tcl_Alloc(sizeof(Sp_ExclusiveMutex_));
	    memset(*muxPtr, 0, sizeof(Sp_ExclusiveMutex_));
	}
	Tcl_MutexUnlock(&initMutex);
    }

    /*
     * Try locking if not currently locked by anybody.
     */

    emPtr = *(Sp_ExclusiveMutex_**)muxPtr;
    Tcl_MutexLock(&emPtr->lock);
    if (emPtr->lockcount && emPtr->owner == thisThread) {
        Tcl_MutexUnlock(&emPtr->lock);
        return 0; /* Already locked by the same thread */
	Tcl_MutexUnlock(&emPtr->lock);
	return 0; /* Already locked by the same thread */
    }
    Tcl_MutexUnlock(&emPtr->lock);

    /*
     * Many threads can come to this point.
     * Only one will succeed locking the
     * mutex. Others will block...
1444
1445
1446
1447
1448
1449
1450
1451

1452
1453
1454
1455
1456
1457
1458
1459


1460
1461
1462
1463
1464
1465
1466
1438
1439
1440
1441
1442
1443
1444

1445
1446
1447
1448
1449
1450
1451


1452
1453
1454
1455
1456
1457
1458
1459
1460







-
+






-
-
+
+








int
Sp_ExclusiveMutexUnlock(Sp_ExclusiveMutex *muxPtr)
{
    Sp_ExclusiveMutex_ *emPtr;

    if (*muxPtr == (Sp_ExclusiveMutex_*)0) {
        return 0; /* Never locked before */
	return 0; /* Never locked before */
    }

    emPtr = *(Sp_ExclusiveMutex_**)muxPtr;

    Tcl_MutexLock(&emPtr->lock);
    if (emPtr->lockcount == 0) {
        Tcl_MutexUnlock(&emPtr->lock);
        return 0; /* Not locked */
	Tcl_MutexUnlock(&emPtr->lock);
	return 0; /* Not locked */
    }
    emPtr->owner = NULL;
    emPtr->lockcount = 0;
    Tcl_MutexUnlock(&emPtr->lock);

    /*
     * Only one thread should be able
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503








1504
1505
1506
1507
1508
1509
1510
1483
1484
1485
1486
1487
1488
1489








1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







 *----------------------------------------------------------------------
 */

void
Sp_ExclusiveMutexFinalize(Sp_ExclusiveMutex *muxPtr)
{
    if (*muxPtr != (Sp_ExclusiveMutex_*)0) {
        Sp_ExclusiveMutex_ *emPtr = *(Sp_ExclusiveMutex_**)muxPtr;
        if (emPtr->lock) {
            Tcl_MutexFinalize(&emPtr->lock);
        }
        if (emPtr->mutex) {
            Tcl_MutexFinalize(&emPtr->mutex);
        }
        Tcl_Free(*muxPtr);
	Sp_ExclusiveMutex_ *emPtr = *(Sp_ExclusiveMutex_**)muxPtr;
	if (emPtr->lock) {
	    Tcl_MutexFinalize(&emPtr->lock);
	}
	if (emPtr->mutex) {
	    Tcl_MutexFinalize(&emPtr->mutex);
	}
	Tcl_Free(*muxPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Sp_RecursiveMutexLock --
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540







1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551





1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571



















1572
1573
1574
1575
1576
1577
1578
1521
1522
1523
1524
1525
1526
1527







1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540





1541
1542
1543
1544
1545
1546



















1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572







-
-
-
-
-
-
-
+
+
+
+
+
+
+






-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    Tcl_ThreadId thisThread = Tcl_GetCurrentThread();

    /*
     * Allocate the mutex structure on first access
     */

    if (*muxPtr == (Sp_RecursiveMutex_*)0) {
        Tcl_MutexLock(&initMutex);
        if (*muxPtr == (Sp_RecursiveMutex_*)0) {
            *muxPtr = (Sp_RecursiveMutex_ *)
                Tcl_Alloc(sizeof(Sp_RecursiveMutex_));
            memset(*muxPtr, 0, sizeof(Sp_RecursiveMutex_));
        }
        Tcl_MutexUnlock(&initMutex);
	Tcl_MutexLock(&initMutex);
	if (*muxPtr == (Sp_RecursiveMutex_*)0) {
	    *muxPtr = (Sp_RecursiveMutex_ *)
		Tcl_Alloc(sizeof(Sp_RecursiveMutex_));
	    memset(*muxPtr, 0, sizeof(Sp_RecursiveMutex_));
	}
	Tcl_MutexUnlock(&initMutex);
    }

    rmPtr = *(Sp_RecursiveMutex_**)muxPtr;
    Tcl_MutexLock(&rmPtr->lock);

    if (rmPtr->owner == thisThread) {
        /*
         * We are already holding the mutex
         * so just count one more lock.
         */
        rmPtr->lockcount++;
	/*
	 * We are already holding the mutex
	 * so just count one more lock.
	 */
	rmPtr->lockcount++;
    } else {
        if (rmPtr->owner == NULL) {
            /*
             * Nobody holds the mutex, we do now.
             */
            rmPtr->owner = thisThread;
            rmPtr->lockcount = 1;
        } else {
            /*
             * Somebody else holds the mutex; wait.
             */
            while (1) {
                Tcl_ConditionWait(&rmPtr->cond, &rmPtr->lock, NULL);
                if (rmPtr->owner == NULL) {
                    rmPtr->owner = thisThread;
                    rmPtr->lockcount = 1;
                    break;
                }
            }
        }
	if (rmPtr->owner == NULL) {
	    /*
	     * Nobody holds the mutex, we do now.
	     */
	    rmPtr->owner = thisThread;
	    rmPtr->lockcount = 1;
	} else {
	    /*
	     * Somebody else holds the mutex; wait.
	     */
	    while (1) {
		Tcl_ConditionWait(&rmPtr->cond, &rmPtr->lock, NULL);
		if (rmPtr->owner == NULL) {
		    rmPtr->owner = thisThread;
		    rmPtr->lockcount = 1;
		    break;
		}
	    }
	}
    }

    Tcl_MutexUnlock(&rmPtr->lock);

    return 1;
}

1618
1619
1620
1621
1622
1623
1624
1625

1626
1627
1628
1629
1630
1631
1632


1633
1634
1635
1636
1637
1638
1639





1640
1641
1642
1643
1644
1645
1646
1612
1613
1614
1615
1616
1617
1618

1619
1620
1621
1622
1623
1624


1625
1626
1627
1628





1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640







-
+





-
-
+
+


-
-
-
-
-
+
+
+
+
+








int
Sp_RecursiveMutexUnlock(Sp_RecursiveMutex *muxPtr)
{
    Sp_RecursiveMutex_ *rmPtr;

    if (*muxPtr == (Sp_RecursiveMutex_*)0) {
        return 0; /* Never locked before */
	return 0; /* Never locked before */
    }

    rmPtr = *(Sp_RecursiveMutex_**)muxPtr;
    Tcl_MutexLock(&rmPtr->lock);
    if (rmPtr->lockcount == 0) {
        Tcl_MutexUnlock(&rmPtr->lock);
        return 0; /* Not locked now */
	Tcl_MutexUnlock(&rmPtr->lock);
	return 0; /* Not locked now */
    }
    if (--rmPtr->lockcount <= 0) {
        rmPtr->lockcount = 0;
        rmPtr->owner = NULL;
        if (rmPtr->cond) {
            Tcl_ConditionNotify(&rmPtr->cond);
        }
	rmPtr->lockcount = 0;
	rmPtr->owner = NULL;
	if (rmPtr->cond) {
	    Tcl_ConditionNotify(&rmPtr->cond);
	}
    }
    Tcl_MutexUnlock(&rmPtr->lock);

    return 1;
}

/*
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674








1675
1676
1677
1678
1679
1680
1681
1654
1655
1656
1657
1658
1659
1660








1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







 *----------------------------------------------------------------------
 */

void
Sp_RecursiveMutexFinalize(Sp_RecursiveMutex *muxPtr)
{
    if (*muxPtr != (Sp_RecursiveMutex_*)0) {
        Sp_RecursiveMutex_ *rmPtr = *(Sp_RecursiveMutex_**)muxPtr;
        if (rmPtr->lock) {
            Tcl_MutexFinalize(&rmPtr->lock);
        }
        if (rmPtr->cond) {
            Tcl_ConditionFinalize(&rmPtr->cond);
        }
        Tcl_Free(*muxPtr);
	Sp_RecursiveMutex_ *rmPtr = *(Sp_RecursiveMutex_**)muxPtr;
	if (rmPtr->lock) {
	    Tcl_MutexFinalize(&rmPtr->lock);
	}
	if (rmPtr->cond) {
	    Tcl_ConditionFinalize(&rmPtr->cond);
	}
	Tcl_Free(*muxPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * Sp_ReadWriteMutexRLock --
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712







1713
1714
1715
1716
1717
1718
1719


1720
1721
1722
1723
1724



1725
1726
1727
1728
1729
1730
1731
1693
1694
1695
1696
1697
1698
1699







1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711


1712
1713
1714
1715



1716
1717
1718
1719
1720
1721
1722
1723
1724
1725







-
-
-
-
-
-
-
+
+
+
+
+
+
+





-
-
+
+


-
-
-
+
+
+







    Tcl_ThreadId thisThread = Tcl_GetCurrentThread();

    /*
     * Allocate the mutex structure on first access
     */

    if (*muxPtr == (Sp_ReadWriteMutex_*)0) {
        Tcl_MutexLock(&initMutex);
        if (*muxPtr == (Sp_ReadWriteMutex_*)0) {
            *muxPtr = (Sp_ReadWriteMutex_ *)
                Tcl_Alloc(sizeof(Sp_ReadWriteMutex_));
            memset(*muxPtr, 0, sizeof(Sp_ReadWriteMutex_));
        }
        Tcl_MutexUnlock(&initMutex);
	Tcl_MutexLock(&initMutex);
	if (*muxPtr == (Sp_ReadWriteMutex_*)0) {
	    *muxPtr = (Sp_ReadWriteMutex_ *)
		Tcl_Alloc(sizeof(Sp_ReadWriteMutex_));
	    memset(*muxPtr, 0, sizeof(Sp_ReadWriteMutex_));
	}
	Tcl_MutexUnlock(&initMutex);
    }

    rwPtr = *(Sp_ReadWriteMutex_**)muxPtr;
    Tcl_MutexLock(&rwPtr->lock);
    if (rwPtr->lockcount == -1 && rwPtr->owner == thisThread) {
        Tcl_MutexUnlock(&rwPtr->lock);
        return 0; /* We already hold the write lock */
	Tcl_MutexUnlock(&rwPtr->lock);
	return 0; /* We already hold the write lock */
    }
    while (rwPtr->lockcount < 0) {
        rwPtr->numrd++;
        Tcl_ConditionWait(&rwPtr->rcond, &rwPtr->lock, NULL);
        rwPtr->numrd--;
	rwPtr->numrd++;
	Tcl_ConditionWait(&rwPtr->rcond, &rwPtr->lock, NULL);
	rwPtr->numrd--;
    }
    rwPtr->lockcount++;
    rwPtr->owner = NULL; /* Many threads can read-lock */
    Tcl_MutexUnlock(&rwPtr->lock);

    return 1;
}
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767







1768
1769
1770
1771
1772
1773
1774


1775
1776
1777
1778
1779



1780
1781
1782
1783
1784
1785
1786
1748
1749
1750
1751
1752
1753
1754







1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766


1767
1768
1769
1770



1771
1772
1773
1774
1775
1776
1777
1778
1779
1780







-
-
-
-
-
-
-
+
+
+
+
+
+
+





-
-
+
+


-
-
-
+
+
+







    Tcl_ThreadId thisThread = Tcl_GetCurrentThread();

    /*
     * Allocate the mutex structure on first access
     */

    if (*muxPtr == (Sp_ReadWriteMutex_*)0) {
        Tcl_MutexLock(&initMutex);
        if (*muxPtr == (Sp_ReadWriteMutex_*)0) {
            *muxPtr = (Sp_ReadWriteMutex_ *)
                Tcl_Alloc(sizeof(Sp_ReadWriteMutex_));
            memset(*muxPtr, 0, sizeof(Sp_ReadWriteMutex_));
        }
        Tcl_MutexUnlock(&initMutex);
	Tcl_MutexLock(&initMutex);
	if (*muxPtr == (Sp_ReadWriteMutex_*)0) {
	    *muxPtr = (Sp_ReadWriteMutex_ *)
		Tcl_Alloc(sizeof(Sp_ReadWriteMutex_));
	    memset(*muxPtr, 0, sizeof(Sp_ReadWriteMutex_));
	}
	Tcl_MutexUnlock(&initMutex);
    }

    rwPtr = *(Sp_ReadWriteMutex_**)muxPtr;
    Tcl_MutexLock(&rwPtr->lock);
    if (rwPtr->owner == thisThread && rwPtr->lockcount == -1) {
        Tcl_MutexUnlock(&rwPtr->lock);
        return 0; /* The same thread attempts to write-lock again */
	Tcl_MutexUnlock(&rwPtr->lock);
	return 0; /* The same thread attempts to write-lock again */
    }
    while (rwPtr->lockcount != 0) {
        rwPtr->numwr++;
        Tcl_ConditionWait(&rwPtr->wcond, &rwPtr->lock, NULL);
        rwPtr->numwr--;
	rwPtr->numwr++;
	Tcl_ConditionWait(&rwPtr->wcond, &rwPtr->lock, NULL);
	rwPtr->numwr--;
    }
    rwPtr->lockcount = -1;     /* This designates the sole writer */
    rwPtr->owner = thisThread; /* which is our current thread     */
    Tcl_MutexUnlock(&rwPtr->lock);

    return 1;
}
1825
1826
1827
1828
1829
1830
1831
1832

1833
1834
1835
1836
1837
1838
1839


1840
1841
1842
1843


1844
1845
1846

1847
1848

1849
1850
1851
1852
1853
1854
1855
1819
1820
1821
1822
1823
1824
1825

1826
1827
1828
1829
1830
1831


1832
1833
1834
1835


1836
1837
1838
1839

1840
1841

1842
1843
1844
1845
1846
1847
1848
1849







-
+





-
-
+
+


-
-
+
+


-
+

-
+








int
Sp_ReadWriteMutexUnlock(Sp_ReadWriteMutex *muxPtr)
{
    Sp_ReadWriteMutex_ *rwPtr;

    if (*muxPtr == (Sp_ReadWriteMutex_*)0) {
        return 0; /* Never locked before */
	return 0; /* Never locked before */
    }

    rwPtr = *(Sp_ReadWriteMutex_**)muxPtr;
    Tcl_MutexLock(&rwPtr->lock);
    if (rwPtr->lockcount == 0) {
        Tcl_MutexUnlock(&rwPtr->lock);
        return 0; /* Not locked now */
	Tcl_MutexUnlock(&rwPtr->lock);
	return 0; /* Not locked now */
    }
    if (--rwPtr->lockcount <= 0) {
        rwPtr->lockcount = 0;
        rwPtr->owner = NULL;
	rwPtr->lockcount = 0;
	rwPtr->owner = NULL;
    }
    if (rwPtr->numwr) {
        Tcl_ConditionNotify(&rwPtr->wcond);
	Tcl_ConditionNotify(&rwPtr->wcond);
    } else if (rwPtr->numrd) {
        Tcl_ConditionNotify(&rwPtr->rcond);
	Tcl_ConditionNotify(&rwPtr->rcond);
    }

    Tcl_MutexUnlock(&rwPtr->lock);

    return 1;
}

1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887











1888
1889
1890
1891
1892
1893
1894
1864
1865
1866
1867
1868
1869
1870











1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888







-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







 *----------------------------------------------------------------------
 */

void
Sp_ReadWriteMutexFinalize(Sp_ReadWriteMutex *muxPtr)
{
    if (*muxPtr != (Sp_ReadWriteMutex_*)0) {
        Sp_ReadWriteMutex_ *rwPtr = *(Sp_ReadWriteMutex_**)muxPtr;
        if (rwPtr->lock) {
            Tcl_MutexFinalize(&rwPtr->lock);
        }
        if (rwPtr->rcond) {
            Tcl_ConditionFinalize(&rwPtr->rcond);
        }
        if (rwPtr->wcond) {
            Tcl_ConditionFinalize(&rwPtr->wcond);
        }
        Tcl_Free(*muxPtr);
	Sp_ReadWriteMutex_ *rwPtr = *(Sp_ReadWriteMutex_**)muxPtr;
	if (rwPtr->lock) {
	    Tcl_MutexFinalize(&rwPtr->lock);
	}
	if (rwPtr->rcond) {
	    Tcl_ConditionFinalize(&rwPtr->rcond);
	}
	if (rwPtr->wcond) {
	    Tcl_ConditionFinalize(&rwPtr->wcond);
	}
	Tcl_Free(*muxPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * AnyMutexIsLocked --
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920






1921
1922
1923
1924
1925
1926
1927
1902
1903
1904
1905
1906
1907
1908






1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921







-
-
-
-
-
-
+
+
+
+
+
+







 */
static int
AnyMutexIsLocked(Sp_AnyMutex *mPtr, Tcl_ThreadId threadId)
{
    int locked = 0;

    if (mPtr != NULL) {
        Tcl_MutexLock(&mPtr->lock);
        locked = mPtr->lockcount != 0;
        if (locked && threadId != NULL) {
            locked = mPtr->owner == threadId;
        }
        Tcl_MutexUnlock(&mPtr->lock);
	Tcl_MutexLock(&mPtr->lock);
	locked = mPtr->lockcount != 0;
	if (locked && threadId != NULL) {
	    locked = mPtr->owner == threadId;
	}
	Tcl_MutexUnlock(&mPtr->lock);
    }

    return locked;
}


/* EOF $RCSfile: threadSpCmd.c,v $ */
Changes to generic/threadSvCmd.c.
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63







-
+







static const Tcl_ObjType* intObjTypePtr = 0;
static const Tcl_ObjType* wideIntObjTypePtr = 0;
static const Tcl_ObjType* stringObjTypePtr = 0;

/*
 * In order to be fully stub enabled, a small
 * hack is needed to query the tclEmptyStringRep
 * global symbol defined by Tcl. See Sv_Init.
 * global symbol defined by Tcl. See SvInit.
 */

static char *Sv_tclEmptyStringRep = NULL;

/*
 * Global variables used within this file.
 */
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95










96
97
98
99
100
101
102
103
104



105
106
107
108
109
110
111
79
80
81
82
83
84
85










86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101



102
103
104
105
106
107
108
109
110
111







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+






-
-
-
+
+
+








/*
 * The standard commands found in NaviServer/AOLserver nsv_* interface.
 * For sharp-eye readers: the implementation of the "lappend" command
 * is moved to new list-command package, since it really belongs there.
 */

static Tcl_ObjCmdProc SvObjObjCmd;
static Tcl_ObjCmdProc SvAppendObjCmd;
static Tcl_ObjCmdProc SvIncrObjCmd;
static Tcl_ObjCmdProc SvSetObjCmd;
static Tcl_ObjCmdProc SvExistsObjCmd;
static Tcl_ObjCmdProc SvGetObjCmd;
static Tcl_ObjCmdProc SvArrayObjCmd;
static Tcl_ObjCmdProc SvUnsetObjCmd;
static Tcl_ObjCmdProc SvNamesObjCmd;
static Tcl_ObjCmdProc SvHandlersObjCmd;
static Tcl_ObjCmdProc2 SvObjObjCmd;
static Tcl_ObjCmdProc2 SvAppendObjCmd;
static Tcl_ObjCmdProc2 SvIncrObjCmd;
static Tcl_ObjCmdProc2 SvSetObjCmd;
static Tcl_ObjCmdProc2 SvExistsObjCmd;
static Tcl_ObjCmdProc2 SvGetObjCmd;
static Tcl_ObjCmdProc2 SvArrayObjCmd;
static Tcl_ObjCmdProc2 SvUnsetObjCmd;
static Tcl_ObjCmdProc2 SvNamesObjCmd;
static Tcl_ObjCmdProc2 SvHandlersObjCmd;

/*
 * New commands added to
 * standard set of nsv_*
 */

static Tcl_ObjCmdProc SvPopObjCmd;
static Tcl_ObjCmdProc SvMoveObjCmd;
static Tcl_ObjCmdProc SvLockObjCmd;
static Tcl_ObjCmdProc2 SvPopObjCmd;
static Tcl_ObjCmdProc2 SvMoveObjCmd;
static Tcl_ObjCmdProc2 SvLockObjCmd;

/*
 * Forward declarations for functions to
 * manage buckets, arrays and shared objects.
 */

static Container* CreateContainer(Array*, Tcl_HashEntry*, Tcl_Obj*);
126
127
128
129
130
131
132
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156




157
158
159
160
161
162
163
126
127
128
129
130
131
132

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152




153
154
155
156
157
158
159
160
161
162
163







-
+



















-
-
-
-
+
+
+
+







static void SvFinalizeContainers(Bucket*);
static void SvFinalize(void *);
#endif /* SV_FINALIZE */

static PsStore* GetPsStore(const char *handle);

static int SvObjDispatchObjCmd(void *arg,
            Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
	    Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]);

/*
 *-----------------------------------------------------------------------------
 *
 * Sv_RegisterCommand --
 *
 *      Utility to register commands to be loaded at module start.
 *
 * Results:
 *      None.
 *
 * Side effects;
 *      New command will be added to a linked list of registered commands.
 *
 *-----------------------------------------------------------------------------
 */

void
Sv_RegisterCommand(
                   const char *cmdName,                /* Name of command to register */
                   Tcl_ObjCmdProc *objProc,            /* Object-based command procedure */
                   Tcl_CmdDeleteProc *delProc,         /* Command delete procedure */
                   int aolSpecial)
		   const char *cmdName,                /* Name of command to register */
		   Tcl_ObjCmdProc2 *objProc,            /* Object-based command procedure */
		   Tcl_CmdDeleteProc *delProc,         /* Command delete procedure */
		   int aolSpecial)
{
    size_t len = strlen(cmdName) + strlen(TSV_CMD_PREFIX) + 1;
    size_t len2 = strlen(cmdName) + strlen(TSV_CMD2_PREFIX) + 1;
    SvCmdInfo *newCmd = (SvCmdInfo *)Tcl_Alloc(sizeof(SvCmdInfo) + len + len2);

    /*
     * Setup new command structure
184
185
186
187
188
189
190
191
192


193
194
195


196
197
198
199
200
201
202
184
185
186
187
188
189
190


191
192
193


194
195
196
197
198
199
200
201
202







-
-
+
+

-
-
+
+








    /*
     * Plug-in in shared list of commands.
     */

    Tcl_MutexLock(&svMutex);
    if (svCmdInfo == NULL) {
        svCmdInfo = newCmd;
        newCmd->nextPtr = NULL;
	svCmdInfo = newCmd;
	newCmd->nextPtr = NULL;
    } else {
        newCmd->nextPtr = svCmdInfo;
        svCmdInfo = newCmd;
	newCmd->nextPtr = svCmdInfo;
	svCmdInfo = newCmd;
    }
    Tcl_MutexUnlock(&svMutex);

    return;
}

/*
217
218
219
220
221
222
223
224
225


226
227
228
229
230
231
232
217
218
219
220
221
222
223


224
225
226
227
228
229
230
231
232







-
-
+
+







 *      Memory gets allocated.
 *
 *-----------------------------------------------------------------------------
 */

void
Sv_RegisterObjType(
                   const Tcl_ObjType *typePtr,               /* Type of object to register */
                   Tcl_DupInternalRepProc *dupProc)    /* Custom object duplicator */
		   const Tcl_ObjType *typePtr,               /* Type of object to register */
		   Tcl_DupInternalRepProc *dupProc)    /* Custom object duplicator */
{
    RegType *newType = (RegType *)Tcl_Alloc(sizeof(RegType));

    /*
     * Setup new type structure
     */

269
270
271
272
273
274
275
276
277


278
279
280


281
282
283
284
285
286
287
269
270
271
272
273
274
275


276
277
278


279
280
281
282
283
284
285
286
287







-
-
+
+

-
-
+
+








    /*
     * Plug-in in shared list
     */

    Tcl_MutexLock(&svMutex);
    if (psStore == NULL) {
        psStore = psPtr;
        psStore->nextPtr = NULL;
	psStore = psPtr;
	psStore->nextPtr = NULL;
    } else {
        psPtr->nextPtr = psStore;
        psStore = psPtr;
	psPtr->nextPtr = psStore;
	psStore = psPtr;
    }
    Tcl_MutexUnlock(&svMutex);
}

/*
 *-----------------------------------------------------------------------------
 *
301
302
303
304
305
306
307
308
309
310
311
312
313






314
315
316
317
318

319
320
321
322



323
324
325
326
327




328
329
330


331
332

333
334
335
336



337
338
339
340
341
342
343
344
345
346
347










348
349
350
351
352
353
354
355
356








357
358
359
360
361
362
363
301
302
303
304
305
306
307






308
309
310
311
312
313
314
315
316
317

318
319



320
321
322
323




324
325
326
327
328


329
330
331

332
333



334
335
336
337










338
339
340
341
342
343
344
345
346
347
348








349
350
351
352
353
354
355
356
357
358
359
360
361
362
363







-
-
-
-
-
-
+
+
+
+
+
+




-
+

-
-
-
+
+
+

-
-
-
-
+
+
+
+

-
-
+
+

-
+

-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







 *      New container might be created.
 *
 *-----------------------------------------------------------------------------
 */

int
Sv_GetContainer(
                Tcl_Interp *interp,                 /* Current interpreter. */
                int objc,                           /* Number of arguments */
                Tcl_Obj *const objv[],              /* Argument objects. */
                Container **retObj,                 /* OUT: shared object container */
                int *offset,                        /* Shift in argument list */
                int flags)                          /* Options for locking shared array */
		Tcl_Interp *interp,                 /* Current interpreter. */
		Tcl_Size objc,                      /* Number of arguments */
		Tcl_Obj *const objv[],              /* Argument objects. */
		Container **retObj,                 /* OUT: shared object container */
		Tcl_Size *offset,                   /* Shift in argument list */
		int flags)                          /* Options for locking shared array */
{
    const char *array, *key;

    if (*retObj == NULL) {
        Array *arrayPtr = NULL;
	Array *arrayPtr = NULL;

        /*
         * Parse mandatory arguments: <cmd> array key
         */
	/*
	 * Parse mandatory arguments: <cmd> array key
	 */

        if (objc < 3) {
            Tcl_WrongNumArgs(interp, 1, objv, "array key ?args?");
            return TCL_ERROR;
        }
	if (objc < 3) {
	    Tcl_WrongNumArgs(interp, 1, objv, "array key ?args?");
	    return TCL_ERROR;
	}

        array = Tcl_GetString(objv[1]);
        key   = Tcl_GetString(objv[2]);
	array = Tcl_GetString(objv[1]);
	key   = Tcl_GetString(objv[2]);

        *offset = 3; /* Consumed three arguments: cmd, array, key */
	*offset = 3; /* Consumed three arguments: cmd, array, key */

        /*
         * Lock the shared array and locate the shared object
         */
	/*
	 * Lock the shared array and locate the shared object
	 */

        arrayPtr = LockArray(interp, array, flags);
        if (arrayPtr == NULL) {
            return TCL_BREAK;
        }
        *retObj = AcquireContainer(arrayPtr, Tcl_GetString(objv[2]), flags);
        if (*retObj == NULL) {
            UnlockArray(arrayPtr);
            Tcl_AppendResult(interp, "no key ", array, "(", key, ")", NULL);
            return TCL_BREAK;
        }
	arrayPtr = LockArray(interp, array, flags);
	if (arrayPtr == NULL) {
	    return TCL_BREAK;
	}
	*retObj = AcquireContainer(arrayPtr, Tcl_GetString(objv[2]), flags);
	if (*retObj == NULL) {
	    UnlockArray(arrayPtr);
	    Tcl_AppendResult(interp, "no key ", array, "(", key, ")", (void *)NULL);
	    return TCL_BREAK;
	}
    } else {
        Tcl_HashTable *handles = &((*retObj)->bucketPtr->handles);
        LOCK_CONTAINER(*retObj);
        if (Tcl_FindHashEntry(handles, (char*)(*retObj)) == NULL) {
            UNLOCK_CONTAINER(*retObj);
            Tcl_SetObjResult(interp, Tcl_NewStringObj("key has been deleted", TCL_AUTO_LENGTH));
            return TCL_BREAK;
        }
        *offset = 2; /* Consumed two arguments: object, cmd */
	Tcl_HashTable *handles = &((*retObj)->bucketPtr->handles);
	LOCK_CONTAINER(*retObj);
	if (Tcl_FindHashEntry(handles, (char*)(*retObj)) == NULL) {
	    UNLOCK_CONTAINER(*retObj);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj("key has been deleted", TCL_INDEX_NONE));
	    return TCL_BREAK;
	}
	*offset = 2; /* Consumed two arguments: object, cmd */
    }

    return TCL_OK;
}

/*
 *-----------------------------------------------------------------------------
373
374
375
376
377
378
379
380
381
382



383
384
385
386
387
388
389
373
374
375
376
377
378
379



380
381
382
383
384
385
386
387
388
389







-
-
-
+
+
+







 *      For bound arrays, update the underlying persistent storage.
 *
 *-----------------------------------------------------------------------------
 */

int
Sv_PutContainer(
                Tcl_Interp *interp,               /* For error reporting; might be NULL */
                Container *svObj,                 /* Shared object container */
                int mode)                         /* One of SV_XXX modes */
		Tcl_Interp *interp,               /* For error reporting; might be NULL */
		Container *svObj,                 /* Shared object container */
		int mode)                         /* One of SV_XXX modes */
{
    int ret;

    ret = ReleaseContainer(interp, svObj, mode);
    UnlockArray(svObj->arrayPtr);

    return ret;
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
















451
452
453
454
455
456
457
458

459
460
461


462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479









480
481
482
483
484

485
486
487
488
489
490
491
428
429
430
431
432
433
434
















435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457

458
459


460
461
462
463
464
465
466
467
468
469
470









471
472
473
474
475
476
477
478
479
480
481
482
483

484
485
486
487
488
489
490
491







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







-
+

-
-
+
+









-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+




-
+








    /*
     * Try to see wether some array is already bound to the
     * same persistent storage address.
     */

    for (i = 0; i < NUMBUCKETS; i++) {
        Tcl_HashSearch search;
        Tcl_HashEntry *hPtr;
        Bucket *bucketPtr = &buckets[i];
        LOCK_BUCKET(bucketPtr);
        hPtr = Tcl_FirstHashEntry(&bucketPtr->arrays, &search);
        while (hPtr) {
            Array *arrayPtr = (Array*)Tcl_GetHashValue(hPtr);
            if (arrayPtr->bindAddr && arrayPtr->psPtr) {
                if (strcmp(arrayPtr->bindAddr, handle) == 0) {
                    UNLOCK_BUCKET(bucketPtr);
                    return NULL; /* Array already bound */
                }
            }
            hPtr = Tcl_NextHashEntry(&search);
        }
        UNLOCK_BUCKET(bucketPtr);
	Tcl_HashSearch search;
	Tcl_HashEntry *hPtr;
	Bucket *bucketPtr = &buckets[i];
	LOCK_BUCKET(bucketPtr);
	hPtr = Tcl_FirstHashEntry(&bucketPtr->arrays, &search);
	while (hPtr) {
	    Array *arrayPtr = (Array*)Tcl_GetHashValue(hPtr);
	    if (arrayPtr->bindAddr && arrayPtr->psPtr) {
		if (strcmp(arrayPtr->bindAddr, handle) == 0) {
		    UNLOCK_BUCKET(bucketPtr);
		    return NULL; /* Array already bound */
		}
	    }
	    hPtr = Tcl_NextHashEntry(&search);
	}
	UNLOCK_BUCKET(bucketPtr);
    }

    /*
     * Split the address and storage handler
     */

    if (delimiter == NULL) {
        addr = NULL;
	addr = NULL;
    } else {
        *delimiter = 0;
        addr = delimiter + 1;
	*delimiter = 0;
	addr = delimiter + 1;
    }

    /*
     * No array was bound to the same persistent storage.
     * Lookup the persistent storage to bind to.
     */

    Tcl_MutexLock(&svMutex);
    for (tmpPtr = psStore; tmpPtr; tmpPtr = tmpPtr->nextPtr) {
        if (strcmp(tmpPtr->type, type) == 0) {
            tmpPtr->psHandle = tmpPtr->psOpen(addr);
            if (tmpPtr->psHandle) {
                psPtr = (PsStore *)Tcl_Alloc(sizeof(PsStore));
                *psPtr = *tmpPtr;
                psPtr->nextPtr = NULL;
            }
            break;
        }
	if (strcmp(tmpPtr->type, type) == 0) {
	    tmpPtr->psHandle = tmpPtr->psOpen(addr);
	    if (tmpPtr->psHandle) {
		psPtr = (PsStore *)Tcl_Alloc(sizeof(PsStore));
		*psPtr = *tmpPtr;
		psPtr->nextPtr = NULL;
	    }
	    break;
	}
    }
    Tcl_MutexUnlock(&svMutex);

    if (delimiter) {
        *delimiter = ':';
	*delimiter = ':';
    }

    return psPtr;
}

/*
 *-----------------------------------------------------------------------------
502
503
504
505
506
507
508
509
510
511



512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534

















535
536
537
538
539
540
541
502
503
504
505
506
507
508



509
510
511
512
513
514
515
516
517

















518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541







-
-
-
+
+
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *      the key in the persistent storage as well.
 *
 *-----------------------------------------------------------------------------
 */

static Container *
AcquireContainer(
                 Array *arrayPtr,
                 const char *key,
                 int flags)
		 Array *arrayPtr,
		 const char *key,
		 int flags)
{
    int isNew;
    Tcl_Obj *tclObj = NULL;
    Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&arrayPtr->vars, key);

    if (hPtr == NULL) {
        PsStore *psPtr = arrayPtr->psPtr;
        if (psPtr) {
            char *val = NULL;
            size_t len = 0;
            if (psPtr->psGet(psPtr->psHandle, key, &val, &len) == 0) {
                tclObj = Tcl_NewStringObj(val, len);
                psPtr->psFree(psPtr->psHandle, val);
            }
        }
        if (!(flags & FLAGS_CREATEVAR) && tclObj == NULL) {
            return NULL;
        }
        if (tclObj == NULL) {
            tclObj = Tcl_NewObj();
        }
        hPtr = Tcl_CreateHashEntry(&arrayPtr->vars, key, &isNew);
        Tcl_SetHashValue(hPtr, CreateContainer(arrayPtr, hPtr, tclObj));
	PsStore *psPtr = arrayPtr->psPtr;
	if (psPtr) {
	    char *val = NULL;
	    Tcl_Size len = 0;
	    if (psPtr->psGet(psPtr->psHandle, key, &val, &len) == 0) {
		tclObj = Tcl_NewStringObj(val, len);
		psPtr->psFree(psPtr->psHandle, val);
	    }
	}
	if (!(flags & FLAGS_CREATEVAR) && tclObj == NULL) {
	    return NULL;
	}
	if (tclObj == NULL) {
	    tclObj = Tcl_NewObj();
	}
	hPtr = Tcl_CreateHashEntry(&arrayPtr->vars, key, &isNew);
	Tcl_SetHashValue(hPtr, CreateContainer(arrayPtr, hPtr, tclObj));
    }

    return (Container*)Tcl_GetHashValue(hPtr);
}

/*
 *-----------------------------------------------------------------------------
553
554
555
556
557
558
559
560
561
562



563
564
565

566
567
568
569
570
571
572
573
574



575
576
577
578
579
580
581
582







583
584
585
586
587
588
589
553
554
555
556
557
558
559



560
561
562
563
564

565
566
567
568
569
570
571



572
573
574








575
576
577
578
579
580
581
582
583
584
585
586
587
588







-
-
-
+
+
+


-
+






-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+







 *      Persistent storage, if bound, might be modified.
 *
 *-----------------------------------------------------------------------------
 */

static int
ReleaseContainer(
                 Tcl_Interp *interp,
                 Container *svObj,
                 int mode)
		 Tcl_Interp *interp,
		 Container *svObj,
		 int mode)
{
    const PsStore *psPtr = svObj->arrayPtr->psPtr;
    size_t len;
    Tcl_Size len;
    char *key, *val;

    switch (mode) {
    case SV_UNCHANGED: return TCL_OK;
    case SV_ERROR:     return TCL_ERROR;
    case SV_CHANGED:
        if (psPtr) {
            key = (char *)Tcl_GetHashKey(&svObj->arrayPtr->vars, svObj->entryPtr);
            val = Tcl_GetString(svObj->tclObj);
	if (psPtr) {
	    key = (char *)Tcl_GetHashKey(&svObj->arrayPtr->vars, svObj->entryPtr);
	    val = Tcl_GetStringFromObj(svObj->tclObj, &len);
            len = svObj->tclObj->length;
            if (psPtr->psPut(psPtr->psHandle, key, val, len) == -1) {
                const char *err = psPtr->psError(psPtr->psHandle);
                Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_AUTO_LENGTH));
                return TCL_ERROR;
            }
        }
        return TCL_OK;
	    if (psPtr->psPut(psPtr->psHandle, key, val, len) == -1) {
		const char *err = psPtr->psError(psPtr->psHandle);
		Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_INDEX_NONE));
		return TCL_ERROR;
	    }
	}
	return TCL_OK;
    }

    return TCL_ERROR; /* Should never be reached */
}

/*
 *-----------------------------------------------------------------------------
600
601
602
603
604
605
606
607
608
609



610
611
612
613
614

615
616
617
618
619
620
621
622
623
624
625
626
627

628
629
630
631
632
633
634
599
600
601
602
603
604
605



606
607
608
609
610
611
612

613
614
615
616
617
618
619
620
621
622
623
624
625

626
627
628
629
630
631
632
633







-
-
-
+
+
+




-
+












-
+







 *      Memory gets allocated.
 *
 *-----------------------------------------------------------------------------
 */

static Container *
CreateContainer(
                Array *arrayPtr,
                Tcl_HashEntry *entryPtr,
                Tcl_Obj *tclObj)
		Array *arrayPtr,
		Tcl_HashEntry *entryPtr,
		Tcl_Obj *tclObj)
{
    Container *svObj;

    if (arrayPtr->bucketPtr->freeCt == NULL) {
        SvAllocateContainers(arrayPtr->bucketPtr);
	SvAllocateContainers(arrayPtr->bucketPtr);
    }

    svObj = arrayPtr->bucketPtr->freeCt;
    arrayPtr->bucketPtr->freeCt = svObj->nextPtr;

    svObj->arrayPtr  = arrayPtr;
    svObj->bucketPtr = arrayPtr->bucketPtr;
    svObj->tclObj    = tclObj;
    svObj->entryPtr  = entryPtr;
    svObj->handlePtr = NULL;

    if (svObj->tclObj) {
        Tcl_IncrRefCount(svObj->tclObj);
	Tcl_IncrRefCount(svObj->tclObj);
    }

    return svObj;
}

/*
 *-----------------------------------------------------------------------------
646
647
648
649
650
651
652
653

654
655
656

657
658
659

660
661
662
663
664
665
666
667
668
669








670
671
672
673
674
675
676
645
646
647
648
649
650
651

652
653
654

655
656
657

658
659
660








661
662
663
664
665
666
667
668
669
670
671
672
673
674
675







-
+


-
+


-
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







 *      storage, it removes the corresponding record.
 *
 *-----------------------------------------------------------------------------
 */

static int
DeleteContainer(
                Container *svObj)
		Container *svObj)
{
    if (svObj->tclObj) {
        Tcl_DecrRefCount(svObj->tclObj);
	Tcl_DecrRefCount(svObj->tclObj);
    }
    if (svObj->handlePtr) {
        Tcl_DeleteHashEntry(svObj->handlePtr);
	Tcl_DeleteHashEntry(svObj->handlePtr);
    }
    if (svObj->entryPtr) {
        PsStore *psPtr = svObj->arrayPtr->psPtr;
        if (psPtr) {
            char *key = (char *)Tcl_GetHashKey(&svObj->arrayPtr->vars,svObj->entryPtr);
            if (psPtr->psDelete(psPtr->psHandle, key) == -1) {
                return TCL_ERROR;
            }
        }
        Tcl_DeleteHashEntry(svObj->entryPtr);
	PsStore *psPtr = svObj->arrayPtr->psPtr;
	if (psPtr) {
	    char *key = (char *)Tcl_GetHashKey(&svObj->arrayPtr->vars,svObj->entryPtr);
	    if (psPtr->psDelete(psPtr->psHandle, key) == -1) {
		return TCL_ERROR;
	    }
	}
	Tcl_DeleteHashEntry(svObj->entryPtr);
    }

    svObj->arrayPtr  = NULL;
    svObj->entryPtr  = NULL;
    svObj->handlePtr = NULL;
    svObj->tclObj    = NULL;

695
696
697
698
699
700
701
702
703
704



705
706
707

708
709
710
711
712
713
714
715
716
717
718
719
720


721
722

723
724
725
726
727
728
729
730
731
732

733
734
735
736
737
738
739
740
741
742
743










744
745
746
747
748
749
750
694
695
696
697
698
699
700



701
702
703
704
705

706

707
708
709
710
711
712
713
714
715
716


717
718
719

720
721
722
723
724
725
726
727
728
729

730
731










732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748







-
-
-
+
+
+


-
+
-










-
-
+
+

-
+









-
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







 *      Sets *arrayPtrPtr with Array pointer or leave error in given interp.
 *
 *-----------------------------------------------------------------------------
 */

static Array *
LockArray(
          Tcl_Interp *interp,                 /* Interpreter to leave result. */
          const char *array,                  /* Name of array to lock */
          int flags)                          /* FLAGS_CREATEARRAY/FLAGS_NOERRMSG*/
	  Tcl_Interp *interp,                 /* Interpreter to leave result. */
	  const char *array,                  /* Name of array to lock */
	  int flags)                          /* FLAGS_CREATEARRAY/FLAGS_NOERRMSG*/
{
    const char *p;
    unsigned int result;
    size_t result, i;
    int i;
    Bucket *bucketPtr;
    Array *arrayPtr;

    /*
     * Compute a hash to map an array to a bucket.
     */

    p = array;
    result = 0;
    while (*p++) {
        i = *p;
        result += (result << 3) + i;
	i = (unsigned char)*p;
	result += (result << 3) + i;
    }
    i = result % NUMBUCKETS;
    i = (result % NUMBUCKETS);
    bucketPtr = &buckets[i];

    /*
     * Lock the bucket and find the array, or create a new one.
     * The bucket will be left locked on success.
     */

    LOCK_BUCKET(bucketPtr); /* Note: no matching unlock below ! */
    if (flags & FLAGS_CREATEARRAY) {
        arrayPtr = CreateArray(bucketPtr, array);
	arrayPtr = CreateArray(bucketPtr, array);
    } else {
        Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&bucketPtr->arrays, array);
        if (hPtr == NULL) {
            UNLOCK_BUCKET(bucketPtr);
            if (!(flags & FLAGS_NOERRMSG)) {
                Tcl_AppendResult(interp, "\"", array,
                                 "\" is not a thread shared array", NULL);
            }
            return NULL;
        }
        arrayPtr = (Array*)Tcl_GetHashValue(hPtr);
	Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&bucketPtr->arrays, array);
	if (hPtr == NULL) {
	    UNLOCK_BUCKET(bucketPtr);
	    if (!(flags & FLAGS_NOERRMSG)) {
		Tcl_AppendResult(interp, "\"", array,
				 "\" is not a thread shared array", (void *)NULL);
	    }
	    return NULL;
	}
	arrayPtr = (Array*)Tcl_GetHashValue(hPtr);
    }

    return arrayPtr;
}
/*
 *-----------------------------------------------------------------------------
 *
765
766
767
768
769
770
771
772
773
774
775




776
777
778
779
780
781
782
763
764
765
766
767
768
769




770
771
772
773
774
775
776
777
778
779
780







-
-
-
-
+
+
+
+







static int
FlushArray(Array *arrayPtr)                    /* Name of array to flush */
{
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;

    for (hPtr = Tcl_FirstHashEntry(&arrayPtr->vars, &search); hPtr;
         hPtr = Tcl_NextHashEntry(&search)) {
        if (DeleteContainer((Container*)Tcl_GetHashValue(hPtr)) != TCL_OK) {
            return TCL_ERROR;
        }
	 hPtr = Tcl_NextHashEntry(&search)) {
	if (DeleteContainer((Container*)Tcl_GetHashValue(hPtr)) != TCL_OK) {
	    return TCL_ERROR;
	}
    }

    return TCL_OK;
}

/*
 *-----------------------------------------------------------------------------
792
793
794
795
796
797
798
799
800


801
802
803
804
805
806
807
808

809
810
811
812
813
814
815
790
791
792
793
794
795
796


797
798
799
800
801
802
803
804
805

806
807
808
809
810
811
812
813







-
-
+
+







-
+







 *      Memory gets allocated
 *
 *-----------------------------------------------------------------------------
 */

static Array *
CreateArray(
            Bucket *bucketPtr,
            const char *arrayName)
	    Bucket *bucketPtr,
	    const char *arrayName)
{
    int isNew;
    Array *arrayPtr;
    Tcl_HashEntry *hPtr;

    hPtr = Tcl_CreateHashEntry(&bucketPtr->arrays, arrayName, &isNew);
    if (!isNew) {
        return (Array*)Tcl_GetHashValue(hPtr);
	return (Array*)Tcl_GetHashValue(hPtr);
    }

    arrayPtr = (Array *)Tcl_Alloc(sizeof(Array));
    arrayPtr->bucketPtr = bucketPtr;
    arrayPtr->entryPtr  = hPtr;
    arrayPtr->psPtr     = NULL;
    arrayPtr->bindAddr  = NULL;
837
838
839
840
841
842
843
844
845


846
847
848
849
850
851
852
853
854
855
856









857
858
859
860
861
862
863
864
865

866
867
868
869
870



871
872
873

874
875
876
877
878
879
880
835
836
837
838
839
840
841


842
843
844
845









846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862

863
864
865



866
867
868
869
870

871
872
873
874
875
876
877
878







-
-
+
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+








-
+


-
-
-
+
+
+


-
+







 */

static int
UnbindArray(Tcl_Interp *interp, Array *arrayPtr)
{
    PsStore *psPtr = arrayPtr->psPtr;
    if (arrayPtr->bindAddr) {
        Tcl_Free(arrayPtr->bindAddr);
        arrayPtr->bindAddr = NULL;
	Tcl_Free(arrayPtr->bindAddr);
	arrayPtr->bindAddr = NULL;
    }
    if (psPtr) {
        if (psPtr->psClose(psPtr->psHandle) == -1) {
            if (interp) {
                const char *err = psPtr->psError(psPtr->psHandle);
                Tcl_SetObjResult(interp, Tcl_NewStringObj(err, -1));
            }
            return TCL_ERROR;
        }
        Tcl_Free(arrayPtr->psPtr), arrayPtr->psPtr = NULL;
        arrayPtr->psPtr = NULL;
	if (psPtr->psClose(psPtr->psHandle) == -1) {
	    if (interp) {
		const char *err = psPtr->psError(psPtr->psHandle);
		Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_INDEX_NONE));
	    }
	    return TCL_ERROR;
	}
	Tcl_Free(arrayPtr->psPtr), arrayPtr->psPtr = NULL;
	arrayPtr->psPtr = NULL;
    }
    return TCL_OK;
}

static int
DeleteArray(Tcl_Interp *interp, Array *arrayPtr)
{
    if (FlushArray(arrayPtr) == -1) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if (arrayPtr->psPtr) {
        if (UnbindArray(interp, arrayPtr) != TCL_OK) {
            return TCL_ERROR;
        };
	if (UnbindArray(interp, arrayPtr) != TCL_OK) {
	    return TCL_ERROR;
	};
    }
    if (arrayPtr->entryPtr) {
        Tcl_DeleteHashEntry(arrayPtr->entryPtr);
	Tcl_DeleteHashEntry(arrayPtr->entryPtr);
    }

    Tcl_DeleteHashTable(&arrayPtr->vars);
    Tcl_Free(arrayPtr);

    return TCL_OK;
}
909
910
911
912
913
914
915
916
917
918



919
920
921
922
923
924
925
907
908
909
910
911
912
913



914
915
916
917
918
919
920
921
922
923







-
-
-
+
+
+







    basePtr = (char *)Tcl_Alloc(bytesToAlloc);
    memset(basePtr, 0, bytesToAlloc);

    objPtr = (Container*)basePtr;
    objPtr->chunkAddr = basePtr; /* Mark chunk address for reclaim */

    for (i = 0; i < OBJS_TO_ALLOC_EACH_TIME; i++) {
        objPtr->nextPtr = prevPtr;
        prevPtr = objPtr;
        objPtr = (Container*)(((char*)objPtr) + objSizePlusPadding);
	objPtr->nextPtr = prevPtr;
	prevPtr = objPtr;
	objPtr = (Container*)(((char*)objPtr) + objSizePlusPadding);
    }
    bucketPtr->freeCt = prevPtr;
}

#ifdef SV_FINALIZE
/*
 *-----------------------------------------------------------------------------
939
940
941
942
943
944
945
946
947
948
949
950
951
952







953
954
955
956
957
958
959
937
938
939
940
941
942
943







944
945
946
947
948
949
950
951
952
953
954
955
956
957







-
-
-
-
-
-
-
+
+
+
+
+
+
+








static void
SvFinalizeContainers(Bucket *bucketPtr)
{
   Container *tmpPtr, *objPtr = bucketPtr->freeCt;

    while (objPtr) {
        if (objPtr->chunkAddr == (char*)objPtr) {
            tmpPtr = objPtr->nextPtr;
            Tcl_Free(objPtr);
            objPtr = tmpPtr;
        } else {
            objPtr = objPtr->nextPtr;
        }
	if (objPtr->chunkAddr == (char*)objPtr) {
	    tmpPtr = objPtr->nextPtr;
	    Tcl_Free(objPtr);
	    objPtr = tmpPtr;
	} else {
	    objPtr = objPtr->nextPtr;
	}
    }
}
#endif /* SV_FINALIZE */

/*
 *-----------------------------------------------------------------------------
 *
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049














































1050
1051
1052
1053
1054
1055
1056

1057


1058
1059
1060
1061
1062
1063
1064
1065
1066








1067
1068
1069
1070
1071
1072
1073
999
1000
1001
1002
1003
1004
1005










































1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059

1060
1061
1062








1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







+
-
+
+

-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







    Tcl_Obj *dupPtr = Tcl_NewObj();

    /*
     * Handle the internal rep
     */

    if (objPtr->typePtr != NULL) {
        if (objPtr->typePtr->dupIntRepProc == NULL) {
            dupPtr->internalRep = objPtr->internalRep;
            dupPtr->typePtr = objPtr->typePtr;
            Tcl_InvalidateStringRep(dupPtr);
        } else {
            if (   objPtr->typePtr == booleanObjTypePtr    \
                || objPtr->typePtr == byteArrayObjTypePtr  \
                || objPtr->typePtr == doubleObjTypePtr     \
                || objPtr->typePtr == intObjTypePtr        \
                || objPtr->typePtr == wideIntObjTypePtr    \
                || objPtr->typePtr == stringObjTypePtr) {
               /*
                * Cover all "safe" obj types (see header comment)
                */
              (*objPtr->typePtr->dupIntRepProc)(objPtr, dupPtr);
              Tcl_InvalidateStringRep(dupPtr);
            } else {
                int found = 0;
                RegType *regPtr;
               /*
                * Cover special registered types. Assume not
                * very many of those, so this sequential walk
                * should be fast enough.
                */
                for (regPtr = regType; regPtr; regPtr = regPtr->nextPtr) {
                    if (objPtr->typePtr == regPtr->typePtr) {
                        (*regPtr->dupIntRepProc)(objPtr, dupPtr);
                        Tcl_InvalidateStringRep(dupPtr);
                        found = 1;
                        break;
                    }
                }
               /*
                * Assure at least string rep of the source
                * is present, which will be copied below.
                */
                if (found == 0 && objPtr->bytes == NULL
                    && objPtr->typePtr->updateStringProc != NULL) {
                    (*objPtr->typePtr->updateStringProc)(objPtr);
                }
            }
        }
	if (objPtr->typePtr->dupIntRepProc == NULL) {
	    dupPtr->internalRep = objPtr->internalRep;
	    dupPtr->typePtr = objPtr->typePtr;
	    Tcl_InvalidateStringRep(dupPtr);
	} else {
	    if (   objPtr->typePtr == booleanObjTypePtr    \
		|| objPtr->typePtr == byteArrayObjTypePtr  \
		|| objPtr->typePtr == doubleObjTypePtr     \
		|| objPtr->typePtr == intObjTypePtr        \
		|| objPtr->typePtr == wideIntObjTypePtr    \
		|| objPtr->typePtr == stringObjTypePtr) {
	       /*
		* Cover all "safe" obj types (see header comment)
		*/
	      (*objPtr->typePtr->dupIntRepProc)(objPtr, dupPtr);
	      if (dupPtr->typePtr != NULL) {
		  Tcl_InvalidateStringRep(dupPtr);
	      }
	    } else {
		int found = 0;
		RegType *regPtr;
	       /*
		* Cover special registered types. Assume not
		* very many of those, so this sequential walk
		* should be fast enough.
		*/
		for (regPtr = regType; regPtr; regPtr = regPtr->nextPtr) {
		    if (objPtr->typePtr == regPtr->typePtr) {
			(*regPtr->dupIntRepProc)(objPtr, dupPtr);
			if (dupPtr->typePtr != NULL) {
			    Tcl_InvalidateStringRep(dupPtr);
			}
			found = 1;
			break;
		    }
		}
	       /*
		* Assure at least string rep of the source
		* is present, which will be copied below.
		*/
		if (found == 0 && objPtr->bytes == NULL
		    && objPtr->typePtr->updateStringProc != NULL) {
		    (*objPtr->typePtr->updateStringProc)(objPtr);
		}
	    }
	}
    }

    /*
     * Handle the string rep
     */

    if (objPtr->bytes == NULL) {
	if (dupPtr->bytes != Sv_tclEmptyStringRep) {
        dupPtr->bytes = NULL;
	    dupPtr->bytes = NULL;
	}
    } else if (objPtr->bytes != Sv_tclEmptyStringRep) {
        /* A copy of TclInitStringRep macro */
        dupPtr->bytes = (char *)Tcl_Alloc(objPtr->length + 1);
        if (objPtr->length > 0) {
            memcpy((void*)dupPtr->bytes,(void*)objPtr->bytes,
                   (unsigned)objPtr->length);
        }
        dupPtr->length = objPtr->length;
        dupPtr->bytes[objPtr->length] = '\0';
	/* A copy of TclInitStringRep macro */
	dupPtr->bytes = (char *)Tcl_Alloc(objPtr->length + 1);
	if (objPtr->length > 0) {
	    memcpy(dupPtr->bytes, objPtr->bytes,
		    objPtr->length);
	}
	dupPtr->length = objPtr->length;
	dupPtr->bytes[objPtr->length] = '\0';
    }

    return dupPtr;
}

/*
 *-----------------------------------------------------------------------------
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094




1095
1096
1097
1098
1099
1100
1101


1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116



1117
1118
1119

1120
1121
1122
1123
1124
1125
1126
1088
1089
1090
1091
1092
1093
1094




1095
1096
1097
1098
1099
1100
1101
1102
1103


1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117



1118
1119
1120
1121
1122

1123
1124
1125
1126
1127
1128
1129
1130







-
-
-
-
+
+
+
+





-
-
+
+












-
-
-
+
+
+


-
+







 *      Depends on the dispatched command
 *
 *-----------------------------------------------------------------------------
 */

static int
SvObjDispatchObjCmd(
                    void *arg,                     /* Pointer to object container. */
                    Tcl_Interp *interp,                 /* Current interpreter. */
                    int objc,                           /* Number of arguments. */
                    Tcl_Obj *const objv[])              /* Argument objects. */
		    void *arg,                     /* Pointer to object container. */
		    Tcl_Interp *interp,                 /* Current interpreter. */
		    Tcl_Size objc,                           /* Number of arguments. */
		    Tcl_Obj *const objv[])              /* Argument objects. */
{
    const char *cmdName;
    SvCmdInfo *cmdPtr;

    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "args");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "args");
	return TCL_ERROR;
    }

    cmdName = Tcl_GetString(objv[1]);

    /*
     * Do simple linear search. We may later replace this list
     * with the hash table to gain speed. Currently, the list
     * of registered commands is so small, so this will work
     * fast enough.
     */

    for (cmdPtr = svCmdInfo; cmdPtr; cmdPtr = cmdPtr->nextPtr) {
        if (!strcmp(cmdPtr->name, cmdName)) {
            return (*cmdPtr->objProcPtr)(arg, interp, objc, objv);
        }
	if (!strcmp(cmdPtr->name, cmdName)) {
	    return (*cmdPtr->objProcPtr)(arg, interp, objc, objv);
	}
    }

    Tcl_AppendResult(interp, "invalid command name \"", cmdName, "\"", NULL);
    Tcl_AppendResult(interp, "invalid command name \"", cmdName, "\"", (void *)NULL);
    return TCL_ERROR;
}

/*
 *-----------------------------------------------------------------------------
 *
 * SvObjObjCmd --
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144




1145
1146


1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170













1171
1172

1173
1174
1175
1176
1177


1178
1179
1180
1181
1182
1183
1184

1185
1186

1187
1188

1189
1190
1191
1192
1193
1194
1195
1138
1139
1140
1141
1142
1143
1144




1145
1146
1147
1148
1149

1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162













1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176

1177
1178
1179
1180


1181
1182
1183
1184
1185
1186
1187
1188

1189
1190

1191
1192

1193
1194
1195
1196
1197
1198
1199
1200







-
-
-
-
+
+
+
+

-
+
+











-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+



-
-
+
+






-
+

-
+

-
+







 *      New Tcl command gets created.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvObjObjCmd(
            void *arg,                     /* != NULL if aolSpecial */
            Tcl_Interp *interp,                 /* Current interpreter. */
            int objc,                   /* Number of arguments. */
            Tcl_Obj *const objv[])              /* Argument objects. */
	    void *arg,                     /* != NULL if aolSpecial */
	    Tcl_Interp *interp,                 /* Current interpreter. */
	    Tcl_Size objc,                   /* Number of arguments. */
	    Tcl_Obj *const objv[])              /* Argument objects. */
{
    int isNew, off, ret, flg;
    int isNew, ret, flg;
    Tcl_Size off;
    char buf[128];
    Tcl_Obj *val = NULL;
    Container *svObj = NULL;

    /*
     * Syntax: sv::object array key ?var?
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    switch (ret) {
    case TCL_BREAK: /* Shared array was not found */
        if ((objc - off)) {
            val = objv[off];
        }
        Tcl_ResetResult(interp);
        flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
        ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
        if (ret != TCL_OK) {
            return TCL_ERROR;
        }
        Tcl_DecrRefCount(svObj->tclObj);
        svObj->tclObj = Sv_DuplicateObj(val ? val : Tcl_NewObj());
        Tcl_IncrRefCount(svObj->tclObj);
        break;
	if (objc != off) {
	    val = objv[off];
	}
	Tcl_ResetResult(interp);
	flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
	ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
	if (ret != TCL_OK) {
	    return TCL_ERROR;
	}
	Tcl_DecrRefCount(svObj->tclObj);
	svObj->tclObj = Sv_DuplicateObj(val ? val : Tcl_NewObj());
	Tcl_IncrRefCount(svObj->tclObj);
	break;
    case TCL_ERROR:
        return TCL_ERROR;
	return TCL_ERROR;
    }

    if (svObj->handlePtr == NULL) {
        Tcl_HashTable *handles = &svObj->arrayPtr->bucketPtr->handles;
        svObj->handlePtr = Tcl_CreateHashEntry(handles, (char*)svObj, &isNew);
	Tcl_HashTable *handles = &svObj->arrayPtr->bucketPtr->handles;
	svObj->handlePtr = Tcl_CreateHashEntry(handles, (char*)svObj, &isNew);
    }

    /*
     * Format the command name
     */

    sprintf(buf, "::%p", (int*)svObj);
    snprintf(buf, sizeof(buf), "::%p", svObj);
    svObj->aolSpecial = (arg != NULL);
    Tcl_CreateObjCommand(interp, buf, SvObjDispatchObjCmd, svObj, NULL);
    Tcl_CreateObjCommand2(interp, buf, SvObjDispatchObjCmd, svObj, NULL);
    Tcl_ResetResult(interp);
    Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_AUTO_LENGTH));
    Tcl_SetObjResult(interp, Tcl_NewStringObj(buf, TCL_INDEX_NONE));

    return Sv_PutContainer(interp, svObj, SV_UNCHANGED);
}

/*
 *-----------------------------------------------------------------------------
 *
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215




1216
1217
1218


1219
1220
1221
1222
1223
1224
1225
1226


1227
1228
1229
1230
1231



1232
1233
1234
1235
1236
1237


1238
1239
1240
1241
1242
1243
1244

1245
1246
1247
1248
1249
1250

1251
1252
1253

1254
1255
1256
1257
1258
1259
1260





1261
1262
1263
1264
1265
1266
1267





1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310









































1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332




















1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346











1347
1348
1349
1350
1351
1352





1353
1354
1355
1356
1357
1358





1359
1360
1361
1362
1363
1364





1365
1366

1367
1368

1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
































1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412









1413
1414
1415
1416
1417

1418
1419
1420
1421
1422
1423
1424
1210
1211
1212
1213
1214
1215
1216




1217
1218
1219
1220
1221


1222
1223
1224
1225
1226
1227
1228
1229


1230
1231
1232
1233



1234
1235
1236
1237
1238
1239
1240


1241
1242
1243
1244
1245
1246
1247
1248

1249
1250
1251
1252
1253
1254

1255
1256
1257

1258
1259
1260





1261
1262
1263
1264
1265
1266
1267





1268
1269
1270
1271
1272
1273
1274









































1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317




















1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340











1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352





1353
1354
1355
1356
1357
1358





1359
1360
1361
1362
1363
1364





1365
1366
1367
1368
1369
1370

1371


1372
1373
































1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407









1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420

1421
1422
1423
1424
1425
1426
1427
1428







-
-
-
-
+
+
+
+

-
-
+
+






-
-
+
+


-
-
-
+
+
+




-
-
+
+






-
+





-
+


-
+


-
-
-
-
-
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
+
-
-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+




-
+







 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvArrayObjCmd(
              void *arg,                     /* Pointer to object container. */
              Tcl_Interp *interp,                 /* Current interpreter. */
              int objc,                   /* Number of arguments. */
              Tcl_Obj *const objv[])              /* Argument objects. */
	      void *arg,                     /* Pointer to object container. */
	      Tcl_Interp *interp,                 /* Current interpreter. */
	      Tcl_Size objc,                   /* Number of arguments. */
	      Tcl_Obj *const objv[])              /* Argument objects. */
{
    int i, argx = 0, index, ret = TCL_OK;
    int lobjc = 0;
    int ret = TCL_OK;
    Tcl_Size i, argx = 0, lobjc = 0;
    const char *arrayName = NULL;
    Array *arrayPtr = NULL;
    Tcl_Obj **lobjv = NULL;
    Container *svObj, *elObj = NULL;

    static const char *const opts[] = {
        "set",  "reset", "get", "names", "size", "exists", "isbound",
        "bind", "unbind", NULL
	"set",  "reset", "get", "names", "size", "exists", "isbound",
	"bind", "unbind", NULL
    };
    enum options {
        ASET,   ARESET,  AGET,  ANAMES,  ASIZE,  AEXISTS, AISBOUND,
        ABIND,  AUNBIND
    };
	ASET,   ARESET,  AGET,  ANAMES,  ASIZE,  AEXISTS, AISBOUND,
	ABIND,  AUNBIND
    } index;

    svObj = (Container*)arg;

    if (objc < 3) {
        Tcl_WrongNumArgs(interp, 1, objv, "option array");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "option array");
	return TCL_ERROR;
    }

    arrayName = Tcl_GetString(objv[2]);
    arrayPtr  = LockArray(interp, arrayName, FLAGS_NOERRMSG);

    if (objc > 3) {
        argx = 3;
	argx = 3;
    }

    Tcl_ResetResult(interp);

    if (Tcl_GetIndexFromObjStruct(interp,objv[1],opts, sizeof(char *),"option",0,&index) != TCL_OK) {
        ret = TCL_ERROR;
	ret = TCL_ERROR;

    } else if (index == AEXISTS) {
        Tcl_SetIntObj(Tcl_GetObjResult(interp), arrayPtr!=0);
	Tcl_SetIntObj(Tcl_GetObjResult(interp), arrayPtr!=0);

    } else if (index == AISBOUND) {
        if (arrayPtr == NULL) {
            Tcl_SetIntObj(Tcl_GetObjResult(interp), 0);
        } else {
            Tcl_SetIntObj(Tcl_GetObjResult(interp), arrayPtr->psPtr!=0);
        }
	if (arrayPtr == NULL) {
	    Tcl_SetIntObj(Tcl_GetObjResult(interp), 0);
	} else {
	    Tcl_SetIntObj(Tcl_GetObjResult(interp), arrayPtr->psPtr!=0);
	}

    } else if (index == ASIZE) {
        if (arrayPtr == NULL) {
            Tcl_SetIntObj(Tcl_GetObjResult(interp), 0);
        } else {
            Tcl_SetWideIntObj(Tcl_GetObjResult(interp),arrayPtr->vars.numEntries);
        }
	if (arrayPtr == NULL) {
	    Tcl_SetIntObj(Tcl_GetObjResult(interp), 0);
	} else {
	    Tcl_SetWideIntObj(Tcl_GetObjResult(interp), (Tcl_WideInt)arrayPtr->vars.numEntries);
	}

    } else if (index == ASET || index == ARESET) {
        if (argx == (objc - 1)) {
            if (argx && Tcl_ListObjGetElements(interp, objv[argx], &lobjc,
                    &lobjv) != TCL_OK) {
                ret = TCL_ERROR;
                goto cmdExit;
            }
        } else {
            lobjc = objc - 3;
            lobjv = (Tcl_Obj**)objv + 3;
        }
        if (lobjc & 1) {
            Tcl_AppendResult(interp, "list must have an even number"
                    " of elements", NULL);
            ret = TCL_ERROR;
            goto cmdExit;
        }
        if (arrayPtr == NULL) {
            arrayPtr = LockArray(interp, arrayName, FLAGS_CREATEARRAY);
        }
        if (index == ARESET) {
            ret = FlushArray(arrayPtr);
            if (ret != TCL_OK) {
                if (arrayPtr->psPtr) {
                    PsStore *psPtr = arrayPtr->psPtr;
                    const char *err = psPtr->psError(psPtr->psHandle);
                    Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_AUTO_LENGTH));
                }
                goto cmdExit;
            }
        }
        for (i = 0; i < lobjc; i += 2) {
            const char *key = Tcl_GetString(lobjv[i]);
            elObj = AcquireContainer(arrayPtr, key, FLAGS_CREATEVAR);
            Tcl_DecrRefCount(elObj->tclObj);
            elObj->tclObj = Sv_DuplicateObj(lobjv[i+1]);
            Tcl_IncrRefCount(elObj->tclObj);
            if (ReleaseContainer(interp, elObj, SV_CHANGED) != TCL_OK) {
                ret = TCL_ERROR;
                goto cmdExit;
            }
        }
	if (argx == (objc - 1)) {
	    if (argx && Tcl_ListObjGetElements(interp, objv[argx], &lobjc,
		    &lobjv) != TCL_OK) {
		ret = TCL_ERROR;
		goto cmdExit;
	    }
	} else {
	    lobjc = objc - 3;
	    lobjv = (Tcl_Obj**)objv + 3;
	}
	if (lobjc & 1) {
	    Tcl_AppendResult(interp, "list must have an even number"
		    " of elements", (void *)NULL);
	    ret = TCL_ERROR;
	    goto cmdExit;
	}
	if (arrayPtr == NULL) {
	    arrayPtr = LockArray(interp, arrayName, FLAGS_CREATEARRAY);
	}
	if (index == ARESET) {
	    ret = FlushArray(arrayPtr);
	    if (ret != TCL_OK) {
		if (arrayPtr->psPtr) {
		    PsStore *psPtr = arrayPtr->psPtr;
		    const char *err = psPtr->psError(psPtr->psHandle);
		    Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_INDEX_NONE));
		}
		goto cmdExit;
	    }
	}
	for (i = 0; i < lobjc; i += 2) {
	    const char *key = Tcl_GetString(lobjv[i]);
	    elObj = AcquireContainer(arrayPtr, key, FLAGS_CREATEVAR);
	    Tcl_DecrRefCount(elObj->tclObj);
	    elObj->tclObj = Sv_DuplicateObj(lobjv[i+1]);
	    Tcl_IncrRefCount(elObj->tclObj);
	    if (ReleaseContainer(interp, elObj, SV_CHANGED) != TCL_OK) {
		ret = TCL_ERROR;
		goto cmdExit;
	    }
	}

    } else if (index == AGET || index == ANAMES) {
        if (arrayPtr) {
            Tcl_HashSearch search;
            Tcl_Obj *resObj = Tcl_NewListObj(0, NULL);
            const char *pattern = (argx == 0) ? NULL : Tcl_GetString(objv[argx]);
            Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&arrayPtr->vars,&search);
            while (hPtr) {
                char *key = (char *)Tcl_GetHashKey(&arrayPtr->vars, hPtr);
                if (pattern == NULL || Tcl_StringCaseMatch(key, pattern, 0)) {
                    Tcl_ListObjAppendElement(interp, resObj,
                            Tcl_NewStringObj(key, TCL_AUTO_LENGTH));
                    if (index == AGET) {
                        elObj = (Container*)Tcl_GetHashValue(hPtr);
                        Tcl_ListObjAppendElement(interp, resObj,
                                Sv_DuplicateObj(elObj->tclObj));
                    }
                }
                hPtr = Tcl_NextHashEntry(&search);
            }
            Tcl_SetObjResult(interp, resObj);
        }
	if (arrayPtr) {
	    Tcl_HashSearch search;
	    Tcl_Obj *resObj = Tcl_NewListObj(0, NULL);
	    const char *pattern = (argx == 0) ? NULL : Tcl_GetString(objv[argx]);
	    Tcl_HashEntry *hPtr = Tcl_FirstHashEntry(&arrayPtr->vars,&search);
	    while (hPtr) {
		char *key = (char *)Tcl_GetHashKey(&arrayPtr->vars, hPtr);
		if (pattern == NULL || Tcl_StringCaseMatch(key, pattern, 0)) {
		    Tcl_ListObjAppendElement(interp, resObj,
			    Tcl_NewStringObj(key, TCL_INDEX_NONE));
		    if (index == AGET) {
			elObj = (Container*)Tcl_GetHashValue(hPtr);
			Tcl_ListObjAppendElement(interp, resObj,
				Sv_DuplicateObj(elObj->tclObj));
		    }
		}
		hPtr = Tcl_NextHashEntry(&search);
	    }
	    Tcl_SetObjResult(interp, resObj);
	}

    } else if (index == ABIND) {

        /*
         * This is more complex operation, requiring some clarification.
         *
         * When binding an already existing array, we walk the array
         * first and store all key/value pairs found there in the
         * persistent storage. Then we proceed with the below.
         *
         * When binding an non-existent array, we open the persistent
         * storage and cache all key/value pairs found there into tne
         * newly created shared array.
         */
	/*
	 * This is more complex operation, requiring some clarification.
	 *
	 * When binding an already existing array, we walk the array
	 * first and store all key/value pairs found there in the
	 * persistent storage. Then we proceed with the below.
	 *
	 * When binding an non-existent array, we open the persistent
	 * storage and cache all key/value pairs found there into tne
	 * newly created shared array.
	 */

        PsStore *psPtr;
        Tcl_HashEntry *hPtr;
        size_t len;
        int isNew;
        char *psurl, *key = NULL, *val = NULL;
	PsStore *psPtr;
	Tcl_HashEntry *hPtr;
	Tcl_Size len;
	int isNew;
	char *psurl, *key = NULL, *val = NULL;

        if (objc < 4) {
            Tcl_WrongNumArgs(interp, 2, objv, "array handle");
            ret = TCL_ERROR;
            goto cmdExit;
        }
	if (objc < 4) {
	    Tcl_WrongNumArgs(interp, 2, objv, "array handle");
	    ret = TCL_ERROR;
	    goto cmdExit;
	}

        if (arrayPtr && arrayPtr->psPtr) {
            Tcl_AppendResult(interp, "array is already bound", NULL);
            ret = TCL_ERROR;
            goto cmdExit;
        }
	if (arrayPtr && arrayPtr->psPtr) {
	    Tcl_AppendResult(interp, "array is already bound", (void *)NULL);
	    ret = TCL_ERROR;
	    goto cmdExit;
	}

        psurl = Tcl_GetString(objv[3]);
	psurl = Tcl_GetStringFromObj(objv[3], &len);
        len = objv[3]->length;
        psPtr = GetPsStore(psurl);
	psPtr = GetPsStore(psurl);

        if (psPtr == NULL) {
            Tcl_AppendResult(interp, "can't open persistent storage on \"",
                             psurl, "\"", NULL);
            ret = TCL_ERROR;
            goto cmdExit;
        }
        if (arrayPtr) {
            Tcl_HashSearch search;
            hPtr = Tcl_FirstHashEntry(&arrayPtr->vars,&search);
            arrayPtr->psPtr = psPtr;
            arrayPtr->bindAddr = strcpy((char *)Tcl_Alloc(len+1), psurl);
            while (hPtr) {
                svObj = (Container *)Tcl_GetHashValue(hPtr);
                if (ReleaseContainer(interp, svObj, SV_CHANGED) != TCL_OK) {
                    ret = TCL_ERROR;
                    goto cmdExit;
                }
                hPtr = Tcl_NextHashEntry(&search);
            }
        } else {
            arrayPtr = LockArray(interp, arrayName, FLAGS_CREATEARRAY);
            arrayPtr->psPtr = psPtr;
            arrayPtr->bindAddr = strcpy((char *)Tcl_Alloc(len+1), psurl);
        }
        if (!psPtr->psFirst(psPtr->psHandle, &key, &val, &len)) {
            do {
                Tcl_Obj * tclObj = Tcl_NewStringObj(val, len);
                hPtr = Tcl_CreateHashEntry(&arrayPtr->vars, key, &isNew);
                Tcl_SetHashValue(hPtr, CreateContainer(arrayPtr, hPtr, tclObj));
                psPtr->psFree(psPtr->psHandle, val);
            } while (!psPtr->psNext(psPtr->psHandle, &key, &val, &len));
        }
	if (psPtr == NULL) {
	    Tcl_AppendResult(interp, "can't open persistent storage on \"",
			     psurl, "\"", (void *)NULL);
	    ret = TCL_ERROR;
	    goto cmdExit;
	}
	if (arrayPtr) {
	    Tcl_HashSearch search;
	    hPtr = Tcl_FirstHashEntry(&arrayPtr->vars,&search);
	    arrayPtr->psPtr = psPtr;
	    arrayPtr->bindAddr = strcpy((char *)Tcl_Alloc(len+1), psurl);
	    while (hPtr) {
		svObj = (Container *)Tcl_GetHashValue(hPtr);
		if (ReleaseContainer(interp, svObj, SV_CHANGED) != TCL_OK) {
		    ret = TCL_ERROR;
		    goto cmdExit;
		}
		hPtr = Tcl_NextHashEntry(&search);
	    }
	} else {
	    arrayPtr = LockArray(interp, arrayName, FLAGS_CREATEARRAY);
	    arrayPtr->psPtr = psPtr;
	    arrayPtr->bindAddr = strcpy((char *)Tcl_Alloc(len+1), psurl);
	}
	if (!psPtr->psFirst(psPtr->psHandle, &key, &val, &len)) {
	    do {
		Tcl_Obj * tclObj = Tcl_NewStringObj(val, len);
		hPtr = Tcl_CreateHashEntry(&arrayPtr->vars, key, &isNew);
		Tcl_SetHashValue(hPtr, CreateContainer(arrayPtr, hPtr, tclObj));
		psPtr->psFree(psPtr->psHandle, val);
	    } while (!psPtr->psNext(psPtr->psHandle, &key, &val, &len));
	}

    } else if (index == AUNBIND) {
        if (!arrayPtr || !arrayPtr->psPtr) {
            Tcl_AppendResult(interp, "shared variable is not bound", NULL);
            ret = TCL_ERROR;
            goto cmdExit;
        }
        if (UnbindArray(interp, arrayPtr) != TCL_OK) {
            ret = TCL_ERROR;
            goto cmdExit;
        }
	if (!arrayPtr || !arrayPtr->psPtr) {
	    Tcl_AppendResult(interp, "shared variable is not bound", (void *)NULL);
	    ret = TCL_ERROR;
	    goto cmdExit;
	}
	if (UnbindArray(interp, arrayPtr) != TCL_OK) {
	    ret = TCL_ERROR;
	    goto cmdExit;
	}
    }

 cmdExit:
    if (arrayPtr) {
        UnlockArray(arrayPtr);
	UnlockArray(arrayPtr);
    }

    return ret;
}

/*
 *-----------------------------------------------------------------------------
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445




1446
1447

1448
1449
1450
1451
1452
1453
1454


1455
1456
1457
1458
1459
1460
1461

1462
1463
1464
1465
1466
1467




1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
















1485
1486
1487
1488
1489
1490
1491
1439
1440
1441
1442
1443
1444
1445




1446
1447
1448
1449
1450

1451
1452
1453

1454
1455


1456
1457
1458
1459
1460
1461
1462
1463

1464
1465
1466




1467
1468
1469
1470
1471
















1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494







-
-
-
-
+
+
+
+

-
+


-


-
-
+
+






-
+


-
-
-
-
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvUnsetObjCmd(
              void *dummy,                   /* Not used. */
              Tcl_Interp *interp,                 /* Current interpreter. */
              int objc,                   /* Number of arguments. */
              Tcl_Obj *const objv[])              /* Argument objects. */
	      TCL_UNUSED(void *),                 /* Not used. */
	      Tcl_Interp *interp,                 /* Current interpreter. */
	      Tcl_Size objc,                   /* Number of arguments. */
	      Tcl_Obj *const objv[])              /* Argument objects. */
{
    int ii;
    Tcl_Size ii;
    const char *arrayName;
    Array *arrayPtr;
    (void)dummy;

    if (objc < 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "array ?key ...?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "array ?key ...?");
	return TCL_ERROR;
    }

    arrayName = Tcl_GetString(objv[1]);
    arrayPtr  = LockArray(interp, arrayName, 0);

    if (arrayPtr == NULL) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if (objc == 2) {
        UnlockArray(arrayPtr);
        if (DeleteArray(interp, arrayPtr) != TCL_OK) {
            return TCL_ERROR;
        }
	UnlockArray(arrayPtr);
	if (DeleteArray(interp, arrayPtr) != TCL_OK) {
	    return TCL_ERROR;
	}
    } else {
        for (ii = 2; ii < objc; ii++) {
            const char *key = Tcl_GetString(objv[ii]);
            Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&arrayPtr->vars, key);
            if (hPtr) {
                if (DeleteContainer((Container*)Tcl_GetHashValue(hPtr))
                    != TCL_OK) {
                    UnlockArray(arrayPtr);
                    return TCL_ERROR;
                }
            } else {
                UnlockArray(arrayPtr);
                Tcl_AppendResult(interp,"no key ",arrayName,"(",key,")",NULL);
                return TCL_ERROR;
            }
        }
        UnlockArray(arrayPtr);
	for (ii = 2; ii < objc; ii++) {
	    const char *key = Tcl_GetString(objv[ii]);
	    Tcl_HashEntry *hPtr = Tcl_FindHashEntry(&arrayPtr->vars, key);
	    if (hPtr) {
		if (DeleteContainer((Container*)Tcl_GetHashValue(hPtr))
		    != TCL_OK) {
		    UnlockArray(arrayPtr);
		    return TCL_ERROR;
		}
	    } else {
		UnlockArray(arrayPtr);
		Tcl_AppendResult(interp,"no key ",arrayName,"(",key,")",(void *)NULL);
		return TCL_ERROR;
	    }
	}
	UnlockArray(arrayPtr);
    }

    return TCL_OK;
}

/*
 *-----------------------------------------------------------------------------
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512




1513
1514
1515
1516
1517
1518
1519
1520
1521
1522


1523
1524
1525

1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543













1544
1545
1546
1547
1548
1549
1550
1505
1506
1507
1508
1509
1510
1511




1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523


1524
1525
1526
1527

1528
1529
1530
1531
1532
1533













1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553







-
-
-
-
+
+
+
+








-
-
+
+


-
+





-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+







 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvNamesObjCmd(
              void *arg,                     /* != NULL if aolSpecial */
              Tcl_Interp *interp,                 /* Current interpreter. */
              int objc,                   /* Number of arguments. */
              Tcl_Obj *const objv[])              /* Argument objects. */
	      void *arg,                     /* != NULL if aolSpecial */
	      Tcl_Interp *interp,                 /* Current interpreter. */
	      Tcl_Size objc,                   /* Number of arguments. */
	      Tcl_Obj *const objv[])              /* Argument objects. */
{
    int i;
    const char *pattern = NULL;
    Tcl_HashEntry *hPtr;
    Tcl_HashSearch search;
    Tcl_Obj *resObj;

    if (objc > 2) {
        Tcl_WrongNumArgs(interp, 1, objv, "?pattern?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "?pattern?");
	return TCL_ERROR;
    }
    if (objc == 2) {
        pattern = Tcl_GetString(objv[1]);
	pattern = Tcl_GetString(objv[1]);
    }

    resObj = Tcl_NewListObj(0, NULL);

    for (i = 0; i < NUMBUCKETS; i++) {
        Bucket *bucketPtr = &buckets[i];
        LOCK_BUCKET(bucketPtr);
        hPtr = Tcl_FirstHashEntry(&bucketPtr->arrays, &search);
        while (hPtr) {
            char *key = (char *)Tcl_GetHashKey(&bucketPtr->arrays, hPtr);
            if ((arg==NULL || (*key != '.')) /* Hide .<name> arrays for AOL*/ &&
                (pattern == NULL || Tcl_StringCaseMatch(key, pattern, 0))) {
                Tcl_ListObjAppendElement(interp, resObj,
                        Tcl_NewStringObj(key, -1));
            }
            hPtr = Tcl_NextHashEntry(&search);
        }
        UNLOCK_BUCKET(bucketPtr);
	Bucket *bucketPtr = &buckets[i];
	LOCK_BUCKET(bucketPtr);
	hPtr = Tcl_FirstHashEntry(&bucketPtr->arrays, &search);
	while (hPtr) {
	    char *key = (char *)Tcl_GetHashKey(&bucketPtr->arrays, hPtr);
	    if ((arg==NULL || (*key != '.')) /* Hide .<name> arrays for AOL*/ &&
		(pattern == NULL || Tcl_StringCaseMatch(key, pattern, 0))) {
		Tcl_ListObjAppendElement(interp, resObj,
			Tcl_NewStringObj(key, TCL_INDEX_NONE));
	    }
	    hPtr = Tcl_NextHashEntry(&search);
	}
	UNLOCK_BUCKET(bucketPtr);
    }

    Tcl_SetObjResult(interp, resObj);

    return TCL_OK;
}

1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573




1574
1575


1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593






1594
1595

1596
1597
1598
1599
1600
1601


1602
1603
1604
1605
1606
1607





1608
1609
1610
1611
1612
1613
1614
1566
1567
1568
1569
1570
1571
1572




1573
1574
1575
1576
1577

1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591






1592
1593
1594
1595
1596
1597
1598

1599
1600
1601
1602
1603


1604
1605
1606





1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618







-
-
-
-
+
+
+
+

-
+
+












-
-
-
-
-
-
+
+
+
+
+
+

-
+




-
-
+
+

-
-
-
-
-
+
+
+
+
+







 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvGetObjCmd(
            void *arg,                     /* Pointer to object container. */
            Tcl_Interp *interp,                 /* Current interpreter. */
            int objc,                   /* Number of arguments. */
            Tcl_Obj *const objv[])              /* Argument objects. */
	    void *arg,                     /* Pointer to object container. */
	    Tcl_Interp *interp,                 /* Current interpreter. */
	    Tcl_Size objc,                   /* Number of arguments. */
	    Tcl_Obj *const objv[])              /* Argument objects. */
{
    int off, ret;
    int ret;
    Tcl_Size off;
    Tcl_Obj *res;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::get array key ?var?
     *          $object get ?var?
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    switch (ret) {
    case TCL_BREAK:
        if ((objc - off) == 0) {
            return TCL_ERROR;
        } else {
            Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
            return TCL_OK;
        }
	if (objc == off) {
	    return TCL_ERROR;
	} else {
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
	    return TCL_OK;
	}
    case TCL_ERROR:
        return TCL_ERROR;
	return TCL_ERROR;
    }

    res = Sv_DuplicateObj(svObj->tclObj);

    if ((objc - off) == 0) {
        Tcl_SetObjResult(interp, res);
    if (objc == off) {
	Tcl_SetObjResult(interp, res);
    } else {
        if (Tcl_ObjSetVar2(interp, objv[off], NULL, res, 0) == NULL) {
            Tcl_DecrRefCount(res);
            goto cmd_err;
        }
        Tcl_SetObjResult(interp, Tcl_NewIntObj(1));
	if (Tcl_ObjSetVar2(interp, objv[off], NULL, res, 0) == NULL) {
	    Tcl_DecrRefCount(res);
	    goto cmd_err;
	}
	Tcl_SetObjResult(interp, Tcl_NewIntObj(1));
    }

    return Sv_PutContainer(interp, svObj, SV_UNCHANGED);

 cmd_err:
    return Sv_PutContainer(interp, svObj, SV_ERROR);
}
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638




1639

1640

1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653


1654
1655

1656
1657
1658
1659
1660
1661
1662
1632
1633
1634
1635
1636
1637
1638




1639
1640
1641
1642
1643
1644

1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656


1657
1658
1659

1660
1661
1662
1663
1664
1665
1666
1667







-
-
-
-
+
+
+
+

+
-
+











-
-
+
+

-
+







 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvExistsObjCmd(
               void *arg,                     /* Pointer to object container. */
               Tcl_Interp *interp,                 /* Current interpreter. */
               int objc,                   /* Number of arguments. */
               Tcl_Obj *const objv[])              /* Argument objects. */
	       void *arg,                     /* Pointer to object container. */
	       Tcl_Interp *interp,                 /* Current interpreter. */
	       Tcl_Size objc,                   /* Number of arguments. */
	       Tcl_Obj *const objv[])              /* Argument objects. */
{
    Tcl_Size off;
    int off, ret;
    int ret;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::exists array key
     *          $object exists
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    switch (ret) {
    case TCL_BREAK: /* Array/key not found */
        Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
        return TCL_OK;
	Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
	return TCL_OK;
    case TCL_ERROR:
        return TCL_ERROR;
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Tcl_NewIntObj(1));

    return Sv_PutContainer(interp, svObj, SV_UNCHANGED);
}

1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685




1686
1687


1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710











1711
1712

1713
1714
1715
1716
1717
1718
1719






1720
1721
1722


1723
1724
1725
1726
1727
1728
1729
1680
1681
1682
1683
1684
1685
1686




1687
1688
1689
1690
1691

1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705











1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717

1718
1719






1720
1721
1722
1723
1724
1725
1726


1727
1728
1729
1730
1731
1732
1733
1734
1735







-
-
-
-
+
+
+
+

-
+
+












-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+

-
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+







 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvSetObjCmd(
            void *arg,                     /* Pointer to object container */
            Tcl_Interp *interp,                 /* Current interpreter. */
            int objc,                   /* Number of arguments. */
            Tcl_Obj *const objv[])              /* Argument objects. */
	    void *arg,                     /* Pointer to object container */
	    Tcl_Interp *interp,                 /* Current interpreter. */
	    Tcl_Size objc,                   /* Number of arguments. */
	    Tcl_Obj *const objv[])              /* Argument objects. */
{
    int ret, off, flg, mode;
    int ret, flg, mode;
    Tcl_Size off;
    Tcl_Obj *val;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::set array key ?value?
     *          $object set ?value?
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    switch (ret) {
    case TCL_BREAK:
        if ((objc - off) == 0) {
            return TCL_ERROR;
        } else {
            Tcl_ResetResult(interp);
            flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
            ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
            if (ret != TCL_OK) {
                return TCL_ERROR;
            }
        }
        break;
	if (objc == off) {
	    return TCL_ERROR;
	} else {
	    Tcl_ResetResult(interp);
	    flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
	    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
	    if (ret != TCL_OK) {
		return TCL_ERROR;
	    }
	}
	break;
    case TCL_ERROR:
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off)) {
        val = objv[off];
        Tcl_DecrRefCount(svObj->tclObj);
        svObj->tclObj = Sv_DuplicateObj(val);
        Tcl_IncrRefCount(svObj->tclObj);
        mode = SV_CHANGED;
    if (objc != off) {
	val = objv[off];
	Tcl_DecrRefCount(svObj->tclObj);
	svObj->tclObj = Sv_DuplicateObj(val);
	Tcl_IncrRefCount(svObj->tclObj);
	mode = SV_CHANGED;
    } else {
        val = Sv_DuplicateObj(svObj->tclObj);
        mode = SV_UNCHANGED;
	val = Sv_DuplicateObj(svObj->tclObj);
	mode = SV_UNCHANGED;
    }

    Tcl_SetObjResult(interp, val);

    return Sv_PutContainer(interp, svObj, mode);
}

1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752




1753
1754


1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775










1776
1777
1778
1779
1780
1781





1782
1783
1784

1785
1786
1787
1788
1789




1790
1791
1792
1793
1794
1795
1796
1748
1749
1750
1751
1752
1753
1754




1755
1756
1757
1758
1759

1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772










1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783





1784
1785
1786
1787
1788
1789
1790

1791
1792




1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803







-
-
-
-
+
+
+
+

-
+
+











-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+


-
+

-
-
-
-
+
+
+
+







 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvIncrObjCmd(
             void *arg,                     /* Pointer to object container */
             Tcl_Interp *interp,                 /* Current interpreter. */
             int objc,                   /* Number of arguments. */
             Tcl_Obj *const objv[])              /* Argument objects. */
	     void *arg,                     /* Pointer to object container */
	     Tcl_Interp *interp,                 /* Current interpreter. */
	     Tcl_Size objc,                   /* Number of arguments. */
	     Tcl_Obj *const objv[])              /* Argument objects. */
{
    int off, ret, flg, isNew = 0;
    int ret, flg, isNew = 0;
    Tcl_Size off;
    Tcl_WideInt incrValue = 1, currValue = 0;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::incr array key ?increment?
     *          $object incr ?increment?
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        if (ret != TCL_BREAK) {
            return TCL_ERROR;
        }
        flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
        Tcl_ResetResult(interp);
        ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
        if (ret != TCL_OK) {
            return TCL_ERROR;
        }
        isNew = 1;
	if (ret != TCL_BREAK) {
	    return TCL_ERROR;
	}
	flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
	Tcl_ResetResult(interp);
	ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
	if (ret != TCL_OK) {
	    return TCL_ERROR;
	}
	isNew = 1;
    }
    if ((objc - off)) {
        ret = Tcl_GetWideIntFromObj(interp, objv[off], &incrValue);
        if (ret != TCL_OK) {
            goto cmd_err;
        }
    if ((objc != off)) {
	ret = Tcl_GetWideIntFromObj(interp, objv[off], &incrValue);
	if (ret != TCL_OK) {
	    goto cmd_err;
	}
    }
    if (isNew) {
        currValue = 0;
	currValue = 0;
    } else {
        ret = Tcl_GetWideIntFromObj(interp, svObj->tclObj, &currValue);
        if (ret != TCL_OK) {
            goto cmd_err;
        }
	ret = Tcl_GetWideIntFromObj(interp, svObj->tclObj, &currValue);
	if (ret != TCL_OK) {
	    goto cmd_err;
	}
    }

    incrValue += currValue;
    Tcl_SetWideIntObj(svObj->tclObj, incrValue);
    Tcl_ResetResult(interp);
    Tcl_SetWideIntObj(Tcl_GetObjResult(interp), incrValue);

1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825




1826
1827


1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839

1840
1841
1842
1843



1844
1845
1846

1847
1848
1849
1850
1851
1852
1853
1822
1823
1824
1825
1826
1827
1828




1829
1830
1831
1832
1833

1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846

1847
1848



1849
1850
1851
1852
1853

1854
1855
1856
1857
1858
1859
1860
1861







-
-
-
-
+
+
+
+

-
+
+











-
+

-
-
-
+
+
+


-
+







 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvAppendObjCmd(
               void *arg,                     /* Pointer to object container */
               Tcl_Interp *interp,                 /* Current interpreter. */
               int objc,                   /* Number of arguments. */
               Tcl_Obj *const objv[])              /* Argument objects. */
	       void *arg,                     /* Pointer to object container */
	       Tcl_Interp *interp,                 /* Current interpreter. */
	       Tcl_Size objc,                   /* Number of arguments. */
	       Tcl_Obj *const objv[])              /* Argument objects. */
{
    int i, off, flg, ret;
    int flg, ret;
    Tcl_Size i, off;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::append array key value ?value ...?
     *          $object append value ?value ...?
     */

    flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) < 1) {
        Tcl_WrongNumArgs(interp, off, objv, "value ?value ...?");
        goto cmd_err;
    if (objc < 1 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "value ?value ...?");
	goto cmd_err;
    }
    for (i = off; i < objc; ++i) {
        Tcl_AppendObjToObj(svObj->tclObj, Sv_DuplicateObj(objv[i]));
	Tcl_AppendObjToObj(svObj->tclObj, Sv_DuplicateObj(objv[i]));
    }

    Tcl_SetObjResult(interp, Sv_DuplicateObj(svObj->tclObj));

    return Sv_PutContainer(interp, svObj, SV_CHANGED);

 cmd_err:
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879




1880
1881


1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902






1903
1904

1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919







1920
1921
1922
1923


1924
1925
1926
1927
1928
1929





1930
1931
1932
1933
1934
1935
1936
1877
1878
1879
1880
1881
1882
1883




1884
1885
1886
1887
1888

1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905






1906
1907
1908
1909
1910
1911
1912

1913
1914
1915
1916
1917
1918
1919
1920
1921







1922
1923
1924
1925
1926
1927
1928
1929
1930


1931
1932
1933





1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945







-
-
-
-
+
+
+
+

-
+
+















-
-
-
-
-
-
+
+
+
+
+
+

-
+








-
-
-
-
-
-
-
+
+
+
+
+
+
+


-
-
+
+

-
-
-
-
-
+
+
+
+
+







 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvPopObjCmd(
            void *arg,                     /* Pointer to object container */
            Tcl_Interp *interp,                 /* Current interpreter. */
            int objc,                   /* Number of arguments. */
            Tcl_Obj *const objv[])              /* Argument objects. */
	    void *arg,                     /* Pointer to object container */
	    Tcl_Interp *interp,                 /* Current interpreter. */
	    Tcl_Size objc,                   /* Number of arguments. */
	    Tcl_Obj *const objv[])              /* Argument objects. */
{
    int ret, off;
    int ret;
    Tcl_Size off;
    Tcl_Obj *retObj;
    Array *arrayPtr = NULL;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::pop array key ?var?
     *          $object pop ?var?
     *
     * Note: the object command will run into error next time !
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    switch (ret) {
    case TCL_BREAK:
        if ((objc - off) == 0) {
            return TCL_ERROR;
        } else {
            Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
            return TCL_OK;
        }
	if (objc == off) {
	    return TCL_ERROR;
	} else {
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
	    return TCL_OK;
	}
    case TCL_ERROR:
        return TCL_ERROR;
	return TCL_ERROR;
    }

    arrayPtr = svObj->arrayPtr;

    retObj = svObj->tclObj;
    svObj->tclObj = NULL;

    if (DeleteContainer(svObj) != TCL_OK) {
        if (svObj->arrayPtr->psPtr) {
            PsStore *psPtr = svObj->arrayPtr->psPtr;
            const char *err = psPtr->psError(psPtr->psHandle);
            Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_AUTO_LENGTH));
        }
        ret = TCL_ERROR;
        goto cmd_exit;
	if (svObj->arrayPtr->psPtr) {
	    PsStore *psPtr = svObj->arrayPtr->psPtr;
	    const char *err = psPtr->psError(psPtr->psHandle);
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_INDEX_NONE));
	}
	ret = TCL_ERROR;
	goto cmd_exit;
    }

    if ((objc - off) == 0) {
        Tcl_SetObjResult(interp, retObj);
    if (objc == off) {
	Tcl_SetObjResult(interp, retObj);
    } else {
        if (Tcl_ObjSetVar2(interp, objv[off], NULL, retObj, 0) == NULL) {
            ret = TCL_ERROR;
            goto cmd_exit;
        }
        Tcl_SetObjResult(interp, Tcl_NewIntObj(1));
	if (Tcl_ObjSetVar2(interp, objv[off], NULL, retObj, 0) == NULL) {
	    ret = TCL_ERROR;
	    goto cmd_exit;
	}
	Tcl_SetObjResult(interp, Tcl_NewIntObj(1));
    }

  cmd_exit:
    Tcl_DecrRefCount(retObj);
    UnlockArray(arrayPtr);

    return ret;
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962




1963
1964


1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977

1978
1979
1980
1981
1982
1983
1984
1985


1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997










1998
1999
2000
2001
2002
2003
2004
1961
1962
1963
1964
1965
1966
1967




1968
1969
1970
1971
1972

1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986

1987
1988
1989
1990
1991
1992
1993


1994
1995
1996
1997










1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014







-
-
-
-
+
+
+
+

-
+
+












-
+






-
-
+
+


-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

static int
SvMoveObjCmd(
             void *arg,                     /* Pointer to object container. */
             Tcl_Interp *interp,                 /* Current interpreter. */
             int objc,                   /* Number of arguments. */
             Tcl_Obj *const objv[])              /* Argument objects. */
	     void *arg,                     /* Pointer to object container. */
	     Tcl_Interp *interp,                 /* Current interpreter. */
	     Tcl_Size objc,                   /* Number of arguments. */
	     Tcl_Obj *const objv[])              /* Argument objects. */
{
    int ret, off, isNew;
    int ret, isNew;
    Tcl_Size off;
    const char *toKey;
    Tcl_HashEntry *hPtr;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::move array key to
     *          $object move to
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    toKey = Tcl_GetString(objv[off]);
    hPtr = Tcl_CreateHashEntry(&svObj->arrayPtr->vars, toKey, &isNew);

    if (!isNew) {
        Tcl_AppendResult(interp, "key \"", toKey, "\" exists", NULL);
        goto cmd_err;
	Tcl_AppendResult(interp, "key \"", toKey, "\" exists", (void *)NULL);
	goto cmd_err;
    }
    if (svObj->entryPtr) {
        char *key = (char *)Tcl_GetHashKey(&svObj->arrayPtr->vars, svObj->entryPtr);
        if (svObj->arrayPtr->psPtr) {
            PsStore *psPtr = svObj->arrayPtr->psPtr;
            if (psPtr->psDelete(psPtr->psHandle, key) == -1) {
                const char *err = psPtr->psError(psPtr->psHandle);
                Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_AUTO_LENGTH));
                return TCL_ERROR;
            }
        }
        Tcl_DeleteHashEntry(svObj->entryPtr);
	char *key = (char *)Tcl_GetHashKey(&svObj->arrayPtr->vars, svObj->entryPtr);
	if (svObj->arrayPtr->psPtr) {
	    PsStore *psPtr = svObj->arrayPtr->psPtr;
	    if (psPtr->psDelete(psPtr->psHandle, key) == -1) {
		const char *err = psPtr->psError(psPtr->psHandle);
		Tcl_SetObjResult(interp, Tcl_NewStringObj(err, TCL_INDEX_NONE));
		return TCL_ERROR;
	    }
	}
	Tcl_DeleteHashEntry(svObj->entryPtr);
    }

    svObj->entryPtr = hPtr;
    Tcl_SetHashValue(hPtr, svObj);

    return Sv_PutContainer(interp, svObj, SV_CHANGED);

2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032




2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048


2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062

2063
2064

2065
2066
2067
2068
2069
2070
2071

2072
2073
2074
2075


2076
2077
2078
2079
2080
2081
2082
2032
2033
2034
2035
2036
2037
2038




2039
2040
2041
2042
2043
2044
2045
2046
2047

2048
2049
2050
2051
2052
2053
2054
2055


2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070

2071
2072

2073
2074
2075
2076
2077
2078
2079

2080




2081
2082
2083
2084
2085
2086
2087
2088
2089







-
-
-
-
+
+
+
+





-








-
-
+
+













-
+

-
+






-
+
-
-
-
-
+
+







 *    See the user documentation.
 *
 *----------------------------------------------------------------------
 */

static int
SvLockObjCmd(
             void *dummy,                   /* Not used. */
             Tcl_Interp *interp,                 /* Current interpreter. */
             int objc,                   /* Number of arguments. */
             Tcl_Obj *const objv[])              /* Argument objects. */
	     TCL_UNUSED(void *),                 /* Not used. */
	     Tcl_Interp *interp,                 /* Current interpreter. */
	     Tcl_Size objc,                   /* Number of arguments. */
	     Tcl_Obj *const objv[])              /* Argument objects. */
{
    int ret;
    Tcl_Obj *scriptObj;
    Bucket *bucketPtr;
    Array *arrayPtr = NULL;
    (void)dummy;

    /*
     * Syntax:
     *
     *     tsv::lock array arg ?arg ...?
     */

    if (objc < 3) {
        Tcl_WrongNumArgs(interp, 1, objv, "array arg ?arg...?");
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, "array arg ?arg...?");
	return TCL_ERROR;
    }

    arrayPtr  = LockArray(interp, Tcl_GetString(objv[1]), FLAGS_CREATEARRAY);
    bucketPtr = arrayPtr->bucketPtr;

    /*
     * Evaluate passed arguments as Tcl script. Note that
     * Tcl_EvalObjEx throws away the passed object by
     * doing an decrement reference count on it. This also
     * means we need not build object bytecode rep.
     */

    if (objc == 3) {
        scriptObj = Tcl_DuplicateObj(objv[2]);
	scriptObj = Tcl_DuplicateObj(objv[2]);
    } else {
        scriptObj = Tcl_ConcatObj(objc-2, objv + 2);
	scriptObj = Tcl_ConcatObj(objc-2, objv + 2);
    }

    Tcl_AllowExceptions(interp);
    ret = Tcl_EvalObjEx(interp, scriptObj, TCL_EVAL_DIRECT);

    if (ret == TCL_ERROR) {
        char msg[32 + TCL_INTEGER_SPACE];
	char msg[32 + TCL_INTEGER_SPACE];
        /* Next line generates a Deprecation warning when compiled with Tcl 8.6.
         * See Tcl bug #3562640 */
        sprintf(msg, "\n    (\"eval\" body line %d)", Tcl_GetErrorLine(interp));
        Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(msg, TCL_AUTO_LENGTH));
	snprintf(msg, sizeof(msg), "\n    (\"eval\" body line %d)", Tcl_GetErrorLine(interp));
	Tcl_AppendObjToErrorInfo(interp, Tcl_NewStringObj(msg, TCL_INDEX_NONE));
    }

    /*
     * We unlock the bucket directly, w/o going to Sv_Unlock()
     * since it needs the array which may be unset by the script.
     */

2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109




2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122


2123
2124
2125
2126
2127
2128

2129
2130
2131
2132
2133
2134
2135
2106
2107
2108
2109
2110
2111
2112




2113
2114
2115
2116
2117
2118

2119
2120
2121
2122
2123
2124
2125
2126


2127
2128
2129
2130
2131
2132
2133

2134
2135
2136
2137
2138
2139
2140
2141







-
-
-
-
+
+
+
+


-








-
-
+
+





-
+







 * Side effects:
 *      None.
 *
 *-----------------------------------------------------------------------------
 */
static int
SvHandlersObjCmd(
             void *dummy,                     /* Not used. */
             Tcl_Interp *interp,                 /* Current interpreter. */
             int objc,                           /* Number of arguments. */
             Tcl_Obj *const objv[])              /* Argument objects. */
	     TCL_UNUSED(void *),                 /* Not used. */
	     Tcl_Interp *interp,                 /* Current interpreter. */
	     Tcl_Size objc,                           /* Number of arguments. */
	     Tcl_Obj *const objv[])              /* Argument objects. */
{
    PsStore *tmpPtr = NULL;
    (void)dummy;

    /*
     * Syntax:
     *
     *     tsv::handlers
     */

    if (objc != 1) {
        Tcl_WrongNumArgs(interp, 1, objv, NULL);
        return TCL_ERROR;
	Tcl_WrongNumArgs(interp, 1, objv, NULL);
	return TCL_ERROR;
    }

    Tcl_ResetResult(interp);
    Tcl_MutexLock(&svMutex);
    for (tmpPtr = psStore; tmpPtr; tmpPtr = tmpPtr->nextPtr) {
        Tcl_AppendElement(interp, tmpPtr->type);
	Tcl_AppendElement(interp, tmpPtr->type);
    }
    Tcl_MutexUnlock(&svMutex);

    return TCL_OK;
}


2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176



















2177
2178
2179
2180
2181
2182
2183

2184
2185
2186
2187
2188

2189
2190
2191
2192
2193
2194
2195
2196
2197


2198
2199

2200

2201
2202
2203
2204
2205
2206
2207
2157
2158
2159
2160
2161
2162
2163



















2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188

2189
2190
2191
2192
2193

2194
2195
2196
2197
2198
2199
2200
2201


2202
2203
2204
2205
2206

2207
2208
2209
2210
2211
2212
2213
2214







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+






-
+




-
+







-
-
+
+


+
-
+








static void
SvRegisterStdCommands(void)
{
    static int initialized = 0;

    if (initialized == 0) {
        Tcl_MutexLock(&initMutex);
        if (initialized == 0) {
            Sv_RegisterCommand("var",      SvObjObjCmd,      NULL, 1);
            Sv_RegisterCommand("object",   SvObjObjCmd,      NULL, 1);
            Sv_RegisterCommand("set",      SvSetObjCmd,      NULL, 0);
            Sv_RegisterCommand("unset",    SvUnsetObjCmd,    NULL, 0);
            Sv_RegisterCommand("get",      SvGetObjCmd,      NULL, 0);
            Sv_RegisterCommand("incr",     SvIncrObjCmd,     NULL, 0);
            Sv_RegisterCommand("exists",   SvExistsObjCmd,   NULL, 0);
            Sv_RegisterCommand("append",   SvAppendObjCmd,   NULL, 0);
            Sv_RegisterCommand("array",    SvArrayObjCmd,    NULL, 0);
            Sv_RegisterCommand("names",    SvNamesObjCmd,    NULL, 0);
            Sv_RegisterCommand("pop",      SvPopObjCmd,      NULL, 0);
            Sv_RegisterCommand("move",     SvMoveObjCmd,     NULL, 0);
            Sv_RegisterCommand("lock",     SvLockObjCmd,     NULL, 0);
            Sv_RegisterCommand("handlers", SvHandlersObjCmd, NULL, 0);
            initialized = 1;
        }
        Tcl_MutexUnlock(&initMutex);
	Tcl_MutexLock(&initMutex);
	if (initialized == 0) {
	    Sv_RegisterCommand("var",      SvObjObjCmd,      NULL, 1);
	    Sv_RegisterCommand("object",   SvObjObjCmd,      NULL, 1);
	    Sv_RegisterCommand("set",      SvSetObjCmd,      NULL, 0);
	    Sv_RegisterCommand("unset",    SvUnsetObjCmd,    NULL, 0);
	    Sv_RegisterCommand("get",      SvGetObjCmd,      NULL, 0);
	    Sv_RegisterCommand("incr",     SvIncrObjCmd,     NULL, 0);
	    Sv_RegisterCommand("exists",   SvExistsObjCmd,   NULL, 0);
	    Sv_RegisterCommand("append",   SvAppendObjCmd,   NULL, 0);
	    Sv_RegisterCommand("array",    SvArrayObjCmd,    NULL, 0);
	    Sv_RegisterCommand("names",    SvNamesObjCmd,    NULL, 0);
	    Sv_RegisterCommand("pop",      SvPopObjCmd,      NULL, 0);
	    Sv_RegisterCommand("move",     SvMoveObjCmd,     NULL, 0);
	    Sv_RegisterCommand("lock",     SvLockObjCmd,     NULL, 0);
	    Sv_RegisterCommand("handlers", SvHandlersObjCmd, NULL, 0);
	    initialized = 1;
	}
	Tcl_MutexUnlock(&initMutex);
    }
}

/*
 *-----------------------------------------------------------------------------
 *
 * Sv_Init --
 * SvInit --
 *
 *    Creates commands in current interpreter.
 *
 * Results:
 *    None.
 *    NULL
 *
 * Side effects
 *    Many new command created in current interpreter. Global data
 *    structures used by them initialized as well.
 *
 *-----------------------------------------------------------------------------
 */
int
Sv_Init (
const char *
SvInit (
    Tcl_Interp *interp
) {
    Tcl_Size i;
    int i;
    int b;
    Bucket *bucketPtr;
    SvCmdInfo *cmdPtr;
    Tcl_Obj *obj;

#ifdef SV_FINALIZE
    /*
     * Create exit handler for this thread
2232
2233
2234
2235
2236
2237
2238
2239
2240


2241
2242
2243
2244

2245
2246
2247
2248
2249
2250
2251
2239
2240
2241
2242
2243
2244
2245


2246
2247
2248
2249
2250

2251
2252
2253
2254
2255
2256
2257
2258







-
-
+
+



-
+







    Sv_RegisterListCommands();

    /*
     * Get Tcl object types. These are used
     * in custom object duplicator function.
     */

    obj = Tcl_NewStringObj("no", -1);
    Tcl_GetBooleanFromObj(NULL, obj, &i);
    obj = Tcl_NewStringObj("no", TCL_INDEX_NONE);
    Tcl_GetBooleanFromObj(NULL, obj, &b);
    booleanObjTypePtr   = obj->typePtr;

#ifdef USE_TCL_STUBS
    if (Tcl_GetUnicodeFromObj)
    if (tclStubsPtr->tcl_GetUnicodeFromObj)
#endif
    {
	Tcl_GetUnicodeFromObj(obj, &i);
	stringObjTypePtr = obj->typePtr;
    }
    Tcl_GetByteArrayFromObj(obj, &i);
    byteArrayObjTypePtr = obj->typePtr;
2264
2265
2266
2267
2268
2269
2270
2271
2272


2273
2274
2275


2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286



2287
2288
2289
2290
2291
2292
2293






2294
2295
2296
2297
2298




2299
2300
2301
2302
2303
2304





2305
2306
2307
2308



2309
2310

2311
2312
2313

2314
2315
2316


2317
2318
2319

2320
2321
2322
2323
2324
2325
2326
2271
2272
2273
2274
2275
2276
2277


2278
2279
2280


2281
2282
2283
2284
2285
2286
2287
2288
2289
2290



2291
2292
2293
2294






2295
2296
2297
2298
2299
2300
2301




2302
2303
2304
2305
2306





2307
2308
2309
2310
2311
2312



2313
2314
2315
2316

2317
2318
2319

2320
2321


2322
2323
2324
2325

2326
2327
2328
2329
2330
2331
2332
2333







-
-
+
+

-
-
+
+








-
-
-
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
-
+
+
+

-
+


-
+

-
-
+
+


-
+







    Tcl_DecrRefCount(obj);

    /*
     * Plug-in registered commands in current interpreter
     */

    for (cmdPtr = svCmdInfo; cmdPtr; cmdPtr = cmdPtr->nextPtr) {
        Tcl_CreateObjCommand(interp, cmdPtr->cmdName, cmdPtr->objProcPtr,
                NULL, NULL);
	Tcl_CreateObjCommand2(interp, cmdPtr->cmdName, cmdPtr->objProcPtr,
		NULL, NULL);
#ifdef NS_AOLSERVER
        Tcl_CreateObjCommand(interp, cmdPtr->cmdName2, cmdPtr->objProcPtr,
                (void *)(size_t)cmdPtr->aolSpecial, NULL);
	Tcl_CreateObjCommand2(interp, cmdPtr->cmdName2, cmdPtr->objProcPtr,
		(void *)(size_t)cmdPtr->aolSpecial, NULL);
#endif
    }

    /*
     * Create array of buckets and initialize each bucket
     */

    if (buckets == NULL) {
        Tcl_MutexLock(&bucketsMutex);
        if (buckets == NULL) {
            buckets = (Bucket *)Tcl_Alloc(sizeof(Bucket) * NUMBUCKETS);
	Tcl_MutexLock(&bucketsMutex);
	if (buckets == NULL) {
	    buckets = (Bucket *)Tcl_Alloc(sizeof(Bucket) * NUMBUCKETS);

            for (i = 0; i < NUMBUCKETS; ++i) {
                bucketPtr = &buckets[i];
                memset(bucketPtr, 0, sizeof(Bucket));
                Tcl_InitHashTable(&bucketPtr->arrays, TCL_STRING_KEYS);
                Tcl_InitHashTable(&bucketPtr->handles, TCL_ONE_WORD_KEYS);
            }
	    for (i = 0; i < NUMBUCKETS; ++i) {
		bucketPtr = &buckets[i];
		memset(bucketPtr, 0, sizeof(Bucket));
		Tcl_InitHashTable(&bucketPtr->arrays, TCL_STRING_KEYS);
		Tcl_InitHashTable(&bucketPtr->handles, TCL_ONE_WORD_KEYS);
	    }

            /*
             * There is no other way to get Sv_tclEmptyStringRep
             * pointer value w/o this trick.
             */
	    /*
	     * There is no other way to get Sv_tclEmptyStringRep
	     * pointer value w/o this trick.
	     */

            {
                Tcl_Obj *dummy = Tcl_NewObj();
                Sv_tclEmptyStringRep = dummy->bytes;
                Tcl_DecrRefCount(dummy);
            }
	    {
		Tcl_Obj *dummy = Tcl_NewObj();
		Sv_tclEmptyStringRep = dummy->bytes;
		Tcl_DecrRefCount(dummy);
	    }

            /*
             * Register persistent store handlers
             */
	    /*
	     * Register persistent store handlers
	     */
#ifdef HAVE_GDBM
            Sv_RegisterGdbmStore();
	    Sv_RegisterGdbmStore();
#endif
#ifdef HAVE_LMDB
            Sv_RegisterLmdbStore();
	    Sv_RegisterLmdbStore();
#endif
        }
        Tcl_MutexUnlock(&bucketsMutex);
	}
	Tcl_MutexUnlock(&bucketsMutex);
    }

    return TCL_OK;
    return NULL;
}

#ifdef SV_FINALIZE
/*
 * Left for reference, but unused since multithreaded finalization is
 * unsolvable in the general case. Brave souls can revive this by
 * installing a late exit handler on Thread's behalf, bringing the
2340
2341
2342
2343
2344
2345
2346
2347


2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366

2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398

























2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414







2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428







2429
2430
2431
2432
2433
2434
2435
2347
2348
2349
2350
2351
2352
2353

2354
2355
2356
2357
2358
2359
2360
2361
2362

2363
2364
2365
2366
2367
2368
2369
2370
2371
2372

2373
2374
2375
2376
2377
2378
2379
2380

























2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414







2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428







2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442







-
+
+







-










-
+







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
-
-
-
-
-
-
+
+
+
+
+
+
+







-
-
-
-
-
-
-
+
+
+
+
+
+
+







 * Side effects
 *    Memory gets reclaimed.
 *
 *-----------------------------------------------------------------------------
 */

static void
SvFinalize (void *dummy)
SvFinalize (
    TCL_UNUSED(void *))
{
    int i;
    SvCmdInfo *cmdPtr;
    RegType *regPtr;

    Tcl_HashEntry *hashPtr;
    Tcl_HashSearch search;
    (void)dummy;

    /*
     * Decrement number of threads. Proceed only if I was the last one. The
     * mutex is unlocked at the end of this function, so new threads that might
     * want to register in the meanwhile will find a clean environment when
     * they eventually succeed acquiring nofThreadsMutex.
     */
    Tcl_MutexLock(&nofThreadsMutex);
    if (nofThreads > 1)
    {
        goto done;
	goto done;
    }

    /*
     * Reclaim memory for shared arrays
     */

    if (buckets != NULL) {
        Tcl_MutexLock(&bucketsMutex);
        if (buckets != NULL) {
            for (i = 0; i < NUMBUCKETS; ++i) {
                Bucket *bucketPtr = &buckets[i];
                hashPtr = Tcl_FirstHashEntry(&bucketPtr->arrays, &search);
                while (hashPtr != NULL) {
                    Array *arrayPtr = (Array*)Tcl_GetHashValue(hashPtr);
                    UnlockArray(arrayPtr);
                    /* unbind array before delete (avoid flush of persistent storage) */
                    UnbindArray(NULL, arrayPtr);
                    /* flush, delete etc. */
                    DeleteArray(NULL, arrayPtr);
                    hashPtr = Tcl_NextHashEntry(&search);
                }
                if (bucketPtr->lock) {
                    Sp_RecursiveMutexFinalize(&bucketPtr->lock);
                }
                SvFinalizeContainers(bucketPtr);
                Tcl_DeleteHashTable(&bucketPtr->handles);
                Tcl_DeleteHashTable(&bucketPtr->arrays);
            }
            Tcl_Free(buckets), buckets = NULL;
        }
        buckets = NULL;
        Tcl_MutexUnlock(&bucketsMutex);
	Tcl_MutexLock(&bucketsMutex);
	if (buckets != NULL) {
	    for (i = 0; i < NUMBUCKETS; ++i) {
		Bucket *bucketPtr = &buckets[i];
		hashPtr = Tcl_FirstHashEntry(&bucketPtr->arrays, &search);
		while (hashPtr != NULL) {
		    Array *arrayPtr = (Array*)Tcl_GetHashValue(hashPtr);
		    UnlockArray(arrayPtr);
		    /* unbind array before delete (avoid flush of persistent storage) */
		    UnbindArray(NULL, arrayPtr);
		    /* flush, delete etc. */
		    DeleteArray(NULL, arrayPtr);
		    hashPtr = Tcl_NextHashEntry(&search);
		}
		if (bucketPtr->lock) {
		    Sp_RecursiveMutexFinalize(&bucketPtr->lock);
		}
		SvFinalizeContainers(bucketPtr);
		Tcl_DeleteHashTable(&bucketPtr->handles);
		Tcl_DeleteHashTable(&bucketPtr->arrays);
	    }
	    Tcl_Free(buckets), buckets = NULL;
	}
	buckets = NULL;
	Tcl_MutexUnlock(&bucketsMutex);
    }

    Tcl_MutexLock(&svMutex);

    /*
     * Reclaim memory for registered commands
     */

    if (svCmdInfo != NULL) {
        cmdPtr = svCmdInfo;
        while (cmdPtr) {
            SvCmdInfo *tmpPtr = cmdPtr->nextPtr;
            Tcl_Free(cmdPtr);
            cmdPtr = tmpPtr;
        }
        svCmdInfo = NULL;
	cmdPtr = svCmdInfo;
	while (cmdPtr) {
	    SvCmdInfo *tmpPtr = cmdPtr->nextPtr;
	    Tcl_Free(cmdPtr);
	    cmdPtr = tmpPtr;
	}
	svCmdInfo = NULL;
    }

    /*
     * Reclaim memory for registered object types
     */

    if (regType != NULL) {
        regPtr = regType;
        while (regPtr) {
            RegType *tmpPtr = regPtr->nextPtr;
            Tcl_Free(regPtr);
            regPtr = tmpPtr;
        }
        regType = NULL;
	regPtr = regType;
	while (regPtr) {
	    RegType *tmpPtr = regPtr->nextPtr;
	    Tcl_Free(regPtr);
	    regPtr = tmpPtr;
	}
	regType = NULL;
    }

    Tcl_MutexUnlock(&svMutex);

done:
    --nofThreads;
    Tcl_MutexUnlock(&nofThreadsMutex);
Changes to generic/threadSvCmd.h.
80
81
82
83
84
85
86
87
88
89
90




91
92
93
94
95
96
97
80
81
82
83
84
85
86




87
88
89
90
91
92
93
94
95
96
97







-
-
-
-
+
+
+
+







/*
 * Definitions of functions implementing simple key/value
 * persistent storage for shared variable arrays.
 */

typedef void *(ps_open_proc)(const char*);

typedef int (ps_get_proc)   (void *, const char*, char**, size_t*);
typedef int (ps_put_proc)   (void *, const char*, char*, size_t);
typedef int (ps_first_proc) (void *, char**, char**, size_t*);
typedef int (ps_next_proc)  (void *, char**, char**, size_t*);
typedef int (ps_get_proc)   (void *, const char*, char**, Tcl_Size*);
typedef int (ps_put_proc)   (void *, const char*, char*, Tcl_Size);
typedef int (ps_first_proc) (void *, char**, char**, Tcl_Size*);
typedef int (ps_next_proc)  (void *, char**, char**, Tcl_Size*);
typedef int (ps_delete_proc)(void *, const char*);
typedef int (ps_close_proc) (void *);
typedef void(ps_free_proc)  (void *, void*);

typedef const char* (ps_geterr_proc)(void *);

/*
146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174







-
+













-
+








typedef struct Container {
    Bucket *bucketPtr;         /* Bucket holding the array below */
    Array *arrayPtr;           /* Array with the object container*/
    Tcl_HashEntry *entryPtr;   /* Entry in array table. */
    Tcl_HashEntry *handlePtr;  /* Entry in handles table */
    Tcl_Obj *tclObj;           /* Tcl object to hold shared values */
    int epoch;                 /* Track object changes */
    Tcl_Size epoch;            /* Track object changes */
    char *chunkAddr;           /* Address of one chunk of object containers */
    struct Container *nextPtr; /* Next object container in the free list */
    int aolSpecial;
} Container;

/*
 * Structure for generating command names in Tcl
 */

typedef struct SvCmdInfo {
    char *name;                 /* The short name of the command */
    char *cmdName;              /* Real (rewritten) name of the command */
    char *cmdName2;             /* Real AOL (rewritten) name of the command */
    Tcl_ObjCmdProc *objProcPtr; /* The object-based command procedure */
    Tcl_ObjCmdProc2 *objProcPtr; /* The object-based command procedure */
    Tcl_CmdDeleteProc *delProcPtr; /* Pointer to command delete function */
    struct SvCmdInfo *nextPtr;  /* Next in chain of registered commands */
    int aolSpecial;
} SvCmdInfo;

/*
 * Structure for registering special object duplicator functions.
188
189
190
191
192
193
194
195

196
197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
188
189
190
191
192
193
194

195
196
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211







-
+








-
+







} RegType;

/*
 * Limited API functions
 */

MODULE_SCOPE void
Sv_RegisterCommand(const char*,Tcl_ObjCmdProc*,Tcl_CmdDeleteProc*, int);
Sv_RegisterCommand(const char*,Tcl_ObjCmdProc2*,Tcl_CmdDeleteProc*, int);

MODULE_SCOPE void
Sv_RegisterObjType(const Tcl_ObjType*, Tcl_DupInternalRepProc*);

MODULE_SCOPE void
Sv_RegisterPsStore(const PsStore*);

MODULE_SCOPE int
Sv_GetContainer(Tcl_Interp*,int,Tcl_Obj*const objv[],Container**,int*,int);
Sv_GetContainer(Tcl_Interp*,Tcl_Size,Tcl_Obj*const objv[],Container**,Tcl_Size*,int);

MODULE_SCOPE int
Sv_PutContainer(Tcl_Interp*, Container*, int);

/*
 * Private version of Tcl_DuplicateObj which takes care about
 * copying objects when loaded to and retrieved from shared array.
Changes to generic/threadSvKeylistCmd.c.
17
18
19
20
21
22
23
24
25
26
27




28
29
30
31
32
33
34
17
18
19
20
21
22
23




24
25
26
27
28
29
30
31
32
33
34







-
-
-
-
+
+
+
+







#include "threadSvKeylistCmd.h"
#include "tclXkeylist.h"

/*
 * Wrapped keyed-list commands
 */

static Tcl_ObjCmdProc SvKeylsetObjCmd;
static Tcl_ObjCmdProc SvKeylgetObjCmd;
static Tcl_ObjCmdProc SvKeyldelObjCmd;
static Tcl_ObjCmdProc SvKeylkeysObjCmd;
static Tcl_ObjCmdProc2 SvKeylsetObjCmd;
static Tcl_ObjCmdProc2 SvKeylgetObjCmd;
static Tcl_ObjCmdProc2 SvKeyldelObjCmd;
static Tcl_ObjCmdProc2 SvKeylkeysObjCmd;

/*
 * This mutex protects a static variable which tracks
 * registration of commands and object types.
 */

static Tcl_Mutex initMutex;
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67










68
69
70
71
72
73
74
51
52
53
54
55
56
57










58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







 */
void
Sv_RegisterKeylistCommands(void)
{
    static int initialized;

    if (initialized == 0) {
        Tcl_MutexLock(&initMutex);
        if (initialized == 0) {
            Sv_RegisterCommand("keylset",  SvKeylsetObjCmd,  NULL, 0);
            Sv_RegisterCommand("keylget",  SvKeylgetObjCmd,  NULL, 0);
            Sv_RegisterCommand("keyldel",  SvKeyldelObjCmd,  NULL, 0);
            Sv_RegisterCommand("keylkeys", SvKeylkeysObjCmd, NULL, 0);
            Sv_RegisterObjType(&keyedListType, DupKeyedListInternalRepShared);
            initialized = 1;
        }
        Tcl_MutexUnlock(&initMutex);
	Tcl_MutexLock(&initMutex);
	if (initialized == 0) {
	    Sv_RegisterCommand("keylset",  SvKeylsetObjCmd,  NULL, 0);
	    Sv_RegisterCommand("keylget",  SvKeylgetObjCmd,  NULL, 0);
	    Sv_RegisterCommand("keyldel",  SvKeyldelObjCmd,  NULL, 0);
	    Sv_RegisterCommand("keylkeys", SvKeylkeysObjCmd, NULL, 0);
	    Sv_RegisterObjType(&keyedListType, DupKeyedListInternalRepShared);
	    initialized = 1;
	}
	Tcl_MutexUnlock(&initMutex);
    }
}

/*
 *-----------------------------------------------------------------------------
 *
 * SvKeylsetObjCmd --
85
86
87
88
89
90
91
92

93
94
95


96
97
98
99
100
101
102
103
104
105
106
107
108
109

110
111
112
113



114
115
116
117
118
119
120
121






122
123
124
125
126
127
128
85
86
87
88
89
90
91

92
93
94

95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

110
111



112
113
114
115
116






117
118
119
120
121
122
123
124
125
126
127
128
129







-
+


-
+
+













-
+

-
-
-
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+







 *-----------------------------------------------------------------------------
 */

static int
SvKeylsetObjCmd(
    void *arg,                         /* Not used. */
    Tcl_Interp *interp,                /* Current interpreter. */
    int objc,                          /* Number of arguments. */
    Tcl_Size objc,                          /* Number of arguments. */
    Tcl_Obj *const objv[]              /* Argument objects. */
) {
    int i, off, ret, flg;
    int ret, flg;
    Tcl_Size i, off;
    char *key;
    Tcl_Obj *val;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          sv::keylset array lkey key value ?key value ...?
     *          $keylist keylset key value ?key value ...?
     */

    flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) < 2 || ((objc - off) % 2)) {
        Tcl_WrongNumArgs(interp, off, objv, "key value ?key value ...?");
        goto cmd_err;
    if (objc < 2 + off || ((objc - off) % 2)) {
	Tcl_WrongNumArgs(interp, off, objv, "key value ?key value ...?");
	goto cmd_err;
    }
    for (i = off; i < objc; i += 2) {
        key = Tcl_GetString(objv[i]);
        val = Sv_DuplicateObj(objv[i+1]);
        ret = TclX_KeyedListSet(interp, svObj->tclObj, key, val);
        if (ret != TCL_OK) {
            goto cmd_err;
        }
	key = Tcl_GetString(objv[i]);
	val = Sv_DuplicateObj(objv[i+1]);
	ret = TclX_KeyedListSet(interp, svObj->tclObj, key, val);
	if (ret != TCL_OK) {
	    goto cmd_err;
	}
    }

    return Sv_PutContainer(interp, svObj, SV_CHANGED);

 cmd_err:
    return Sv_PutContainer(interp, svObj, SV_ERROR);
}
144
145
146
147
148
149
150
151

152
153
154


155
156
157
158
159
160
161
162
163
164
165
166
167
168

169
170
171
172



173
174
175
176
177
178





179
180
181


182
183

184
185
186
187
188
189

190
191
192
193
194
195
196
197
198






199
200
201
202
203
204
205
206
207
208
209











210
211
212
213
214
215
216
145
146
147
148
149
150
151

152
153
154

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

170
171



172
173
174
175





176
177
178
179
180
181


182
183
184

185
186
187
188
189
190

191
192
193
194






195
196
197
198
199
200
201










202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219







-
+


-
+
+













-
+

-
-
-
+
+
+

-
-
-
-
-
+
+
+
+
+

-
-
+
+

-
+





-
+



-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







 *-----------------------------------------------------------------------------
 */

static int
SvKeylgetObjCmd(
    void *arg,                         /* Not used. */
    Tcl_Interp *interp,                /* Current interpreter. */
    int objc,                          /* Number of arguments. */
    Tcl_Size objc,                          /* Number of arguments. */
    Tcl_Obj *const objv[]              /* Argument objects. */
) {
    int ret, flg, off;
    int ret, flg;
    Tcl_Size off;
    char *key;
    Tcl_Obj *varObjPtr = NULL, *valObjPtr = NULL;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          sv::keylget array lkey ?key? ?var?
     *          $keylist keylget ?key? ?var?
     */

    flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) > 2) {
        Tcl_WrongNumArgs(interp, off, objv, "?key? ?var?");
        goto cmd_err;
    if (objc > 2 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "?key? ?var?");
	goto cmd_err;
    }
    if ((objc - off) == 0) {
        if (Sv_PutContainer(interp, svObj, SV_UNCHANGED) != TCL_OK) {
            return TCL_ERROR;
        }
        return SvKeylkeysObjCmd(arg, interp, objc, objv);
    if (objc == off) {
	if (Sv_PutContainer(interp, svObj, SV_UNCHANGED) != TCL_OK) {
	    return TCL_ERROR;
	}
	return SvKeylkeysObjCmd(arg, interp, objc, objv);
    }
    if ((objc - off) == 2) {
        varObjPtr = objv[off+1];
    if (objc == 2 + off) {
	varObjPtr = objv[off+1];
    } else {
        varObjPtr = NULL;
	varObjPtr = NULL;
    }

    key = Tcl_GetString(objv[off]);
    ret = TclX_KeyedListGet(interp, svObj->tclObj, key, &valObjPtr);
    if (ret == TCL_ERROR) {
        goto cmd_err;
	goto cmd_err;
    }

    if (ret == TCL_BREAK) {
        if (varObjPtr) {
            Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
        } else {
            Tcl_AppendResult (interp, "key \"", key, "\" not found", NULL);
            goto cmd_err;
        }
	if (varObjPtr) {
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
	} else {
	    Tcl_AppendResult (interp, "key \"", key, "\" not found", (void *)NULL);
	    goto cmd_err;
	}
    } else {
        Tcl_Obj *resObjPtr = Sv_DuplicateObj(valObjPtr);
        if (varObjPtr) {
            Tcl_SetObjResult(interp, Tcl_NewIntObj(1));
            Tcl_GetString(varObjPtr);
            if (varObjPtr->length) {
                Tcl_ObjSetVar2(interp, varObjPtr, NULL, resObjPtr, 0);
            }
        } else {
            Tcl_SetObjResult(interp, resObjPtr);
        }
	Tcl_Obj *resObjPtr = Sv_DuplicateObj(valObjPtr);
	if (varObjPtr) {
	    Tcl_Size len;
	    Tcl_SetObjResult(interp, Tcl_NewIntObj(1));
	    Tcl_GetStringFromObj(varObjPtr, &len);
	    if (len) {
		Tcl_ObjSetVar2(interp, varObjPtr, NULL, resObjPtr, 0);
	    }
	} else {
	    Tcl_SetObjResult(interp, resObjPtr);
	}
    }

    return Sv_PutContainer(interp, svObj, SV_UNCHANGED);

 cmd_err:
    return Sv_PutContainer(interp, svObj, SV_ERROR);
}
232
233
234
235
236
237
238
239

240
241
242


243
244
245
246
247
248
249
250
251
252
253
254

255
256
257
258



259
260
261
262
263
264
265
266
267
268








269
270
271
272
273
274
275
235
236
237
238
239
240
241

242
243
244

245
246
247
248
249
250
251
252
253
254
255
256
257

258
259



260
261
262
263
264








265
266
267
268
269
270
271
272
273
274
275
276
277
278
279







-
+


-
+
+











-
+

-
-
-
+
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+







 *-----------------------------------------------------------------------------
 */

static int
SvKeyldelObjCmd(
    void *arg,                         /* Not used. */
    Tcl_Interp *interp,                /* Current interpreter. */
    int objc,                          /* Number of arguments. */
    Tcl_Size objc,                          /* Number of arguments. */
    Tcl_Obj *const objv[]              /* Argument objects. */
) {
    int i, off, ret;
    Tcl_Size i, off;
    int ret;
    char *key;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          sv::keyldel array lkey key ?key ...?
     *          $keylist keyldel ?key ...?
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) < 1) {
        Tcl_WrongNumArgs(interp, off, objv, "key ?key ...?");
        goto cmd_err;
    if (objc < 1 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "key ?key ...?");
	goto cmd_err;
    }
    for (i = off; i < objc; i++) {
        key = Tcl_GetString(objv[i]);
        ret = TclX_KeyedListDelete(interp, svObj->tclObj, key);
        if (ret == TCL_BREAK) {
            Tcl_AppendResult(interp, "key \"", key, "\" not found", NULL);
        }
        if (ret == TCL_BREAK || ret == TCL_ERROR) {
            goto cmd_err;
        }
	key = Tcl_GetString(objv[i]);
	ret = TclX_KeyedListDelete(interp, svObj->tclObj, key);
	if (ret == TCL_BREAK) {
	    Tcl_AppendResult(interp, "key \"", key, "\" not found", (void *)NULL);
	}
	if (ret == TCL_BREAK || ret == TCL_ERROR) {
	    goto cmd_err;
	}
    }

    return Sv_PutContainer(interp, svObj, SV_CHANGED);

 cmd_err:
    return Sv_PutContainer(interp, svObj, SV_ERROR);
}
291
292
293
294
295
296
297
298

299
300
301


302
303
304
305
306
307
308
309
310
311
312
313
314

315
316
317
318



319
320
321


322
323
324
325
326
327

328
329
330

331
332
333
334
335
336
337
295
296
297
298
299
300
301

302
303
304

305
306
307
308
309
310
311
312
313
314
315
316
317
318

319
320



321
322
323
324


325
326
327
328
329
330
331

332
333
334

335
336
337
338
339
340
341
342







-
+


-
+
+












-
+

-
-
-
+
+
+

-
-
+
+





-
+


-
+







 *-----------------------------------------------------------------------------
 */

static int
SvKeylkeysObjCmd(
    void *arg,                         /* Not used. */
    Tcl_Interp *interp,                /* Current interpreter. */
    int objc,                          /* Number of arguments. */
    Tcl_Size objc,                          /* Number of arguments. */
    Tcl_Obj *const objv[]              /* Argument objects. */
) {
    int ret, off;
    int ret;
    Tcl_Size off;
    char *key = NULL;
    Tcl_Obj *listObj = NULL;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          sv::keylkeys array lkey ?key?
     *          $keylist keylkeys ?key?
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) > 1) {
         Tcl_WrongNumArgs(interp, 1, objv, "?lkey?");
         goto cmd_err;
    if (objc > 1 + off) {
	 Tcl_WrongNumArgs(interp, 1, objv, "?lkey?");
	 goto cmd_err;
    }
    if ((objc - off) == 1) {
        key = Tcl_GetString(objv[off]);
    if (objc == 1 + off) {
	key = Tcl_GetString(objv[off]);
    }

    ret = TclX_KeyedListGetKeys(interp, svObj->tclObj, key, &listObj);

    if (key && ret == TCL_BREAK) {
        Tcl_AppendResult(interp, "key \"", key, "\" not found", NULL);
	Tcl_AppendResult(interp, "key \"", key, "\" not found", (void *)NULL);
    }
    if (ret == TCL_BREAK || ret == TCL_ERROR) {
        goto cmd_err;
	goto cmd_err;
    }

    Tcl_SetObjResult (interp, listObj); /* listObj allocated by API !*/

    return Sv_PutContainer(interp, svObj, SV_UNCHANGED);

 cmd_err:
Changes to generic/threadSvListCmd.c.
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37










38
39
40
41
42
43
44
21
22
23
24
25
26
27










28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







 *
 * Main difference to standard Tcl commands is that our commands
 * operate on list variable per-reference instead per-value.
 * This way we avoid frequent object shuffling between shared
 * containers and current interpreter, thus increasing speed.
 */

static Tcl_ObjCmdProc SvLpopObjCmd;      /* lpop        */
static Tcl_ObjCmdProc SvLpushObjCmd;     /* lpush       */
static Tcl_ObjCmdProc SvLappendObjCmd;   /* lappend     */
static Tcl_ObjCmdProc SvLreplaceObjCmd;  /* lreplace    */
static Tcl_ObjCmdProc SvLlengthObjCmd;   /* llength     */
static Tcl_ObjCmdProc SvLindexObjCmd;    /* lindex      */
static Tcl_ObjCmdProc SvLinsertObjCmd;   /* linsert     */
static Tcl_ObjCmdProc SvLrangeObjCmd;    /* lrange      */
static Tcl_ObjCmdProc SvLsearchObjCmd;   /* lsearch     */
static Tcl_ObjCmdProc SvLsetObjCmd;      /* lset        */
static Tcl_ObjCmdProc2 SvLpopObjCmd;      /* lpop        */
static Tcl_ObjCmdProc2 SvLpushObjCmd;     /* lpush       */
static Tcl_ObjCmdProc2 SvLappendObjCmd;   /* lappend     */
static Tcl_ObjCmdProc2 SvLreplaceObjCmd;  /* lreplace    */
static Tcl_ObjCmdProc2 SvLlengthObjCmd;   /* llength     */
static Tcl_ObjCmdProc2 SvLindexObjCmd;    /* lindex      */
static Tcl_ObjCmdProc2 SvLinsertObjCmd;   /* linsert     */
static Tcl_ObjCmdProc2 SvLrangeObjCmd;    /* lrange      */
static Tcl_ObjCmdProc2 SvLsearchObjCmd;   /* lsearch     */
static Tcl_ObjCmdProc2 SvLsetObjCmd;      /* lset        */

/*
 * Inefficient list duplicator function which,
 * however, produces deep list copies, unlike
 * the original, which just makes shallow copies.
 */

52
53
54
55
56
57
58
59
60


61
62
63
64
65
66
67
52
53
54
55
56
57
58


59
60
61
62
63
64
65
66
67







-
-
+
+







static Tcl_Mutex initMutex;

/*
 * Functions for implementing the "lset" list command
 */

static Tcl_Obj*
SvLsetFlat(Tcl_Interp *interp, Tcl_Obj *listPtr, int indexCount,
           Tcl_Obj **indexArray, Tcl_Obj *valuePtr);
SvLsetFlat(Tcl_Interp *interp, Tcl_Obj *listPtr, Tcl_Size indexCount,
	   Tcl_Obj **indexArray, Tcl_Obj *valuePtr);


/*
 *-----------------------------------------------------------------------------
 *
 * Sv_RegisterListCommands --
 *
78
79
80
81
82
83
84
85
86
87
88
89
90
91







92
93
94
95
96
97
98
99
100
101
102










103
104
105
106



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

137
138
139
140


141
142
143
144
145
146
147
148
149
150
151
152

153
154
155
156



157
158
159


160
161
162
163

164
165
166
167
168
169




170
171
172



173
174
175
176

177
178
179
180
181
182
183


184
185
186
187
188
189
190
191
192
193
194
195
78
79
80
81
82
83
84







85
86
87
88
89
90
91
92










93
94
95
96
97
98
99
100
101
102
103



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126





127
128
129
130

131
132
133


134
135
136
137
138
139
140
141
142
143
144
145
146

147
148



149
150
151
152


153
154
155
156
157

158
159
160




161
162
163
164
165


166
167
168
169
170
171

172
173
174
175
176
177


178
179
180
181
182


183
184
185
186
187
188
189







-
-
-
-
-
-
-
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
+
+
+




















-
-
-
-
-




-
+


-
-
+
+











-
+

-
-
-
+
+
+

-
-
+
+



-
+


-
-
-
-
+
+
+
+

-
-
+
+
+



-
+





-
-
+
+



-
-








void
Sv_RegisterListCommands(void)
{
    static int initialized = 0;

    if (initialized == 0) {
        Tcl_MutexLock(&initMutex);
        if (initialized == 0) {
            /* Create list with 1 empty element. */
            Tcl_Obj *listobj = Tcl_NewObj();
            listobj = Tcl_NewListObj(1, &listobj);
            Sv_RegisterObjType(listobj->typePtr, DupListObjShared);
            Tcl_DecrRefCount(listobj);
	Tcl_MutexLock(&initMutex);
	if (initialized == 0) {
	    /* Create list with 1 empty element. */
	    Tcl_Obj *listobj = Tcl_NewObj();
	    listobj = Tcl_NewListObj(1, &listobj);
	    Sv_RegisterObjType(listobj->typePtr, DupListObjShared);
	    Tcl_DecrRefCount(listobj);

            Sv_RegisterCommand("lpop",     SvLpopObjCmd,     NULL, 0);
            Sv_RegisterCommand("lpush",    SvLpushObjCmd,    NULL, 0);
            Sv_RegisterCommand("lappend",  SvLappendObjCmd,  NULL, 0);
            Sv_RegisterCommand("lreplace", SvLreplaceObjCmd, NULL, 0);
            Sv_RegisterCommand("linsert",  SvLinsertObjCmd,  NULL, 0);
            Sv_RegisterCommand("llength",  SvLlengthObjCmd,  NULL, 0);
            Sv_RegisterCommand("lindex",   SvLindexObjCmd,   NULL, 0);
            Sv_RegisterCommand("lrange",   SvLrangeObjCmd,   NULL, 0);
            Sv_RegisterCommand("lsearch",  SvLsearchObjCmd,  NULL, 0);
            Sv_RegisterCommand("lset",     SvLsetObjCmd,     NULL, 0);
	    Sv_RegisterCommand("lpop",     SvLpopObjCmd,     NULL, 0);
	    Sv_RegisterCommand("lpush",    SvLpushObjCmd,    NULL, 0);
	    Sv_RegisterCommand("lappend",  SvLappendObjCmd,  NULL, 0);
	    Sv_RegisterCommand("lreplace", SvLreplaceObjCmd, NULL, 0);
	    Sv_RegisterCommand("linsert",  SvLinsertObjCmd,  NULL, 0);
	    Sv_RegisterCommand("llength",  SvLlengthObjCmd,  NULL, 0);
	    Sv_RegisterCommand("lindex",   SvLindexObjCmd,   NULL, 0);
	    Sv_RegisterCommand("lrange",   SvLrangeObjCmd,   NULL, 0);
	    Sv_RegisterCommand("lsearch",  SvLsearchObjCmd,  NULL, 0);
	    Sv_RegisterCommand("lset",     SvLsetObjCmd,     NULL, 0);

            initialized = 1;
        }
        Tcl_MutexUnlock(&initMutex);
	    initialized = 1;
	}
	Tcl_MutexUnlock(&initMutex);
    }
}

/*
 *-----------------------------------------------------------------------------
 *
 * SvLpopObjCmd --
 *
 *      This procedure is invoked to process the "tsv::lpop" command.
 *      See the user documentation for details on what it does.
 *
 * Results:
 *      A standard Tcl result.
 *
 * Side effects:
 *      See the user documentation.
 *
 *-----------------------------------------------------------------------------
 */

#if TCL_MAJOR_VERSION < 9
#   undef size_t
#   define size_t int
#endif

static int
SvLpopObjCmd (
    void *arg,
    Tcl_Interp *interp,
    int objc,
    Tcl_Size objc,
    Tcl_Obj *const objv[]
) {
    int ret, off, llen, iarg = 0;
    size_t index = 0;
    int ret;
    Tcl_Size off, llen, index = 0, iarg = 0;
    Tcl_Obj *elPtr = NULL;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::lpop array key ?index?
     *          $list lpop ?index?
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) > 1) {
        Tcl_WrongNumArgs(interp, off, objv, "?index?");
        goto cmd_err;
    if (objc > 1 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "?index?");
	goto cmd_err;
    }
    if ((objc - off) == 1) {
        iarg = off;
    if (objc == 1 + off) {
	iarg = off;
    }
    ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    if (iarg) {
        ret = Tcl_GetIntForIndex(interp, objv[iarg], llen-1, &index);
        if (ret != TCL_OK) {
            goto cmd_err;
        }
	ret = Tcl_GetIntForIndex(interp, objv[iarg], llen-1, &index);
	if (ret != TCL_OK) {
	    goto cmd_err;
	}
    }
    if (index >= (size_t)llen) {
        goto cmd_ok; /* Ignore out-of bounds, like Tcl does */
    if ((index < 0) || (index >= llen)) {
	/* Ignore out-of bounds, like Tcl does */
	return Sv_PutContainer(interp, svObj, SV_UNCHANGED);
    }
    ret = Tcl_ListObjIndex(interp, svObj->tclObj, index, &elPtr);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }

    Tcl_IncrRefCount(elPtr);
    ret = Tcl_ListObjReplace(interp, svObj->tclObj, index, 1, 0, NULL);
    if (ret != TCL_OK) {
        Tcl_DecrRefCount(elPtr);
        goto cmd_err;
	Tcl_DecrRefCount(elPtr);
	goto cmd_err;
    }
    Tcl_SetObjResult(interp, elPtr);
    Tcl_DecrRefCount(elPtr);

 cmd_ok:
    return Sv_PutContainer(interp, svObj, SV_CHANGED);

 cmd_err:
    return Sv_PutContainer(interp, svObj, SV_ERROR);
}

/*
209
210
211
212
213
214
215
216

217
218
219
220


221
222
223
224
225
226
227
228
229
230
231
232
233

234
235
236
237



238
239
240
241

242
243
244
245
246
247
248
249
250
251
252










253
254
255
256
257
258
259


260
261
262
263
264
265
266
203
204
205
206
207
208
209

210
211
212


213
214
215
216
217
218
219
220
221
222
223
224
225
226

227
228



229
230
231
232
233
234

235
236










237
238
239
240
241
242
243
244
245
246
247
248
249
250
251


252
253
254
255
256
257
258
259
260







-
+


-
-
+
+












-
+

-
-
-
+
+
+



-
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+





-
-
+
+







 *-----------------------------------------------------------------------------
 */

static int
SvLpushObjCmd (
    void *arg,
    Tcl_Interp *interp,
    int objc,
    Tcl_Size objc,
    Tcl_Obj *const objv[]
) {
    int off, ret, flg, llen;
    size_t index = 0;
    int ret, flg;
    Tcl_Size off, llen, index = 0;
    Tcl_Obj *args[1];
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::lpush array key element ?index?
     *          $list lpush element ?index?
     */

    flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) < 1) {
        Tcl_WrongNumArgs(interp, off, objv, "element ?index?");
        goto cmd_err;
    if (objc < 1 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "element ?index?");
	goto cmd_err;
    }
    ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    if ((objc - off) == 2) {
        ret = Tcl_GetIntForIndex(interp, objv[off+1], llen, &index);
        if (ret != TCL_OK) {
            goto cmd_err;
        }
        if (index == TCL_INDEX_NONE) {
            index = 0;
        } else if (index > (size_t)llen) {
            index = llen;
        }
    if (objc == 2 + off) {
	ret = Tcl_GetIntForIndex(interp, objv[off+1], llen, &index);
	if (ret != TCL_OK) {
	    goto cmd_err;
	}
	if (index < 0) {
	    index = 0;
	} else if (index > llen) {
	    index = llen;
	}
    }

    args[0] = Sv_DuplicateObj(objv[off]);
    ret = Tcl_ListObjReplace(interp, svObj->tclObj, index, 0, 1, args);
    if (ret != TCL_OK) {
        Tcl_DecrRefCount(args[0]);
        goto cmd_err;
	Tcl_DecrRefCount(args[0]);
	goto cmd_err;
    }

    return Sv_PutContainer(interp, svObj, SV_CHANGED);

 cmd_err:
    return Sv_PutContainer(interp, svObj, SV_ERROR);
}
282
283
284
285
286
287
288
289

290
291
292


293
294
295
296
297
298
299
300
301
302
303
304
305

306
307
308
309



310
311
312
313
314
315
316
317






318
319
320
321
322
323
324
276
277
278
279
280
281
282

283
284
285

286
287
288
289
290
291
292
293
294
295
296
297
298
299

300
301



302
303
304
305
306






307
308
309
310
311
312
313
314
315
316
317
318
319







-
+


-
+
+












-
+

-
-
-
+
+
+


-
-
-
-
-
-
+
+
+
+
+
+







 *-----------------------------------------------------------------------------
 */

static int
SvLappendObjCmd(
    void *arg,
    Tcl_Interp *interp,
    int objc,
    Tcl_Size objc,
    Tcl_Obj *const objv[]
) {
    int i, ret, flg, off;
    int ret, flg;
    Tcl_Size i, off;
    Tcl_Obj *dup;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::lappend array key value ?value ...?
     *          $list lappend value ?value ...?
     */

    flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) < 1) {
        Tcl_WrongNumArgs(interp, off, objv, "value ?value ...?");
        goto cmd_err;
    if (objc < 1 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "value ?value ...?");
	goto cmd_err;
    }
    for (i = off; i < objc; i++) {
        dup = Sv_DuplicateObj(objv[i]);
        ret = Tcl_ListObjAppendElement(interp, svObj->tclObj, dup);
        if (ret != TCL_OK) {
            Tcl_DecrRefCount(dup);
            goto cmd_err;
        }
	dup = Sv_DuplicateObj(objv[i]);
	ret = Tcl_ListObjAppendElement(interp, svObj->tclObj, dup);
	if (ret != TCL_OK) {
	    Tcl_DecrRefCount(dup);
	    goto cmd_err;
	}
    }

    Tcl_SetObjResult(interp, Sv_DuplicateObj(svObj->tclObj));

    return Sv_PutContainer(interp, svObj, SV_CHANGED);

 cmd_err:
342
343
344
345
346
347
348
349

350
351
352
353
354


355
356
357
358
359
360
361
362
363
364
365
366
367

368
369
370
371



372
373
374
375

376
377
378
379

380
381
382
383

384
385
386

387
388
389


390
391
392
393



394
395
396


397
398
399


400
401

402
403
404

405
406
407
408
409




410
411
412
413
414
415
416
417
418
419






420
421
422
423
424
425
426
337
338
339
340
341
342
343

344
345
346
347


348
349

350
351
352
353
354
355
356
357
358
359
360

361
362



363
364
365
366
367
368

369
370
371
372

373
374
375
376

377
378
379

380



381
382
383



384
385
386
387


388
389
390


391
392
393

394
395
396

397
398




399
400
401
402
403
404
405
406






407
408
409
410
411
412
413
414
415
416
417
418
419







-
+



-
-
+
+
-











-
+

-
-
-
+
+
+



-
+



-
+



-
+


-
+
-
-
-
+
+

-
-
-
+
+
+

-
-
+
+

-
-
+
+

-
+


-
+

-
-
-
-
+
+
+
+




-
-
-
-
-
-
+
+
+
+
+
+







 *-----------------------------------------------------------------------------
 */

static int
SvLreplaceObjCmd(
    void *arg,
    Tcl_Interp *interp,
    int objc,
    Tcl_Size objc,
    Tcl_Obj *const objv[]
) {
    const char *firstArg;
    size_t argLen;
    int ret, off, llen, ndel, nargs, i, j;
    Tcl_Size off, llen, argLen, first, last, ndel, nargs, i, j;
    int ret;
    size_t first, last;
    Tcl_Obj **args = NULL;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::lreplace array key first last ?element ...?
     *          $list lreplace first last ?element ...?
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) < 2) {
        Tcl_WrongNumArgs(interp, off, objv, "first last ?element ...?");
        goto cmd_err;
    if (objc < 2 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "first last ?element ...?");
	goto cmd_err;
    }
    ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    ret = Tcl_GetIntForIndex(interp, objv[off], llen-1, &first);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    ret = Tcl_GetIntForIndex(interp, objv[off+1], llen-1, &last);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }

    firstArg = Tcl_GetString(objv[off]);
    firstArg = Tcl_GetStringFromObj(objv[off], &argLen);
    argLen = objv[off]->length;
    if (first == TCL_INDEX_NONE)  {
        first = 0;
    if (first < 0)  {
	first = 0;
    }
    if (llen && first >= (size_t)llen && strncmp(firstArg, "end", argLen)) {
        Tcl_AppendResult(interp, "list doesn't have element ", firstArg, NULL);
        goto cmd_err;
    if (llen && first >= llen && strncmp(firstArg, "end", argLen)) {
	Tcl_AppendResult(interp, "list doesn't have element ", firstArg, (void *)NULL);
	goto cmd_err;
    }
    if (last + 1 >= (size_t)llen + 1) {
        last = llen - 1;
    if (last >= llen) {
	last = llen - 1;
    }
    if (first + 1 <= last + 1) {
        ndel = last - first + 1;
    if (first <= last) {
	ndel = last - first + 1;
    } else {
        ndel = 0;
	ndel = 0;
    }

    nargs = objc - (off + 2);
    nargs = objc - off - 2;
    if (nargs) {
        args = (Tcl_Obj**)Tcl_Alloc(nargs * sizeof(Tcl_Obj*));
        for(i = off + 2, j = 0; i < objc; i++, j++) {
            args[j] = Sv_DuplicateObj(objv[i]);
        }
	args = (Tcl_Obj**)Tcl_Alloc(nargs * sizeof(Tcl_Obj*));
	for(i = off + 2, j = 0; i < objc; i++, j++) {
	    args[j] = Sv_DuplicateObj(objv[i]);
	}
    }

    ret = Tcl_ListObjReplace(interp, svObj->tclObj, first, ndel, nargs, args);
    if (args) {
        if (ret != TCL_OK) {
            for(i = off + 2, j = 0; i < objc; i++, j++) {
                Tcl_DecrRefCount(args[j]);
            }
        }
        Tcl_Free(args);
	if (ret != TCL_OK) {
	    for(i = off + 2, j = 0; i < objc; i++, j++) {
		Tcl_DecrRefCount(args[j]);
	    }
	}
	Tcl_Free(args);
    }

    return Sv_PutContainer(interp, svObj, SV_CHANGED);

 cmd_err:
    return Sv_PutContainer(interp, svObj, SV_ERROR);
}
442
443
444
445
446
447
448
449

450
451
452
453


454
455
456
457
458
459
460
461
462
463
464
465

466
467
468
469



470
471
472
473

474
475
476
477

478
479
480
481

482
483
484


485
486
487


488
489
490


491
492
493
494
495
496

497
498
499
500
501
502
503
435
436
437
438
439
440
441

442
443
444


445
446
447
448
449
450
451
452
453
454
455
456
457

458
459



460
461
462
463
464
465

466
467
468
469

470
471
472
473

474
475


476
477
478


479
480
481


482
483
484
485
486
487
488

489
490
491
492
493
494
495
496







-
+


-
-
+
+











-
+

-
-
-
+
+
+



-
+



-
+



-
+

-
-
+
+

-
-
+
+

-
-
+
+





-
+







 *-----------------------------------------------------------------------------
 */

static int
SvLrangeObjCmd(
    void *arg,
    Tcl_Interp *interp,
    int objc,
    Tcl_Size objc,
    Tcl_Obj *const objv[]
) {
    int ret, off, llen, nargs, j;
    size_t first, last, i;
    int ret;
    Tcl_Size first, last, i, off, llen, nargs, j;
    Tcl_Obj **elPtrs, **args;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::lrange array key first last
     *          $list lrange first last
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) != 2) {
        Tcl_WrongNumArgs(interp, off, objv, "first last");
        goto cmd_err;
    if (objc != 2 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "first last");
	goto cmd_err;
    }
    ret = Tcl_ListObjGetElements(interp, svObj->tclObj, &llen, &elPtrs);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    ret = Tcl_GetIntForIndex(interp, objv[off], llen-1, &first);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    ret = Tcl_GetIntForIndex(interp, objv[off+1], llen-1, &last);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    if (first == TCL_INDEX_NONE)  {
        first = 0;
    if (first < 0)  {
	first = 0;
    }
    if (last + 1 >= (size_t)llen + 1) {
        last = llen - 1;
    if (last >= llen) {
	last = llen - 1;
    }
    if (first + 1 > last + 1) {
        goto cmd_ok;
    if (first > last) {
	goto cmd_ok;
    }

    nargs = last - first + 1;
    args  = (Tcl_Obj **)Tcl_Alloc(nargs * sizeof(Tcl_Obj *));
    for (i = first, j = 0; i <= last; i++, j++) {
        args[j] = Sv_DuplicateObj(elPtrs[i]);
	args[j] = Sv_DuplicateObj(elPtrs[i]);
    }

    Tcl_ResetResult(interp);
    Tcl_SetListObj(Tcl_GetObjResult(interp), nargs, args);
    Tcl_Free(args);

 cmd_ok:
524
525
526
527
528
529
530
531

532
533
534
535


536
537
538
539
540
541
542
543
544
545
546
547
548

549
550
551
552



553
554
555
556

557
558
559
560

561
562
563
564
565




566
567
568

569
570
571

572
573
574
575
576
577
578
579





580
581
582
583
584
585
586
517
518
519
520
521
522
523

524
525
526


527
528
529
530
531
532
533
534
535
536
537
538
539
540

541
542



543
544
545
546
547
548

549
550
551
552

553
554




555
556
557
558
559
560

561
562
563

564
565
566
567





568
569
570
571
572
573
574
575
576
577
578
579







-
+


-
-
+
+












-
+

-
-
-
+
+
+



-
+



-
+

-
-
-
-
+
+
+
+


-
+


-
+



-
-
-
-
-
+
+
+
+
+







 *-----------------------------------------------------------------------------
 */

static int
SvLinsertObjCmd(
    void *arg,
    Tcl_Interp *interp,
    int objc,
    Tcl_Size objc,
    Tcl_Obj *const objv[]
) {
    int off, ret, flg, llen, nargs, i, j;
    size_t index = 0;
    int ret, flg;
    Tcl_Size off, nargs, i, j, llen, index = 0;
    Tcl_Obj **args;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::linsert array key index element ?element ...?
     *          $list linsert element ?element ...?
     */

    flg = FLAGS_CREATEARRAY | FLAGS_CREATEVAR;
    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, flg);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) < 2) {
        Tcl_WrongNumArgs(interp, off, objv, "index element ?element ...?");
        goto cmd_err;
    if (objc < 2 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "index element ?element ...?");
	goto cmd_err;
    }
    ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    ret = Tcl_GetIntForIndex(interp, objv[off], llen, &index);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    if (index == TCL_INDEX_NONE) {
        index = 0;
    } else if (index > (size_t)llen) {
        index = llen;
    if (index < 0) {
	index = 0;
    } else if (index > llen) {
	index = llen;
    }

    nargs = objc - (off + 1);
    nargs = objc - off - 1;
    args  = (Tcl_Obj **)Tcl_Alloc(nargs * sizeof(Tcl_Obj *));
    for (i = off + 1, j = 0; i < objc; i++, j++) {
         args[j] = Sv_DuplicateObj(objv[i]);
	 args[j] = Sv_DuplicateObj(objv[i]);
    }
    ret = Tcl_ListObjReplace(interp, svObj->tclObj, index, 0, nargs, args);
    if (ret != TCL_OK) {
        for (i = off + 1, j = 0; i < objc; i++, j++) {
            Tcl_DecrRefCount(args[j]);
        }
        Tcl_Free(args);
        goto cmd_err;
	for (i = off + 1, j = 0; i < objc; i++, j++) {
	    Tcl_DecrRefCount(args[j]);
	}
	Tcl_Free(args);
	goto cmd_err;
    }

    Tcl_Free(args);

    return Sv_PutContainer(interp, svObj, SV_CHANGED);

 cmd_err:
604
605
606
607
608
609
610
611

612
613
614


615
616
617
618
619
620
621
622
623
624
625

626
627
628
629
630

631
632
633

634
635
636
637
638
639
640
597
598
599
600
601
602
603

604
605
606

607
608
609
610
611
612
613
614
615
616
617
618

619
620
621
622
623

624
625
626

627
628
629
630
631
632
633
634







-
+


-
+
+










-
+




-
+


-
+







 *-----------------------------------------------------------------------------
 */

static int
SvLlengthObjCmd(
    void *arg,
    Tcl_Interp *interp,
    int objc,
    Tcl_Size objc,
    Tcl_Obj *const objv[]
) {
    int llen, off, ret;
    Tcl_Size llen, off;
    int ret;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::llength array key
     *          $list llength
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    ret = Tcl_ListObjLength(interp, svObj->tclObj, &llen);
    if (ret == TCL_OK) {
        Tcl_SetObjResult(interp, Tcl_NewIntObj(llen));
	Tcl_SetObjResult(interp, Tcl_NewIntObj(llen));
    }
    if (Sv_PutContainer(interp, svObj, SV_UNCHANGED) != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    return ret;
}

/*
 *-----------------------------------------------------------------------------
653
654
655
656
657
658
659
660

661
662
663
664


665
666
667
668
669
670

671
672
673
674
675
676
677
678
679
680
681
682

683
684
685
686
687
688
689






690
691
692


693
694
695
696
697
698
699





700
701
702
703

704
705
706
707


708
709
710
711
712
713
714
715





716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734



















735
736
737

738
739
740
741
742
743
744
647
648
649
650
651
652
653

654
655
656


657
658
659
660
661
662
663

664
665
666
667
668
669
670
671
672
673
674
675

676
677






678
679
680
681
682
683
684


685
686
687
688





689
690
691
692
693
694
695
696

697
698
699


700
701

702
703





704
705
706
707
708
709


















710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730

731
732
733
734
735
736
737
738







-
+


-
-
+
+





-
+











-
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
+
+


-
-
-
-
-
+
+
+
+
+



-
+


-
-
+
+
-


-
-
-
-
-
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


-
+







 *-----------------------------------------------------------------------------
 */

static int
SvLsearchObjCmd(
    void *arg,
    Tcl_Interp *interp,
    int objc,
    Tcl_Size objc,
    Tcl_Obj *const objv[]
) {
    size_t length;
    int ret, off, listc, mode, imode, ipatt, index, match, i;
    int ret, match;
    Tcl_Size off, index, length, i, listc, imode, ipatt;
    const char *patBytes;
    Tcl_Obj **listv;
    Container *svObj = (Container*)arg;

    static const char *const modes[] = {"-exact", "-glob", "-regexp", NULL};
    enum {LS_EXACT, LS_GLOB, LS_REGEXP};
    enum {LS_EXACT, LS_GLOB, LS_REGEXP} mode;

    mode = LS_GLOB;

    /*
     * Syntax:
     *          tsv::lsearch array key ?mode? pattern
     *          $list lsearch ?mode? pattern
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) == 2) {
        imode = off;
        ipatt = off + 1;
    } else if ((objc - off) == 1) {
        imode = 0;
        ipatt = off;
    if (objc == 2 + off) {
	imode = off;
	ipatt = off + 1;
    } else if (objc == 1 + off) {
	imode = 0;
	ipatt = off;
    } else {
        Tcl_WrongNumArgs(interp, off, objv, "?mode? pattern");
        goto cmd_err;
	Tcl_WrongNumArgs(interp, off, objv, "?mode? pattern");
	goto cmd_err;
    }
    if (imode) {
        ret = Tcl_GetIndexFromObjStruct(interp, objv[imode], modes, sizeof(char *), "search mode",
                0, &mode);
        if (ret != TCL_OK) {
            goto cmd_err;
        }
	ret = Tcl_GetIndexFromObjStruct(interp, objv[imode], modes, sizeof(char *), "search mode",
		0, &mode);
	if (ret != TCL_OK) {
	    goto cmd_err;
	}
    }
    ret = Tcl_ListObjGetElements(interp, svObj->tclObj, &listc, &listv);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }

    index = -1;
    patBytes = Tcl_GetString(objv[ipatt]);
    index = TCL_INDEX_NONE;
    patBytes = Tcl_GetStringFromObj(objv[ipatt], &length);
    length = objv[ipatt]->length;

    for (i = 0; i < listc; i++) {
        match = 0;
        switch (mode) {
        case LS_GLOB:
            match = Tcl_StringCaseMatch(Tcl_GetString(listv[i]), patBytes, 0);
            break;
	match = 0;
	switch (mode) {
	case LS_GLOB:
	    match = Tcl_StringCaseMatch(Tcl_GetString(listv[i]), patBytes, 0);
	    break;

        case LS_EXACT: {
            const char *bytes = Tcl_GetString(listv[i]);
            if (length == (size_t)listv[i]->length) {
                match = (memcmp(bytes, patBytes, length) == 0);
            }
            break;
        }
        case LS_REGEXP:
            match = Tcl_RegExpMatchObj(interp, listv[i], objv[ipatt]);
            if (match < 0) {
                goto cmd_err;
            }
            break;
        }
        if (match) {
            index = i;
            break;
        }
	case LS_EXACT: {
	    Tcl_Size len;
	    const char *bytes = Tcl_GetStringFromObj(listv[i], &len);
	    if (length == len) {
		match = (memcmp(bytes, patBytes, length) == 0);
	    }
	    break;
	}
	case LS_REGEXP:
	    match = Tcl_RegExpMatchObj(interp, listv[i], objv[ipatt]);
	    if (match < 0) {
		goto cmd_err;
	    }
	    break;
	}
	if (match) {
	    index = i;
	    break;
	}
    }

    Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
    Tcl_SetObjResult(interp, Tcl_NewWideIntObj(index));

    return Sv_PutContainer(interp, svObj, SV_UNCHANGED);

 cmd_err:
    return Sv_PutContainer(interp, svObj, SV_ERROR);
}

759
760
761
762
763
764
765
766

767
768
769
770
771


772
773
774
775
776
777
778
779
780
781
782

783
784
785
786



787
788
789
790

791
792
793
794

795
796
797


798
799
800
801
802
803
804
753
754
755
756
757
758
759

760
761
762
763


764
765
766
767
768
769
770
771
772
773
774
775

776
777



778
779
780
781
782
783

784
785
786
787

788
789


790
791
792
793
794
795
796
797
798







-
+



-
-
+
+










-
+

-
-
-
+
+
+



-
+



-
+

-
-
+
+







 *-----------------------------------------------------------------------------
 */

static int
SvLindexObjCmd(
    void *arg,
    Tcl_Interp *interp,
    int objc,
    Tcl_Size objc,
    Tcl_Obj *const objv[]
) {
    Tcl_Obj **elPtrs;
    int ret, off, llen;
    size_t index;
    int ret;
    Tcl_Size llen, index, off;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::lindex array key index
     *          $list lindex index
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) != 1) {
        Tcl_WrongNumArgs(interp, off, objv, "index");
        goto cmd_err;
    if (objc != 1 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "index");
	goto cmd_err;
    }
    ret = Tcl_ListObjGetElements(interp, svObj->tclObj, &llen, &elPtrs);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    ret = Tcl_GetIntForIndex(interp, objv[off], llen-1, &index);
    if (ret != TCL_OK) {
        goto cmd_err;
	goto cmd_err;
    }
    if (index < (size_t)llen) {
        Tcl_SetObjResult(interp, Sv_DuplicateObj(elPtrs[index]));
    if ((index >= 0) && (index < llen)) {
	Tcl_SetObjResult(interp, Sv_DuplicateObj(elPtrs[index]));
    }

    return Sv_PutContainer(interp, svObj, SV_UNCHANGED);

 cmd_err:
    return Sv_PutContainer(interp, svObj, SV_ERROR);
}
820
821
822
823
824
825
826
827

828
829
830
831


832
833
834
835
836
837
838
839
840
841
842

843
844
845
846



847
848
849
850
851
852
853

854
855
856
857
858
859
860
814
815
816
817
818
819
820

821
822
823
824

825
826
827
828
829
830
831
832
833
834
835
836

837
838



839
840
841
842
843
844
845
846
847

848
849
850
851
852
853
854
855







-
+



-
+
+










-
+

-
-
-
+
+
+






-
+







 *-----------------------------------------------------------------------------
 */

static int
SvLsetObjCmd(
    void *arg,
    Tcl_Interp *interp,
    int objc,
    Tcl_Size objc,
    Tcl_Obj *const objv[]
) {
    Tcl_Obj *lPtr;
    int ret, argc, off;
    int ret;
    Tcl_Size argc, off;
    Container *svObj = (Container*)arg;

    /*
     * Syntax:
     *          tsv::lset array key index ?index ...? value
     *          $list lset index ?index ...? value
     */

    ret = Sv_GetContainer(interp, objc, objv, &svObj, &off, 0);
    if (ret != TCL_OK) {
        return TCL_ERROR;
	return TCL_ERROR;
    }
    if ((objc - off) < 2) {
        Tcl_WrongNumArgs(interp, off, objv, "index ?index...? value");
        goto cmd_err;
    if (objc < 2 + off) {
	Tcl_WrongNumArgs(interp, off, objv, "index ?index...? value");
	goto cmd_err;
    }

    lPtr = svObj->tclObj;
    argc = objc - off - 1;

    if (!SvLsetFlat(interp, lPtr, argc, (Tcl_Obj**)objv+off,objv[objc-1])) {
        return TCL_ERROR;
	return TCL_ERROR;
    }

    Tcl_SetObjResult(interp, Sv_DuplicateObj(lPtr));

    return Sv_PutContainer(interp, svObj, SV_CHANGED);

 cmd_err:
885
886
887
888
889
890
891
892
893

894

895
896
897
898
899
900
901
902
903

904
905
906
907


908
909
910
911

912


913
914
915
916
917
918
919
880
881
882
883
884
885
886


887
888
889
890
891







892
893
894


895
896
897
898
899
900
901

902
903
904
905
906
907
908
909
910







-
-
+

+


-
-
-
-
-
-
-
+


-
-
+
+




+
-
+
+







 */

static void
DupListObjShared(
    Tcl_Obj *srcPtr,           /* Object with internal rep to copy. */
    Tcl_Obj *copyPtr           /* Object with internal rep to set. */
) {
    int i;
    int llen;
    Tcl_Size i, llen;
    Tcl_Obj *elObj, **newObjList;
    Tcl_Obj *buf[16];

    Tcl_ListObjLength(NULL, srcPtr, &llen);
    if (llen == 0) {
        (*srcPtr->typePtr->dupIntRepProc)(srcPtr, copyPtr);
        copyPtr->refCount = 0;
        return;
    }

    newObjList = (Tcl_Obj **)Tcl_Alloc(llen*sizeof(Tcl_Obj *));
    newObjList = (llen > 16) ? (Tcl_Obj**)Tcl_Alloc(llen*sizeof(Tcl_Obj *)) : &buf[0];

    for (i = 0; i < llen; i++) {
        Tcl_ListObjIndex(NULL, srcPtr, i, &elObj);
        newObjList[i] = Sv_DuplicateObj(elObj);
	Tcl_ListObjIndex(NULL, srcPtr, i, &elObj);
	newObjList[i] = Sv_DuplicateObj(elObj);
    }

    Tcl_SetListObj(copyPtr, llen, newObjList);

    if (newObjList != &buf[0]) {
    Tcl_Free(newObjList);
	Tcl_Free(newObjList);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * SvLsetFlat --
 *
927
928
929
930
931
932
933
934

935
936
937
938
939
940







941
942
943
944
945
946
947
948
949
950
951
952
953






954
955

956
957
958
959
960
961
962
963
964

965
966
967
968
969




970
971


972
973
974
975
976
977
978
979
980
981
982



983
984
985
986
987




988
989
990
991
992
993



994
995
996
997
998




999
1000
1001
1002



1003
1004
1005
1006
1007
1008
1009






1010
1011
1012
1013









1014
1015
1016
1017
1018




1019
1020
1021
1022
1023
1024
1025

1026
1027
1028
1029


1030


1031
1032
1033
1034
1035
1036
1037
1038






1039
1040
1041
1042
1043
1044





1045
1046


1047
1048
1049
1050
1051





1052
1053

1054

1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
918
919
920
921
922
923
924

925
926
927
928



929
930
931
932
933
934
935
936
937
938
939
940
941
942






943
944
945
946
947
948
949

950
951
952
953
954
955
956
957
958

959
960
961



962
963
964
965


966
967

968
969
970
971
972
973
974



975
976
977
978




979
980
981
982


983



984
985
986
987




988
989
990
991
992



993
994
995
996






997
998
999
1000
1001
1002
1003



1004
1005
1006
1007
1008
1009
1010
1011
1012
1013




1014
1015
1016
1017
1018






1019


1020
1021
1022
1023

1024
1025
1026
1027






1028
1029
1030
1031
1032
1033
1034
1035
1036



1037
1038
1039
1040
1041


1042
1043





1044
1045
1046
1047
1048
1049
1050
1051

1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063







-
+



-
-
-
+
+
+
+
+
+
+







-
-
-
-
-
-
+
+
+
+
+
+

-
+








-
+


-
-
-
+
+
+
+
-
-
+
+
-







-
-
-
+
+
+

-
-
-
-
+
+
+
+
-
-

-
-
-
+
+
+

-
-
-
-
+
+
+
+

-
-
-
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
+
+
+
+
+
+
+
+
+

-
-
-
-
+
+
+
+

-
-
-
-
-
-
+
-
-


+
+
-
+
+


-
-
-
-
-
-
+
+
+
+
+
+



-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
-
-
+
+
+
+
+


+
-
+











 *----------------------------------------------------------------------
 */

static Tcl_Obj*
SvLsetFlat(
     Tcl_Interp *interp,    /* Tcl interpreter */
     Tcl_Obj *listPtr,      /* Pointer to the list being modified */
     int indexCount,        /* Number of index args */
     Tcl_Size indexCount,   /* Number of index args */
     Tcl_Obj **indexArray,
     Tcl_Obj *valuePtr      /* Value arg to 'lset' */
) {
    int elemCount, result, i;
    size_t index;
    Tcl_Obj **elemPtrs, *chainPtr, *subListPtr;
    Tcl_Size i, elemCount, index;
    int result;
    Tcl_Obj **elemPtrs;
    Tcl_Obj *pendingInvalidates[10]; /* Assumed max nesting depth */
    Tcl_Obj **pendingInvalidatesPtr = pendingInvalidates;
    Tcl_Size numPendingInvalidates = 0;


    /*
     * Determine whether the index arg designates a list
     * or a single index.
     */

    if (indexCount == 1 &&
        Tcl_ListObjGetElements(interp, indexArray[0], &indexCount,
                               &indexArray) != TCL_OK) {
        /*
         * Index arg designates something that is neither an index
         * nor a well formed list.
         */
	Tcl_ListObjGetElements(interp, indexArray[0], &indexCount,
		&indexArray) != TCL_OK) {
	/*
	 * Index arg designates something that is neither an index
	 * nor a well formed list.
	 */

        return NULL;
	return NULL;
    }

    /*
     * If there are no indices, then simply return the new value,
     * counting the returned pointer as a reference
     */

    if (indexCount == 0) {
        return valuePtr;
	return valuePtr;
    }

    /*
     * Anchor the linked list of Tcl_Obj's whose string reps must be
     * invalidated if the operation succeeds.
    /* Allocate if static array for pending invalidations is too small */
    if (indexCount > (Tcl_Size)(sizeof(pendingInvalidates) /
	    sizeof(pendingInvalidates[0]))) {
	pendingInvalidatesPtr =
     */

	    (Tcl_Obj **)Tcl_Alloc(indexCount * sizeof(*pendingInvalidatesPtr));
    }
    chainPtr = NULL;

    /*
     * Handle each index arg by diving into the appropriate sublist
     */

    for (i = 0; ; ++i) {

        /*
         * Take the sublist apart.
         */
	/*
	 * Take the sublist apart.
	 */

        result = Tcl_ListObjGetElements(interp,listPtr,&elemCount,&elemPtrs);
        if (result != TCL_OK) {
            break;
        }
	result = Tcl_ListObjGetElements(interp,listPtr,&elemCount,&elemPtrs);
	if (result != TCL_OK) {
	    break;
	}

        listPtr->internalRep.twoPtrValue.ptr2 = (void*)chainPtr;

        /*
         * Determine the index of the requested element.
         */
	/*
	 * Determine the index of the requested element.
	 */

        result = Tcl_GetIntForIndex(interp, indexArray[i], elemCount-1, &index);
        if (result != TCL_OK) {
            break;
        }
	result = Tcl_GetIntForIndex(interp, indexArray[i], elemCount-1, &index);
	if (result != TCL_OK) {
	    break;
	}

        /*
         * Check that the index is in range.
         */
	/*
	 * Check that the index is in range.
	 */

        if (index >= (size_t)elemCount) {
            Tcl_SetObjResult(interp,
                             Tcl_NewStringObj("list index out of range", -1));
            result = TCL_ERROR;
            break;
        }
	if ((index < 0) || (index >= elemCount)) {
	    Tcl_SetObjResult(interp,
		    Tcl_NewStringObj("list index out of range", TCL_INDEX_NONE));
	    result = TCL_ERROR;
	    break;
	}

        /*
         * Break the loop after extracting the innermost sublist
         */
	/*
	 * Remember list of Tcl_Objs that need invalidation of string reps.
	 */
	pendingInvalidatesPtr[numPendingInvalidates] = listPtr;
	++numPendingInvalidates;

	/*
	 * Break the loop after extracting the innermost sublist
	 */

        if (i + 1 >= indexCount) {
            result = TCL_OK;
            break;
        }
	if (i + 1 >= indexCount) {
	    result = TCL_OK;
	    break;
	}

        /*
         * Extract the appropriate sublist and chain it onto the linked
         * list of Tcl_Obj's whose string reps must be spoilt.
         */

        subListPtr = elemPtrs[index];
	listPtr = elemPtrs[index];
        chainPtr = listPtr;
        listPtr = subListPtr;
    }

    /*
     * At this point listPtr holds the sublist (which could even be the
    /* Store the result in the list element */
     * top level list) whose element is to be modified.
     */

    if (result == TCL_OK) {
        result = Tcl_ListObjGetElements(interp,listPtr,&elemCount,&elemPtrs);
        if (result == TCL_OK) {
            Tcl_DecrRefCount(elemPtrs[index]);
            elemPtrs[index] = Sv_DuplicateObj(valuePtr);
            Tcl_IncrRefCount(elemPtrs[index]);
        }
	result = Tcl_ListObjGetElements(interp,listPtr,&elemCount,&elemPtrs);
	if (result == TCL_OK) {
	    Tcl_DecrRefCount(elemPtrs[index]);
	    elemPtrs[index] = Sv_DuplicateObj(valuePtr);
	    Tcl_IncrRefCount(elemPtrs[index]);
	}
    }

    if (result == TCL_OK) {
        listPtr->internalRep.twoPtrValue.ptr2 = (void*)chainPtr;
        /* Spoil all the string reps */
        while (listPtr != NULL) {
	/*
	 * Since modification was successful, we need to invalidate string
	 * representations of all ancestors of the modified sublist.
	 */
	while (numPendingInvalidates > 0) {
            subListPtr = (Tcl_Obj*)listPtr->internalRep.twoPtrValue.ptr2;
            Tcl_InvalidateStringRep(listPtr);
	    --numPendingInvalidates;
	    Tcl_InvalidateStringRep(pendingInvalidatesPtr[numPendingInvalidates]);
            listPtr->internalRep.twoPtrValue.ptr2 = NULL;
            listPtr = subListPtr;
        }

        return valuePtr;
	}
    }

    if (pendingInvalidatesPtr != pendingInvalidates) {
	Tcl_Free(pendingInvalidatesPtr);
    }

    /* Note return only matters as non-NULL vs NULL */
    return NULL;
    return result == TCL_OK ? valuePtr : NULL;
}

/* EOF $RCSfile: threadSvListCmd.c,v $ */

/* Emacs Setup Variables */
/* Local Variables:      */
/* mode: C               */
/* indent-tabs-mode: nil */
/* c-basic-offset: 4     */
/* End:                  */

Changes to lib/ttrace.tcl.
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58










59
60

61
62
63
64
65
66
67
68
69
70









71
72

73
74
75
76



77
78
79
80
81
82
83
42
43
44
45
46
47
48










49
50
51
52
53
54
55
56
57
58
59

60
61









62
63
64
65
66
67
68
69
70
71

72
73
74


75
76
77
78
79
80
81
82
83
84







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
+

-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+

-
+


-
-
+
+
+







#      command in order to avoid potential slowdown.
#

namespace eval ttrace {

    # Setup some compatibility wrappers
    if {[info commands nsv_set] != ""} {
        variable tvers 0
        variable mutex ns_mutex
        variable elock [$mutex create traceepochmutex]
        # Import the underlying API; faster than recomputing
        interp alias {} [namespace current]::_array   {} nsv_array
        interp alias {} [namespace current]::_incr    {} nsv_incr
        interp alias {} [namespace current]::_lappend {} nsv_lappend
        interp alias {} [namespace current]::_names   {} nsv_names
        interp alias {} [namespace current]::_set     {} nsv_set
        interp alias {} [namespace current]::_unset   {} nsv_unset
	variable tvers 0
	variable mutex ns_mutex
	variable elock [$mutex create traceepochmutex]
	# Import the underlying API; faster than recomputing
	interp alias {} [namespace current]::_array   {} nsv_array
	interp alias {} [namespace current]::_incr    {} nsv_incr
	interp alias {} [namespace current]::_lappend {} nsv_lappend
	interp alias {} [namespace current]::_names   {} nsv_names
	interp alias {} [namespace current]::_set     {} nsv_set
	interp alias {} [namespace current]::_unset   {} nsv_unset
    } elseif {![catch {
        variable tvers [package require Thread]
	variable tvers [package require thread]
    }]} {
        variable mutex thread::mutex
        variable elock [$mutex create]
        # Import the underlying API; faster than recomputing
        interp alias {} [namespace current]::_array   {} tsv::array
        interp alias {} [namespace current]::_incr    {} tsv::incr
        interp alias {} [namespace current]::_lappend {} tsv::lappend
        interp alias {} [namespace current]::_names   {} tsv::names
        interp alias {} [namespace current]::_set     {} tsv::set
        interp alias {} [namespace current]::_unset   {} tsv::unset
	variable mutex thread::mutex
	variable elock [$mutex create]
	# Import the underlying API; faster than recomputing
	interp alias {} [namespace current]::_array   {} tsv::array
	interp alias {} [namespace current]::_incr    {} tsv::incr
	interp alias {} [namespace current]::_lappend {} tsv::lappend
	interp alias {} [namespace current]::_names   {} tsv::names
	interp alias {} [namespace current]::_set     {} tsv::set
	interp alias {} [namespace current]::_unset   {} tsv::unset
    } else {
        error "requires NaviServer/AOLserver or Tcl threading extension"
	error "requires NaviServer/AOLserver or Tcl threading extension"
    }

    # Keep in sync with the Thread package
    package provide Ttrace 3.0a2
    # Keep in sync with the thread package
    package provide ttrace 3.0.2
    package provide Ttrace 3.0.2

    # Package variables
    variable resolvers ""     ; # List of registered resolvers
    variable tracers   ""     ; # List of registered cmd tracers
    variable scripts   ""     ; # List of registered script makers
    variable enables   ""     ; # List of trace-enable callbacks
    variable disables  ""     ; # List of trace-disable callbacks
96
97
98
99
100
101
102
103
104


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125















126
127
128
129
130
131
132
133
134
135
136
137
138
139











140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162




















163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
















182
183
184
185
186


187
188
189
190
191
192
193
194
195
196
197
198









199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216















217
218
219
220
221
222



223
224
225
226
227
228
229




230
231
232
233
234
235
236
237
238
239







240
241
242
243
244
245
246
247
248
249







250
251
252
253
254
255
256
257
258
259
260
261
262










263
264
265
266
267
268
269
270
271
272







273
274
275
276
277
278
279
280
281
282







283
284
285
286
287
288
289




290
291
292
293
294


295
296
297
298
299
300
301
302
303






304
305
306
307
308
309
310
311
312
313
314
315









316
317
318
319
320


321
322
323
324
325
326
327
328
329
330







331
332
333
334
335
336
337
338
339
340







341
342
343
344
345
346
347
348





349
350
351
352
353
354
355
356
357
358
359








360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375













376
377
378
379
380
381
382




383
384
385
386
387
388
389
390
391
392
393
394
395










396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413















414
415
416
417
418
419
420
421
422






423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442

















443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467






















468
469
470
471
472
473
474
97
98
99
100
101
102
103


104
105
106
107
108
109
110
111















112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129











130
131
132
133
134
135
136
137
138
139
140
141
142
143




















144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
















167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185


186
187
188
189
190









191
192
193
194
195
196
197
198
199
200
201
202















203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220



221
222
223
224
225
226




227
228
229
230
231
232
233







234
235
236
237
238
239
240
241
242
243







244
245
246
247
248
249
250
251
252
253










254
255
256
257
258
259
260
261
262
263
264
265
266







267
268
269
270
271
272
273
274
275
276







277
278
279
280
281
282
283
284
285
286




287
288
289
290
291
292
293


294
295
296
297
298






299
300
301
302
303
304
305
306
307









308
309
310
311
312
313
314
315
316
317
318
319


320
321
322
323
324







325
326
327
328
329
330
331
332
333
334







335
336
337
338
339
340
341
342
343
344





345
346
347
348
349
350
351
352








353
354
355
356
357
358
359
360
361
362
363













364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379




380
381
382
383
384
385
386










387
388
389
390
391
392
393
394
395
396
397
398
399















400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417






418
419
420
421
422
423
424
425
426

















427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446






















447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475







-
-
+
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
+
+



-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
+
+
+



-
-
-
-
+
+
+
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
-
-
+
+
+
+



-
-
+
+



-
-
-
-
-
-
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+



-
-
+
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
-
-
-
-
-
+
+
+
+
+
+
+



-
-
-
-
-
+
+
+
+
+



-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
+
+
+
+



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    namespace eval script  "" ; # Commands for generating scripts

    # Exported commands
    namespace export unknown

    # Initialize ttrace shared state
    if {[_array exists ttrace] == 0} {
        _set ttrace lastepoch $epoch
        _set ttrace epochlist ""
	_set ttrace lastepoch $epoch
	_set ttrace epochlist ""
    }

    # Initially, allow creation of epochs
    set config(-doepochs) 1

    proc eval {cmd args} {
        enable
        set code [catch {uplevel 1 [concat $cmd $args]} result]
        disable
        if {$code == 0} {
            if {[llength [info commands ns_ictl]]} {
                ns_ictl save [getscript]
            } else {
                thread::broadcast {
                    package require Ttrace
                    ttrace::update
                }
            }
        }
        return -code $code \
            -errorinfo $::errorInfo -errorcode $::errorCode $result
	enable
	set code [catch {uplevel 1 [concat $cmd $args]} result]
	disable
	if {$code == 0} {
	    if {[llength [info commands ns_ictl]]} {
		ns_ictl save [getscript]
	    } else {
		thread::broadcast {
		    package require ttrace
		    ttrace::update
		}
	    }
	}
	return -code $code \
	    -errorinfo $::errorInfo -errorcode $::errorCode $result
    }

    proc config {args} {
        variable config
        if {[llength $args] == 0} {
            array get config
        } elseif {[llength $args] == 1} {
            set opt [lindex $args 0]
            set config($opt)
        } else {
            set opt [lindex $args 0]
            set val [lindex $args 1]
            set config($opt) $val
        }
	variable config
	if {[llength $args] == 0} {
	    array get config
	} elseif {[llength $args] == 1} {
	    set opt [lindex $args 0]
	    set config($opt)
	} else {
	    set opt [lindex $args 0]
	    set val [lindex $args 1]
	    set config($opt) $val
	}
    }

    proc enable {} {
        variable config
        variable tracers
        variable enables
        variable enabled
        incr enabled 1
        if {$enabled > 1} {
            return
        }
        if {$config(-doepochs) != 0} {
            variable epoch [_newepoch]
        }
        set nsp [namespace current]
        foreach enabler $enables {
            enable::_$enabler
        }
        foreach trace $tracers {
            if {[info commands $trace] != ""} {
                trace add execution $trace leave ${nsp}::trace::_$trace
            }
        }
	variable config
	variable tracers
	variable enables
	variable enabled
	incr enabled 1
	if {$enabled > 1} {
	    return
	}
	if {$config(-doepochs) != 0} {
	    variable epoch [_newepoch]
	}
	set nsp [namespace current]
	foreach enabler $enables {
	    enable::_$enabler
	}
	foreach trace $tracers {
	    if {[info commands $trace] != ""} {
		trace add execution $trace leave ${nsp}::trace::_$trace
	    }
	}
    }

    proc disable {} {
        variable enabled
        variable tracers
        variable disables
        incr enabled -1
        if {$enabled > 0} {
            return
        }
        set nsp [namespace current]
        foreach disabler $disables {
            disable::_$disabler
        }
        foreach trace $tracers {
            if {[info commands $trace] != ""} {
                trace remove execution $trace leave ${nsp}::trace::_$trace
            }
        }
	variable enabled
	variable tracers
	variable disables
	incr enabled -1
	if {$enabled > 0} {
	    return
	}
	set nsp [namespace current]
	foreach disabler $disables {
	    disable::_$disabler
	}
	foreach trace $tracers {
	    if {[info commands $trace] != ""} {
		trace remove execution $trace leave ${nsp}::trace::_$trace
	    }
	}
    }

    proc isenabled {} {
        variable enabled
        expr {$enabled > 0}
	variable enabled
	expr {$enabled > 0}
    }

    proc update {{from -1}} {
        if {$from == -1} {
            variable epoch [_set ttrace lastepoch]
        } else {
            if {[lsearch [_set ttrace epochlist] $from] == -1} {
                error "no such epoch: $from"
            }
            variable epoch $from
        }
        uplevel [getscript]
	if {$from < 0} {
	    variable epoch [_set ttrace lastepoch]
	} else {
	    if {[lsearch [_set ttrace epochlist] $from] < 0} {
		error "no such epoch: $from"
	    }
	    variable epoch $from
	}
	uplevel 1 [getscript]
    }

    proc getscript {} {
        variable preloads
        variable epoch
        variable scripts
        append script [_serializensp] \n
        append script "::namespace eval [namespace current] {" \n
        append script "::namespace export unknown" \n
        append script "_useepoch $epoch" \n
        append script "}" \n
        foreach cmd $preloads {
            append script [_serializeproc $cmd] \n
        }
        foreach maker $scripts {
            append script [script::_$maker]
        }
        return $script
	variable preloads
	variable epoch
	variable scripts
	append script [_serializensp] \n
	append script "::namespace eval [namespace current] {" \n
	append script "::namespace export unknown" \n
	append script "_useepoch $epoch" \n
	append script "}" \n
	foreach cmd $preloads {
	    append script [_serializeproc $cmd] \n
	}
	foreach maker $scripts {
	    append script [script::_$maker]
	}
	return $script
    }

    proc cleanup {args} {
        foreach cmd [info commands resolve::cleaner_*] {
            uplevel $cmd $args
        }
	foreach cmd [info commands resolve::cleaner_*] {
	    uplevel 1 $cmd $args
	}
    }

    proc preload {cmd} {
        variable preloads
        if {[lsearch $preloads $cmd] == -1} {
            lappend preloads $cmd
        }
	variable preloads
	if {[lsearch $preloads $cmd] < 0} {
	    lappend preloads $cmd
	}
    }

    proc atenable {cmd arglist body} {
        variable enables
        if {[lsearch $enables $cmd] == -1} {
            lappend enables $cmd
            set cmd [namespace current]::enable::_$cmd
            proc $cmd $arglist $body
            return $cmd
        }
	variable enables
	if {[lsearch $enables $cmd] < 0} {
	    lappend enables $cmd
	    set cmd [namespace current]::enable::_$cmd
	    proc $cmd $arglist $body
	    return $cmd
	}
    }

    proc atdisable {cmd arglist body} {
        variable disables
        if {[lsearch $disables $cmd] == -1} {
            lappend disables $cmd
            set cmd [namespace current]::disable::_$cmd
            proc $cmd $arglist $body
            return $cmd
        }
	variable disables
	if {[lsearch $disables $cmd] < 0} {
	    lappend disables $cmd
	    set cmd [namespace current]::disable::_$cmd
	    proc $cmd $arglist $body
	    return $cmd
	}
    }

    proc addtrace {cmd arglist body} {
        variable tracers
        if {[lsearch $tracers $cmd] == -1} {
            lappend tracers $cmd
            set tracer [namespace current]::trace::_$cmd
            proc $tracer $arglist $body
            if {[isenabled]} {
                trace add execution $cmd leave $tracer
            }
            return $tracer
        }
	variable tracers
	if {[lsearch $tracers $cmd] < 0} {
	    lappend tracers $cmd
	    set tracer [namespace current]::trace::_$cmd
	    proc $tracer $arglist $body
	    if {[isenabled]} {
		trace add execution $cmd leave $tracer
	    }
	    return $tracer
	}
    }

    proc addscript {cmd body} {
        variable scripts
        if {[lsearch $scripts $cmd] == -1} {
            lappend scripts $cmd
            set cmd [namespace current]::script::_$cmd
            proc $cmd args $body
            return $cmd
        }
	variable scripts
	if {[lsearch $scripts $cmd] < 0} {
	    lappend scripts $cmd
	    set cmd [namespace current]::script::_$cmd
	    proc $cmd args $body
	    return $cmd
	}
    }

    proc addresolver {cmd arglist body} {
        variable resolvers
        if {[lsearch $resolvers $cmd] == -1} {
            lappend resolvers $cmd
            set cmd [namespace current]::resolve::$cmd
            proc $cmd $arglist $body
            return $cmd
        }
	variable resolvers
	if {[lsearch $resolvers $cmd] < 0} {
	    lappend resolvers $cmd
	    set cmd [namespace current]::resolve::$cmd
	    proc $cmd $arglist $body
	    return $cmd
	}
    }

    proc addcleanup {body} {
        variable cleancnt
        set cmd [namespace current]::resolve::cleaner_[incr cleancnt]
        proc $cmd args $body
        return $cmd
	variable cleancnt
	set cmd [namespace current]::resolve::cleaner_[incr cleancnt]
	proc $cmd args $body
	return $cmd
    }

    proc addentry {cmd var val} {
        variable epoch
        _set ${epoch}-$cmd $var $val
	variable epoch
	_set ${epoch}-$cmd $var $val
    }

    proc delentry {cmd var} {
        variable epoch
        set ei $::errorInfo
        set ec $::errorCode
        catch {_unset ${epoch}-$cmd $var}
        set ::errorInfo $ei
        set ::errorCode $ec
	variable epoch
	set ei $::errorInfo
	set ec $::errorCode
	catch {_unset ${epoch}-$cmd $var}
	set ::errorInfo $ei
	set ::errorCode $ec
    }

    proc getentry {cmd var} {
        variable epoch
        set ei $::errorInfo
        set ec $::errorCode
        if {[catch {_set ${epoch}-$cmd $var} val]} {
            set ::errorInfo $ei
            set ::errorCode $ec
            set val ""
        }
        return $val
	variable epoch
	set ei $::errorInfo
	set ec $::errorCode
	if {[catch {_set ${epoch}-$cmd $var} val]} {
	    set ::errorInfo $ei
	    set ::errorCode $ec
	    set val ""
	}
	return $val
    }

    proc getentries {cmd {pattern *}} {
        variable epoch
        _array names ${epoch}-$cmd $pattern
	variable epoch
	_array names ${epoch}-$cmd $pattern
    }

    proc unknown {args} {
        set cmd [lindex $args 0]
        if {[uplevel ttrace::_resolve [list $cmd]]} {
            set c [catch {uplevel $cmd [lrange $args 1 end]} r]
        } else {
            set c [catch {::eval ::tcl::unknown $args} r]
        }
        return -code $c -errorcode $::errorCode -errorinfo $::errorInfo $r
	set cmd [lindex $args 0]
	if {[uplevel 1 ttrace::_resolve [list $cmd]]} {
	    set c [catch {uplevel 1 $cmd [lrange $args 1 end]} r]
	} else {
	    set c [catch {uplevel 1 ::tcl::unknown $args} r]
	}
	return -code $c -errorcode $::errorCode -errorinfo $::errorInfo $r
    }

    proc _resolve {cmd} {
        variable resolvers
        foreach resolver $resolvers {
            if {[uplevel [info comm resolve::$resolver] [list $cmd]]} {
                return 1
            }
        }
        return 0
	variable resolvers
	foreach resolver $resolvers {
	    if {[uplevel 1 [info comm resolve::$resolver] [list $cmd]]} {
		return 1
	    }
	}
	return 0
    }

    proc _getthread {} {
        if {[info commands ns_thread] == ""} {
            thread::id
        } else {
            ns_thread getid
        }
	if {[info commands ns_thread] == ""} {
	    thread::id
	} else {
	    ns_thread getid
	}
    }

    proc _getthreads {} {
        if {[info commands ns_thread] == ""} {
            return [thread::names]
        } else {
            foreach entry [ns_info threads] {
                lappend threads [lindex $entry 2]
            }
            return $threads
        }
	if {[info commands ns_thread] == ""} {
	    return [thread::names]
	} else {
	    foreach entry [ns_info threads] {
		lappend threads [lindex $entry 2]
	    }
	    return $threads
	}
    }

    proc _newepoch {} {
        variable elock
        variable mutex
        $mutex lock $elock
        set old [_set ttrace lastepoch]
        set new [_incr ttrace lastepoch]
        _lappend ttrace $new [_getthread]
        if {$old >= 0} {
            _copyepoch $old $new
            _delepochs
        }
        _lappend ttrace epochlist $new
        $mutex unlock $elock
        return $new
	variable elock
	variable mutex
	$mutex lock $elock
	set old [_set ttrace lastepoch]
	set new [_incr ttrace lastepoch]
	_lappend ttrace $new [_getthread]
	if {$old >= 0} {
	    _copyepoch $old $new
	    _delepochs
	}
	_lappend ttrace epochlist $new
	$mutex unlock $elock
	return $new
    }

    proc _copyepoch {old new} {
        foreach var [_names $old-*] {
            set cmd [lindex [split $var -] 1]
            _array reset $new-$cmd [_array get $var]
        }
	foreach var [_names $old-*] {
	    set cmd [lindex [split $var -] 1]
	    _array reset $new-$cmd [_array get $var]
	}
    }

    proc _delepochs {} {
        set tlist [_getthreads]
        set elist ""
        foreach epoch [_set ttrace epochlist] {
            if {[_dropepoch $epoch $tlist] == 0} {
                lappend elist $epoch
            } else {
                _unset ttrace $epoch
            }
        }
        _set ttrace epochlist $elist
	set tlist [_getthreads]
	set elist ""
	foreach epoch [_set ttrace epochlist] {
	    if {[_dropepoch $epoch $tlist] == 0} {
		lappend elist $epoch
	    } else {
		_unset ttrace $epoch
	    }
	}
	_set ttrace epochlist $elist
    }

    proc _dropepoch {epoch threads} {
        set self [_getthread]
        foreach tid [_set ttrace $epoch] {
            if {$tid != $self && [lsearch $threads $tid] >= 0} {
                lappend alive $tid
            }
        }
        if {[info exists alive]} {
            _set ttrace $epoch $alive
            return 0
        } else {
            foreach var [_names $epoch-*] {
                _unset $var
            }
            return 1
        }
	set self [_getthread]
	foreach tid [_set ttrace $epoch] {
	    if {$tid != $self && [lsearch $threads $tid] >= 0} {
		lappend alive $tid
	    }
	}
	if {[info exists alive]} {
	    _set ttrace $epoch $alive
	    return 0
	} else {
	    foreach var [_names $epoch-*] {
		_unset $var
	    }
	    return 1
	}
    }

    proc _useepoch {epoch} {
        if {$epoch >= 0} {
            set tid [_getthread]
            if {[lsearch [_set ttrace $epoch] $tid] == -1} {
                _lappend ttrace $epoch $tid
            }
        }
	if {$epoch >= 0} {
	    set tid [_getthread]
	    if {[lsearch [_set ttrace $epoch] $tid] == -1} {
		_lappend ttrace $epoch $tid
	    }
	}
    }

    proc _serializeproc {cmd} {
        set dargs [info args $cmd]
        set pbody [info body $cmd]
        set pargs ""
        foreach arg $dargs {
            if {![info default $cmd $arg def]} {
                lappend pargs $arg
            } else {
                lappend pargs [list $arg $def]
            }
        }
        set nsp [namespace qual $cmd]
        if {$nsp == ""} {
            set nsp "::"
        }
        append res [list ::namespace eval $nsp] " {" \n
        append res [list ::proc [namespace tail $cmd] $pargs $pbody] \n
        append res "}" \n
	set dargs [info args $cmd]
	set pbody [info body $cmd]
	set pargs ""
	foreach arg $dargs {
	    if {![info default $cmd $arg def]} {
		lappend pargs $arg
	    } else {
		lappend pargs [list $arg $def]
	    }
	}
	set nsp [namespace qual $cmd]
	if {$nsp == ""} {
	    set nsp "::"
	}
	append res [list ::namespace eval $nsp] " {" \n
	append res [list ::proc [namespace tail $cmd] $pargs $pbody] \n
	append res "}" \n
    }

    proc _serializensp {{nsp ""} {result _}} {
        upvar $result res
        if {$nsp == ""} {
            set nsp [namespace current]
        }
        append res [list ::namespace eval $nsp] " {" \n
        foreach var [info vars ${nsp}::*] {
            set vname [namespace tail $var]
            if {[array exists $var] == 0} {
                append res [list ::variable $vname [set $var]] \n
            } else {
                append res [list ::variable $vname] \n
                append res [list ::array set $vname [array get $var]] \n
            }
        }
        foreach cmd [info procs ${nsp}::*] {
            append res [_serializeproc $cmd] \n
        }
        append res "}" \n
        foreach nn [namespace children $nsp] {
            _serializensp $nn res
        }
        return $res
	upvar $result res
	if {$nsp == ""} {
	    set nsp [namespace current]
	}
	append res [list ::namespace eval $nsp] " {" \n
	foreach var [info vars ${nsp}::*] {
	    set vname [namespace tail $var]
	    if {[array exists $var] == 0} {
		append res [list ::variable $vname [set $var]] \n
	    } else {
		append res [list ::variable $vname] \n
		append res [list ::array set $vname [array get $var]] \n
	    }
	}
	foreach cmd [info procs ${nsp}::*] {
	    append res [_serializeproc $cmd] \n
	}
	append res "}" \n
	foreach nn [namespace children $nsp] {
	    _serializensp $nn res
	}
	return $res
    }
}

#
# The code below is ment to be run once during the application start.  It
# provides implementation of tracing callbacks for some Tcl commands.  Users
# can supply their own tracer implementations on-the-fly.
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511













512
513
514
515
516
517
518
519
520






521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575



































576
577
578
579
580
581
582
583
584
585
586
587
588












589
590
591
592
593
594
595
596





597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
















628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
















647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681




















682
683
684
685
686
687
688
689
690






691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734




























735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782













































783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838















































839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869













870
871
872
873
874
875
876
877
878






879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899


















900
901
902
903
904
905
906
907
908
909
910
911









912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930











931
932
933
934
935
936
937
938
939
940
941
942
493
494
495
496
497
498
499













500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515






516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541



































542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577












578
579
580
581
582
583
584
585
586
587
588
589
590
591
592





593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
















613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
















632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662




















663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685






686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707




























708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738













































739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792















































793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857













858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873






874
875
876
877
878
879
880
881
882


















883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903









904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920











921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943







-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
+
+
+
+
+
+




















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
+
+
+
+
+















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
+
+
+
+
+
+
















-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+


















-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+








-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+












    #
    # We normally need only the name_of_the_init_proc for being able to load
    # the package in other interpreters, but we store the path to the image
    # file as well.
    #

    ttrace::addtrace load {cmdline code args} {
        if {$code != 0} {
            return
        }
        set image [lindex $cmdline 1]
        set initp [lindex $cmdline 2]
        if {$initp == ""} {
            foreach pkg [info loaded] {
                if {[lindex $pkg 0] == $image} {
                    set initp [lindex $pkg 1]
                }
            }
        }
        ttrace::addentry load $image $initp
	if {$code != 0} {
	    return
	}
	set image [lindex $cmdline 1]
	set initp [lindex $cmdline 2]
	if {$initp == ""} {
	    foreach pkg [info loaded] {
		if {[lindex $pkg 0] == $image} {
		    set initp [lindex $pkg 1]
		}
	    }
	}
	ttrace::addentry load $image $initp
    }

    ttrace::addscript load {
        append res "\n"
        foreach entry [ttrace::getentries load] {
            set initp [ttrace::getentry load $entry]
            append res "::load {} $initp" \n
        }
        return $res
	append res "\n"
	foreach entry [ttrace::getentries load] {
	    set initp [ttrace::getentry load $entry]
	    append res "::load {} $initp" \n
	}
	return $res
    }

    #
    # Register the "namespace" trace. This will create the following key/value
    # entry in "namespace" store:
    #
    #  --- key ----                   --- value ---
    #  ::fully::qualified::namespace  1
    #
    # It will also fill the "proc" store for procedures and commands imported
    # in this namespace with following:
    #
    #  --- key ----                   --- value ---
    #  ::fully::qualified::proc       [list <ns>  "" ""]
    #
    # The <ns> is the name of the namespace where the command or procedure is
    # imported from.
    #

    ttrace::addtrace namespace {cmdline code args} {
        if {$code != 0} {
            return
        }
        set nop [lindex $cmdline 1]
        set cns [uplevel namespace current]
        if {$cns == "::"} {
            set cns ""
        }
        switch -glob $nop {
            eva* {
                set nsp [lindex $cmdline 2]
                if {![string match "::*" $nsp]} {
                    set nsp ${cns}::$nsp
                }
                ttrace::addentry namespace $nsp 1
            }
            imp* {
                # - parse import arguments (skip opt "-force")
                set opts [lrange $cmdline 2 end]
                if {[string match "-fo*" [lindex $opts 0]]} {
                    set opts [lrange $cmdline 3 end]
                }
                # - register all imported procs and commands
                foreach opt $opts {
                    if {![string match "::*" [::namespace qual $opt]]} {
                        set opt ${cns}::$opt
                    }
                    # - first import procs
                    foreach entry [ttrace::getentries proc $opt] {
                        set cmd ${cns}::[::namespace tail $entry]
                        set nsp [::namespace qual $entry]
                        set done($cmd) 1
                        set entry [list 0 $nsp "" ""]
                        ttrace::addentry proc $cmd $entry
                    }
	if {$code != 0} {
	    return
	}
	set nop [lindex $cmdline 1]
	set cns [uplevel 1 namespace current]
	if {$cns == "::"} {
	    set cns ""
	}
	switch -glob $nop {
	    eva* {
		set nsp [lindex $cmdline 2]
		if {![string match "::*" $nsp]} {
		    set nsp ${cns}::$nsp
		}
		ttrace::addentry namespace $nsp 1
	    }
	    imp* {
		# - parse import arguments (skip opt "-force")
		set opts [lrange $cmdline 2 end]
		if {[string match "-fo*" [lindex $opts 0]]} {
		    set opts [lrange $cmdline 3 end]
		}
		# - register all imported procs and commands
		foreach opt $opts {
		    if {![string match "::*" [::namespace qual $opt]]} {
			set opt ${cns}::$opt
		    }
		    # - first import procs
		    foreach entry [ttrace::getentries proc $opt] {
			set cmd ${cns}::[::namespace tail $entry]
			set nsp [::namespace qual $entry]
			set done($cmd) 1
			set entry [list 0 $nsp "" ""]
			ttrace::addentry proc $cmd $entry
		    }

                    # - then import commands
                    foreach entry [info commands $opt] {
                        set cmd ${cns}::[::namespace tail $entry]
                        set nsp [::namespace qual $entry]
                        if {[info exists done($cmd)] == 0} {
                            set entry [list 0 $nsp "" ""]
                            ttrace::addentry proc $cmd $entry
                        }
                    }
                }
            }
        }
		    # - then import commands
		    foreach entry [info commands $opt] {
			set cmd ${cns}::[::namespace tail $entry]
			set nsp [::namespace qual $entry]
			if {[info exists done($cmd)] == 0} {
			    set entry [list 0 $nsp "" ""]
			    ttrace::addentry proc $cmd $entry
			}
		    }
		}
	    }
	}
    }

    ttrace::addscript namespace {
        append res \n
        foreach entry [ttrace::getentries namespace] {
            append res "::namespace eval $entry {}" \n
        }
        return $res
	append res \n
	foreach entry [ttrace::getentries namespace] {
	    append res "::namespace eval $entry {}" \n
	}
	return $res
    }

    #
    # Register the "variable" trace. This will create the following key/value
    # entry in the "variable" store:
    #
    #  --- key ----                   --- value ---
    #  ::fully::qualified::variable   1
    #
    # The variable value itself is ignored at the time of
    # trace/collection. Instead, we take the real value at the time of script
    # generation.
    #

    ttrace::addtrace variable {cmdline code args} {
        if {$code != 0} {
            return
        }
        set opts [lrange $cmdline 1 end]
        if {[llength $opts]} {
            set cns [uplevel namespace current]
            if {$cns == "::"} {
                set cns ""
            }
            foreach {var val} $opts {
                if {![string match "::*" $var]} {
                    set var ${cns}::$var
                }
                ttrace::addentry variable $var 1
            }
        }
	if {$code != 0} {
	    return
	}
	set opts [lrange $cmdline 1 end]
	if {[llength $opts]} {
	    set cns [uplevel 1 namespace current]
	    if {$cns == "::"} {
		set cns ""
	    }
	    foreach {var val} $opts {
		if {![string match "::*" $var]} {
		    set var ${cns}::$var
		}
		ttrace::addentry variable $var 1
	    }
	}
    }

    ttrace::addscript variable {
        append res \n
        foreach entry [ttrace::getentries variable] {
            set cns [namespace qual $entry]
            set var [namespace tail $entry]
            append res "::namespace eval $cns {" \n
            append res "::variable $var"
            if {[array exists $entry]} {
                append res "\n::array set $var [list [array get $entry]]" \n
            } elseif {[info exists $entry]} {
                append res " [list [set $entry]]" \n
            } else {
                append res \n
            }
            append res "}" \n
        }
        return $res
	append res \n
	foreach entry [ttrace::getentries variable] {
	    set cns [namespace qual $entry]
	    set var [namespace tail $entry]
	    append res "::namespace eval $cns {" \n
	    append res "::variable $var"
	    if {[array exists $entry]} {
		append res "\n::array set $var [list [array get $entry]]" \n
	    } elseif {[info exists $entry]} {
		append res " [list [set $entry]]" \n
	    } else {
		append res \n
	    }
	    append res "}" \n
	}
	return $res
    }


    #
    # Register the "rename" trace. It will create the following key/value pair
    # in "rename" store:
    #
    #  --- key ----              --- value ---
    #  ::fully::qualified::old  ::fully::qualified::new
    #
    # The "new" value may be empty, for commands that have been deleted. In
    # such cases we also remove any traced procedure definitions.
    #

    ttrace::addtrace rename {cmdline code args} {
        if {$code != 0} {
            return
        }
        set cns [uplevel namespace current]
        if {$cns == "::"} {
            set cns ""
        }
        set old [lindex $cmdline 1]
        if {![string match "::*" $old]} {
            set old ${cns}::$old
        }
        set new [lindex $cmdline 2]
        if {$new != ""} {
            if {![string match "::*" $new]} {
                set new ${cns}::$new
            }
            ttrace::addentry rename $old $new
        } else {
            ttrace::delentry proc $old
        }
	if {$code != 0} {
	    return
	}
	set cns [uplevel 1 namespace current]
	if {$cns == "::"} {
	    set cns ""
	}
	set old [lindex $cmdline 1]
	if {![string match "::*" $old]} {
	    set old ${cns}::$old
	}
	set new [lindex $cmdline 2]
	if {$new != ""} {
	    if {![string match "::*" $new]} {
		set new ${cns}::$new
	    }
	    ttrace::addentry rename $old $new
	} else {
	    ttrace::delentry proc $old
	}
    }

    ttrace::addscript rename {
        append res \n
        foreach old [ttrace::getentries rename] {
            set new [ttrace::getentry rename $old]
            append res "::rename $old {$new}" \n
        }
        return $res
	append res \n
	foreach old [ttrace::getentries rename] {
	    set new [ttrace::getentry rename $old]
	    append res "::rename $old {$new}" \n
	}
	return $res
    }

    #
    # Register the "proc" trace. This will create the following key/value pair
    # in the "proc" store:
    #
    #  --- key ----              --- value ---
    #  ::fully::qualified::proc  [list <epoch> <ns> <arglist> <body>]
    #
    # The <epoch> chages anytime one (re)defines a proc.  The <ns> is the
    # namespace where the command was imported from. If empty, the <arglist>
    # and <body> will hold the actual procedure definition. See the
    # "namespace" tracer implementation also.
    #

    ttrace::addtrace proc {cmdline code args} {
        if {$code != 0} {
            return
        }
        set cns [uplevel namespace current]
        if {$cns == "::"} {
            set cns ""
        }
        set cmd [lindex $cmdline 1]
        if {![string match "::*" $cmd]} {
            set cmd ${cns}::$cmd
        }
        set dargs [info args $cmd]
        set pbody [info body $cmd]
        set pargs ""
        foreach arg $dargs {
            if {![info default $cmd $arg def]} {
                lappend pargs $arg
            } else {
                lappend pargs [list $arg $def]
            }
        }
        set pdef [ttrace::getentry proc $cmd]
        if {$pdef == ""} {
            set epoch -1 ; # never traced before
        } else {
            set epoch [lindex $pdef 0]
        }
        ttrace::addentry proc $cmd [list [incr epoch] "" $pargs $pbody]
	if {$code != 0} {
	    return
	}
	set cns [uplevel 1 namespace current]
	if {$cns == "::"} {
	    set cns ""
	}
	set cmd [lindex $cmdline 1]
	if {![string match "::*" $cmd]} {
	    set cmd ${cns}::$cmd
	}
	set dargs [info args $cmd]
	set pbody [info body $cmd]
	set pargs ""
	foreach arg $dargs {
	    if {![info default $cmd $arg def]} {
		lappend pargs $arg
	    } else {
		lappend pargs [list $arg $def]
	    }
	}
	set pdef [ttrace::getentry proc $cmd]
	if {$pdef == ""} {
	    set epoch -1 ; # never traced before
	} else {
	    set epoch [lindex $pdef 0]
	}
	ttrace::addentry proc $cmd [list [incr epoch] "" $pargs $pbody]
    }

    ttrace::addscript proc {
        return {
            if {[info command ::tcl::unknown] == ""} {
                rename ::unknown ::tcl::unknown
                namespace import -force ::ttrace::unknown
            }
            if {[info command ::tcl::info] == ""} {
                rename ::info ::tcl::info
            }
            proc ::info args {
                set cmd [lindex $args 0]
                set hit [lsearch -glob {commands procs args default body} $cmd*]
                if {$hit > 1} {
                    if {[catch {uplevel ::tcl::info $args}]} {
                        uplevel ttrace::_resolve [list [lindex $args 1]]
                    }
                    return [uplevel ::tcl::info $args]
                }
                if {$hit == -1} {
                    return [uplevel ::tcl::info $args]
                }
                set cns [uplevel namespace current]
                if {$cns == "::"} {
                    set cns ""
                }
                set pat [lindex $args 1]
                if {![string match "::*" $pat]} {
                    set pat ${cns}::$pat
                }
                set fns [ttrace::getentries proc $pat]
                if {[string match $cmd* commands]} {
                    set fns [concat $fns [ttrace::getentries xotcl $pat]]
                }
                foreach entry $fns {
                    if {$cns != [namespace qual $entry]} {
                        set lazy($entry) 1
                    } else {
                        set lazy([namespace tail $entry]) 1
                    }
                }
                foreach entry [uplevel ::tcl::info $args] {
                    set lazy($entry) 1
                }
                array names lazy
            }
        }
	return {
	    if {[info command ::tcl::unknown] == ""} {
		rename ::unknown ::tcl::unknown
		namespace import -force ::ttrace::unknown
	    }
	    if {[info command ::tcl::info] == ""} {
		rename ::info ::tcl::info
	    }
	    proc ::info args {
		set cmd [lindex $args 0]
		set hit [lsearch -glob {commands procs args default body} $cmd*]
		if {$hit > 1} {
		    if {[catch {uplevel 1 ::tcl::info $args}]} {
			uplevel 1 ttrace::_resolve [list [lindex $args 1]]
		    }
		    return [uplevel 1 ::tcl::info $args]
		}
		if {$hit == -1} {
		    return [uplevel 1 ::tcl::info $args]
		}
		set cns [uplevel 1 namespace current]
		if {$cns == "::"} {
		    set cns ""
		}
		set pat [lindex $args 1]
		if {![string match "::*" $pat]} {
		    set pat ${cns}::$pat
		}
		set fns [ttrace::getentries proc $pat]
		if {[string match $cmd* commands]} {
		    set fns [concat $fns [ttrace::getentries xotcl $pat]]
		}
		foreach entry $fns {
		    if {$cns != [namespace qual $entry]} {
			set lazy($entry) 1
		    } else {
			set lazy([namespace tail $entry]) 1
		    }
		}
		foreach entry [uplevel 1 ::tcl::info $args] {
		    set lazy($entry) 1
		}
		array names lazy
	    }
	}
    }

    #
    # Register procedure resolver. This will try to resolve the command in the
    # current namespace first, and if not found, in global namespace.  It also
    # handles commands imported from other namespaces.
    #

    ttrace::addresolver resolveprocs {cmd {export 0}} {
        set cns [uplevel namespace current]
        set name [namespace tail $cmd]
        if {$cns == "::"} {
            set cns ""
        }
        if {![string match "::*" $cmd]} {
            set ncmd ${cns}::$cmd
            set gcmd ::$cmd
        } else {
            set ncmd $cmd
            set gcmd $cmd
        }
        set pdef [ttrace::getentry proc $ncmd]
        if {$pdef == ""} {
            set pdef [ttrace::getentry proc $gcmd]
            if {$pdef == ""} {
                return 0
            }
            set cmd $gcmd
        } else {
            set cmd $ncmd
        }
        set epoch [lindex $pdef 0]
        set pnsp  [lindex $pdef 1]
        if {$pnsp != ""} {
            set nsp [namespace qual $cmd]
            if {$nsp == ""} {
                set nsp ::
            }
            set cmd ${pnsp}::$name
            if {[resolveprocs $cmd 1] == 0 && [info commands $cmd] == ""} {
                return 0
            }
            namespace eval $nsp "namespace import -force $cmd"
        } else {
            uplevel 0 [list ::proc $cmd [lindex $pdef 2] [lindex $pdef 3]]
            if {$export} {
                set nsp [namespace qual $cmd]
                if {$nsp == ""} {
                    set nsp ::
                }
                namespace eval $nsp "namespace export $name"
            }
        }
        variable resolveproc
        set resolveproc($cmd) $epoch
        return 1
	set cns [uplevel 1 namespace current]
	set name [namespace tail $cmd]
	if {$cns == "::"} {
	    set cns ""
	}
	if {![string match "::*" $cmd]} {
	    set ncmd ${cns}::$cmd
	    set gcmd ::$cmd
	} else {
	    set ncmd $cmd
	    set gcmd $cmd
	}
	set pdef [ttrace::getentry proc $ncmd]
	if {$pdef == ""} {
	    set pdef [ttrace::getentry proc $gcmd]
	    if {$pdef == ""} {
		return 0
	    }
	    set cmd $gcmd
	} else {
	    set cmd $ncmd
	}
	set epoch [lindex $pdef 0]
	set pnsp  [lindex $pdef 1]
	if {$pnsp != ""} {
	    set nsp [namespace qual $cmd]
	    if {$nsp == ""} {
		set nsp ::
	    }
	    set cmd ${pnsp}::$name
	    if {[resolveprocs $cmd 1] == 0 && [info commands $cmd] == ""} {
		return 0
	    }
	    namespace eval $nsp "namespace import -force $cmd"
	} else {
	    uplevel 0 [list ::proc $cmd [lindex $pdef 2] [lindex $pdef 3]]
	    if {$export} {
		set nsp [namespace qual $cmd]
		if {$nsp == ""} {
		    set nsp ::
		}
		namespace eval $nsp "namespace export $name"
	    }
	}
	variable resolveproc
	set resolveproc($cmd) $epoch
	return 1
    }

    #
    # For XOTcl, the entire item introspection/tracing is delegated to XOTcl
    # itself. The xotcl store is filled with this:
    #
    #  --- key ----               --- value ---
    #  ::fully::qualified::item   <body>
    #
    # The <body> is the script used to generate the entire item (class,
    # object). Note that we do not fill in this during code tracing. It is
    # done during the script generation. In this step, only the placeholder is
    # set.
    #
    # NOTE: we assume all XOTcl commands are imported in global namespace
    #

    ttrace::atenable XOTclEnabler {args} {
        if {[info commands ::xotcl::Class] == ""} {
            return
        }
        if {[info commands ::xotcl::_creator] == ""} {
            ::xotcl::Class create ::xotcl::_creator -instproc create {args} {
                set result [next]
                if {![string match ::xotcl::_* $result]} {
                    ttrace::addentry xotcl $result ""
                }
                return $result
            }
        }
        ::xotcl::Class instmixin ::xotcl::_creator
	if {[info commands ::xotcl::Class] == ""} {
	    return
	}
	if {[info commands ::xotcl::_creator] == ""} {
	    ::xotcl::Class create ::xotcl::_creator -instproc create {args} {
		set result [next]
		if {![string match ::xotcl::_* $result]} {
		    ttrace::addentry xotcl $result ""
		}
		return $result
	    }
	}
	::xotcl::Class instmixin ::xotcl::_creator
    }

    ttrace::atdisable XOTclDisabler {args} {
        if {   [info commands ::xotcl::Class] == ""
            || [info commands ::xotcl::_creator] == ""} {
            return
        }
        ::xotcl::Class instmixin ""
        ::xotcl::_creator destroy
	if {   [info commands ::xotcl::Class] == ""
	    || [info commands ::xotcl::_creator] == ""} {
	    return
	}
	::xotcl::Class instmixin ""
	::xotcl::_creator destroy
    }

    set resolver [ttrace::addresolver resolveclasses {classname} {
        set cns [uplevel namespace current]
        set script [ttrace::getentry xotcl $classname]
        if {$script == ""} {
            set name [namespace tail $classname]
            if {$cns == "::"} {
                set script [ttrace::getentry xotcl ::$name]
            } else {
                set script [ttrace::getentry xotcl ${cns}::$name]
                if {$script == ""} {
                    set script [ttrace::getentry xotcl ::$name]
                }
            }
            if {$script == ""} {
                return 0
            }
        }
        uplevel [list namespace eval $cns $script]
        return 1
	set cns [uplevel 1 namespace current]
	set script [ttrace::getentry xotcl $classname]
	if {$script == ""} {
	    set name [namespace tail $classname]
	    if {$cns == "::"} {
		set script [ttrace::getentry xotcl ::$name]
	    } else {
		set script [ttrace::getentry xotcl ${cns}::$name]
		if {$script == ""} {
		    set script [ttrace::getentry xotcl ::$name]
		}
	    }
	    if {$script == ""} {
		return 0
	    }
	}
	uplevel 1 [list namespace eval $cns $script]
	return 1
    }]

    ttrace::addscript xotcl [subst -nocommands {
        if {![catch {Serializer new} ss]} {
            foreach entry [ttrace::getentries xotcl] {
                if {[ttrace::getentry xotcl \$entry] == ""} {
                    ttrace::addentry xotcl \$entry [\$ss serialize \$entry]
                }
            }
            \$ss destroy
            return {::xotcl::Class proc __unknown name {$resolver \$name}}
        }
	if {![catch {Serializer new} ss]} {
	    foreach entry [ttrace::getentries xotcl] {
		if {[ttrace::getentry xotcl \$entry] == ""} {
		    ttrace::addentry xotcl \$entry [\$ss serialize \$entry]
		}
	    }
	    \$ss destroy
	    return {::xotcl::Class proc __unknown name {$resolver \$name}}
	}
    }]

    #
    # Register callback to be called on cleanup. This will trash lazily loaded
    # procs which have changed since.
    #

    ttrace::addcleanup {
        variable resolveproc
        foreach cmd [array names resolveproc] {
            set def [ttrace::getentry proc $cmd]
            if {$def != ""} {
                set new [lindex $def 0]
                set old $resolveproc($cmd)
                if {[info command $cmd] != "" && $new != $old} {
                    catch {rename $cmd ""}
                }
            }
        }
	variable resolveproc
	foreach cmd [array names resolveproc] {
	    set def [ttrace::getentry proc $cmd]
	    if {$def != ""} {
		set new [lindex $def 0]
		set old $resolveproc($cmd)
		if {[info command $cmd] != "" && $new != $old} {
		    catch {rename $cmd ""}
		}
	    }
	}
    }
}

# EOF
return

# Local Variables:
# mode: tcl
# fill-column: 78
# tab-width: 8
# indent-tabs-mode: nil
# End:
Changes to naviserver.m4.
27
28
29
30
31
32
33
34
35
36
37
38





39
40
41
42

43
44
45
46
47
48
49
50
51
52
53










54
55
56
57
27
28
29
30
31
32
33





34
35
36
37
38
39
40
41

42
43










44
45
46
47
48
49
50
51
52
53
54
55
56
57







-
-
-
-
-
+
+
+
+
+



-
+

-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+




    AC_MSG_CHECKING([for NaviServer/AOLserver configuration])
    AC_ARG_WITH(naviserver,
    [  --with-naviserver       directory with NaviServer/AOLserver distribution],\
    with_naviserver=${withval})

    AC_CACHE_VAL(ac_cv_c_naviserver,[
    if test x"${with_naviserver}" != x ; then
        if test -f "${with_naviserver}/include/ns.h" ; then
            ac_cv_c_naviserver=`(cd ${with_naviserver}; pwd)`
        else
            AC_MSG_ERROR([${with_naviserver} directory doesn't contain ns.h])
        fi
	if test -f "${with_naviserver}/include/ns.h" ; then
	    ac_cv_c_naviserver=`(cd ${with_naviserver}; pwd)`
	else
	    AC_MSG_ERROR([${with_naviserver} directory doesn't contain ns.h])
	fi
    fi
    ])
    if test x"${ac_cv_c_naviserver}" = x ; then
        AC_MSG_RESULT([none found])
	AC_MSG_RESULT([none found])
    else
        NS_DIR=${ac_cv_c_naviserver}
        AC_MSG_RESULT([found NaviServer/AOLserver in $NS_DIR])
        NS_INCLUDES="-I\"${NS_DIR}/include\""
        if test "`uname -s`" = Darwin ; then
            aollibs=`ls ${NS_DIR}/lib/libns* 2>/dev/null`
            if test x"$aollibs" != x ; then
                NS_LIBS="-L\"${NS_DIR}/lib\" -lnsd -lnsthread"
            fi
        fi
        AC_DEFINE(NS_AOLSERVER)
	NS_DIR=${ac_cv_c_naviserver}
	AC_MSG_RESULT([found NaviServer/AOLserver in $NS_DIR])
	NS_INCLUDES="-I\"${NS_DIR}/include\""
	if test "`uname -s`" = Darwin ; then
	    aollibs=`ls ${NS_DIR}/lib/libns* 2>/dev/null`
	    if test x"$aollibs" != x ; then
		NS_LIBS="-L\"${NS_DIR}/lib\" -lnsd -lnsthread"
	    fi
	fi
	AC_DEFINE(NS_AOLSERVER)
    fi
])

# EOF
Changes to pkgIndex.tcl.in.
1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17

18
19
20
21
22
23

24

25



26
27

28
29
30
31

32
33
34
35
36
37
38



39
40
41
42
43



44
45
46
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16

17
18
19
20
21
22

23
24
25

26
27
28
29

30
31
32
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55












-
+



-
+





-
+

+
-
+
+
+

-
+



-
+







+
+
+





+
+
+



# -*- tcl -*-
# Tcl package index file, version 1.1
#

# Tcl 8.7 interps are only supported on 32-bit platforms.
# Lower than that is never supported. Bye!
if {![package vsatisfies [package provide Tcl] 9.0]
	&& ((![package vsatisfies [package provide Tcl] 8.7])
	|| ($::tcl_platform(pointerSize)!=4))} {
    return
}

# All Tcl 8.7+ interps can [load] Thread @PACKAGE_VERSION@
# All Tcl 8.7+ interps can [load] thread @PACKAGE_VERSION@
#
# For interps that are not thread-enabled, we still call [package ifneeded].
# This is contrary to the usual convention, but is a good idea because we
# cannot imagine any other version of Thread that might succeed in a
# cannot imagine any other version of thread that might succeed in a
# thread-disabled interp.  There's nothing to gain by yielding to other
# competing callers of [package ifneeded Thread].  On the other hand,
# deferring the error has the advantage that a script calling
# [package require Thread] in a thread-disabled interp gets an error message
# about a thread-disabled interp, instead of the message
# "can't find package Thread".
# "can't find package thread".

package ifneeded [string tolower @PACKAGE_NAME@] @PACKAGE_VERSION@ \
package ifneeded Thread @PACKAGE_VERSION@ [list load [file join $dir @PKG_LIB_FILE@]]
    [list load [file join $dir @PKG_LIB_FILE@] [string totitle @PACKAGE_NAME@]]
package ifneeded [string totitle @PACKAGE_NAME@] @PACKAGE_VERSION@ \
    [list package require -exact [string tolower @PACKAGE_NAME@] @PACKAGE_VERSION@]

# package Ttrace uses some support machinery.
# package ttrace uses some support machinery.

# In Tcl 8.7+ interps; use [::apply]

package ifneeded Ttrace @PACKAGE_VERSION@ [list ::apply {{dir} {
package ifneeded ttrace @PACKAGE_VERSION@ [list ::apply {{dir} {
    if {[info exists ::env(TCL_THREAD_LIBRARY)] &&
	[file readable $::env(TCL_THREAD_LIBRARY)/ttrace.tcl]} {
	source $::env(TCL_THREAD_LIBRARY)/ttrace.tcl
    } elseif {[file readable [file join $dir .. lib ttrace.tcl]]} {
	source [file join $dir .. lib ttrace.tcl]
    } elseif {[file readable [file join $dir ttrace.tcl]]} {
	source [file join $dir ttrace.tcl]
    } elseif {[file exists //zipfs:/lib/thread/ttrace.tcl] ||
              ![catch {zipfs mount [file join $dir @PKG_LIB_FILE@] //zipfs:/lib/thread}]} {
	source //zipfs:/lib/thread/ttrace.tcl
    }
    if {[namespace which ::ttrace::update] ne ""} {
	::ttrace::update
    }
}} $dir]
package ifneeded Ttrace @PACKAGE_VERSION@ \
    [list package require -exact ttrace @PACKAGE_VERSION@]




Changes to project.shed.
1
2
3
4
5
6
7
8
9
10

11
12
13

14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9

10
11
12

13
14
15
16
17
18
19
20









-
+


-
+








7bce708b4197acccd1db4644fdbe5ee249f3b5dd {
  entity {
    name: thread
    shed_class: project
    version: {}
  }
  meta {
    class: generic
    description: {The Tcl Thread package}
    description: {The Tcl thread package}
    distribution: fossil
    generated: {2015-10-06 10:32:03 UTC}
    release: trunk
    release: main
  }
  release/ {
    ccc83b2283498a2ec86d00bf8593e7de0cf8a456
  }
  distribution/ {
    e47b6a79a963c99b7de15a4817b3010fbb3dd693
  }
30
31
32
33
34
35
36
37

38
39
40
41
42

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

58
59
60


61
62
63
64
65
66
67

68
69
70
71
72
73
74
30
31
32
33
34
35
36

37
38
39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

57
58


59
60
61
62
63
64
65
66

67
68
69
70
71
72
73
74







-
+




-
+














-
+

-
-
+
+






-
+







  }
  file/ {
    032fb91c412db8ae1a282ae54d353fe33e45ff6a
  }
}
ccc83b2283498a2ec86d00bf8593e7de0cf8a456 {
  entity {
    name: trunk
    name: main
    shed_class: release
    version: {}
  }
  meta {
    checkout: trunk
    checkout: main
    class: generic
    timestamp: {2015-10-06 10:32:03 UTC}
  }
}
e47b6a79a963c99b7de15a4817b3010fbb3dd693 {
  entity {
    name: fossil
    shed_class: distribution
    version: {}
  }
  meta {
    class: generic
    format: fossil
    project: 7bce708b4197acccd1db4644fdbe5ee249f3b5dd
    project-name: {Tcl package Thread source code}
    project-name: {Tcl package thread source code}
    project-short-name: thread
    release: trunk
    url: http://fossil.etoyoc.com/fossil/thread
    release: main
    url: https://core.tcl-lang.org/thread
  }
}
41c2f28a24688f0ad5c1431fbd22f1621b6b0d6e {
  entity {
    name: thread
    shed_class: package
    version: 2.7.2
    version: 3.0.2
  }
  meta {
    build: tea
    class: binary
  }
}
6dbf64aeadfe9d6fb88c0d84562a98a4b33d374b {
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103







-
+







    name: tcl
    shed_class: module
    version: {}
  }
  meta {
    class: source
    package-provide: {}
    package-require: {{Tcl 8.7} {Thread 2.8}}
    package-require: {{Tcl 8.7} {thread 3.0}}
    path: tcl
  }
}
cf5303e1f3f79bc837e9b1a18e5e2e3f4892c58c {
  entity {
    name: generic
    shed_class: module
Changes to tcl/README.
1
2
3
4
5
6
7
8
9
10
11




12
13
14
15
16
17
18
19
20
21








22
23
24
25


26
27
28
29
30
31
32
1
2
3
4
5
6
7




8
9
10
11
12
13








14
15
16
17
18
19
20
21
22
23


24
25
26
27
28
29
30
31
32







-
-
-
-
+
+
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
-
+
+








Software here is provided as example of making some interesting
things and applications using the Tcl threading extension.

Currently, following packages are supplied:

   tpool/    Example Tcl-only implementation of thread pools.
             The threading extension includes an efficient
             threadpool implementation in C. This file is
             provided as a fully functional example on how this
             functionality could be implemented in Tcl alone.
	     The threading extension includes an efficient
	     threadpool implementation in C. This file is
	     provided as a fully functional example on how this
	     functionality could be implemented in Tcl alone.

   phttpd/   MT-enabled httpd server. It uses threadpool to
             distribute incoming requests among several worker
             threads in the threadpool. This way blocking
             requests may be handled much better, w/o halting
             the event loop of the main responder thread.
             In this directory you will also find the uhttpd.
             This is the same web-server but operating in the
             event-loop mode alone, no threadpool support.
             This is good for comparison purposes.
	     distribute incoming requests among several worker
	     threads in the threadpool. This way blocking
	     requests may be handled much better, w/o halting
	     the event loop of the main responder thread.
	     In this directory you will also find the uhttpd.
	     This is the same web-server but operating in the
	     event-loop mode alone, no threadpool support.
	     This is good for comparison purposes.

   cmdsrv/   Socket command-line server. Each new connection
             gets new thread, thus allowing multiple outstanding
             blocking calls without halting the event loop.
	     gets new thread, thus allowing multiple outstanding
	     blocking calls without halting the event loop.

To play around with above packages, change to the corresponding
directory and source files in the Tcl8.7 (or later) Tcl shell.
Be sure to have the latest Tcl threading extension installed in
your package path.

- EOF
Changes to tcl/cmdsrv/cmdsrv.tcl.
9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

31
32
33
34
35
36
37
38







-
+














-
+







#
#    port         Tcp port where the server listens
#    -idletime    # of sec to idle before tearing down socket (def: 300 sec)
#    -initcmd     script to initialize new worker thread (def: empty)
#
# Example:
#
#    # tclsh8.6
#    # tclsh9.0
#    % source cmdsrv.tcl
#    % cmdsrv::create 5000 -idletime 60
#    % vwait forever
#
#    Starts the server on the port 5000, sets idle timer to 1 minute.
#    You can now use "telnet" utility to connect.
#
# Copyright (c) 2002 by Zoran Vasiljevic.
#
# See the file "license.terms" for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# -----------------------------------------------------------------------------

package require Tcl    8.5-
package require Thread 2.8-
package require thread 2.9-

namespace eval cmdsrv {
    variable data; # Stores global configuration options
}

#
# cmdsrv::create --
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67


68
69
70
71
72
73
74
75
76
77
78
79
80
81







82
83
84
85
86
87
88
51
52
53
54
55
56
57

58
59
60
61
62
63
64
65


66
67
68
69
70
71
72
73
74







75
76
77
78
79
80
81
82
83
84
85
86
87
88







-
+







-
-
+
+







-
-
-
-
-
-
-
+
+
+
+
+
+
+







#

proc cmdsrv::create {port args} {

    variable data

    if {[llength $args] % 2} {
        error "wrong \# arguments, should be: key1 val1 key2 val2..."
	error "wrong \# arguments, should be: key1 val1 key2 val2..."
    }

    #
    # Setup default pool data.
    #

    array set data {
        -idletime 300000
        -initcmd  {source cmdsrv.tcl}
	-idletime 300000
	-initcmd  {source cmdsrv.tcl}
    }

    #
    # Override with user-supplied data
    #

    foreach {arg val} $args {
        switch -- $arg {
            -idletime {set data($arg) [expr {$val*1000}]}
            -initcmd  {append data($arg) \n $val}
            default {
                error "unsupported pool option \"$arg\""
            }
        }
	switch -- $arg {
	    -idletime {set data($arg) [expr {$val*1000}]}
	    -initcmd  {append data($arg) \n $val}
	    default {
		error "unsupported pool option \"$arg\""
	    }
	}
    }

    #
    # Start the server on the given port. Note that we wrap
    # the actual accept with a helper after/idle callback.
    # This is a workaround for a well-known Tcl bug.
    #
154
155
156
157
158
159
160
161
162
163
164




165
166
167
168
169
170
171
154
155
156
157
158
159
160




161
162
163
164
165
166
167
168
169
170
171







-
-
-
-
+
+
+
+







    thread::transfer $tid $s ; # This flushes the socket as well

    #
    # Start event-loop processing in the remote thread
    #

    thread::send -async $tid [subst {
        array set [namespace current]::data {[array get data]}
        fileevent $s readable {[namespace current]::Read $s}
        proc exit args {[namespace current]::SockDone $s}
        [namespace current]::StartIdleTimer $s
	array set [namespace current]::data {[array get data]}
	fileevent $s readable {[namespace current]::Read $s}
	proc exit args {[namespace current]::SockDone $s}
	[namespace current]::StartIdleTimer $s
    }]
}

#
# cmdsrv::Read --
#
#	Event loop procedure to read data from socket and collect the
189
190
191
192
193
194
195
196

197
198
199
200
201
202




203
204
205
206
207
208
209
210
211
212
213
214




215
216
217
218
219
220
221
222
223

224
225
226
227

228
229
230
231
232
233
234
189
190
191
192
193
194
195

196
197
198




199
200
201
202
203
204
205
206
207
208
209
210




211
212
213
214
215
216
217
218
219
220
221
222

223
224
225
226

227
228
229
230
231
232
233
234







-
+


-
-
-
-
+
+
+
+








-
-
-
-
+
+
+
+








-
+



-
+







    StopIdleTimer $s

    #
    # Cover client closing connection
    #

    if {[eof $s] || [catch {read $s} line]} {
        return [SockDone $s]
	return [SockDone $s]
    }
    if {$line == "\n" || $line == ""} {
        if {[catch {puts -nonewline $s "% "}]} {
            return [SockDone $s]
        }
        return [StartIdleTimer $s]
	if {[catch {puts -nonewline $s "% "}]} {
	    return [SockDone $s]
	}
	return [StartIdleTimer $s]
    }

    #
    # Construct command line to eval
    #

    append data(cmd) $line
    if {[info complete $data(cmd)] == 0} {
        if {[catch {puts -nonewline $s "> "}]} {
            return [SockDone $s]
        }
        return [StartIdleTimer $s]
	if {[catch {puts -nonewline $s "> "}]} {
	    return [SockDone $s]
	}
	return [StartIdleTimer $s]
    }

    #
    # Run the command
    #

    catch {uplevel \#0 $data(cmd)} ret
    if {[catch {puts $s $ret}]} {
        return [SockDone $s]
	return [SockDone $s]
    }
    set data(cmd) ""
    if {[catch {puts -nonewline $s "% "}]} {
        return [SockDone $s]
	return [SockDone $s]
    }
    StartIdleTimer $s
}

#
# cmdsrv::SockDone --
#
267
268
269
270
271
272
273
274
275


276
277
278
279
280
281
282
267
268
269
270
271
272
273


274
275
276
277
278
279
280
281
282







-
-
+
+







#

proc cmdsrv::StopIdleTimer {s} {

    variable data

    if {[info exists data(idleevent)]} {
        after cancel $data(idleevent)
        unset data(idleevent)
	after cancel $data(idleevent)
	unset data(idleevent)
    }
}

#
# cmdsrv::StartIdleTimer --
#
#	Initiates the connection idle timer.
292
293
294
295
296
297
298
299

300
301
302
303
304
305
306
307
308
309
310
292
293
294
295
296
297
298

299
300
301
302
303
304
305
306
307
308
309
310







-
+











#

proc cmdsrv::StartIdleTimer {s} {

    variable data

    set data(idleevent) \
        [after $data(-idletime) [list [namespace current]::SockDone $s]]
	[after $data(-idletime) [list [namespace current]::SockDone $s]]
}

# EOF $RCSfile: cmdsrv.tcl,v $

# Emacs Setup Variables
# Local Variables:
# mode: Tcl
# indent-tabs-mode: nil
# tcl-basic-offset: 4
# End:

Changes to tcl/phttpd/phttpd.tcl.
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59




60
61
62
63
64
65




66
67
68
69
70
71
72
73
74







75
76
77
78
79
80
81





82
83
84
85
86
87
88
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55




56
57
58
59
60
61




62
63
64
65
66
67







68
69
70
71
72
73
74
75
76





77
78
79
80
81
82
83
84
85
86
87
88







-
+


















-
+



















-
-
-
-
+
+
+
+


-
-
-
-
+
+
+
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+







# Usage:
#    phttpd::create port
#
#    port         Tcp port where the server listens
#
# Example:
#
#    # tclsh8.6
#    # tclsh9.0
#    % source phttpd.tcl
#    % phttpd::create 5000
#    % vwait forever
#
#    Starts the server on the port 5000. Also, look at the Httpd array
#    definition in the "phttpd" namespace declaration to find out
#    about other options you may put on the command line.
#
#    You can use: http://localhost:5000/monitor URL to test the
#    server functionality.
#
# Copyright (c) 2002 by Zoran Vasiljevic.
#
# See the file "license.terms" for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# -----------------------------------------------------------------------------

package require Tcl    8.5-
package require Thread 2.8-
package require thread 2.9-

#
# Modify the following in order to load the
# example Tcl implementation of threadpools.
# Per default, the C-level threadpool is used.
#

if {0} {
    eval [set TCL_TPOOL {source ../tpool/tpool.tcl}]
}

namespace eval phttpd {

    variable Httpd;           # Internal server state and config params
    variable MimeTypes;       # Cache of file-extension/mime-type
    variable HttpCodes;       # Portion of well-known http return codes
    variable ErrorPage;       # Format of error response page in html

    array set Httpd {
        -name  phttpd
        -vers  1.0
        -root  "."
        -index index.htm
	-name  phttpd
	-vers  1.0
	-root  "."
	-index index.htm
    }
    array set HttpCodes {
        400  "Bad Request"
        401  "Not Authorized"
        404  "Not Found"
        500  "Server error"
	400  "Bad Request"
	401  "Not Authorized"
	404  "Not Found"
	500  "Server error"
    }
    array set MimeTypes {
        {}   "text/plain"
        .txt "text/plain"
        .htm "text/html"
        .htm "text/html"
        .gif "image/gif"
        .jpg "image/jpeg"
        .png "image/png"
	{}   "text/plain"
	.txt "text/plain"
	.htm "text/html"
	.htm "text/html"
	.gif "image/gif"
	.jpg "image/jpeg"
	.png "image/png"
    }
    set ErrorPage {
        <title>Error: %1$s %2$s</title>
        <h1>%3$s</h1>
        <p>Problem in accessing "%4$s" on this server.</p>
        <hr>
        <i>%5$s/%6$s Server at %7$s Port %8$s</i>
	<title>Error: %1$s %2$s</title>
	<h1>%3$s</h1>
	<p>Problem in accessing "%4$s" on this server.</p>
	<hr>
	<i>%5$s/%6$s Server at %7$s Port %8$s</i>
    }
}

#
# phttpd::create --
#
#	Start the server by listening for connections on the desired port.
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116










117
118
119
120
121
122
123
124
125
126
127




128
129
130
131
132




133
134
135
136
137
138
139
100
101
102
103
104
105
106










107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123




124
125
126
127
128




129
130
131
132
133
134
135
136
137
138
139







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







-
-
-
-
+
+
+
+

-
-
-
-
+
+
+
+








proc phttpd::create {port args} {

    variable Httpd

    set arglen [llength $args]
    if {$arglen} {
        if {$arglen % 2} {
            error "wrong \# args, should be: key1 val1 key2 val2..."
        }
        set opts [array names Httpd]
        foreach {arg val} $args {
            if {[lsearch $opts $arg] == -1} {
                error "unknown option \"$arg\""
            }
            set Httpd($arg) $val
        }
	if {$arglen % 2} {
	    error "wrong \# args, should be: key1 val1 key2 val2..."
	}
	set opts [array names Httpd]
	foreach {arg val} $args {
	    if {[lsearch $opts $arg] < 0} {
		error "unknown option \"$arg\""
	    }
	    set Httpd($arg) $val
	}
    }

    #
    # Create thread pool with max 8 worker threads.
    #

    if {[info exists ::TCL_TPOOL] == 0} {
        #
        # Using the internal C-based thread pool
        #
        set initcmd "source ../phttpd/phttpd.tcl"
	#
	# Using the internal C-based thread pool
	#
	set initcmd "source ../phttpd/phttpd.tcl"
    } else {
        #
        # Using the Tcl-level hand-crafted thread pool
        #
        append initcmd "source ../phttpd/phttpd.tcl" \n $::TCL_TPOOL
	#
	# Using the Tcl-level hand-crafted thread pool
	#
	append initcmd "source ../phttpd/phttpd.tcl" \n $::TCL_TPOOL
    }

    set Httpd(tpid) [tpool::create -maxworkers 8 -initcmd $initcmd]

    #
    # Start the server on the given port. Note that we wrap
    # the actual accept with a helper after/idle callback.
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274














275
276

277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311


































312
313
314
315
316
317
318
254
255
256
257
258
259
260














261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

276
277


































278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318







-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








    variable Httpd
    variable data

    set data(sock) $sock

    while {1} {
        if {[catch {gets $data(sock) line} readCount] || [eof $data(sock)]} {
            return [Done]
        }
        if {![info exists data(state)]} {
            set pat {(POST|GET) ([^?]+)\??([^ ]*) HTTP/1\.[0-9]}
            if {[regexp $pat $line x data(proto) data(url) data(query)]} {
                set data(state) mime
                continue
            } else {
                Log error "bad request line: (%s)" $line
                Error 400
                return [Done]
            }
        }
	if {[catch {gets $data(sock) line} readCount] || [eof $data(sock)]} {
	    return [Done]
	}
	if {![info exists data(state)]} {
	    set pat {(POST|GET) ([^?]+)\??([^ ]*) HTTP/1\.[0-9]}
	    if {[regexp $pat $line x data(proto) data(url) data(query)]} {
		set data(state) mime
		continue
	    } else {
		Log error "bad request line: (%s)" $line
		Error 400
		return [Done]
	    }
	}

        # string compare $readCount 0 maps -1 to -1, 0 to 0, and > 0 to 1
	# string compare $readCount 0 maps -1 to -1, 0 to 0, and > 0 to 1

        set state [string compare $readCount 0],$data(state),$data(proto)
        switch -- $state {
            "0,mime,GET" - "0,query,POST" {
                Respond
                return [Done]
            }
            "0,mime,POST" {
                set data(state) query
                set data(query) ""
            }
            "1,mime,POST" - "1,mime,GET" {
                if [regexp {([^:]+):[   ]*(.*)}  $line dummy key value] {
                    set data(mime,[string tolower $key]) $value
                }
            }
            "1,query,POST" {
                append data(query) $line
                set clen $data(mime,content-length)
                if {($clen - [string length $data(query)]) <= 0} {
                    Respond
                    return [Done]
                }
            }
            default {
                if [eof $data(sock)] {
                    Log error "unexpected eof; client closed connection"
                    return [Done]
                } else {
                    Log error "bad http protocol state: %s" $state
                    Error 400
                    return [Done]
                }
            }
        }
	set state [string compare $readCount 0],$data(state),$data(proto)
	switch -- $state {
	    "0,mime,GET" - "0,query,POST" {
		Respond
		return [Done]
	    }
	    "0,mime,POST" {
		set data(state) query
		set data(query) ""
	    }
	    "1,mime,POST" - "1,mime,GET" {
		if [regexp {([^:]+):[   ]*(.*)}  $line dummy key value] {
		    set data(mime,[string tolower $key]) $value
		}
	    }
	    "1,query,POST" {
		append data(query) $line
		set clen $data(mime,content-length)
		if {($clen - [string length $data(query)]) <= 0} {
		    Respond
		    return [Done]
		}
	    }
	    default {
		if [eof $data(sock)] {
		    Log error "unexpected eof; client closed connection"
		    return [Done]
		} else {
		    Log error "bad http protocol state: %s" $state
		    Error 400
		    return [Done]
		}
	    }
	}
    }
}

#
# phttpd::Done --
#
#	Close the connection socket
331
332
333
334
335
336
337
338

339
340
341
342
343
344
345
331
332
333
334
335
336
337

338
339
340
341
342
343
344
345







-
+








    variable done
    variable data

    close $data(sock)

    if {[info exists data]} {
        unset data
	unset data
    }

    set done 1 ; # Releases the request thread (See Ticket procedure)
}

#
# phttpd::Respond --
358
359
360
361
362
363
364
365
366
367



368
369
370
371
372
373
374
375
376
377
378
379











380
381
382
383
384
385



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406




















407
408
409
410
411
412
413
358
359
360
361
362
363
364



365
366
367
368











369
370
371
372
373
374
375
376
377
378
379
380
381
382



383
384
385
386




















387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413







-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+



-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








proc phttpd::Respond {} {

    variable data

    if {[info commands $data(url)] == $data(url)} {

        #
        # Service URL-procedure
        #
	#
	# Service URL-procedure
	#

        if {[catch {
            puts $data(sock) "HTTP/1.0 200 OK"
            puts $data(sock) "Date: [Date]"
            puts $data(sock) "Last-Modified: [Date]"
        } err]} {
            Log error "client closed connection prematurely: %s" $err
            return
        }
        if {[catch {$data(url) data} err]} {
            Log error "%s: %s" $data(url) $err
        }
	if {[catch {
	    puts $data(sock) "HTTP/1.0 200 OK"
	    puts $data(sock) "Date: [Date]"
	    puts $data(sock) "Last-Modified: [Date]"
	} err]} {
	    Log error "client closed connection prematurely: %s" $err
	    return
	}
	if {[catch {$data(url) data} err]} {
	    Log error "%s: %s" $data(url) $err
	}

    } else {

        #
        # Service regular file path
        #
	#
	# Service regular file path
	#

        set mypath [Url2File $data(url)]
        if {![catch {open $mypath} i]} {
            if {[catch {
                puts $data(sock) "HTTP/1.0 200 OK"
                puts $data(sock) "Date: [Date]"
                puts $data(sock) "Last-Modified: [Date [file mtime $mypath]]"
                puts $data(sock) "Content-Type: [ContentType $mypath]"
                puts $data(sock) "Content-Length: [file size $mypath]"
                puts $data(sock) ""
                fconfigure $data(sock) -translation binary -blocking 0
                fconfigure $i          -translation binary
                fcopy $i $data(sock)
                close $i
            } err]} {
                Log error "client closed connection prematurely: %s" $err
            }
        } else {
            Log error "%s: %s" $data(url) $i
            Error 404
        }
	set mypath [Url2File $data(url)]
	if {![catch {open $mypath} i]} {
	    if {[catch {
		puts $data(sock) "HTTP/1.0 200 OK"
		puts $data(sock) "Date: [Date]"
		puts $data(sock) "Last-Modified: [Date [file mtime $mypath]]"
		puts $data(sock) "Content-Type: [ContentType $mypath]"
		puts $data(sock) "Content-Length: [file size $mypath]"
		puts $data(sock) ""
		fconfigure $data(sock) -translation binary -blocking 0
		fconfigure $i          -translation binary
		fcopy $i $data(sock)
		close $i
	    } err]} {
		Log error "client closed connection prematurely: %s" $err
	    }
	} else {
	    Log error "%s: %s" $data(url) $i
	    Error 404
	}
    }
}

#
# phttpd::ContentType --
#
#	Convert the file suffix into a mime type.
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471










472
473
474
475
476
477





478
479

480
481
482
483
484
485
486
455
456
457
458
459
460
461










462
463
464
465
466
467
468
469
470
471
472





473
474
475
476
477
478

479
480
481
482
483
484
485
486







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
+







    variable Httpd
    variable HttpCodes
    variable ErrorPage
    variable data

    append data(url) ""
    set msg \
        [format $ErrorPage     \
             $code             \
             $HttpCodes($code) \
             $HttpCodes($code) \
             $data(url)        \
             $Httpd(-name)     \
             $Httpd(-vers)     \
             [info hostname]   \
             80                \
            ]
	[format $ErrorPage     \
	     $code             \
	     $HttpCodes($code) \
	     $HttpCodes($code) \
	     $data(url)        \
	     $Httpd(-name)     \
	     $Httpd(-vers)     \
	     [info hostname]   \
	     80                \
	    ]
    if {[catch {
        puts $data(sock) "HTTP/1.0 $code $HttpCodes($code)"
        puts $data(sock) "Date: [Date]"
        puts $data(sock) "Content-Length: [string length $msg]"
        puts $data(sock) ""
        puts $data(sock) $msg
	puts $data(sock) "HTTP/1.0 $code $HttpCodes($code)"
	puts $data(sock) "Date: [Date]"
	puts $data(sock) "Content-Length: [string length $msg]"
	puts $data(sock) ""
	puts $data(sock) $msg
    } err]} {
        Log error "client closed connection prematurely: %s" $err
	Log error "client closed connection prematurely: %s" $err
    }
}

#
# phttpd::Date --
#
#	Generate a date string in HTTP format.
496
497
498
499
500
501
502
503

504
505
506
507
508
509
510
496
497
498
499
500
501
502

503
504
505
506
507
508
509
510







-
+







#

proc phttpd::Date {{seconds 0}} {

    # @c Generate a date string in HTTP format.

    if {$seconds == 0} {
        set seconds [clock seconds]
	set seconds [clock seconds]
    }
    clock format $seconds -format {%a, %d %b %Y %T %Z} -gmt 1
}

#
# phttpd::Log --
#
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568













569
570
571
572
573
574

575
576

577
578
579
580
581
582
583
549
550
551
552
553
554
555













556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573

574
575

576
577
578
579
580
581
582
583







-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+

-
+








    variable Httpd

    lappend pathlist $Httpd(-root)
    set level 0

    foreach part [split $url /] {
        set part [CgiMap $part]
        if [regexp {[:/]} $part] {
            return ""
        }
        switch -- $part {
            "." { }
            ".." {incr level -1}
            default {incr level}
        }
        if {$level <= 0} {
            return ""
        }
        lappend pathlist $part
	set part [CgiMap $part]
	if [regexp {[:/]} $part] {
	    return ""
	}
	switch -- $part {
	    "." { }
	    ".." {incr level -1}
	    default {incr level}
	}
	if {$level <= 0} {
	    return ""
	}
	lappend pathlist $part
    }

    set file [eval file join $pathlist]

    if {[file isdirectory $file]} {
        return [file join $file $Httpd(-index)]
	return [file join $file $Httpd(-index)]
    } else {
        return $file
	return $file
    }
}

#
# phttpd::CgiMap --
#
#	Decode url-encoded strings.
620
621
622
623
624
625
626
627

628
629
630
631
632
633
634
620
621
622
623
624
625
626

627
628
629
630
631
632
633
634







-
+








    set res [list]

    regsub -all {[&=]} $query { }    query
    regsub -all {  }   $query { {} } query; # Othewise we lose empty values

    foreach {key val} $query {
        lappend res [CgiMap $key] [CgiMap $val]
	lappend res [CgiMap $key] [CgiMap $val]
    }
    return $res
}

#
# monitor --
#
659
660
661
662
663
664
665
666
667
668



669
670
671
672
673
674
675


676
677
678
679
680
681
682
683
684
685
686
659
660
661
662
663
664
665



666
667
668
669
670
671
672
673


674
675
676
677
678
679
680
681
682
683
684
685
686







-
-
-
+
+
+





-
-
+
+











    puts $data(sock) ""

    #
    # Emit body
    #

    puts $data(sock) [subst {
        <html>
        <body>
        <h3>[clock format [clock seconds]]</h3>
	<html>
	<body>
	<h3>[clock format [clock seconds]]</h3>
    }]

    after 1 ; # Simulate blocking call

    puts $data(sock) [subst {
        </body>
        </html>
	</body>
	</html>
    }]
}

# EOF $RCSfile: phttpd.tcl,v $
# Emacs Setup Variables
# Local Variables:
# mode: Tcl
# indent-tabs-mode: nil
# tcl-basic-offset: 4
# End:

Changes to tcl/phttpd/uhttpd.tcl.
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24







-
+







# Usage:
#    phttpd::create port
#
#    port         Tcp port where the server listens
#
# Example:
#
#    # tclsh8.6
#    # tclsh9.0
#    % source uhttpd.tcl
#    % uhttpd::create 5000
#    % vwait forever
#
#    Starts the server on the port 5000. Also, look at the Httpd array
#    definition in the "uhttpd" namespace declaration to find out
#    about other options you may put on the command line.
37
38
39
40
41
42
43
44
45
46
47




48
49
50
51
52
53




54
55
56
57
58
59
60
61
62







63
64
65
66
67
68
69





70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90










91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

107
108

109
110
111
112
113
114
115
37
38
39
40
41
42
43




44
45
46
47
48
49




50
51
52
53
54
55







56
57
58
59
60
61
62
63
64





65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80










81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

106
107

108
109
110
111
112
113
114
115







-
-
-
-
+
+
+
+


-
-
-
-
+
+
+
+


-
-
-
-
-
-
-
+
+
+
+
+
+
+


-
-
-
-
-
+
+
+
+
+











-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+















-
+

-
+








    variable Httpd;           # Internal server state and config params
    variable MimeTypes;       # Cache of file-extension/mime-type
    variable HttpCodes;       # Portion of well-known http return codes
    variable ErrorPage;       # Format of error response page in html

    array set Httpd {
        -name    uhttpd
        -vers    1.0
        -root    ""
        -index   index.htm
	-name    uhttpd
	-vers    1.0
	-root    ""
	-index   index.htm
    }
    array set HttpCodes {
        400  "Bad Request"
        401  "Not Authorized"
        404  "Not Found"
        500  "Server error"
	400  "Bad Request"
	401  "Not Authorized"
	404  "Not Found"
	500  "Server error"
    }
    array set MimeTypes {
        {}   "text/plain"
        .txt "text/plain"
        .htm "text/html"
        .htm "text/html"
        .gif "image/gif"
        .jpg "image/jpeg"
        .png "image/png"
	{}   "text/plain"
	.txt "text/plain"
	.htm "text/html"
	.htm "text/html"
	.gif "image/gif"
	.jpg "image/jpeg"
	.png "image/png"
    }
    set ErrorPage {
        <title>Error: %1$s %2$s</title>
        <h1>%3$s</h1>
        <p>Problem in accessing "%4$s" on this server.</p>
        <hr>
        <i>%5$s/%6$s Server at %7$s Port %8$s</i>
	<title>Error: %1$s %2$s</title>
	<h1>%3$s</h1>
	<p>Problem in accessing "%4$s" on this server.</p>
	<hr>
	<i>%5$s/%6$s Server at %7$s Port %8$s</i>
    }
}

proc uhttpd::create {port args} {

    # @c Start the server by listening for connections on the desired port.

    variable Httpd
    set arglen [llength $args]

    if {$arglen} {
        if {$arglen % 2} {
            error "wrong \# arguments, should be: key1 val1 key2 val2..."
        }
        set opts [array names Httpd]
        foreach {arg val} $args {
            if {[lsearch $opts $arg] == -1} {
                error "unknown option \"$arg\""
            }
            set Httpd($arg) $val
        }
	if {$arglen % 2} {
	    error "wrong \# arguments, should be: key1 val1 key2 val2..."
	}
	set opts [array names Httpd]
	foreach {arg val} $args {
	    if {[lsearch $opts $arg] < 0} {
		error "unknown option \"$arg\""
	    }
	    set Httpd($arg) $val
	}
    }

    set Httpd(port) $port
    set Httpd(host) [info hostname]

    socket -server [namespace current]::Accept $port
}

proc uhttpd::respond {s status contype data {length 0}} {

    puts $s "HTTP/1.0 $status"
    puts $s "Date: [Date]"
    puts $s "Content-Type: $contype"

    if {$length} {
        puts $s "Content-Length: $length"
	puts $s "Content-Length: $length"
    } else {
        puts $s "Content-Length: [string length $data]"
	puts $s "Content-Length: [string length $data]"
    }

    puts $s ""
    puts $s $data
}

proc uhttpd::Accept {newsock ipaddr port} {
129
130
131
132
133
134
135
136

137
138
139


140
141
142
143
144
145
146
147
148
149








150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184





























185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207



208
209
210
211
212
213
214
215
216
217
218
219
220












221
222
223
224
225
226



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247




















248
249
250
251
252
253
254
129
130
131
132
133
134
135

136
137


138
139
140
141








142
143
144
145
146
147
148
149
150
151
152
153
154
155





























156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204



205
206
207
208












209
210
211
212
213
214
215
216
217
218
219
220
221
222
223



224
225
226
227




















228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254







-
+

-
-
+
+


-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+






-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




















-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+



-
-
-
+
+
+

-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








    # @c Read data from client

    variable Httpd
    upvar \#0 [namespace current]::Httpd$s data

    if {[catch {gets $s line} readCount] || [eof $s]} {
        return [Done $s]
	return [Done $s]
    }
    if {$readCount == -1} {
        return ;# Insufficient data on non-blocking socket !
    if {$readCount < 0} {
	return ;# Insufficient data on non-blocking socket !
    }
    if {![info exists data(state)]} {
        set pat {(POST|GET) ([^?]+)\??([^ ]*) HTTP/1\.[0-9]}
        if {[regexp $pat $line x data(proto) data(url) data(query)]} {
            return [set data(state) mime]
        } else {
            Log error "bad request line: %s" $line
            Error $s 400
            return [Done $s]
        }
	set pat {(POST|GET) ([^?]+)\??([^ ]*) HTTP/1\.[0-9]}
	if {[regexp $pat $line x data(proto) data(url) data(query)]} {
	    return [set data(state) mime]
	} else {
	    Log error "bad request line: %s" $line
	    Error $s 400
	    return [Done $s]
	}
    }

    # string compare $readCount 0 maps -1 to -1, 0 to 0, and > 0 to 1

    set state [string compare $readCount 0],$data(state),$data(proto)
    switch -- $state {
        "0,mime,GET" - "0,query,POST" {
            Respond $s
        }
        "0,mime,POST" {
            set data(state) query
            set data(query) ""
        }
        "1,mime,POST" - "1,mime,GET" {
            if [regexp {([^:]+):[   ]*(.*)}  $line dummy key value] {
                set data(mime,[string tolower $key]) $value
            }
        }
        "1,query,POST" {
            append data(query) $line
            set clen $data(mime,content-length)
            if {($clen - [string length $data(query)]) <= 0} {
                Respond $s
            }
        }
        default {
            if [eof $s] {
                Log error "unexpected eof; client closed connection"
                return [Done $s]
            } else {
                Log error "bad http protocol state: %s" $state
                Error $s 400
                return [Done $s]
            }
        }
	"0,mime,GET" - "0,query,POST" {
	    Respond $s
	}
	"0,mime,POST" {
	    set data(state) query
	    set data(query) ""
	}
	"1,mime,POST" - "1,mime,GET" {
	    if [regexp {([^:]+):[   ]*(.*)}  $line dummy key value] {
		set data(mime,[string tolower $key]) $value
	    }
	}
	"1,query,POST" {
	    append data(query) $line
	    set clen $data(mime,content-length)
	    if {($clen - [string length $data(query)]) <= 0} {
		Respond $s
	    }
	}
	default {
	    if [eof $s] {
		Log error "unexpected eof; client closed connection"
		return [Done $s]
	    } else {
		Log error "bad http protocol state: %s" $state
		Error $s 400
		return [Done $s]
	    }
	}
    }
}

proc uhttpd::Done {s} {

    # @c Close the connection socket and discard token

    close $s
    unset [namespace current]::Httpd$s
}

proc uhttpd::Respond {s} {

    # @c Respond to the query.

    variable Httpd
    upvar \#0 [namespace current]::Httpd$s data

    if {[uplevel \#0 info proc $data(url)] == $data(url)} {

        #
        # Service URL-procedure first
        #
	#
	# Service URL-procedure first
	#

        if {[catch {
            puts $s "HTTP/1.0 200 OK"
            puts $s "Date: [Date]"
            puts $s "Last-Modified: [Date]"
        } err]} {
            Log error "client closed connection prematurely: %s" $err
            return [Done $s]
        }
        set data(sock) $s
        if {[catch {$data(url) data} err]} {
            Log error "%s: %s" $data(url) $err
        }
	if {[catch {
	    puts $s "HTTP/1.0 200 OK"
	    puts $s "Date: [Date]"
	    puts $s "Last-Modified: [Date]"
	} err]} {
	    Log error "client closed connection prematurely: %s" $err
	    return [Done $s]
	}
	set data(sock) $s
	if {[catch {$data(url) data} err]} {
	    Log error "%s: %s" $data(url) $err
	}

    } else {

        #
        # Service regular file path next.
        #
	#
	# Service regular file path next.
	#

        set mypath [Url2File $data(url)]
        if {![catch {open $mypath} i]} {
            if {[catch {
                puts $s "HTTP/1.0 200 OK"
                puts $s "Date: [Date]"
                puts $s "Last-Modified: [Date [file mtime $mypath]]"
                puts $s "Content-Type: [ContentType $mypath]"
                puts $s "Content-Length: [file size $mypath]"
                puts $s ""
                fconfigure $s -translation binary -blocking 0
                fconfigure $i -translation binary
                fcopy $i $s
                close $i
            } err]} {
                Log error "client closed connection prematurely: %s" $err
            }
        } else {
            Log error "%s: %s" $data(url) $i
            Error $s 404
        }
	set mypath [Url2File $data(url)]
	if {![catch {open $mypath} i]} {
	    if {[catch {
		puts $s "HTTP/1.0 200 OK"
		puts $s "Date: [Date]"
		puts $s "Last-Modified: [Date [file mtime $mypath]]"
		puts $s "Content-Type: [ContentType $mypath]"
		puts $s "Content-Length: [file size $mypath]"
		puts $s ""
		fconfigure $s -translation binary -blocking 0
		fconfigure $i -translation binary
		fcopy $i $s
		close $i
	    } err]} {
		Log error "client closed connection prematurely: %s" $err
	    }
	} else {
	    Log error "%s: %s" $data(url) $i
	    Error $s 404
	}
    }

    Done $s
}

proc uhttpd::ContentType {path} {

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286










287
288
289
290
291
292





293
294

295
296
297
298
299
300
301
302
303

304
305
306
307
308
309
310
270
271
272
273
274
275
276










277
278
279
280
281
282
283
284
285
286
287





288
289
290
291
292
293

294
295
296
297
298
299
300
301
302

303
304
305
306
307
308
309
310







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
+
+
+

-
+








-
+







    variable HttpCodes
    variable ErrorPage

    upvar \#0 [namespace current]::Httpd$s data

    append data(url) ""
    set msg \
        [format $ErrorPage     \
             $code             \
             $HttpCodes($code) \
             $HttpCodes($code) \
             $data(url)        \
             $Httpd(-name)     \
             $Httpd(-vers)     \
             $Httpd(host)      \
             $Httpd(port)      \
            ]
	[format $ErrorPage     \
	     $code             \
	     $HttpCodes($code) \
	     $HttpCodes($code) \
	     $data(url)        \
	     $Httpd(-name)     \
	     $Httpd(-vers)     \
	     $Httpd(host)      \
	     $Httpd(port)      \
	    ]
    if {[catch {
        puts $s "HTTP/1.0 $code $HttpCodes($code)"
        puts $s "Date: [Date]"
        puts $s "Content-Length: [string length $msg]"
        puts $s ""
        puts $s $msg
	puts $s "HTTP/1.0 $code $HttpCodes($code)"
	puts $s "Date: [Date]"
	puts $s "Content-Length: [string length $msg]"
	puts $s ""
	puts $s $msg
    } err]} {
        Log error "client closed connection prematurely: %s" $err
	Log error "client closed connection prematurely: %s" $err
    }
}

proc uhttpd::Date {{seconds 0}} {

    # @c Generate a date string in HTTP format.

    if {$seconds == 0} {
        set seconds [clock seconds]
	set seconds [clock seconds]
    }
    clock format $seconds -format {%a, %d %b %Y %T %Z} -gmt 1
}

proc uhttpd::Log {reason format args} {

    # @c Log an httpd transaction.
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340













341
342
343
344
345
346

347
348

349
350
351
352
353
354
355
321
322
323
324
325
326
327













328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347

348
349
350
351
352
353
354
355







-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+





-
+

-
+








    variable Httpd

    lappend pathlist $Httpd(-root)
    set level 0

    foreach part [split $url /] {
        set part [CgiMap $part]
        if [regexp {[:/]} $part] {
            return ""
        }
        switch -- $part {
            "." { }
            ".." {incr level -1}
            default {incr level}
        }
        if {$level <= 0} {
            return ""
        }
        lappend pathlist $part
	set part [CgiMap $part]
	if [regexp {[:/]} $part] {
	    return ""
	}
	switch -- $part {
	    "." { }
	    ".." {incr level -1}
	    default {incr level}
	}
	if {$level <= 0} {
	    return ""
	}
	lappend pathlist $part
    }

    set file [eval file join $pathlist]

    if {[file isdirectory $file]} {
        return [file join $file $Httpd(-index)]
	return [file join $file $Httpd(-index)]
    } else {
        return $file
	return $file
    }
}

proc uhttpd::CgiMap {data} {

    # @c Decode url-encoded strings

366
367
368
369
370
371
372
373

374
375
376
377
378
379
380
366
367
368
369
370
371
372

373
374
375
376
377
378
379
380







-
+








    set res [list]

    regsub -all {[&=]} $query { }    query
    regsub -all {  }   $query { {} } query; # Othewise we lose empty values

    foreach {key val} $query {
        lappend res [CgiMap $key] [CgiMap $val]
	lappend res [CgiMap $key] [CgiMap $val]
    }
    return $res
}

proc /monitor {array} {

    upvar $array data ; # Holds the socket to remote client
389
390
391
392
393
394
395
396
397
398



399
400
401
402
403
404
405


406
407
408
409
410
411
412
413
414
415
416
389
390
391
392
393
394
395



396
397
398
399
400
401
402
403


404
405
406
407
408
409
410
411
412
413
414
415
416







-
-
-
+
+
+





-
-
+
+











    puts $data(sock) ""

    #
    # Emit body
    #

    puts $data(sock) [subst {
        <html>
        <body>
        <h3>[clock format [clock seconds]]</h3>
	<html>
	<body>
	<h3>[clock format [clock seconds]]</h3>
    }]

    after 1 ; # Simulate blocking call

    puts $data(sock) [subst {
        </body>
        </html>
	</body>
	</html>
    }]
}

# EOF $RCSfile: uhttpd.tcl,v $
# Emacs Setup Variables
# Local Variables:
# mode: Tcl
# indent-tabs-mode: nil
# tcl-basic-offset: 4
# End:

Changes to tcl/tpool/tpool.tcl.
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47




48
49
50
51
52
53
54
19
20
21
22
23
24
25

26

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42




43
44
45
46
47
48
49
50
51
52
53







-
+
-
















-
-
-
-
+
+
+
+







#
# Copyright (c) 2002 by Zoran Vasiljevic.
#
# See the file "license.terms" for information on usage and
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
# -----------------------------------------------------------------------------

package require Tcl    8.5-
package require thread 2.9-
package require Thread 2.5-
set thisScript [info script]

namespace eval tpool {

    variable afterevent "" ; # Idle timer event for worker threads
    variable result        ; # Stores result from the worker thread
    variable waiter        ; # Waits for an idle worker thread
    variable jobsdone      ; # Accumulates results from worker threads

    #
    # Create shared array with a single element.
    # It is used for automatic pool handles creation.
    #

    set ns [namespace current]
    tsv::lock $ns {
        if {[tsv::exists $ns count] == 0} {
            tsv::set $ns count 0
        }
        tsv::set $ns count -1
	if {[tsv::exists $ns count] == 0} {
	    tsv::set $ns count 0
	}
	tsv::set $ns count -1
    }
    variable thisScript [info script]
}

#
# tpool::create --
#
76
77
78
79
80
81
82
83
84
85



86
87
88
89
90
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108










109
110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126
127
128
129
130
131










132
133
134
135
136
137
138
139

140
141
142
143
144
145
146
75
76
77
78
79
80
81



82
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97










98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

117
118
119
120










121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145







-
-
-
+
+
+





-
+







-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+









-
+



-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







-
+







    variable thisScript

    #
    # Get next threadpool handle and create the pool array.
    #

    set usage "wrong \# args: should be \"[lindex [info level 1] 0]\
               ?-minworkers count? ?-maxworkers count?\
               ?-initcmd script? ?-exitcmd script?\
               ?-idletime seconds?\""
	       ?-minworkers count? ?-maxworkers count?\
	       ?-initcmd script? ?-exitcmd script?\
	       ?-idletime seconds?\""

    set ns [namespace current]
    set tpid [namespace tail $ns][tsv::incr $ns count]

    tsv::lock $tpid {
        tsv::set $tpid name $tpid
	tsv::set $tpid name $tpid
    }

    #
    # Setup default pool data.
    #

    tsv::array set $tpid {
         thrworkers  ""
         thrwaiters  ""
         jobcounter  0
         refcounter  0
         numworkers  0
        -minworkers  0
        -maxworkers  4
        -idletime    0
        -initcmd    ""
        -exitcmd    ""
	 thrworkers  ""
	 thrwaiters  ""
	 jobcounter  0
	 refcounter  0
	 numworkers  0
	-minworkers  0
	-maxworkers  4
	-idletime    0
	-initcmd    ""
	-exitcmd    ""
    }

    tsv::set $tpid -initcmd  "source $thisScript"

    #
    # Override with user-supplied data
    #

    if {[llength $args] % 2} {
        error $usage
	error $usage
    }

    foreach {arg val} $args {
        switch -- $arg {
            -minworkers -
            -maxworkers {tsv::set $tpid $arg $val}
            -idletime   {tsv::set $tpid $arg [expr {$val*1000}]}
            -initcmd    {tsv::append $tpid $arg \n $val}
            -exitcmd    {tsv::append $tpid $arg \n $val}
            default {
                error $usage
            }
        }
	switch -- $arg {
	    -minworkers -
	    -maxworkers {tsv::set $tpid $arg $val}
	    -idletime   {tsv::set $tpid $arg [expr {$val*1000}]}
	    -initcmd    {tsv::append $tpid $arg \n $val}
	    -exitcmd    {tsv::append $tpid $arg \n $val}
	    default {
		error $usage
	    }
	}
    }

    #
    # Start initial (minimum) number of worker threads.
    #

    for {set ii 0} {$ii < [tsv::set $tpid -minworkers]} {incr ii} {
        Worker $tpid
	Worker $tpid
    }

    return $tpid
}

#
# tpool::names --
194
195
196
197
198
199
200
201

202
203
204
205
206



207
208
209
210
211
212
213






214
215

216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239













240
241
242
243
244
245
246
247
248


249
250
251


252
253
254
255
256
257
258
193
194
195
196
197
198
199

200
201
202



203
204
205
206






207
208
209
210
211
212
213

214
215
216
217
218
219
220
221
222
223
224
225













226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245


246
247
248


249
250
251
252
253
254
255
256
257







-
+


-
-
-
+
+
+

-
-
-
-
-
-
+
+
+
+
+
+

-
+











-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+







-
-
+
+

-
-
+
+








    #
    # Parse command arguments.
    #

    set ns [namespace current]
    set usage "wrong \# args: should be \"[lindex [info level 1] 0]\
               ?-detached? tpoolId script\""
	       ?-detached? tpoolId script\""

    if {[llength $args] == 2} {
        set detached 0
        set tpid [lindex $args 0]
        set cmd  [lindex $args 1]
	set detached 0
	set tpid [lindex $args 0]
	set cmd  [lindex $args 1]
    } elseif {[llength $args] == 3} {
        if {[lindex $args 0] != "-detached"} {
            error $usage
        }
        set detached 1
        set tpid [lindex $args 1]
        set cmd  [lindex $args 2]
	if {[lindex $args 0] != "-detached"} {
	    error $usage
	}
	set detached 1
	set tpid [lindex $args 1]
	set cmd  [lindex $args 2]
    } else {
        error $usage
	error $usage
    }

    #
    # Find idle (or create new) worker thread. This is relatively
    # a complex issue, since we must honour the limits about number
    # of allowed worker threads imposed to us by the caller.
    #

    set tid ""

    while {$tid == ""} {
        tsv::lock $tpid {
            set tid [tsv::lpop $tpid thrworkers]
            if {$tid == "" || [catch {thread::preserve $tid}]} {
                set tid ""
                tsv::lpush $tpid thrwaiters [thread::id] end
                if {[tsv::set $tpid numworkers]<[tsv::set $tpid -maxworkers]} {
                    Worker $tpid
                }
            }
        }
        if {$tid == ""} {
            vwait ${ns}::waiter
        }
	tsv::lock $tpid {
	    set tid [tsv::lpop $tpid thrworkers]
	    if {$tid == "" || [catch {thread::preserve $tid}]} {
		set tid ""
		tsv::lpush $tpid thrwaiters [thread::id] end
		if {[tsv::set $tpid numworkers]<[tsv::set $tpid -maxworkers]} {
		    Worker $tpid
		}
	    }
	}
	if {$tid == ""} {
	    vwait ${ns}::waiter
	}
    }

    #
    # Post the command to the worker thread
    #

    if {$detached} {
        set j ""
        thread::send -async $tid [list ${ns}::Run $tpid 0 $cmd]
	set j ""
	thread::send -async $tid [list ${ns}::Run $tpid 0 $cmd]
    } else {
        set j [tsv::incr $tpid jobcounter]
        thread::send -async $tid [list ${ns}::Run $tpid $j $cmd] ${ns}::result
	set j [tsv::incr $tpid jobcounter]
	thread::send -async $tid [list ${ns}::Run $tpid $j $cmd] ${ns}::result
    }

    variable jobsdone
    set jobsdone($j) ""

    return $j
}
279
280
281
282
283
284
285
286

287
288
289
290
291
292
293
294
295
296
297
298
299
300








301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317















318
319
320
321
322
323
324
278
279
280
281
282
283
284

285
286
287
288
289
290
291








292
293
294
295
296
297
298
299
300
301















302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323







-
+






-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+


-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








proc tpool::wait {tpid jobList {jobLeft ""}} {

    variable result
    variable jobsdone

    if {$jobLeft != ""} {
        upvar $jobLeft jobleft
	upvar $jobLeft jobleft
    }

    set retlist ""
    set jobleft ""

    foreach j $jobList {
        if {[info exists jobsdone($j)] == 0} {
            continue ; # Ignore (skip) bogus job ids
        }
        if {$jobsdone($j) != ""} {
            lappend retlist $j
        } else {
            lappend jobleft $j
        }
	if {[info exists jobsdone($j)] == 0} {
	    continue ; # Ignore (skip) bogus job ids
	}
	if {$jobsdone($j) != ""} {
	    lappend retlist $j
	} else {
	    lappend jobleft $j
	}
    }
    if {[llength $retlist] == 0 && [llength $jobList]} {
        #
        # No jobs found; wait for the first one to get ready.
        #
        set jobleft $jobList
        while {1} {
            vwait [namespace current]::result
            set doneid [lindex $result 0]
            set jobsdone($doneid) $result
            if {[lsearch $jobList $doneid] >= 0} {
                lappend retlist $doneid
                set x [lsearch $jobleft $doneid]
                set jobleft [lreplace $jobleft $x $x]
                break
            }
        }
	#
	# No jobs found; wait for the first one to get ready.
	#
	set jobleft $jobList
	while {1} {
	    vwait [namespace current]::result
	    set doneid [lindex $result 0]
	    set jobsdone($doneid) $result
	    if {[lsearch $jobList $doneid] >= 0} {
		lappend retlist $doneid
		set x [lsearch $jobleft $doneid]
		set jobleft [lreplace $jobleft $x $x]
		break
	    }
	}
    }

    return $retlist
}

#
# tpool::get --
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
337
338
339
340
341
342
343

344
345
346
347
348
349
350
351







-
+







#

proc tpool::get {tpid jobid} {

    variable jobsdone

    if {[lindex $jobsdone($jobid) 1] != 0} {
        eval error [lrange $jobsdone($jobid) 2 end]
	eval error [lrange $jobsdone($jobid) 2 end]
    }

    return [lindex $jobsdone($jobid) 2]
}

#
# tpool::preserve --
384
385
386
387
388
389
390
391
392
393
394
395
396
397







398
399
400
401
402
403
404
383
384
385
386
387
388
389







390
391
392
393
394
395
396
397
398
399
400
401
402
403







-
-
-
-
-
-
-
+
+
+
+
+
+
+







# Results:
#   Current number of threadpool reservations.
#

proc tpool::release {tpid} {

    tsv::lock $tpid {
        if {[tsv::incr $tpid refcounter -1] <= 0} {
            # Release all workers threads
            foreach t [tsv::set $tpid thrworkers] {
                thread::release -wait $t
            }
            tsv::unset $tpid ; # This is not an error; it works!
        }
	if {[tsv::incr $tpid refcounter -1] <= 0} {
	    # Release all workers threads
	    foreach t [tsv::set $tpid thrworkers] {
		thread::release -wait $t
	    }
	    tsv::unset $tpid ; # This is not an error; it works!
	}
    }
}

#
# Private procedures, not a part of the threadpool API.
#

434
435
436
437
438
439
440
441
442
443



444
445
446
447
448
449
450
433
434
435
436
437
438
439



440
441
442
443
444
445
446
447
448
449







-
-
-
+
+
+








    #
    # Signalize waiter threads if any
    #

    set waiter [tsv::lpop $tpid thrwaiters]
    if {$waiter != ""} {
        thread::send -async $waiter [subst {
            set [namespace current]::waiter 1
        }]
	thread::send -async $waiter [subst {
	    set [namespace current]::waiter 1
	}]
    }
}

#
# tpool::Timer --
#
#   This procedure should be executed within the worker thread only.
459
460
461
462
463
464
465
466

467
468
469
470
471
472
473






474
475
476
477
478
479
480
481
482
483
484
485











486
487
488
489
490
491
492
458
459
460
461
462
463
464

465
466






467
468
469
470
471
472
473











474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491







-
+

-
-
-
-
-
-
+
+
+
+
+
+

-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+







# Results:
#   None.
#

proc tpool::Timer {tpid} {

    tsv::lock $tpid {
        if {[tsv::set $tpid  numworkers] > [tsv::set $tpid -minworkers]} {
	if {[tsv::set $tpid  numworkers] > [tsv::set $tpid -minworkers]} {

            #
            # We have more workers than needed, so kill this one.
            # We first splice ourselves from the list of active
            # workers, adjust the number of workers and release
            # this thread, which may exit eventually.
            #
	    #
	    # We have more workers than needed, so kill this one.
	    # We first splice ourselves from the list of active
	    # workers, adjust the number of workers and release
	    # this thread, which may exit eventually.
	    #

            set x [tsv::lsearch $tpid thrworkers [thread::id]]
            if {$x >= 0} {
                tsv::lreplace $tpid thrworkers $x $x
                tsv::incr $tpid numworkers -1
                set exitcmd [tsv::set $tpid -exitcmd]
                if {$exitcmd != ""} {
                    catch {eval $exitcmd}
                }
                thread::release
            }
        }
	    set x [tsv::lsearch $tpid thrworkers [thread::id]]
	    if {$x >= 0} {
		tsv::lreplace $tpid thrworkers $x $x
		tsv::incr $tpid numworkers -1
		set exitcmd [tsv::set $tpid -exitcmd]
		if {$exitcmd != ""} {
		    catch {eval $exitcmd}
		}
		thread::release
	    }
	}
    }
}

#
# tpool::Run --
#
#   This procedure should be executed within the worker thread only.
508
509
510
511
512
513
514
515

516
517
518
519
520
521
522
523
524

525
526

527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543







544
545
546
547
548
549
550
551
552
553

554
555
556
557
558
559
560
561
562
563



564
565
566
567
568
569
570
507
508
509
510
511
512
513

514
515
516
517
518
519
520
521
522

523
524

525
526
527
528
529
530
531
532
533
534
535







536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551

552
553
554
555
556
557
558
559



560
561
562
563
564
565
566
567
568
569







-
+








-
+

-
+










-
-
-
-
-
-
-
+
+
+
+
+
+
+









-
+







-
-
-
+
+
+








    #
    # Cancel the idle timer callback, if any.
    #

    variable afterevent
    if {$afterevent != ""} {
        after cancel $afterevent
	after cancel $afterevent
    }

    #
    # Evaluate passed command and build the result list.
    #

    set code [catch {uplevel \#0 $cmd} ret]
    if {$code == 0} {
        set res [list $jid 0 $ret]
	set res [list $jid 0 $ret]
    } else {
        set res [list $jid $code $ret $::errorInfo $::errorCode]
	set res [list $jid $code $ret $::errorInfo $::errorCode]
    }

    #
    # Check to see if any caller is waiting to be serviced.
    # If yes, kick it out of the waiting state.
    #

    set ns [namespace current]

    tsv::lock $tpid {
        tsv::lpush $tpid thrworkers [thread::id]
        set waiter [tsv::lpop $tpid thrwaiters]
        if {$waiter != ""} {
            thread::send -async $waiter [subst {
                set ${ns}::waiter 1
            }]
        }
	tsv::lpush $tpid thrworkers [thread::id]
	set waiter [tsv::lpop $tpid thrwaiters]
	if {$waiter != ""} {
	    thread::send -async $waiter [subst {
		set ${ns}::waiter 1
	    }]
	}
    }

    #
    # Release the thread. If this turns out to be
    # the last refcount held, don't bother to do
    # any more work, since thread will soon exit.
    #

    if {[thread::release] <= 0} {
        return $res
	return $res
    }

    #
    # Register the idle timer again.
    #

    if {[set idle [tsv::set $tpid -idletime]]} {
        set afterevent [after $idle [subst {
            ${ns}::Timer $tpid
        }]]
	set afterevent [after $idle [subst {
	    ${ns}::Timer $tpid
	}]]
    }

    return $res
}

# EOF $RCSfile: tpool.tcl,v $

Changes to tests/all.tcl.
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19











-
+







# all.tcl --
#
# This file contains a top-level script to run all of the Tcl
# tests.  Execute it by invoking "source all.test" when running tcltest
# in this directory.
#
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.

package require tcltest
::tcltest::loadTestedCommands
package require Thread
package require -exact thread 3.0.2

set ::tcltest::testSingleFile false
set ::tcltest::testsDirectory [file dir [info script]]

# We need to ensure that the testsDirectory is absolute
::tcltest::normalizePath ::tcltest::testsDirectory

35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
58
59
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49

50
51
52
53
54
55
56
57
58
59







-
+







-
+










set timeCmd {clock format [clock seconds]}
puts stdout "Tests began at [eval $timeCmd]"

# These tests need to know which is the main thread
set ::tcltest::mainThread [thread::id]

puts stdout "Thread [package provide Thread]"
puts stdout "thread [package provide thread]"
puts stdout "Mainthread id is $::tcltest::mainThread"

# Source each of the specified tests
foreach file [lsort [::tcltest::getMatchingFiles]] {
    set tail [file tail $file]
    puts stdout $tail
    if {[catch {source $file} msg]} {
        puts stdout $msg
	puts stdout $msg
    }
}

# Cleanup
puts stdout "\nTests ended at [eval $timeCmd]"
::tcltest::cleanupTests 1

return

Changes to tests/store-load.tcl.
1
2
3
4

5
6
7
8
9
10

11
12
13


14
15

16
17
18
19
20
21
22
1
2
3

4
5
6
7
8
9

10
11


12
13
14

15
16
17
18
19
20
21
22



-
+





-
+

-
-
+
+

-
+







#!/usr/bin/env tclsh

lappend auto_path .
package require Thread
package require thread

if {[llength $argv] != 3} {
    puts "Usage: $argv0 handle path times"
    puts {
    handle
        A persistent storage handle (see [tsv::array bind] manpage).
	A persistent storage handle (see [tsv::array bind] manpage).
    path
        The path to file containing lines in the form of "key<tab>val", where
        key is a single-word and val is everyting else.
	The path to file containing lines in the form of "key<tab>val", where
	key is a single-word and val is everyting else.
    times
        The number of times to reload the data from persistent storage.
	The number of times to reload the data from persistent storage.

    This script reads lines of data from <path> and stores them into the
    persistent storage described by <handle>. Values for duplicate keys are
    handled as a lists. The persistent storage engine is then stress-tested by
    reloading the whole store <times> times.
    }
    exit 1
31
32
33
34
35
36
37
38

39
40
41
42


43
44
45
46
47
48
49

50
51
52
53
54
55
56
31
32
33
34
35
36
37

38
39
40


41
42
43
44
45
46
47
48

49
50
51
52
53
54
55
56







-
+


-
-
+
+






-
+







### Load and store tab-separated values
tsv::array bind a $handle
set fd [open $path r]
set start [clock milliseconds]
set pairs 0
while {[gets $fd line] >  0} {
    if {[string index $line 0] eq {#}} {
        continue
	continue
    }
    set tab [string first {	} $line]
    if {$tab == -1} {
        continue
    if {$tab < 0} {
	continue
    }

    set k [string range $line 0 $tab-1]
    set v [string range $line $tab+1 end]

    if {![tsv::exists a $k]} {
        incr pairs
	incr pairs
    }

    tsv::lappend a $k $v
}
puts "Stored $pairs pairs in [expr {[clock milliseconds]-$start}] milliseconds"

tsv::array unbind a
Changes to tests/thread.test.
10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31





32
33
34































35
36
37
38
39
40
41


42
43
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69







70
71
72
73
74
75
76
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26





27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70


71
72



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91







92
93
94
95
96
97
98
99
100
101
102
103
104
105







-
+









-
-
-
-
-
+
+
+
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+





-
-
+
+
-
-
-
+


















-
-
-
-
-
-
-
+
+
+
+
+
+
+







#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

package require tcltest
namespace import ::tcltest::*
tcltest::loadTestedCommands
package require Thread
package require thread

tcltest::testConstraint chanTransfer               \
    [expr {$::tcl_platform(platform) == "unix"}]

set dummy [makeFile dummyForTransfer dummyForTransfer]
set tcltest::mainThread [thread::id]

proc ThreadReap {} {
    while {[llength [thread::names]] > 1} {
        foreach tid [thread::names] {
            if {$tid != $::tcltest::mainThread} {
                catch {thread::release -wait $tid}
            }
        }
	foreach tid [thread::names] {
	    if {$tid != $::tcltest::mainThread} {
		catch {thread::release -wait $tid}
	    }
	}
    }
    llength [thread::names]
}

test thread-1.11 {no segfault on 2nd interpreter, bug [d4ba38d00d06ebba]} -body {
    # This behavior needs to be covered in a separate shell, because it doesn't expect
    # any other thread invocation before 2nd interpreter gets the thread::id (TSD),
    # but test-suite calls thread::id command (tcltest, all.tcl and thread.test):
    set fd [open [list |[info nameofexecutable] << [string map [list {$$load} [tcltest::loadScript]] {
	$$load; package require thread
	interp create ci
	set l {}
	ci eval {$$load; package require thread; thread::id}
	thread::send -async [thread::id] {lappend l ev-1}; update
	interp delete ci
	thread::send -async [thread::id] {lappend l ev-2}; update; # no SF here
	puts $l
    }] 2>@stderr] r]
    gets $fd
} -cleanup {
    catch { close $fd }
} -result {ev-1 ev-2}

test thread-1.12 {no events in 2nd interpreter, bug [d4ba38d00d06ebba]} -setup {
    interp create ci
} -body {
    set l {}
    thread::send -async [thread::id] {lappend l ev-1}; update
    ci eval {package require tcltest; tcltest::loadTestedCommands; package require thread}
    thread::send -async [thread::id] {lappend l ev-2}; update
    set l
} -cleanup {
    interp delete ci
} -result {ev-1 ev-2}

test thread-2.0 {no global thread command} {
    info commands thread
} {}

test thread-2.84 {thread subcommands} {
    set cmds [info commands thread::*]
test thread-2.84 {thread subcommands} -body {
    lsort [info commands thread::*]
    set idx [lsearch -exact $cmds ::thread::cancel]
    lsort [lreplace $cmds $idx $idx]
} {::thread::attach ::thread::broadcast ::thread::cond ::thread::configure ::thread::create ::thread::detach ::thread::errorproc ::thread::eval ::thread::exists ::thread::exit ::thread::id ::thread::join ::thread::mutex ::thread::names ::thread::preserve ::thread::release ::thread::rwmutex ::thread::send ::thread::transfer ::thread::unwind ::thread::wait}
} -match glob -result {::thread::attach ::thread::broadcast *::thread::cond ::thread::configure ::thread::create ::thread::detach ::thread::errorproc ::thread::eval ::thread::exists ::thread::exit ::thread::id ::thread::join ::thread::mutex ::thread::names ::thread::preserve ::thread::release ::thread::rwmutex ::thread::send ::thread::transfer ::thread::unwind ::thread::wait}

test thread-3.0 {thread::names initial thread list} {
    list [ThreadReap] [llength [thread::names]]
} {1 1}

test thread-4.0 {thread::create: create server thread} {
    ThreadReap
    set tid [thread::create]
    update
    set l [llength [thread::names]]
    ThreadReap
    set l
} {2}

test thread-4.1 {thread::create: create one shot thread} {
    ThreadReap
    thread::create {set x 5}
    foreach try {0 1 2 4 5 6} {
        # Try various ways to yield
        update
        after 10
        set l [llength [thread::names]]
        if {$l == 1} {
            break
        }
	# Try various ways to yield
	update
	after 10
	set l [llength [thread::names]]
	if {$l == 1} {
	    break
	}
    }
    ThreadReap
    set l
} {1}

test thread-4.2 {thread::create - create preservable thread} {
    ThreadReap
340
341
342
343
344
345
346
347

348
349
350
351
352
353

354
355
356
357
358
359
360
369
370
371
372
373
374
375

376
377
378
379
380
381

382
383
384
385
386
387
388
389







-
+





-
+







    set five
} {5}

test thread-13.0 {thread::broadcast} {
    ThreadReap
    catch {unset tids}
    foreach i {1 2 3 4} {
        lappend tids [thread::create]
	lappend tids [thread::create]
    }
    thread::broadcast {set x 5}
    update
    catch {unset r}
    foreach tid $tids {
        lappend r [thread::send $tid {if {[info exists x]} {set x}}]
	lappend r [thread::send $tid {if {[info exists x]} {set x}}]
    }
    ThreadReap
    set r
} {5 5 5 5}

test thread-13.1 {thread::broadcast no args} {
    set c [catch {thread::broadcast} msg]
484
485
486
487
488
489
490
491
492
493



494
495
496
497
498
499
500
513
514
515
516
517
518
519



520
521
522
523
524
525
526
527
528
529







-
-
-
+
+
+







    set new [thread::errorproc]
} {ThreadError}

test thread-16.2 {thread::errorproc - async reporting} {
    set etid ""
    set emsg ""
    proc myerrproc {tid msg} {
        global etid emsg
        set etid $tid
        set emsg $msg
	global etid emsg
	set etid $tid
	set emsg $msg
    }
    ThreadReap
    thread::errorproc myerrproc
    set tid [thread::create]
    update
    after 10
    thread::send -async $tid {set x}
528
529
530
531
532
533
534
535
536
537
538
539
540
541







542
543
544
545
546
547
548
557
558
559
560
561
562
563







564
565
566
567
568
569
570
571
572
573
574
575
576
577







-
-
-
-
-
-
-
+
+
+
+
+
+
+







    close $file
    ThreadReap
    set msg
} {transfer failed: target thread died}

test thread-17.3 {thread::transfer - clearing of fileevents} {chanTransfer} {
    proc _HandleIt_ {} {
        global gotEvents tid file
        if {$gotEvents == 0} {
            thread::transfer $tid $file
            # From now on no events should be delivered anymore,
            # restricting the end value to 1
        }
        incr gotEvents
	global gotEvents tid file
	if {$gotEvents == 0} {
	    thread::transfer $tid $file
	    # From now on no events should be delivered anymore,
	    # restricting the end value to 1
	}
	incr gotEvents
    }
    ThreadReap
    set tid [thread::create]
    set file [open $dummy r]
    set gotEvents 0
    fileevent $file readable _HandleIt_
    vwait gotEvents
898
899
900
901
902
903
904
905
906
907



908
909
910
911
912
913
914
927
928
929
930
931
932
933



934
935
936
937
938
939
940
941
942
943







-
-
-
+
+
+







} {1 {mutex is in use}}

test thread-19.12 {thread::mutex - lock exclusive between threads} {
    ThreadReap
    set tid [thread::create]
    set emutex [thread::mutex create]
    thread::send -async $tid [subst {
        thread::mutex lock $emutex
        after 2000
        thread::mutex unlock $emutex
	thread::mutex lock $emutex
	after 2000
	thread::mutex unlock $emutex
    }]
    update
    after 10
    set time1 [clock seconds]
    thread::mutex lock $emutex
    set time2 [clock seconds]
    thread::mutex unlock $emutex
983
984
985
986
987
988
989
990
991
992



993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012



1013
1014
1015
1016
1017
1018
1019
1012
1013
1014
1015
1016
1017
1018



1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048







-
-
-
+
+
+

















-
-
-
+
+
+







} {1 {mutex is in use}}

test thread-20.8 {thread::rwmutex - readlock mutex} {
    ThreadReap
    set tid [thread::create]
    set rwmutex [thread::rwmutex create]
    thread::send -async $tid [subst {
        thread::rwmutex rlock $rwmutex
        after 1000
        thread::rwmutex unlock $rwmutex
	thread::rwmutex rlock $rwmutex
	after 1000
	thread::rwmutex unlock $rwmutex
    }]
    update
    after 10
    set time1 [clock seconds]
    thread::rwmutex rlock $rwmutex
    set time2 [clock seconds]
    thread::rwmutex unlock $rwmutex
    ThreadReap
    thread::rwmutex destroy $rwmutex
    expr {($time2 - $time1) < 1}
} {1}

test thread-20.9 {thread::rwmutex - writelock mutex} {
    ThreadReap
    set tid [thread::create]
    set rwmutex [thread::rwmutex create]
    thread::send -async $tid [subst {
        thread::rwmutex wlock $rwmutex
        after 2000
        thread::rwmutex unlock $rwmutex
	thread::rwmutex wlock $rwmutex
	after 2000
	thread::rwmutex unlock $rwmutex
    }]
    update
    after 10
    set time1 [clock seconds]
    thread::rwmutex rlock $rwmutex
    set time2 [clock seconds]
    thread::rwmutex unlock $rwmutex
1140
1141
1142
1143
1144
1145
1146
1147

1148
1149
1150
1151
1152
1153
1154
1169
1170
1171
1172
1173
1174
1175

1176
1177
1178
1179
1180
1181
1182
1183







-
+







test thread-21.12 {thread::cond - wait locked mutex from wrong thread} {
    ThreadReap
    set tid [thread::create]
    set emutex [thread::mutex create]
    set cond [thread::cond create]
    thread::mutex lock $emutex
    thread::send -async $tid [subst -nocommands {
        set code [catch {thread::cond wait $cond $emutex 1000} result]
	set code [catch {thread::cond wait $cond $emutex 1000} result]
    }]
    update
    after 20
    thread::cond notify $cond
    set c [thread::send $tid "set code"]
    set r [thread::send $tid "set result"]
    ThreadReap
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188




1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210



1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230





1231
1232
1233
1234
1235
1236





1237
1238
1239
1207
1208
1209
1210
1211
1212
1213




1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236



1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254





1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273







-
-
-
-
+
+
+
+



















-
-
-
+
+
+















-
-
-
-
-
+
+
+
+
+






+
+
+
+
+




test thread-21.15 {thread::cond - regular timed wait} {
    ThreadReap
    set tid [thread::create]
    set emutex [thread::mutex create]
    set cond [thread::cond create]
    thread::send -async $tid [subst {
        thread::mutex lock $emutex
        thread::cond wait $cond $emutex 2000
        thread::mutex unlock $emutex
        set test 1
	thread::mutex lock $emutex
	thread::cond wait $cond $emutex 2000
	thread::mutex unlock $emutex
	set test 1
    }]
    update
    after 10
    set time1 [clock seconds]
    thread::cond notify $cond
    set c [thread::send $tid "info exists test"]
    set time2 [clock seconds]
    ThreadReap
    thread::mutex destroy $emutex
    thread::cond destroy $cond
    list $c [expr {($time2 - $time1) < 2}]
} {1 1}

test thread-21.16 {thread::cond - delete waited variable} {
    ThreadReap
    set tid [thread::create]
    set emutex [thread::mutex create]
    set cond [thread::cond create]
    thread::send -async $tid [subst {
        thread::mutex lock $emutex
        thread::cond wait $cond $emutex 500
        thread::mutex unlock $emutex
	thread::mutex lock $emutex
	thread::cond wait $cond $emutex 500
	thread::mutex unlock $emutex
    }]
    update
    after 10
    set c1 [catch {thread::cond destroy $cond} r1]
    thread::cond notify $cond
    after 1000
    set c2 [catch {thread::cond destroy $cond} r2]
    ThreadReap
    thread::mutex destroy $emutex
    list $c1 $c2 $r1 $r2
} {1 0 {condition variable is in use} {}}

test thread-22.1  {thread::send -command} {
    ThreadReap
    after 0 [list ::apply [list {} {
        set tid [thread::create]
        thread::send -command $tid {lindex hello} [list ::apply [list args {
            variable result
            set result $args
        } [namespace current]]]
	set tid [thread::create]
	thread::send -command $tid {lindex hello} [list ::apply [list args {
	    variable result
	    set result $args
	} [namespace current]]]
    } [namespace current]]]
    vwait [namespace current]::result
    ThreadReap
    set result
} hello

test thread-bug-f32864afe3 {Hang in thread::eval -lock} -body {
    set mu [thread::mutex create]
    thread::eval -lock $mu {}
    thread::mutex destroy $mu ; # <- Bug f32864af hang
} -result {}

removeFile dummyForTransfer
::tcltest::cleanupTests
Changes to tests/tkt-84be1b5a73.test.
1
2
3
4

5
6
7
8
9
10
11
12
13


14
15
16
17
18

19
20
21
22

23
24
25
1
2
3

4
5
6
7
8
9
10
11


12
13
14
15
16
17

18
19
20
21

22
23
24
25



-
+







-
-
+
+




-
+



-
+



package require tcltest
namespace import ::tcltest::*
tcltest::loadTestedCommands
package require Thread
package require thread

# This test used to segfault before commit f4c95731c0.
test tkt-84be1b5a73 {Ticket 84be1b5a73} -body {
    set t [thread::create]
    set resultvar() {}

    trace add variable resultvar() write {
        unset -nocomplain resultvar()
        list}
	unset -nocomplain resultvar()
	list}

    proc errorproc {tid einfo} {}
    thread::errorproc errorproc
    thread::send -async $t {
        error ""
	error ""
    } resultvar()

    after 1000 {
        set forever 1
	set forever 1
    }
    vwait forever
} -returnCodes 0
Changes to tests/tsv.test.
1
2
3
4

5
6
7
8
9
10
11
12
13
14
15
16
17
18

19
20
21

22
23
24
25
26
27

28
29

30
31

32
33
34
35
36
37

38
39

40
41
42
43
44
45
46
47

48
49

50
51

52
53
54
55
56
57

58
59

60
61

62
63
64
65
66
67

68
69

70
71

72
73
74
75
76
77

78
79

80
81

82
83
84
85
86
87

88
89

90
91

92
93
94
95
96
97

98
99

100
101

102
103
104
105





106
107
1
2
3

4
5
6
7
8
9
10
11
12
13
14
15
16
17

18
19
20

21
22
23
24
25
26

27
28

29
30

31
32
33
34
35
36

37
38

39
40
41
42
43
44
45
46

47
48

49
50

51
52
53
54
55
56

57
58

59
60

61
62
63
64
65
66

67
68

69
70

71
72
73
74
75
76

77
78

79
80

81
82
83
84
85
86

87
88

89
90

91
92
93
94
95
96

97
98

99
100

101
102
103
104
105
106
107
108
109
110
111
112



-
+













-
+


-
+





-
+

-
+

-
+





-
+

-
+







-
+

-
+

-
+





-
+

-
+

-
+





-
+

-
+

-
+





-
+

-
+

-
+





-
+

-
+

-
+





-
+

-
+

-
+




+
+
+
+
+


package require tcltest
namespace import ::tcltest::*
tcltest::loadTestedCommands
package require Thread
package require thread

set backends {gdbm lmdb}

foreach b $backends {
    testConstraint have_$b [expr {$b in [tsv::handlers]}]
}

foreach backend $backends {
    set db "data"
    file delete -force $db
    set ::handle $backend:$db

    proc setup {} {
        tsv::array bind a $::handle
	tsv::array bind a $::handle
    }
    proc cleanup {} {
        tsv::array unbind a
	tsv::array unbind a
    }

    test tsv-$backend-1.0 {tsv::array isboud} \
    -constraints have_$backend \
    -setup {
        setup
	setup
    } -body {
        tsv::array isbound a
	tsv::array isbound a
    } -cleanup {
        cleanup
	cleanup
    } -result {1}

    test tsv-$backend-1.1 {tsv::array bind - empty} \
    -constraints have_$backend \
    -setup {
        setup
	setup
    } -body {
        tsv::array names b
	tsv::array names b
    } -cleanup {
       cleanup
    } -result {}

    test tsv-$backend-1.2 {tsv::set} \
    -constraints have_$backend \
    -setup {
        setup
	setup
    } -body {
        tsv::set a Key Val
	tsv::set a Key Val
    } -cleanup {
        cleanup
	cleanup
    } -result {Val}

    test tsv-$backend-1.3 {tsv::get - previously set was persisted} \
    -constraints have_$backend \
    -setup {
        setup
	setup
    } -body {
        tsv::get a Key
	tsv::get a Key
    } -cleanup {
        cleanup
	cleanup
    } -result {Val}

    test tsv-$backend-1.4 {tsv::array names - previously set was persisted} \
    -constraints have_$backend \
    -setup {
        setup
	setup
    } -body {
        tsv::array names a
	tsv::array names a
    } -cleanup {
        cleanup
	cleanup
    } -result {Key}

    test tsv-$backend-1.5 {tsv::exists - previously set exists} \
    -constraints have_$backend \
    -setup {
        setup
	setup
    } -body {
        tsv::exists a Key
	tsv::exists a Key
    } -cleanup {
        cleanup
	cleanup
    } -result {1}

    test tsv-$backend-1.6 {tsv::pop - get previously set} \
    -constraints have_$backend \
    -setup {
        setup
	setup
    } -body {
        tsv::pop a Key
	tsv::pop a Key
    } -cleanup {
        cleanup
	cleanup
    } -result {Val}

    test tsv-$backend-1.7 {tsv::exists - popped was removed} \
    -constraints have_$backend \
    -setup {
        setup
	setup
    } -body {
        tsv::exists a Key
	tsv::exists a Key
    } -cleanup {
        cleanup
	cleanup
    } -result {0}

    file delete -force $db
}

test tsv-bug-c2dfd8b7ea {tsv::lset crash} -body {
    tsv::linsert mytsv mylist 0 A {X Y}
    tsv::lset mytsv mylist end 1 P
} -result {A {X P}}

::tcltest::cleanupTests
Changes to unix/CONFIG.
34
35
36
37
38
39
40
41

42
43
44
45
46
47
48
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48







-
+







# ----------------------------------------------------
# nsdir="/usr/local/naviserver"
# ../configure --enable-threads \
#   --with-naviserver=$nsdir \
#   --prefix=$nsdir --exec-prefix=$nsdir
#
# NaviServer/AOLserver uses its own package loading mechanism.
# To load, just do "ns_eval package require Thread"
# To load, just do "ns_eval package require thread"
# at the NaviServer/AOLserver startup or later from any thread.
#
#
# Mac OS X; Uses public Tcl library.
# ----------------------------------------------------
# ../configure --enable-threads \
#   --mandir=/usr/local/share/man \
Changes to win/CONFIG.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1
2
3
4







5
6
7
8
9
10
11




-
-
-
-
-
-
-







#
# This is how I run configure.  You'll want to change the
# pathnames to match your system, of course.
#
# Remember that if you use the --enable-sybols, you need to
# use the thread25d.dll in a tclsh that has also been compiled
# with symbols (e.g., tclsh84g.exe or tclsh84d.exe).
# If you want to build both debug and non-debug versions, then
# create "debug" and "release" directories and run configure
# from in those directories with the appropriate flags.
#
# Note the CC=gcc must be set *before* the "configure" is ran.
# This is really needed, otherwise configure will not be able
# to compile the small test file which checks the presence
# of the MinGW build environment. It is *not* enough to use
# "--enable-gcc" configure option; you *need* to define CC.
#

Added win/gitmanifest.in.

1
+
git-
Changes to win/makefile.vc.
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31



32
33
34
35
36
37
38
1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


30
31
32
33
34
35
36
37
38
39










-
+


















-
-
+
+
+







#------------------------------------------------------------- -*- makefile -*-
#
# Makefile for thread extension
#
# Basic build, test and install
#   nmake /f makefile.vc INSTALLDIR=c:\tcl
#   nmake /f makefile.vc INSTALLDIR=c:\tcl test
#   nmake /f makefile.vc INSTALLDIR=c:\tcl install
#
# For other build options (debug, static etc.),
# See TIP 477 (https://core.tcl.tk/tips/doc/trunk/tip/477.md) for
# See TIP 477 (https://core.tcl-lang.org/tips/doc/main/tip/477.md) for
# detailed documentation.
#
# In addition to the command line macros described there the following
# may also be defined.
#  ADDOPTDEFINES - addition compiler options
#  ADDLINKOPTS - addition link options
# E.g.
#   nmake -nologo -f makefile.vc TCLDIR=%TCLDIR% ... ADDOPTDEFINES="-I%LMDBDIR%" ADDLINKOPTS="%LMDBDIR%\Release\lmdb.lib"
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#------------------------------------------------------------------------------

PROJECT = thread
RCFILE = thread.rc
DOCDIR          = $(ROOT)\doc\html

PRJ_DEFINES = -D _CRT_SECURE_NO_DEPRECATE -D _CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS
PRJ_DEFINES = $(PRJ_DEFINES) -DTCL_NO_DEPRECATED=1 $(ADDOPTDEFINES)
PRJ_DEFINES = /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE
PRJ_DEFINES = $(PRJ_DEFINES) /D_CRT_SECURE_NO_WARNINGS
PRJ_DEFINES = $(PRJ_DEFINES) $(ADDOPTDEFINES) -I$(TMP_DIR)
PRJ_LIBS = $(ADDLINKOPTS)

!include "rules-ext.vc"

PRJ_OBJS = \
	$(TMP_DIR)\threadNs.obj \
	$(TMP_DIR)\threadCmd.obj \
46
47
48
49
50
51
52







53
54
55
56

57
58
59
60
61
62
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

64
65
66
67
68
69
70







+
+
+
+
+
+
+



-
+






	$(TMP_DIR)\tclXkeylist.obj

!include "$(_RULESDIR)\targets.vc"

install:    default-install-docs-html
pkgindex:   default-pkgindex-tea

$(ROOT)\manifest.uuid:
   copy $(WIN_DIR)\gitmanifest.in $(ROOT)\manifest.uuid
   git rev-parse HEAD >>$(ROOT)\manifest.uuid

$(TMP_DIR)\threadUuid.h:	$(ROOT)\manifest.uuid
	copy $(WIN_DIR)\threadUuid.h.in+$(ROOT)\manifest.uuid $(TMP_DIR)\threadUuid.h

# Explicit dependency rules
$(GENERICDIR)\psGdbm.c: $(GENERICDIR)\psGdbm.h
$(GENERICDIR)\psLmdb.c: $(GENERICDIR)\psLmdb.h
$(GENERICDIR)\threadCmd.c : $(GENERICDIR)\tclThreadInt.h
$(GENERICDIR)\threadCmd.c : $(GENERICDIR)\tclThreadInt.h $(TMP_DIR)\threadUuid.h
$(GENERICDIR)\threadSpCmd.c : $(GENERICDIR)\tclThreadInt.h
$(GENERICDIR)\threadSvCmd.c : $(GENERICDIR)\tclThreadInt.h
$(GENERICDIR)\threadPoolCmd.c : $(GENERICDIR)\tclThreadInt.h
$(GENERICDIR)\threadSvListCmd.c : $(GENERICDIR)\tclThreadInt.h
$(GENERICDIR)\threadSvKeylistCmd.c : $(GENERICDIR)\tclThreadInt.h

Changes to win/nmakehlp.c.
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15
16

17
18

19
20
21
22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58


59
60
61
62
63
64
65
1
2
3
4
5
6


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57


58
59
60
61
62
63
64
65
66






-
-
+
+








+


+

-











-
+







-
+
















-
-
+
+







/*
 * ----------------------------------------------------------------------------
 * nmakehlp.c --
 *
 *	This is used to fix limitations within nmake and the environment.
 *
 * Copyright (c) 2002 by David Gravereaux.
 * Copyright (c) 2006 by Pat Thoyts
 * Copyright (c) 2002 David Gravereaux.
 * Copyright (c) 2006 Pat Thoyts
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * ----------------------------------------------------------------------------
 */

#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#ifdef _MSC_VER
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "kernel32.lib")
#endif
#include <stdio.h>
#include <math.h>

/*
 * This library is required for x64 builds with _some_ versions of MSVC
 */
#if defined(_M_IA64) || defined(_M_AMD64)
#if _MSC_VER >= 1400 && _MSC_VER < 1500
#pragma comment(lib, "bufferoverflowU")
#endif
#endif

/* ISO hack for dumb VC++ */
#ifdef _MSC_VER
#if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1900
#define   snprintf	_snprintf
#endif


/* protos */

static int CheckForCompilerFeature(const char *option);
static int CheckForLinkerFeature(const char **options, int count);
static int CheckForLinkerFeature(char **options, int count);
static int IsIn(const char *string, const char *substring);
static int SubstituteFile(const char *substs, const char *filename);
static int QualifyPath(const char *path);
static int LocateDependency(const char *keyfile);
static const char *GetVersionFromFile(const char *filename, const char *match, int numdots);
static DWORD WINAPI ReadFromPipe(LPVOID args);

/* globals */

#define CHUNK	25
#define STATICBUFFERSIZE    1000
typedef struct {
    HANDLE pipe;
    char buffer[STATICBUFFERSIZE];
} pipeinfo;

pipeinfo Out = {INVALID_HANDLE_VALUE, '\0'};
pipeinfo Err = {INVALID_HANDLE_VALUE, '\0'};
pipeinfo Out = {INVALID_HANDLE_VALUE, ""};
pipeinfo Err = {INVALID_HANDLE_VALUE, ""};

/*
 * exitcodes: 0 == no, 1 == yes, 2 == error
 */

int
main(
85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111







-
+










-
+







    SetEnvironmentVariable("LINK", "");

    if (argc > 1 && *argv[1] == '-') {
	switch (*(argv[1]+1)) {
	case 'c':
	    if (argc != 3) {
		chars = snprintf(msg, sizeof(msg) - 1,
		        "usage: %s -c <compiler option>\n"
			"usage: %s -c <compiler option>\n"
			"Tests for whether cl.exe supports an option\n"
			"exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
		WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
			&dwWritten, NULL);
		return 2;
	    }
	    return CheckForCompilerFeature(argv[2]);
	case 'l':
	    if (argc < 3) {
		chars = snprintf(msg, sizeof(msg) - 1,
	       		"usage: %s -l <linker option> ?<mandatory option> ...?\n"
			"usage: %s -l <linker option> ?<mandatory option> ...?\n"
			"Tests for whether link.exe supports an option\n"
			"exitcodes: 0 == no, 1 == yes, 2 == error\n", argv[0]);
		WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, chars,
			&dwWritten, NULL);
		return 2;
	    }
	    return CheckForLinkerFeature(&argv[2], argc-2);
201
202
203
204
205
206
207
208
209


210
211
212
213
214

215
216
217
218
219
220

221
222
223
224
225
226

227
228
229
230
231
232
233
202
203
204
205
206
207
208


209
210
211
212
213
214

215
216
217
218
219
220

221
222
223
224
225
226

227
228
229
230
231
232
233
234







-
-
+
+




-
+





-
+





-
+







    char msg[300];
    BOOL ok;
    HANDLE hProcess, h, pipeThreads[2];
    char cmdline[100];

    hProcess = GetCurrentProcess();

    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
    ZeroMemory(&si, sizeof(STARTUPINFO));
    memset(&pi, 0, sizeof(PROCESS_INFORMATION));
    memset(&si, 0, sizeof(STARTUPINFO));
    si.cb = sizeof(STARTUPINFO);
    si.dwFlags   = STARTF_USESTDHANDLES;
    si.hStdInput = INVALID_HANDLE_VALUE;

    ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
    memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = FALSE;

    /*
     * Create a non-inheritible pipe.
     * Create a non-inheritable pipe.
     */

    CreatePipe(&Out.pipe, &h, &sa, 0);

    /*
     * Dupe the write side, make it inheritible, and close the original.
     * Dupe the write side, make it inheritable, and close the original.
     */

    DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
	    DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);

    /*
     * Same as above, but for the error side.
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
270
271
272
273
274
275
276

277
278
279
280
281
282
283
284







-
+








    if (!ok) {
	DWORD err = GetLastError();
	int chars = snprintf(msg, sizeof(msg) - 1,
		"Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);

	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
		FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
		FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars],
		(300-chars), 0);
	WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, lstrlen(msg), &err,NULL);
	return 2;
    }

    /*
     * Close our references to the write handles that have now been inherited.
313
314
315
316
317
318
319
320
321
322
323
324





325
326
327
328
329

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345


346
347
348
349
350

351
352
353
354
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
314
315
316
317
318
319
320





321
322
323
324
325
326
327
328
329

330
331
332
333
334
335
336
337
338
339
340
341
342
343
344


345
346
347
348
349
350

351
352
353
354
355
356
357
358
359
360
361
362

363
364
365
366
367
368
369
370







-
-
-
-
-
+
+
+
+
+




-
+














-
-
+
+




-
+











-
+








    /*
     * Look for the commandline warning code in both streams.
     *  - in MSVC 6 & 7 we get D4002, in MSVC 8 we get D9002.
     */

    return !(strstr(Out.buffer, "D4002") != NULL
             || strstr(Err.buffer, "D4002") != NULL
             || strstr(Out.buffer, "D9002") != NULL
             || strstr(Err.buffer, "D9002") != NULL
             || strstr(Out.buffer, "D2021") != NULL
             || strstr(Err.buffer, "D2021") != NULL);
	    || strstr(Err.buffer, "D4002") != NULL
	    || strstr(Out.buffer, "D9002") != NULL
	    || strstr(Err.buffer, "D9002") != NULL
	    || strstr(Out.buffer, "D2021") != NULL
	    || strstr(Err.buffer, "D2021") != NULL);
}

static int
CheckForLinkerFeature(
    const char **options,
    char **options,
    int count)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    SECURITY_ATTRIBUTES sa;
    DWORD threadID;
    char msg[300];
    BOOL ok;
    HANDLE hProcess, h, pipeThreads[2];
    int i;
    char cmdline[255];

    hProcess = GetCurrentProcess();

    ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
    ZeroMemory(&si, sizeof(STARTUPINFO));
    memset(&pi, 0, sizeof(PROCESS_INFORMATION));
    memset(&si, 0, sizeof(STARTUPINFO));
    si.cb = sizeof(STARTUPINFO);
    si.dwFlags   = STARTF_USESTDHANDLES;
    si.hStdInput = INVALID_HANDLE_VALUE;

    ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
    memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
    sa.nLength = sizeof(SECURITY_ATTRIBUTES);
    sa.lpSecurityDescriptor = NULL;
    sa.bInheritHandle = TRUE;

    /*
     * Create a non-inheritible pipe.
     */

    CreatePipe(&Out.pipe, &h, &sa, 0);

    /*
     * Dupe the write side, make it inheritible, and close the original.
     * Dupe the write side, make it inheritable, and close the original.
     */

    DuplicateHandle(hProcess, h, hProcess, &si.hStdOutput, 0, TRUE,
	    DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE);

    /*
     * Same as above, but for the error side.
403
404
405
406
407
408
409
410

411
412
413
414
415
416
417
404
405
406
407
408
409
410

411
412
413
414
415
416
417
418







-
+








    if (!ok) {
	DWORD err = GetLastError();
	int chars = snprintf(msg, sizeof(msg) - 1,
		"Tried to launch: \"%s\", but got error [%u]: ", cmdline, err);

	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|
		FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPVOID)&msg[chars],
		FORMAT_MESSAGE_MAX_WIDTH_MASK, 0L, err, 0, (LPSTR)&msg[chars],
		(300-chars), 0);
	WriteFile(GetStdHandle(STD_ERROR_HANDLE), msg, lstrlen(msg), &err,NULL);
	return 2;
    }

    /*
     * Close our references to the write handles that have now been inherited.
488
489
490
491
492
493
494
495
496
497



498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

517
518
519
520
521
522
523
524
525
526

527
528
529
530
531
532
533
534
535
536


537
538
539
540
541
542


543
544
545
546
547
548
549
489
490
491
492
493
494
495



496
497
498
499
500
501
502
503
504
505
506

507
508
509
510
511
512
513
514
515

516
517
518
519
520
521
522
523
524
525

526
527
528
529
530
531
532
533
534


535
536
537
538
539



540
541
542
543
544
545
546
547
548







-
-
-
+
+
+








-









-
+









-
+








-
-
+
+



-
-
-
+
+







    const char *substring)
{
    return (strstr(string, substring) != NULL);
}

/*
 * GetVersionFromFile --
 * 	Looks for a match string in a file and then returns the version
 * 	following the match where a version is anything acceptable to
 * 	package provide or package ifneeded.
 *	Looks for a match string in a file and then returns the version
 *	following the match where a version is anything acceptable to
 *	package provide or package ifneeded.
 */

static const char *
GetVersionFromFile(
    const char *filename,
    const char *match,
    int numdots)
{
    size_t cbBuffer = 100;
    static char szBuffer[100];
    char *szResult = NULL;
    FILE *fp = fopen(filename, "rt");

    if (fp != NULL) {
	/*
	 * Read data until we see our match string.
	 */

	while (fgets(szBuffer, cbBuffer, fp) != NULL) {
	while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) {
	    LPSTR p, q;

	    p = strstr(szBuffer, match);
	    if (p != NULL) {
		/*
		 * Skip to first digit after the match.
		 */

		p += strlen(match);
		while (*p && !isdigit(*p)) {
		while (*p && !isdigit((unsigned char)*p)) {
		    ++p;
		}

		/*
		 * Find ending whitespace.
		 */

		q = p;
		while (*q && (strchr("0123456789.ab", *q)) && ((!strchr(".ab", *q)
			    && (!strchr("ab", q[-1])) || --numdots))) {
		while (*q && (strchr("0123456789.ab", *q)) && (((!strchr(".ab", *q)
			    && !strchr("ab", q[-1])) || --numdots))) {
		    ++q;
		}

		memcpy(szBuffer, p, q - p);
		szBuffer[q-p] = 0;
		szResult = szBuffer;
		*q = 0;
		szResult = p;
		break;
	    }
	}
	fclose(fp);
    }
    return szResult;
}
558
559
560
561
562
563
564
565

566
567
568
569
570
571
572
557
558
559
560
561
562
563

564
565
566
567
568
569
570
571







-
+







    char * value;
} list_item_t;

/* insert a list item into the list (list may be null) */
static list_item_t *
list_insert(list_item_t **listPtrPtr, const char *key, const char *value)
{
    list_item_t *itemPtr = malloc(sizeof(list_item_t));
    list_item_t *itemPtr = (list_item_t *)malloc(sizeof(list_item_t));
    if (itemPtr) {
	itemPtr->key = strdup(key);
	itemPtr->value = strdup(value);
	itemPtr->nextPtr = NULL;

	while(*listPtrPtr) {
	    listPtrPtr = &(*listPtrPtr)->nextPtr;
589
590
591
592
593
594
595
596

597
598
599
600
601
602
603
604
605
606



607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624

625
626
627
628
629

630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646

647
648
649
650
651
652
653
654
655
656
657
658
659
660

661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677

678
679
680
681
682
683
684
588
589
590
591
592
593
594

595
596
597
598
599
600
601
602



603
604
605
606
607
608
609
610
611
612

613

614
615
616
617
618
619
620

621
622
623
624
625

626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642

643
644
645
646
647
648
649
650
651
652
653
654
655
656

657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673

674
675
676
677
678
679
680
681







-
+







-
-
-
+
+
+







-

-







-
+




-
+
















-
+













-
+
















-
+







    }
}

/*
 * SubstituteFile --
 *	As windows doesn't provide anything useful like sed and it's unreliable
 *	to use the tclsh you are building against (consider x-platform builds -
 *	eg compiling AMD64 target from IX86) we provide a simple substitution
 *	e.g. compiling AMD64 target from IX86) we provide a simple substitution
 *	option here to handle autoconf style substitutions.
 *	The substitution file is whitespace and line delimited. The file should
 *	consist of lines matching the regular expression:
 *	  \s*\S+\s+\S*$
 *
 *	Usage is something like:
 *	  nmakehlp -S << $** > $@
 *        @PACKAGE_NAME@ $(PACKAGE_NAME)
 *        @PACKAGE_VERSION@ $(PACKAGE_VERSION)
 *        <<
 *	    @PACKAGE_NAME@ $(PACKAGE_NAME)
 *	    @PACKAGE_VERSION@ $(PACKAGE_VERSION)
 *	    <<
 */

static int
SubstituteFile(
    const char *substitutions,
    const char *filename)
{
    size_t cbBuffer = 1024;
    static char szBuffer[1024], szCopy[1024];
    char *szResult = NULL;
    list_item_t *substPtr = NULL;
    FILE *fp, *sp;

    fp = fopen(filename, "rt");
    if (fp != NULL) {

	/*
	 * Build a list of substutitions from the first filename
	 * Build a list of substitutions from the first filename
	 */

	sp = fopen(substitutions, "rt");
	if (sp != NULL) {
	    while (fgets(szBuffer, cbBuffer, sp) != NULL) {
	    while (fgets(szBuffer, sizeof(szBuffer), sp) != NULL) {
		unsigned char *ks, *ke, *vs, *ve;
		ks = (unsigned char*)szBuffer;
		while (ks && *ks && isspace(*ks)) ++ks;
		ke = ks;
		while (ke && *ke && !isspace(*ke)) ++ke;
		vs = ke;
		while (vs && *vs && isspace(*vs)) ++vs;
		ve = vs;
		while (ve && *ve && !(*ve == '\r' || *ve == '\n')) ++ve;
		*ke = 0, *ve = 0;
		list_insert(&substPtr, (char*)ks, (char*)vs);
	    }
	    fclose(sp);
	}

	/* debug: dump the list */
#ifdef _DEBUG
#ifndef NDEBUG
	{
	    int n = 0;
	    list_item_t *p = NULL;
	    for (p = substPtr; p != NULL; p = p->nextPtr, ++n) {
		fprintf(stderr, "% 3d '%s' => '%s'\n", n, p->key, p->value);
	    }
	}
#endif

	/*
	 * Run the substitutions over each line of the input
	 */

	while (fgets(szBuffer, cbBuffer, fp) != NULL) {
	while (fgets(szBuffer, sizeof(szBuffer), fp) != NULL) {
	    list_item_t *p = NULL;
	    for (p = substPtr; p != NULL; p = p->nextPtr) {
		char *m = strstr(szBuffer, p->key);
		if (m) {
		    char *cp, *op, *sp;
		    cp = szCopy;
		    op = szBuffer;
		    while (op != m) *cp++ = *op++;
		    sp = p->value;
		    while (sp && *sp) *cp++ = *sp++;
		    op += strlen(p->key);
		    while (*op) *cp++ = *op++;
		    *cp = 0;
		    memcpy(szBuffer, szCopy, sizeof(szCopy));
		}
	    }
	    printf(szBuffer);
	    printf("%s", szBuffer);
	}

	list_free(&substPtr);
    }
    fclose(fp);
    return 0;
}
704
705
706
707
708
709
710
711

712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727

728

729
730
731

732

733
734

735

736
737
738
739
740
741
742
743
744
745
746
747
748
749
750

751

752
753
754
755
756
757
758
759
760
761

762

763
764

765

766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786


787
788
789
790
791




792
793
794

795
796


797
798
799
800

801

802
803
804
805
806
807
808
701
702
703
704
705
706
707

708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725

726
727
728

729
730
731
732

733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749

750
751
752
753
754
755
756
757
758
759
760
761

762
763
764
765

766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787


788
789
790




791
792
793
794
795
796
797
798


799
800
801
802
803

804
805
806
807
808
809
810
811
812
813







-
+
















+
-
+


-
+

+

-
+

+














-
+

+









-
+

+

-
+

+



















-
-
+
+

-
-
-
-
+
+
+
+



+
-
-
+
+



-
+

+








static int
QualifyPath(
    const char *szPath)
{
    char szCwd[MAX_PATH + 1];

	GetFullPathName(szPath, sizeof(szCwd)-1, szCwd, NULL);
    GetFullPathName(szPath, sizeof(szCwd)-1, szCwd, NULL);
    printf("%s\n", szCwd);
    return 0;
}

/*
 * Implements LocateDependency for a single directory. See that command
 * for an explanation.
 * Returns 0 if found after printing the directory.
 * Returns 1 if not found but no errors.
 * Returns 2 on any kind of error
 * Basically, these are used as exit codes for the process.
 */
static int LocateDependencyHelper(const char *dir, const char *keypath)
{
    HANDLE hSearch;
    char path[MAX_PATH+1];
    size_t dirlen;
    int dirlen, keylen, ret;
    int keylen, ret;
    WIN32_FIND_DATA finfo;

    if (dir == NULL || keypath == NULL)
    if (dir == NULL || keypath == NULL) {
	return 2; /* Have no real error reporting mechanism into nmake */
    }
    dirlen = strlen(dir);
    if ((dirlen + 3) > sizeof(path))
    if (dirlen > sizeof(path) - 3) {
	return 2;
    }
    strncpy(path, dir, dirlen);
    strncpy(path+dirlen, "\\*", 3);	/* Including terminating \0 */
    keylen = strlen(keypath);

#if 0 /* This function is not available in Visual C++ 6 */
    /*
     * Use numerics 0 -> FindExInfoStandard,
     * 1 -> FindExSearchLimitToDirectories,
     * as these are not defined in Visual C++ 6
     */
    hSearch = FindFirstFileEx(path, 0, &finfo, 1, NULL, 0);
#else
    hSearch = FindFirstFile(path, &finfo);
#endif
    if (hSearch == INVALID_HANDLE_VALUE)
    if (hSearch == INVALID_HANDLE_VALUE) {
	return 1; /* Not found */
    }

    /* Loop through all subdirs checking if the keypath is under there */
    ret = 1; /* Assume not found */
    do {
	int sublen;
	/*
	 * We need to check it is a directory despite the
	 * FindExSearchLimitToDirectories in the above call. See SDK docs
	 */
	if ((finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
	if ((finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
	    continue;
	}
	sublen = strlen(finfo.cFileName);
	if ((dirlen+1+sublen+1+keylen+1) > sizeof(path))
	if ((dirlen+1+sublen+1+keylen+1) > sizeof(path)) {
	    continue;		/* Path does not fit, assume not matched */
	}
	strncpy(path+dirlen+1, finfo.cFileName, sublen);
	path[dirlen+1+sublen] = '\\';
	strncpy(path+dirlen+1+sublen+1, keypath, keylen+1);
	if (FileExists(path)) {
	    /* Found a match, print to stdout */
	    path[dirlen+1+sublen] = '\0';
	    QualifyPath(path);
	    ret = 0;
	    break;
	}
    } while (FindNextFile(hSearch, &finfo));
    FindClose(hSearch);
    return ret;
}

/*
 * LocateDependency --
 *
 *	Locates a dependency for a package.
 *        keypath - a relative path within the package directory
 *          that is used to confirm it is the correct directory.
 *	    keypath - a relative path within the package directory
 *	      that is used to confirm it is the correct directory.
 *	The search path for the package directory is currently only
 *      the parent and grandparent of the current working directory.
 *      If found, the command prints
 *         name_DIRPATH=<full path of located directory>
 *      and returns 0. If not found, does not print anything and returns 1.
 *	    the parent and grandparent of the current working directory.
 *	    If found, the command prints
 *	      name_DIRPATH=<full path of located directory>
 *	    and returns 0. If not found, does not print anything and returns 1.
 */
static int LocateDependency(const char *keypath)
{
    size_t i;
    int i, ret;
    static char *paths[] = {"..", "..\\..", "..\\..\\.."};
    int ret;
    static const char *paths[] = {"..", "..\\..", "..\\..\\.."};

    for (i = 0; i < (sizeof(paths)/sizeof(paths[0])); ++i) {
	ret = LocateDependencyHelper(paths[i], keypath);
	if (ret == 0)
	if (ret == 0) {
	    return ret;
	}
    }
    return ret;
}


/*
 * Local variables:
Changes to win/pkg.vc.
1
2
3
4
5
6

1
2
3
4
5

6





-
+
# remember to change configure.ac as well when these change
# (then re-autoconf)

PACKAGE_MAJOR	= 3
PACKAGE_MINOR	= 0
PACKAGE_VERSION	= "3.0a2"
PACKAGE_VERSION	= "3.0.2"
Changes to win/rules-ext.vc.
27
28
29
30
31
32
33

34





35
36
37
38
39
40
41
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46







+
-
+
+
+
+
+







!if "$(PROJECT)" == "tcl"
!error The rules-ext.vc file is not intended for Tcl itself.
!endif

# We extract version numbers using the nmakehlp program. For now use
# the local copy of nmakehlp. Once we locate Tcl, we will use that
# one if it is newer.
!if "$(MACHINE)" == "IX86" || "$(MACHINE)" == "$(NATIVE_ARCH)"
!if [$(CC) -nologo "nmakehlp.c" -link -subsystem:console > nul]
!if [$(CC) -nologo -DNDEBUG "nmakehlp.c" -link -subsystem:console > nul]
!endif
!else
!if [copy x86_64-w64-mingw32-nmakehlp.exe nmakehlp.exe >NUL]
!endif
!endif

# First locate the Tcl directory that we are working with.
!if "$(TCLDIR)" != ""

_RULESDIR = $(TCLDIR:/=\)

Changes to win/rules.vc.
1
2
3
4
5
6
7
8
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
1
2
3
4
5
6
7
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34








-
+

















-
+







#------------------------------------------------------------- -*- makefile -*-
# rules.vc --
#
# Part of the nmake based build system for Tcl and its extensions.
# This file does all the hard work in terms of parsing build options,
# compiler switches, defining common targets and macros. The Tcl makefile
# directly includes this. Extensions include it via "rules-ext.vc".
#
# See TIP 477 (https://core.tcl-lang.org/tips/doc/trunk/tip/477.md) for
# See TIP 477 (https://core.tcl-lang.org/tips/doc/main/tip/477.md) for
# detailed documentation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# Copyright (c) 2001-2003 David Gravereaux.
# Copyright (c) 2003-2008 Patrick Thoyts
# Copyright (c) 2017      Ashok P. Nadkarni
#------------------------------------------------------------------------------

!ifndef _RULES_VC
_RULES_VC = 1

# The following macros define the version of the rules.vc nmake build system
# For modifications that are not backward-compatible, you *must* change
# the major version.
RULES_VERSION_MAJOR = 1
RULES_VERSION_MINOR = 6
RULES_VERSION_MINOR = 15

# The PROJECT macro must be defined by parent makefile.
!if "$(PROJECT)" == ""
!error *** Error: Macro PROJECT not defined! Please define it before including rules.vc
!endif

!if "$(PRJ_PACKAGE_TCLNAME)" == ""
75
76
77
78
79
80
81


82
83
84



85
86
87
88
89
90
91
92
75
76
77
78
79
80
81
82
83



84
85
86

87
88
89
90
91
92
93







+
+
-
-
-
+
+
+
-







# 1. First define the external tools used for compiling, copying etc.
#    as this is independent of everything else.
# 2. Figure out our build structure in terms of the directory, whether
#    we are building Tcl or an extension, etc.
# 3. Determine the compiler and linker versions
# 4. Build the nmakehlp helper application
# 5. Determine the supported compiler options and features
# 6. Extract Tcl, Tk, and possibly extensions, version numbers from the
#    headers
# 6. Parse the OPTS macro value for user-specified build configuration
# 7. Parse the STATS macro value for statistics instrumentation
# 8. Parse the CHECKS macro for additional compilation checks
# 7. Parse the OPTS macro value for user-specified build configuration
# 8. Parse the STATS macro value for statistics instrumentation
# 9. Parse the CHECKS macro for additional compilation checks
# 9. Extract Tcl, and possibly Tk, version numbers from the headers
# 10. Based on this selected configuration, construct the output
#     directory and file paths
# 11. Construct the paths where the package is to be installed
# 12. Set up the actual options passed to compiler and linker based
#     on the information gathered above.
# 13. Define some standard build targets and implicit rules. These may
#     be optionally disabled by the parent makefile.
407
408
409
410
411
412
413
414
415


416
417
418
419
420
421
422
408
409
410
411
412
413
414


415
416
417
418
419
420
421
422
423







-
-
+
+







# following macros:
# VCVERSION - the internal compiler version as 1200, 1400, 1910 etc.
#     This is also printed by the compiler in dotted form 19.10 etc.
# VCVER - the "marketing version", for example Visual C++ 6 for internal
#     compiler version 1200. This is kept only for legacy reasons as it
#     does not make sense for recent Microsoft compilers. Only used for
#     output directory names.
# ARCH - set to IX86 or AMD64 depending on 32- or 64-bit target
# NATIVE_ARCH - set to IX86 or AMD64 for the host machine
# ARCH - set to IX86, ARM64 or AMD64 depending on 32- or 64-bit target
# NATIVE_ARCH - set to IX86, ARM64 or AMD64 for the host machine
# MACHINE - same as $(ARCH) - legacy
# _VC_MANIFEST_EMBED_{DLL,EXE} - commands for embedding a manifest if needed

cc32		= $(CC)   # built-in default.
link32		= link
lib32		= lib
rc32		= $(RC)   # built-in default.
431
432
433
434
435
436
437


438
439
440
441
442
443
444
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447







+
+







_VC_MANIFEST_EMBED_DLL=
VCVER=0
!if ![echo VCVERSION=_MSC_VER > vercl.x] \
    && ![echo $(_HASH)if defined(_M_IX86) >> vercl.x] \
    && ![echo ARCH=IX86 >> vercl.x] \
    && ![echo $(_HASH)elif defined(_M_AMD64) >> vercl.x] \
    && ![echo ARCH=AMD64 >> vercl.x] \
    && ![echo $(_HASH)elif defined(_M_ARM64) >> vercl.x] \
    && ![echo ARCH=ARM64 >> vercl.x] \
    && ![echo $(_HASH)endif >> vercl.x] \
    && ![$(cc32) -nologo -TC -P vercl.x 2>NUL]
!include vercl.i
!if $(VCVERSION) < 1900
!if ![echo VCVER= ^\> vercl.vc] \
    && ![set /a $(VCVERSION) / 100 - 6 >> vercl.vc]
!include vercl.vc
455
456
457
458
459
460
461



462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477


478
479
480
481
482
483
484
485
486
487
488
489
490
491
492


493
494
495
496
497
498
499
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509







+
+
+
















+
+















+
+








#----------------------------------------------------------------
# The MACHINE macro is used by legacy makefiles so set it as well
!ifdef MACHINE
!if "$(MACHINE)" == "x86"
!undef MACHINE
MACHINE = IX86
!elseif "$(MACHINE)" == "arm64"
!undef MACHINE
MACHINE = ARM64
!elseif "$(MACHINE)" == "x64"
!undef MACHINE
MACHINE = AMD64
!endif
!if "$(MACHINE)" != "$(ARCH)"
!error Specified MACHINE macro $(MACHINE) does not match detected target architecture $(ARCH).
!endif
!else
MACHINE=$(ARCH)
!endif

#---------------------------------------------------------------
# The PLATFORM_IDENTIFY macro matches the values returned by
# the Tcl platform::identify command
!if "$(MACHINE)" == "AMD64"
PLATFORM_IDENTIFY = win32-x86_64
!elseif "$(MACHINE)" == "ARM64"
PLATFORM_IDENTIFY = win32-arm
!else
PLATFORM_IDENTIFY = win32-ix86
!endif

# The MULTIPLATFORM macro controls whether binary extensions are installed
# in platform-specific directories. Intended to be set/used by extensions.
!ifndef MULTIPLATFORM_INSTALL
MULTIPLATFORM_INSTALL = 0
!endif

#------------------------------------------------------------
# Figure out the *host* architecture by reading the registry

!if ![reg query HKLM\Hardware\Description\System\CentralProcessor\0 /v Identifier | findstr /i x86]
NATIVE_ARCH=IX86
!elseif ![reg query HKLM\Hardware\Description\System\CentralProcessor\0 /v Identifier | findstr /i ARM | findstr /i 64-bit]
NATIVE_ARCH=ARM64
!else
NATIVE_ARCH=AMD64
!endif

# Since MSVC8 we must deal with manifest resources.
!if $(VCVERSION) >= 1400
_VC_MANIFEST_EMBED_EXE=if exist [email protected] mt -nologo -manifest [email protected] -outputresource:$@;1
537
538
539
540
541
542
543

544
545




546
547
548
549
550
551
552
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567







+


+
+
+
+







!endif # $(TCLINSTALL)
!endif # !$(DOING_TCL)

!endif # NMAKEHLPC

# We always build nmakehlp even if it exists since we do not know
# what source it was built from.
!if "$(MACHINE)" == "IX86" || "$(MACHINE)" == "$(NATIVE_ARCH)"
!if [$(cc32) -nologo "$(NMAKEHLPC)" -link -subsystem:console > nul]
!endif
!else
!if [copy $(NMAKEHLPC:nmakehlp.c=x86_64-w64-mingw32-nmakehlp.exe) nmakehlp.exe >NUL]
!endif
!endif

################################################################
# 5. Test for compiler features
# Visual C++ compiler options have changed over the years. Check
# which options are supported by the compiler in use.
#
# The following macros are set:
648
649
650
651
652
653
654


























































































































655
656

657
658
659
660
661
662
663
664
665
666
667
668
669

670
671
672


673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792

793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808


809
810
811
812
813
814
815
816
817
818
819


820
821
822
823
824
825
826







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+













+

-
-
+
+









-
-







# If compiler has enabled link time optimization, linker must too with -ltcg
!ifdef CC_GL_OPT_ENABLED
!if [nmakehlp -l -ltcg $(LINKER_TESTFLAGS)]
LINKERFLAGS     = $(LINKERFLAGS) -ltcg
!endif
!endif


################################################################
# 6. Extract various version numbers from headers
# For Tcl and Tk, version numbers are extracted from tcl.h and tk.h
# respectively. For extensions, versions are extracted from the
# configure.in or configure.ac from the TEA configuration if it
# exists, and unset otherwise.
# Sets the following macros:
# TCL_MAJOR_VERSION
# TCL_MINOR_VERSION
# TCL_RELEASE_SERIAL
# TCL_PATCH_LEVEL
# TCL_PATCH_LETTER
# TCL_VERSION
# TK_MAJOR_VERSION
# TK_MINOR_VERSION
# TK_RELEASE_SERIAL
# TK_PATCH_LEVEL
# TK_PATCH_LETTER
# TK_VERSION
# DOTVERSION - set as (for example) 2.5
# VERSION - set as (for example 25)
#--------------------------------------------------------------

!if [echo REM = This file is generated from rules.vc > versions.vc]
!endif
!if [echo TCL_MAJOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" "define TCL_MAJOR_VERSION" >> versions.vc]
!endif
!if [echo TCL_MINOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" "define TCL_MINOR_VERSION" >> versions.vc]
!endif
!if [echo TCL_RELEASE_SERIAL = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" TCL_RELEASE_SERIAL >> versions.vc]
!endif
!if [echo TCL_PATCH_LEVEL = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" TCL_PATCH_LEVEL >> versions.vc]
!endif

!if defined(_TK_H)
!if [echo TK_MAJOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V $(_TK_H) "define TK_MAJOR_VERSION" >> versions.vc]
!endif
!if [echo TK_MINOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V $(_TK_H) TK_MINOR_VERSION >> versions.vc]
!endif
!if [echo TK_RELEASE_SERIAL = \>> versions.vc] \
   && [nmakehlp -V "$(_TK_H)" TK_RELEASE_SERIAL >> versions.vc]
!endif
!if [echo TK_PATCH_LEVEL = \>> versions.vc] \
   && [nmakehlp -V $(_TK_H) TK_PATCH_LEVEL >> versions.vc]
!endif
!endif # _TK_H

!include versions.vc

TCL_VERSION	= $(TCL_MAJOR_VERSION)$(TCL_MINOR_VERSION)
TCL_DOTVERSION	= $(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION)
!if [nmakehlp -f $(TCL_PATCH_LEVEL) "a"]
TCL_PATCH_LETTER = a
!elseif [nmakehlp -f $(TCL_PATCH_LEVEL) "b"]
TCL_PATCH_LETTER = b
!else
TCL_PATCH_LETTER = .
!endif

!if defined(_TK_H)

TK_VERSION	= $(TK_MAJOR_VERSION)$(TK_MINOR_VERSION)
TK_DOTVERSION	= $(TK_MAJOR_VERSION).$(TK_MINOR_VERSION)
!if [nmakehlp -f $(TK_PATCH_LEVEL) "a"]
TK_PATCH_LETTER = a
!elseif [nmakehlp -f $(TK_PATCH_LEVEL) "b"]
TK_PATCH_LETTER = b
!else
TK_PATCH_LETTER = .
!endif

!endif

# Set DOTVERSION and VERSION
!if $(DOING_TCL)

DOTVERSION = $(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION)
VERSION = $(TCL_VERSION)

!elseif $(DOING_TK)

DOTVERSION = $(TK_DOTVERSION)
VERSION = $(TK_VERSION)

!else # Doing a non-Tk extension

# If parent makefile has not defined DOTVERSION, try to get it from TEA
# first from a configure.in file, and then from configure.ac
!ifndef DOTVERSION
!if [echo DOTVERSION = \> versions.vc] \
   || [nmakehlp -V $(ROOT)\configure.in ^[$(PROJECT)^] >> versions.vc]
!if [echo DOTVERSION = \> versions.vc] \
   || [nmakehlp -V $(ROOT)\configure.ac ^[$(PROJECT)^] >> versions.vc]
!error *** Could not figure out extension version. Please define DOTVERSION in parent makefile before including rules.vc.
!endif
!endif
!include versions.vc
!endif # DOTVERSION
VERSION         = $(DOTVERSION:.=)

!endif # $(DOING_TCL) ... etc.

# Windows RC files have 3 version components. Ensure this irrespective
# of how many components the package has specified. Basically, ensure
# minimum 4 components by appending 4 0's and then pick out the first 4.
# Also take care of the fact that DOTVERSION may have "a" or "b" instead
# of "." separating the version components.
DOTSEPARATED=$(DOTVERSION:a=.)
DOTSEPARATED=$(DOTSEPARATED:b=.)
!if [echo RCCOMMAVERSION = \> versions.vc] \
  || [for /f "tokens=1,2,3,4,5* delims=." %a in ("$(DOTSEPARATED).0.0.0.0") do echo %a,%b,%c,%d >> versions.vc]
!error *** Could not generate RCCOMMAVERSION ***
!endif
!include versions.vc

########################################################################
# 6. Parse the OPTS macro to work out the requested build configuration.
# 7. Parse the OPTS macro to work out the requested build configuration.
# Based on this, we will construct the actual switches to be passed to the
# compiler and linker using the macros defined in the previous section.
# The following macros are defined by this section based on OPTS
# STATIC_BUILD - 0 -> Tcl is to be built as a shared library
#                1 -> build as a static library and shell
# TCL_THREADS - legacy but always 1 on Windows since winsock requires it.
# DEBUG - 1 -> debug build, 0 -> release builds
# SYMBOLS - 1 -> generate PDB's, 0 -> no PDB's
# PROFILE - 1 -> generate profiling info, 0 -> no profiling
# PGO     - 1 -> profile based optimization, 0 -> no
# MSVCRT  - 1 -> link to dynamic C runtime even when building static Tcl build
#           0 -> link to static C runtime for static Tcl build.
#           Does not impact shared Tcl builds (STATIC_BUILD == 0)
#           Default: 1 for Tcl 8.7 and up, 0 otherwise.
# TCL_USE_STATIC_PACKAGES - 1 -> statically link the registry and dde extensions
#           in the Tcl shell. 0 -> keep them as shared libraries
#           Does not impact shared Tcl builds.
#           in the Tcl and Wish shell. 0 -> keep them as shared libraries. Does
#           not impact shared Tcl builds. Implied by STATIC_BUILD since Tcl 8.7.
# USE_THREAD_ALLOC - 1 -> Use a shared global free pool for allocation.
#           0 -> Use the non-thread allocator.
# UNCHECKED - 1 -> when doing a debug build with symbols, use the release
#           C runtime, 0 -> use the debug C runtime.
# USE_STUBS - 1 -> compile to use stubs interfaces, 0 -> direct linking
# CONFIG_CHECK - 1 -> check current build configuration against Tcl
#           configuration (ignored for Tcl itself)
# _USE_64BIT_TIME_T - forces a build using 64-bit time_t for 32-bit build
#           (CRT library should support this, not needed for Tcl 9.x)
# TCL_UTF_MAX=4 - forces a build allowing 4-byte UTF-8 sequences internally.
#           (Not needed for Tcl 9.x)
# Further, LINKERFLAGS are modified based on above.

# Default values for all the above
STATIC_BUILD	= 0
TCL_THREADS	= 1
DEBUG		= 0
SYMBOLS		= 0
720
721
722
723
724
725
726
727

728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743





744

745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
856
857
858
859
860
861
862

863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884

885
886
887
888
889





890
891
892
893
894
895
896







-
+
















+
+
+
+
+
-
+




-
-
-
-
-







!if [nmakehlp -f $(OPTS) "nomsvcrt"]
!message *** Doing nomsvcrt
MSVCRT		= 0
!else
!if [nmakehlp -f $(OPTS) "msvcrt"]
!message *** Doing msvcrt
!else
!if $(STATIC_BUILD)
!if $(TCL_MAJOR_VERSION) == 8 && $(TCL_MINOR_VERSION) < 7 && $(STATIC_BUILD)
MSVCRT		= 0
!endif
!endif
!endif # [nmakehlp -f $(OPTS) "nomsvcrt"]

!if [nmakehlp -f $(OPTS) "staticpkg"] && $(STATIC_BUILD)
!message *** Doing staticpkg
TCL_USE_STATIC_PACKAGES	= 1
!endif

!if [nmakehlp -f $(OPTS) "nothreads"]
!message *** Compile explicitly for non-threaded tcl
TCL_THREADS = 0
USE_THREAD_ALLOC= 0
!endif

!if [nmakehlp -f $(OPTS) "tcl8"]
!message *** Build for Tcl8
TCL_BUILD_FOR = 8
!endif

!if "$(TCL_MAJOR_VERSION)" == "8"
!if $(TCL_MAJOR_VERSION) == 8
!if [nmakehlp -f $(OPTS) "time64bit"]
!message *** Force 64-bit time_t
_USE_64BIT_TIME_T = 1
!endif

!if [nmakehlp -f $(OPTS) "utfmax"]
!message *** Force allowing 4-byte UTF-8 sequences internally
TCL_UTF_MAX = 4
!endif
!endif

# Yes, it's weird that the "symbols" option controls DEBUG and
# the "pdbs" option controls SYMBOLS. That's historical.
!if [nmakehlp -f $(OPTS) "symbols"]
!message *** Doing symbols
DEBUG		= 1
832
833
834
835
836
837
838
839

840
841
842
843
844
845
846
968
969
970
971
972
973
974

975
976
977
978
979
980
981
982







-
+







MSG=^
This compiler does not support profile guided optimization.
!error $(MSG)
!endif
!endif

################################################################
# 7. Parse the STATS macro to configure code instrumentation
# 8. Parse the STATS macro to configure code instrumentation
# The following macros are set by this section:
# TCL_MEM_DEBUG - 1 -> enables memory allocation instrumentation
#                 0 -> disables
# TCL_COMPILE_DEBUG - 1 -> enables byte compiler logging
#                     0 -> disables

# Default both are off
862
863
864
865
866
867
868
869

870
871
872
873
874
875
876
998
999
1000
1001
1002
1003
1004

1005
1006
1007
1008
1009
1010
1011
1012







-
+







!else
TCL_COMPILE_DEBUG   = 0
!endif

!endif

####################################################################
# 8. Parse the CHECKS macro to configure additional compiler checks
# 9. Parse the CHECKS macro to configure additional compiler checks
# The following macros are set by this section:
# WARNINGS - compiler switches that control the warnings level
# TCL_NO_DEPRECATED - 1 -> disable support for deprecated functions
#                     0 -> enable deprecated functions

# Defaults - Permit deprecated functions and warning level 3
TCL_NO_DEPRECATED	    = 0
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1030
1031
1032
1033
1034
1035
1036





























































































1037
1038
1039
1040
1041
1042
1043







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-







!if [nmakehlp -f $(CHECKS) "64bit"] && [nmakehlp -c -Wp64]
!message *** Doing 64bit portability warnings
WARNINGS		    = $(WARNINGS) -Wp64
!endif

!endif

################################################################
# 9. Extract various version numbers
# For Tcl and Tk, version numbers are extracted from tcl.h and tk.h
# respectively. For extensions, versions are extracted from the
# configure.in or configure.ac from the TEA configuration if it
# exists, and unset otherwise.
# Sets the following macros:
# TCL_MAJOR_VERSION
# TCL_MINOR_VERSION
# TCL_PATCH_LEVEL
# TCL_VERSION
# TK_MAJOR_VERSION
# TK_MINOR_VERSION
# TK_PATCH_LEVEL
# TK_VERSION
# DOTVERSION - set as (for example) 2.5
# VERSION - set as (for example 25)
#--------------------------------------------------------------

!if [echo REM = This file is generated from rules.vc > versions.vc]
!endif
!if [echo TCL_MAJOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" TCL_MAJOR_VERSION >> versions.vc]
!endif
!if [echo TCL_MINOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" TCL_MINOR_VERSION >> versions.vc]
!endif
!if [echo TCL_PATCH_LEVEL = \>> versions.vc] \
   && [nmakehlp -V "$(_TCL_H)" TCL_PATCH_LEVEL >> versions.vc]
!endif

!if defined(_TK_H)
!if [echo TK_MAJOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V $(_TK_H) TK_MAJOR_VERSION >> versions.vc]
!endif
!if [echo TK_MINOR_VERSION = \>> versions.vc] \
   && [nmakehlp -V $(_TK_H) TK_MINOR_VERSION >> versions.vc]
!endif
!if [echo TK_PATCH_LEVEL = \>> versions.vc] \
   && [nmakehlp -V $(_TK_H) TK_PATCH_LEVEL >> versions.vc]
!endif
!endif # _TK_H

!include versions.vc

TCL_VERSION	= $(TCL_MAJOR_VERSION)$(TCL_MINOR_VERSION)
TCL_DOTVERSION	= $(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION)
!if defined(_TK_H)
TK_VERSION	= $(TK_MAJOR_VERSION)$(TK_MINOR_VERSION)
TK_DOTVERSION	= $(TK_MAJOR_VERSION).$(TK_MINOR_VERSION)
!endif

# Set DOTVERSION and VERSION
!if $(DOING_TCL)

DOTVERSION = $(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION)
VERSION = $(TCL_VERSION)

!elseif $(DOING_TK)

DOTVERSION = $(TK_DOTVERSION)
VERSION = $(TK_VERSION)

!else # Doing a non-Tk extension

# If parent makefile has not defined DOTVERSION, try to get it from TEA
# first from a configure.in file, and then from configure.ac
!ifndef DOTVERSION
!if [echo DOTVERSION = \> versions.vc] \
   || [nmakehlp -V $(ROOT)\configure.in ^[$(PROJECT)^] >> versions.vc]
!if [echo DOTVERSION = \> versions.vc] \
   || [nmakehlp -V $(ROOT)\configure.ac ^[$(PROJECT)^] >> versions.vc]
!error *** Could not figure out extension version. Please define DOTVERSION in parent makefile before including rules.vc.
!endif
!endif
!include versions.vc
!endif # DOTVERSION
VERSION         = $(DOTVERSION:.=)

!endif # $(DOING_TCL) ... etc.

# Windows RC files have 3 version components. Ensure this irrespective
# of how many components the package has specified. Basically, ensure
# minimum 4 components by appending 4 0's and then pick out the first 4.
# Also take care of the fact that DOTVERSION may have "a" or "b" instead
# of "." separating the version components.
DOTSEPARATED=$(DOTVERSION:a=.)
DOTSEPARATED=$(DOTSEPARATED:b=.)
!if [echo RCCOMMAVERSION = \> versions.vc] \
  || [for /f "tokens=1,2,3,4,5* delims=." %a in ("$(DOTSEPARATED).0.0.0.0") do echo %a,%b,%c,%d >> versions.vc]
!error *** Could not generate RCCOMMAVERSION ***
!endif
!include versions.vc

################################################################
# 10. Construct output directory and file paths
# Figure-out how to name our intermediate and output directories.
# In order to avoid inadvertent mixing of object files built using
# different compilers, build configurations etc.,
#
1047
1048
1049
1050
1051
1052
1053
1054

1055
1056
1057
1058
1059
1060
1061
1090
1091
1092
1093
1094
1095
1096

1097
1098
1099
1100
1101
1102
1103
1104







-
+







SUFX	    = $(SUFX:s=)
EXT	    = dll
TMP_DIRFULL = $(TMP_DIRFULL:X=)
SUFX	    = $(SUFX:x=)
!else
TMP_DIRFULL = $(TMP_DIRFULL:Dynamic=)
EXT	    = lib
!if !$(MSVCRT)
!if $(MSVCRT) && $(TCL_VERSION) > 86 || !$(MSVCRT) && $(TCL_VERSION) < 87
TMP_DIRFULL = $(TMP_DIRFULL:X=)
SUFX	    = $(SUFX:x=)
!endif
!endif

!if !$(TCL_THREADS) || $(TCL_VERSION) > 86
TMP_DIRFULL = $(TMP_DIRFULL:Threaded=)
1083
1084
1085
1086
1087
1088
1089

1090

1091




1092

1093
1094
1095
1096
1097

1098

1099



1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114

1115



1116
1117
1118
1119
1120
1121
1122
1123
1124

1125
1126
1127
1128
1129
1130
1131
1132
1133

1134



1135
1136
1137
1138
1139
1140
1141
1142
1143

1144
1145
1146
1147
1148



1149

1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167










1168

1169


1170
1171
1172

1173
1174
1175
1176


1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190


1191

1192
1193
1194
1195
1196
1197
1198
1199
1200
1201


1202

1203
1204
1205
1206
1207
1208
1209





1210




1211
1212

1213



1214
1215
1216
1217
1218
1219
1220
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135

1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234

1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246

1247
1248
1249
1250

1251
1252
1253
1254

1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300

1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318







+

+
-
+
+
+
+

+





+

+

+
+
+















+

+
+
+









+









+

+
+
+









+





+
+
+

+

















-
+
+
+
+
+
+
+
+
+
+

+
-
+
+


-
+



-
+
+














+
+

+










+
+

+







+
+
+
+
+
-
+
+
+
+


+

+
+
+







!error *** Could not fully qualify path TMP_DIR=$(TMP_DIR)
!endif
!include nmakehlp.out

# The name of the stubs library for the project being built
STUBPREFIX      = $(PROJECT)stub

#
# Set up paths to various Tcl executables and libraries needed by extensions
#
!if $(DOING_TCL)

# TIP 430. Unused for 8.6 but no harm defining it to allow a common rules.vc
TCL_ZIP_FILE = libtcl$(TCL_MAJOR_VERSION).$(TCL_MINOR_VERSION)$(TCL_PATCH_LETTER)$(TCL_RELEASE_SERIAL).zip
TK_ZIP_FILE = libtk$(TK_MAJOR_VERSION).$(TK_MINOR_VERSION)$(TK_PATCH_LETTER)$(TK_RELEASE_SERIAL).zip

!if $(DOING_TCL)
TCLSHNAME       = $(PROJECT)sh$(VERSION)$(SUFX).exe
TCLSH		= $(OUT_DIR)\$(TCLSHNAME)
TCLIMPLIB	= $(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib
TCLLIBNAME	= $(PROJECT)$(VERSION)$(SUFX).$(EXT)
TCLLIB		= $(OUT_DIR)\$(TCLLIBNAME)
TCLSCRIPTZIP    = $(OUT_DIR)\$(TCL_ZIP_FILE)

!if $(TCL_MAJOR_VERSION) == 8
TCLSTUBLIBNAME	= $(STUBPREFIX)$(VERSION).lib
!else
TCLSTUBLIBNAME	= $(STUBPREFIX).lib
!endif
TCLSTUBLIB	= $(OUT_DIR)\$(TCLSTUBLIBNAME)
TCL_INCLUDES    = -I"$(WIN_DIR)" -I"$(GENERICDIR)"

!else # !$(DOING_TCL)

!if $(TCLINSTALL) # Building against an installed Tcl

# When building extensions, we need to locate tclsh. Depending on version
# of Tcl we are building against, this may or may not have a "t" suffix.
# Try various possibilities in turn.
TCLSH		= $(_TCLDIR)\bin\tclsh$(TCL_VERSION)$(SUFX:t=).exe
!if !exist("$(TCLSH)")
TCLSH           = $(_TCLDIR)\bin\tclsh$(TCL_VERSION)t$(SUFX:t=).exe
!endif

!if $(TCL_MAJOR_VERSION) == 8
TCLSTUBLIB	= $(_TCLDIR)\lib\tclstub$(TCL_VERSION).lib
!else
TCLSTUBLIB	= $(_TCLDIR)\lib\tclstub.lib
!endif
TCLIMPLIB	= $(_TCLDIR)\lib\tcl$(TCL_VERSION)$(SUFX:t=).lib
# When building extensions, may be linking against Tcl that does not add
# "t" suffix (e.g. 8.5 or 8.7). If lib not found check for that possibility.
!if !exist("$(TCLIMPLIB)")
TCLIMPLIB	= $(_TCLDIR)\lib\tcl$(TCL_VERSION)t$(SUFX:t=).lib
!endif
TCL_LIBRARY	= $(_TCLDIR)\lib
TCLREGLIB	= $(_TCLDIR)\lib\tclreg13$(SUFX:t=).lib
TCLDDELIB	= $(_TCLDIR)\lib\tcldde14$(SUFX:t=).lib
TCLSCRIPTZIP	= $(_TCLDIR)\lib\$(TCL_ZIP_FILE)
TCLTOOLSDIR	= \must\have\tcl\sources\to\build\this\target
TCL_INCLUDES    = -I"$(_TCLDIR)\include"

!else # Building against Tcl sources

TCLSH		= $(_TCLDIR)\win\$(BUILDDIRTOP)\tclsh$(TCL_VERSION)$(SUFX:t=).exe
!if !exist($(TCLSH))
TCLSH		= $(_TCLDIR)\win\$(BUILDDIRTOP)\tclsh$(TCL_VERSION)t$(SUFX:t=).exe
!endif
!if $(TCL_MAJOR_VERSION) == 8
TCLSTUBLIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tclstub$(TCL_VERSION).lib
!else
TCLSTUBLIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tclstub.lib
!endif
TCLIMPLIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tcl$(TCL_VERSION)$(SUFX:t=).lib
# When building extensions, may be linking against Tcl that does not add
# "t" suffix (e.g. 8.5 or 8.7). If lib not found check for that possibility.
!if !exist("$(TCLIMPLIB)")
TCLIMPLIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tcl$(TCL_VERSION)t$(SUFX:t=).lib
!endif
TCL_LIBRARY	= $(_TCLDIR)\library
TCLREGLIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tclreg13$(SUFX:t=).lib
TCLDDELIB	= $(_TCLDIR)\win\$(BUILDDIRTOP)\tcldde14$(SUFX:t=).lib
TCLSCRIPTZIP	= $(_TCLDIR)\win\$(BUILDDIRTOP)\$(TCL_ZIP_FILE)
TCLTOOLSDIR	= $(_TCLDIR)\tools
TCL_INCLUDES	= -I"$(_TCLDIR)\generic" -I"$(_TCLDIR)\win"

!endif # TCLINSTALL

!if !$(STATIC_BUILD) && "$(TCL_BUILD_FOR)" == "8"
tcllibs = "$(TCLSTUBLIB)"
!else
tcllibs = "$(TCLSTUBLIB)" "$(TCLIMPLIB)"
!endif

!endif # $(DOING_TCL)

# We need a tclsh that will run on the host machine as part of the build.
# IX86 runs on all architectures.
!ifndef TCLSH_NATIVE
!if "$(MACHINE)" == "IX86" || "$(MACHINE)" == "$(NATIVE_ARCH)"
TCLSH_NATIVE	= $(TCLSH)
!else
!error You must explicitly set TCLSH_NATIVE for cross-compilation
!endif
!endif

# Do the same for Tk and Tk extensions that require the Tk libraries
!if $(DOING_TK) || $(NEED_TK)
WISHNAMEPREFIX = wish
WISHNAME = $(WISHNAMEPREFIX)$(TK_VERSION)$(SUFX).exe
TKLIBNAME	= $(PROJECT)$(TK_VERSION)$(SUFX).$(EXT)
TKLIBNAME8	= tk$(TK_VERSION)$(SUFX).$(EXT)
TKLIBNAME9	= tcl9tk$(TK_VERSION)$(SUFX).$(EXT)
!if $(TCL_MAJOR_VERSION) == 8 || "$(TCL_BUILD_FOR)" == "8"
TKLIBNAME	= tk$(TK_VERSION)$(SUFX).$(EXT)
TKIMPLIBNAME	= tk$(TK_VERSION)$(SUFX).lib
!else
TKLIBNAME	= tcl9tk$(TK_VERSION)$(SUFX).$(EXT)
TKIMPLIBNAME	= tcl9tk$(TK_VERSION)$(SUFX).lib
!endif
!if $(TK_MAJOR_VERSION) == 8
TKSTUBLIBNAME	= tkstub$(TK_VERSION).lib
!else
TKIMPLIBNAME	= tk$(TK_VERSION)$(SUFX).lib
TKSTUBLIBNAME	= tkstub.lib
!endif

!if $(DOING_TK)
WISH 		= $(OUT_DIR)\$(WISHNAME)
WISH		= $(OUT_DIR)\$(WISHNAME)
TKSTUBLIB	= $(OUT_DIR)\$(TKSTUBLIBNAME)
TKIMPLIB	= $(OUT_DIR)\$(TKIMPLIBNAME)
TKLIB		= $(OUT_DIR)\$(TKLIBNAME)
TK_INCLUDES    = -I"$(WIN_DIR)" -I"$(GENERICDIR)"
TK_INCLUDES     = -I"$(WIN_DIR)" -I"$(GENERICDIR)"
TKSCRIPTZIP     = $(OUT_DIR)\$(TK_ZIP_FILE)

!else # effectively NEED_TK

!if $(TKINSTALL) # Building against installed Tk
WISH		= $(_TKDIR)\bin\$(WISHNAME)
TKSTUBLIB	= $(_TKDIR)\lib\$(TKSTUBLIBNAME)
TKIMPLIB	= $(_TKDIR)\lib\$(TKIMPLIBNAME)
# When building extensions, may be linking against Tk that does not add
# "t" suffix (e.g. 8.5 or 8.7). If lib not found check for that possibility.
!if !exist("$(TKIMPLIB)")
TKIMPLIBNAME	= tk$(TK_VERSION)$(SUFX:t=).lib
TKIMPLIB	= $(_TKDIR)\lib\$(TKIMPLIBNAME)
!endif
TK_INCLUDES     = -I"$(_TKDIR)\include"
TKSCRIPTZIP     = $(_TKDIR)\lib\$(TK_ZIP_FILE)

!else # Building against Tk sources

WISH		= $(_TKDIR)\win\$(BUILDDIRTOP)\$(WISHNAME)
TKSTUBLIB	= $(_TKDIR)\win\$(BUILDDIRTOP)\$(TKSTUBLIBNAME)
TKIMPLIB	= $(_TKDIR)\win\$(BUILDDIRTOP)\$(TKIMPLIBNAME)
# When building extensions, may be linking against Tk that does not add
# "t" suffix (e.g. 8.5 or 8.7). If lib not found check for that possibility.
!if !exist("$(TKIMPLIB)")
TKIMPLIBNAME	= tk$(TK_VERSION)$(SUFX:t=).lib
TKIMPLIB	= $(_TKDIR)\win\$(BUILDDIRTOP)\$(TKIMPLIBNAME)
!endif
TK_INCLUDES     = -I"$(_TKDIR)\generic" -I"$(_TKDIR)\win" -I"$(_TKDIR)\xlib"
TKSCRIPTZIP     = $(_TKDIR)\win\$(BUILDDIRTOP)\$(TK_ZIP_FILE)

!endif # TKINSTALL

tklibs = "$(TKSTUBLIB)" "$(TKIMPLIB)"

!endif # $(DOING_TK)
!endif # $(DOING_TK) || $(NEED_TK)

# Various output paths
PRJIMPLIB	= $(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib
# Even when building against Tcl 9, PRJLIBNAME8 must have "t"
PRJLIBNAME8	= $(PROJECT)$(VERSION)t$(SUFX:t=).$(EXT)
# Even when building against Tcl 8, PRJLIBNAME9 must not have "t"
PRJLIBNAME9	= tcl9$(PROJECT)$(VERSION)$(SUFX:t=).$(EXT)
!if $(TCL_MAJOR_VERSION) == 8 || "$(TCL_BUILD_FOR)" == "8"
PRJLIBNAME	= $(PROJECT)$(VERSION)$(SUFX).$(EXT)
PRJLIBNAME	= $(PRJLIBNAME8)
!else
PRJLIBNAME	= $(PRJLIBNAME9)
!endif
PRJLIB		= $(OUT_DIR)\$(PRJLIBNAME)

!if $(TCL_MAJOR_VERSION) == 8
PRJSTUBLIBNAME	= $(STUBPREFIX)$(VERSION).lib
!else
PRJSTUBLIBNAME	= $(STUBPREFIX).lib
!endif
PRJSTUBLIB	= $(OUT_DIR)\$(PRJSTUBLIBNAME)

# If extension parent makefile has not defined a resource definition file,
# we will generate one from standard template.
!if !$(DOING_TCL) && !$(DOING_TK) && !$(STATIC_BUILD)
!ifdef RCFILE
RESFILE = $(TMP_DIR)\$(RCFILE:.rc=.res)
1268
1269
1270
1271
1272
1273
1274
1275

1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289


1290
1291
1292
1293
1294
1295
1296
1366
1367
1368
1369
1370
1371
1372

1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385


1386
1387
1388
1389
1390
1391
1392
1393
1394







-
+












-
-
+
+







# 12. Set up actual options to be passed to the compiler and linker
# Now we have all the information we need, set up the actual flags and
# options that we will pass to the compiler and linker. The main
# makefile should use these in combination with whatever other flags
# and switches are specific to it.
# The following macros are defined, names are for historical compatibility:
# OPTDEFINES - /Dxxx C macro flags based on user-specified OPTS
# COMPILERFLAGS - /Dxxx C macro flags independent of any configuration opttions
# COMPILERFLAGS - /Dxxx C macro flags independent of any configuration options
# crt - Compiler switch that selects the appropriate C runtime
# cdebug - Compiler switches related to debug AND optimizations
# cwarn - Compiler switches that set warning levels
# cflags - complete compiler switches (subsumes cdebug and cwarn)
# ldebug - Linker switches controlling debug information and optimization
# lflags - complete linker switches (subsumes ldebug) except subsystem type
# dlllflags - complete linker switches to build DLLs (subsumes lflags)
# conlflags - complete linker switches for console program (subsumes lflags)
# guilflags - complete linker switches for GUI program (subsumes lflags)
# baselibs - minimum Windows libraries required. Parent makefile can
#    define PRJ_LIBS before including rules.rc if additional libs are needed

OPTDEFINES	= /DSTDC_HEADERS
!if $(VCVERSION) >= 1600
OPTDEFINES	= /DSTDC_HEADERS /DUSE_NMAKE=1
!if $(VCVERSION) > 1600
OPTDEFINES	= $(OPTDEFINES) /DHAVE_STDINT_H=1
!else
OPTDEFINES	= $(OPTDEFINES) /DMP_NO_STDINT=1
!endif
!if $(VCVERSION) >= 1800
OPTDEFINES	= $(OPTDEFINES) /DHAVE_INTTYPES_H=1 /DHAVE_STDBOOL_H=1
!endif
1307
1308
1309
1310
1311
1312
1313
1314

1315
1316
1317
1318
1319
1320
1321
1405
1406
1407
1408
1409
1410
1411

1412
1413
1414
1415
1416
1417
1418
1419







-
+







OPTDEFINES	= $(OPTDEFINES) /DUSE_THREAD_ALLOC=1
!endif
!endif
!if $(STATIC_BUILD)
OPTDEFINES	= $(OPTDEFINES) /DSTATIC_BUILD
!elseif $(TCL_VERSION) > 86
OPTDEFINES	= $(OPTDEFINES) /DTCL_WITH_EXTERNAL_TOMMATH
!if "$(MACHINE)" == "AMD64"
!if "$(MACHINE)" == "AMD64" || "$(MACHINE)" == "ARM64"
OPTDEFINES	= $(OPTDEFINES) /DMP_64BIT
!endif
!endif
!if $(TCL_NO_DEPRECATED)
OPTDEFINES	= $(OPTDEFINES) /DTCL_NO_DEPRECATED
!endif

1335
1336
1337
1338
1339
1340
1341
1342

1343
1344
1345
1346
1347
1348
1349

1350
1351
1352
1353
1354
1355
1356

1357
1358

1359
1360
1361
1362
1363
1364
1365
1366
1367
1368



1369
1370
1371
1372
1373
1374
1375
1433
1434
1435
1436
1437
1438
1439

1440
1441
1442
1443
1444
1445
1446

1447
1448
1449
1450


1451

1452


1453
1454
1455
1456
1457
1458
1459
1460



1461
1462
1463
1464
1465
1466
1467
1468
1469
1470







-
+






-
+



-
-

-
+
-
-
+







-
-
-
+
+
+







!if $(OPTIMIZING)
OPTDEFINES	= $(OPTDEFINES) /DTCL_CFG_OPTIMIZED
!endif
!endif
!if $(PROFILE)
OPTDEFINES	= $(OPTDEFINES) /DTCL_CFG_PROFILED
!endif
!if "$(MACHINE)" == "AMD64"
!if "$(MACHINE)" == "AMD64" || "$(MACHINE)" == "ARM64"
OPTDEFINES	= $(OPTDEFINES) /DTCL_CFG_DO64BIT
!endif
!if $(VCVERSION) < 1300
OPTDEFINES	= $(OPTDEFINES) /DNO_STRTOI64=1
!endif

!if "$(TCL_MAJOR_VERSION)" == "8"
!if $(TCL_MAJOR_VERSION) == 8
!if "$(_USE_64BIT_TIME_T)" == "1"
OPTDEFINES	= $(OPTDEFINES) /D_USE_64BIT_TIME_T=1
!endif
!if "$(TCL_UTF_MAX)" == "4"
OPTDEFINES	= $(OPTDEFINES) /DTCL_UTF_MAX=4
!endif

!if "$(TCL_BUILD_FOR)" == "8"
# _ATL_XP_TARGETING - Newer SDK's need this to build for XP
COMPILERFLAGS  = /D_ATL_XP_TARGETING
OPTDEFINES	= $(OPTDEFINES) /DTCL_MAJOR_VERSION=8 /DTK_MAJOR_VERSION=8
!endif

# Like the TEA system only set this non empty for non-Tk extensions
# Note: some extensions use PACKAGE_NAME and others use PACKAGE_TCLNAME
# so we pass both
!if !$(DOING_TCL) && !$(DOING_TK)
PKGNAMEFLAGS = /DPACKAGE_NAME="\"$(PRJ_PACKAGE_TCLNAME)\"" \
               /DPACKAGE_TCLNAME="\"$(PRJ_PACKAGE_TCLNAME)\"" \
               /DPACKAGE_VERSION="\"$(DOTVERSION)\"" \
               /DMODULE_SCOPE=extern
	/DPACKAGE_TCLNAME="\"$(PRJ_PACKAGE_TCLNAME)\"" \
	/DPACKAGE_VERSION="\"$(DOTVERSION)\"" \
	/DMODULE_SCOPE=extern
!endif

# crt picks the C run time based on selected OPTS
!if $(MSVCRT)
!if $(DEBUG) && !$(UNCHECKED)
crt = -MDd
!else
1394
1395
1396
1397
1398
1399
1400
1401
1402


1403
1404

1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418





1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435




1436
1437
1438
1439
1440
1441
1442
1489
1490
1491
1492
1493
1494
1495


1496
1497
1498

1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546







-
-
+
+

-
+














+
+
+
+
+

















+
+
+
+







cdebug = $(OPTIMIZATIONS)
!if $(SYMBOLS)
cdebug = $(cdebug) -Zi
!endif

!endif # $(DEBUG)

# cwarn includes default warning levels.
cwarn = $(WARNINGS)
# cwarn includes default warning levels, also C4090 (buggy) and C4146 is useless.
cwarn = $(WARNINGS) -wd4090 -wd4146

!if "$(MACHINE)" == "AMD64"
!if "$(MACHINE)" == "AMD64" || "$(MACHINE)" == "ARM64"
# Disable pointer<->int warnings related to cast between different sizes
# There are a gadzillion of these due to use of ClientData and
# clutter up compiler
# output increasing chance of a real warning getting lost. So disable them.
# Eventually some day, Tcl will be 64-bit clean.
cwarn = $(cwarn) -wd4311 -wd4312
!endif

### Common compiler options that are architecture specific
!if "$(MACHINE)" == "ARM"
carch = /D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE
!else
carch =
!endif

# cpuid is only available on intel machines
!if "$(MACHINE)" == "IX86" || "$(MACHINE)" == "AMD64"
carch = $(carch) /DHAVE_CPUID=1
!endif

!if $(DEBUG)
# Turn warnings into errors
cwarn = $(cwarn) -WX
!endif

INCLUDES = $(TCL_INCLUDES) $(TK_INCLUDES) $(PRJ_INCLUDES)
!if !$(DOING_TCL) && !$(DOING_TK)
INCLUDES = $(INCLUDES) -I"$(GENERICDIR)" -I"$(WIN_DIR)" -I"$(COMPATDIR)"
!endif

# These flags are defined roughly in the order of the pre-reform
# rules.vc/makefile.vc to help visually compare that the pre- and
# post-reform build logs

# cflags contains generic flags used for building practically all object files
cflags = -nologo -c $(COMPILERFLAGS) $(carch) $(cwarn) -Fp$(TMP_DIR)^\ $(cdebug)

!if $(TCL_MAJOR_VERSION) == 8 && $(TCL_MINOR_VERSION) < 7
cflags = $(cflags) -DTcl_Size=int
!endif

# appcflags contains $(cflags) and flags for building the application
# object files (e.g. tclsh, or wish) pkgcflags contains $(cflags) plus
# flags used for building shared object files The two differ in the
# BUILD_$(PROJECT) macro which should be defined only for the shared
# library *implementation* and not for its caller interface

1452
1453
1454
1455
1456
1457
1458
1459

1460
1461
1462
1463
1464
1465
1466
1556
1557
1558
1559
1560
1561
1562

1563
1564
1565
1566
1567
1568
1569
1570







-
+







# here irrespective of the OPTS setting.
#
# TBD - tclvfs has a comment that stubs libs should not be compiled with -GL
# without stating why. Tcl itself compiled stubs libs with this flag.
# so we do not remove it from cflags. -GL may prevent extensions
# compiled with one VC version to fail to link against stubs library
# compiled with another VC version. Check for this and fix accordingly.
stubscflags = $(cflags) $(PKGNAMEFLAGS) $(PRJ_DEFINES) $(OPTDEFINES) -Zl /DSTATIC_BUILD $(INCLUDES) $(USE_STUBS_DEFS)
stubscflags = $(cflags) $(PKGNAMEFLAGS) $(PRJ_DEFINES) $(OPTDEFINES) /Zl /GL- /DSTATIC_BUILD $(INCLUDES) $(USE_STUBS_DEFS)

# Link flags

!if $(DEBUG)
ldebug	= -debug -debugtype:cv
!else
ldebug	= -release -opt:ref -opt:icf,3
1474
1475
1476
1477
1478
1479
1480
1481

1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1578
1579
1580
1581
1582
1583
1584

1585












1586
1587
1588
1589
1590
1591
1592







-
+
-
-
-
-
-
-
-
-
-
-
-
-







ldebug= $(ldebug) -profile
!endif

### Declarations common to all linker versions
lflags	= -nologo -machine:$(MACHINE) $(LINKERFLAGS) $(ldebug)

!if $(MSVCRT) && !($(DEBUG) && !$(UNCHECKED)) && $(VCVERSION) >= 1900
lflags	= $(lflags) -nodefaultlib:libucrt.lib
lflags	= $(lflags) -nodefaultlib:ucrt.lib
!endif

# Old linkers (Visual C++ 6 in particular) will link for fast loading
# on Win98. Since we do not support Win98 any more, we specify nowin98
# as recommended for NT and later. However, this is only required by
# IX86 on older compilers and only needed if we are not doing a static build.

!if "$(MACHINE)" == "IX86" && !$(STATIC_BUILD)
!if [nmakehlp -l -opt:nowin98 $(LINKER_TESTFLAGS)]
# Align sections for PE size savings.
lflags	= $(lflags) -opt:nowin98
!endif
!endif

dlllflags = $(lflags) -dll
conlflags = $(lflags) -subsystem:console
guilflags = $(lflags) -subsystem:windows

# Libraries that are required for every image.
1528
1529
1530
1531
1532
1533
1534
1535

1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551

1552
1553





1554
1555

1556
1557





1558
1559
1560
1561
1562
1563
1564
1565


1566
1567
1568
1569
1570
1571
1572
1620
1621
1622
1623
1624
1625
1626

1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645

1646
1647
1648
1649
1650
1651
1652
1653
1654

1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676







-
+
















+

-
+
+
+
+
+


+

-
+
+
+
+
+








+
+








LIBCMD = $(lib32) -nologo $(LINKERFLAGS) -out:$@
DLLCMD = $(link32) $(dlllflags) -out:$@ $(baselibs) $(tcllibs) $(tklibs)

CONEXECMD = $(link32) $(conlflags) -out:$@ $(baselibs) $(tcllibs) $(tklibs)
GUIEXECMD = $(link32) $(guilflags) -out:$@ $(baselibs) $(tcllibs) $(tklibs)
RESCMD  = $(rc32) -fo $@ -r -i "$(GENERICDIR)" -i "$(TMP_DIR)" \
	    $(TCL_INCLUDES) \
	    $(TCL_INCLUDES) /DSTATIC_BUILD=$(STATIC_BUILD) \
	    /DDEBUG=$(DEBUG) -d UNCHECKED=$(UNCHECKED) \
	    /DCOMMAVERSION=$(RCCOMMAVERSION) \
	    /DDOTVERSION=\"$(DOTVERSION)\" \
	    /DVERSION=\"$(VERSION)\" \
	    /DSUFX=\"$(SUFX)\" \
	    /DPROJECT=\"$(PROJECT)\" \
	    /DPRJLIBNAME=\"$(PRJLIBNAME)\"

!ifndef DEFAULT_BUILD_TARGET
DEFAULT_BUILD_TARGET = $(PROJECT)
!endif

default-target: $(DEFAULT_BUILD_TARGET)

!if $(MULTIPLATFORM_INSTALL)
default-pkgindex:
	@echo if {[package vsatisfies [package provide Tcl] 9.0]} { > $(OUT_DIR)\pkgIndex.tcl
	@echo package ifneeded $(PRJ_PACKAGE_TCLNAME) $(DOTVERSION) \
	    [list load [file join $$dir $(PLATFORM_IDENTIFY) $(PRJLIBNAME)]] > $(OUT_DIR)\pkgIndex.tcl
	    [list load [file join $$dir $(PLATFORM_IDENTIFY) $(PRJLIBNAME9)]] >> $(OUT_DIR)\pkgIndex.tcl
	@echo } else { >> $(OUT_DIR)\pkgIndex.tcl
	@echo package ifneeded $(PRJ_PACKAGE_TCLNAME) $(DOTVERSION) \
	    [list load [file join $$dir $(PLATFORM_IDENTIFY) $(PRJLIBNAME8)]] >> $(OUT_DIR)\pkgIndex.tcl
	@echo } >> $(OUT_DIR)\pkgIndex.tcl
!else
default-pkgindex:
	@echo if {[package vsatisfies [package provide Tcl] 9.0]} { > $(OUT_DIR)\pkgIndex.tcl
	@echo package ifneeded $(PRJ_PACKAGE_TCLNAME) $(DOTVERSION) \
	    [list load [file join $$dir $(PRJLIBNAME)]] > $(OUT_DIR)\pkgIndex.tcl
	    [list load [file join $$dir $(PRJLIBNAME9)]] >> $(OUT_DIR)\pkgIndex.tcl
	@echo } else { >> $(OUT_DIR)\pkgIndex.tcl
	@echo package ifneeded $(PRJ_PACKAGE_TCLNAME) $(DOTVERSION) \
	    [list load [file join $$dir $(PRJLIBNAME8)]] >> $(OUT_DIR)\pkgIndex.tcl
	@echo } >> $(OUT_DIR)\pkgIndex.tcl
!endif

default-pkgindex-tea:
	@if exist $(ROOT)\pkgIndex.tcl.in nmakehlp -s << $(ROOT)\pkgIndex.tcl.in > $(OUT_DIR)\pkgIndex.tcl
@PACKAGE_VERSION@    $(DOTVERSION)
@PACKAGE_NAME@       $(PRJ_PACKAGE_TCLNAME)
@PACKAGE_TCLNAME@    $(PRJ_PACKAGE_TCLNAME)
@PKG_LIB_FILE@       $(PRJLIBNAME)
@PKG_LIB_FILE8@      $(PRJLIBNAME8)
@PKG_LIB_FILE9@      $(PRJLIBNAME9)
<<

default-install: default-install-binaries default-install-libraries
!if $(SYMBOLS)
default-install: default-install-pdbs
!endif

1582
1583
1584
1585
1586
1587
1588

1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601


1602
1603
1604
1605
1606
1607
1608
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715







+













+
+







	@$(CPY) $(PRJLIB) "$(LIB_INSTALL_DIR)" >NUL

# Alias for default-install-scripts
default-install-libraries: default-install-scripts

default-install-scripts: $(OUT_DIR)\pkgIndex.tcl
	@echo Installing libraries to '$(SCRIPT_INSTALL_DIR)'
	@if not exist "$(SCRIPT_INSTALL_DIR)" mkdir "$(SCRIPT_INSTALL_DIR)"
	@if exist $(LIBDIR) $(CPY) $(LIBDIR)\*.tcl "$(SCRIPT_INSTALL_DIR)"
	@echo Installing package index in '$(SCRIPT_INSTALL_DIR)'
	@$(CPY) $(OUT_DIR)\pkgIndex.tcl $(SCRIPT_INSTALL_DIR)

default-install-stubs:
	@echo Installing stubs library to '$(SCRIPT_INSTALL_DIR)'
	@if not exist "$(SCRIPT_INSTALL_DIR)" mkdir "$(SCRIPT_INSTALL_DIR)"
	@$(CPY) $(PRJSTUBLIB) "$(SCRIPT_INSTALL_DIR)" >NUL

default-install-pdbs:
	@echo Installing PDBs to '$(LIB_INSTALL_DIR)'
	@if not exist "$(LIB_INSTALL_DIR)" mkdir "$(LIB_INSTALL_DIR)"
	@$(CPY) "$(OUT_DIR)\*.pdb" "$(LIB_INSTALL_DIR)\"

# "emacs font-lock highlighting fix

default-install-docs-html:
	@echo Installing documentation files to '$(DOC_INSTALL_DIR)'
	@if not exist "$(DOC_INSTALL_DIR)" mkdir "$(DOC_INSTALL_DIR)"
	@if exist $(DOCDIR) for %f in ("$(DOCDIR)\*.html" "$(DOCDIR)\*.css" "$(DOCDIR)\*.png") do @$(COPY) %f "$(DOC_INSTALL_DIR)"

default-install-docs-n:
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701








1702
1703
1704
1705

1706
1707
1708
1709
1710
1711
1712
1794
1795
1796
1797
1798
1799
1800








1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811

1812
1813
1814
1815
1816
1817
1818
1819







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+



-
+







#endif
 FILEOS		VOS_NT_WINDOWS32
 FILETYPE	VFT_DLL
 FILESUBTYPE	0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "FileDescription",  "Tcl extension " PROJECT
            VALUE "OriginalFilename", PRJLIBNAME
            VALUE "FileVersion",      DOTVERSION
            VALUE "ProductName",      "Package " PROJECT " for Tcl"
            VALUE "ProductVersion",   DOTVERSION
        END
	BLOCK "040904b0"
	BEGIN
	    VALUE "FileDescription",  "Tcl extension " PROJECT
	    VALUE "OriginalFilename", PRJLIBNAME
	    VALUE "FileVersion",      DOTVERSION
	    VALUE "ProductName",      "Package " PROJECT " for Tcl"
	    VALUE "ProductVersion",   DOTVERSION
	END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
	VALUE "Translation", 0x409, 1200
    END
END

<<

!endif # ifdef RCFILE

1760
1761
1762
1763
1764
1765
1766
1767
1768


1769
1770
1771
1772
1773
1774
1775
1867
1868
1869
1870
1871
1872
1873


1874
1875
1876
1877
1878
1879
1880
1881
1882







-
-
+
+







!if !$(DOING_TCL)

!if $(TCLINSTALL) # Building against an installed Tcl
!if exist("$(_TCLDIR)\lib\nmake\tcl.nmake")
TCLNMAKECONFIG = "$(_TCLDIR)\lib\nmake\tcl.nmake"
!endif
!else # !$(TCLINSTALL) - building against Tcl source
!if exist("$(OUT_DIR)\tcl.nmake")
TCLNMAKECONFIG = "$(OUT_DIR)\tcl.nmake"
!if exist("$(_TCLDIR)\win\$(BUILDDIRTOP)\tcl.nmake")
TCLNMAKECONFIG	= "$(_TCLDIR)\win\$(BUILDDIRTOP)\tcl.nmake"
!endif
!endif # TCLINSTALL

!if $(CONFIG_CHECK)
!ifdef TCLNMAKECONFIG
!include $(TCLNMAKECONFIG)

Added win/svnmanifest.in.

1
+
svn-r
Changes to win/targets.vc.
1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







#------------------------------------------------------------- -*- makefile -*-
# targets.vc --
#
# Part of the nmake based build system for Tcl and its extensions.
# This file defines some standard targets for the convenience of extensions
# and can be optionally included by the extension makefile.
# See TIP 477 (https://core.tcl.tk/tips/doc/trunk/tip/477.md) for docs.
# See TIP 477 (https://core.tcl-lang.org/tips/doc/main/tip/477.md) for docs.

$(PROJECT): setup pkgindex $(PRJLIB)

!ifdef PRJ_STUBOBJS
$(PROJECT): $(PRJSTUBLIB)
$(PRJSTUBLIB): $(PRJ_STUBOBJS)
	$(LIBCMD) $**
49
50
51
52
53
54
55

56
57
58
59
60
61
62
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63







+







# Unlike the other default targets, these cannot be in rules.vc because
# the executed command depends on existence of macro PRJ_HEADERS_PUBLIC
# that the parent makefile will not define until after including rules-ext.vc
!if "$(PRJ_HEADERS_PUBLIC)" != ""
default-install: default-install-headers
default-install-headers:
	@echo Installing headers to '$(INCLUDE_INSTALL_DIR)'
	@if not exist "$(INCLUDE_INSTALL_DIR)" $(MKDIR) "$(INCLUDE_INSTALL_DIR)"
	@for %f in ($(PRJ_HEADERS_PUBLIC)) do @$(COPY) %f "$(INCLUDE_INSTALL_DIR)"
!endif

!if "$(DISABLE_STANDARD_TARGETS)" == ""
DISABLE_STANDARD_TARGETS = 0
!endif

Changes to win/thread.rc.
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51











52
53
54
55

56
57
34
35
36
37
38
39
40











41
42
43
44
45
46
47
48
49
50
51
52
53
54

55
56
57







-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+



-
+


#endif
 FILEOS     VOS_NT_WINDOWS32
 FILETYPE     VFT_DLL
 FILESUBTYPE     0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0" /* LANG_ENGLISH/SUBLANG_ENGLISH_US, Unicode CP */
        BEGIN
            VALUE "FileDescription", "Threading extension library for Tcl"
            VALUE "OriginalFilename", PRJLIBNAME
            VALUE "CompanyName", "NONE! Open-sourced with no owner\0"
            VALUE "FileVersion", DOTVERSION
            VALUE "LegalCopyright", "Under BSD license\0"
            VALUE "ProductName", "Tcl for Windows\0"
            VALUE "ProductVersion", DOTVERSION
            VALUE "Authors", "Brent Welch,\r\n" "Andreas Kupries, \r\n" "David Gravereaux,\r\n" "Zoran Vasiljevic" "\0"
        END
	BLOCK "040904b0" /* LANG_ENGLISH/SUBLANG_ENGLISH_US, Unicode CP */
	BEGIN
	    VALUE "FileDescription", "Threading extension library for Tcl"
	    VALUE "OriginalFilename", PRJLIBNAME
	    VALUE "CompanyName", "NONE! Open-sourced with no owner\0"
	    VALUE "FileVersion", DOTVERSION
	    VALUE "LegalCopyright", "Under BSD license\0"
	    VALUE "ProductName", "Tcl for Windows\0"
	    VALUE "ProductVersion", DOTVERSION
	    VALUE "Authors", "Brent Welch,\r\n" "Andreas Kupries, \r\n" "David Gravereaux,\r\n" "Zoran Vasiljevic" "\0"
	END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
	VALUE "Translation", 0x409, 1200
    END
END
Added win/threadUuid.h.in.

1
+
#define THREAD_VERSION_UUID \
Added win/x86_64-w64-mingw32-nmakehlp.exe.

cannot compute difference between binary files