GNU bug report logs - #34123
A patch to fix reading EOF characters in non-interactive mode

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Shawn Presser <shawnpresser@HIDDEN>; dated Fri, 18 Jan 2019 10:48:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 18 Jan 2019 10:47:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 18 05:47:10 2019
Received: from localhost ([127.0.0.1]:35731 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gkRg6-0004qE-6T
	for submit <at> debbugs.gnu.org; Fri, 18 Jan 2019 05:47:10 -0500
Received: from eggs.gnu.org ([209.51.188.92]:42924)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <shawnpresser@HIDDEN>) id 1gkRUZ-0002h1-4N
 for submit <at> debbugs.gnu.org; Fri, 18 Jan 2019 05:35:15 -0500
Received: from lists.gnu.org ([209.51.188.17]:54490)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <shawnpresser@HIDDEN>)
 id 1gkRUS-0000pS-5A
 for submit <at> debbugs.gnu.org; Fri, 18 Jan 2019 05:35:09 -0500
Received: from eggs.gnu.org ([209.51.188.92]:53099)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <shawnpresser@HIDDEN>) id 1gkRUP-0000ho-6U
 for bug-gnu-emacs@HIDDEN; Fri, 18 Jan 2019 05:35:08 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05,FREEMAIL_FROM,
 HTML_MESSAGE autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <shawnpresser@HIDDEN>) id 1gkRUN-0000My-36
 for bug-gnu-emacs@HIDDEN; Fri, 18 Jan 2019 05:35:05 -0500
Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]:39934)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <shawnpresser@HIDDEN>)
 id 1gkRUH-0007RJ-AH
 for bug-gnu-emacs@HIDDEN; Fri, 18 Jan 2019 05:35:01 -0500
Received: by mail-lf1-x131.google.com with SMTP id n18so10112714lfh.6
 for <bug-gnu-emacs@HIDDEN>; Fri, 18 Jan 2019 02:34:51 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:from:date:message-id:subject:to;
 bh=mhl7j8YuudxTapeE3gK7jnbbfVtT33M7T1PzeVtOHE4=;
 b=UKJ/n+OEkvG5bZD3QOO1C5JTN8Wz2HjiW/iu5+S4IkFySySvklb2pfseoj8lfrzty5
 9q2owp18Xr9kr/hrXtoUwkNuBlqG3QAX9jP7zpIzQdMnkVWEmskD2ZVJBHGIqkki9tpO
 H6vY0DGaDDkpO+T7dBy5v/Pc99JstjhOmefBGgdKFsXMj9+x9phf4WeZk1pfVGxBlkNx
 EPNNs5W4FfSHOxHgoaEUIDAgRmc/uSvf8Zh3hjc6xcLU7Vgz9o1Ti4j4wPhwYr2f7Kd/
 jMGcBQ5FtcV4I2Y0ChKV0m0CvtxXyt/dDzl5TAREnjqTJm360B171bc92tSDH4UBjuzh
 Wotw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
 bh=mhl7j8YuudxTapeE3gK7jnbbfVtT33M7T1PzeVtOHE4=;
 b=K/tXd3nsXlZaPz/onH7YaTeN9+940aV1Xi3KOf4gF7wr5eZ6tZVB0iF0tdgUmbEye8
 u/o5e4k9Q5jYhPa96Q2rHTs3baqqP3IJRVYwQD/+JZgHRtM7nnqKaUukLZ116wdwfO90
 MEK4XP4aeXpekijHfYPRbAd4nhGTT3TY355ekqeyFV/GA987+76CdsiLW/IYh2gQczee
 QZsH2N0Iv45CNcrzqwWBoQzF8rnohVMUMGRAwLVl5XYfYaKdg8w0W/qA+C5p1Ey410oh
 q4g/Wr9YTbAO7jQ9qyJVSV1Vd3HJ1wOs/ki2tCs0lvB1O+GOD5s8z5Rrast33+71NVHp
 TAJw==
X-Gm-Message-State: AJcUukfm9LWFZX1Wu++OgA4S4DS02+JyjTVT8cJTYdNxKfTg/FrjI5RO
 ZNkRtcwuUeiJA2kEPjKZCPeQv6CA6/SNWDVqQrGNYDS2
X-Google-Smtp-Source: ALg8bN5J3wscW34biX1ZloZL2agtkPiUVUA6Xr2pF2H1H45mx6GGptRHzk/dR3+CGwYSSLDeZK3XrrriL8bs4PYpIBs=
X-Received: by 2002:ac2:55a3:: with SMTP id y3mr11724971lfg.93.1547807689634; 
 Fri, 18 Jan 2019 02:34:49 -0800 (PST)
