Overview
| Artifact ID: | 8a81e0eba7e9446268b9b50aff9ced0a3d831e2a |
|---|---|
| Ticket: | 520304ffffffffffffffffffffffffffffffffff
Tcl_GetIndexFromObjStruct signature |
| User & Date: | jenglish on 2002-02-21 03:02:46 |
Changes
- icomment:
Logged In: YES user_id=68433 Hm, I'm having a hard time locating instances of Tcl_GetIndexFromObjStruct in the wild. As an example, here's a modified version of the option-parsing part of Tcl_SubstObjCommand; switching to Tcl_GetIndexFromObjStruct() simplifies the code since we can get rid of an enum declaration and a switch statement: static struct substOption { const char *option; unsigned int mask; } substOptions[] = { { "-nobackslashes", TCL_SUBST_BACKSLASHES }, { "-nocommands", TCL_SUBST_COMMANDS }, { "-novariables", TCL_SUBST_VARIABLES }, { NULL, 0 } }; flags = TCL_SUBST_ALL; for (i = 1; i < (objc-1); i++) { if (Tcl_GetIndexFromObjStruct(interp, objv[i], (SOME_CAST)substOptions, sizeof(substOptions[0]), "switch", 0, &optionIndex) != TCL_OK) { return TCL_ERROR; } flags &= ~substOptions[optionIndex].mask; } /* ... */ With the old signature, "SOME_CAST" is 'char **'; with the current signature 'SOME_CAST' is 'CONST84 char **'. With the proposed signature, a cast isn't necessary. For cross-version compatibility, SOME_CAST can be 'void *', which will work with all three signatures (except in C++ code, in which case it will only work if Tcl_GetIndexFromObjStruct takes a 'void *'). But the main issue is that the "tablePtr" argument normally points to a an array of structures of unknown type, so 'void *' is the most appropriate type. [later] > Payoff is really in calls to Tcl_GetIndexFromObj(), where you can let the compiler auto-cast to (void *) I don't think Tcl_GetIndexFromObj() should be changed, only Tcl_GetIndexFromObjStruct(). The 'tablePtr' argument to the former really _is_ a 'const char **'; declaring it as a 'void *' would only weaken the type-safety that TIP27 was intended to enhance. - login: "jenglish"
- mimetype: "text/plain"
- username: "jenglish"