emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master d08e81c: Make make-{network, serial}-process handle :coding nil c


From: Robert Pluim
Subject: master d08e81c: Make make-{network, serial}-process handle :coding nil consistently
Date: Fri, 3 Apr 2020 08:48:33 -0400 (EDT)

branch: master
commit d08e81ce5a19a0394c2efbdfeb4ebb246d609635
Author: Robert Pluim <address@hidden>
Commit: Robert Pluim <address@hidden>

    Make make-{network,serial}-process handle :coding nil consistently
    
    The handling of :coding nil was different between
    make-{network,serial}-process and make-{pipe}process.  Now they all
    handle :coding nil as if :coding had not been specified.
    
    * process.c (Fmake_serial_process)
    (set_network_socket_coding_system): Use plist-get to check if
    :coding has been specified instead of plist-member, to ensure that
    ":coding nil" does not override coding-system-for-{read,write}.
    
    * network-stream-tests.el (check-network-process-coding-system-bind)
    (check-network-process-coding-system-no-override)
    (check-network-process-coding-system-override): New tests.
    
    * etc/NEWS: Describe change in make-network-process and
    make-serial-process :coding behavior.
---
 etc/NEWS                              | 10 +++++++
 src/process.c                         | 16 ++++-------
 test/lisp/net/network-stream-tests.el | 52 +++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 91729e4..fa33364 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -317,6 +317,16 @@ optional argument specifying whether to follow symbolic 
links.
 ** 'parse-time-string' can now parse ISO 8601 format strings,
 such as "2020-01-15T16:12:21-08:00".
 
+---
+** 'make-network-process', 'make-serial-process' :coding behavior change.
+Previously, passing ":coding nil" to either of these functions would
+override any non-nil binding for 'coding-system-for-read' and
+'coding-system-for-write'.  For consistency with 'make-process' and
+'make-pipe-process', passing ":coding nil" is now ignored.  No code in
+Emacs depended on the previous behavior; if you really want the
+process' coding-system to be nil, use 'set-process-coding-system'
+after the process has been created, or pass in ":coding '(nil nil)".
+
 
 * Changes in Emacs 28.1 on Non-Free Operating Systems
 
diff --git a/src/process.c b/src/process.c
index 07881d6..e6d18fb 100644
--- a/src/process.c
+++ b/src/process.c
@@ -3188,14 +3188,12 @@ usage:  (make-serial-process &rest ARGS)  */)
                       BUF_ZV_BYTE (XBUFFER (buffer)));
     }
 
-  tem = Fplist_member (contact, QCcoding);
-  if (!NILP (tem) && (!CONSP (tem) || !CONSP (XCDR (tem))))
-    tem = Qnil;
+  tem = Fplist_get (contact, QCcoding);
 
   val = Qnil;
   if (!NILP (tem))
     {
-      val = XCAR (XCDR (tem));
+      val = tem;
       if (CONSP (val))
        val = XCAR (val);
     }
@@ -3209,7 +3207,7 @@ usage:  (make-serial-process &rest ARGS)  */)
   val = Qnil;
   if (!NILP (tem))
     {
-      val = XCAR (XCDR (tem));
+      val = tem;
       if (CONSP (val))
        val = XCDR (val);
     }
@@ -3244,16 +3242,14 @@ set_network_socket_coding_system (Lisp_Object proc, 
Lisp_Object host,
   Lisp_Object coding_systems = Qt;
   Lisp_Object val;
 
-  tem = Fplist_member (contact, QCcoding);
-  if (!NILP (tem) && (!CONSP (tem) || !CONSP (XCDR (tem))))
-    tem = Qnil;  /* No error message (too late!).  */
+  tem = Fplist_get (contact, QCcoding);
 
   /* Setup coding systems for communicating with the network stream.  */
   /* Qt denotes we have not yet called Ffind_operation_coding_system.  */
 
   if (!NILP (tem))
     {
-      val = XCAR (XCDR (tem));
+      val = tem;
       if (CONSP (val))
        val = XCAR (val);
     }
@@ -3287,7 +3283,7 @@ set_network_socket_coding_system (Lisp_Object proc, 
Lisp_Object host,
 
   if (!NILP (tem))
     {
-      val = XCAR (XCDR (tem));
+      val = tem;
       if (CONSP (val))
        val = XCDR (val);
     }
diff --git a/test/lisp/net/network-stream-tests.el 
b/test/lisp/net/network-stream-tests.el
index 2868654..7a98254 100644
--- a/test/lisp/net/network-stream-tests.el
+++ b/test/lisp/net/network-stream-tests.el
@@ -724,4 +724,56 @@
     44777
     (vector :nowait t))))
 
+(ert-deftest check-network-process-coding-system-bind ()
+  "Check that binding coding-system-for-{read,write} works."
+  (let* ((coding-system-for-read 'binary)
+         (coding-system-for-write 'utf-8-unix)
+         (server
+         (make-network-process
+          :name "server"
+          :server t
+          :noquery t
+          :family 'ipv4
+          :service t
+          :host 'local))
+         (coding (process-coding-system server)))
+    (should (eq (car coding) 'binary))
+    (should (eq (cdr coding) 'utf-8-unix))
+    (delete-process server)))
+
+(ert-deftest check-network-process-coding-system-no-override ()
+  "Check that coding-system-for-{read,write} is not overridden by :coding nil."
+  (let* ((coding-system-for-read 'binary)
+         (coding-system-for-write 'utf-8-unix)
+         (server
+         (make-network-process
+          :name "server"
+          :server t
+          :noquery t
+          :family 'ipv4
+          :service t
+          :coding nil
+          :host 'local))
+         (coding (process-coding-system server)))
+    (should (eq (car coding) 'binary))
+    (should (eq (cdr coding) 'utf-8-unix))
+    (delete-process server)))
+
+(ert-deftest check-network-process-coding-system-override ()
+  "Check that :coding non-nil overrides coding-system-for-{read,write}."
+  (let* ((coding-system-for-read 'binary)
+         (coding-system-for-write 'utf-8-unix)
+         (server
+         (make-network-process
+          :name "server"
+          :server t
+          :noquery t
+          :family 'ipv4
+          :service t
+          :coding 'georgian-academy
+          :host 'local))
+         (coding (process-coding-system server)))
+    (should (eq (car coding) 'georgian-academy))
+    (should (eq (cdr coding) 'georgian-academy))
+    (delete-process server)))
 ;;; network-stream-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]