MIME-Version: 1.0
From: Shawn Presser <shawnpresser@HIDDEN>
Date: Fri, 18 Jan 2019 04:35:34 -0600
Message-ID: <CALtdh+-KwGRrmujB1mbAn43bT-4UZMuDM4PR0teDWWsQDsWZUQ@HIDDEN>
Subject: A patch to fix reading EOF characters in non-interactive mode
To: bug-gnu-emacs@HIDDEN
Content-Type: multipart/mixed; boundary="00000000000085adee057fb90f67"
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
X-Received-From: 2a00:1450:4864:20::131
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Fri, 18 Jan 2019 05:47:09 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

--00000000000085adee057fb90f67
Content-Type: multipart/alternative; boundary="00000000000085adea057fb90f65"

--00000000000085adea057fb90f65
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello,

Here is a patch to allow batch mode scripts to handle EOF characters. This
solves the following problem:

$ git clone https://github.com/shawwn/y
$ cd y
$ bin/y
> (read t)
Lisp expression: 42
42
> (read t)
Lisp expression: ^Derror: Error reading from stdin
> Error reading from stdin
$

Notice that it=E2=80=99s currently impossible for non-interactive scripts t=
o
recover from EOF when reading from tty. After the user sends an EOF
character by pressing C-d, calling read-from-minibuffer will always result
in an error.

This patch solves this by clearing stdin of errors and returning nil when
an EOF character is detected.

Here is the patch:

From 685452ca4a098bbd7c1062a35064755c1d09512a Mon Sep 17 00:00:00 2001
From: Shawn Presser <shawnpresser@HIDDEN>
Date: Fri, 18 Jan 2019 03:57:37 -0600
Subject: [PATCH] Fix reading EOF characters in batch mode.

* src/minibuf.c (read_minibuf_noninteractive): Handle EOF characters by
clearing stdin and returning Qnil.
---
 src/minibuf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/minibuf.c b/src/minibuf.c
index 321fda1ba8..8c88a316a7 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -250,7 +250,8 @@ read_minibuf_noninteractive (Lisp_Object prompt, bool
expflag,
   else
     {
       xfree (line);
-      error ("Error reading from stdin");
+      clearerr(stdin);
+      return Qnil;
     }

   /* If Lisp form desired instead of string, parse it.  */
--=20
2.19.1

Thanks!
=E2=80=94 shawn

--00000000000085adea057fb90f65
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><span style=3D"color:rgb(0,0,0);font-fami=
ly:Helvetica;font-size:12px">Hello,</span><br style=3D"color:rgb(0,0,0);fon=
t-family:Helvetica;font-size:12px"><br style=3D"color:rgb(0,0,0);font-famil=
y:Helvetica;font-size:12px"><span style=3D"color:rgb(0,0,0);font-family:Hel=
vetica;font-size:12px">Here is a patch to allow batch mode scripts to handl=
e EOF characters. This solves the following problem:</span><br style=3D"col=
or:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br style=3D"color:rgb(=
0,0,0);font-family:Helvetica;font-size:12px"><font face=3D"Courier New" sty=
le=3D"color:rgb(0,0,0);font-size:12px">$ git clone=C2=A0<a href=3D"https://=
github.com/shawwn/y">https://github.com/shawwn/y</a><br>$ cd y<br>$ bin/y<b=
r>&gt; (read t)<br>Lisp expression: 42<br>42<br>&gt; (read t)<br>Lisp expre=
ssion: ^Derror: Error reading from stdin<br>&gt; Error reading from stdin</=
font><div style=3D"color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><=
font face=3D"Courier New">$=C2=A0<br></font><br>Notice that it=E2=80=99s cu=
rrently impossible for non-interactive scripts to recover from EOF when rea=
ding from tty. After the user sends an EOF character by pressing C-d, calli=
ng read-from-minibuffer will always result in an error.</div><div style=3D"=
color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><div style=
=3D"text-size-adjust: auto;"><font color=3D"#000000" face=3D"Helvetica"><sp=
an style=3D"font-size:12px">This patch solves this by clearing stdin of err=
ors and returning nil when an EOF character is detected.</span></font><div =
style=3D"color:rgb(0,0,0);font-family:Helvetica;font-size:12px"><br></div><=
div style=3D"color:rgb(0,0,0);font-family:Helvetica;font-size:12px">Here is=
 the patch:</div><div style=3D"color:rgb(0,0,0);font-family:Helvetica;font-=
