Artifacts Associated With Ticket 2c51973607
Ticket change [f42c397fd4] (rid 164438) by stu on 2018-07-04 11:50:45:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
In Tcl extensions, a call to Tcl_WrongNumArgs is almost invariably followed by return TCL_ERROR.<br> If Tcl_WrongNumArgs, which currently has a void return, were to instead return TCL_ERROR then extension writing would be a little bit nicer. Currently: <pre> if (objc != 1) { Tcl_WrongNumArgs(interp, 1, objv, NULL); return TCL_ERROR; } </pre> Nicer: <pre> if (objc != 1) { return Tcl_WrongNumArgs(interp, 1, objv, NULL); } </pre> - foundin initialized to: "current"
- is_private initialized to: "0"
- login: "stu"
- priority initialized to: "5 Medium"
- private_contact initialized to: "36034badbf4fa68e1e6f55bc81729916152660a8"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "stu"
- subsystem initialized to: "69. Other"
- title initialized to:
Having Tcl_WrongNumArgs return TCL_ERROR makes extension writing a little nicer
- type initialized to: "RFE"
Ticket change [7585e05005] (rid 164439) by sebres on 2018-07-04 18:56:32:
- icomment:
Why not so? <code><pre> if (objc != 1) { return Tcl_WrongNumArgs(interp, 1, objv, NULL), TCL_ERROR; } </pre></code> Without any change of the interface. - login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [ee8ad62929] (rid 164453) by stu on 2018-07-04 20:47:28:
- icomment:
Interesting suggestion, but I don't write code like that, and neither should anyone else. :D
- login: "stu"
- mimetype: "text/plain"
- username: "stu"
- icomment:
Ticket change [47f4a43c4f] (rid 164468) by oehhar on 2018-07-05 06:26:19:
- icomment:
Hi, thank you for the proposition which looks beautiful at a first glance. IMHO any function should return the status of itself. There might be a lot of troubble inside Tcl_WrongNumArgs which may be reported: * Invalid interpreter * Invalid objv * Position number out of range I would prefer, that the function returns an error instead of returnin a convenience value. If you prefer, you may also define a macro or an inline proc to beautify your code. Or use the solution by Sergey. Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [3a41bd60af] (rid 164469) by sebres on 2018-07-05 10:33:21:
- icomment:
> neither should anyone else. :D Why not?... Explicit looks always better as implicit... Despite the function would not return anything else as TCL_ERROR, so IMHO no return code expected also. So as regards the readability of the source code. At first glance, the one reason speak for the implicit return code inside Tcl_WrongNumArgs - the minimization of resulting assembler code (if it's the last function in the simple stack block, modern compiler will replace "call Tcl_WrongNumArgs" with "jmp Tcl_WrongNumArgs")... So: <code><pre style="padding-left:10pt"> test(Tcl_Interp*, int, Tcl_Obj*): sub rsp, 8 xor ecx, ecx call Tcl_WrongNumArgs xor eax, eax add rsp, 8 ret <pre></code> resulting to: <code><pre style="padding-left:10pt"> test(Tcl_Interp*, int, Tcl_Obj*): xor ecx, ecx jmp Tcl_WrongNumArgs; <pre></code> But only if nothing else is to do (free stack, decrement references, etc). Otherwise it may be bad, because steals a register (eax) for return code from function (because the compiler does not know that it's always the same return code). And as Harald correct said, you could simply write your own macro resp. inliner.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [c450341fe4] (rid 164494) by stu on 2018-07-06 18:56:01:
- icomment:
Also nice if Tcl_SetObjResult were to return TCL_OK.
- login: "stu"
- mimetype: "text/plain"
- username: "stu"
- icomment: