Compare commits

...
Author SHA1 Message Date
jan.nijtmans 8847027dc3 use longValue as internal repr in stead of wideValue.
name new type "lindex" in stead of already existing "index"
2013-02-12 21:40:34 +00:00
jan.nijtmans 032840f45e Still to be TIP'ed.
In this branch objTypes are not registered to Tcl any more, and still can do everything. It proves that Tcl_ConvertToType and the toAnyProc in thc Tcl_ObjType struct can be safely removed. Conversion to any specific type must be done by the "Tcl_GetXXXFromObj" type functions. 
One objType which didn't have such a function yet: "end-offset". This branch replaces this type by an "index" objType with its own Tcl_GetIntForIndex function (which functions the same as the currently private TclGetIntForIndex, only faster...). 
In addition, it affects Tcl_GetBoolean, which now follows the same same parsing rules as Tcl_GetBooleanFromObj.
2013-02-11 15:53:09 +00:00
35 changed files with 283 additions and 741 deletions
-12
View File
@@ -75,18 +75,6 @@ left in the interpreter's result unless \fIinterp\fR is NULL.
fields of \fI*objPtr\fR so that future calls to
\fBTcl_GetBooleanFromObj\fR on the same \fIobjPtr\fR can be
performed more efficiently.
.PP
Note that the routines \fBTcl_GetBooleanFromObj\fR and
\fBTcl_GetBoolean\fR are not functional equivalents.
The set of values for which \fBTcl_GetBooleanFromObj\fR
will return \fBTCL_OK\fR is strictly larger than
the set of values for which \fBTcl_GetBoolean\fR will do the same.
For example, the value
.QW 5
passed to \fBTcl_GetBooleanFromObj\fR
will lead to a \fBTCL_OK\fR return (and the boolean value 1),
while the same value passed to \fBTcl_GetBoolean\fR will lead to
a \fBTCL_ERROR\fR return.
.SH "SEE ALSO"
Tcl_NewObj, Tcl_IsShared, Tcl_GetBoolean
+22 -17
View File
@@ -8,7 +8,7 @@
.TH Tcl_IntObj 3 8.5 Tcl "Tcl Library Procedures"
.BS
.SH NAME
Tcl_NewIntObj, Tcl_NewLongObj, Tcl_NewWideIntObj, Tcl_SetIntObj, Tcl_SetLongObj, Tcl_SetWideIntObj, Tcl_GetIntFromObj, Tcl_GetLongFromObj, Tcl_GetWideIntFromObj, Tcl_NewBignumObj, Tcl_SetBignumObj, Tcl_GetBignumFromObj, Tcl_TakeBignumFromObj \- manipulate Tcl values as integers
Tcl_NewIntObj, Tcl_NewLongObj, Tcl_NewWideIntObj, Tcl_SetIntObj, Tcl_SetLongObj, Tcl_SetWideIntObj, Tcl_GetIntFromObj, Tcl_GetIntForIndex, Tcl_GetLongFromObj, Tcl_GetWideIntFromObj, Tcl_NewBignumObj, Tcl_SetBignumObj, Tcl_GetBignumFromObj, Tcl_TakeBignumFromObj \- manipulate Tcl values as integers
.SH SYNOPSIS
.nf
\fB#include <tcl.h>\fR
@@ -32,6 +32,9 @@ int
\fBTcl_GetIntFromObj\fR(\fIinterp, objPtr, intPtr\fR)
.sp
int
\fBTcl_GetIntForIndex\fR(\fIinterp, objPtr, endValue, intPtr\fR)
.sp
int
\fBTcl_GetLongFromObj\fR(\fIinterp, objPtr, longPtr\fR)
.sp
int
@@ -57,6 +60,8 @@ int
.AS Tcl_WideInt doubleValue in/out
.AP int intValue in
Integer value used to initialize or set a Tcl value.
.AP int endValue in
Integer value returned when the index is \fBend\fR.
.AP long longValue in
Long integer value used to initialize or set a Tcl value.
.AP Tcl_WideInt wideValue in
@@ -65,8 +70,8 @@ Wide integer value used to initialize or set a Tcl value.
For \fBTcl_SetIntObj\fR, \fBTcl_SetLongObj\fR, \fBTcl_SetWideIntObj\fR,
and \fBTcl_SetBignumObj\fR, this points to the value in which to store an
integral value. For \fBTcl_GetIntFromObj\fR, \fBTcl_GetLongFromObj\fR,
\fBTcl_GetWideIntFromObj\fR, \fBTcl_GetBignumFromObj\fR, and
\fBTcl_TakeBignumFromObj\fR, this refers to the value from which
\fBTcl_GetWideIntFromObj\fR, \fBTcl_GetBignumFromObj\fR, \fBTcl_TakeBignumFromObj\fR,
and \fBTcl_GetIntForIndex\fR, this refers to the value from which
to retrieve an integral value.
.AP Tcl_Interp *interp in/out
When non-NULL, an error message is left here when integral value
@@ -116,20 +121,20 @@ or internal representation in the unshared Tcl value will be freed
as a consequence of setting the new value.
.PP
The \fBTcl_GetIntFromObj\fR, \fBTcl_GetLongFromObj\fR,
\fBTcl_GetWideIntFromObj\fR, \fBTcl_GetBignumFromObj\fR, and
\fBTcl_TakeBignumFromObj\fR routines attempt to retrieve an integral
value of the appropriate type from the Tcl value \fIobjPtr\fR. If the
attempt succeeds, then \fBTCL_OK\fR is returned, and the value is
written to the storage provided by the caller. The attempt might
fail if \fIobjPtr\fR does not hold an integral value, or if the
value exceeds the range of the target type. If the attempt fails,
then \fBTCL_ERROR\fR is returned, and if \fIinterp\fR is non-NULL,
an error message is left in \fIinterp\fR. The \fBTcl_ObjType\fR
of \fIobjPtr\fR may be changed to make subsequent calls to the
same routine more efficient. Unlike the other functions,
\fBTcl_TakeBignumFromObj\fR may set the content of the Tcl value
\fIobjPtr\fR to an empty string in the process of retrieving the
multiple-precision integer value.
\fBTcl_GetWideIntFromObj\fR, \fBTcl_GetBignumFromObj\fR,
\fBTcl_TakeBignumFromObj\fR and \fBTcl_GetIntFromObj\fR,
routines attempt to retrieve an integral value of the appropriate
type from the Tcl value \fIobjPtr\fR. If the attempt succeeds, then
\fBTCL_OK\fR is returned, and the value is written to the storage
provided by the caller. The attempt might fail if \fIobjPtr\fR
does not hold an integral value, or if the value exceeds the range
of the target type. If the attempt fails, then \fBTCL_ERROR\fR is
returned, and if \fIinterp\fR is non-NULL, an error message is left
in \fIinterp\fR. The \fBTcl_ObjType\fR of \fIobjPtr\fR may be
changed to make subsequent calls to the same routine more efficient.
Unlike the other functions, \fBTcl_TakeBignumFromObj\fR may set the
content of the Tcl value \fIobjPtr\fR to an empty string in the
process of retrieving the multiple-precision integer value.
.PP
The choice between \fBTcl_GetBignumFromObj\fR and
\fBTcl_TakeBignumFromObj\fR is governed by how the caller will
+19 -10
View File
@@ -79,9 +79,10 @@ declare 12 {
declare 13 {
int Tcl_WaitForEvent(const Tcl_Time *timePtr)
}
declare 14 {
int Tcl_AppendAllObjTypes(Tcl_Interp *interp, Tcl_Obj *objPtr)
}
# Removed in 9.0:
#declare 14 {
# int Tcl_AppendAllObjTypes(Tcl_Interp *interp, Tcl_Obj *objPtr)
#}
declare 15 {
void Tcl_AppendStringsToObj(Tcl_Obj *objPtr, ...)
}
@@ -91,10 +92,11 @@ declare 16 {
declare 17 {
Tcl_Obj *Tcl_ConcatObj(int objc, Tcl_Obj *const objv[])
}
declare 18 {
int Tcl_ConvertToType(Tcl_Interp *interp, Tcl_Obj *objPtr,
const Tcl_ObjType *typePtr)
}
# Remove in 9.0:
#declare 18 {
# int Tcl_ConvertToType(Tcl_Interp *interp, Tcl_Obj *objPtr,
# const Tcl_ObjType *typePtr)
#}
declare 19 {
void Tcl_DbDecrRefCount(Tcl_Obj *objPtr, const char *file, int line)
}
@@ -764,9 +766,10 @@ declare 209 {
declare 210 {
void Tcl_RegisterChannel(Tcl_Interp *interp, Tcl_Channel chan)
}
declare 211 {
void Tcl_RegisterObjType(const Tcl_ObjType *typePtr)
}
# Removed in 9.0:
#declare 211 {
# void Tcl_RegisterObjType(const Tcl_ObjType *typePtr)
#}
declare 212 {
Tcl_RegExp Tcl_RegExpCompile(Tcl_Interp *interp, const char *pattern)
}
@@ -2348,6 +2351,12 @@ declare 630 {
# ----- BASELINE -- FOR -- 8.6.0 ----- #
declare 631 {
int Tcl_GetIntForIndex(Tcl_Interp *interp, Tcl_Obj *objPtr,
int endValue, int *indexPtr)
}
##############################################################################
# Define the platform specific public Tcl interface. These functions are only
+1 -1
View File
@@ -181,7 +181,7 @@ const Tcl_ObjType tclByteArrayType = {
FreeByteArrayInternalRep,
DupByteArrayInternalRep,
UpdateStringOfByteArray,
SetByteArrayFromAny
NULL
};
/*
+10 -10
View File
@@ -2371,7 +2371,7 @@ Tcl_LinsertObjCmd(
* appended to the list.
*/
result = TclGetIntForIndexM(interp, objv[2], /*end*/ len, &index);
result = TclGetIntForIndex(interp, objv[2], /*end*/ len, &index);
if (result != TCL_OK) {
return result;
}
@@ -2527,7 +2527,7 @@ Tcl_LrangeObjCmd(
return result;
}
result = TclGetIntForIndexM(interp, objv[2], /*endValue*/ listLen - 1,
result = TclGetIntForIndex(interp, objv[2], /*endValue*/ listLen - 1,
&first);
if (result != TCL_OK) {
return result;
@@ -2536,7 +2536,7 @@ Tcl_LrangeObjCmd(
first = 0;
}
result = TclGetIntForIndexM(interp, objv[3], /*endValue*/ listLen - 1,
result = TclGetIntForIndex(interp, objv[3], /*endValue*/ listLen - 1,
&last);
if (result != TCL_OK) {
return result;
@@ -2737,12 +2737,12 @@ Tcl_LreplaceObjCmd(
* included for deletion.
*/
result = TclGetIntForIndexM(interp, objv[2], /*end*/ listLen-1, &first);
result = TclGetIntForIndex(interp, objv[2], /*end*/ listLen-1, &first);
if (result != TCL_OK) {
return result;
}
result = TclGetIntForIndexM(interp, objv[3], /*end*/ listLen-1, &last);
result = TclGetIntForIndex(interp, objv[3], /*end*/ listLen-1, &last);
if (result != TCL_OK) {
return result;
}
@@ -2754,7 +2754,7 @@ Tcl_LreplaceObjCmd(
/*
* Complain if the user asked for a start element that is greater than the
* list length. This won't ever trigger for the "end-*" case as that will
* be properly constrained by TclGetIntForIndex because we use listLen-1
* be properly constrained by Tcl_GetIntForIndex because we use listLen-1
* (to allow for replacing the last elem).
*/
@@ -3105,7 +3105,7 @@ Tcl_LsearchObjCmd(
*/
for (j=0 ; j<sortInfo.indexc ; j++) {
if (TclGetIntForIndexM(interp, indices[j], SORTIDX_END,
if (TclGetIntForIndex(interp, indices[j], SORTIDX_END,
&sortInfo.indexv[j]) != TCL_OK) {
Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
"\n (-index option item number %d)", j));
@@ -3190,7 +3190,7 @@ Tcl_LsearchObjCmd(
*/
if (startPtr) {
result = TclGetIntForIndexM(interp, startPtr, listc-1, &offset);
result = TclGetIntForIndex(interp, startPtr, listc-1, &offset);
Tcl_DecrRefCount(startPtr);
if (result != TCL_OK) {
goto done;
@@ -3749,7 +3749,7 @@ Tcl_LsortObjCmd(
*/
for (j=0 ; j<indexc ; j++) {
if (TclGetIntForIndexM(interp, indexv[j], SORTIDX_END,
if (TclGetIntForIndex(interp, indexv[j], SORTIDX_END,
&dummy) != TCL_OK) {
Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
"\n (-index option item number %d)", j));
@@ -3830,7 +3830,7 @@ Tcl_LsortObjCmd(
* might be decreased by 1 later. */
}
for (j=0 ; j<sortInfo.indexc ; j++) {
TclGetIntForIndexM(interp, indexv[j], SORTIDX_END,
TclGetIntForIndex(interp, indexv[j], SORTIDX_END,
&sortInfo.indexv[j]);
}
}
+20 -20
View File
@@ -196,7 +196,7 @@ Tcl_RegexpObjCmd(
if (++i >= objc) {
goto endOfForLoop;
}
if (TclGetIntForIndexM(interp, objv[i], 0, &temp) != TCL_OK) {
if (TclGetIntForIndex(interp, objv[i], 0, &temp) != TCL_OK) {
goto optionError;
}
if (startIndex) {
@@ -258,7 +258,7 @@ Tcl_RegexpObjCmd(
stringLength = Tcl_GetCharLength(objPtr);
if (startIndex) {
TclGetIntForIndexM(NULL, startIndex, stringLength, &offset);
TclGetIntForIndex(NULL, startIndex, stringLength, &offset);
Tcl_DecrRefCount(startIndex);
if (offset < 0) {
offset = 0;
@@ -545,7 +545,7 @@ Tcl_RegsubObjCmd(
if (++idx >= objc) {
goto endOfForLoop;
}
if (TclGetIntForIndexM(interp, objv[idx], 0, &temp) != TCL_OK) {
if (TclGetIntForIndex(interp, objv[idx], 0, &temp) != TCL_OK) {
goto optionError;
}
if (startIndex) {
@@ -578,7 +578,7 @@ Tcl_RegsubObjCmd(
if (startIndex) {
int stringLength = Tcl_GetCharLength(objv[1]);
TclGetIntForIndexM(NULL, startIndex, stringLength, &offset);
TclGetIntForIndex(NULL, startIndex, stringLength, &offset);
Tcl_DecrRefCount(startIndex);
if (offset < 0) {
offset = 0;
@@ -1202,7 +1202,7 @@ StringFirstCmd(
* point in the string before we think about a match.
*/
if (TclGetIntForIndexM(interp, objv[3], haystackLen-1,
if (TclGetIntForIndex(interp, objv[3], haystackLen-1,
&start) != TCL_OK){
return TCL_ERROR;
}
@@ -1315,7 +1315,7 @@ StringLastCmd(
* range to that char index in the string
*/
if (TclGetIntForIndexM(interp, objv[3], haystackLen-1,
if (TclGetIntForIndex(interp, objv[3], haystackLen-1,
&start) != TCL_OK){
return TCL_ERROR;
}
@@ -1399,7 +1399,7 @@ StringIndexCmd(
*/
length = Tcl_GetCharLength(objv[1]);
if (TclGetIntForIndexM(interp, objv[2], length-1, &index) != TCL_OK) {
if (TclGetIntForIndex(interp, objv[2], length-1, &index) != TCL_OK) {
return TCL_ERROR;
}
@@ -1541,7 +1541,7 @@ StringIsCmd(
case STR_IS_TRUE:
case STR_IS_FALSE:
if ((objPtr->typePtr != &tclBooleanType)
&& (TCL_OK != TclSetBooleanFromAny(NULL, objPtr))) {
&& (TCL_OK != Tcl_GetBooleanFromObj(NULL, objPtr, &i))) {
if (strict) {
result = 0;
} else {
@@ -2181,8 +2181,8 @@ StringRangeCmd(
length = Tcl_GetCharLength(objv[1]) - 1;
if (TclGetIntForIndexM(interp, objv[2], length, &first) != TCL_OK ||
TclGetIntForIndexM(interp, objv[3], length, &last) != TCL_OK) {
if (TclGetIntForIndex(interp, objv[2], length, &first) != TCL_OK ||
TclGetIntForIndex(interp, objv[3], length, &last) != TCL_OK) {
return TCL_ERROR;
}
@@ -2346,8 +2346,8 @@ StringRplcCmd(
ustring = Tcl_GetUnicodeFromObj(objv[1], &length);
length--;
if (TclGetIntForIndexM(interp, objv[2], length, &first) != TCL_OK ||
TclGetIntForIndexM(interp, objv[3], length, &last) != TCL_OK){
if (TclGetIntForIndex(interp, objv[2], length, &first) != TCL_OK ||
TclGetIntForIndex(interp, objv[3], length, &last) != TCL_OK){
return TCL_ERROR;
}
@@ -2447,7 +2447,7 @@ StringStartCmd(
string = TclGetStringFromObj(objv[1], &length);
numChars = Tcl_NumUtfChars(string, length);
if (TclGetIntForIndexM(interp, objv[2], numChars-1, &index) != TCL_OK) {
if (TclGetIntForIndex(interp, objv[2], numChars-1, &index) != TCL_OK) {
return TCL_ERROR;
}
string = TclGetStringFromObj(objv[1], &length);
@@ -2508,7 +2508,7 @@ StringEndCmd(
string = TclGetStringFromObj(objv[1], &length);
numChars = Tcl_NumUtfChars(string, length);
if (TclGetIntForIndexM(interp, objv[2], numChars-1, &index) != TCL_OK) {
if (TclGetIntForIndex(interp, objv[2], numChars-1, &index) != TCL_OK) {
return TCL_ERROR;
}
string = TclGetStringFromObj(objv[1], &length);
@@ -2951,7 +2951,7 @@ StringLowerCmd(
Tcl_Obj *resultPtr;
length1 = Tcl_NumUtfChars(string1, length1) - 1;
if (TclGetIntForIndexM(interp,objv[2],length1, &first) != TCL_OK) {
if (TclGetIntForIndex(interp,objv[2],length1, &first) != TCL_OK) {
return TCL_ERROR;
}
if (first < 0) {
@@ -2959,7 +2959,7 @@ StringLowerCmd(
}
last = first;
if ((objc == 4) && (TclGetIntForIndexM(interp, objv[3], length1,
if ((objc == 4) && (TclGetIntForIndex(interp, objv[3], length1,
&last) != TCL_OK)) {
return TCL_ERROR;
}
@@ -3036,7 +3036,7 @@ StringUpperCmd(
Tcl_Obj *resultPtr;
length1 = Tcl_NumUtfChars(string1, length1) - 1;
if (TclGetIntForIndexM(interp,objv[2],length1, &first) != TCL_OK) {
if (TclGetIntForIndex(interp,objv[2],length1, &first) != TCL_OK) {
return TCL_ERROR;
}
if (first < 0) {
@@ -3044,7 +3044,7 @@ StringUpperCmd(
}
last = first;
if ((objc == 4) && (TclGetIntForIndexM(interp, objv[3], length1,
if ((objc == 4) && (TclGetIntForIndex(interp, objv[3], length1,
&last) != TCL_OK)) {
return TCL_ERROR;
}
@@ -3121,7 +3121,7 @@ StringTitleCmd(
Tcl_Obj *resultPtr;
length1 = Tcl_NumUtfChars(string1, length1) - 1;
if (TclGetIntForIndexM(interp,objv[2],length1, &first) != TCL_OK) {
if (TclGetIntForIndex(interp,objv[2],length1, &first) != TCL_OK) {
return TCL_ERROR;
}
if (first < 0) {
@@ -3129,7 +3129,7 @@ StringTitleCmd(
}
last = first;
if ((objc == 4) && (TclGetIntForIndexM(interp, objv[3], length1,
if ((objc == 4) && (TclGetIntForIndex(interp, objv[3], length1,
&last) != TCL_OK)) {
return TCL_ERROR;
}
+5 -5
View File
@@ -4273,7 +4273,7 @@ TclCompileLindexCmd(
result = TCL_ERROR;
}
} else {
result = TclGetIntForIndexM(NULL, tmpObj, -2, &idx);
result = TclGetIntForIndex(NULL, tmpObj, -2, &idx);
if (result == TCL_OK && idx > -2) {
result = TCL_ERROR;
}
@@ -4474,7 +4474,7 @@ TclCompileLrangeCmd(
result = TCL_ERROR;
}
} else {
result = TclGetIntForIndexM(NULL, tmpObj, -2, &idx1);
result = TclGetIntForIndex(NULL, tmpObj, -2, &idx1);
if (result == TCL_OK && idx1 > -2) {
result = TCL_ERROR;
}
@@ -4501,7 +4501,7 @@ TclCompileLrangeCmd(
result = TCL_ERROR;
}
} else {
result = TclGetIntForIndexM(NULL, tmpObj, -2, &idx2);
result = TclGetIntForIndex(NULL, tmpObj, -2, &idx2);
if (result == TCL_OK && idx2 > -2) {
result = TCL_ERROR;
}
@@ -4573,7 +4573,7 @@ TclCompileLreplaceCmd(
result = TCL_ERROR;
}
} else {
result = TclGetIntForIndexM(NULL, tmpObj, -2, &idx1);
result = TclGetIntForIndex(NULL, tmpObj, -2, &idx1);
if (result == TCL_OK && idx1 > -2) {
result = TCL_ERROR;
}
@@ -4600,7 +4600,7 @@ TclCompileLreplaceCmd(
result = TCL_ERROR;
}
} else {
result = TclGetIntForIndexM(NULL, tmpObj, -2, &idx2);
result = TclGetIntForIndex(NULL, tmpObj, -2, &idx2);
if (result == TCL_OK && idx2 > -2) {
result = TCL_ERROR;
}
+2 -2
View File
@@ -641,7 +641,7 @@ TclCompileStringRangeCmd(
if (idx1 >= 0) {
result = TCL_OK;
}
} else if (TclGetIntForIndexM(NULL, tmpObj, -2, &idx1) == TCL_OK) {
} else if (TclGetIntForIndex(NULL, tmpObj, -2, &idx1) == TCL_OK) {
if (idx1 <= -2) {
result = TCL_OK;
}
@@ -665,7 +665,7 @@ TclCompileStringRangeCmd(
if (idx2 >= 0) {
result = TCL_OK;
}
} else if (TclGetIntForIndexM(NULL, tmpObj, -2, &idx2) == TCL_OK) {
} else if (TclGetIntForIndex(NULL, tmpObj, -2, &idx2) == TCL_OK) {
if (idx2 <= -2) {
result = TCL_OK;
}
+2 -39
View File
@@ -557,8 +557,6 @@ static int GetCmdLocEncodingSize(CompileEnv *envPtr);
#ifdef TCL_COMPILE_STATS
static void RecordByteCodeStats(ByteCode *codePtr);
#endif /* TCL_COMPILE_STATS */
static int SetByteCodeFromAny(Tcl_Interp *interp,
Tcl_Obj *objPtr);
static int FormatInstruction(ByteCode *codePtr,
const unsigned char *pc, Tcl_Obj *bufferObj);
static void PrintSourceToObj(Tcl_Obj *appendObj,
@@ -584,7 +582,7 @@ const Tcl_ObjType tclByteCodeType = {
FreeByteCodeInternalRep, /* freeIntRepProc */
DupByteCodeInternalRep, /* dupIntRepProc */
NULL, /* updateStringProc */
SetByteCodeFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
/*
@@ -661,7 +659,7 @@ TclSetByteCodeFromAny(
if (!traceInitialized) {
if (Tcl_LinkVar(interp, "tcl_traceCompile",
(char *) &tclTraceCompile, TCL_LINK_INT) != TCL_OK) {
Tcl_Panic("SetByteCodeFromAny: unable to create link for tcl_traceCompile variable");
Tcl_Panic("TclSetByteCodeFromAny: unable to create link for tcl_traceCompile variable");
}
traceInitialized = 1;
}
@@ -757,41 +755,6 @@ TclSetByteCodeFromAny(
return result;
}
/*
*-----------------------------------------------------------------------
*
* SetByteCodeFromAny --
*
* Part of the bytecode Tcl object type implementation. Attempts to
* generate an byte code internal form for the Tcl object "objPtr" by
* compiling its string representation.
*
* Results:
* The return value is a standard Tcl object result. If an error occurs
* during compilation, an error message is left in the interpreter's
* result unless "interp" is NULL.
*
* Side effects:
* Frees the old internal representation. If no error occurs, then the
* compiled code is stored as "objPtr"s bytecode representation. Also, if
* debugging, initializes the "tcl_traceCompile" Tcl variable used to
* trace compilations.
*
*----------------------------------------------------------------------
*/
static int
SetByteCodeFromAny(
Tcl_Interp *interp, /* The interpreter for which the code is being
* compiled. Must not be NULL. */
Tcl_Obj *objPtr) /* The object to make a ByteCode object. */
{
if (interp == NULL) {
return TCL_ERROR;
}
return TclSetByteCodeFromAny(interp, objPtr, NULL, NULL);
}
/*
*----------------------------------------------------------------------
*
+1 -1
View File
@@ -229,7 +229,7 @@ typedef struct CompileEnv {
* are specific to an interpreter so the code
* emitted will depend on the interpreter. */
const char *source; /* The source string being compiled by
* SetByteCodeFromAny. This pointer is not
* TclSetByteCodeFromAny. This pointer is not
* owned by the CompileEnv and must not be
* freed or changed by it. */
int numSrcBytes; /* Number of bytes in source. */
+20 -17
View File
@@ -72,9 +72,7 @@ TCLAPI void Tcl_SetTimer(const Tcl_Time *timePtr);
TCLAPI void Tcl_Sleep(int ms);
/* 13 */
TCLAPI int Tcl_WaitForEvent(const Tcl_Time *timePtr);
/* 14 */
TCLAPI int Tcl_AppendAllObjTypes(Tcl_Interp *interp,
Tcl_Obj *objPtr);
/* Slot 14 is reserved */
/* 15 */
TCLAPI void Tcl_AppendStringsToObj(Tcl_Obj *objPtr, ...);
/* 16 */
@@ -82,9 +80,7 @@ TCLAPI void Tcl_AppendToObj(Tcl_Obj *objPtr, const char *bytes,
int length);
/* 17 */
TCLAPI Tcl_Obj * Tcl_ConcatObj(int objc, Tcl_Obj *const objv[]);
/* 18 */
TCLAPI int Tcl_ConvertToType(Tcl_Interp *interp,
Tcl_Obj *objPtr, const Tcl_ObjType *typePtr);
/* Slot 18 is reserved */
/* 19 */
TCLAPI void Tcl_DbDecrRefCount(Tcl_Obj *objPtr, const char *file,
int line);
@@ -591,8 +587,7 @@ TCLAPI int Tcl_RecordAndEvalObj(Tcl_Interp *interp,
/* 210 */
TCLAPI void Tcl_RegisterChannel(Tcl_Interp *interp,
Tcl_Channel chan);
/* 211 */
TCLAPI void Tcl_RegisterObjType(const Tcl_ObjType *typePtr);
/* Slot 211 is reserved */
/* 212 */
TCLAPI Tcl_RegExp Tcl_RegExpCompile(Tcl_Interp *interp,
const char *pattern);
@@ -1747,6 +1742,9 @@ TCLAPI int Tcl_FSUnloadFile(Tcl_Interp *interp,
TCLAPI void Tcl_ZlibStreamSetCompressionDictionary(
Tcl_ZlibStream zhandle,
Tcl_Obj *compressionDictionaryObj);
/* 631 */
TCLAPI int Tcl_GetIntForIndex(Tcl_Interp *interp,
Tcl_Obj *objPtr, int endValue, int *indexPtr);
typedef struct {
const struct TclPlatStubs *tclPlatStubs;
@@ -1788,11 +1786,11 @@ typedef struct TclStubs {
void (*tcl_SetTimer) (const Tcl_Time *timePtr); /* 11 */
void (*tcl_Sleep) (int ms); /* 12 */
int (*tcl_WaitForEvent) (const Tcl_Time *timePtr); /* 13 */
int (*tcl_AppendAllObjTypes) (Tcl_Interp *interp, Tcl_Obj *objPtr); /* 14 */
void (*reserved14)(void);
void (*tcl_AppendStringsToObj) (Tcl_Obj *objPtr, ...); /* 15 */
void (*tcl_AppendToObj) (Tcl_Obj *objPtr, const char *bytes, int length); /* 16 */
Tcl_Obj * (*tcl_ConcatObj) (int objc, Tcl_Obj *const objv[]); /* 17 */
int (*tcl_ConvertToType) (Tcl_Interp *interp, Tcl_Obj *objPtr, const Tcl_ObjType *typePtr); /* 18 */
void (*reserved18)(void);
void (*tcl_DbDecrRefCount) (Tcl_Obj *objPtr, const char *file, int line); /* 19 */
void (*tcl_DbIncrRefCount) (Tcl_Obj *objPtr, const char *file, int line); /* 20 */
int (*tcl_DbIsShared) (Tcl_Obj *objPtr, const char *file, int line); /* 21 */
@@ -1993,7 +1991,7 @@ typedef struct TclStubs {
int (*tcl_RecordAndEval) (Tcl_Interp *interp, const char *cmd, int flags); /* 208 */
int (*tcl_RecordAndEvalObj) (Tcl_Interp *interp, Tcl_Obj *cmdPtr, int flags); /* 209 */
void (*tcl_RegisterChannel) (Tcl_Interp *interp, Tcl_Channel chan); /* 210 */
void (*tcl_RegisterObjType) (const Tcl_ObjType *typePtr); /* 211 */
void (*reserved211)(void);
Tcl_RegExp (*tcl_RegExpCompile) (Tcl_Interp *interp, const char *pattern); /* 212 */
int (*tcl_RegExpExec) (Tcl_Interp *interp, Tcl_RegExp regexp, const char *text, const char *start); /* 213 */
int (*tcl_RegExpMatch) (Tcl_Interp *interp, const char *text, const char *pattern); /* 214 */
@@ -2413,6 +2411,7 @@ typedef struct TclStubs {
void * (*tcl_FindSymbol) (Tcl_Interp *interp, Tcl_LoadHandle handle, const char *symbol); /* 628 */
int (*tcl_FSUnloadFile) (Tcl_Interp *interp, Tcl_LoadHandle handlePtr); /* 629 */
void (*tcl_ZlibStreamSetCompressionDictionary) (Tcl_ZlibStream zhandle, Tcl_Obj *compressionDictionaryObj); /* 630 */
int (*tcl_GetIntForIndex) (Tcl_Interp *interp, Tcl_Obj *objPtr, int endValue, int *indexPtr); /* 631 */
} TclStubs;
#ifdef __cplusplus
@@ -2469,16 +2468,14 @@ extern const TclStubs *tclStubsPtr;
(tclStubsPtr->tcl_Sleep) /* 12 */
#define Tcl_WaitForEvent \
(tclStubsPtr->tcl_WaitForEvent) /* 13 */
#define Tcl_AppendAllObjTypes \
(tclStubsPtr->tcl_AppendAllObjTypes) /* 14 */
/* Slot 14 is reserved */
#define Tcl_AppendStringsToObj \
(tclStubsPtr->tcl_AppendStringsToObj) /* 15 */
#define Tcl_AppendToObj \
(tclStubsPtr->tcl_AppendToObj) /* 16 */
#define Tcl_ConcatObj \
(tclStubsPtr->tcl_ConcatObj) /* 17 */
#define Tcl_ConvertToType \
(tclStubsPtr->tcl_ConvertToType) /* 18 */
/* Slot 18 is reserved */
#define Tcl_DbDecrRefCount \
(tclStubsPtr->tcl_DbDecrRefCount) /* 19 */
#define Tcl_DbIncrRefCount \
@@ -2852,8 +2849,7 @@ extern const TclStubs *tclStubsPtr;
(tclStubsPtr->tcl_RecordAndEvalObj) /* 209 */
#define Tcl_RegisterChannel \
(tclStubsPtr->tcl_RegisterChannel) /* 210 */
#define Tcl_RegisterObjType \
(tclStubsPtr->tcl_RegisterObjType) /* 211 */
/* Slot 211 is reserved */
#define Tcl_RegExpCompile \
(tclStubsPtr->tcl_RegExpCompile) /* 212 */
#define Tcl_RegExpExec \
@@ -3680,6 +3676,8 @@ extern const TclStubs *tclStubsPtr;
(tclStubsPtr->tcl_FSUnloadFile) /* 629 */
#define Tcl_ZlibStreamSetCompressionDictionary \
(tclStubsPtr->tcl_ZlibStreamSetCompressionDictionary) /* 630 */
#define Tcl_GetIntForIndex \
(tclStubsPtr->tcl_GetIntForIndex) /* 631 */
#endif /* defined(USE_TCL_STUBS) */
@@ -3734,6 +3732,11 @@ TCLAPI void Tcl_MainExW(int argc, wchar_t **argv,
Tcl_AppendObjToErrorInfo((interp), Tcl_NewStringObj((message), -1))
#define Tcl_AddObjErrorInfo(interp, message, length) \
Tcl_AppendObjToErrorInfo((interp), Tcl_NewStringObj((message), length))
#define Tcl_AppendAllObjTypes(interp, objPtr) (TCL_OK)
#define Tcl_RegisterObjType(typePtr) /* Do Nothing */
#define Tcl_ConvertToType(interp, objPtr, type) \
(Tcl_ResetResult(interp),Tcl_AppendResult((interp), "cannot convert to ", \
(type)->name, NULL), TCL_ERROR)
/*
* Deprecated Tcl procedures:
+1 -1
View File
@@ -164,7 +164,7 @@ const Tcl_ObjType tclDictType = {
FreeDictInternalRep, /* freeIntRepProc */
DupDictInternalRep, /* dupIntRepProc */
UpdateStringOfDict, /* updateStringProc */
SetDictFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
/*
+4 -4
View File
@@ -4307,7 +4307,7 @@ TEBCresume(
if ((TclListObjGetElements(interp, valuePtr, &objc, &objv) == TCL_OK)
&& (value2Ptr->typePtr != &tclListType)
&& (TclGetIntForIndexM(NULL , value2Ptr, objc-1,
&& (TclGetIntForIndex(NULL , value2Ptr, objc-1,
&index) == TCL_OK)) {
TclDecrRefCount(value2Ptr);
tosPtr--;
@@ -4784,7 +4784,7 @@ TEBCresume(
*/
length = Tcl_GetCharLength(valuePtr);
if (TclGetIntForIndexM(interp, value2Ptr, length-1, &index)!=TCL_OK) {
if (TclGetIntForIndex(interp, value2Ptr, length-1, &index)!=TCL_OK) {
goto gotError;
}
@@ -4818,9 +4818,9 @@ TEBCresume(
TRACE(("\"%.20s\" %s %s =>",
O2S(OBJ_AT_DEPTH(2)), O2S(OBJ_UNDER_TOS), O2S(OBJ_AT_TOS)));
length = Tcl_GetCharLength(OBJ_AT_DEPTH(2)) - 1;
if (TclGetIntForIndexM(interp, OBJ_UNDER_TOS, length,
if (TclGetIntForIndex(interp, OBJ_UNDER_TOS, length,
&fromIdx) != TCL_OK
|| TclGetIntForIndexM(interp, OBJ_AT_TOS, length,
|| TclGetIntForIndex(interp, OBJ_AT_TOS, length,
&toIdx) != TCL_OK) {
goto gotError;
}
+1 -4
View File
@@ -137,13 +137,10 @@ Tcl_GetBoolean(
obj.length = strlen(src);
obj.typePtr = NULL;
code = TclSetBooleanFromAny(interp, &obj);
code = Tcl_GetBooleanFromObj(interp, &obj, boolPtr);
if (obj.refCount > 1) {
Tcl_Panic("invalid sharing of Tcl_Obj on C stack");
}
if (code == TCL_OK) {
*boolPtr = obj.internalRep.longValue;
}
return code;
}
+1 -35
View File
@@ -22,7 +22,6 @@
static int GetIndexFromObjList(Tcl_Interp *interp,
Tcl_Obj *objPtr, Tcl_Obj *tableObjPtr,
const char *msg, int flags, int *indexPtr);
static int SetIndexFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
static void UpdateStringOfIndex(Tcl_Obj *objPtr);
static void DupIndex(Tcl_Obj *srcPtr, Tcl_Obj *dupPtr);
static void FreeIndex(Tcl_Obj *objPtr);
@@ -48,7 +47,7 @@ static const Tcl_ObjType indexType = {
FreeIndex, /* freeIntRepProc */
DupIndex, /* dupIntRepProc */
UpdateStringOfIndex, /* updateStringProc */
SetIndexFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
/*
@@ -331,39 +330,6 @@ Tcl_GetIndexFromObjStruct(
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* SetIndexFromAny --
*
* This function is called to convert a Tcl object to index internal
* form. However, this doesn't make sense (need to have a table of
* keywords in order to do the conversion) so the function always
* generates an error.
*
* Results:
* The return value is always TCL_ERROR, and an error message is left in
* interp's result if interp isn't NULL.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
SetIndexFromAny(
Tcl_Interp *interp, /* Used for error reporting if not NULL. */
register Tcl_Obj *objPtr) /* The object to convert. */
{
if (interp) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"can't convert value to index except via Tcl_GetIndexFromObj API",
-1));
}
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
+5 -4
View File
@@ -153,10 +153,11 @@ declare 32 {
#declare 33 {
# TclCmdProcType TclGetInterpProc(void)
#}
declare 34 {
int TclGetIntForIndex(Tcl_Interp *interp, Tcl_Obj *objPtr,
int endValue, int *indexPtr)
}
# Removed in 9.0:
#declare 34 {
# int TclGetIntForIndex(Tcl_Interp *interp, Tcl_Obj *objPtr,
# int endValue, int *indexPtr)
#}
# Removed in 8.4b2:
#declare 35 {
# Tcl_Obj *TclGetIndexedScalar(Tcl_Interp *interp, int localIndex,
+4 -9
View File
@@ -2483,15 +2483,15 @@ typedef struct List {
(((objPtr)->typePtr == &tclIntType) \
? ((*(intPtr) = (objPtr)->internalRep.longValue), TCL_OK) \
: Tcl_GetIntFromObj((interp), (objPtr), (intPtr)))
#define TclGetIntForIndexM(interp, objPtr, endValue, idxPtr) \
#define TclGetIntForIndex(interp, objPtr, endValue, idxPtr) \
(((objPtr)->typePtr == &tclIntType) \
? ((*(idxPtr) = (objPtr)->internalRep.longValue), TCL_OK) \
: TclGetIntForIndex((interp), (objPtr), (endValue), (idxPtr)))
: Tcl_GetIntForIndex((interp), (objPtr), (endValue), (idxPtr)))
#else
#define TclGetIntFromObj(interp, objPtr, intPtr) \
Tcl_GetIntFromObj((interp), (objPtr), (intPtr))
#define TclGetIntForIndexM(interp, objPtr, ignore, idxPtr) \
TclGetIntForIndex(interp, objPtr, ignore, idxPtr)
#define TclGetIntForIndex(interp, objPtr, ignore, idxPtr) \
Tcl_GetIntForIndex(interp, objPtr, ignore, idxPtr)
#endif
/*
@@ -2690,18 +2690,14 @@ MODULE_SCOPE const Tcl_ObjType tclBooleanType;
MODULE_SCOPE const Tcl_ObjType tclByteArrayType;
MODULE_SCOPE const Tcl_ObjType tclByteCodeType;
MODULE_SCOPE const Tcl_ObjType tclDoubleType;
MODULE_SCOPE const Tcl_ObjType tclEndOffsetType;
MODULE_SCOPE const Tcl_ObjType tclIntType;
MODULE_SCOPE const Tcl_ObjType tclListType;
MODULE_SCOPE const Tcl_ObjType tclDictType;
MODULE_SCOPE const Tcl_ObjType tclProcBodyType;
MODULE_SCOPE const Tcl_ObjType tclStringType;
MODULE_SCOPE const Tcl_ObjType tclArraySearchType;
MODULE_SCOPE const Tcl_ObjType tclEnsembleCmdType;
#ifndef NO_WIDE_TYPE
MODULE_SCOPE const Tcl_ObjType tclWideIntType;
#endif
MODULE_SCOPE const Tcl_ObjType tclRegexpType;
MODULE_SCOPE Tcl_ObjType tclCmdNameType;
/*
@@ -3092,7 +3088,6 @@ MODULE_SCOPE void TclSetBgErrorHandler(Tcl_Interp *interp,
Tcl_Obj *cmdPrefix);
MODULE_SCOPE void TclSetBignumIntRep(Tcl_Obj *objPtr,
mp_int *bignumValue);
MODULE_SCOPE int TclSetBooleanFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
MODULE_SCOPE void TclSetCmdNameObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
Command *cmdPtr);
MODULE_SCOPE void TclSetDuplicateObj(Tcl_Obj *dupPtr, Tcl_Obj *objPtr);
+3 -6
View File
@@ -94,9 +94,7 @@ TCLAPI const char * TclGetExtension(const char *name);
TCLAPI int TclGetFrame(Tcl_Interp *interp, const char *str,
CallFrame **framePtrPtr);
/* Slot 33 is reserved */
/* 34 */
TCLAPI int TclGetIntForIndex(Tcl_Interp *interp,
Tcl_Obj *objPtr, int endValue, int *indexPtr);
/* Slot 34 is reserved */
/* Slot 35 is reserved */
/* Slot 36 is reserved */
/* 37 */
@@ -581,7 +579,7 @@ typedef struct TclIntStubs {
const char * (*tclGetExtension) (const char *name); /* 31 */
int (*tclGetFrame) (Tcl_Interp *interp, const char *str, CallFrame **framePtrPtr); /* 32 */
void (*reserved33)(void);
int (*tclGetIntForIndex) (Tcl_Interp *interp, Tcl_Obj *objPtr, int endValue, int *indexPtr); /* 34 */
void (*reserved34)(void);
void (*reserved35)(void);
void (*reserved36)(void);
int (*tclGetLoadedPackages) (Tcl_Interp *interp, const char *targetName); /* 37 */
@@ -865,8 +863,7 @@ extern const TclIntStubs *tclIntStubsPtr;
#define TclGetFrame \
(tclIntStubsPtr->tclGetFrame) /* 32 */
/* Slot 33 is reserved */
#define TclGetIntForIndex \
(tclIntStubsPtr->tclGetIntForIndex) /* 34 */
/* Slot 34 is reserved */
/* Slot 35 is reserved */
/* Slot 36 is reserved */
#define TclGetLoadedPackages \
+7 -7
View File
@@ -43,7 +43,7 @@ const Tcl_ObjType tclListType = {
FreeListInternalRep, /* freeIntRepProc */
DupListInternalRep, /* dupIntRepProc */
UpdateStringOfList, /* updateStringProc */
SetListFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
#ifndef TCL_MIN_ELEMENT_GROWTH
@@ -1099,7 +1099,7 @@ TclLindexList(
*/
if (argPtr->typePtr != &tclListType
&& TclGetIntForIndexM(NULL , argPtr, 0, &index) == TCL_OK) {
&& TclGetIntForIndex(NULL , argPtr, 0, &index) == TCL_OK) {
/*
* argPtr designates a single index.
*/
@@ -1207,7 +1207,7 @@ TclLindexFlat(
}
TclListObjGetElements(NULL, sublistCopy, &listLen, &elemPtrs);
if (TclGetIntForIndexM(interp, indexArray[i], /*endValue*/ listLen-1,
if (TclGetIntForIndex(interp, indexArray[i], /*endValue*/ listLen-1,
&index) == TCL_OK) {
if (index<0 || index>=listLen) {
/*
@@ -1216,7 +1216,7 @@ TclLindexFlat(
*/
while (++i < indexCount) {
if (TclGetIntForIndexM(interp, indexArray[i], -1, &index)
if (TclGetIntForIndex(interp, indexArray[i], -1, &index)
!= TCL_OK) {
Tcl_DecrRefCount(sublistCopy);
return NULL;
@@ -1284,7 +1284,7 @@ TclLsetList(
*/
if (indexArgPtr->typePtr != &tclListType
&& TclGetIntForIndexM(NULL, indexArgPtr, 0, &index) == TCL_OK) {
&& TclGetIntForIndex(NULL, indexArgPtr, 0, &index) == TCL_OK) {
/*
* indexArgPtr designates a single index.
*/
@@ -1422,11 +1422,11 @@ TclLsetFlat(
}
/*
* WARNING: the macro TclGetIntForIndexM is not safe for
* WARNING: the macro TclGetIntForIndex is not safe for
* post-increments, avoid '*indexArray++' here.
*/
if (TclGetIntForIndexM(interp, *indexArray, elemCount - 1, &index)
if (TclGetIntForIndex(interp, *indexArray, elemCount - 1, &index)
!= TCL_OK) {
/* ...the index we're trying to use isn't an index at all. */
result = TCL_ERROR;
+1 -1
View File
@@ -151,7 +151,7 @@ static const Tcl_ObjType nsNameType = {
FreeNsNameInternalRep, /* freeIntRepProc */
DupNsNameInternalRep, /* dupIntRepProc */
NULL, /* updateStringProc */
SetNsNameFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
/*
+9 -348
View File
@@ -18,14 +18,6 @@
#include "tommath.h"
#include <math.h>
/*
* Table of all object types.
*/
static Tcl_HashTable typeTable;
static int typeTableInitialized = 0; /* 0 means not yet initialized. */
TCL_DECLARE_MUTEX(tableMutex)
/*
* Head of the list of free Tcl_Obj structs we maintain.
*/
@@ -209,12 +201,10 @@ static Tcl_ThreadDataKey pendingObjDataKey;
static int ParseBoolean(Tcl_Obj *objPtr);
static int SetDoubleFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
static int SetIntFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
static void UpdateStringOfDouble(Tcl_Obj *objPtr);
static void UpdateStringOfInt(Tcl_Obj *objPtr);
#ifndef NO_WIDE_TYPE
static void UpdateStringOfWideInt(Tcl_Obj *objPtr);
static int SetWideIntFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
#endif
static void FreeBignum(Tcl_Obj *objPtr);
static void DupBignum(Tcl_Obj *objPtr, Tcl_Obj *copyPtr);
@@ -244,33 +234,26 @@ static int SetCmdNameFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
* implementations.
*/
static const Tcl_ObjType oldBooleanType = {
"boolean", /* name */
NULL, /* freeIntRepProc */
NULL, /* dupIntRepProc */
NULL, /* updateStringProc */
TclSetBooleanFromAny /* setFromAnyProc */
};
const Tcl_ObjType tclBooleanType = {
"booleanString", /* name */
"boolean", /* name */
NULL, /* freeIntRepProc */
NULL, /* dupIntRepProc */
NULL, /* updateStringProc */
TclSetBooleanFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
const Tcl_ObjType tclDoubleType = {
"double", /* name */
NULL, /* freeIntRepProc */
NULL, /* dupIntRepProc */
UpdateStringOfDouble, /* updateStringProc */
SetDoubleFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
const Tcl_ObjType tclIntType = {
"int", /* name */
NULL, /* freeIntRepProc */
NULL, /* dupIntRepProc */
UpdateStringOfInt, /* updateStringProc */
SetIntFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
#ifndef NO_WIDE_TYPE
const Tcl_ObjType tclWideIntType = {
@@ -278,7 +261,7 @@ const Tcl_ObjType tclWideIntType = {
NULL, /* freeIntRepProc */
NULL, /* dupIntRepProc */
UpdateStringOfWideInt, /* updateStringProc */
SetWideIntFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
#endif
const Tcl_ObjType tclBignumType = {
@@ -330,7 +313,7 @@ Tcl_ObjType tclCmdNameType = {
FreeCmdNameInternalRep, /* freeIntRepProc */
DupCmdNameInternalRep, /* dupIntRepProc */
NULL, /* updateStringProc */
SetCmdNameFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
/*
@@ -375,14 +358,13 @@ typedef struct ResolvedCmdName {
* TclInitObjectSubsystem --
*
* This function is invoked to perform once-only initialization of the
* type table. It also registers the object types defined in this file.
* things needed when Tcl is compiled with the TCL_COMPILE_STATS option.
*
* Results:
* None.
*
* Side effects:
* Initializes the table of defined object types "typeTable" with builtin
* object types defined in this file.
* None
*
*-------------------------------------------------------------------------
*/
@@ -390,30 +372,6 @@ typedef struct ResolvedCmdName {
void
TclInitObjSubsystem(void)
{
Tcl_MutexLock(&tableMutex);
typeTableInitialized = 1;
Tcl_InitHashTable(&typeTable, TCL_STRING_KEYS);
Tcl_MutexUnlock(&tableMutex);
Tcl_RegisterObjType(&tclByteArrayType);
Tcl_RegisterObjType(&tclDoubleType);
Tcl_RegisterObjType(&tclEndOffsetType);
Tcl_RegisterObjType(&tclIntType);
Tcl_RegisterObjType(&tclStringType);
Tcl_RegisterObjType(&tclListType);
Tcl_RegisterObjType(&tclDictType);
Tcl_RegisterObjType(&tclByteCodeType);
Tcl_RegisterObjType(&tclArraySearchType);
Tcl_RegisterObjType(&tclCmdNameType);
Tcl_RegisterObjType(&tclRegexpType);
Tcl_RegisterObjType(&tclProcBodyType);
/* For backward compatibility only ... */
Tcl_RegisterObjType(&oldBooleanType);
#ifndef NO_WIDE_TYPE
Tcl_RegisterObjType(&tclWideIntType);
#endif
#ifdef TCL_COMPILE_STATS
Tcl_MutexLock(&tclObjMutex);
tclObjsAlloced = 0;
@@ -492,13 +450,6 @@ TclFinalizeThreadObjects(void)
void
TclFinalizeObjects(void)
{
Tcl_MutexLock(&tableMutex);
if (typeTableInitialized) {
Tcl_DeleteHashTable(&typeTable);
typeTableInitialized = 0;
}
Tcl_MutexUnlock(&tableMutex);
/*
* All we do here is reset the head pointer of the linked list of free
* Tcl_Obj's to NULL; the memory finalization will take care of releasing
@@ -844,97 +795,6 @@ ContLineLocFree(
ckfree(clientData);
}
/*
*--------------------------------------------------------------
*
* Tcl_RegisterObjType --
*
* This function is called to register a new Tcl object type in the table
* of all object types supported by Tcl.
*
* Results:
* None.
*
* Side effects:
* The type is registered in the Tcl type table. If there was already a
* type with the same name as in typePtr, it is replaced with the new
* type.
*
*--------------------------------------------------------------
*/
void
Tcl_RegisterObjType(
const Tcl_ObjType *typePtr) /* Information about object type; storage must
* be statically allocated (must live
* forever). */
{
int isNew;
Tcl_MutexLock(&tableMutex);
Tcl_SetHashValue(
Tcl_CreateHashEntry(&typeTable, typePtr->name, &isNew), typePtr);
Tcl_MutexUnlock(&tableMutex);
}
/*
*----------------------------------------------------------------------
*
* Tcl_AppendAllObjTypes --
*
* This function appends onto the argument object the name of each object
* type as a list element. This includes the builtin object types (e.g.
* int, list) as well as those added using Tcl_NewObj. These names can be
* used, for example, with Tcl_GetObjType to get pointers to the
* corresponding Tcl_ObjType structures.
*
* Results:
* The return value is normally TCL_OK; in this case the object
* referenced by objPtr has each type name appended to it. If an error
* occurs, TCL_ERROR is returned and the interpreter's result holds an
* error message.
*
* Side effects:
* If necessary, the object referenced by objPtr is converted into a list
* object.
*
*----------------------------------------------------------------------
*/
int
Tcl_AppendAllObjTypes(
Tcl_Interp *interp, /* Interpreter used for error reporting. */
Tcl_Obj *objPtr) /* Points to the Tcl object onto which the
* name of each registered type is appended as
* a list element. */
{
register Tcl_HashEntry *hPtr;
Tcl_HashSearch search;
int numElems;
/*
* Get the test for a valid list out of the way first.
*/
if (TclListObjLength(interp, objPtr, &numElems) != TCL_OK) {
return TCL_ERROR;
}
/*
* Type names are NUL-terminated, not counted strings. This code relies on
* that.
*/
Tcl_MutexLock(&tableMutex);
for (hPtr = Tcl_FirstHashEntry(&typeTable, &search);
hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
Tcl_ListObjAppendElement(NULL, objPtr,
Tcl_NewStringObj(Tcl_GetHashKey(&typeTable, hPtr), -1));
}
Tcl_MutexUnlock(&tableMutex);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
@@ -956,59 +816,7 @@ const Tcl_ObjType *
Tcl_GetObjType(
const char *typeName) /* Name of Tcl object type to look up. */
{
register Tcl_HashEntry *hPtr;
const Tcl_ObjType *typePtr = NULL;
Tcl_MutexLock(&tableMutex);
hPtr = Tcl_FindHashEntry(&typeTable, typeName);
if (hPtr != NULL) {
typePtr = Tcl_GetHashValue(hPtr);
}
Tcl_MutexUnlock(&tableMutex);
return typePtr;
}
/*
*----------------------------------------------------------------------
*
* Tcl_ConvertToType --
*
* Convert the Tcl object "objPtr" to have type "typePtr" if possible.
*
* Results:
* The return value is TCL_OK on success and TCL_ERROR on failure. If
* TCL_ERROR is returned, then the interpreter's result contains an error
* message unless "interp" is NULL. Passing a NULL "interp" allows this
* function to be used as a test whether the conversion could be done
* (and in fact was done).
*
* Side effects:
* Any internal representation for the old type is freed.
*
*----------------------------------------------------------------------
*/
int
Tcl_ConvertToType(
Tcl_Interp *interp, /* Used for error reporting if not NULL. */
Tcl_Obj *objPtr, /* The object to convert. */
const Tcl_ObjType *typePtr) /* The target type. */
{
if (objPtr->typePtr == typePtr) {
return TCL_OK;
}
/*
* Use the target type's Tcl_SetFromAnyProc to set "objPtr"s internal form
* as appropriate for the target type. This frees the old internal
* representation.
*/
if (typePtr->setFromAnyProc == NULL) {
Tcl_Panic("may not convert object to type %s", typePtr->name);
}
return typePtr->setFromAnyProc(interp, objPtr);
return NULL;
}
/*
@@ -1771,80 +1579,6 @@ Tcl_GetBooleanFromObj(
return TCL_ERROR;
}
/*
*----------------------------------------------------------------------
*
* TclSetBooleanFromAny --
*
* Attempt to generate a boolean internal form for the Tcl object
* "objPtr".
*
* Results:
* The return value is a standard Tcl result. If an error occurs during
* conversion, an error message is left in the interpreter's result
* unless "interp" is NULL.
*
* Side effects:
* If no error occurs, an integer 1 or 0 is stored as "objPtr"s internal
* representation and the type of "objPtr" is set to boolean.
*
*----------------------------------------------------------------------
*/
int
TclSetBooleanFromAny(
Tcl_Interp *interp, /* Used for error reporting if not NULL. */
register Tcl_Obj *objPtr) /* The object to convert. */
{
/*
* For some "pure" numeric Tcl_ObjTypes (no string rep), we can determine
* whether a boolean conversion is possible without generating the string
* rep.
*/
if (objPtr->bytes == NULL) {
if (objPtr->typePtr == &tclIntType) {
switch (objPtr->internalRep.longValue) {
case 0L: case 1L:
return TCL_OK;
}
goto badBoolean;
}
if (objPtr->typePtr == &tclBignumType) {
goto badBoolean;
}
#ifndef NO_WIDE_TYPE
if (objPtr->typePtr == &tclWideIntType) {
goto badBoolean;
}
#endif
if (objPtr->typePtr == &tclDoubleType) {
goto badBoolean;
}
}
if (ParseBoolean(objPtr) == TCL_OK) {
return TCL_OK;
}
badBoolean:
if (interp != NULL) {
int length;
const char *str = Tcl_GetStringFromObj(objPtr, &length);
Tcl_Obj *msg;
TclNewLiteralStringObj(msg, "expected boolean value but got \"");
Tcl_AppendLimitedToObj(msg, str, length, 50, "");
Tcl_AppendToObj(msg, "\"", -1);
Tcl_SetObjResult(interp, msg);
Tcl_SetErrorCode(interp, "TCL", "VALUE", "BOOLEAN", NULL);
}
return TCL_ERROR;
}
static int
ParseBoolean(
register Tcl_Obj *objPtr) /* The object to parse/convert. */
@@ -1861,21 +1595,6 @@ ParseBoolean(
return TCL_ERROR;
}
switch (str[0]) {
case '0':
if (length == 1) {
newBool = 0;
goto numericBoolean;
}
return TCL_ERROR;
case '1':
if (length == 1) {
newBool = 1;
goto numericBoolean;
}
return TCL_ERROR;
}
/*
* Force to lower case for case-insensitive detection. Filter out known
* invalid characters at the same time.
@@ -1953,12 +1672,6 @@ ParseBoolean(
objPtr->internalRep.longValue = newBool;
objPtr->typePtr = &tclBooleanType;
return TCL_OK;
numericBoolean:
TclFreeIntRep(objPtr);
objPtr->internalRep.longValue = newBool;
objPtr->typePtr = &tclIntType;
return TCL_OK;
}
/*
@@ -2275,32 +1988,7 @@ Tcl_GetIntFromObj(
return TCL_OK;
#endif
}
/*
*----------------------------------------------------------------------
*
* SetIntFromAny --
*
* Attempts to force the internal representation for a Tcl object to
* tclIntType, specifically.
*
* Results:
* The return value is a standard object Tcl result. If an error occurs
* during conversion, an error message is left in the interpreter's
* result unless "interp" is NULL.
*
*----------------------------------------------------------------------
*/
static int
SetIntFromAny(
Tcl_Interp *interp, /* Tcl interpreter */
Tcl_Obj *objPtr) /* Pointer to the object to convert */
{
long l;
return TclGetLongFromObj(interp, objPtr, &l);
}
/*
*----------------------------------------------------------------------
@@ -2892,33 +2580,6 @@ Tcl_GetWideIntFromObj(
TCL_PARSE_INTEGER_ONLY)==TCL_OK);
return TCL_ERROR;
}
#ifndef NO_WIDE_TYPE
/*
*----------------------------------------------------------------------
*
* SetWideIntFromAny --
*
* Attempts to force the internal representation for a Tcl object to
* tclWideIntType, specifically.
*
* Results:
* The return value is a standard object Tcl result. If an error occurs
* during conversion, an error message is left in the interpreter's
* result unless "interp" is NULL.
*
*----------------------------------------------------------------------
*/
static int
SetWideIntFromAny(
Tcl_Interp *interp, /* Tcl interpreter */
Tcl_Obj *objPtr) /* Pointer to the object to convert */
{
Tcl_WideInt w;
return Tcl_GetWideIntFromObj(interp, objPtr, &w);
}
#endif /* !NO_WIDE_TYPE */
/*
*----------------------------------------------------------------------
+1 -1
View File
@@ -40,7 +40,7 @@ static const Tcl_ObjType tclFsPathType = {
FreeFsPathInternalRep, /* freeIntRepProc */
DupFsPathInternalRep, /* dupIntRepProc */
UpdateStringOfFsPath, /* updateStringProc */
SetFsPathFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
/*
+6 -6
View File
@@ -61,7 +61,7 @@ static Tcl_NRPostProc Uplevel_Callback;
* The ProcBodyObjType type
*/
const Tcl_ObjType tclProcBodyType = {
static const Tcl_ObjType procBodyType = {
"procbody", /* name for this type */
ProcBodyFree, /* FreeInternalRep function */
ProcBodyDup, /* DupInternalRep function */
@@ -100,7 +100,7 @@ static const Tcl_ObjType lambdaType = {
FreeLambdaInternalRep, /* freeIntRepProc */
DupLambdaInternalRep, /* dupIntRepProc */
NULL, /* updateStringProc */
SetLambdaFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
/*
@@ -324,7 +324,7 @@ Tcl_ProcObjCmd(
* of all procs whose argument list is just _args_
*/
if (objv[3]->typePtr == &tclProcBodyType) {
if (objv[3]->typePtr == &procBodyType) {
goto done;
}
@@ -408,7 +408,7 @@ TclCreateProc(
Tcl_Obj *defPtr;
int precompiled = 0;
if (bodyPtr->typePtr == &tclProcBodyType) {
if (bodyPtr->typePtr == &procBodyType) {
/*
* Because the body is a TclProProcBody, the actual body is already
* compiled, and it is not shared with anyone else, so it's OK not to
@@ -2364,7 +2364,7 @@ TclNewProcBodyObj(
TclNewObj(objPtr);
if (objPtr) {
objPtr->typePtr = &tclProcBodyType;
objPtr->typePtr = &procBodyType;
objPtr->internalRep.twoPtrValue.ptr1 = procPtr;
procPtr->refCount++;
@@ -2397,7 +2397,7 @@ ProcBodyDup(
{
Proc *procPtr = srcPtr->internalRep.twoPtrValue.ptr1;
dupPtr->typePtr = &tclProcBodyType;
dupPtr->typePtr = &procBodyType;
dupPtr->internalRep.twoPtrValue.ptr1 = procPtr;
procPtr->refCount++;
}
+6 -38
View File
@@ -93,19 +93,18 @@ static void FreeRegexpInternalRep(Tcl_Obj *objPtr);
static int RegExpExecUniChar(Tcl_Interp *interp, Tcl_RegExp re,
const Tcl_UniChar *uniString, int numChars,
int nmatches, int flags);
static int SetRegexpFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr);
/*
* The regular expression Tcl object type. This serves as a cache of the
* compiled form of the regular expression.
*/
const Tcl_ObjType tclRegexpType = {
static const Tcl_ObjType regexpType = {
"regexp", /* name */
FreeRegexpInternalRep, /* freeIntRepProc */
DupRegexpInternalRep, /* dupIntRepProc */
NULL, /* updateStringProc */
SetRegexpFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
/*
@@ -575,12 +574,12 @@ Tcl_GetRegExpFromObj(
/*
* This is OK because we only actually interpret this value properly as a
* TclRegexp* when the type is tclRegexpType.
* TclRegexp* when the type is regexpType.
*/
regexpPtr = objPtr->internalRep.twoPtrValue.ptr1;
if ((objPtr->typePtr != &tclRegexpType) || (regexpPtr->flags != flags)) {
if ((objPtr->typePtr != &regexpType) || (regexpPtr->flags != flags)) {
pattern = TclGetStringFromObj(objPtr, &length);
regexpPtr = CompileRegexp(interp, pattern, length, flags);
@@ -602,7 +601,7 @@ Tcl_GetRegExpFromObj(
TclFreeIntRep(objPtr);
objPtr->internalRep.twoPtrValue.ptr1 = regexpPtr;
objPtr->typePtr = &tclRegexpType;
objPtr->typePtr = &regexpType;
}
return (Tcl_RegExp) regexpPtr;
}
@@ -787,38 +786,7 @@ DupRegexpInternalRep(
regexpPtr->refCount++;
copyPtr->internalRep.twoPtrValue.ptr1 = srcPtr->internalRep.twoPtrValue.ptr1;
copyPtr->typePtr = &tclRegexpType;
}
/*
*----------------------------------------------------------------------
*
* SetRegexpFromAny --
*
* Attempt to generate a compiled regular expression for the Tcl object
* "objPtr".
*
* Results:
* The return value is TCL_OK or TCL_ERROR. If an error occurs during
* conversion, an error message is left in the interpreter's result
* unless "interp" is NULL.
*
* Side effects:
* If no error occurs, a regular expression is stored as "objPtr"s
* internal representation.
*
*----------------------------------------------------------------------
*/
static int
SetRegexpFromAny(
Tcl_Interp *interp, /* Used for error reporting if not NULL. */
Tcl_Obj *objPtr) /* The object to convert. */
{
if (Tcl_GetRegExpFromObj(interp, objPtr, REG_ADVANCED) == NULL) {
return TCL_ERROR;
}
return TCL_OK;
copyPtr->typePtr = &regexpType;
}
/*
+1 -1
View File
@@ -87,7 +87,7 @@ const Tcl_ObjType tclStringType = {
FreeStringInternalRep, /* freeIntRepPro */
DupStringInternalRep, /* dupIntRepProc */
UpdateStringOfString, /* updateStringProc */
SetStringFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
/*
+5 -4
View File
@@ -222,7 +222,7 @@ static const TclIntStubs tclIntStubs = {
TclGetExtension, /* 31 */
TclGetFrame, /* 32 */
0, /* 33 */
TclGetIntForIndex, /* 34 */
0, /* 34 */
0, /* 35 */
0, /* 36 */
TclGetLoadedPackages, /* 37 */
@@ -666,11 +666,11 @@ const TclStubs tclStubs = {
Tcl_SetTimer, /* 11 */
Tcl_Sleep, /* 12 */
Tcl_WaitForEvent, /* 13 */
Tcl_AppendAllObjTypes, /* 14 */
0, /* 14 */
Tcl_AppendStringsToObj, /* 15 */
Tcl_AppendToObj, /* 16 */
Tcl_ConcatObj, /* 17 */
Tcl_ConvertToType, /* 18 */
0, /* 18 */
Tcl_DbDecrRefCount, /* 19 */
Tcl_DbIncrRefCount, /* 20 */
Tcl_DbIsShared, /* 21 */
@@ -871,7 +871,7 @@ const TclStubs tclStubs = {
Tcl_RecordAndEval, /* 208 */
Tcl_RecordAndEvalObj, /* 209 */
Tcl_RegisterChannel, /* 210 */
Tcl_RegisterObjType, /* 211 */
0, /* 211 */
Tcl_RegExpCompile, /* 212 */
Tcl_RegExpExec, /* 213 */
Tcl_RegExpMatch, /* 214 */
@@ -1291,6 +1291,7 @@ const TclStubs tclStubs = {
Tcl_FindSymbol, /* 628 */
Tcl_FSUnloadFile, /* 629 */
Tcl_ZlibStreamSetCompressionDictionary, /* 630 */
Tcl_GetIntForIndex, /* 631 */
};
/* !END!: Do not edit above this line. */
+3 -1
View File
@@ -1684,7 +1684,9 @@ TestdoubledigitsObjCmd(ClientData unused,
}
status = Tcl_GetDoubleFromObj(interp, objv[1], &d);
if (status != TCL_OK) {
doubleType = Tcl_GetObjType("double");
Tcl_Obj *doubleObj = Tcl_NewDoubleObj(0.0);
doubleType = doubleObj->typePtr;
Tcl_DecrRefCount(doubleObj);
if (objv[1]->typePtr == doubleType
|| TclIsNaN(objv[1]->internalRep.doubleValue)) {
status = TCL_OK;
+30 -20
View File
@@ -936,7 +936,6 @@ TestobjCmd(
{
int varIndex, destIndex, i;
const char *index, *subCmd, *string;
const Tcl_ObjType *targetType;
Tcl_Obj **varPtr;
if (objc < 2) {
@@ -989,13 +988,34 @@ TestobjCmd(
return TCL_ERROR;
}
typeName = Tcl_GetString(objv[3]);
if ((targetType = Tcl_GetObjType(typeName)) == NULL) {
if (!strcmp(typeName, "bytearray")) {
int len;
(void)Tcl_GetByteArrayFromObj(varPtr[varIndex], &len);
} else if (!strcmp(typeName, "double")) {
double d;
if (Tcl_GetDoubleFromObj(interp, varPtr[varIndex], &d) != TCL_OK) {
return TCL_ERROR;
}
} else if (!strcmp(typeName, "lindex")) {
int index;
if (Tcl_GetIntForIndex(interp, varPtr[varIndex], 0, &index) != TCL_OK) {
return TCL_ERROR;
}
} else if (!strcmp(typeName, "list")) {
int objc;
Tcl_Obj **objv;
if (Tcl_ListObjGetElements(interp, varPtr[varIndex], &objc, &objv) != TCL_OK) {
return TCL_ERROR;
}
} else if (!strcmp(typeName, "string")) {
if (Tcl_GetUnicodeFromObj(varPtr[varIndex], NULL) != TCL_OK) {
return TCL_ERROR;
}
} else {
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
"no type ", typeName, " found", NULL);
return TCL_ERROR;
}
if (Tcl_ConvertToType(interp, varPtr[varIndex], targetType)
!= TCL_OK) {
"bad typename \"", typeName,
"\": must be bytearray, double, index, list, "
"or string", NULL);
return TCL_ERROR;
}
Tcl_SetObjResult(interp, varPtr[varIndex]);
@@ -1095,19 +1115,11 @@ TestobjCmd(
Tcl_AppendToObj(Tcl_GetObjResult(interp),
varPtr[varIndex]->typePtr->name, -1);
}
} else if (strcmp(subCmd, "types") == 0) {
if (objc != 2) {
goto wrongNumArgs;
}
if (Tcl_AppendAllObjTypes(interp,
Tcl_GetObjResult(interp)) != TCL_OK) {
return TCL_ERROR;
}
} else {
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp),
"bad option \"", Tcl_GetString(objv[1]),
"\": must be assign, convert, duplicate, freeallvars, "
"newobj, objcount, objtype, refcount, type, or types", NULL);
"newobj, objcount, objtype, refcount, or type", NULL);
return TCL_ERROR;
}
return TCL_OK;
@@ -1249,8 +1261,7 @@ TeststringobjCmd(
goto wrongNumArgs;
}
if (varPtr[varIndex] != NULL) {
Tcl_ConvertToType(NULL, varPtr[varIndex],
Tcl_GetObjType("string"));
(void)Tcl_GetUnicodeFromObj(varPtr[varIndex], &i);
strPtr = varPtr[varIndex]->internalRep.twoPtrValue.ptr1;
length = (int) strPtr->allocated;
} else {
@@ -1303,8 +1314,7 @@ TeststringobjCmd(
goto wrongNumArgs;
}
if (varPtr[varIndex] != NULL) {
Tcl_ConvertToType(NULL, varPtr[varIndex],
Tcl_GetObjType("string"));
(void)Tcl_GetUnicodeFromObj(varPtr[varIndex], &i);
strPtr = varPtr[varIndex]->internalRep.twoPtrValue.ptr1;
length = strPtr->maxChars;
} else {
+64 -48
View File
@@ -107,23 +107,22 @@ static void ClearHash(Tcl_HashTable *tablePtr);
static void FreeProcessGlobalValue(ClientData clientData);
static void FreeThreadHash(ClientData clientData);
static Tcl_HashTable * GetThreadHash(Tcl_ThreadDataKey *keyPtr);
static int SetEndOffsetFromAny(Tcl_Interp *interp,
Tcl_Obj *objPtr);
static void UpdateStringOfEndOffset(Tcl_Obj *objPtr);
static int SetIndexFromAny(Tcl_Obj *objPtr);
static void UpdateStringOfIndex(Tcl_Obj *objPtr);
/*
* The following is the Tcl object type definition for an object that
* represents a list index in the form, "end-offset". It is used as a
* performance optimization in TclGetIntForIndex. The internal rep is an
* integer, so no memory management is required for it.
* represents a list index in the form, "offset[+-]offset" or "end-offset".
* It is used as a performance optimization in TclGetIntForIndex. The
* internal rep is an integer, so no memory management is required for it.
*/
const Tcl_ObjType tclEndOffsetType = {
"end-offset", /* name */
static const Tcl_ObjType indexType = {
"lindex", /* name */
NULL, /* freeIntRepProc */
NULL, /* dupIntRepProc */
UpdateStringOfEndOffset, /* updateStringProc */
SetEndOffsetFromAny
UpdateStringOfIndex, /* updateStringProc */
NULL
};
/*
@@ -3330,7 +3329,7 @@ TclFormatInt(
/*
*----------------------------------------------------------------------
*
* TclGetIntForIndex --
* Tcl_GetIntForIndex --
*
* This function returns an integer corresponding to the list index held
* in a Tcl object. The Tcl object's value is expected to be in the
@@ -3352,7 +3351,7 @@ TclFormatInt(
*/
int
TclGetIntForIndex(
Tcl_GetIntForIndex(
Tcl_Interp *interp, /* Interpreter to use for error reporting. If
* NULL, then no error message is left after
* errors. */
@@ -3371,13 +3370,17 @@ TclGetIntForIndex(
return TCL_OK;
}
if (SetEndOffsetFromAny(NULL, objPtr) == TCL_OK) {
if (SetIndexFromAny(objPtr) == TCL_OK) {
/*
* If the object is already an offset from the end of the list, or can
* be converted to one, use it.
*/
*indexPtr = endValue + objPtr->internalRep.longValue;
if (objPtr->internalRep.longValue > -2) {
*indexPtr = objPtr->internalRep.longValue;
} else {
*indexPtr = endValue + objPtr->internalRep.longValue + 3;
}
return TCL_OK;
}
@@ -3417,6 +3420,19 @@ TclGetIntForIndex(
} else {
*indexPtr = first - second;
}
/*
* The conversion succeeded. Free the old internal rep and set the new
* one.
*/
TclFreeIntRep(objPtr);
if (*indexPtr > -1) {
objPtr->internalRep.longValue = *indexPtr;
} else {
objPtr->internalRep.longValue = -1;
}
objPtr->typePtr = &indexType;
return TCL_OK;
}
@@ -3442,10 +3458,10 @@ TclGetIntForIndex(
/*
*----------------------------------------------------------------------
*
* UpdateStringOfEndOffset --
* UpdateStringOfIndex --
*
* Update the string rep of a Tcl object holding an "end-offset"
* expression.
* Update the string rep of a Tcl object holding an "offset[+-]offset" or
* "end-offset" expression.
*
* Results:
* None.
@@ -3460,17 +3476,25 @@ TclGetIntForIndex(
*/
static void
UpdateStringOfEndOffset(
UpdateStringOfIndex(
register Tcl_Obj *objPtr)
{
char buffer[TCL_INTEGER_SPACE + 5];
register int len;
memcpy(buffer, "end", 4);
len = sizeof("end") - 1;
if (objPtr->internalRep.longValue != 0) {
buffer[len++] = '-';
len += TclFormatInt(buffer+len, -(objPtr->internalRep.longValue));
if (objPtr->internalRep.longValue < -1) {
memcpy(buffer, "end", 4);
len = sizeof("end") - 1;
if (objPtr->internalRep.longValue == -2) {
buffer[len++] = '+';
buffer[len++] = '1';
buffer[len] = 0;
} else if (objPtr->internalRep.longValue != -3) {
buffer[len++] = '-';
len += TclFormatInt(buffer+len, (long)-(objPtr->internalRep.longValue+3));
}
} else {
len = TclFormatInt(buffer, objPtr->internalRep.longValue);
}
objPtr->bytes = ckalloc((unsigned) len+1);
memcpy(objPtr->bytes, buffer, (unsigned) len+1);
@@ -3480,10 +3504,14 @@ UpdateStringOfEndOffset(
/*
*----------------------------------------------------------------------
*
* SetEndOffsetFromAny --
* SetIndexFromAny --
*
* Look for a string of the form "end[+-]offset" and convert it to an
* internal representation holding the offset.
* Look for a string of the form "offset[+-]offset" or "end[+-]offset"
* and convert it to an internal representation holding the offset.
* If the resulting offset is < "-1" or > "end+1", the index is still
* considered valid but it points to a list element which is not
* valid. The value stored in internalRep.longValue will be -1.
* For values <= "end+1", internalRep.longValue will be set to offset-3.
*
* Results:
* Returns TCL_OK if ok, TCL_ERROR if the string was badly formed.
@@ -3496,8 +3524,7 @@ UpdateStringOfEndOffset(
*/
static int
SetEndOffsetFromAny(
Tcl_Interp *interp, /* Tcl interpreter or NULL */
SetIndexFromAny(
Tcl_Obj *objPtr) /* Pointer to the object to parse */
{
int offset; /* Offset in the "end-offset" expression */
@@ -3508,7 +3535,7 @@ SetEndOffsetFromAny(
* If it's already the right type, we're fine.
*/
if (objPtr->typePtr == &tclEndOffsetType) {
if (objPtr->typePtr == &indexType) {
return TCL_OK;
}
@@ -3519,11 +3546,6 @@ SetEndOffsetFromAny(
bytes = TclGetStringFromObj(objPtr, &length);
if ((*bytes != 'e') || (strncmp(bytes, "end",
(size_t)((length > 3) ? 3 : length)) != 0)) {
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"bad index \"%s\": must be end?[+-]integer?", bytes));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX", NULL);
}
return TCL_ERROR;
}
@@ -3540,25 +3562,15 @@ SetEndOffsetFromAny(
*/
if (TclIsSpaceProc(bytes[4])) {
goto badIndexFormat;
return TCL_ERROR;
}
if (Tcl_GetInt(interp, bytes+4, &offset) != TCL_OK) {
if (Tcl_GetInt(NULL, bytes+4, &offset) != TCL_OK) {
return TCL_ERROR;
}
if (bytes[3] == '-') {
offset = -offset;
}
} else {
/*
* Conversion failed. Report the error.
*/
badIndexFormat:
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"bad index \"%s\": must be end?[+-]integer?", bytes));
Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX", NULL);
}
return TCL_ERROR;
}
@@ -3568,8 +3580,12 @@ SetEndOffsetFromAny(
*/
TclFreeIntRep(objPtr);
objPtr->internalRep.longValue = offset;
objPtr->typePtr = &tclEndOffsetType;
if (offset < 2) {
objPtr->internalRep.longValue = offset - 3;
} else {
objPtr->internalRep.longValue = -1;
}
objPtr->typePtr = &indexType;
return TCL_OK;
}
+8 -21
View File
@@ -184,9 +184,6 @@ static Tcl_FreeInternalRepProc FreeParsedVarName;
static Tcl_DupInternalRepProc DupParsedVarName;
static Tcl_UpdateStringProc UpdateParsedVarName;
static Tcl_UpdateStringProc PanicOnUpdateVarName;
static Tcl_SetFromAnyProc PanicOnSetVarName;
/*
* Types of Tcl_Objs used to cache variable lookups.
*
@@ -208,7 +205,7 @@ static Tcl_SetFromAnyProc PanicOnSetVarName;
static const Tcl_ObjType localVarNameType = {
"localVarName",
FreeLocalVarName, DupLocalVarName, PanicOnUpdateVarName, PanicOnSetVarName
FreeLocalVarName, DupLocalVarName, PanicOnUpdateVarName, NULL
};
/*
@@ -226,13 +223,13 @@ static Tcl_DupInternalRepProc DupNsVarName;
static const Tcl_ObjType tclNsVarNameType = {
"namespaceVarName",
FreeNsVarName, DupNsVarName, PanicOnUpdateVarName, PanicOnSetVarName
FreeNsVarName, DupNsVarName, PanicOnUpdateVarName, NULL
};
#endif
static const Tcl_ObjType tclParsedVarNameType = {
"parsedVarName",
FreeParsedVarName, DupParsedVarName, UpdateParsedVarName, PanicOnSetVarName
FreeParsedVarName, DupParsedVarName, UpdateParsedVarName, NULL
};
/*
@@ -247,9 +244,9 @@ static const Tcl_ObjType tclParsedVarNameType = {
* as this can be safely copied.
*/
const Tcl_ObjType tclArraySearchType = {
static const Tcl_ObjType arraySearchType = {
"array search",
NULL, NULL, NULL, SetArraySearchObj
NULL, NULL, NULL, NULL
};
Var *
@@ -5019,7 +5016,7 @@ Tcl_UpvarObjCmd(
*
* Side effects:
* Updates the internal type and representation of the object to make
* this an array-search object. See the tclArraySearchType declaration
* this an array-search object. See the arraySearchType declaration
* above for details of the internal representation.
*
*----------------------------------------------------------------------
@@ -5062,7 +5059,7 @@ SetArraySearchObj(
offset = end - string;
TclFreeIntRep(objPtr);
objPtr->typePtr = &tclArraySearchType;
objPtr->typePtr = &arraySearchType;
objPtr->internalRep.twoPtrValue.ptr1 = INT2PTR(id);
objPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(offset);
return TCL_OK;
@@ -5116,7 +5113,7 @@ ParseSearchId(
* Parse the id.
*/
if ((handleObj->typePtr != &tclArraySearchType)
if ((handleObj->typePtr != &arraySearchType)
&& (SetArraySearchObj(interp, handleObj) != TCL_OK)) {
return NULL;
}
@@ -5569,16 +5566,6 @@ PanicOnUpdateVarName(
objPtr->typePtr->name);
}
static int
PanicOnSetVarName(
Tcl_Interp *interp,
Tcl_Obj *objPtr)
{
Tcl_Panic("%s of type %s should not be called", "setFromAnyProc",
objPtr->typePtr->name);
return TCL_ERROR;
}
/*
* localVarName -
*
+1 -1
View File
@@ -88,7 +88,7 @@ static const Tcl_ObjType tclOSTypeType = {
NULL, /* freeIntRepProc */
NULL, /* dupIntRepProc */
UpdateStringOfOSType, /* updateStringProc */
SetOSTypeFromAny /* setFromAnyProc */
NULL /* setFromAnyProc */
};
enum {
+16 -37
View File
@@ -23,27 +23,6 @@ testConstraint testobj [llength [info commands testobj]]
testConstraint longIs32bit [expr {int(0x80000000) < 0}]
testConstraint wideBiggerThanInt [expr {wide(0x80000000) != int(0x80000000)}]
test obj-1.1 {Tcl_AppendAllObjTypes, and InitTypeTable, Tcl_RegisterObjType} testobj {
set r 1
foreach {t} {
{array search}
bytearray
bytecode
cmdName
dict
end-offset
regexp
string
} {
set first [string first $t [testobj types]]
set r [expr {$r && ($first != -1)}]
}
set result $r
} {1}
test obj-2.1 {Tcl_GetObjType error} testobj {
list [testintobj set 1 0] [catch {testobj convert 1 foo} msg] $msg
} {0 1 {no type foo found}}
test obj-2.2 {Tcl_GetObjType and Tcl_ConvertToType} testobj {
set result ""
lappend result [testobj freeallvars]
@@ -55,12 +34,12 @@ test obj-2.2 {Tcl_GetObjType and Tcl_ConvertToType} testobj {
test obj-3.1 {Tcl_ConvertToType error} testobj {
list [testdoubleobj set 1 12.34] \
[catch {testobj convert 1 end-offset} msg] \
[catch {testobj convert 1 lindex} msg] \
$msg
} {12.34 1 {bad index "12.34": must be end?[+-]integer?}}
} {12.34 1 {bad index "12.34": must be integer?[+-]integer? or end?[+-]integer?}}
test obj-3.2 {Tcl_ConvertToType error, "empty string" object} testobj {
list [testobj newobj 1] [catch {testobj convert 1 end-offset} msg] $msg
} {{} 1 {bad index "": must be end?[+-]integer?}}
list [testobj newobj 1] [catch {testobj convert 1 lindex} msg] $msg
} {{} 1 {bad index "": must be integer?[+-]integer? or end?[+-]integer?}}
test obj-4.1 {Tcl_NewObj and AllocateFreeObjects} testobj {
set result ""
@@ -555,39 +534,39 @@ test obj-30.1 {Ref counting and object deletion, simple types} testobj {
test obj-31.1 {regenerate string rep of "end"} testobj {
testobj freeallvars
teststringobj set 1 end
testobj convert 1 end-offset
testobj convert 1 lindex
testobj invalidateStringRep 1
} end
test obj-31.2 {regenerate string rep of "end-1"} testobj {
testobj freeallvars
teststringobj set 1 end-0x1
testobj convert 1 end-offset
testobj convert 1 lindex
testobj invalidateStringRep 1
} end-1
test obj-31.3 {regenerate string rep of "end--1"} testobj {
testobj freeallvars
teststringobj set 1 end--0x1
testobj convert 1 end-offset
testobj convert 1 lindex
testobj invalidateStringRep 1
} end--1
} end+1
test obj-31.4 {regenerate string rep of "end-bigInteger"} testobj {
testobj freeallvars
teststringobj set 1 end-0x7fffffff
testobj convert 1 end-offset
teststringobj set 1 end-0x7ffffffd
testobj convert 1 lindex
testobj invalidateStringRep 1
} end-2147483647
} end-2147483645
test obj-31.5 {regenerate string rep of "end--bigInteger"} testobj {
testobj freeallvars
teststringobj set 1 end--0x7fffffff
testobj convert 1 end-offset
testobj convert 1 lindex
testobj invalidateStringRep 1
} end--2147483647
} -1
test obj-31.6 {regenerate string rep of "end--bigInteger"} {testobj longIs32bit} {
testobj freeallvars
teststringobj set 1 end--0x80000000
testobj convert 1 end-offset
teststringobj set 1 end--0x7fffffff
testobj convert 1 lindex
testobj invalidateStringRep 1
} end--2147483648
} -1
test obj-32.1 {freeing very large object trees} {
set x {}
+1 -1
View File
@@ -88,7 +88,7 @@ test opt-7.1 {OptCheckType} {
[::tcl::OptCheckType {a b c} list] \
[::tcl::OptCheckType maYbe choice {yes maYbe no}] \
[catch {::tcl::OptCheckType "-blah" string}] \
[catch {::tcl::OptCheckType 6 boolean}] \
[::tcl::OptCheckType 6 boolean] \
[catch {::tcl::OptCheckType x float}] \
[catch {::tcl::OptCheckType "a \{ c" list}] \
[catch {::tcl::OptCheckType 2.3 int}] \
+2 -2
View File
@@ -531,7 +531,7 @@ test string-6.72 {string is true, false} {
} {0 0}
test string-6.73 {string is true, false} {
catch {unset var}
list [string is true -fail var 25] $var
list [string is true -fail var 25x] $var
} {0 0}
test string-6.74 {string is true, false} {
catch {unset var}
@@ -1603,7 +1603,7 @@ test string-23.0 {string is boolean, Bug 1187123} testindexobj {
set x 5
catch {testindexobj $x foo bar soom}
string is boolean $x
} 0
} 1
test string-23.1 {string is command with empty string} {
set s ""
list \
+1 -7
View File
@@ -23,12 +23,6 @@ catch [list package require -exact Tcltest [info patchlevel]]
testConstraint testobj [llength [info commands testobj]]
testConstraint testdstring [llength [info commands testdstring]]
test stringObj-1.1 {string type registration} testobj {
set t [testobj types]
set first [string first "string" $t]
set result [expr {$first != -1}]
} {1}
test stringObj-2.1 {Tcl_NewStringObj} testobj {
set result ""
lappend result [testobj freeallvars]
@@ -203,7 +197,7 @@ test stringObj-8.1 {DupStringInternalRep procedure} testobj {
[teststringobj maxchars 1] [teststringobj get 1] \
[teststringobj length 2] [teststringobj length2 2] \
[teststringobj maxchars 2] [teststringobj get 2]
} {5 10 0 abcde 5 5 0 abcde}
} {5 10 5 abcde 5 5 5 abcde}
test stringObj-8.2 {DupUnicodeInternalRep, mixed width chars} testobj {
set x abc\u00ef\u00bf\u00aeghi
string length $x