size:12px"><br></div><div><div><font color=3D"#000000" face=3D"monospace, m=
onospace"><span style=3D"font-size:12px">From 685452ca4a098bbd7c1062a350647=
55c1d09512a Mon Sep 17 00:00:00 2001</span></font></div><div><font color=3D=
"#000000" face=3D"monospace, monospace"><span style=3D"font-size:12px">From=
: Shawn Presser &lt;<a href=3D"mailto:shawnpresser@HIDDEN">shawnpresser@=
gmail.com</a>&gt;</span></font></div><div><font color=3D"#000000" face=3D"m=
onospace, monospace"><span style=3D"font-size:12px">Date: Fri, 18 Jan 2019 =
03:57:37 -0600</span></font></div><div><font color=3D"#000000" face=3D"mono=
space, monospace"><span style=3D"font-size:12px">Subject: [PATCH] Fix readi=
ng EOF characters in batch mode.</span></font></div><div><font color=3D"#00=
0000" face=3D"monospace, monospace"><span style=3D"font-size:12px"><br></sp=
an></font></div><div><font color=3D"#000000" face=3D"monospace, monospace">=
<span style=3D"font-size:12px">* src/minibuf.c (read_minibuf_noninteractive=
): Handle EOF characters by</span></font></div><div><font color=3D"#000000"=
 face=3D"monospace, monospace"><span style=3D"font-size:12px">clearing stdi=
n and returning Qnil.</span></font></div><div><font color=3D"#000000" face=
=3D"monospace, monospace"><span style=3D"font-size:12px">---</span></font><=
/div><div><font color=3D"#000000" face=3D"monospace, monospace"><span style=
=3D"font-size:12px">=C2=A0src/minibuf.c | 3 ++-</span></font></div><div><fo=
nt color=3D"#000000" face=3D"monospace, monospace"><span style=3D"font-size=
:12px">=C2=A01 file changed, 2 insertions(+), 1 deletion(-)</span></font></=
div><div><font color=3D"#000000" face=3D"monospace, monospace"><span style=
=3D"font-size:12px"><br></span></font></div><div><font color=3D"#000000" fa=
ce=3D"monospace, monospace"><span style=3D"font-size:12px">diff --git a/src=
/minibuf.c b/src/minibuf.c</span></font></div><div><font color=3D"#000000" =
face=3D"monospace, monospace"><span style=3D"font-size:12px">index 321fda1b=
a8..8c88a316a7 100644</span></font></div><div><font color=3D"#000000" face=
=3D"monospace, monospace"><span style=3D"font-size:12px">--- a/src/minibuf.=
c</span></font></div><div><font color=3D"#000000" face=3D"monospace, monosp=
ace"><span style=3D"font-size:12px">+++ b/src/minibuf.c</span></font></div>=
<div><font color=3D"#000000" face=3D"monospace, monospace"><span style=3D"f=
ont-size:12px">@@ -250,7 +250,8 @@ read_minibuf_noninteractive (Lisp_Object=
 prompt, bool expflag,</span></font></div><div><font color=3D"#000000" face=
=3D"monospace, monospace"><span style=3D"font-size:12px">=C2=A0 =C2=A0else<=
/span></font></div><div><font color=3D"#000000" face=3D"monospace, monospac=
e"><span style=3D"font-size:12px">=C2=A0 =C2=A0 =C2=A0{</span></font></div>=
<div><font color=3D"#000000" face=3D"monospace, monospace"><span style=3D"f=
ont-size:12px">=C2=A0 =C2=A0 =C2=A0 =C2=A0xfree (line);</span></font></div>=
<div><font color=3D"#000000" face=3D"monospace, monospace"><span style=3D"f=
ont-size:12px">-=C2=A0 =C2=A0 =C2=A0 error (&quot;Error reading from stdin&=
quot;);</span></font></div><div><font color=3D"#000000" face=3D"monospace, =
monospace"><span style=3D"font-size:12px">+=C2=A0 =C2=A0 =C2=A0 clearerr(st=
din);</span></font></div><div><font color=3D"#000000" face=3D"monospace, mo=
nospace"><span style=3D"font-size:12px">+=C2=A0 =C2=A0 =C2=A0 return Qnil;<=
/span></font></div><div><font color=3D"#000000" face=3D"monospace, monospac=
e"><span style=3D"font-size:12px">=C2=A0 =C2=A0 =C2=A0}</span></font></div>=
<div><font color=3D"#000000" face=3D"monospace, monospace"><span style=3D"f=
ont-size:12px">=C2=A0</span></font></div><div><font color=3D"#000000" face=
=3D"monospace, monospace"><span style=3D"font-size:12px">=C2=A0 =C2=A0/* If=
 Lisp form desired instead of string, parse it.=C2=A0 */</span></font></div=
