Posted to tcl by kbk at Tue Sep 23 20:51:28 GMT 2008view pretty

Index: generic/tcl.h
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tcl.h,v
retrieving revision 1.270
diff -b -u -r1.270 tcl.h
--- generic/tcl.h	3 Sep 2008 05:43:31 -0000	1.270
+++ generic/tcl.h	23 Sep 2008 20:32:44 -0000
@@ -458,6 +458,8 @@
  */
 
 typedef struct Tcl_Interp {
+    /* TIP #330: Strongly discourage extensions from using the string result. */
+#ifdef USE_INTERP_RESULT
     char *result;		/* If the last command returned a string
 				 * result, this points to it. */
     void (*freeProc) (char *blockPtr);
@@ -468,6 +470,10 @@
 				 * of function to invoke to free the result.
 				 * Tcl_Eval must free it before executing next
 				 * command. */
+#else
+    char* unused1;
+    void (*unused2) (char*);
+#endif
     int errorLine;		/* When TCL_ERROR is returned, this gives the
 				 * line number within the command where the
 				 * error occurred (1 if first line). */
Index: generic/tclBasic.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclBasic.c,v
retrieving revision 1.367
diff -b -u -r1.367 tclBasic.c
--- generic/tclBasic.c	17 Sep 2008 00:01:48 -0000	1.367
+++ generic/tclBasic.c	23 Sep 2008 20:34:10 -0000
@@ -1445,7 +1445,7 @@
      */
 
     Tcl_FreeResult(interp);
-    interp->result = NULL;
+    iPtr->result = NULL;
     Tcl_DecrRefCount(iPtr->objResultPtr);
     iPtr->objResultPtr = NULL;
     Tcl_DecrRefCount(iPtr->ecVar);
@@ -6558,7 +6558,7 @@
 	     * interp->result completely.
 	     */
 
-	    iPtr->errorInfo = Tcl_NewStringObj(interp->result, -1);
+	    iPtr->errorInfo = Tcl_NewStringObj(iPtr->result, -1);
 	} else {
 	    iPtr->errorInfo = iPtr->objResultPtr;
 	}
Index: generic/tclResult.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclResult.c,v
retrieving revision 1.48
diff -b -u -r1.48 tclResult.c
--- generic/tclResult.c	27 Apr 2008 22:21:32 -0000	1.48
+++ generic/tclResult.c	23 Sep 2008 20:35:00 -0000
@@ -471,11 +471,12 @@
      * result, then reset the object result.
      */
 
-    if (*(interp->result) == 0) {
+    Interp* iPtr = (Interp*) interp;
+    if (*(iPtr->result) == 0) {
 	Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)),
 		TCL_VOLATILE);
     }
-    return interp->result;
+    return iPtr->result;
 }
 
 /*
Index: generic/tclStubLib.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclStubLib.c,v
retrieving revision 1.26
diff -b -u -r1.26 tclStubLib.c
--- generic/tclStubLib.c	27 Apr 2008 22:21:32 -0000	1.26
+++ generic/tclStubLib.c	23 Sep 2008 20:43:55 -0000
@@ -46,9 +46,9 @@
 	return iPtr->stubTable;
     }
 
-    interp->result =
+    iPtr->result =
 	    "This interpreter does not support stubs-enabled extensions.";
-    interp->freeProc = TCL_STATIC;
+    iPtr->freeProc = TCL_STATIC;
     return NULL;
 }
 
Index: generic/tclTest.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclTest.c,v
retrieving revision 1.124
diff -b -u -r1.124 tclTest.c
--- generic/tclTest.c	20 Aug 2008 13:14:41 -0000	1.124
+++ generic/tclTest.c	23 Sep 2008 20:47:25 -0000
@@ -1593,6 +1593,7 @@
     const char **argv)		/* Argument strings. */
 {
     int count;
+    Interp* iPtr = (Interp*) interp;
 
     if (argc < 2) {
 	wrongNumArgs:
@@ -1637,12 +1638,12 @@
 	    Tcl_SetResult(interp, "first0 first1 first2 first3 first4 first5 first6 first7 first8 first9\nsecond0 second1 second2 second3 second4 second5 second6 second7 second8 second9\nthird0 third1 third2 third3 third4 third5 third6 third7 third8 third9\nfourth0 fourth1 fourth2 fourth3 fourth4 fourth5 fourth6 fourth7 fourth8 fourth9\nfifth0 fifth1 fifth2 fifth3 fifth4 fifth5 fifth6 fifth7 fifth8 fifth9\nsixth0 sixth1 sixth2 sixth3 sixth4 sixth5 sixth6 sixth7 sixth8 sixth9\nseventh0 seventh1 seventh2 seventh3 seventh4 seventh5 seventh6 seventh7 seventh8 seventh9\n", TCL_STATIC);
 	} else if (strcmp(argv[2], "free") == 0) {
 	    Tcl_SetResult(interp, (char *) ckalloc(100), TCL_DYNAMIC);
-	    strcpy(interp->result, "This is a malloc-ed string");
+	    strcpy(iPtr->result, "This is a malloc-ed string");
 	} else if (strcmp(argv[2], "special") == 0) {
-	    interp->result = (char *) ckalloc(100);
-	    interp->result += 4;
-	    interp->freeProc = SpecialFree;
-	    strcpy(interp->result, "This is a specially-allocated string");
+	    iPtr->result = (char *) ckalloc(100);
+	    iPtr->result += 4;
+	    iPtr->freeProc = SpecialFree;
+	    strcpy(iPtr->result, "This is a specially-allocated string");
 	} else {
 	    Tcl_AppendResult(interp, "bad gresult option \"", argv[2],
 		    "\": must be staticsmall, staticlarge, free, or special",
@@ -4847,6 +4848,7 @@
     int objc,			/* Number of arguments. */
     Tcl_Obj *const objv[])	/* The argument objects. */
 {
+    Interp* iPtr = (Interp*) interp;
     int discard, result, index;
     Tcl_SavedResult state;
     Tcl_Obj *objPtr;
@@ -4915,7 +4917,7 @@
 
     switch ((enum options) index) {
     case RESULT_DYNAMIC: {
-	int present = interp->freeProc == TestsaveresultFree;
+	int present = iPtr->freeProc == TestsaveresultFree;
 	int called = freeCount;
 
 	Tcl_AppendElement(interp, called ? "called" : "notCalled");
Index: generic/tclUtil.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclUtil.c,v
retrieving revision 1.103
diff -b -u -r1.103 tclUtil.c
--- generic/tclUtil.c	22 Aug 2008 18:01:00 -0000	1.103
+++ generic/tclUtil.c	23 Sep 2008 20:39:00 -0000
@@ -2065,14 +2065,15 @@
     Tcl_DString *dsPtr)		/* Dynamic string that is to become the
 				 * result of interp. */
 {
+    Interp* iPtr = (Interp*) interp;
     Tcl_ResetResult(interp);
 
     if (dsPtr->string != dsPtr->staticSpace) {
-	interp->result = dsPtr->string;
-	interp->freeProc = TCL_DYNAMIC;
+	iPtr->result = dsPtr->string;
+	iPtr->freeProc = TCL_DYNAMIC;
     } else if (dsPtr->length < TCL_RESULT_SIZE) {
-	interp->result = ((Interp *) interp)->resultSpace;
-	strcpy(interp->result, dsPtr->string);
+	iPtr->result = ((Interp *) interp)->resultSpace;
+	strcpy(iPtr->result, dsPtr->string);
     } else {
 	Tcl_SetResult(interp, dsPtr->string, TCL_VOLATILE);
     }