diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2001-10-22 09:03:32 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2001-10-22 09:03:32 (GMT) |
commit | 2cc536f771bc9224f8ba83e7789545c9acded91c (patch) | |
tree | 198a48a7f0646f0c50a26eb12335ccf684192978 | |
parent | 04cdbc786a4b538ab85f11d9748b2c3adec5d0f8 (diff) | |
download | tcl-2cc536f771bc9224f8ba83e7789545c9acded91c.zip tcl-2cc536f771bc9224f8ba83e7789545c9acded91c.tar.gz tcl-2cc536f771bc9224f8ba83e7789545c9acded91c.tar.bz2 |
Fixed assumptions in testing code relating to internal representation of
index objects and added note to remind people to keep the code in sync.
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | generic/tclIndexObj.c | 4 | ||||
-rw-r--r-- | generic/tclTestObj.c | 29 |
3 files changed, 29 insertions, 9 deletions
@@ -1,3 +1,8 @@ +2001-10-22 Donal K. Fellows <fellowsd@cs.man.ac.uk> + + * generic/tclTestObj.c (TestindexobjCmd): Fixed assumptions + relating to internal representation of index objects. + 2001-10-19 Donal K. Fellows <fellowsd@cs.man.ac.uk> * doc/GetIndex.3: Added note that table of strings must be ASCII diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c index bc43c7e..873a2dc 100644 --- a/generic/tclIndexObj.c +++ b/generic/tclIndexObj.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclIndexObj.c,v 1.10.6.4 2001/10/19 16:50:47 dgp Exp $ + * RCS: @(#) $Id: tclIndexObj.c,v 1.10.6.5 2001/10/22 09:03:32 dkf Exp $ */ #include "tclInt.h" @@ -43,6 +43,8 @@ Tcl_ObjType tclIndexType = { * The definition of the internal representation of the "index" * object; The internalRep.otherValuePtr field of an object of "index" * type will be a pointer to one of these structures. + * + * Keep this structure declaration in sync with tclTestObj.c */ typedef struct { diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index 8232175..0b8ea26 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclTestObj.c,v 1.7 2000/11/24 11:27:37 dkf Exp $ + * RCS: @(#) $Id: tclTestObj.c,v 1.7.12.1 2001/10/22 09:03:33 dkf Exp $ */ #include "tclInt.h" @@ -406,6 +406,15 @@ TestindexobjCmd(clientData, interp, objc, objv) int allowAbbrev, index, index2, setError, i, result; char **argv; static char *tablePtr[] = {"a", "b", "check", (char *) NULL}; + /* + * Keep this structure declaration in sync with tclIndexObj.c + */ + struct IndexRep { + VOID *tablePtr; /* Pointer to the table of strings */ + int offset; /* Offset between table entries */ + int index; /* Selected index into table. */ + }; + struct IndexRep *indexRep; if ((objc == 3) && (strcmp(Tcl_GetString(objv[1]), "check") == 0)) { @@ -415,13 +424,14 @@ TestindexobjCmd(clientData, interp, objc, objv) * returned on subsequent lookups. */ - Tcl_GetIndexFromObj((Tcl_Interp *) NULL, objv[1], tablePtr, - "token", 0, &index); if (Tcl_GetIntFromObj(interp, objv[2], &index2) != TCL_OK) { return TCL_ERROR; } - objv[1]->internalRep.twoPtrValue.ptr2 = - (VOID *) (index2 * sizeof(char *)); + + Tcl_GetIndexFromObj((Tcl_Interp *) NULL, objv[1], tablePtr, + "token", 0, &index); + indexRep = (struct IndexRep *) objv[1]->internalRep.otherValuePtr; + indexRep->index = index2; result = Tcl_GetIndexFromObj((Tcl_Interp *) NULL, objv[1], tablePtr, "token", 0, &index); if (result == TCL_OK) { @@ -455,9 +465,12 @@ TestindexobjCmd(clientData, interp, objc, objv) * the index object, clear out the object's cached state. */ - if ((objv[3]->typePtr == Tcl_GetObjType("index")) - && (objv[3]->internalRep.twoPtrValue.ptr1 == (VOID *) argv)) { - objv[3]->typePtr = NULL; + if (objv[3]->typePtr == &tclIndexType) { + indexRep = (struct IndexRep *) objv[3]->internalRep.otherValuePtr; + if (indexRep->tablePtr == (VOID *) argv) { + objv[3]->typePtr->freeIntRepProc(objv[3]); + objv[3]->typePtr = NULL; + } } result = Tcl_GetIndexFromObj((setError? interp : NULL), objv[3], |