><div><font color=3D"#000000" face=3D"monospace, monospace"><span style=3D"=
font-size:12px">--=C2=A0</span></font></div><div><font color=3D"#000000" fa=
ce=3D"monospace, monospace"><span style=3D"font-size:12px">2.19.1</span></f=
ont></div><div style=3D"color:rgb(0,0,0);font-family:Helvetica;font-size:12=
px"><br></div></div><div style=3D"color:rgb(0,0,0);font-family:Helvetica;fo=
nt-size:12px">Thanks!<br></div><div style=3D"color:rgb(0,0,0);font-family:H=
elvetica;font-size:12px">=E2=80=94 shawn</div><div style=3D"color:rgb(0,0,0=
);font-family:Helvetica;font-size:12px"><br><div><br><br></div></div></div>=
</div></div>

--00000000000085adea057fb90f65--

--00000000000085adee057fb90f67
Content-Type: application/octet-stream; 
	name="0001-Fix-reading-EOF-characters-in-batch-mode.patch"
Content-Disposition: attachment; 
	filename="0001-Fix-reading-EOF-characters-in-batch-mode.patch"
Content-Transfer-Encoding: base64
Content-ID: <f_jr1wp1to0>
X-Attachment-Id: f_jr1wp1to0

RnJvbSA2ODU0NTJjYTRhMDk4YmJkN2MxMDYyYTM1MDY0NzU1YzFkMDk1MTJhIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBTaGF3biBQcmVzc2VyIDxzaGF3bnByZXNzZXJAZ21haWwuY29t
PgpEYXRlOiBGcmksIDE4IEphbiAyMDE5IDAzOjU3OjM3IC0wNjAwClN1YmplY3Q6IFtQQVRDSF0g
Rml4IHJlYWRpbmcgRU9GIGNoYXJhY3RlcnMgaW4gYmF0Y2ggbW9kZS4KCiogc3JjL21pbmlidWYu
YyAocmVhZF9taW5pYnVmX25vbmludGVyYWN0aXZlKTogSGFuZGxlIEVPRiBjaGFyYWN0ZXJzIGJ5
CmNsZWFyaW5nIHN0ZGluIGFuZCByZXR1cm5pbmcgUW5pbC4KLS0tCiBzcmMvbWluaWJ1Zi5jIHwg
MyArKy0KIDEgZmlsZSBjaGFuZ2VkLCAyIGluc2VydGlvbnMoKyksIDEgZGVsZXRpb24oLSkKCmRp
ZmYgLS1naXQgYS9zcmMvbWluaWJ1Zi5jIGIvc3JjL21pbmlidWYuYwppbmRleCAzMjFmZGExYmE4
Li44Yzg4YTMxNmE3IDEwMDY0NAotLS0gYS9zcmMvbWluaWJ1Zi5jCisrKyBiL3NyYy9taW5pYnVm
LmMKQEAgLTI1MCw3ICsyNTAsOCBAQCByZWFkX21pbmlidWZfbm9uaW50ZXJhY3RpdmUgKExpc3Bf
T2JqZWN0IHByb21wdCwgYm9vbCBleHBmbGFnLAogICBlbHNlCiAgICAgewogICAgICAgeGZyZWUg
KGxpbmUpOwotICAgICAgZXJyb3IgKCJFcnJvciByZWFkaW5nIGZyb20gc3RkaW4iKTsKKyAgICAg
IGNsZWFyZXJyKHN0ZGluKTsKKyAgICAgIHJldHVybiBRbmlsOwogICAgIH0KIAogICAvKiBJZiBM
aXNwIGZvcm0gZGVzaXJlZCBpbnN0ZWFkIG9mIHN0cmluZywgcGFyc2UgaXQuICAqLwotLSAKMi4x
OS4xCgo=
--00000000000085adee057fb90f67--




Acknowledgement sent to Shawn Presser <shawnpresser@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#34123; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 18 Jan 2019 11:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.