From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Po Lu via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61741: 30.0.50; [PATCH] Reset errant timers Date: Fri, 24 Feb 2023 08:55:28 +0800 Message-ID: <87mt536fwf.fsf@yahoo.com> References: <87r0ugtdop.fsf@dick> Reply-To: Po Lu Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7805"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 61741-done@debbugs.gnu.org To: dick.r.chiang@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 24 01:56:26 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVMNs-0001kx-IH for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 24 Feb 2023 01:56:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVMNb-00036x-0T; Thu, 23 Feb 2023 19:56:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pVMNZ-00036C-5m for bug-gnu-emacs@gnu.org; Thu, 23 Feb 2023 19:56:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pVMNW-0003ug-6T for bug-gnu-emacs@gnu.org; Thu, 23 Feb 2023 19:56:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pVMNW-0000ux-1j for bug-gnu-emacs@gnu.org; Thu, 23 Feb 2023 19:56:02 -0500 Resent-From: Po Lu Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 Feb 2023 00:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 61741 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Mail-Followup-To: 61741@debbugs.gnu.org, luangruo@yahoo.com, dick.r.chiang@gmail.com Original-Received: via spool by 61741-done@debbugs.gnu.org id=D61741.16772001493503 (code D ref 61741); Fri, 24 Feb 2023 00:56:01 +0000 Original-Received: (at 61741-done) by debbugs.gnu.org; 24 Feb 2023 00:55:49 +0000 Original-Received: from localhost ([127.0.0.1]:35640 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVMNJ-0000uQ-1w for submit@debbugs.gnu.org; Thu, 23 Feb 2023 19:55:49 -0500 Original-Received: from sonic309-22.consmr.mail.ne1.yahoo.com ([66.163.184.148]:40675) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVMNG-0000uB-Ov for 61741-done@debbugs.gnu.org; Thu, 23 Feb 2023 19:55:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1677200140; bh=NEIHw6gU/gsvM9uXsSP/9lbAtUBB5RuYN8JYZkMF9ow=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From:Subject:Reply-To; b=FN+qSPQSKkK2h+Kd0YC3XlZx4I6RwN8eVhrWZbwWa5xKd4UGLc1JUnWO/j+OTS+1feapr1tOiIhQ0f2VTaLndIa8EY497ubDqiRlgrw4FFCOXYd2BJGH6BzWb6DV7/XyXzzXQP1c++WbVCCoXUOp/pO6CddiWirryB2Dz7Ow34QQBtnuZrL3T3azvparA2p0ZxUutp6p8MOIff3QyMtvm3P2J+NXEuFrnJrUtbBtn5N5xOpIpa3ULoONvan2Jms/rXdawozp7QGcNGaGM82dMWeKd/GhUJe0bQMv44c/h4dEtF0eGImqAP7GBuweJATQkzf4C3nw06J59JfiOCnPEA== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1677200140; bh=ZHzVr8NynEf+j677M/wbRs2lOOAZ84g5vE0lBDN819A=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=VatpHg/ZfLZkB5HUsRGz414AbabCdb3GMo5sqsDUWfhT/BcZA7SaEefpXuQQxaaTveOtBNSOztsAcN4Iv57opy/XxS5G6lrjPBKdzlFGkqKCFe3V7alvnDjIEb6NbZtrgVuxEIZh7yGg71mlHlKpNwP4OLex4ivXYpGqXmEhw8JO6ENidLafm5U4PV9CzjWPjZ0suZ0zAHFd8vh6VM6sGWUX3TLXkFTnq/yFQdYfyAiXx+7YM1fZyl3xv1CFp/doSmNadvsFXh+30nK/f7+5GDay9dXjTBXOABoq5UOCaBo8LFbAEGjqVlGqv2CLoGT0vi3T2gPw4693lA+nRClWqw== X-YMail-OSG: oJGmZrcVM1mFnbYNDJNL9ZOEiynI4rEOpSSMRh3yfuGMLFJjhK7jv1.9en5qA1z CCKuDeFeBN_Ma5XwFGshrQ_qTZps9_oeWeGpBqqr6n6E3lFrr_QsHKN__6.ExmQ4yi6.4uhhiqgE ssEsZdwWuZx8OkcUR6g2mIKgo_oMSDB5GiEjOH.y8zdgmWFF6xRW6Hi23BtBEYYqCQ9zPi_RU9Y8 .m3aB6HGCHtOMHY1svnUsDfgA2gMa1x45m9qkEZE3PbwKhM81V4GyGHlHRPUwqIuwNt7NfiSJJia K8QAysQhqztTsUPmzsS4jKtk.RrHDI3KEKUaUjeSc7BEPjJNWP4_3m7zcNCmRz2MtYdPdfOVPO5I iXf0.p_J__aZxsbPwNa3PtBCE7GxDePqjtYaU_eyj9pc.W5Q1fwCmYHvFWu5ZkEDn7MRY3CX4SRN 2rP0UO6oKHtxbNZFfSUJSt2QGhCqUwfYt2xnR6AcLCEkJyhT598KpyZb5nNhrVyXjJXxF9nvE4Sm 5odDpFK_jTnHvg8NKo1mBKZtyomm.n6xkmprZN04Pu3PWTivYPlO0urxT.o2Sy1JXszxT4nymEo4 bWIFMGbP9pHLAmUuFa08tQjqR5YdMeI0h2sQMsMNS3dCDPoKnW6sySLrV2fY8NUF0rd3UYaiFySM 2PA7syJku7ELjkiCFDnYU94jCL64CcVlnwI6lGKwwvMOK9zHRilBLoXSvuCU8W6Jwfh_56_MiRHb kvi2BdZ6wCnMZ82iW1oKKAL8OguLiiAhiu5AIL07k350ONhXmjWGsx74iNPcyx7DEOA7V_m2pD2g vE4hiDITWxVQS0synfklIWBirF.L4o5V9cTJlthUQc X-Sonic-MF: Original-Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.ne1.yahoo.com with HTTP; Fri, 24 Feb 2023 00:55:40 +0000 Original-Received: by hermes--production-sg3-9fc5746c8-vmkgs (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID 03ca9fa77f6e78221c23cfd61d72c686; Fri, 24 Feb 2023 00:55:36 +0000 (UTC) In-Reply-To: <87r0ugtdop.fsf@dick> (dick r. chiang's message of "Thu, 23 Feb 2023 13:54:46 -0500") X-Mailer: WebService/1.1.21221 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:256536 Archived-At: dick.r.chiang@gmail.com writes: > +(defsubst timer-activate (timer &optional _triggered-p _reuse-cell) > + "Install TIMER." > + (timer--check timer) > + (cl-pushnew timer timer-list)) > + > +(defsubst timer-activate-when-idle (timer &optional _dont-wait _reuse-cell) > + "Install idle TIMER" > + (setf (timer--idle-delay timer) 'idle) > + (timer--check timer) > + (cl-pushnew timer timer-idle-list)) > > (defalias 'disable-timeout #'cancel-timer) > > (defun cancel-timer (timer) > "Remove TIMER from the list of active timers." > - (timer--check timer) > (setq timer-list (delq timer timer-list)) > (setq timer-idle-list (delq timer timer-idle-list)) > nil) > The more doc strings and comments you delete, the less likely it is for anyone to install your change. Quit wasting others' time! > (defun run-with-idle-timer (secs repeat function &rest args) > - "Perform an action the next time Emacs is idle for SECS seconds. > -The action is to call FUNCTION with arguments ARGS. > -SECS may be an integer, a floating point number, or the internal > -time format returned by, e.g., `current-idle-time'. > -If Emacs is currently idle, and has been idle for N seconds (N < SECS), > -then it will call FUNCTION in SECS - N seconds from now. Using > -SECS <= N is not recommended if this function is invoked from an idle > -timer, because FUNCTION will then be called immediately. > - > -If REPEAT is non-nil, do the action each time Emacs has been idle for > -exactly SECS seconds (that is, only once for each time Emacs becomes idle). > - > -This function returns a timer object which you can use in `cancel-timer'." > + "Call FUNCTION on ARGS when idle for SECS seconds. > +If REPEAT is non-nil, repeat the behavior until cancelled via > +`cancel-timer'. SECS may be an integer, a floating point number, > +or the internal time format returned by, e.g., > +`current-idle-time'." Here too. You also deleted the part of the doc string that explains what to give to cancel-timer. > - > + > (defvar with-timeout-timers nil > "List of all timers used by currently pending `with-timeout' calls.") > > @@ -533,7 +431,7 @@ y-or-n-p-with-timeout > If the user does not answer after SECONDS seconds, return DEFAULT-VALUE." > (with-timeout (seconds default-value) > (y-or-n-p prompt))) > - > + Stop removing page breaks. > - FOR_EACH_TAIL (tail) > + FOR_EACH_TAIL_SAFE (tail) > { ...because? Now you will no longer be able to quit from Fcopy_sequence, and instead of a lock up upon encountering a circular list, you get the list with random contents appended at the end. > +/* Trigger any timers meeting their respective criteria. > > -/* Check whether a timer has fired. To prevent larger problems we simply > - disregard elements that are not proper timers. Do not make a circular > - timer list for the time being. > + For ordinary timers, this means current time is at > + or past their scheduled time. > > - Returns the time to wait until the next timer fires. > - If no timer is active, return an invalid value. > + For idle timers, this means the idled period exceeds > + their idle threshold. > > - As long as any timer is ripe, we run it. */ > + Return the time distance to the next upcoming timer. > +*/ > > struct timespec > timer_check (void) > { > - struct timespec nexttime; > - Lisp_Object timers, idle_timers; > - > - Lisp_Object tem = Vinhibit_quit; > - Vinhibit_quit = Qt; > - block_input (); > - turn_on_atimers (false); > - > - /* We use copies of the timers' lists to allow a timer to add itself > - again, without locking up Emacs if the newly added timer is > - already ripe when added. */ > + struct timespec now = current_timespec (); > + struct timespec idled = timespec_valid_p (timer_idleness_start_time) > + ? timespec_sub (now, timer_idleness_start_time) > + : invalid_timespec (); > + struct timespec until_next = invalid_timespec (); > + Lisp_Object *const lists[] = { &Vtimer_list, &Vtimer_idle_list }; > + struct timespec const bogeys[] = { now, idled }; > > - /* Always consider the ordinary timers. */ > - timers = Fcopy_sequence (Vtimer_list); > - /* Consider the idle timers only if Emacs is idle. */ > - if (timespec_valid_p (timer_idleness_start_time)) > - idle_timers = Fcopy_sequence (Vtimer_idle_list); > - else > - idle_timers = Qnil; > - > - turn_on_atimers (true); > - unblock_input (); > - Vinhibit_quit = tem; > - > - do > + for (int i = 0; i < 2; ++i) > { > - nexttime = timer_check_2 (timers, idle_timers); > + struct timespec bogey = bogeys[i]; > + if (! timespec_valid_p (bogey)) > + continue; > + > + Lisp_Object timers = Fcopy_sequence (*lists[i]); > + FOR_EACH_TAIL_SAFE (timers) > + { > + struct timespec time; > + Lisp_Object *vec; > + CHECK_VECTOR (XCAR (timers)); > + vec = XVECTOR (XCAR (timers))->contents; > + if (NILP (vec[0])) /* not yet triggered */ > + { > + if (list4_to_timespec (vec[1], vec[2], vec[3], vec[8], &time)) > + { > + /* Trigger when: > + For ordinary timer, now is at or past trigger time. > + For idle timer, idled duration at or past threshold. */ > + if (timespec_cmp (bogey, time) >= 0) > + { > + trigger_timer (XCAR (timers)); > + } > + else > + { > + struct timespec diff = timespec_sub (time, bogey); > + if (! timespec_valid_p (until_next) > + || timespectod (diff) < timespectod (until_next)) > + until_next = diff; > + } > + } > + } > + else /* was triggered */ > + { > + /* Clean up timers that errored out. */ > + if (NILP (vec[4])) /* if not repeated, delete it. */ > + *lists[i] = Fdelq (XCAR (timers), *lists[i]); > + else if (NILP (vec[7]) /* if not idle, reset it. */) > + vec[0] = Qnil; > + } > + } > } > - while (nexttime.tv_sec == 0 && nexttime.tv_nsec == 0); > > - return nexttime; > + return until_next; > } If you cannot quit your habit of making irrelevant changes that go unexplained and reduce the total volume of the commentary, do not expect anything you write to be installed. Please file a bug for whatever you think is the problem instead.