Artifact
397a24337f5554e0bda0255239495f472158bcdb:
Attachment "TCLTtest.patch" to
ticket [1001997fff]
added by
dgp
2004-08-02 22:14:50.
0000: 49 6e 64 65 78 3a 20 74 65 73 74 73 2f 63 6f 6d Index: tests/com
0010: 70 69 6c 65 2e 74 65 73 74 0a 3d 3d 3d 3d 3d 3d pile.test.======
0020: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0030: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0040: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
0050: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 0a 52 43 =============.RC
0060: 53 20 66 69 6c 65 3a 20 2f 63 76 73 72 6f 6f 74 S file: /cvsroot
0070: 2f 74 63 6c 2f 74 63 6c 2f 74 65 73 74 73 2f 63 /tcl/tcl/tests/c
0080: 6f 6d 70 69 6c 65 2e 74 65 73 74 2c 76 0a 72 65 ompile.test,v.re
0090: 74 72 69 65 76 69 6e 67 20 72 65 76 69 73 69 6f trieving revisio
00a0: 6e 20 31 2e 33 30 0a 64 69 66 66 20 2d 75 20 2d n 1.30.diff -u -
00b0: 72 31 2e 33 30 20 63 6f 6d 70 69 6c 65 2e 74 65 r1.30 compile.te
00c0: 73 74 0a 2d 2d 2d 20 74 65 73 74 73 2f 63 6f 6d st.--- tests/com
00d0: 70 69 6c 65 2e 74 65 73 74 09 32 30 20 4e 6f 76 pile.test.20 Nov
00e0: 20 32 30 30 33 20 30 30 3a 31 36 3a 30 30 20 2d 2003 00:16:00 -
00f0: 30 30 30 30 09 31 2e 33 30 0a 2b 2b 2b 20 74 65 0000.1.30.+++ te
0100: 73 74 73 2f 63 6f 6d 70 69 6c 65 2e 74 65 73 74 sts/compile.test
0110: 09 32 20 41 75 67 20 32 30 30 34 20 31 35 3a 31 .2 Aug 2004 15:1
0120: 33 3a 32 35 20 2d 30 30 30 30 0a 40 40 20 2d 33 3:25 -0000.@@ -3
0130: 32 30 2c 36 20 2b 33 32 30 2c 36 33 20 40 40 0a 20,6 +320,63 @@.
0140: 20 20 20 20 20 6c 69 73 74 20 5b 63 61 74 63 68 list [catch
0150: 20 63 72 61 73 68 20 6d 73 67 5d 20 24 6d 73 67 crash msg] $msg
0160: 0a 20 7d 20 7b 31 20 7b 73 79 6e 74 61 78 20 65 . } {1 {syntax e
0170: 72 72 6f 72 20 69 6e 20 65 78 70 72 65 73 73 69 rror in expressi
0180: 6f 6e 20 22 61 2b 32 22 3a 20 76 61 72 69 61 62 on "a+2": variab
0190: 6c 65 20 72 65 66 65 72 65 6e 63 65 73 20 72 65 le references re
01a0: 71 75 69 72 65 20 70 72 65 63 65 64 69 6e 67 20 quire preceding
01b0: 24 7d 7d 0a 20 0a 2b 74 65 73 74 20 63 6f 6d 70 $}}. .+test comp
01c0: 69 6c 65 2d 31 32 2e 34 20 7b 54 63 6c 43 6c 65 ile-12.4 {TclCle
01d0: 61 6e 75 70 4c 69 74 65 72 61 6c 54 61 62 6c 65 anupLiteralTable
01e0: 20 73 65 67 66 61 75 6c 74 7d 20 7b 0a 2b 20 20 segfault} {.+
01f0: 20 20 23 20 54 63 6c 20 42 75 67 20 31 30 30 31 # Tcl Bug 1001
0200: 39 39 37 0a 2b 20 20 20 20 23 20 48 65 72 65 2c 997.+ # Here,
0210: 20 77 65 27 72 65 20 74 72 79 69 6e 67 20 74 6f we're trying to
0220: 20 74 65 73 74 20 61 20 63 61 73 65 20 74 68 61 test a case tha
0230: 74 20 63 61 75 73 65 73 20 61 20 63 72 61 73 68 t causes a crash
0240: 20 69 6e 0a 2b 20 20 20 20 23 20 54 63 6c 43 6c in.+ # TclCl
0250: 65 61 6e 75 70 4c 69 74 65 72 61 6c 54 61 62 6c eanupLiteralTabl
0260: 65 2e 20 20 54 68 65 20 63 6f 6e 64 69 74 69 6f e. The conditio
0270: 6e 73 20 74 68 61 74 20 77 65 27 72 65 20 74 72 ns that we're tr
0280: 79 69 6e 67 20 74 6f 0a 2b 20 20 20 20 23 20 65 ying to.+ # e
0290: 73 74 61 62 6c 69 73 68 20 61 72 65 3a 0a 2b 20 stablish are:.+
02a0: 20 20 20 23 20 2d 20 54 63 6c 43 6c 65 61 6e 75 # - TclCleanu
02b0: 70 4c 69 74 65 72 61 6c 54 61 62 6c 65 20 69 73 pLiteralTable is
02c0: 20 61 74 74 65 6d 70 74 69 6e 67 20 74 6f 20 63 attempting to c
02d0: 6c 65 61 6e 20 75 70 20 61 20 62 79 74 65 63 6f lean up a byteco
02e0: 64 65 0a 2b 20 20 20 20 23 20 20 20 6f 62 6a 65 de.+ # obje
02f0: 63 74 20 69 6e 20 74 68 65 20 6c 69 74 65 72 61 ct in the litera
0300: 6c 20 74 61 62 6c 65 2e 0a 2b 20 20 20 20 23 20 l table..+ #
0310: 2d 20 54 68 65 20 62 79 74 65 63 6f 64 65 20 6f - The bytecode o
0320: 62 6a 65 63 74 20 69 6e 20 71 75 65 73 74 69 6f bject in questio
0330: 6e 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 6f n contains the o
0340: 6e 6c 79 20 72 65 66 65 72 65 6e 63 65 0a 2b 20 nly reference.+
0350: 20 20 20 23 20 20 20 74 6f 20 61 6e 6f 74 68 65 # to anothe
0360: 72 20 6c 69 74 65 72 61 6c 2e 0a 2b 20 20 20 20 r literal..+
0370: 23 20 2d 20 54 68 65 20 6c 69 74 65 72 61 6c 20 # - The literal
0380: 69 6e 20 71 75 65 73 74 69 6f 6e 20 69 73 20 69 in question is i
0390: 6e 20 74 68 65 20 73 61 6d 65 20 68 61 73 68 20 n the same hash
03a0: 62 75 63 6b 65 74 20 61 73 20 74 68 65 20 62 79 bucket as the by
03b0: 74 65 63 6f 64 65 0a 2b 20 20 20 20 23 20 20 20 tecode.+ #
03c0: 6f 62 6a 65 63 74 2c 20 61 6e 64 20 69 6d 6d 65 object, and imme
03d0: 64 69 61 74 65 6c 79 20 66 6f 6c 6c 6f 77 73 20 diately follows
03e0: 69 74 20 69 6e 20 74 68 65 20 63 68 61 69 6e 2e it in the chain.
03f0: 0a 2b 20 20 20 20 23 20 53 69 6e 63 65 20 6e 65 .+ # Since ne
0400: 77 6c 79 20 72 65 67 69 73 74 65 72 65 64 20 6c wly registered l
0410: 69 74 65 72 61 6c 73 20 61 72 65 20 61 64 64 65 iterals are adde
0420: 64 20 61 74 20 74 68 65 20 46 52 4f 4e 54 20 6f d at the FRONT o
0430: 66 20 74 68 65 0a 2b 20 20 20 20 23 20 62 75 63 f the.+ # buc
0440: 6b 65 74 20 63 68 61 69 6e 73 2c 20 61 6e 64 20 ket chains, and
0450: 73 69 6e 63 65 20 74 68 65 20 62 79 74 65 63 6f since the byteco
0460: 64 65 20 6f 62 6a 65 63 74 20 69 73 20 72 65 67 de object is reg
0470: 69 73 74 65 72 65 64 20 62 65 66 6f 72 65 0a 2b istered before.+
0480: 20 20 20 20 23 20 69 74 73 20 6c 69 74 65 72 61 # its litera
0490: 6c 73 2c 20 74 68 69 73 20 69 73 20 64 69 66 66 ls, this is diff
04a0: 69 63 75 6c 74 20 74 6f 20 61 63 68 69 65 76 65 icult to achieve
04b0: 2e 20 20 57 68 61 74 20 77 65 20 64 6f 20 69 73 . What we do is
04c0: 3a 0a 2b 20 20 20 20 23 20 20 28 61 29 20 64 6f :.+ # (a) do
04d0: 20 61 20 5b 6e 61 6d 65 73 70 61 63 65 20 65 76 a [namespace ev
04e0: 61 6c 5d 20 6f 66 20 61 20 73 74 72 69 6e 67 20 al] of a string
04f0: 74 68 61 74 27 73 20 63 61 6c 63 75 6c 61 74 65 that's calculate
0500: 64 20 74 6f 0a 2b 20 20 20 20 23 20 20 20 20 20 d to.+ #
0510: 20 68 61 73 68 20 69 6e 74 6f 20 74 68 65 20 73 hash into the s
0520: 61 6d 65 20 62 75 63 6b 65 74 20 61 73 20 61 20 ame bucket as a
0530: 6c 69 74 65 72 61 6c 20 74 68 61 74 20 69 74 20 literal that it
0540: 63 6f 6e 74 61 69 6e 73 2e 0a 2b 20 20 20 20 23 contains..+ #
0550: 20 20 20 20 20 20 49 6e 20 74 68 69 73 20 63 61 In this ca
0560: 73 65 2c 20 74 68 65 20 73 63 72 69 70 74 20 61 se, the script a
0570: 6e 64 20 74 68 65 20 76 61 72 69 61 62 6c 65 20 nd the variable
0580: 27 62 75 67 62 75 67 27 20 0a 2b 20 20 20 20 23 'bugbug' .+ #
0590: 20 20 20 20 20 20 6c 61 6e 64 20 69 6e 20 74 68 land in th
05a0: 65 20 73 61 6d 65 20 62 75 63 6b 65 74 2e 0a 2b e same bucket..+
05b0: 20 20 20 20 23 20 20 28 62 29 20 64 6f 20 61 20 # (b) do a
05c0: 5b 6e 61 6d 65 73 70 61 63 65 20 65 76 61 6c 5d [namespace eval]
05d0: 20 6f 66 20 61 20 73 74 72 69 6e 67 20 74 68 61 of a string tha
05e0: 74 20 63 6f 6e 74 61 69 6e 73 20 65 6e 6f 75 67 t contains enoug
05f0: 68 0a 2b 20 20 20 20 23 20 20 20 20 20 20 6c 69 h.+ # li
0600: 74 65 72 61 6c 73 20 74 6f 20 66 6f 72 63 65 20 terals to force
0610: 54 63 6c 52 65 67 69 73 74 65 72 4c 69 74 65 72 TclRegisterLiter
0620: 61 6c 20 74 6f 20 72 65 62 75 69 6c 64 20 74 68 al to rebuild th
0630: 65 20 67 6c 6f 62 61 6c 0a 2b 20 20 20 20 23 20 e global.+ #
0640: 20 20 20 20 20 6c 69 74 65 72 61 6c 20 74 61 62 literal tab
0650: 6c 65 2e 20 20 54 68 65 20 6e 65 77 6c 79 20 63 le. The newly c
0660: 72 65 61 74 65 64 20 68 61 73 68 20 62 75 63 6b reated hash buck
0670: 65 74 73 20 77 69 6c 6c 20 63 6f 6e 74 61 69 6e ets will contain
0680: 0a 2b 20 20 20 20 23 20 20 20 20 20 20 74 68 65 .+ # the
0690: 20 6c 69 74 65 72 61 6c 73 2c 20 49 4e 20 52 45 literals, IN RE
06a0: 56 45 52 53 45 20 4f 52 44 45 52 2c 20 74 68 75 VERSE ORDER, thu
06b0: 73 20 70 75 74 74 69 6e 67 20 74 68 65 20 62 79 s putting the by
06c0: 74 65 63 6f 64 65 0a 2b 20 20 20 20 23 20 20 20 tecode.+ #
06d0: 20 20 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 61 immediately a
06e0: 68 65 61 64 20 6f 66 20 27 62 75 67 62 75 67 27 head of 'bugbug'
06f0: 20 61 6e 64 20 27 62 75 67 34 33 34 35 62 75 67 and 'bug4345bug
0700: 27 2e 20 20 54 68 65 20 62 79 74 65 63 6f 64 65 '. The bytecode
0710: 0a 2b 20 20 20 20 23 20 20 20 20 20 20 6f 62 6a .+ # obj
0720: 65 63 74 20 77 69 6c 6c 20 63 6f 6e 74 61 69 6e ect will contain
0730: 20 74 68 65 20 6f 6e 6c 79 20 72 65 66 65 72 65 the only refere
0740: 6e 63 65 73 20 74 6f 20 74 68 6f 73 65 20 74 77 nces to those tw
0750: 6f 20 6c 69 74 65 72 61 6c 73 2e 0a 2b 20 20 20 o literals..+
0760: 20 23 20 20 28 63 29 20 44 65 6c 65 74 65 20 74 # (c) Delete t
0770: 68 65 20 69 6e 74 65 72 70 72 65 74 65 72 20 74 he interpreter t
0780: 6f 20 69 6e 76 6f 6b 65 20 54 63 6c 43 6c 65 61 o invoke TclClea
0790: 6e 75 70 4c 69 74 65 72 61 6c 54 61 62 6c 65 0a nupLiteralTable.
07a0: 2b 20 20 20 20 23 20 20 20 20 20 20 61 6e 64 20 + # and
07b0: 74 69 63 6b 6c 65 20 74 68 65 20 62 75 67 2e 0a tickle the bug..
07c0: 2b 20 20 20 20 70 72 6f 63 20 66 6f 6f 20 7b 7d + proc foo {}
07d0: 20 7b 0a 2b 20 20 20 20 73 65 74 20 69 20 5b 69 {.+ set i [i
07e0: 6e 74 65 72 70 20 63 72 65 61 74 65 5d 0a 2b 20 nterp create].+
07f0: 20 20 20 24 69 20 65 76 61 6c 20 7b 0a 2b 09 6e $i eval {.+.n
0800: 61 6d 65 73 70 61 63 65 20 65 76 61 6c 20 3a 3a amespace eval ::
0810: 77 20 7b 63 6f 6e 63 61 74 20 34 36 34 39 3b 20 w {concat 4649;
0820: 76 61 72 69 61 62 6c 65 20 62 75 67 62 75 67 7d variable bugbug}
0830: 0a 2b 09 6e 61 6d 65 73 70 61 63 65 20 65 76 61 .+.namespace eva
0840: 6c 20 3a 3a 77 20 7b 0a 2b 09 20 20 20 20 63 6f l ::w {.+. co
0850: 6e 63 61 74 20 78 31 20 78 32 20 78 33 20 78 34 ncat x1 x2 x3 x4
0860: 20 78 35 20 78 36 20 78 37 20 78 38 20 78 39 20 x5 x6 x7 x8 x9
0870: 78 31 30 20 5c 0a 2b 09 09 78 31 31 20 78 31 32 x10 \.+..x11 x12
0880: 20 78 31 33 20 78 31 34 20 78 31 35 20 78 31 36 x13 x14 x15 x16
0890: 20 78 31 37 20 78 31 38 20 78 31 39 20 78 32 30 x17 x18 x19 x20
08a0: 20 5c 0a 2b 09 09 78 32 31 20 78 32 32 20 78 32 \.+..x21 x22 x2
08b0: 33 20 78 32 34 20 78 32 35 20 78 32 36 20 78 32 3 x24 x25 x26 x2
08c0: 37 20 78 32 38 20 78 32 39 20 78 33 30 20 5c 0a 7 x28 x29 x30 \.
08d0: 2b 09 09 78 33 31 20 78 33 32 20 58 33 33 20 58 +..x31 x32 X33 X
08e0: 33 34 20 58 33 35 20 58 33 36 20 58 33 37 20 58 34 X35 X36 X37 X
08f0: 33 38 20 58 33 39 20 58 34 30 20 5c 0a 2b 09 09 38 X39 X40 \.+..
0900: 78 34 31 20 78 34 32 20 78 34 33 20 78 34 34 20 x41 x42 x43 x44
0910: 78 34 35 20 78 34 36 20 78 34 37 20 78 34 38 20 x45 x46 x47 x48
0920: 78 34 39 20 78 35 30 20 5c 0a 2b 09 09 78 35 31 x49 x50 \.+..x51
0930: 20 78 35 32 20 78 35 33 20 78 35 34 20 78 35 35 x52 x53 x54 x55
0940: 20 78 35 36 20 78 35 37 20 78 35 38 20 78 35 39 x56 x57 x58 x59
0950: 20 78 36 30 20 5c 0a 2b 09 09 78 36 31 20 78 36 x60 \.+..x61 x6
0960: 32 20 78 36 33 20 78 36 34 0a 2b 09 20 20 20 20 2 x63 x64.+.
0970: 63 6f 6e 63 61 74 20 79 31 20 79 32 20 79 33 20 concat y1 y2 y3
0980: 79 34 20 79 35 20 79 36 20 79 37 20 79 38 20 79 y4 y5 y6 y7 y8 y
0990: 39 20 79 31 30 20 5c 0a 2b 09 09 79 31 31 20 79 9 y10 \.+..y11 y
09a0: 31 32 20 79 31 33 20 79 31 34 20 79 31 35 20 79 12 y13 y14 y15 y
09b0: 31 36 20 79 31 37 20 79 31 38 20 79 31 39 20 79 16 y17 y18 y19 y
09c0: 32 30 20 5c 0a 2b 09 09 79 32 31 20 79 32 32 20 20 \.+..y21 y22
09d0: 79 32 33 20 79 32 34 20 79 32 35 20 79 32 36 20 y23 y24 y25 y26
09e0: 79 32 37 20 79 32 38 20 79 32 39 20 79 33 30 20 y27 y28 y29 y30
09f0: 5c 0a 2b 09 09 79 33 31 20 79 33 32 20 59 33 33 \.+..y31 y32 Y33
0a00: 20 59 33 34 20 59 33 35 20 59 33 36 20 59 33 37 Y34 Y35 Y36 Y37
0a10: 20 59 33 38 20 59 33 39 20 59 34 30 20 5c 0a 2b Y38 Y39 Y40 \.+
0a20: 09 09 79 34 31 20 79 34 32 20 79 34 33 20 79 34 ..y41 y42 y43 y4
0a30: 34 20 79 34 35 20 79 34 36 20 79 34 37 20 79 34 4 y45 y46 y47 y4
0a40: 38 20 79 34 39 20 79 35 30 20 5c 0a 2b 09 09 79 8 y49 y50 \.+..y
0a50: 35 31 20 79 35 32 20 79 35 33 20 79 35 34 20 79 51 y52 y53 y54 y
0a60: 35 35 20 79 35 36 20 79 35 37 20 79 35 38 20 79 55 y56 y57 y58 y
0a70: 35 39 20 79 36 30 20 5c 0a 2b 09 09 79 36 31 20 59 y60 \.+..y61
0a80: 79 36 32 20 79 36 33 20 79 36 34 0a 2b 09 20 20 y62 y63 y64.+.
0a90: 20 20 63 6f 6e 63 61 74 20 7a 31 20 7a 32 20 7a concat z1 z2 z
0aa0: 33 20 7a 34 20 7a 35 20 7a 36 20 7a 37 20 7a 38 3 z4 z5 z6 z7 z8
0ab0: 20 7a 39 20 7a 31 30 20 5c 0a 2b 09 09 7a 31 31 z9 z10 \.+..z11
0ac0: 20 7a 31 32 20 7a 31 33 20 7a 31 34 20 7a 31 35 z12 z13 z14 z15
0ad0: 20 7a 31 36 20 7a 31 37 20 7a 31 38 20 7a 31 39 z16 z17 z18 z19
0ae0: 20 7a 32 30 20 5c 0a 2b 09 09 7a 32 31 20 7a 32 z20 \.+..z21 z2
0af0: 32 20 7a 32 33 20 7a 32 34 20 7a 32 35 20 7a 32 2 z23 z24 z25 z2
0b00: 36 20 7a 32 37 20 7a 32 38 20 7a 32 39 20 7a 33 6 z27 z28 z29 z3
0b10: 30 20 5c 0a 2b 09 09 7a 33 31 20 7a 33 32 0a 2b 0 \.+..z31 z32.+
0b20: 09 7d 0a 2b 20 20 20 20 7d 0a 2b 20 20 20 20 69 .}.+ }.+ i
0b30: 6e 74 65 72 70 20 64 65 6c 65 74 65 20 24 69 3b nterp delete $i;
0b40: 20 23 20 6d 75 73 74 20 6e 6f 74 20 63 72 61 73 # must not cras
0b50: 68 0a 2b 20 20 20 20 72 65 74 75 72 6e 20 6f 6b h.+ return ok
0b60: 0a 2b 20 20 20 20 7d 0a 2b 20 20 20 20 66 6f 6f .+ }.+ foo
0b70: 0a 2b 7d 20 6f 6b 0a 2b 0a 20 23 20 53 70 65 63 .+} ok.+. # Spec
0b80: 69 61 6c 20 74 65 73 74 20 66 6f 72 20 75 6e 64 ial test for und
0b90: 65 72 65 73 74 69 6d 61 74 69 6e 67 20 74 68 65 erestimating the
0ba0: 20 6d 61 78 53 74 61 63 6b 53 69 7a 65 20 72 65 maxStackSize re
0bb0: 71 75 69 72 65 64 20 66 6f 72 20 61 0a 20 23 20 quired for a. #
0bc0: 63 6f 6d 70 69 6c 65 64 20 63 6f 6d 6d 61 6e 64 compiled command
0bd0: 2e 20 41 20 66 61 69 6c 75 72 65 20 77 69 6c 6c . A failure will
0be0: 20 63 61 75 73 65 20 61 20 73 65 67 66 61 75 6c cause a segfaul
0bf0: 74 20 69 6e 20 74 68 65 20 63 68 69 6c 64 20 0a t in the child .
0c00: 20 23 20 70 72 6f 63 65 73 73 2e 0a # process..