summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/GetIndex.311
-rw-r--r--generic/tclIndexObj.c41
2 files changed, 28 insertions, 24 deletions
diff --git a/doc/GetIndex.3 b/doc/GetIndex.3
index fa8455a..1169c6c 100644
--- a/doc/GetIndex.3
+++ b/doc/GetIndex.3
@@ -56,9 +56,10 @@ OR-ed combination of bits providing additional information for
operation. The only bits that are currently defined are \fBTCL_EXACT\fR
, \fBTCL_INDEX_TEMP_TABLE\fR, and \fBTCL_INDEX_NULL_OK\fR.
.AP enum|char|short|int|long *indexPtr out
-The index of the string in \fItablePtr\fR that matches the value of
-\fIobjPtr\fR is returned here. The variable can be any integer type,
-signed or unsigned, char, short, long or long long. It can also be an enum.
+If not (int *)NULL, the index of the string in \fItablePtr\fR that
+matches the value of \fIobjPtr\fR is returned here. The variable can
+be any integer type, signed or unsigned, char, short, long or
+long long. It can also be an enum.
.BE
.SH DESCRIPTION
.PP
@@ -71,8 +72,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 \fIindexPtr\fR is not NULL the index
+of the matching entry is stored at \fI*indexPtr\fR.
.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 cb376f3..cd15345 100644
--- a/generic/tclIndexObj.c
+++ b/generic/tclIndexObj.c
@@ -235,11 +235,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:
@@ -367,22 +368,24 @@ Tcl_GetIndexFromObjStruct(
}
uncachedDone:
- 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;
+ 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;
}
- *(int *)indexPtr = index;
return TCL_OK;
error: