diff options
-rw-r--r-- | doc/GetIndex.3 | 8 | ||||
-rw-r--r-- | generic/tclIndexObj.c | 31 |
2 files changed, 22 insertions, 17 deletions
diff --git a/doc/GetIndex.3 b/doc/GetIndex.3 index 8591c56..111ae62 100644 --- a/doc/GetIndex.3 +++ b/doc/GetIndex.3 @@ -56,8 +56,8 @@ OR-ed combination of bits providing additional information for operation. The only bits that are currently defined are \fBTCL_EXACT\fR and \fBTCL_INDEX_TEMP_TABLE\fR. .AP int *indexPtr out -The index of the string in \fItablePtr\fR that matches the value of -\fIobjPtr\fR is returned here. +If not NULL, the index of the string in \fItablePtr\fR that matches +the value of \fIobjPtr\fR is returned here. .BE .SH DESCRIPTION .PP @@ -70,8 +70,8 @@ the strings in \fItablePtr\fR to find a match. A match occurs if \fItablePtr\fR, or if it is a non-empty unique abbreviation for exactly one of the strings in \fItablePtr\fR and the \fBTCL_EXACT\fR flag was not specified; in either case -the index of the matching entry is stored at \fI*indexPtr\fR -and \fBTCL_OK\fR is returned. +\fBTCL_OK\fR is returned. If \fI*indexPtr\fR is not NULL the index +of the matching entry is stored there. .PP If there is no matching entry, \fBTCL_ERROR\fR is returned and an error message is left in \fIinterp\fR's diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c index 89582b7..c3092c9 100644 --- a/generic/tclIndexObj.c +++ b/generic/tclIndexObj.c @@ -166,11 +166,12 @@ GetIndexFromObjList( * Results: * If the value of objPtr is identical to or a unique abbreviation for * one of the entries in tablePtr, then the return value is TCL_OK and - * the index of the matching entry is stored at *indexPtr. If there isn't - * a proper match, then TCL_ERROR is returned and an error message is - * left in interp's result (unless interp is NULL). The msg argument is - * used in the error message; for example, if msg has the value "option" - * then the error message will say something like 'bad option "foo": must + * the index of the matching entry is stored at *indexPtr + * (unless indexPtr is NULL). If there isn't a proper match, then + * TCL_ERROR is returned and an error message is left in interp's + * result (unless interp is NULL). The msg argument is used in the + * error message; for example, if msg has the value "option" then + * the error message will say something like 'bad option "foo": must * be ...' * * Side effects: @@ -212,15 +213,17 @@ Tcl_GetIndexFromObjStruct( */ if (!(flags & TCL_INDEX_TEMP_TABLE)) { - irPtr = TclFetchIntRep(objPtr, &indexType); - if (irPtr) { - indexRep = (IndexRep *)irPtr->twoPtrValue.ptr1; - if (indexRep->tablePtr==tablePtr && indexRep->offset==offset) { - *indexPtr = indexRep->index; - return TCL_OK; + irPtr = TclFetchIntRep (objPtr, &indexType); + if (irPtr) { + indexRep = (IndexRep *) irPtr->twoPtrValue.ptr1; + if (indexRep->tablePtr == tablePtr && indexRep->offset == offset) { + if (indexPtr != NULL) { + *indexPtr = indexRep->index; + } + return TCL_OK; + } } } - } /* * Lookup the value of the object in the table. Accept unique @@ -291,7 +294,9 @@ Tcl_GetIndexFromObjStruct( indexRep->index = index; } - *indexPtr = index; + if(indexPtr != NULL) { + *indexPtr = index; + } return TCL_OK; error: |