Tcl_Cancel(3)
π Tcl_Cancel β the tea on canceling Tcl scripts π
okay so bestie, this is a page from the Tcl Library Procedures manual, and it's literally all about telling a running script to sit down and stop. two functions, one mission: cancel. let's get into it π«Ά
β¨ NAME β¨
Tcl_CancelEval, Tcl_Canceled β cancel Tcl scripts. that's it, that's the whole vibe π
πΈ SYNOPSIS πΈ
#include <tcl.h>
int
Tcl_CancelEval(interp, resultObjPtr, clientData, flags)
int
Tcl_Canceled(interp, flags)
π¦ ARGUMENTS π¦
Tcl_Interp *interp(in) β the interpreter where we're canceling the script. it's giving "the scene of the crime" β¨Tcl_Obj *resultObjPtr(in) β the error message you want to use for the cancellation, orNULLif you'd rather just use a default message (no thoughts, head empty, default slay). lowkey important: if this is notNULL, this object will have its reference count decremented beforeTcl_CancelEvalreturns. yes, really, it's a whole thing β more on that below πint flags(in) β an OR'ed combination of flag bits that specify extra options. forTcl_CancelEval, onlyTCL_CANCEL_UNWINDis currently supported. forTcl_Canceled, onlyTCL_LEAVE_ERR_MSGandTCL_CANCEL_UNWINDare currently supported. so like, pick from the menu, don't freestyle π§void *clientData(in) β currently reserved for future use. set it toNULL. periodt π
π DESCRIPTION π
Tcl_CancelEval cancels or unwinds the script in progress soon after the next invocation of asynchronous handlers, and it makes TCL_ERROR the return code for that script. the way it's thread-safe and can be called from any thread in the process? iconic. truly main character energy π
Tcl_Canceled checks if the script in progress has been canceled and returns TCL_ERROR if it has. otherwise, TCL_OK is returned. extensions can use this function to check whether they should abort a long running command β like a little vibe check mid-command, fr fr. this function is thread sensitive though, so it may only be called from the thread the interpreter was created in. don't try it anywhere else bestie, that's not your lane π
π FLAG BITS π
any OR'ed combination of the following values may be used for the flags argument to procedures such as Tcl_CancelEval:
TCL_CANCEL_UNWINDβ this flag is used by bothTcl_CancelEvalandTcl_Canceled. forTcl_CancelEval: if this flag is set, the script in progress is canceled and the evaluation stack for the interpreter is unwound (we're going all the way down, no half measures π). forTcl_Canceled: if this flag is set, the script in progress is considered to be canceled only if the evaluation stack for the interpreter is being unwound. so it's a picky lil flag, iykyk.TCL_LEAVE_ERR_MSGβ this flag is only used byTcl_Canceled; it is ignored by other procedures (they literally do not care π). if an error is returned and this bit is set inflags, then an error message will be left in the interpreter's result, where it can be retrieved withTcl_GetObjResultorTcl_GetStringResult. if this flag bit is not set, then no error message is left and the interpreter's result will not be modified. so either you get the message or you get silence, no in-between β¨
π REFERENCE COUNT MANAGEMENT π
okay this is the part where you pay attention, bestie, because refcounts are where dreams go to die π
Tcl_CancelEval always decrements the reference count of its resultObjPtr argument (if that is non-NULL). it is expected to be usually called with an object with zero reference count. if the object is shared with some other location (including the Tcl evaluation stack), it should have its reference count incremented before calling this function.
so like. if you're sharing that object around, bump the refcount first. otherwise you're gonna have a bad time and the crash will be entirely your fault π
π SEE ALSO π
π KEYWORDS π
cancel, unwind
and that's the whole page, no cap. go forth and cancel responsibly, bestie π«Ά
this was brought to you by the Tcl girls, version 8.6, on the Tcl_Cancel(3) page β mwah ππβ¨
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- nixpkgs unstable: tcl 9.1.0
- Copyright (c) 2006-2008 Joe Mistachkin
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms