Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2026-10-22
17:19 • Ticket [ece07271f4] Bug in Tcl_ParseArgsObjv() TCL_ARGV_GENFUNC status still... artifact: da2f8957d8 user: serhiy.storchaka
2026-10-21
09:58 • Closed ticket [ece07271f4]. artifact: 016fd1302c user: serhiy.storchaka
2019-03-25
12:43 • New ticket [ece07271f4]. artifact: b5208301f8 user: anonymous

Bug in Tcl_ParseArgsObjv() TCL_ARGV_GENFUNC

Closed / Duplicateece07271f480ae32005ef014d72520e9a595012fCreated 8 years agoUpdated 41 days ago
Descriptionplain2019-03-25 12:43:53
Hi,

I was playing with the Tcl_ParseArgsObjv() function and I needed it to do something more specific than what the pre-defined matchers provide. The TCL_ARGV_GENFUNC option seemed like a good solution. However I couldn't get it to work. After some debugging, I believe, I tracked it down to a bug in Tcl_ParseArgsObjv() itself.

Currently tcl8.6.9/generic/TclIndexObj.c:1275 is
    case TCL_ARGV_GENFUNC: {
        Tcl_ArgvGenFuncProc *handlerProc = (Tcl_ArgvGenFuncProc *)infoPtr->srcPtr;
        objc = handlerProc(infoPtr->clientData, interp, objc, &objv[srcIndex], infoPtr->dstPtr);
        if (objc < 0) {
            goto error;
        }
        break;
    }

But I believe it should be
    case TCL_ARGV_GENFUNC: {
        Tcl_ArgvGenFuncProc *handlerProc = (Tcl_ArgvGenFuncProc *)infoPtr->srcPtr;
        int consumed = handlerProc(infoPtr->clientData, interp, objc, &objv[srcIndex], infoPtr->dstPtr);
        if (consumed < 0) {
            goto error;
        }
        srcIndex += consumed;
        objc -= consumed;
        break;
    }

If I read the documentation correctly (https://www.tcl.tk/man/tcl8.6/TclLib/ParseArgs.htm#M14), then the return value of handlerProc indicates how many arguments must be consumed, not how many are still remaining.

I verified that tcl8.7a1 still contains the same bug.


Wouter
serhiy.storchakawiki2026-10-21 09:58:25

Duplicate of [7cb7409e05]. Fixed by [8cfa5d1ee9] (8.6.15) and [c28a455139] (9.0.0): the handler's return value is now treated as the number of consumed arguments.

serhiy.storchaka Ticket [ece07271f4]: 3 changes [History diff]2026-10-22 17:19:29
Log in (anonymous is fine) to add a comment.