Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Parsing of "profile" for TIP #656

Closed / Fixede778e3f804cacd70deefcdf5ed5d1f8921f32ab1Created 4 years agoUpdated 4 years ago
Descriptionwiki2023-02-28 16:06:40
Some examples:
    % fconfigure stdin -encodingprofile xx
    bad profile "xx". Must be "tcl8" or "strict".
    % fconfigure stdin -translation xx
    bad value for -translation: must be one of auto, binary, cr, lf, crlf, or platform
Looking at consistancy, I would expect "bad value for -encodingprofile: must be one of replace, strict, or tcl8". "replace" was missing, and options should be alphabetical.

Same for "encoding convertfrom/convertto"

    % encoding convertfrom -profile xx ascii é
    bad profile "xx". Must be "tcl8" or "strict".

Looking at the implementation, there's a special function `TclEncodingProfileNameToId()` which does the parsing. Suggestion, use the standard Tcl function `Tcl_GetIndexFromObjStruct()` in stead, wherever possible. This function handles all those minor details.

Referenced by3
jan.nijtmanswiki2023-02-28 16:11:20

Another advantage of using `Tcl_GetIndexFromObjStruct()`: The Tcl_Obj is converted to an "index" objType, which cashes the internal id.

Proposed fix: [here]

jan.nijtmans Ticket [e778e3f804]: 3 changes [History diff]2023-02-28 16:14:59
apnadkarniplain2023-02-28 16:57:09
I'll fix the missing "replace" and alphabetical order.

I didn't use Tcl_GetIndexFromObjStruct specifically because it cannot be used from the configure which only has a string and not a Tcl_Obj. Allocating a Tcl_Obj just to call Tcl_GetIndexFromObjStruct did not seem like a good trade-off. I was not in favour of using Tcl_GetIndexFromObjStruct in one place and then using an inline loop (much less readable imo) in the configure code as you have done for essentially the same function. I much prefer code for a specific purpose to be encapsulated into a single function.

Thanks for the feedback.

/Ashok
apnadkarniplain2023-03-02 06:56:26
Fixed in [f9e3e55bb8] and [80abdf9c7d] respectively for tip-656 and tip-656-tcl9
Log in (anonymous is fine) to add a comment.