all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: "J.P." <jp@neverwas.me>
Cc: fernandodemorais.jf@gmail.com, bandali@gnu.org, 54458@debbugs.gnu.org
Subject: bug#54458: 27.2; erc-dcc-get: Re-entering top level after C stack overflow
Date: Tue, 29 Mar 2022 17:49:05 +0200	[thread overview]
Message-ID: <4DA2DB05-D902-42DF-860D-87617FBB74C8@acm.org> (raw)
In-Reply-To: <87r16m46uf.fsf@neverwas.me>

[-- Attachment #1: Type: text/plain, Size: 923 bytes --]

28 mars 2022 kl. 14.08 skrev J.P. <jp@neverwas.me>:

> As you highlighted up thread, inhibited sends appeal to
> `wait_reading_process_output' to try and shake something loose. I agree
> such occasions seem likeliest to trigger "unexpected" filter nesting.

Although it seems reasonable to require that filter functions abstain from sending more data to the process, there may be another way: preventing re-entering process-send calls from recursing further.

Attached is a proof of concept: if process-send calls are invoked when another activation already exists, just enqueue the data and let the previous activation deal with the actual transmission. That nips the recursion in the buds.

The principle seems sound but if anyone can think of problems with the approach, please do tell.

Of course, one reason to make the change in ERC is that it would fix the problem in all Emacs versions, not just 29.


[-- Attachment #2: send-process-nesting.diff --]
[-- Type: application/octet-stream, Size: 1407 bytes --]

diff --git a/src/process.c b/src/process.c
index 993e1c5603..694307b43a 100644
--- a/src/process.c
+++ b/src/process.c
@@ -6393,6 +6393,14 @@ write_queue_pop (struct Lisp_Process *p, Lisp_Object *obj,
   return 1;
 }
 
+static int send_process_nesting = 0;
+
+static void
+unwind_send_process (void)
+{
+  send_process_nesting--;
+}
+
 /* Send some data to process PROC.
    BUF is the beginning of the data; LEN is the number of characters.
    OBJECT is the Lisp object that the data comes from.  If OBJECT is
@@ -6510,6 +6518,18 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
       buf = SSDATA (object);
     }
 
+  if (send_process_nesting > 0)
+    {
+      /* We are already inside a send_process activation higher up the
+	 call chain; let that take care of writing the queued data.  */
+      write_queue_push (p, object, buf, len, 0);
+      return;
+    }
+
+  specpdl_ref count = SPECPDL_INDEX ();
+  record_unwind_protect_void (unwind_send_process);
+  send_process_nesting++;
+
   /* If there is already data in the write_queue, put the new data
      in the back of queue.  Otherwise, ignore it.  */
   if (!NILP (p->write_queue))
@@ -6633,6 +6653,7 @@ send_process (Lisp_Object proc, const char *buf, ptrdiff_t len,
 	}
     }
   while (!NILP (p->write_queue));
+  unbind_to (count, Qnil);
 }
 
 DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region,

[-- Attachment #3: Type: text/plain, Size: 2 bytes --]




  reply	other threads:[~2022-03-29 15:49 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-18 22:59 bug#54458: 27.2; erc-dcc-get: Re-entering top level after C stack overflow Fernando de Morais
2022-03-21 14:09 ` J.P.
2022-03-22 13:50   ` Fernando de Morais
2022-03-22 14:36     ` Eli Zaretskii
     [not found]       ` <87tubj1eq4.fsf@gmail.com>
2022-03-27 17:56         ` Eli Zaretskii
2022-03-27 22:09           ` Fernando de Morais
2022-03-27 20:54 ` Mattias Engdegård
2022-03-28  9:23   ` Mattias Engdegård
2022-03-28 11:14     ` Eli Zaretskii
2022-03-28 12:08       ` J.P.
2022-03-29 15:49         ` Mattias Engdegård [this message]
2022-03-29 16:45           ` Eli Zaretskii
2022-03-29 17:47             ` Mattias Engdegård
2022-03-29 19:44               ` J.P.
2022-03-30  4:02                 ` J.P.
     [not found]                 ` <87mth8rst7.fsf@neverwas.me>
2022-03-30 15:28                   ` Mattias Engdegård
2022-03-31 19:18                     ` J.P.
     [not found]                     ` <87sfqygccz.fsf@neverwas.me>
2022-04-03 17:20                       ` Fernando de Morais
2022-04-03 19:46                         ` J.P.
     [not found]                         ` <87wng67xxd.fsf@neverwas.me>
2022-04-10 21:31                           ` J.P.
     [not found]                           ` <875yng39sa.fsf@neverwas.me>
2022-04-11  3:17                             ` J.P.
     [not found]                             ` <87sfqkz4ts.fsf@neverwas.me>
2022-04-25  0:59                               ` Fernando de Morais
     [not found]                               ` <87ilqyrn9s.fsf@gmail.com>
2022-04-25 12:08                                 ` J.P.
     [not found]                                 ` <878rrtz7or.fsf@neverwas.me>
2022-04-29 14:51                                   ` Fernando de Morais
     [not found]                                   ` <87r15guen2.fsf@gmail.com>
2022-04-30 13:39                                     ` J.P.
     [not found]                                     ` <87ilqqy9km.fsf@neverwas.me>
2022-05-04 13:03                                       ` Fernando de Morais
     [not found]                                       ` <87pmkth2lr.fsf@gmail.com>
2022-05-06 13:06                                         ` J.P.
     [not found]                                         ` <874k22zu7s.fsf@neverwas.me>
2022-05-08  1:16                                           ` Fernando de Morais
     [not found]                                           ` <87sfpk4ydj.fsf@gmail.com>
2022-05-11 14:29                                             ` J.P.
     [not found]                                             ` <87ee10xhw3.fsf@neverwas.me>
2022-05-23  1:22                                               ` J.P.
2022-04-01  6:32                   ` J.P.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DA2DB05-D902-42DF-860D-87617FBB74C8@acm.org \
    --to=mattiase@acm.org \
    --cc=54458@debbugs.gnu.org \
    --cc=bandali@gnu.org \
    --cc=fernandodemorais.jf@gmail.com \
    --cc=jp@neverwas.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.