From f096df217044ed5ecc6f481b148f94f85949569d Mon Sep 17 00:00:00 2001
From: dkf <donal.k.fellows@manchester.ac.uk>
Date: Tue, 22 Nov 2016 15:04:28 +0000
Subject: Corrections to misleading comments.

---
 generic/tcl.h | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/generic/tcl.h b/generic/tcl.h
index eb53c70..7984005 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -831,19 +831,20 @@ typedef struct Tcl_Obj {
     union {			/* The internal representation: */
 	long longValue;		/*   - an long integer value. */
 	double doubleValue;	/*   - a double-precision floating value. */
-	void *otherValuePtr;	/*   - another, type-specific value,
-	                       not used internally any more. */
+	void *otherValuePtr;	/*   - another, type-specific value, not used
+				 *     internally any more. */
 	Tcl_WideInt wideValue;	/*   - a long long value. */
 	struct {		/*   - internal rep as two pointers.
-				 *     the main use of which is a bignum's
+				 *     Many uses in Tcl, including a bignum's
 				 *     tightly packed fields, where the alloc,
 				 *     used and signum flags are packed into
-				 *     ptr2 with everything else hung off ptr1. */
+				 *     ptr2 with everything else hung off
+				 *     ptr1. */
 	    void *ptr1;
 	    void *ptr2;
 	} twoPtrValue;
 	struct {		/*   - internal rep as a pointer and a long,
-	                       not used internally any more. */
+				 *     not used internally any more. */
 	    void *ptr;
 	    unsigned long value;
 	} ptrAndLongRep;
-- 
cgit v0.12


From c8d9ab8790cf3ce9e8a7ef9bc1593d7ad97a94cc Mon Sep 17 00:00:00 2001
From: "jan.nijtmans" <nijtmans@users.sourceforge.net>
Date: Thu, 24 Nov 2016 10:26:28 +0000
Subject: typos

---
 generic/tclCmdMZ.c | 2 +-
 generic/tclLoad.c  | 2 +-
 generic/tclPipe.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c
index e9a6933..023c671 100644
--- a/generic/tclCmdMZ.c
+++ b/generic/tclCmdMZ.c
@@ -323,7 +323,7 @@ Tcl_RegexpObjCmd(
 
 	if (match == 0) {
 	    /*
-	     * We want to set the value of the intepreter result only when
+	     * We want to set the value of the interpreter result only when
 	     * this is the first time through the loop.
 	     */
 
diff --git a/generic/tclLoad.c b/generic/tclLoad.c
index 7c70e03..be296b3 100644
--- a/generic/tclLoad.c
+++ b/generic/tclLoad.c
@@ -1015,7 +1015,7 @@ Tcl_StaticPackage(
  * TclGetLoadedPackages --
  *
  *	This function returns information about all of the files that are
- *	loaded (either in a particular intepreter, or for all interpreters).
+ *	loaded (either in a particular interpreter, or for all interpreters).
  *
  * Results:
  *	The return value is a standard Tcl completion code. If successful, a
diff --git a/generic/tclPipe.c b/generic/tclPipe.c
index 83fb818..d6cd188 100644
--- a/generic/tclPipe.c
+++ b/generic/tclPipe.c
@@ -60,7 +60,7 @@ static TclFile		FileForRedirect(Tcl_Interp *interp, const char *spec,
 
 static TclFile
 FileForRedirect(
-    Tcl_Interp *interp,		/* Intepreter to use for error reporting. */
+    Tcl_Interp *interp,		/* Interpreter to use for error reporting. */
     const char *spec,		/* Points to character just after redirection
 				 * character. */
     int atOK,			/* Non-zero means that '@' notation can be
-- 
cgit v0.12


From c2f9601344d1cf1b6c483fcf165bbef57b1124af Mon Sep 17 00:00:00 2001
From: "jan.nijtmans" <nijtmans@users.sourceforge.net>
Date: Thu, 24 Nov 2016 13:33:32 +0000
Subject: Make compileEpoch "unsigned int", and start counting at 1.

---
 generic/tclBasic.c   | 2 +-
 generic/tclCompile.h | 2 +-
 generic/tclInt.h     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 8eebab1..c1dd52d 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -588,7 +588,7 @@ Tcl_CreateInterp(void)
 
     iPtr->cmdCount = 0;
     TclInitLiteralTable(&iPtr->literalTable);
-    iPtr->compileEpoch = 0;
+    iPtr->compileEpoch = 1;
     iPtr->compiledProcPtr = NULL;
     iPtr->resolverPtr = NULL;
     iPtr->evalFlags = 0;
diff --git a/generic/tclCompile.h b/generic/tclCompile.h
index 89cdc59..5ef154e 100644
--- a/generic/tclCompile.h
+++ b/generic/tclCompile.h
@@ -417,7 +417,7 @@ typedef struct ByteCode {
 				 * procs are specific to an interpreter so the
 				 * code emitted will depend on the
 				 * interpreter. */
-    int compileEpoch;		/* Value of iPtr->compileEpoch when this
+    unsigned int compileEpoch;	/* Value of iPtr->compileEpoch when this
 				 * ByteCode was compiled. Used to invalidate
 				 * code when, e.g., commands with compile
 				 * procs are redefined. */
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 3e55004..4257ea1 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -1898,7 +1898,7 @@ typedef struct Interp {
 				 * compiled by the interpreter. Indexed by the
 				 * string representations of literals. Used to
 				 * avoid creating duplicate objects. */
-    int compileEpoch;		/* Holds the current "compilation epoch" for
+    unsigned int compileEpoch;	/* Holds the current "compilation epoch" for
 				 * this interpreter. This is incremented to
 				 * invalidate existing ByteCodes when, e.g., a
 				 * command with a compile procedure is
-- 
cgit v0.12


From 5e9f62442819a26249ffe7584158ee47fa974cc9 Mon Sep 17 00:00:00 2001
From: andy <andrew.m.goth@gmail.com>
Date: Thu, 24 Nov 2016 19:21:12 +0000
Subject: Partially backout [ef4da65408] because AppendPrintfToObjVA() (used
 indirectly by [tcl::unsupported::disassemble]) does not yet support wide and
 bignum arguments.  This fixes a SIGSEGV in compile.test and makes
 [disassemble] work again.

---
 generic/tclDisassemble.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/generic/tclDisassemble.c b/generic/tclDisassemble.c
index 88ff094..0d6da8e 100644
--- a/generic/tclDisassemble.c
+++ b/generic/tclDisassemble.c
@@ -272,8 +272,8 @@ DisassembleByteCodeObj(
     sprintf(ptrBuf1, "%p", codePtr);
     sprintf(ptrBuf2, "%p", iPtr);
     Tcl_AppendPrintfToObj(bufferObj,
-	    "ByteCode 0x%s, refCt %" TCL_LL_MODIFIER "u, epoch %u, interp 0x%s (epoch %u)\n",
-	    ptrBuf1, (Tcl_WideInt)codePtr->refCount, codePtr->compileEpoch, ptrBuf2,
+	    "ByteCode 0x%s, refCt %u, epoch %u, interp 0x%s (epoch %u)\n",
+	    ptrBuf1, codePtr->refCount, codePtr->compileEpoch, ptrBuf2,
 	    iPtr->compileEpoch);
     Tcl_AppendToObj(bufferObj, "  Source ", -1);
     PrintSourceToObj(bufferObj, codePtr->source,
-- 
cgit v0.12


From d37425bc053928c2dc1de59a8e91638ed468dc9e Mon Sep 17 00:00:00 2001
From: andy <andrew.m.goth@gmail.com>
Date: Fri, 25 Nov 2016 01:39:13 +0000
Subject: Remove spurious article in comments

---
 generic/tclHash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/generic/tclHash.c b/generic/tclHash.c
index ac9d40e..78ad514 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -924,7 +924,7 @@ HashStringKey(
  *
  * BogusFind --
  *
- *	This function is invoked when an Tcl_FindHashEntry is called on a
+ *	This function is invoked when Tcl_FindHashEntry is called on a
  *	table that has been deleted.
  *
  * Results:
@@ -951,7 +951,7 @@ BogusFind(
  *
  * BogusCreate --
  *
- *	This function is invoked when an Tcl_CreateHashEntry is called on a
+ *	This function is invoked when Tcl_CreateHashEntry is called on a
  *	table that has been deleted.
  *
  * Results:
-- 
cgit v0.12


From 1000af34faa34a6becf22244a8d7a91bd73f7c45 Mon Sep 17 00:00:00 2001
From: andy <andrew.m.goth@gmail.com>
Date: Fri, 25 Nov 2016 07:31:46 +0000
Subject: Allow [array names -regexp] to use backreferences. This capability
 was broken by [71270e9141]. See also bug [1366683].

---
 generic/tclRegexp.c | 13 ++++++++++---
 tests/set-old.test  |  7 +++++++
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/generic/tclRegexp.c b/generic/tclRegexp.c
index ea25d4b..eb23f72 100644
--- a/generic/tclRegexp.c
+++ b/generic/tclRegexp.c
@@ -502,9 +502,16 @@ Tcl_RegExpMatchObj(
 {
     Tcl_RegExp re;
 
-    re = Tcl_GetRegExpFromObj(interp, patternObj,
-	    TCL_REG_ADVANCED | TCL_REG_NOSUB);
-    if (re == NULL) {
+    /*
+     * For performance reasons, first try compiling the RE without support for
+     * subexpressions. On failure, try again without TCL_REG_NOSUB in case the
+     * RE has backreferences in it. Closely related to [Bug 1366683]. If this
+     * still fails, an error message will be left in the interpreter.
+     */
+
+    if (!(re = Tcl_GetRegExpFromObj(interp, patternObj,
+	    TCL_REG_ADVANCED | TCL_REG_NOSUB))
+     && !(re = Tcl_GetRegExpFromObj(interp, patternObj, TCL_REG_ADVANCED))) {
 	return -1;
     }
     return Tcl_RegExpExecObj(interp, re, textObj, 0 /* offset */,
diff --git a/tests/set-old.test b/tests/set-old.test
index 93169f1..309abaf 100644
--- a/tests/set-old.test
+++ b/tests/set-old.test
@@ -652,6 +652,13 @@ test set-old-8.52 {array command, array names -regexp on regexp pattern} {
     set a(11) 1
     list [catch {lsort [array names a -regexp ^1]} msg] $msg
 } {0 {1*2 11 12}}
+test set-old-8.52.1 {array command, array names -regexp, backrefs} {
+    catch {unset a}
+    set a(1*2) 1
+    set a(12) 1
+    set a(11) 1
+    list [catch {lsort [array names a -regexp {^(.)\1}]} msg] $msg
+} {0 11}
 test set-old-8.53 {array command, array names -regexp} {
     catch {unset a}
     set a(-glob) 1
-- 
cgit v0.12