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

  1. Index: generic/tcl.h
  2. ===================================================================
  3. RCS file: /cvsroot/tcl/tcl/generic/tcl.h,v
  4. retrieving revision 1.270
  5. diff -b -u -r1.270 tcl.h
  6. --- generic/tcl.h 3 Sep 2008 05:43:31 -0000 1.270
  7. +++ generic/tcl.h 23 Sep 2008 20:32:44 -0000
  8. @@ -458,6 +458,8 @@
  9. */
  10.  
  11. typedef struct Tcl_Interp {
  12. + /* TIP #330: Strongly discourage extensions from using the string result. */
  13. +#ifdef USE_INTERP_RESULT
  14. char *result; /* If the last command returned a string
  15. * result, this points to it. */
  16. void (*freeProc) (char *blockPtr);
  17. @@ -468,6 +470,10 @@
  18. * of function to invoke to free the result.
  19. * Tcl_Eval must free it before executing next
  20. * command. */
  21. +#else
  22. + char* unused1;
  23. + void (*unused2) (char*);
  24. +#endif
  25. int errorLine; /* When TCL_ERROR is returned, this gives the
  26. * line number within the command where the
  27. * error occurred (1 if first line). */
  28. Index: generic/tclBasic.c
  29. ===================================================================
  30. RCS file: /cvsroot/tcl/tcl/generic/tclBasic.c,v
  31. retrieving revision 1.367
  32. diff -b -u -r1.367 tclBasic.c
  33. --- generic/tclBasic.c 17 Sep 2008 00:01:48 -0000 1.367
  34. +++ generic/tclBasic.c 23 Sep 2008 20:34:10 -0000
  35. @@ -1445,7 +1445,7 @@
  36. */
  37.  
  38. Tcl_FreeResult(interp);
  39. - interp->result = NULL;
  40. + iPtr->result = NULL;
  41. Tcl_DecrRefCount(iPtr->objResultPtr);
  42. iPtr->objResultPtr = NULL;
  43. Tcl_DecrRefCount(iPtr->ecVar);
  44. @@ -6558,7 +6558,7 @@
  45. * interp->result completely.
  46. */
  47.  
  48. - iPtr->errorInfo = Tcl_NewStringObj(interp->result, -1);
  49. + iPtr->errorInfo = Tcl_NewStringObj(iPtr->result, -1);
  50. } else {
  51. iPtr->errorInfo = iPtr->objResultPtr;
  52. }
  53. Index: generic/tclResult.c
  54. ===================================================================
  55. RCS file: /cvsroot/tcl/tcl/generic/tclResult.c,v
  56. retrieving revision 1.48
  57. diff -b -u -r1.48 tclResult.c
  58. --- generic/tclResult.c 27 Apr 2008 22:21:32 -0000 1.48
  59. +++ generic/tclResult.c 23 Sep 2008 20:35:00 -0000
  60. @@ -471,11 +471,12 @@
  61. * result, then reset the object result.
  62. */
  63.  
  64. - if (*(interp->result) == 0) {
  65. + Interp* iPtr = (Interp*) interp;
  66. + if (*(iPtr->result) == 0) {
  67. Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)),
  68. TCL_VOLATILE);
  69. }
  70. - return interp->result;
  71. + return iPtr->result;
  72. }
  73.  
  74. /*
  75. Index: generic/tclStubLib.c
  76. ===================================================================
  77. RCS file: /cvsroot/tcl/tcl/generic/tclStubLib.c,v
  78. retrieving revision 1.26
  79. diff -b -u -r1.26 tclStubLib.c
  80. --- generic/tclStubLib.c 27 Apr 2008 22:21:32 -0000 1.26
  81. +++ generic/tclStubLib.c 23 Sep 2008 20:43:55 -0000
  82. @@ -46,9 +46,9 @@
  83. return iPtr->stubTable;
  84. }
  85.  
  86. - interp->result =
  87. + iPtr->result =
  88. "This interpreter does not support stubs-enabled extensions.";
  89. - interp->freeProc = TCL_STATIC;
  90. + iPtr->freeProc = TCL_STATIC;
  91. return NULL;
  92. }
  93.  
  94. Index: generic/tclTest.c
  95. ===================================================================
  96. RCS file: /cvsroot/tcl/tcl/generic/tclTest.c,v
  97. retrieving revision 1.124
  98. diff -b -u -r1.124 tclTest.c
  99. --- generic/tclTest.c 20 Aug 2008 13:14:41 -0000 1.124
  100. +++ generic/tclTest.c 23 Sep 2008 20:47:25 -0000
  101. @@ -1593,6 +1593,7 @@
  102. const char **argv) /* Argument strings. */
  103. {
  104. int count;
  105. + Interp* iPtr = (Interp*) interp;
  106.  
  107. if (argc < 2) {
  108. wrongNumArgs:
  109. @@ -1637,12 +1638,12 @@
  110. 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);
  111. } else if (strcmp(argv[2], "free") == 0) {
  112. Tcl_SetResult(interp, (char *) ckalloc(100), TCL_DYNAMIC);
  113. - strcpy(interp->result, "This is a malloc-ed string");
  114. + strcpy(iPtr->result, "This is a malloc-ed string");
  115. } else if (strcmp(argv[2], "special") == 0) {
  116. - interp->result = (char *) ckalloc(100);
  117. - interp->result += 4;
  118. - interp->freeProc = SpecialFree;
  119. - strcpy(interp->result, "This is a specially-allocated string");
  120. + iPtr->result = (char *) ckalloc(100);
  121. + iPtr->result += 4;
  122. + iPtr->freeProc = SpecialFree;
  123. + strcpy(iPtr->result, "This is a specially-allocated string");
  124. } else {
  125. Tcl_AppendResult(interp, "bad gresult option \"", argv[2],
  126. "\": must be staticsmall, staticlarge, free, or special",
  127. @@ -4847,6 +4848,7 @@
  128. int objc, /* Number of arguments. */
  129. Tcl_Obj *const objv[]) /* The argument objects. */
  130. {
  131. + Interp* iPtr = (Interp*) interp;
  132. int discard, result, index;
  133. Tcl_SavedResult state;
  134. Tcl_Obj *objPtr;
  135. @@ -4915,7 +4917,7 @@
  136.  
  137. switch ((enum options) index) {
  138. case RESULT_DYNAMIC: {
  139. - int present = interp->freeProc == TestsaveresultFree;
  140. + int present = iPtr->freeProc == TestsaveresultFree;
  141. int called = freeCount;
  142.  
  143. Tcl_AppendElement(interp, called ? "called" : "notCalled");
  144. Index: generic/tclUtil.c
  145. ===================================================================
  146. RCS file: /cvsroot/tcl/tcl/generic/tclUtil.c,v
  147. retrieving revision 1.103
  148. diff -b -u -r1.103 tclUtil.c
  149. --- generic/tclUtil.c 22 Aug 2008 18:01:00 -0000 1.103
  150. +++ generic/tclUtil.c 23 Sep 2008 20:39:00 -0000
  151. @@ -2065,14 +2065,15 @@
  152. Tcl_DString *dsPtr) /* Dynamic string that is to become the
  153. * result of interp. */
  154. {
  155. + Interp* iPtr = (Interp*) interp;
  156. Tcl_ResetResult(interp);
  157.  
  158. if (dsPtr->string != dsPtr->staticSpace) {
  159. - interp->result = dsPtr->string;
  160. - interp->freeProc = TCL_DYNAMIC;
  161. + iPtr->result = dsPtr->string;
  162. + iPtr->freeProc = TCL_DYNAMIC;
  163. } else if (dsPtr->length < TCL_RESULT_SIZE) {
  164. - interp->result = ((Interp *) interp)->resultSpace;
  165. - strcpy(interp->result, dsPtr->string);
  166. + iPtr->result = ((Interp *) interp)->resultSpace;
  167. + strcpy(iPtr->result, dsPtr->string);
  168. } else {
  169. Tcl_SetResult(interp, dsPtr->string, TCL_VOLATILE);
  170. }
  171.