diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-02-17 11:21:56 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-02-17 11:21:56 (GMT) |
| commit | 36024b4c2dfa88a5b42c42342e1630cb846b59f0 (patch) | |
| tree | d47999a8c08e11fc113066b725060f5e9b8182b7 /generic/tclIndexObj.c | |
| parent | e49055022daf853edd8df42e1f9a6772f4e37422 (diff) | |
| parent | aa93fba41a6764dce6c1f918388efd0f46136ada (diff) | |
| download | tcl-36024b4c2dfa88a5b42c42342e1630cb846b59f0.zip tcl-36024b4c2dfa88a5b42c42342e1630cb846b59f0.tar.gz tcl-36024b4c2dfa88a5b42c42342e1630cb846b59f0.tar.bz2 | |
Merge 8.7
Diffstat (limited to 'generic/tclIndexObj.c')
| -rw-r--r-- | generic/tclIndexObj.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/generic/tclIndexObj.c b/generic/tclIndexObj.c index 4c3e53d..d7c3ab7 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: @@ -180,6 +181,7 @@ GetIndexFromObjList( *---------------------------------------------------------------------- */ +#undef Tcl_GetIndexFromObjStruct int Tcl_GetIndexFromObjStruct( Tcl_Interp *interp, /* Used for error reporting if not NULL. */ @@ -192,8 +194,8 @@ Tcl_GetIndexFromObjStruct( size_t offset, /* The number of bytes between entries */ const char *msg, /* Identifying word to use in error * messages. */ - int flags, /* 0, TCL_EXACT or TCL_INDEX_TEMP_TABLE */ - int *indexPtr) /* Place to store resulting integer index. */ + int flags, /* 0, TCL_EXACT, TCL_INDEX_TEMP_TABLE or TCL_INDEX_NULL_OK */ + void *indexPtr) /* Place to store resulting index. */ { size_t index, idx, numAbbrev; const char *key, *p1; @@ -218,8 +220,8 @@ Tcl_GetIndexFromObjStruct( if ((indexRep->tablePtr == tablePtr) && (indexRep->offset == offset) && (indexRep->index != TCL_INDEX_NONE)) { - *indexPtr = (int)indexRep->index; - return TCL_OK; + index = indexRep->index; + goto uncachedDone; } } } @@ -233,6 +235,9 @@ Tcl_GetIndexFromObjStruct( index = TCL_INDEX_NONE; numAbbrev = 0; + if (!*key && (flags & TCL_INDEX_NULL_OK)) { + goto uncachedDone; + } /* * Scan the table looking for one of: * - An exact match (always preferred) @@ -293,7 +298,25 @@ Tcl_GetIndexFromObjStruct( indexRep->index = index; } - *indexPtr = (int)index; + uncachedDone: + if (indexPtr != NULL) { + if ((flags>>8) & (int)~sizeof(int)) { + if ((flags>>8) == sizeof(uint64_t)) { + *(uint64_t *)indexPtr = index; + return TCL_OK; + } else if ((flags>>8) == sizeof(uint32_t)) { + *(uint32_t *)indexPtr = index; + return TCL_OK; + } else if ((flags>>8) == sizeof(uint16_t)) { + *(uint16_t *)indexPtr = index; + return TCL_OK; + } else if ((flags>>8) == sizeof(uint8_t)) { + *(uint8_t *)indexPtr = index; + return TCL_OK; + } + } + *(int *)indexPtr = index; + } return TCL_OK; error: @@ -319,7 +342,7 @@ Tcl_GetIndexFromObjStruct( *entryPtr, NULL); entryPtr = NEXT_ENTRY(entryPtr, offset); while (*entryPtr != NULL) { - if (*NEXT_ENTRY(entryPtr, offset) == NULL) { + if ((*NEXT_ENTRY(entryPtr, offset) == NULL) && !(flags & TCL_INDEX_NULL_OK)) { Tcl_AppendStringsToObj(resultPtr, (count > 0 ? "," : ""), " or ", *entryPtr, NULL); } else if (**entryPtr) { @@ -328,6 +351,9 @@ Tcl_GetIndexFromObjStruct( } entryPtr = NEXT_ENTRY(entryPtr, offset); } + if ((flags & TCL_INDEX_NULL_OK)) { + Tcl_AppendStringsToObj(resultPtr, ", or \"\"", NULL); + } } Tcl_SetObjResult(interp, resultPtr); Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", msg, key, NULL); |
