summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2012-04-18 18:42:54 (GMT)
committerdgp <dgp@users.sourceforge.net>2012-04-18 18:42:54 (GMT)
commit88574b7bc539d00b6477f8d9bbe7f25158b57662 (patch)
tree4399ca38b73edfafc667956c4bb05e731d0dc862
parente5ced1c96d6213766cd6263eddcab12ba1a916a9 (diff)
downloadtcl-88574b7bc539d00b6477f8d9bbe7f25158b57662.zip
tcl-88574b7bc539d00b6477f8d9bbe7f25158b57662.tar.gz
tcl-88574b7bc539d00b6477f8d9bbe7f25158b57662.tar.bz2
Experimental branch where the interp->result field and related are removed
and all simplifications that makes possible are done. Seems this can at best be a Tcl 9 reform.
-rw-r--r--generic/tcl.h16
-rw-r--r--generic/tclBasic.c42
-rw-r--r--generic/tclHistory.c2
-rw-r--r--generic/tclInt.h15
-rw-r--r--generic/tclResult.c52
-rw-r--r--generic/tclStubLib.c8
-rw-r--r--generic/tclTest.c13
-rw-r--r--generic/tclUtil.c13
8 files changed, 146 insertions, 15 deletions
diff --git a/generic/tcl.h b/generic/tcl.h
index 729e521..46266d2 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -499,7 +499,7 @@ typedef unsigned TCL_WIDE_INT_TYPE Tcl_WideUInt;
* Instead, they set a Tcl_Obj member in the "real" structure that can be
* accessed with Tcl_GetObjResult() and Tcl_SetObjResult().
*/
-
+#if 0
typedef struct Tcl_Interp {
/* TIP #330: Strongly discourage extensions from using the string
* result. */
@@ -529,6 +529,8 @@ typedef struct Tcl_Interp {
int unused5 TCL_DEPRECATED_API("bad field access");
#endif
} Tcl_Interp;
+#endif
+typedef struct Tcl_Interp Tcl_Interp;
typedef struct Tcl_AsyncHandler_ *Tcl_AsyncHandler;
typedef struct Tcl_Channel_ *Tcl_Channel;
@@ -870,13 +872,13 @@ int Tcl_IsShared(Tcl_Obj *objPtr);
*/
typedef struct Tcl_SavedResult {
- char *result;
- Tcl_FreeProc *freeProc;
+ char *unused1;
+ Tcl_FreeProc *unused2;
Tcl_Obj *objResultPtr;
- char *appendResult;
- int appendAvl;
- int appendUsed;
- char resultSpace[TCL_RESULT_SIZE+1];
+ char *unused3;
+ int unused4;
+ int unused5;
+ char unused6[TCL_RESULT_SIZE+1];
} Tcl_SavedResult;
/*
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index e09ea1e..d55faeb 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -503,8 +503,10 @@ Tcl_CreateInterp(void)
iPtr = ckalloc(sizeof(Interp));
interp = (Tcl_Interp *) iPtr;
+#if 0
iPtr->result = iPtr->resultSpace;
iPtr->freeProc = NULL;
+#endif
iPtr->errorLine = 0;
iPtr->objResultPtr = Tcl_NewObj();
Tcl_IncrRefCount(iPtr->objResultPtr);
@@ -560,9 +562,11 @@ Tcl_CreateInterp(void)
iPtr->rootFramePtr = NULL; /* Initialise as soon as :: is available */
iPtr->lookupNsPtr = NULL;
+#if 0
iPtr->appendResult = NULL;
iPtr->appendAvl = 0;
iPtr->appendUsed = 0;
+#endif
Tcl_InitHashTable(&iPtr->packageTable, TCL_STRING_KEYS);
iPtr->packageUnknown = NULL;
@@ -591,7 +595,9 @@ Tcl_CreateInterp(void)
iPtr->emptyObjPtr = Tcl_NewObj();
/* Another empty object. */
Tcl_IncrRefCount(iPtr->emptyObjPtr);
+#if 0
iPtr->resultSpace[0] = 0;
+#endif
iPtr->threadId = Tcl_GetCurrentThread();
/* TIP #378 */
@@ -1493,7 +1499,9 @@ DeleteInterpProc(
*/
Tcl_FreeResult(interp);
+#if 0
iPtr->result = NULL;
+#endif
Tcl_DecrRefCount(iPtr->objResultPtr);
iPtr->objResultPtr = NULL;
Tcl_DecrRefCount(iPtr->ecVar);
@@ -1515,10 +1523,12 @@ DeleteInterpProc(
if (iPtr->returnOpts) {
Tcl_DecrRefCount(iPtr->returnOpts);
}
+#if 0
if (iPtr->appendResult != NULL) {
ckfree(iPtr->appendResult);
iPtr->appendResult = NULL;
}
+#endif
TclFreePackageInfo(iPtr);
while (iPtr->tracePtr != NULL) {
Tcl_DeleteTrace((Tcl_Interp *) iPtr, (Tcl_Trace) iPtr->tracePtr);
@@ -2385,7 +2395,7 @@ TclInvokeStringCommand(
* in the Command structure.
*
* Results:
- * A standard Tcl string result value.
+ * A standard Tcl result value.
*
* Side effects:
* Besides those side effects of the called Tcl_CmdProc,
@@ -2425,12 +2435,14 @@ TclInvokeObjectCommand(
cmdPtr->objClientData, argc, objv);
}
+#if 0
/*
* Move the interpreter's object result to the string result, then reset
* the object result.
*/
(void) Tcl_GetStringResult(interp);
+#endif
/*
* Decrement the ref counts for the argument objects created above, then
@@ -3800,7 +3812,7 @@ Tcl_ListMathFuncs(
* otherwise.
*
* Side effects:
- * The interpreters object and string results are cleared.
+ * The interpreter's result is cleared.
*
*----------------------------------------------------------------------
*/
@@ -3812,8 +3824,8 @@ TclInterpReady(
register Interp *iPtr = (Interp *) interp;
/*
- * Reset both the interpreter's string and object results and clear out
- * any previous error information.
+ * Reset the interpreter's result and clear out any previous error
+ * information.
*/
Tcl_ResetResult(interp);
@@ -4333,10 +4345,11 @@ TclNRRunCallbacks(
/* All callbacks down to rootPtr not inclusive
* are to be run. */
{
- Interp *iPtr = (Interp *) interp;
+/* Interp *iPtr = (Interp *) interp;*/
NRE_callback *callbackPtr;
Tcl_NRPostProc *procPtr;
+#if 0
/*
* If the interpreter has a non-empty string result, the result object is
* either empty or stale because some function set interp->result
@@ -4350,6 +4363,7 @@ TclNRRunCallbacks(
if (*(iPtr->result) != 0) {
(void) Tcl_GetObjResult(interp);
}
+#endif
while (TOP_CB(interp) != rootPtr) {
callbackPtr = TOP_CB(interp);
@@ -5828,6 +5842,7 @@ Tcl_Eval(
* previous call to Tcl_CreateInterp). */
const char *script) /* Pointer to TCL command to execute. */
{
+#if 0
int code = Tcl_EvalEx(interp, script, -1, 0);
/*
@@ -5838,6 +5853,8 @@ Tcl_Eval(
(void) Tcl_GetStringResult(interp);
return code;
+#endif
+ return Tcl_EvalEx(interp, script, -1, 0);
}
/*
@@ -6335,9 +6352,11 @@ Tcl_ExprLong(
Tcl_IncrRefCount(exprPtr);
result = Tcl_ExprLongObj(interp, exprPtr, ptr);
Tcl_DecrRefCount(exprPtr);
+#if 0
if (result != TCL_OK) {
(void) Tcl_GetStringResult(interp);
}
+#endif
}
return result;
}
@@ -6364,9 +6383,11 @@ Tcl_ExprDouble(
result = Tcl_ExprDoubleObj(interp, exprPtr, ptr);
Tcl_DecrRefCount(exprPtr);
/* Discard the expression object. */
+#if 0
if (result != TCL_OK) {
(void) Tcl_GetStringResult(interp);
}
+#endif
}
return result;
}
@@ -6392,6 +6413,7 @@ Tcl_ExprBoolean(
Tcl_IncrRefCount(exprPtr);
result = Tcl_ExprBooleanObj(interp, exprPtr, ptr);
Tcl_DecrRefCount(exprPtr);
+#if 0
if (result != TCL_OK) {
/*
* Move the interpreter's object result to the string result, then
@@ -6400,6 +6422,7 @@ Tcl_ExprBoolean(
(void) Tcl_GetStringResult(interp);
}
+#endif
return result;
}
}
@@ -6724,12 +6747,13 @@ Tcl_ExprString(
Tcl_DecrRefCount(resultPtr);
}
}
-
+#if 0
/*
* Force the string rep of the interp result.
*/
(void) Tcl_GetStringResult(interp);
+#endif
return code;
}
@@ -6833,6 +6857,7 @@ Tcl_AddObjErrorInfo(
iPtr->flags |= ERR_LEGACY_COPY;
if (iPtr->errorInfo == NULL) {
+#if 0
if (iPtr->result[0] != 0) {
/*
* The interp's string result is set, apparently by some extension
@@ -6844,8 +6869,11 @@ Tcl_AddObjErrorInfo(
iPtr->errorInfo = Tcl_NewStringObj(iPtr->result, -1);
} else {
+#endif
iPtr->errorInfo = iPtr->objResultPtr;
+#if 0
}
+#endif
Tcl_IncrRefCount(iPtr->errorInfo);
if (!iPtr->errorCode) {
Tcl_SetErrorCode(interp, "NONE", NULL);
@@ -6923,7 +6951,7 @@ Tcl_VarEvalVA(
*
* Results:
* A standard Tcl return result. An error message or other result may be
- * left in interp->result.
+ * left in the interp.
*
* Side effects:
* Depends on what was done by the command.
diff --git a/generic/tclHistory.c b/generic/tclHistory.c
index b10d423..5448365 100644
--- a/generic/tclHistory.c
+++ b/generic/tclHistory.c
@@ -74,12 +74,14 @@ Tcl_RecordAndEval(
Tcl_IncrRefCount(cmdPtr);
result = Tcl_RecordAndEvalObj(interp, cmdPtr, flags);
+#if 0
/*
* Move the interpreter's object result to the string result, then
* reset the object result.
*/
(void) Tcl_GetStringResult(interp);
+#endif
/*
* Discard the Tcl object created to hold the command.
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 08b3f70..0d541a8 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -1811,6 +1811,7 @@ typedef struct Interp {
* Tcl_GetStringResult. See the SetResult man page for details.
*/
+#if 0
char *result; /* If the last command returned a string
* result, this points to it. Should not be
* accessed directly; see comment above. */
@@ -1821,6 +1822,10 @@ typedef struct Interp {
* address of procedure to invoke to free the
* string result. Tcl_Eval must free it before
* executing next command. */
+#else
+ char *unused3;
+ Tcl_FreeProc *unused4;
+#endif
int errorLine; /* When TCL_ERROR is returned, this gives the
* line number in the command where the error
* occurred (1 means first line). */
@@ -1878,6 +1883,7 @@ typedef struct Interp {
* See Tcl_AppendResult code for details.
*/
+#if 0
char *appendResult; /* Storage space for results generated by
* Tcl_AppendResult. Ckalloc-ed. NULL means
* not yet allocated. */
@@ -1885,6 +1891,11 @@ typedef struct Interp {
* partialResult. */
int appendUsed; /* Number of non-null bytes currently stored
* at partialResult. */
+#else
+ char *unused5;
+ int unused6;
+ int unused7;
+#endif
/*
* Information about packages. Used only in tclPkg.c.
@@ -1946,8 +1957,12 @@ typedef struct Interp {
* string. Returned by Tcl_ObjSetVar2 when
* variable traces change a variable in a
* gross way. */
+#if 0
char resultSpace[TCL_RESULT_SIZE+1];
/* Static space holding small results. */
+#else
+ char unused8[TCL_RESULT_SIZE+1];
+#endif
Tcl_Obj *objResultPtr; /* If the last command returned an object
* result, this points to it. Should not be
* accessed directly; see comment above. */
diff --git a/generic/tclResult.c b/generic/tclResult.c
index 4443cc1..cbaefcb 100644
--- a/generic/tclResult.c
+++ b/generic/tclResult.c
@@ -27,7 +27,9 @@ enum returnKeys {
static Tcl_Obj ** GetKeys(void);
static void ReleaseKeys(ClientData clientData);
static void ResetObjResult(Interp *iPtr);
+#if 0
static void SetupAppendBuffer(Interp *iPtr, int newSpace);
+#endif
/*
* This structure is used to take a snapshot of the interpreter state in
@@ -247,6 +249,7 @@ Tcl_SaveResult(
iPtr->objResultPtr = Tcl_NewObj();
Tcl_IncrRefCount(iPtr->objResultPtr);
+#if 0
/*
* Save the string result.
*/
@@ -284,6 +287,7 @@ Tcl_SaveResult(
iPtr->result = iPtr->resultSpace;
iPtr->resultSpace[0] = 0;
iPtr->freeProc = 0;
+#endif
}
/*
@@ -313,6 +317,7 @@ Tcl_RestoreResult(
Tcl_ResetResult(interp);
+#if 0
/*
* Restore the string result.
*/
@@ -345,6 +350,7 @@ Tcl_RestoreResult(
iPtr->result = statePtr->result;
}
+#endif
/*
* Restore the object result.
@@ -378,6 +384,7 @@ Tcl_DiscardResult(
{
TclDecrRefCount(statePtr->objResultPtr);
+#if 0
if (statePtr->result == statePtr->appendResult) {
ckfree(statePtr->appendResult);
} else if (statePtr->freeProc) {
@@ -387,6 +394,7 @@ Tcl_DiscardResult(
statePtr->freeProc(statePtr->result);
}
}
+#endif
}
/*
@@ -416,6 +424,7 @@ Tcl_SetResult(
* TCL_STATIC, TCL_VOLATILE, or the address of
* a Tcl_FreeProc such as free. */
{
+#if 0
Interp *iPtr = (Interp *) interp;
register Tcl_FreeProc *oldFreeProc = iPtr->freeProc;
char *oldResult = iPtr->result;
@@ -459,6 +468,17 @@ Tcl_SetResult(
*/
ResetObjResult(iPtr);
+#else
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(result, -1));
+ if (result == NULL || freeProc == NULL || freeProc == TCL_VOLATILE) {
+ return;
+ }
+ if (freeProc == TCL_DYNAMIC) {
+ ckfree(result);
+ } else {
+ (*freeProc)(result);
+ }
+#endif
}
/*
@@ -482,6 +502,7 @@ const char *
Tcl_GetStringResult(
register Tcl_Interp *interp)/* Interpreter whose result to return. */
{
+#if 0
/*
* If the string result is empty, move the object result to the string
* result, then reset the object result.
@@ -494,6 +515,10 @@ Tcl_GetStringResult(
TCL_VOLATILE);
}
return iPtr->result;
+#else
+ Interp *iPtr = (Interp *)interp;
+ return Tcl_GetString(iPtr->objResultPtr);
+#endif
}
/*
@@ -535,6 +560,7 @@ Tcl_SetObjResult(
TclDecrRefCount(oldObjResult);
+#if 0
/*
* Reset the string result since we just set the result object.
*/
@@ -549,6 +575,7 @@ Tcl_SetObjResult(
}
iPtr->result = iPtr->resultSpace;
iPtr->resultSpace[0] = 0;
+#endif
}
/*
@@ -577,6 +604,7 @@ Tcl_GetObjResult(
Tcl_Interp *interp) /* Interpreter whose result to return. */
{
register Interp *iPtr = (Interp *) interp;
+#if 0
Tcl_Obj *objResultPtr;
int length;
@@ -603,6 +631,7 @@ Tcl_GetObjResult(
iPtr->result = iPtr->resultSpace;
iPtr->resultSpace[0] = 0;
}
+#endif
return iPtr->objResultPtr;
}
@@ -721,6 +750,7 @@ Tcl_AppendElement(
* to result. */
{
Interp *iPtr = (Interp *) interp;
+#if 0
char *dst;
int size;
int flags;
@@ -764,7 +794,24 @@ Tcl_AppendElement(
flags |= TCL_DONT_QUOTE_HASH;
}
iPtr->appendUsed += Tcl_ConvertElement(element, dst, flags);
+#else
+ Tcl_Obj *elementPtr = Tcl_NewStringObj(element, -1);
+ Tcl_Obj *listPtr = Tcl_NewListObj(1, &elementPtr);
+ int length;
+ const char *bytes;
+
+ if (Tcl_IsShared(iPtr->objResultPtr)) {
+ Tcl_SetObjResult(interp, Tcl_DuplicateObj(iPtr->objResultPtr));
+ }
+ bytes = Tcl_GetStringFromObj(iPtr->objResultPtr, &length);
+ if (TclNeedSpace(bytes, bytes+length)) {
+ Tcl_AppendToObj(iPtr->objResultPtr, " ", 1);
+ }
+ Tcl_AppendObjToObj(iPtr->objResultPtr, listPtr);
+ Tcl_DecrRefCount(listPtr);
+#endif
}
+#if 0
/*
*----------------------------------------------------------------------
@@ -845,6 +892,7 @@ SetupAppendBuffer(
Tcl_FreeResult((Tcl_Interp *) iPtr);
iPtr->result = iPtr->appendResult;
}
+#endif
/*
*----------------------------------------------------------------------
@@ -874,6 +922,7 @@ Tcl_FreeResult(
{
register Interp *iPtr = (Interp *) interp;
+#if 0
if (iPtr->freeProc != NULL) {
if (iPtr->freeProc == TCL_DYNAMIC) {
ckfree(iPtr->result);
@@ -882,6 +931,7 @@ Tcl_FreeResult(
}
iPtr->freeProc = 0;
}
+#endif
ResetObjResult(iPtr);
}
@@ -912,6 +962,7 @@ Tcl_ResetResult(
register Interp *iPtr = (Interp *) interp;
ResetObjResult(iPtr);
+#if 0
if (iPtr->freeProc != NULL) {
if (iPtr->freeProc == TCL_DYNAMIC) {
ckfree(iPtr->result);
@@ -922,6 +973,7 @@ Tcl_ResetResult(
}
iPtr->result = iPtr->resultSpace;
iPtr->resultSpace[0] = 0;
+#endif
if (iPtr->errorCode) {
/* Legacy support */
if (iPtr->flags & ERR_LEGACY_COPY) {
diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c
index f569820..71933a0 100644
--- a/generic/tclStubLib.c
+++ b/generic/tclStubLib.c
@@ -41,10 +41,16 @@ HasStubSupport(
if (iPtr->stubTable && (iPtr->stubTable->magic == TCL_STUB_MAGIC)) {
return iPtr->stubTable;
}
-
+#if 0
iPtr->result =
(char *)"This interpreter does not support stubs-enabled extensions.";
iPtr->freeProc = TCL_STATIC;
+#else
+ Tcl_Obj errorMsg = {2,
+ "This interpreter does not support stubs-enabled extensions.",
+ 59, NULL, {0}};
+ iPtr->objResultPtr = &errorMsg;
+#endif
return NULL;
}
diff --git a/generic/tclTest.c b/generic/tclTest.c
index 37ec751..1a189c7 100644
--- a/generic/tclTest.c
+++ b/generic/tclTest.c
@@ -120,12 +120,14 @@ typedef struct TclEncoding {
char *fromUtfCmd;
} TclEncoding;
+#if 0
/*
* The counter below is used to determine if the TestsaveresultFree routine
* was called for a result.
*/
static int freeCount;
+#endif
/*
* Boolean flag used by the "testsetmainloop" and "testexitmainloop" commands.
@@ -5063,7 +5065,9 @@ TestsaveresultCmd(
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* The argument objects. */
{
+#if 0
Interp* iPtr = (Interp*) interp;
+#endif
int discard, result, index;
Tcl_SavedResult state;
Tcl_Obj *objPtr;
@@ -5114,7 +5118,9 @@ TestsaveresultCmd(
break;
}
+#if 0
freeCount = 0;
+#endif
Tcl_SaveResult(interp, &state);
if (((enum options) index) == RESULT_OBJECT) {
@@ -5132,11 +5138,16 @@ TestsaveresultCmd(
switch ((enum options) index) {
case RESULT_DYNAMIC: {
+#if 0
int present = iPtr->freeProc == TestsaveresultFree;
int called = freeCount;
Tcl_AppendElement(interp, called ? "called" : "notCalled");
Tcl_AppendElement(interp, present ? "present" : "missing");
+#else
+ Tcl_AppendElement(interp, discard ? "called" : "notCalled");
+ Tcl_AppendElement(interp, !discard ? "present" : "missing");
+#endif
break;
}
case RESULT_OBJECT:
@@ -5169,7 +5180,9 @@ static void
TestsaveresultFree(
char *blockPtr)
{
+#if 0
freeCount++;
+#endif
}
/*
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index a1c1996..32b1bfe 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -2626,6 +2626,7 @@ Tcl_DStringResult(
Tcl_DString *dsPtr) /* Dynamic string that is to become the
* result of interp. */
{
+#if 0
Interp *iPtr = (Interp *) interp;
Tcl_ResetResult(interp);
@@ -2637,8 +2638,11 @@ Tcl_DStringResult(
iPtr->result = iPtr->resultSpace;
memcpy(iPtr->result, dsPtr->string, dsPtr->length + 1);
} else {
+#endif
Tcl_SetResult(interp, dsPtr->string, TCL_VOLATILE);
+#if 0
}
+#endif
dsPtr->string = dsPtr->staticSpace;
dsPtr->length = 0;
@@ -2672,6 +2676,7 @@ Tcl_DStringGetResult(
Tcl_DString *dsPtr) /* Dynamic string that is to become the result
* of interp. */
{
+#if 0
Interp *iPtr = (Interp *) interp;
if (dsPtr->string != dsPtr->staticSpace) {
@@ -2710,6 +2715,14 @@ Tcl_DStringGetResult(
iPtr->result = iPtr->resultSpace;
iPtr->resultSpace[0] = 0;
+#else
+ int length;
+ char *bytes = Tcl_GetStringFromObj(Tcl_GetObjResult(interp), &length);
+
+ Tcl_DStringFree(dsPtr);
+ Tcl_DStringAppend(dsPtr, bytes, length);
+ Tcl_ResetResult(interp);
+#endif
}
/*