Tcl命令update的代码实现

定位udpate命令的实现

% fgrep Tcl_UpdateObjCmd generic/*
generic/tclBasic.c:    {"update", Tcl_UpdateObjCmd, NULL, NULL, CMD_IS_SAFE},
generic/tclEvent.c: * Tcl_UpdateObjCmd --
generic/tclEvent.c:Tcl_UpdateObjCmd(
generic/tclEvent.c:         Tcl_Panic("Tcl_UpdateObjCmd: bad option index to UpdateOptions");
generic/tclInt.h:MODULE_SCOPE int       Tcl_UpdateObjCmd(ClientData clientData,
  • 文件 generic/tclEvent.c

update命令的代码实现

int Tcl_UpdateObjCmd(...) {

    flags = TCL_ALL_EVENTS|TCL_DONT_WAIT;
    //% if idletasks
    flags = TCL_WINDOW_EVENTS|TCL_IDLE_EVENTS|TCL_DONT_WAIT;

    while (Tcl_DoOneEvent(flags) != 0) {
        if (Tcl_Canceled(interp, TCL_LEAVE_ERR_MSG) == TCL_ERROR) {
            return TCL_ERROR;
        }
        if (Tcl_LimitExceeded(interp)) {
            Tcl_ResetResult(interp);
            Tcl_SetObjResult(interp, Tcl_NewStringObj("limit exceeded", -1));
            return TCL_ERROR;
        }
    }
}

主要就是执行所有的事件命令,直到超出资源限值或者发生错误。