From 88574b7bc539d00b6477f8d9bbe7f25158b57662 Mon Sep 17 00:00:00 2001 From: dgp Date: Wed, 18 Apr 2012 18:42:54 +0000 Subject: 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. --- generic/tcl.h | 16 +++++++++------- generic/tclBasic.c | 42 +++++++++++++++++++++++++++++++++++------- generic/tclHistory.c | 2 ++ generic/tclInt.h | 15 +++++++++++++++ generic/tclResult.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ generic/tclStubLib.c | 8 +++++++- generic/tclTest.c | 13 +++++++++++++ generic/tclUtil.c | 13 +++++++++++++ 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 } /* -- cgit v0.12 From e76fa60cb994bd0ad5fce8614a682f88e65c2e8a Mon Sep 17 00:00:00 2001 From: dkf Date: Thu, 19 Apr 2012 12:41:06 +0000 Subject: Clean version of changes; ifdef-free --- generic/tcl.h | 32 +---- generic/tclBasic.c | 105 +-------------- generic/tclHistory.c | 9 -- generic/tclInt.h | 43 +------ generic/tclResult.c | 358 +-------------------------------------------------- generic/tclStubLib.c | 14 +- generic/tclTest.c | 30 +---- generic/tclUtil.c | 59 +-------- 8 files changed, 22 insertions(+), 628 deletions(-) diff --git a/generic/tcl.h b/generic/tcl.h index 46266d2..a7d3917 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -499,37 +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. */ -#ifdef USE_INTERP_RESULT - char *result TCL_DEPRECATED_API("use Tcl_GetResult/Tcl_SetResult"); - /* If the last command returned a string - * result, this points to it. */ - void (*freeProc) (char *blockPtr) - TCL_DEPRECATED_API("use Tcl_GetResult/Tcl_SetResult"); - /* Zero means the string result is statically - * allocated. TCL_DYNAMIC means it was - * allocated with ckalloc and should be freed - * with ckfree. Other values give the address - * of function to invoke to free the result. - * Tcl_Eval must free it before executing next - * command. */ -#else - char *unused3 TCL_DEPRECATED_API("bad field access"); - void (*unused4) (char *) TCL_DEPRECATED_API("bad field access"); -#endif -#ifdef USE_INTERP_ERRORLINE - int errorLine TCL_DEPRECATED_API("use Tcl_GetErrorLine/Tcl_SetErrorLine"); - /* When TCL_ERROR is returned, this gives the - * line number within the command where the - * error occurred (1 if first line). */ -#else - int unused5 TCL_DEPRECATED_API("bad field access"); -#endif -} Tcl_Interp; -#endif + typedef struct Tcl_Interp Tcl_Interp; typedef struct Tcl_AsyncHandler_ *Tcl_AsyncHandler; diff --git a/generic/tclBasic.c b/generic/tclBasic.c index d55faeb..a66b8b2 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -503,10 +503,6 @@ 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); @@ -562,12 +558,6 @@ 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; @@ -595,9 +585,6 @@ 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 */ @@ -1499,9 +1486,6 @@ DeleteInterpProc( */ Tcl_FreeResult(interp); -#if 0 - iPtr->result = NULL; -#endif Tcl_DecrRefCount(iPtr->objResultPtr); iPtr->objResultPtr = NULL; Tcl_DecrRefCount(iPtr->ecVar); @@ -1523,12 +1507,6 @@ 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); @@ -2435,15 +2413,6 @@ 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 * free the objv array if malloc'ed storage was used. @@ -4345,26 +4314,9 @@ TclNRRunCallbacks( /* All callbacks down to rootPtr not inclusive * are to be run. */ { -/* 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 - * directly. If so, move the string result to the result object, then - * reset the string result. - * - * This only needs to be done for the first item in the list: all other - * are for NR function calls, and those are Tcl_Obj based. - */ - - if (*(iPtr->result) != 0) { - (void) Tcl_GetObjResult(interp); - } -#endif - while (TOP_CB(interp) != rootPtr) { callbackPtr = TOP_CB(interp); procPtr = callbackPtr->procPtr; @@ -5842,18 +5794,6 @@ 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); - - /* - * For backwards compatibility with old C code that predates the object - * system in Tcl 8.0, we have to mirror the object result back into the - * string result (some callers may expect it there). - */ - - (void) Tcl_GetStringResult(interp); - return code; -#endif return Tcl_EvalEx(interp, script, -1, 0); } @@ -6352,11 +6292,6 @@ 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; } @@ -6383,11 +6318,6 @@ 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; } @@ -6413,16 +6343,6 @@ 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 - * reset the object result. - */ - - (void) Tcl_GetStringResult(interp); - } -#endif return result; } } @@ -6747,13 +6667,6 @@ Tcl_ExprString( Tcl_DecrRefCount(resultPtr); } } -#if 0 - /* - * Force the string rep of the interp result. - */ - - (void) Tcl_GetStringResult(interp); -#endif return code; } @@ -6857,23 +6770,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 - * making a deprecated direct write to it. That extension may - * expect interp->result to continue to be set, so we'll take - * special pains to avoid clearing it, until we drop support for - * interp->result completely. - */ - - iPtr->errorInfo = Tcl_NewStringObj(iPtr->result, -1); - } else { -#endif - iPtr->errorInfo = iPtr->objResultPtr; -#if 0 - } -#endif + iPtr->errorInfo = iPtr->objResultPtr; Tcl_IncrRefCount(iPtr->errorInfo); if (!iPtr->errorCode) { Tcl_SetErrorCode(interp, "NONE", NULL); diff --git a/generic/tclHistory.c b/generic/tclHistory.c index 5448365..c44ba4c 100644 --- a/generic/tclHistory.c +++ b/generic/tclHistory.c @@ -74,15 +74,6 @@ 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 0d541a8..fa7c03c 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -1800,32 +1800,16 @@ typedef struct Interp { * Tcl_Interp struct (see tcl.h). If you change one, be sure to change the * other. * - * The interpreter's result is held in both the string and the - * objResultPtr fields. These fields hold, respectively, the result's - * string or object value. The interpreter's result is always in the - * result field if that is non-empty, otherwise it is in objResultPtr. - * The two fields are kept consistent unless some C code sets - * interp->result directly. Programs should not access result and - * objResultPtr directly; instead, they should always get and set the - * result using procedures such as Tcl_SetObjResult, Tcl_GetObjResult, and - * Tcl_GetStringResult. See the SetResult man page for details. + * The interpreter's result is held in the objResultPtr field. This field + * holds the result's object value. The interpreter's result is always in + * objResultPtr. Programs should not access objResultPtr directly; + * instead, they should always get and set the result using procedures + * such as Tcl_SetObjResult, Tcl_GetObjResult, and 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. */ - Tcl_FreeProc *freeProc; /* Zero means a string result is statically - * allocated. TCL_DYNAMIC means string result - * was allocated with ckalloc and should be - * freed with ckfree. Other values give - * 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). */ @@ -1883,19 +1867,9 @@ 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. */ - int appendAvl; /* Total amount of space available at - * 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. @@ -1957,12 +1931,7 @@ 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 cbaefcb..693c650 100644 --- a/generic/tclResult.c +++ b/generic/tclResult.c @@ -27,9 +27,6 @@ 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 @@ -248,46 +245,6 @@ Tcl_SaveResult( statePtr->objResultPtr = iPtr->objResultPtr; iPtr->objResultPtr = Tcl_NewObj(); Tcl_IncrRefCount(iPtr->objResultPtr); - -#if 0 - /* - * Save the string result. - */ - - statePtr->freeProc = iPtr->freeProc; - if (iPtr->result == iPtr->resultSpace) { - /* - * Copy the static string data out of the interp buffer. - */ - - statePtr->result = statePtr->resultSpace; - strcpy(statePtr->result, iPtr->result); - statePtr->appendResult = NULL; - } else if (iPtr->result == iPtr->appendResult) { - /* - * Move the append buffer out of the interp. - */ - - statePtr->appendResult = iPtr->appendResult; - statePtr->appendAvl = iPtr->appendAvl; - statePtr->appendUsed = iPtr->appendUsed; - statePtr->result = statePtr->appendResult; - iPtr->appendResult = NULL; - iPtr->appendAvl = 0; - iPtr->appendUsed = 0; - } else { - /* - * Move the dynamic or static string out of the interpreter. - */ - - statePtr->result = iPtr->result; - statePtr->appendResult = NULL; - } - - iPtr->result = iPtr->resultSpace; - iPtr->resultSpace[0] = 0; - iPtr->freeProc = 0; -#endif } /* @@ -317,41 +274,6 @@ Tcl_RestoreResult( Tcl_ResetResult(interp); -#if 0 - /* - * Restore the string result. - */ - - iPtr->freeProc = statePtr->freeProc; - if (statePtr->result == statePtr->resultSpace) { - /* - * Copy the static string data into the interp buffer. - */ - - iPtr->result = iPtr->resultSpace; - strcpy(iPtr->result, statePtr->result); - } else if (statePtr->result == statePtr->appendResult) { - /* - * Move the append buffer back into the interp. - */ - - if (iPtr->appendResult != NULL) { - ckfree(iPtr->appendResult); - } - - iPtr->appendResult = statePtr->appendResult; - iPtr->appendAvl = statePtr->appendAvl; - iPtr->appendUsed = statePtr->appendUsed; - iPtr->result = iPtr->appendResult; - } else { - /* - * Move the dynamic or static string back into the interpreter. - */ - - iPtr->result = statePtr->result; - } -#endif - /* * Restore the object result. */ @@ -383,18 +305,6 @@ Tcl_DiscardResult( Tcl_SavedResult *statePtr) /* State returned by Tcl_SaveResult. */ { TclDecrRefCount(statePtr->objResultPtr); - -#if 0 - if (statePtr->result == statePtr->appendResult) { - ckfree(statePtr->appendResult); - } else if (statePtr->freeProc) { - if (statePtr->freeProc == TCL_DYNAMIC) { - ckfree(statePtr->result); - } else { - statePtr->freeProc(statePtr->result); - } - } -#endif } /* @@ -424,51 +334,6 @@ 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; - - if (result == NULL) { - iPtr->resultSpace[0] = 0; - iPtr->result = iPtr->resultSpace; - iPtr->freeProc = 0; - } else if (freeProc == TCL_VOLATILE) { - int length = strlen(result); - - if (length > TCL_RESULT_SIZE) { - iPtr->result = ckalloc(length + 1); - iPtr->freeProc = TCL_DYNAMIC; - } else { - iPtr->result = iPtr->resultSpace; - iPtr->freeProc = 0; - } - memcpy(iPtr->result, result, (unsigned) length+1); - } else { - iPtr->result = (char *) result; - iPtr->freeProc = freeProc; - } - - /* - * If the old result was dynamically-allocated, free it up. Do it here, - * rather than at the beginning, in case the new result value was part of - * the old result value. - */ - - if (oldFreeProc != 0) { - if (oldFreeProc == TCL_DYNAMIC) { - ckfree(oldResult); - } else { - oldFreeProc(oldResult); - } - } - - /* - * Reset the object result since we just set the string result. - */ - - ResetObjResult(iPtr); -#else Tcl_SetObjResult(interp, Tcl_NewStringObj(result, -1)); if (result == NULL || freeProc == NULL || freeProc == TCL_VOLATILE) { return; @@ -478,7 +343,6 @@ Tcl_SetResult( } else { (*freeProc)(result); } -#endif } /* @@ -502,23 +366,9 @@ 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. - */ - Interp *iPtr = (Interp *) interp; - if (*(iPtr->result) == 0) { - Tcl_SetResult(interp, TclGetString(Tcl_GetObjResult(interp)), - TCL_VOLATILE); - } - return iPtr->result; -#else - Interp *iPtr = (Interp *)interp; return Tcl_GetString(iPtr->objResultPtr); -#endif } /* @@ -559,23 +409,6 @@ Tcl_SetObjResult( */ TclDecrRefCount(oldObjResult); - -#if 0 - /* - * Reset the string result since we just set the result object. - */ - - if (iPtr->freeProc != NULL) { - if (iPtr->freeProc == TCL_DYNAMIC) { - ckfree(iPtr->result); - } else { - iPtr->freeProc(iPtr->result); - } - iPtr->freeProc = 0; - } - iPtr->result = iPtr->resultSpace; - iPtr->resultSpace[0] = 0; -#endif } /* @@ -604,34 +437,7 @@ Tcl_GetObjResult( Tcl_Interp *interp) /* Interpreter whose result to return. */ { register Interp *iPtr = (Interp *) interp; -#if 0 - Tcl_Obj *objResultPtr; - int length; - - /* - * If the string result is non-empty, move the string result to the object - * result, then reset the string result. - */ - if (*(iPtr->result) != 0) { - ResetObjResult(iPtr); - - objResultPtr = iPtr->objResultPtr; - length = strlen(iPtr->result); - TclInitStringRep(objResultPtr, iPtr->result, length); - - if (iPtr->freeProc != NULL) { - if (iPtr->freeProc == TCL_DYNAMIC) { - ckfree(iPtr->result); - } else { - iPtr->freeProc(iPtr->result); - } - iPtr->freeProc = 0; - } - iPtr->result = iPtr->resultSpace; - iPtr->resultSpace[0] = 0; - } -#endif return iPtr->objResultPtr; } @@ -750,51 +556,6 @@ Tcl_AppendElement( * to result. */ { Interp *iPtr = (Interp *) interp; -#if 0 - char *dst; - int size; - int flags; - - /* - * If the string result is empty, move the object result to the string - * result, then reset the object result. - */ - - (void) Tcl_GetStringResult(interp); - - /* - * See how much space is needed, and grow the append buffer if needed to - * accommodate the list element. - */ - - size = Tcl_ScanElement(element, &flags) + 1; - if ((iPtr->result != iPtr->appendResult) - || (iPtr->appendResult[iPtr->appendUsed] != 0) - || ((size + iPtr->appendUsed) >= iPtr->appendAvl)) { - SetupAppendBuffer(iPtr, size+iPtr->appendUsed); - } - - /* - * Convert the string into a list element and copy it to the buffer that's - * forming, with a space separator if needed. - */ - - dst = iPtr->appendResult + iPtr->appendUsed; - if (TclNeedSpace(iPtr->appendResult, dst)) { - iPtr->appendUsed++; - *dst = ' '; - dst++; - - /* - * If we need a space to separate this element from preceding stuff, - * then this element will not lead a list, and need not have it's - * leading '#' quoted. - */ - - 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; @@ -809,90 +570,7 @@ Tcl_AppendElement( } Tcl_AppendObjToObj(iPtr->objResultPtr, listPtr); Tcl_DecrRefCount(listPtr); -#endif -} -#if 0 - -/* - *---------------------------------------------------------------------- - * - * SetupAppendBuffer -- - * - * This function makes sure that there is an append buffer properly - * initialized, if necessary, from the interpreter's result, and that it - * has at least enough room to accommodate newSpace new bytes of - * information. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -static void -SetupAppendBuffer( - Interp *iPtr, /* Interpreter whose result is being set up. */ - int newSpace) /* Make sure that at least this many bytes of - * new information may be added. */ -{ - int totalSpace; - - /* - * Make the append buffer larger, if that's necessary, then copy the - * result into the append buffer and make the append buffer the official - * Tcl result. - */ - - if (iPtr->result != iPtr->appendResult) { - /* - * If an oversized buffer was used recently, then free it up so we go - * back to a smaller buffer. This avoids tying up memory forever after - * a large operation. - */ - - if (iPtr->appendAvl > 500) { - ckfree(iPtr->appendResult); - iPtr->appendResult = NULL; - iPtr->appendAvl = 0; - } - iPtr->appendUsed = strlen(iPtr->result); - } else if (iPtr->result[iPtr->appendUsed] != 0) { - /* - * Most likely someone has modified a result created by - * Tcl_AppendResult et al. so that it has a different size. Just - * recompute the size. - */ - - iPtr->appendUsed = strlen(iPtr->result); - } - - totalSpace = newSpace + iPtr->appendUsed; - if (totalSpace >= iPtr->appendAvl) { - char *new; - - if (totalSpace < 100) { - totalSpace = 200; - } else { - totalSpace *= 2; - } - new = ckalloc(totalSpace); - strcpy(new, iPtr->result); - if (iPtr->appendResult != NULL) { - ckfree(iPtr->appendResult); - } - iPtr->appendResult = new; - iPtr->appendAvl = totalSpace; - } else if (iPtr->result != iPtr->appendResult) { - strcpy(iPtr->appendResult, iPtr->result); - } - - Tcl_FreeResult((Tcl_Interp *) iPtr); - iPtr->result = iPtr->appendResult; } -#endif /* *---------------------------------------------------------------------- @@ -900,18 +578,17 @@ SetupAppendBuffer( * Tcl_FreeResult -- * * This function frees up the memory associated with an interpreter's - * string result. It also resets the interpreter's result object. - * Tcl_FreeResult is most commonly used when a function is about to - * replace one result value with another. + * result, resetting the interpreter's result object. Tcl_FreeResult is + * most commonly used when a function is about to replace one result + * value with another. * * Results: * None. * * Side effects: - * Frees the memory associated with interp's string result and sets - * interp->freeProc to zero, but does not change interp->result or clear - * error state. Resets interp's result object to an unshared empty - * object. + * Frees the memory associated with interp's result but does not change + * any part of the error dictionary (i.e., the errorinfo and errorcode + * remain the same). * *---------------------------------------------------------------------- */ @@ -922,17 +599,6 @@ Tcl_FreeResult( { register Interp *iPtr = (Interp *) interp; -#if 0 - if (iPtr->freeProc != NULL) { - if (iPtr->freeProc == TCL_DYNAMIC) { - ckfree(iPtr->result); - } else { - iPtr->freeProc(iPtr->result); - } - iPtr->freeProc = 0; - } -#endif - ResetObjResult(iPtr); } @@ -962,18 +628,6 @@ Tcl_ResetResult( register Interp *iPtr = (Interp *) interp; ResetObjResult(iPtr); -#if 0 - if (iPtr->freeProc != NULL) { - if (iPtr->freeProc == TCL_DYNAMIC) { - ckfree(iPtr->result); - } else { - iPtr->freeProc(iPtr->result); - } - iPtr->freeProc = 0; - } - 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 71933a0..b36627c 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -37,20 +37,16 @@ HasStubSupport( Tcl_Interp *interp) { Interp *iPtr = (Interp *) interp; + static Tcl_Obj errorMsg = { + 2, /* Stop anything from trying to deallocate this memory! */ + "This interpreter does not support stubs-enabled extensions.", + 59, NULL, {0} + }; 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 1a189c7..b407f51 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -120,15 +120,6 @@ 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. */ @@ -5065,9 +5056,6 @@ 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; @@ -5118,9 +5106,6 @@ TestsaveresultCmd( break; } -#if 0 - freeCount = 0; -#endif Tcl_SaveResult(interp, &state); if (((enum options) index) == RESULT_OBJECT) { @@ -5137,19 +5122,10 @@ 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 + case RESULT_DYNAMIC: Tcl_AppendElement(interp, discard ? "called" : "notCalled"); Tcl_AppendElement(interp, !discard ? "present" : "missing"); -#endif break; - } case RESULT_OBJECT: Tcl_AppendElement(interp, Tcl_GetObjResult(interp) == objPtr ? "same" : "different"); @@ -5180,9 +5156,7 @@ static void TestsaveresultFree( char *blockPtr) { -#if 0 - freeCount++; -#endif + /* empty... */ } /* diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 32b1bfe..f316dfb 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -2626,23 +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); - - if (dsPtr->string != dsPtr->staticSpace) { - iPtr->result = dsPtr->string; - iPtr->freeProc = TCL_DYNAMIC; - } else if (dsPtr->length < TCL_RESULT_SIZE) { - iPtr->result = iPtr->resultSpace; - memcpy(iPtr->result, dsPtr->string, dsPtr->length + 1); - } else { -#endif - Tcl_SetResult(interp, dsPtr->string, TCL_VOLATILE); -#if 0 - } -#endif + Tcl_SetResult(interp, dsPtr->string, TCL_VOLATILE); dsPtr->string = dsPtr->staticSpace; dsPtr->length = 0; @@ -2676,53 +2660,12 @@ 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) { - ckfree(dsPtr->string); - } - - /* - * If the string result is empty, move the object result to the string - * result, then reset the object result. - */ - - (void) Tcl_GetStringResult(interp); - - dsPtr->length = strlen(iPtr->result); - if (iPtr->freeProc != NULL) { - if (iPtr->freeProc == TCL_DYNAMIC) { - dsPtr->string = iPtr->result; - dsPtr->spaceAvl = dsPtr->length+1; - } else { - dsPtr->string = ckalloc(dsPtr->length+1); - memcpy(dsPtr->string, iPtr->result, (unsigned) dsPtr->length+1); - iPtr->freeProc(iPtr->result); - } - dsPtr->spaceAvl = dsPtr->length+1; - iPtr->freeProc = NULL; - } else { - if (dsPtr->length < TCL_DSTRING_STATIC_SIZE) { - dsPtr->string = dsPtr->staticSpace; - dsPtr->spaceAvl = TCL_DSTRING_STATIC_SIZE; - } else { - dsPtr->string = ckalloc(dsPtr->length+1); - dsPtr->spaceAvl = dsPtr->length + 1; - } - memcpy(dsPtr->string, iPtr->result, (unsigned) dsPtr->length+1); - } - - 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 } /* -- cgit v0.12 From b8074d77342d4166a599b933a111edd467153894 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 19 Apr 2012 12:57:45 +0000 Subject: To preserve the ability of [load] to bring in mistmatched stubs-enabled modules and react with an error rather than a crash, HasStubSupport() has to keep fiddling with the same fields as always. --- generic/tclStubLib.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c index b36627c..9e9208d 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -37,16 +37,13 @@ HasStubSupport( Tcl_Interp *interp) { Interp *iPtr = (Interp *) interp; - static Tcl_Obj errorMsg = { - 2, /* Stop anything from trying to deallocate this memory! */ - "This interpreter does not support stubs-enabled extensions.", - 59, NULL, {0} - }; if (iPtr->stubTable && (iPtr->stubTable->magic == TCL_STUB_MAGIC)) { return iPtr->stubTable; } - iPtr->objResultPtr = &errorMsg; + iPtr->unused3 + = "This interpreter does not support stubs-enabled extensions."; + iPtr->unused4 = TCL_STATIC; return NULL; } -- cgit v0.12 From bc2133334d0fb3580be3b1cd65ed85b991887e68 Mon Sep 17 00:00:00 2001 From: dgp Date: Wed, 25 Apr 2012 21:03:58 +0000 Subject: Implement Tcl_DStringResult with call to TclDStringToObj. --- generic/tclUtil.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 8852a56..1e35165 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -2626,12 +2626,7 @@ Tcl_DStringResult( Tcl_DString *dsPtr) /* Dynamic string that is to become the * result of interp. */ { - Tcl_SetResult(interp, dsPtr->string, TCL_VOLATILE); - - dsPtr->string = dsPtr->staticSpace; - dsPtr->length = 0; - dsPtr->spaceAvl = TCL_DSTRING_STATIC_SIZE; - dsPtr->staticSpace[0] = '\0'; + Tcl_SetObjResult(interp, TclDStringToObj(dsPtr)); } /* -- cgit v0.12 From d0aa8bd6eb7c9ef510cf66beb42922019e05180d Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 26 Nov 2012 21:25:26 +0000 Subject: Comments and renamings around the legacy fields for string results. --- generic/tclInt.h | 38 ++++++++++++++++++++------------------ generic/tclStubLib.c | 27 +++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/generic/tclInt.h b/generic/tclInt.h index 7ed9bdf..90f283c 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -1799,31 +1799,33 @@ typedef struct AllocCache { */ typedef struct Interp { + /* - * Note: the first three fields must match exactly the fields in a - * Tcl_Interp struct (see tcl.h). If you change one, be sure to change the - * other. - * - * The interpreter's result is held in the objResultPtr field. This field - * holds the result's object value. The interpreter's result is always in - * objResultPtr. Programs should not access objResultPtr directly; - * instead, they should always get and set the result using procedures - * such as Tcl_SetObjResult, Tcl_GetObjResult, and Tcl_GetStringResult. - * See the SetResult man page for details. + * The first two fields were named "result" and "freeProc" in earlier + * versions of Tcl. They are no longer used within Tcl, and are no + * longer available to be accessed by extensions. However, they cannot + * be removed. Why? There is a deployed base of stub-enabled extensions + * that query the value of iPtr->stubTable. For them to continue to work, + * the location of the field "stubTable" within the Interp struct cannot + * change. The most robust way to assure that is to leave all fields up to + * that one undisturbed. */ - char *unused3; - Tcl_FreeProc *unused4; + char *legacyResult; + Tcl_FreeProc *legacyFreeProc; int errorLine; /* When TCL_ERROR is returned, this gives the * line number in the command where the error * occurred (1 means first line). */ const struct TclStubs *stubTable; - /* Pointer to the exported Tcl stub table. On - * previous versions of Tcl this is a pointer - * to the objResultPtr or a pointer to a - * buckets array in a hash table. We therefore - * have to do some careful checking before we - * can use this. */ + /* Pointer to the exported Tcl stub table. In + * ancient pre-8.1 versions of Tcl this was a + * pointer to the objResultPtr or a pointer to a + * buckets array in a hash table. Deployed stubs + * enabled extensions check for a NULL pointer value + * and for a TCL_STUBS_MAGIC value to verify they + * are not [load]ing into one of those pre-stubs + * interps. + */ TclHandle handle; /* Handle used to keep track of when this * interp is deleted. */ diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c index 9e9208d..35c7f09 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -41,9 +41,32 @@ HasStubSupport( if (iPtr->stubTable && (iPtr->stubTable->magic == TCL_STUB_MAGIC)) { return iPtr->stubTable; } - iPtr->unused3 + + /* + * Either interp has no stubTable field, or its magic number has been + * changed, indicating a release of Tcl that no longer supports the + * stubs mechanism with which the extension has been prepared. This + * either means interp comes from Tcl releases 7.5 - 8.0, when [load] + * of extensions was possible, but stubs were not yet in use, or it means + * interp come from some future release of Tcl where it has been necessary + * to stop supporting this particular stubs mechanism. In either case, + * we can count on the fields legacyResult and legacyFreeProc existing + * (since they persist to maintain the struct offset fo stubTable; see + * tclInt.h comments.), and we can hope that [load] or any sensible + * successor will be able to reach into them to report the mismatch error + * message sensibly. + * + * For maximum compat support, even if only for the sake of reporting + * clean errors, rather than crashing, we assume the TCL_STUB_MAGIC + * value is changed only when absolutely necessary. So long as the first + * slot in the stub table holds (some function compatible with) the routine + * Tcl_PkgRequireEx(), that routine can take care of verifying the version + * compatibility testing with all deployed + */ + + iPtr->legacyResult = "This interpreter does not support stubs-enabled extensions."; - iPtr->unused4 = TCL_STATIC; + iPtr->legacyFreeProc = TCL_STATIC; return NULL; } -- cgit v0.12 From 41e4423638af6265a31c1d9a83d1626801ed5b90 Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 26 Nov 2012 21:30:13 +0000 Subject: ...and here's the lines left behind in the editor. --- generic/tclStubLib.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c index 35c7f09..fe1302c 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -61,7 +61,10 @@ HasStubSupport( * value is changed only when absolutely necessary. So long as the first * slot in the stub table holds (some function compatible with) the routine * Tcl_PkgRequireEx(), that routine can take care of verifying the version - * compatibility testing with all deployed + * compatibility testing with all deployed stubs-enabled extensions. That is, + * there is no need to change the value of TCL_STUB_MAGIC when transitioning + * from the Tcl 8 stubs table to the Tcl 9 stubs table, so long as they + * share just their first slot in common. */ iPtr->legacyResult -- cgit v0.12 From cbc47c069d3d222ae06bb469960912be8f12ef2b Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 26 Nov 2012 22:23:43 +0000 Subject: Stop segfaults in test suite. --- generic/tclBasic.c | 1 + generic/tclLoad.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 3906c0a..abfc456 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -485,6 +485,7 @@ Tcl_CreateInterp(void) iPtr = ckalloc(sizeof(Interp)); interp = (Tcl_Interp *) iPtr; + iPtr->legacyResult = NULL; iPtr->errorLine = 0; iPtr->objResultPtr = Tcl_NewObj(); Tcl_IncrRefCount(iPtr->objResultPtr); diff --git a/generic/tclLoad.c b/generic/tclLoad.c index d4c67d7..ec1c617 100644 --- a/generic/tclLoad.c +++ b/generic/tclLoad.c @@ -472,11 +472,12 @@ Tcl_LoadObjCmd( Interp *iPtr = (Interp *) target; if (iPtr->legacyResult != NULL) { /* - * A call to Tcl_InitStubs() determined the caller extension and this - * interp are incompatible in their stubs mechanisms, and recorded the - * error in the oldest legacy place we have to do so. + * A call to Tcl_InitStubs() determined the caller extension and + * this interp are incompatible in their stubs mechanisms, and + * recorded the error in the oldest legacy place we have to do so. */ Tcl_SetObjResult(interp, Tcl_NewStringObj(iPtr->legacyResult, -1)); + iPtr->legacyResult = NULL; } else { Tcl_TransferResult(target, code, interp); } -- cgit v0.12 From 3c5544ba3c952c9e4415f040bfe93cb22041d02c Mon Sep 17 00:00:00 2001 From: dgp Date: Tue, 27 Nov 2012 21:09:20 +0000 Subject: 3588687 Added cross checks so that [load]ed extension, [load]ing interp, and linked stubs library all agree on their versions in the ways that matter. --- generic/tcl.h | 9 ++++++--- generic/tclStubLib.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/generic/tcl.h b/generic/tcl.h index 147672c..74dd452 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -2394,8 +2394,8 @@ typedef int (Tcl_NRPostProc) (ClientData data[], Tcl_Interp *interp, * main library in case an extension is statically linked into an application. */ -const char * Tcl_InitStubs(Tcl_Interp *interp, const char *version, - int exact); +const char * TclInitStubs(Tcl_Interp *interp, const char *version, + int exact, int major); const char * TclTomMathInitializeStubs(Tcl_Interp *interp, const char *version, int epoch, int revision); @@ -2403,7 +2403,10 @@ const char * TclTomMathInitializeStubs(Tcl_Interp *interp, * When not using stubs, make it a macro. */ -#ifndef USE_TCL_STUBS +#ifdef USE_TCL_STUBS +#define Tcl_InitStubs(interp, version, exact) \ + TclInitStubs(interp, version, exact, TCL_MAJOR_VERSION) +#else #define Tcl_InitStubs(interp, version, exact) \ Tcl_PkgInitStubsCheck(interp, version, exact) #endif diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c index f569820..ca6f4ff 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -76,13 +76,52 @@ static int isDigit(const int c) */ MODULE_SCOPE const char * -Tcl_InitStubs( +TclInitStubs( Tcl_Interp *interp, const char *version, - int exact) + int exact, + int major) { + Interp *iPtr = (Interp *) interp; const char *actualVersion = NULL; ClientData pkgData = NULL; + const char *p, *q; + + /* + * Detect whether the extension and the stubs library were built + * against Tcl header files from different major versions. That's + * seriously broken. + */ + + if (major != TCL_MAJOR_VERSION) { + iPtr->result = + (char *)"extension linked to incompatible stubs library"; + iPtr->freeProc = TCL_STATIC; + return NULL; + } + + /* + * Detect whether an extension compiled against a Tcl header file + * of one major version is requesting to use a stubs table of a + * different major version. According to our compat rules, that's + * a request that cannot succeed. Different major versions imply + * incompatible stub tables. + */ + + p = version; + q = TCL_VERSION; + while (isDigit(*p)) { + if (*p++ != *q++) { + goto badVersion; + } + } + if (isDigit(*q)) { + badVersion: + iPtr->result = + (char *)"extension passed bad version argument to stubs library"; + iPtr->freeProc = TCL_STATIC; + return NULL; + } /* * We can't optimize this check by caching tclStubsPtr because that @@ -100,14 +139,14 @@ Tcl_InitStubs( return NULL; } if (exact) { - const char *p = version; int count = 0; + p = version; while (*p) { count += !isDigit(*p++); } if (count == 1) { - const char *q = actualVersion; + q = actualVersion; p = version; while (*p && (*p == *q)) { @@ -140,6 +179,16 @@ Tcl_InitStubs( return actualVersion; } +#undef Tcl_InitStubs +MODULE_SCOPE const char * +Tcl_InitStubs( + Tcl_Interp *interp, + const char *version, + int exact) +{ + return TclInitStubs(interp, version, exact, TCL_MAJOR_VERSION); +} + /* * Local Variables: * mode: c -- cgit v0.12 From 1213e2c7212fed431301f7cc330ecde40cebf0eb Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 29 Nov 2012 16:52:45 +0000 Subject: Get the updated error message --- generic/tclStubLib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c index e875bf7..648ed24 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -68,7 +68,7 @@ HasStubSupport( */ iPtr->legacyResult - = "This interpreter does not support stubs-enabled extensions."; + = (char *) "interpreter uses an incompatible stubs mechanism"; iPtr->legacyFreeProc = TCL_STATIC; return NULL; } -- cgit v0.12 From 3382c0c47fc468888766bc6bdc9b32d9e485baa2 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 29 Nov 2012 17:03:17 +0000 Subject: missed bit of merge --- generic/tclStubLib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c index 648ed24..23085e2 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -85,7 +85,7 @@ static int isDigit(const int c) /* *---------------------------------------------------------------------- * - * Tcl_InitStubs -- + * TclInitStubs -- * * Tries to initialise the stub table pointers and ensures that the * correct version of Tcl is loaded. -- cgit v0.12 From 02e5732cffb9d23e1ea6612ee37c19a88e4891f2 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 29 Nov 2012 17:25:59 +0000 Subject: Proposed rollback of the TCL_STUB_MAGIC change on novem branch. --- generic/tcl.h | 7 ++--- generic/tclBasic.c | 23 -------------- generic/tclLoad.c | 3 +- generic/tclStubLib.c | 74 ++++++++++++++++++++++++++++++++-------------- generic/tclStubLibCompat.c | 57 ----------------------------------- unix/Makefile.in | 5 ---- win/Makefile.in | 4 --- win/makefile.vc | 1 - 8 files changed, 56 insertions(+), 118 deletions(-) delete mode 100644 generic/tclStubLibCompat.c diff --git a/generic/tcl.h b/generic/tcl.h index b9ff28c..91bf623 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -136,7 +136,6 @@ extern "C" { */ #include -#include /* *---------------------------------------------------------------------------- @@ -2276,7 +2275,7 @@ typedef int (Tcl_NRPostProc) (ClientData data[], Tcl_Interp *interp, * stubs tables. */ -#define TCL_STUB_MAGIC ((int) (0xFCA3BACB + sizeof(size_t))) +#define TCL_STUB_MAGIC ((int) 0xFCA3BACF) /* * The following function is required to be defined in all stubs aware @@ -2286,7 +2285,7 @@ typedef int (Tcl_NRPostProc) (ClientData data[], Tcl_Interp *interp, */ const char * TclInitStubs(Tcl_Interp *interp, const char *version, - int exact, int magic); + int exact, int major, int magic); const char * TclTomMathInitializeStubs(Tcl_Interp *interp, const char *version, int epoch, int revision); @@ -2296,7 +2295,7 @@ const char * TclTomMathInitializeStubs(Tcl_Interp *interp, #ifdef USE_TCL_STUBS #define Tcl_InitStubs(interp, version, exact) \ - TclInitStubs(interp, version, exact, TCL_STUB_MAGIC) + TclInitStubs(interp, version, exact, TCL_MAJOR_VERSION, TCL_STUB_MAGIC) #else #define Tcl_InitStubs(interp, version, exact) \ Tcl_PkgInitStubsCheck(interp, version, exact) diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 146247e..4f3b77e 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -431,14 +431,6 @@ TclFinalizeEvaluation(void) *---------------------------------------------------------------------- */ -/* Template for internal Interp structure: the stubTable entry cannot move! */ -typedef struct { - char *dumm1; - Tcl_FreeProc *dummy2; - int dummy3; - const struct TclStubs *stubTable; -} InterpTemplate; - Tcl_Interp * Tcl_CreateInterp(void) { @@ -474,21 +466,6 @@ Tcl_CreateInterp(void) /*NOTREACHED*/ Tcl_Panic("Tcl_CallFrame must not be smaller than CallFrame"); } - if ((void *) tclStubs.tcl_SetObjResult - != (void *)((&(tclStubs.tcl_PkgProvideEx))[235])) { - /*NOTREACHED*/ - Tcl_Panic("Tcl_SetObjResult entry in the stub table must be kept"); - } - if ((void *) tclStubs.tcl_NewStringObj - != (void *)((&(tclStubs.tcl_PkgProvideEx))[56])) { - /*NOTREACHED*/ - Tcl_Panic("Tcl_NewStringObj entry in the stub table must be kept"); - } - if (TclOffset(InterpTemplate, stubTable) - != TclOffset(Interp, stubTable)) { - /*NOTREACHED*/ - Tcl_Panic("stubsTable entry in the Interp structure must be kept"); - } if (cancelTableInitialized == 0) { Tcl_MutexLock(&cancelLock); diff --git a/generic/tclLoad.c b/generic/tclLoad.c index 61c763f..6f5b9cf 100644 --- a/generic/tclLoad.c +++ b/generic/tclLoad.c @@ -474,9 +474,8 @@ Tcl_LoadObjCmd( /* We have an Tcl 8.x extension with incompatible stub table. */ Tcl_Obj *obj = Tcl_NewStringObj(iPtr->result, -1); Tcl_SetObjResult(interp, obj); - } else { - Tcl_TransferResult(target, code, interp); } + Tcl_TransferResult(target, code, interp); goto done; } diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c index bd80ec1..f1229d5 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -34,29 +34,17 @@ const TclIntPlatStubs *tclIntPlatStubsPtr = NULL; static const TclStubs * HasStubSupport( - Tcl_Interp *interp, - int magic) + Tcl_Interp *interp) { Interp *iPtr = (Interp *) interp; - if (!iPtr->stubTable) { - /* No stub table at all? Nothing we can do. */ - return NULL; - } - if (iPtr->stubTable->magic != magic) { - /* - * The iPtr->stubTable entry from Tcl_Interp and the - * Tcl_NewStringObj() and Tcl_SetObjResult() entries - * in the stub table cannot change in Tcl 9 compared - * to Tcl 8.x. Otherwise the lines below won't work. - * TODO: add a test case for that. - */ - iPtr->stubTable->tcl_SetObjResult(interp, - iPtr->stubTable->tcl_NewStringObj( - "This extension is compiled for Tcl 9.x", -1)); - return NULL; + if (iPtr->stubTable && iPtr->stubTable->magic == TCL_STUB_MAGIC) { + return iPtr->stubTable; } - return iPtr->stubTable; + iPtr->result = + (char *) "interpreter uses an incompatible stubs mechanism"; + iPtr->freeProc = TCL_STATIC; + return NULL; } /* @@ -91,10 +79,52 @@ TclInitStubs( Tcl_Interp *interp, const char *version, int exact, + int major, int magic) { + Interp *iPtr = (Interp *) interp; const char *actualVersion = NULL; ClientData pkgData = NULL; + const char *p, *q; + + /* + * Detect whether the extension and the stubs library were built + * against Tcl header files declaring use of incompatible stubs + * mechanisms. Even within the same mechanism, also detect if + * the header files are from different major versions. Either + * is seriously broken. An extension and its stubs library ought + * to share compatible headers, if not the same one. + */ + + if (magic != TCL_STUB_MAGIC || major != TCL_MAJOR_VERSION) { + iPtr->result = + (char *) "extension linked to incompatible stubs library"; + iPtr->freeProc = TCL_STATIC; + return NULL; + } + + /* + * Detect whether an extension compiled against a Tcl header file + * of one major version is requesting to use a stubs table of a + * different major version. According to our compat rules, that's + * a request that cannot succeed. Different major versions imply + * incompatible stub tables. + */ + + p = version; + q = TCL_VERSION; + while (isDigit(*p)) { + if (*p++ != *q++) { + goto badVersion; + } + } + if (isDigit(*q)) { + badVersion: + iPtr->result = (char *) + "extension passed bad version argument to stubs library"; + iPtr->freeProc = TCL_STATIC; + return NULL; + } /* * We can't optimize this check by caching tclStubsPtr because that @@ -102,7 +132,7 @@ TclInitStubs( * times. [Bug 615304] */ - tclStubsPtr = HasStubSupport(interp, magic); + tclStubsPtr = HasStubSupport(interp); if (!tclStubsPtr) { return NULL; } @@ -112,14 +142,14 @@ TclInitStubs( return NULL; } if (exact) { - const char *p = version; + p = version; int count = 0; while (*p) { count += !isDigit(*p++); } if (count == 1) { - const char *q = actualVersion; + q = actualVersion; p = version; while (*p && (*p == *q)) { diff --git a/generic/tclStubLibCompat.c b/generic/tclStubLibCompat.c deleted file mode 100644 index 7d8c5c3..0000000 --- a/generic/tclStubLibCompat.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * tclStubLibCompat.c -- - * - * Stub object that will be statically linked into extensions that want - * to access Tcl. - * - * Copyright (c) 2012 Jan Nijtmans - * - * See the file "license.terms" for information on usage and redistribution of - * this file, and for a DISCLAIMER OF ALL WARRANTIES. - */ - -/* - * Small wrapper, which allows Tcl8 extensions to use the same stub - * library as Tcl 9. - */ - -#include "tclInt.h" - - -/* - *---------------------------------------------------------------------- - * - * Tcl_InitStubs -- - * - * Tries to initialise the stub table pointers and ensures that the - * correct version of Tcl is loaded. - * - * Results: - * The actual version of Tcl that satisfies the request, or NULL to - * indicate that an error occurred. - * - * Side effects: - * Sets the stub table pointers. - * - *---------------------------------------------------------------------- - */ -#undef Tcl_InitStubs - -MODULE_SCOPE const char * -Tcl_InitStubs( - Tcl_Interp *interp, - const char *version, - int exact) -{ - /* Use the hardcoded Tcl8 magic value here. */ - return TclInitStubs(interp, version, exact, (int) 0xFCA3BACF); -} - -/* - * Local Variables: - * mode: c - * c-basic-offset: 4 - * fill-column: 78 - * End: - */ - diff --git a/unix/Makefile.in b/unix/Makefile.in index 9a7d6db..b89b2e6 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -336,7 +336,6 @@ TOMMATH_OBJS = bncore.o bn_reverse.o bn_fast_s_mp_mul_digs.o \ bn_s_mp_mul_digs.o bn_s_mp_sqr.o bn_s_mp_sub.o STUB_LIB_OBJS = tclStubLib.o \ - tclStubLibCompat.o \ tclTomMathStubLib.o \ tclOOStubLib.o \ ${COMPAT_OBJS} @@ -472,7 +471,6 @@ OO_SRCS = \ STUB_SRCS = \ $(GENERIC_DIR)/tclStubLib.c \ - $(GENERIC_DIR)/tclStubLibCompat.c \ $(GENERIC_DIR)/tclTomMathStubLib.c \ $(GENERIC_DIR)/tclOOStubLib.c @@ -1661,9 +1659,6 @@ Zzutil.o: $(ZLIB_DIR)/zutil.c tclStubLib.o: $(GENERIC_DIR)/tclStubLib.c $(CC) -c $(STUB_CC_SWITCHES) $(GENERIC_DIR)/tclStubLib.c -tclStubLibCompat.o: $(GENERIC_DIR)/tclStubLibCompat.c - $(CC) -c $(STUB_CC_SWITCHES) $(GENERIC_DIR)/tclStubLibCompat.c - tclTomMathStubLib.o: $(GENERIC_DIR)/tclTomMathStubLib.c $(CC) -c $(STUB_CC_SWITCHES) $(GENERIC_DIR)/tclTomMathStubLib.c diff --git a/win/Makefile.in b/win/Makefile.in index 6b9685d..dacbbb5 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -378,7 +378,6 @@ REG_OBJS = tclWinReg.$(OBJEXT) STUB_OBJS = \ tclStubLib.$(OBJEXT) \ - tclStubLibCompat.$(OBJEXT) \ tclTomMathStubLib.$(OBJEXT) \ tclOOStubLib.$(OBJEXT) @@ -506,9 +505,6 @@ tclPkgConfig.${OBJEXT}: tclPkgConfig.c # The following objects are part of the stub library and should not be built # as DLL objects but none of the symbols should be exported -tclStubLibCompat.${OBJEXT}: tclStubLibCompat.c - $(CC) -c $(CC_SWITCHES) -DSTATIC_BUILD @DEPARG@ $(CC_OBJNAME) - tclStubLib.${OBJEXT}: tclStubLib.c $(CC) -c $(CC_SWITCHES) -DSTATIC_BUILD @DEPARG@ $(CC_OBJNAME) diff --git a/win/makefile.vc b/win/makefile.vc index 823142f..2784140 100644 --- a/win/makefile.vc +++ b/win/makefile.vc @@ -448,7 +448,6 @@ TCLOBJS = $(COREOBJS) $(ZLIBOBJS) $(TOMMATHOBJS) $(PLATFORMOBJS) TCLSTUBOBJS = \ $(TMP_DIR)\tclStubLib.obj \ - $(TMP_DIR)\tclStubLibCompat.obj \ $(TMP_DIR)\tclTomMathStubLib.obj \ $(TMP_DIR)\tclOOStubLib.obj -- cgit v0.12 From 7f282b3594655176c8010e0a744c3deb798b76e2 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 29 Nov 2012 21:34:22 +0000 Subject: No string result -> no more need for TCL_RESULT_SIZE --- generic/tcl.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/generic/tcl.h b/generic/tcl.h index c7b9e6a..48b5d53 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -600,8 +600,6 @@ typedef struct stat *Tcl_OldStat_; #define TCL_BREAK 3 #define TCL_CONTINUE 4 -#define TCL_RESULT_SIZE 200 - /* *---------------------------------------------------------------------------- * Flags to control what substitutions are performed by Tcl_SubstObj(): -- cgit v0.12 From c85fd541529c09d23c1091969ad8f96012bb68ec Mon Sep 17 00:00:00 2001 From: dkf Date: Fri, 30 Nov 2012 09:16:16 +0000 Subject: Inform the HTML builder about the TDBC drivers. --- pkgs/package.list.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/package.list.txt b/pkgs/package.list.txt index 5020506..f12111d 100644 --- a/pkgs/package.list.txt +++ b/pkgs/package.list.txt @@ -19,3 +19,8 @@ thread Thread tdbc TDBC Tdbc TDBC TDBC TDBC +# Drivers for TDBC +tdbcmysql tdbc::mysql +tdbcodbc tdbc::odbc +tdbcpostgres tdbc::postgres +tdbcsqlite3- tdbc::sqlite3 -- cgit v0.12 From 7e7cc4ff29c7c60467e3c3c61c861c2df30c5e78 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 30 Nov 2012 15:55:03 +0000 Subject: After a Tcl_SetObjResult, don't do a Tcl_TransferResult to the same interpreter --- generic/tclLoad.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generic/tclLoad.c b/generic/tclLoad.c index 6f5b9cf..61c763f 100644 --- a/generic/tclLoad.c +++ b/generic/tclLoad.c @@ -474,8 +474,9 @@ Tcl_LoadObjCmd( /* We have an Tcl 8.x extension with incompatible stub table. */ Tcl_Obj *obj = Tcl_NewStringObj(iPtr->result, -1); Tcl_SetObjResult(interp, obj); + } else { + Tcl_TransferResult(target, code, interp); } - Tcl_TransferResult(target, code, interp); goto done; } -- cgit v0.12 From fa3bc4b41a79a1a27827362ae3a174b5bb85b3f2 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 30 Nov 2012 16:10:20 +0000 Subject: Stop [glob] complaining about empty list result. Continue support for a no-op -nocomplain option, but don't document it. Old script support only. --- doc/glob.n | 5 ----- generic/tclFileName.c | 51 ++++++++++++++------------------------------------- generic/tclInt.h | 13 ------------- library/package.tcl | 3 +++ tests/fCmd.test | 8 ++++---- tests/fileName.test | 14 +++++++------- 6 files changed, 28 insertions(+), 66 deletions(-) diff --git a/doc/glob.n b/doc/glob.n index 7b71189..11cd952 100644 --- a/doc/glob.n +++ b/doc/glob.n @@ -44,11 +44,6 @@ The remaining pattern arguments, after option processing, are treated as a single pattern obtained by joining the arguments with directory separators. .TP -\fB\-nocomplain\fR -. -Allows an empty list to be returned without error; without this -switch an error is returned if the result list would be empty. -.TP \fB\-path\fR \fIpathPrefix\fR . Search for files with the given \fIpathPrefix\fR where the rest of the name diff --git a/generic/tclFileName.c b/generic/tclFileName.c index 5d4702b..a519f0e 100644 --- a/generic/tclFileName.c +++ b/generic/tclFileName.c @@ -37,6 +37,15 @@ static Tcl_Obj * SplitUnixPath(const char *path); static int DoGlob(Tcl_Interp *interp, Tcl_Obj *resultPtr, const char *separators, Tcl_Obj *pathPtr, int flags, char *pattern, Tcl_GlobTypeData *types); +static int TclGlob(Tcl_Interp *interp, char *pattern, + Tcl_Obj *pathPrefix, int globFlags, + Tcl_GlobTypeData *types); + +/* Flag values used by TclGlob() */ + +#define TCL_GLOBMODE_JOIN 2 +#define TCL_GLOBMODE_DIR 4 +#define TCL_GLOBMODE_TAILS 8 /* * When there is no support for getting the block size of a file in a stat() @@ -1270,7 +1279,10 @@ Tcl_GlobObjCmd( switch (index) { case GLOB_NOCOMPLAIN: /* -nocomplain */ - globFlags |= TCL_GLOBMODE_NO_COMPLAIN; + /* + * Do nothing; This is normal operations in Tcl 9. + * Keep accepting as a no-op option to accommodate old scripts. + */ break; case GLOB_DIR: /* -dir */ if (i == (objc-1)) { @@ -1620,41 +1632,6 @@ Tcl_GlobObjCmd( } } - if ((globFlags & TCL_GLOBMODE_NO_COMPLAIN) == 0) { - if (Tcl_ListObjLength(interp, Tcl_GetObjResult(interp), - &length) != TCL_OK) { - /* - * This should never happen. Maybe we should be more dramatic. - */ - - result = TCL_ERROR; - goto endOfGlob; - } - - if (length == 0) { - Tcl_Obj *errorMsg = - Tcl_ObjPrintf("no files matched glob pattern%s \"", - (join || (objc == 1)) ? "" : "s"); - - if (join) { - Tcl_AppendToObj(errorMsg, Tcl_DStringValue(&prefix), -1); - } else { - const char *sep = ""; - - for (i = 0; i < objc; i++) { - Tcl_AppendPrintfToObj(errorMsg, "%s%s", - sep, Tcl_GetString(objv[i])); - sep = " "; - } - } - Tcl_AppendToObj(errorMsg, "\"", -1); - Tcl_SetObjResult(interp, errorMsg); - Tcl_SetErrorCode(interp, "TCL", "OPERATION", "GLOB", "NOMATCH", - NULL); - result = TCL_ERROR; - } - } - endOfGlob: if (join || (dir == PATH_GENERAL)) { Tcl_DStringFree(&prefix); @@ -1705,7 +1682,7 @@ Tcl_GlobObjCmd( */ /* ARGSUSED */ -int +static int TclGlob( Tcl_Interp *interp, /* Interpreter for returning error message or * appending list of matching file names. */ diff --git a/generic/tclInt.h b/generic/tclInt.h index d548a16..8110248 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -2592,16 +2592,6 @@ typedef struct TclFileAttrProcs { typedef struct TclFile_ *TclFile; -/* - * The "globParameters" argument of the function TclGlob is an or'ed - * combination of the following values: - */ - -#define TCL_GLOBMODE_NO_COMPLAIN 1 -#define TCL_GLOBMODE_JOIN 2 -#define TCL_GLOBMODE_DIR 4 -#define TCL_GLOBMODE_TAILS 8 - typedef enum Tcl_PathPart { TCL_PATH_DIRNAME, TCL_PATH_TAIL, @@ -2982,9 +2972,6 @@ MODULE_SCOPE int TclGetOpenModeEx(Tcl_Interp *interp, int *binaryPtr); MODULE_SCOPE Tcl_Obj * TclGetProcessGlobalValue(ProcessGlobalValue *pgvPtr); MODULE_SCOPE const char *TclGetSrcInfoForCmd(Interp *iPtr, int *lenPtr); -MODULE_SCOPE int TclGlob(Tcl_Interp *interp, char *pattern, - Tcl_Obj *unquotedPrefix, int globFlags, - Tcl_GlobTypeData *types); MODULE_SCOPE int TclIncrObj(Tcl_Interp *interp, Tcl_Obj *valuePtr, Tcl_Obj *incrPtr); MODULE_SCOPE Tcl_Obj * TclIncrObjVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr, diff --git a/library/package.tcl b/library/package.tcl index c30431c..5b99a69 100644 --- a/library/package.tcl +++ b/library/package.tcl @@ -137,6 +137,9 @@ proc pkg_mkIndex {args} { } on error {msg opt} { return -options $opt $msg } + if {[llength $fileList] == 0} { + return -code error "no files matched glob pattern \"$patternList\"" + } foreach file $fileList { # For each file, figure out what commands and packages it provides. # To do this, create a child interpreter, load the file into the diff --git a/tests/fCmd.test b/tests/fCmd.test index 325b374..9fae2c5 100644 --- a/tests/fCmd.test +++ b/tests/fCmd.test @@ -745,12 +745,12 @@ test fCmd-7.4 {FileForceOption: bad option} -constraints {notRoot} -setup { } -result {bad option "-tf1": must be -force or --} test fCmd-7.5 {FileForceOption: multiple times through loop} -setup { cleanup -} -constraints {notRoot} -returnCodes error -body { +} -constraints {notRoot} -body { createfile -- createfile -force file delete -force -force -- -- -force glob -- -- -force -} -result {no files matched glob patterns "-- -force"} +} -result {} test fCmd-8.1 {FileBasename: basename of ~user: argc == 1 && *path == ~} \ -constraints {unix notRoot knownBug} -body { @@ -938,9 +938,9 @@ test fCmd-9.10 {file rename: comprehensive: file to new name and dir} -setup { testchmod 444 tf2 file rename tf1 [file join td1 tf3] file rename tf2 [file join td1 tf4] - list [catch {glob tf*}] [lsort [glob -directory td1 t*]] \ + list [glob tf*] [lsort [glob -directory td1 t*]] \ [file writable [file join td1 tf3]] [file writable [file join td1 tf4]] -} -result [subst {1 {[file join td1 tf3] [file join td1 tf4]} 1 0}] +} -result [subst {{} {[file join td1 tf3] [file join td1 tf4]} 1 0}] test fCmd-9.11 {file rename: comprehensive: dir to new name and dir} -setup { cleanup } -constraints {notRoot testchmod} -body { diff --git a/tests/fileName.test b/tests/fileName.test index 51f00d1..2dac0df 100644 --- a/tests/fileName.test +++ b/tests/fileName.test @@ -696,9 +696,9 @@ test filename-10.24 {Tcl_TranslateFileName} -body { testtranslatefilename ~ouster/foo } -result {/home/ouster/foo} -constraints {nonPortable testtranslatefilename} -test filename-11.1 {Tcl_GlobCmd} -returnCodes error -body { +test filename-11.1 {Tcl_GlobCmd} -body { glob -} -result {no files matched glob patterns ""} +} -result {} test filename-11.2 {Tcl_GlobCmd} -returnCodes error -body { glob -gorp } -result {bad option "-gorp": must be -directory, -join, -nocomplain, -path, -tails, -types, or --} @@ -714,9 +714,9 @@ test filename-11.5 {Tcl_GlobCmd} -returnCodes error -body { test filename-11.6 {Tcl_GlobCmd} -returnCodes error -body { glob ~xyqrszzz } -result {user "xyqrszzz" doesn't exist} -test filename-11.7 {Tcl_GlobCmd} -returnCodes error -body { +test filename-11.7 {Tcl_GlobCmd} -body { glob -- -nocomplain -} -result {no files matched glob pattern "-nocomplain"} +} -result {} test filename-11.8 {Tcl_GlobCmd} -body { glob -nocomplain -- -nocomplain } -result {} @@ -1085,7 +1085,7 @@ test filename-12.1 {simple globbing} {unixOrPc} { } {.} test filename-12.1.1 {simple globbing} -constraints {unixOrPc} -body { glob -types f {} -} -returnCodes error -result {no files matched glob pattern ""} +} -result {} test filename-12.1.2 {simple globbing} {unixOrPc} { glob -types d {} } {.} @@ -1247,10 +1247,10 @@ test filename-14.20 {asterisks, question marks, and brackets} { } {} test filename-14.21 {asterisks, question marks, and brackets} -body { glob globTest/*/gorp -} -returnCodes error -result {no files matched glob pattern "globTest/*/gorp"} +} -result {} test filename-14.22 {asterisks, question marks, and brackets} -body { glob goo/* x*z foo?q -} -returnCodes error -result {no files matched glob patterns "goo/* x*z foo?q"} +} -result {} test filename-14.23 {slash globbing} {unix} { glob / } / -- cgit v0.12 From b2a578281bc651e13b8df894e7ad830511439372 Mon Sep 17 00:00:00 2001 From: dgp Date: Fri, 30 Nov 2012 16:14:11 +0000 Subject: Re-fix failing load-3.2 test. The right way this time. --- generic/tclLoad.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/generic/tclLoad.c b/generic/tclLoad.c index 61c763f..5c47a6b 100644 --- a/generic/tclLoad.c +++ b/generic/tclLoad.c @@ -473,10 +473,9 @@ Tcl_LoadObjCmd( if (iPtr->result != NULL && iPtr->result[0] != '\0') { /* We have an Tcl 8.x extension with incompatible stub table. */ Tcl_Obj *obj = Tcl_NewStringObj(iPtr->result, -1); - Tcl_SetObjResult(interp, obj); - } else { - Tcl_TransferResult(target, code, interp); + Tcl_SetObjResult(target, obj); } + Tcl_TransferResult(target, code, interp); goto done; } -- cgit v0.12 From 7e9565a93e51d737ba2891a4a21dee15ab5f60ce Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 3 Dec 2012 10:01:20 +0000 Subject: Initialize legacyFreeProc with invalid value: This will result in a crash immediately, when an extention tries to call it, in stead of crashing some time later.... Remove some more legacy regarding accessing interp->result --- doc/Interp.3 | 13 ------------- doc/SetResult.3 | 14 ++++---------- generic/tclBasic.c | 10 ++++------ generic/tclInt.h | 4 ++-- generic/tclLoad.c | 3 ++- generic/tclResult.c | 17 ----------------- generic/tclStubLib.c | 4 ++-- 7 files changed, 14 insertions(+), 51 deletions(-) diff --git a/doc/Interp.3 b/doc/Interp.3 index d908057..d5006f9 100644 --- a/doc/Interp.3 +++ b/doc/Interp.3 @@ -33,19 +33,6 @@ the pointer as described below is no longer supported. The supported public routines \fBTcl_SetResult\fR, \fBTcl_GetResult\fR, \fBTcl_SetErrorLine\fR, \fBTcl_GetErrorLine\fR must be used instead. .PP -For legacy programs and extensions no longer being maintained, compiles -against the Tcl 8.6 header files are only possible with the compiler -directives -.CS -#define USE_INTERP_RESULT -.CE -and/or -.CS -#define USE_INTERP_ERRORLINE -.CE -depending on which fields of the \fBTcl_Interp\fR struct are accessed. -These directives may be embedded in code or supplied via compiler options. -.PP The \fIresult\fR and \fIfreeProc\fR fields are used to return results or error messages from commands. This information is returned by command procedures back to \fBTcl_Eval\fR, diff --git a/doc/SetResult.3 b/doc/SetResult.3 index bbeedf1..c863c5a 100644 --- a/doc/SetResult.3 +++ b/doc/SetResult.3 @@ -199,17 +199,11 @@ change \fIinterp->result\fR or clear error state. is about to replace one result value with another. .SS "DIRECT ACCESS TO INTERP->RESULT" .PP -It used to be legal for programs to -directly read and write \fIinterp->result\fR -to manipulate the interpreter result. The Tcl headers no longer -permit this access by default, and C code still doing this must -be updated to use supported routines \fBTcl_GetObjResult\fR, +It used to be legal for programs to directly read and write +\fIinterp->result\fR to manipulate the interpreter result. +The Tcl headers no longer permit this access, and C code still +doing this must be updated to use supported routines \fBTcl_GetObjResult\fR, \fBTcl_GetStringResult\fR, \fBTcl_SetObjResult\fR, and \fBTcl_SetResult\fR. -As a migration aid, access can be restored with the compiler directive -.CS -#define USE_INTERP_RESULT -.CE -but this is meant only to offer life support to otherwise dead code. .SH "THE TCL_FREEPROC ARGUMENT TO TCL_SETRESULT" .PP \fBTcl_SetResult\fR's \fIfreeProc\fR argument specifies how diff --git a/generic/tclBasic.c b/generic/tclBasic.c index 24a1082..7202184 100644 --- a/generic/tclBasic.c +++ b/generic/tclBasic.c @@ -486,7 +486,11 @@ Tcl_CreateInterp(void) interp = (Tcl_Interp *) iPtr; iPtr->legacyResult = NULL; + /* Special invalid value: Any attempt to free the legacy result + * will cause a crash. */ + iPtr->legacyFreeProc = (void (*) (void))-1; iPtr->errorLine = 0; + iPtr->stubTable = &tclStubs; iPtr->objResultPtr = Tcl_NewObj(); Tcl_IncrRefCount(iPtr->objResultPtr); iPtr->handle = TclHandleCreate(iPtr); @@ -681,12 +685,6 @@ Tcl_CreateInterp(void) #endif /* TCL_COMPILE_STATS */ /* - * Initialise the stub table pointer. - */ - - iPtr->stubTable = &tclStubs; - - /* * Initialize the ensemble error message rewriting support. */ diff --git a/generic/tclInt.h b/generic/tclInt.h index 5192688..0efb1b6 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -1811,8 +1811,8 @@ typedef struct Interp { * that one undisturbed. */ - char *legacyResult; - Tcl_FreeProc *legacyFreeProc; + const char *legacyResult; + void (*legacyFreeProc) (void); int errorLine; /* When TCL_ERROR is returned, this gives the * line number in the command where the error * occurred (1 means first line). */ diff --git a/generic/tclLoad.c b/generic/tclLoad.c index 80efdd8..75e513d 100644 --- a/generic/tclLoad.c +++ b/generic/tclLoad.c @@ -470,7 +470,7 @@ Tcl_LoadObjCmd( if (code != TCL_OK) { Interp *iPtr = (Interp *) target; - if (iPtr->legacyResult != NULL) { + if (iPtr->legacyResult && !iPtr->legacyFreeProc) { /* * A call to Tcl_InitStubs() determined the caller extension and * this interp are incompatible in their stubs mechanisms, and @@ -478,6 +478,7 @@ Tcl_LoadObjCmd( */ Tcl_SetObjResult(target, Tcl_NewStringObj(iPtr->legacyResult, -1)); iPtr->legacyResult = NULL; + iPtr->legacyFreeProc = (void (*) (void))-1; } Tcl_TransferResult(target, code, interp); goto done; diff --git a/generic/tclResult.c b/generic/tclResult.c index b8f9c92..618b7d8 100644 --- a/generic/tclResult.c +++ b/generic/tclResult.c @@ -474,23 +474,6 @@ Tcl_AppendResultVA( } Tcl_AppendStringsToObjVA(objPtr, argList); Tcl_SetObjResult(interp, objPtr); - - /* - * Strictly we should call Tcl_GetStringResult(interp) here to make sure - * that interp->result is correct according to the old contract, but that - * makes the performance of much code (e.g. in Tk) absolutely awful. So we - * leave it out; code that really wants interp->result can just insert the - * calls to Tcl_GetStringResult() itself. [Patch 1041072 discussion] - */ - -#ifdef USE_INTERP_RESULT - /* - * Ensure that the interp->result is legal so old Tcl 7.* code still - * works. There's still embarrasingly much of it about... - */ - - (void) Tcl_GetStringResult(interp); -#endif /* USE_INTERP_RESULT */ } /* diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c index 501072c..9a2e063 100644 --- a/generic/tclStubLib.c +++ b/generic/tclStubLib.c @@ -47,8 +47,8 @@ HasStubSupport( return iPtr->stubTable; } iPtr->legacyResult - = (char *) "interpreter uses an incompatible stubs mechanism"; - iPtr->legacyFreeProc = TCL_STATIC; + = "interpreter uses an incompatible stubs mechanism"; + iPtr->legacyFreeProc = 0; /* TCL_STATIC */ return NULL; } -- cgit v0.12 From 2eab5be3ef9be6cc7ec30abf3ea5bf587577e001 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 3 Dec 2012 13:02:08 +0000 Subject: Remove obsolete functions Tcl_GetDefaultEncodingDir and Tcl_SetDefaultEncodingDir --- doc/Encoding.3 | 19 ++-------------- generic/tcl.decls | 16 +++++++------ generic/tclDecls.h | 16 +++++-------- generic/tclEncoding.c | 62 --------------------------------------------------- generic/tclStubInit.c | 4 ++-- unix/tclUnixTest.c | 48 ++++++++++++++++++++++++++------------- 6 files changed, 51 insertions(+), 114 deletions(-) diff --git a/doc/Encoding.3 b/doc/Encoding.3 index 7bcb285..8432d61 100644 --- a/doc/Encoding.3 +++ b/doc/Encoding.3 @@ -8,7 +8,7 @@ .TH Tcl_GetEncoding 3 "8.1" Tcl "Tcl Library Procedures" .BS .SH NAME -Tcl_GetEncoding, Tcl_FreeEncoding, Tcl_GetEncodingFromObj, Tcl_ExternalToUtfDString, Tcl_ExternalToUtf, Tcl_UtfToExternalDString, Tcl_UtfToExternal, Tcl_WinTCharToUtf, Tcl_WinUtfToTChar, Tcl_GetEncodingName, Tcl_SetSystemEncoding, Tcl_GetEncodingNameFromEnvironment, Tcl_GetEncodingNames, Tcl_CreateEncoding, Tcl_GetEncodingSearchPath, Tcl_SetEncodingSearchPath, Tcl_GetDefaultEncodingDir, Tcl_SetDefaultEncodingDir \- procedures for creating and using encodings +Tcl_GetEncoding, Tcl_FreeEncoding, Tcl_GetEncodingFromObj, Tcl_ExternalToUtfDString, Tcl_ExternalToUtf, Tcl_UtfToExternalDString, Tcl_UtfToExternal, Tcl_WinTCharToUtf, Tcl_WinUtfToTChar, Tcl_GetEncodingName, Tcl_SetSystemEncoding, Tcl_GetEncodingNameFromEnvironment, Tcl_GetEncodingNames, Tcl_CreateEncoding, Tcl_GetEncodingSearchPath, Tcl_SetEncodingSearchPath \- procedures for creating and using encodings .SH SYNOPSIS .nf \fB#include \fR @@ -62,12 +62,6 @@ Tcl_Obj * .sp int \fBTcl_SetEncodingSearchPath\fR(\fIsearchPath\fR) -.sp -const char * -\fBTcl_GetDefaultEncodingDir\fR(\fIvoid\fR) -.sp -void -\fBTcl_SetDefaultEncodingDir\fR(\fIpath\fR) .SH ARGUMENTS .AS "const Tcl_EncodingType" *dstWrotePtr in/out .AP Tcl_Interp *interp in @@ -325,7 +319,7 @@ the encoding name to it. The \fBTcl_DStringValue\fR is returned. \fBTcl_GetEncodingNames\fR sets the \fIinterp\fR result to a list consisting of the names of all the encodings that are currently defined or can be dynamically loaded, searching the encoding path specified by -\fBTcl_SetDefaultEncodingDir\fR. This procedure does not ensure that the +\fBTcl_SetEncodingSearchPath\fR. This procedure does not ensure that the dynamically-loadable encoding files contain valid data, but merely that they exist. .PP @@ -440,15 +434,6 @@ are not verified as existing readable filesystem directories. When searching for encoding data files takes place, and non-existent or non-readable filesystem directories on the \fIsearchPath\fR are silently ignored. -.PP -\fBTcl_GetDefaultEncodingDir\fR and \fBTcl_SetDefaultEncodingDir\fR -are obsolete interfaces best replaced with calls to -\fBTcl_GetEncodingSearchPath\fR and \fBTcl_SetEncodingSearchPath\fR. -They are called to access and set the first element of the \fIsearchPath\fR -list. Since Tcl searches \fIsearchPath\fR for encoding data files in -list order, these routines establish the -.QW default -directory in which to find encoding data files. .SH "ENCODING FILES" Space would prohibit precompiling into Tcl every possible encoding algorithm, so many encodings are stored on disk as dynamically-loadable diff --git a/generic/tcl.decls b/generic/tcl.decls index ec7864d..ad725f5 100644 --- a/generic/tcl.decls +++ b/generic/tcl.decls @@ -515,7 +515,7 @@ declare 142 { declare 143 { void Tcl_Finalize(void) } -# Removed in 9.0: +# Removed (from stubtable only) in 9.0: #declare 144 { # void Tcl_FindExecutable(const char *argv0) #} @@ -1217,12 +1217,14 @@ declare 339 { declare 340 { char *Tcl_GetString(Tcl_Obj *objPtr) } -declare 341 { - const char *Tcl_GetDefaultEncodingDir(void) -} -declare 342 { - void Tcl_SetDefaultEncodingDir(const char *path) -} +# Removed in 9.0 +#declare 341 { +# const char *Tcl_GetDefaultEncodingDir(void) +#} +# Removed in 9.0 +#declare 342 { +# void Tcl_SetDefaultEncodingDir(const char *path) +#} declare 343 { void Tcl_AlertNotifier(ClientData clientData) } diff --git a/generic/tclDecls.h b/generic/tclDecls.h index 1b7cf99..d38296d 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -964,10 +964,8 @@ TCLAPI int Tcl_WriteChars(Tcl_Channel chan, const char *src, TCLAPI int Tcl_WriteObj(Tcl_Channel chan, Tcl_Obj *objPtr); /* 340 */ TCLAPI char * Tcl_GetString(Tcl_Obj *objPtr); -/* 341 */ -TCLAPI const char * Tcl_GetDefaultEncodingDir(void); -/* 342 */ -TCLAPI void Tcl_SetDefaultEncodingDir(const char *path); +/* Slot 341 is reserved */ +/* Slot 342 is reserved */ /* 343 */ TCLAPI void Tcl_AlertNotifier(ClientData clientData); /* 344 */ @@ -2146,8 +2144,8 @@ typedef struct TclStubs { int (*tcl_WriteChars) (Tcl_Channel chan, const char *src, int srcLen); /* 338 */ int (*tcl_WriteObj) (Tcl_Channel chan, Tcl_Obj *objPtr); /* 339 */ char * (*tcl_GetString) (Tcl_Obj *objPtr); /* 340 */ - const char * (*tcl_GetDefaultEncodingDir) (void); /* 341 */ - void (*tcl_SetDefaultEncodingDir) (const char *path); /* 342 */ + void (*reserved341)(void); + void (*reserved342)(void); void (*tcl_AlertNotifier) (ClientData clientData); /* 343 */ void (*tcl_ServiceModeHook) (int mode); /* 344 */ int (*tcl_UniCharIsAlnum) (int ch); /* 345 */ @@ -3142,10 +3140,8 @@ extern const TclStubs *tclStubsPtr; (tclStubsPtr->tcl_WriteObj) /* 339 */ #define Tcl_GetString \ (tclStubsPtr->tcl_GetString) /* 340 */ -#define Tcl_GetDefaultEncodingDir \ - (tclStubsPtr->tcl_GetDefaultEncodingDir) /* 341 */ -#define Tcl_SetDefaultEncodingDir \ - (tclStubsPtr->tcl_SetDefaultEncodingDir) /* 342 */ +/* Slot 341 is reserved */ +/* Slot 342 is reserved */ #define Tcl_AlertNotifier \ (tclStubsPtr->tcl_AlertNotifier) /* 343 */ #define Tcl_ServiceModeHook \ diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 7a55724..d2c7bc8 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -672,68 +672,6 @@ TclFinalizeEncodingSubsystem(void) /* *------------------------------------------------------------------------- * - * Tcl_GetDefaultEncodingDir -- - * - * Legacy public interface to retrieve first directory in the encoding - * searchPath. - * - * Results: - * The directory pathname, as a string, or NULL for an empty encoding - * search path. - * - * Side effects: - * None. - * - *------------------------------------------------------------------------- - */ - -const char * -Tcl_GetDefaultEncodingDir(void) -{ - int numDirs; - Tcl_Obj *first, *searchPath = Tcl_GetEncodingSearchPath(); - - Tcl_ListObjLength(NULL, searchPath, &numDirs); - if (numDirs == 0) { - return NULL; - } - Tcl_ListObjIndex(NULL, searchPath, 0, &first); - - return Tcl_GetString(first); -} - -/* - *------------------------------------------------------------------------- - * - * Tcl_SetDefaultEncodingDir -- - * - * Legacy public interface to set the first directory in the encoding - * search path. - * - * Results: - * None. - * - * Side effects: - * Modifies the encoding search path. - * - *------------------------------------------------------------------------- - */ - -void -Tcl_SetDefaultEncodingDir( - const char *path) -{ - Tcl_Obj *searchPath = Tcl_GetEncodingSearchPath(); - Tcl_Obj *directory = Tcl_NewStringObj(path, -1); - - searchPath = Tcl_DuplicateObj(searchPath); - Tcl_ListObjReplace(NULL, searchPath, 0, 0, 1, &directory); - Tcl_SetEncodingSearchPath(searchPath); -} - -/* - *------------------------------------------------------------------------- - * * Tcl_GetEncoding -- * * Given the name of a encoding, find the corresponding Tcl_Encoding diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 7106d3d..6718ef8 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -983,8 +983,8 @@ const TclStubs tclStubs = { Tcl_WriteChars, /* 338 */ Tcl_WriteObj, /* 339 */ Tcl_GetString, /* 340 */ - Tcl_GetDefaultEncodingDir, /* 341 */ - Tcl_SetDefaultEncodingDir, /* 342 */ + 0, /* 341 */ + 0, /* 342 */ Tcl_AlertNotifier, /* 343 */ Tcl_ServiceModeHook, /* 344 */ Tcl_UniCharIsAlnum, /* 345 */ diff --git a/unix/tclUnixTest.c b/unix/tclUnixTest.c index 46fc972..c0c05f0 100644 --- a/unix/tclUnixTest.c +++ b/unix/tclUnixTest.c @@ -67,10 +67,10 @@ static Tcl_CmdProc TestchmodCmd; static Tcl_CmdProc TestfilehandlerCmd; static Tcl_CmdProc TestfilewaitCmd; static Tcl_CmdProc TestfindexecutableCmd; -static Tcl_CmdProc TestgetdefencdirCmd; +static Tcl_ObjCmdProc TestgetdefencdirCmd; static Tcl_CmdProc TestgetopenfileCmd; static Tcl_CmdProc TestgotsigCmd; -static Tcl_CmdProc TestsetdefencdirCmd; +static Tcl_ObjCmdProc TestsetdefencdirCmd; static Tcl_FileProc TestFileHandlerProc; static void AlarmHandler(int signum); @@ -105,9 +105,9 @@ TclplatformtestInit( NULL, NULL); Tcl_CreateCommand(interp, "testgetopenfile", TestgetopenfileCmd, NULL, NULL); - Tcl_CreateCommand(interp, "testgetdefenc", TestgetdefencdirCmd, + Tcl_CreateObjCommand(interp, "testgetdefenc", TestgetdefencdirCmd, NULL, NULL); - Tcl_CreateCommand(interp, "testsetdefenc", TestsetdefencdirCmd, + Tcl_CreateObjCommand(interp, "testsetdefenc", TestsetdefencdirCmd, NULL, NULL); Tcl_CreateCommand(interp, "testalarm", TestalarmCmd, NULL, NULL); @@ -514,16 +514,22 @@ static int TestsetdefencdirCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ - int argc, /* Number of arguments. */ - const char **argv) /* Argument strings. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const *objv) /* Argument strings. */ { - if (argc != 2) { - Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], - " defaultDir\"", NULL); + Tcl_Obj *searchPath; + + if (objc != 2) { + Tcl_WrongNumArgs(interp, 1, objv, "defaultDir"); return TCL_ERROR; } - Tcl_SetDefaultEncodingDir(argv[1]); + searchPath = Tcl_GetEncodingSearchPath(); + + searchPath = Tcl_DuplicateObj(searchPath); + Tcl_ListObjReplace(NULL, searchPath, 0, 0, 1, &objv[1]); + Tcl_SetEncodingSearchPath(searchPath); + return TCL_OK; } @@ -548,15 +554,25 @@ static int TestgetdefencdirCmd( ClientData clientData, /* Not used. */ Tcl_Interp *interp, /* Current interpreter. */ - int argc, /* Number of arguments. */ - const char **argv) /* Argument strings. */ + int objc, /* Number of arguments. */ + Tcl_Obj *const *objv) /* Argument strings. */ { - if (argc != 1) { - Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], NULL); - return TCL_ERROR; + int numDirs; + Tcl_Obj *first, *searchPath; + + if (objc != 1) { + Tcl_WrongNumArgs(interp, 1, objv, NULL); + return TCL_ERROR; + } + + searchPath = Tcl_GetEncodingSearchPath(); + Tcl_ListObjLength(interp, searchPath, &numDirs); + if (numDirs == 0) { + return TCL_ERROR; } + Tcl_ListObjIndex(NULL, searchPath, 0, &first); - Tcl_AppendResult(interp, Tcl_GetDefaultEncodingDir(), NULL); + Tcl_SetObjResult(interp, first); return TCL_OK; } -- cgit v0.12 From 8ef61c13e0df3175cac5b314840f726f7407b6f8 Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 3 Dec 2012 14:33:17 +0000 Subject: Post-header reform (long long ago now) Tcl headers take care of their own protection from EXTERN definitions. --- unix/tclLoadShl.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/unix/tclLoadShl.c b/unix/tclLoadShl.c index c9e4e27..8aaefda 100644 --- a/unix/tclLoadShl.c +++ b/unix/tclLoadShl.c @@ -12,15 +12,6 @@ */ #include - -/* - * On some HP machines, dl.h defines EXTERN; remove that definition. - */ - -#ifdef EXTERN -# undef EXTERN -#endif - #include "tclInt.h" /* -- cgit v0.12 From b222d2f2b2dbf7666e44385dc825b59b5045b3f2 Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 3 Dec 2012 19:14:32 +0000 Subject: Disable the legacy configuration setting from $::argv only when a setting call to [configure] is made. Queries should not disturb that support. Bump to tcltest 2.2.11. --- library/tcltest/pkgIndex.tcl | 2 +- library/tcltest/tcltest.tcl | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/library/tcltest/pkgIndex.tcl b/library/tcltest/pkgIndex.tcl index e569fa5..eb5859e 100644 --- a/library/tcltest/pkgIndex.tcl +++ b/library/tcltest/pkgIndex.tcl @@ -9,4 +9,4 @@ # full path name of this file's directory. if {![package vsatisfies [package provide Tcl] 8.3]} {return} -package ifneeded tcltest 2.2.10 [list source [file join $dir tcltest.tcl]] +package ifneeded tcltest 2.2.11 [list source [file join $dir tcltest.tcl]] diff --git a/library/tcltest/tcltest.tcl b/library/tcltest/tcltest.tcl index 4ae1480c..5d89748 100644 --- a/library/tcltest/tcltest.tcl +++ b/library/tcltest/tcltest.tcl @@ -22,7 +22,7 @@ namespace eval tcltest { # When the version number changes, be sure to update the pkgIndex.tcl file, # and the install directory in the Makefiles. When the minor version # changes (new feature) be sure to update the man page as well. - variable Version 2.2.10 + variable Version 2.2.11 # Compatibility support for dumb variables defined in tcltest 1 # Do not use these. Call [package provide Tcl] and [info patchlevel] @@ -601,7 +601,9 @@ namespace eval tcltest { } } proc configure args { - RemoveAutoConfigureTraces + if {[llength $args] > 1} { + RemoveAutoConfigureTraces + } set code [catch {eval Configure $args} msg] return -code $code $msg } -- cgit v0.12 From ae09e66da466ea68e269fc388798ca6ce2cd1c4c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 4 Dec 2012 13:39:07 +0000 Subject: MODULE_SCOPE symbol names are suppoted to start with 'tcl' (data) or 'Tcl' (code) --- generic/tclParse.c | 2 +- generic/tclParse.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generic/tclParse.c b/generic/tclParse.c index 309e232..08615a7 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -42,7 +42,7 @@ * TYPE_BRACE - Character is a curly brace (either left or right). */ -const char charTypeTable[] = { +const char tclCharTypeTable[] = { /* * Negative character values, from -128 to -1: */ diff --git a/generic/tclParse.h b/generic/tclParse.h index be1ab15..20c609c 100644 --- a/generic/tclParse.h +++ b/generic/tclParse.h @@ -12,6 +12,6 @@ #define TYPE_CLOSE_BRACK 0x20 #define TYPE_BRACE 0x40 -#define CHAR_TYPE(c) (charTypeTable+128)[(int)(c)] +#define CHAR_TYPE(c) (tclCharTypeTable+128)[(int)(c)] -MODULE_SCOPE const char charTypeTable[]; +MODULE_SCOPE const char tclCharTypeTable[]; -- cgit v0.12