From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!.POSTED!not-for-mail
From: Philipp Stephani
Newsgroups: gmane.emacs.devel
Subject: [PATCH 3/3] Inherit process output coding system to stderr process.
Date: Wed, 4 Apr 2018 14:02:18 +0200
Message-ID: <20180404120218.257212-3-phst@google.com>
References: <20180404120218.257212-1-phst@google.com>
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: blaine.gmane.org 1522843436 3253 195.159.176.226 (4 Apr 2018 12:03:56 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 4 Apr 2018 12:03:56 +0000 (UTC)
Cc: Philipp Stephani
To: emacs-devel@gnu.org
Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 04 14:03:52 2018
Return-path:
Envelope-to: ged-emacs-devel@m.gmane.org
Original-Received: from lists.gnu.org ([208.118.235.17])
by blaine.gmane.org with esmtp (Exim 4.84_2)
(envelope-from )
id 1f3h8n-0000hq-KO
for ged-emacs-devel@m.gmane.org; Wed, 04 Apr 2018 14:03:51 +0200
Original-Received: from localhost ([::1]:53017 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from )
id 1f3hAt-00045N-4s
for ged-emacs-devel@m.gmane.org; Wed, 04 Apr 2018 08:05:59 -0400
Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40416)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1f3h8L-0002OJ-FX
for emacs-devel@gnu.org; Wed, 04 Apr 2018 08:03:27 -0400
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from ) id 1f3h8F-0000V9-Hf
for emacs-devel@gnu.org; Wed, 04 Apr 2018 08:03:21 -0400
Original-Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]:44561)
by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
(Exim 4.71) (envelope-from )
id 1f3h8F-0000UL-8l
for emacs-devel@gnu.org; Wed, 04 Apr 2018 08:03:15 -0400
Original-Received: by mail-wr0-x233.google.com with SMTP id u46so22228965wrc.11
for ; Wed, 04 Apr 2018 05:03:15 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=from:to:cc:subject:date:message-id:in-reply-to:references
:mime-version:content-transfer-encoding;
bh=hGyUYCElJUFozMeFKNsVIyjc6g/tBp1X6IfKdK5RyrI=;
b=H3Ny/7vn9bnywX2dhH/kcj+CwultS+jzXlxjbV1M0dhofWwvjs7ugFSI73KRs04Sx2
JA1GfgXCWsAK772rNJlnA4l6d6vEVTYYQVQvbKPTQ+17aH7JmhUmPcfazRndNEIXbkGk
7QOj0/+P1HCbQoT1IenxdtxIfvV3kZuQnzgM9KY4bv7nNPzCKgzaG1LwxJYOOXnBtnNB
NKbrOTEeG/89vsE9JjYGIFGib+WqL3g39URn2rVtsn1K8YGB2yzDm69tr6k4WTlXEO70
OBp3+TNbJbtTq8rMU7vNuWpfF0M4/RYnyglZyKhHQnh68v1Mp1g5OEuz7pgAopHckx+j
CSSg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
:references:mime-version:content-transfer-encoding;
bh=hGyUYCElJUFozMeFKNsVIyjc6g/tBp1X6IfKdK5RyrI=;
b=QRXF4JUhiedymkF6mGfgPIw4cvJ5yObjp7biqvmAbN7JcyLK7MqMxE//qd6116c+1G
acmZ6/qPFcgnSDcZLrOEHl6TDnPc1g62/NYNDbGu1l5wGbEBZNv0ONe6EJKLmGdM/okP
jv0nx9J7NkJkrtLDwk7a1zywkXbn10aL8dLOmRu3IdkkciAe4+BDosk+DePw54zIuuqF
gzwGkEmvSFP3/WT2DTNFs/VvcmRrAvWOYK+gvDCbchg0LXVaaN6lbUQ6GgdBLITo2DOa
whx55aL8OfV6LYZjobtYa/7x22IDvDy/bSeaaYDwvznkvAiB/egWgNSI5mltOoqLnULy
sMew==
X-Gm-Message-State: AElRT7G/TIQTznhKS9dIY5gxXidJawOpgI2sEAFARZ8l9nxYsi9aD0O1
GnVW7gb0V1sS7OLOd2Fftwcsgxyg
X-Google-Smtp-Source: AIpwx4/oY4m2HwxMyvGLAj+2tbVakT3FrGzyS6bEkmr9NPCzPqnlJdb/T4amk/58cr5Zt2qncYkw6w==
X-Received: by 10.223.141.143 with SMTP id o15mr13629629wrb.272.1522843393789;
Wed, 04 Apr 2018 05:03:13 -0700 (PDT)
Original-Received: from phst-glaptop.cm.cablesurf.de
([2001:4c50:25c:c900:2a16:adff:fe49:52c8])
by smtp.gmail.com with ESMTPSA id
n143sm4848233wmd.29.2018.04.04.05.03.12
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Wed, 04 Apr 2018 05:03:12 -0700 (PDT)
X-Google-Original-From: Philipp Stephani
X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog
In-Reply-To: <20180404120218.257212-1-phst@google.com>
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
recognized.
X-Received-From: 2a00:1450:400c:c0c::233
X-BeenThere: emacs-devel@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: "Emacs development discussions."
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org
Original-Sender: "Emacs-devel"
Xref: news.gmane.org gmane.emacs.devel:224315
Archived-At:
* src/process.c (Fmake_process): Inherit output coding system to
newly-created pipe process.
* test/src/process-tests.el (make-process/stderr-coding)
(make-process/mixed-output-coding): New unit tests.
---
src/process.c | 7 ++++
test/src/process-tests.el | 76 +++++++++++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+)
diff --git a/src/process.c b/src/process.c
index dcc9dcb31e..2b3e00d423 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1698,12 +1698,15 @@ usage: (make-process &rest ARGS) */)
bool query_on_exit = NILP (Fplist_get (contact, QCnoquery));
stderrproc = Qnil;
+ bool stderr_inherit_coding_system;
xstderr = Fplist_get (contact, QCstderr);
if (PROCESSP (xstderr))
{
if (!PIPECONN_P (xstderr))
error ("Process is not a pipe process");
stderrproc = xstderr;
+ /* Use the coding system passed to `make-pipe-process'. */
+ stderr_inherit_coding_system = false;
}
else if (!NILP (xstderr))
{
@@ -1717,6 +1720,8 @@ usage: (make-process &rest ARGS) */)
query_on_exit ? Qnil : Qt,
QCsentinel,
Qignore);
+ /* Inherit the output coding system from the main process. */
+ stderr_inherit_coding_system = true;
}
proc = make_process (name);
@@ -1808,6 +1813,8 @@ usage: (make-process &rest ARGS) */)
val = XCAR (Vdefault_process_coding_system);
}
pset_decode_coding_system (XPROCESS (proc), val);
+ if (stderr_inherit_coding_system)
+ Fset_process_coding_system (stderrproc, val, Qno_conversion);
if (!NILP (tem))
{
diff --git a/test/src/process-tests.el b/test/src/process-tests.el
index 838ba78acb..828f4207e1 100644
--- a/test/src/process-tests.el
+++ b/test/src/process-tests.el
@@ -217,5 +217,81 @@ process-test-sentinel-wait-function-working-p
(should (eq (process-exit-status process) 0))
(should (equal (buffer-string) "stderr\n")))))
+(ert-deftest make-process/stderr-coding ()
+ "Check that `make-process' correctly encodes standard error."
+ (skip-unless (executable-find shell-file-name))
+ ;; The byte sequences printed to standard output and error are valid
+ ;; UTF-8 code unit sequences for "ä" and "ö", respectively.
+ ;; However, `make-process' should decode them both using
+ ;; `iso-latin-1-dos', as specified below.
+ (with-temp-buffer
+ (let ((stdout (current-buffer))
+ ;; `coding-system-for-read' should be ignored.
+ (coding-system-for-read 'utf-8-unix))
+ (with-temp-buffer
+ (let ((process (make-process
+ :name "stderr-coding"
+ :command (list shell-file-name shell-command-switch
+ (concat "echo -e '\\xC3\\xA4\\r'; "
+ "echo -e '\\xC3\\xB6\\r' >&2"))
+ :buffer stdout
+ :stderr (current-buffer)
+ :sentinel #'ignore
+ :coding 'iso-latin-1-dos
+ :noquery t
+ :connection-type 'pipe)))
+ (while (process-live-p process)
+ (accept-process-output process))
+ (let ((stderr-process (get-buffer-process (current-buffer))))
+ ;; FIXME: The following form should not be required.
+ (while (process-live-p stderr-process)
+ (accept-process-output stderr-process)))
+ (should (eq (process-status process) 'exit))
+ (should (eq (process-exit-status process) 0))
+ (should (equal (buffer-string) "\u00C3\u00B6\n"))))
+ (should (equal (buffer-string) "\u00C3\u00A4\n")))))
+
+(ert-deftest make-process/mixed-output-coding ()
+ "Check that `make-process' allows different coding systems for
+the output streams."
+ (skip-unless (executable-find shell-file-name))
+ ;; The byte sequences printed to standard output and error are valid
+ ;; UTF-8 code unit sequences for "ä" and "ö", respectively.
+ ;; However, `make-process' should decode them using the coding
+ ;; systems passed to `make-process' and `make-pipe-process',
+ ;; respectively.
+ (with-temp-buffer
+ (let ((stdout (current-buffer))
+ ;; `coding-system-for-read' should be ignored.
+ (coding-system-for-read 'utf-8-unix))
+ (with-temp-buffer
+ (let* ((stderr-process (make-pipe-process
+ :name "stderr-coding stderr"
+ :buffer (current-buffer)
+ :sentinel #'ignore
+ :coding 'iso-latin-1-unix
+ :noquery t))
+ (process (make-process
+ :name "stderr-coding"
+ :command (list shell-file-name shell-command-switch
+ (concat "echo -e '\\xC3\\xA4\\r'; "
+ "echo -e '\\xC3\\xB6\\r' >&2"))
+ :buffer stdout
+ :stderr stderr-process
+ :sentinel #'ignore
+ :coding 'iso-latin-1-dos
+ :noquery t
+ :connection-type 'pipe)))
+ (while (process-live-p process)
+ (accept-process-output process))
+ ;; FIXME: Should the following be required?
+ (while (process-live-p stderr-process)
+ (accept-process-output stderr-process))
+ (should (eq (process-status process) 'exit))
+ (should (eq (process-exit-status process) 0))
+ (should (eq (process-status stderr-process) 'closed))
+ (should (equal (buffer-string) "\u00C3\u00B6\r\n"))))
+ (should (equal (buffer-string) "\u00C3\u00A4\n")))))
+
(provide 'process-tests)
;; process-tests.el ends here.
--
2.17.0.484.g0c8726318c-goog