unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Rob Browning <rlb@defaultvalue.org>
To: guile-devel@gnu.org
Subject: [PATCH 1/1] scm_i_make_transcoded_port: fix mode for input/output ports
Date: Sun,  4 Oct 2020 14:37:48 -0500	[thread overview]
Message-ID: <20201004193748.277642-1-rlb@defaultvalue.org> (raw)

* libguile/r6rs-ports.c (scm_i_make_transcoded_ports): make sure to
  include SCM_RDNG for input/output ports.

Thanks to Göran Weinholt for reporting the problem.

Closes: 41045
---

 Proposed for 3.0.

 libguile/r6rs-ports.c            |  4 ++--
 test-suite/tests/r6rs-ports.test | 26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/libguile/r6rs-ports.c b/libguile/r6rs-ports.c
index 445ae5464..49ca05325 100644
--- a/libguile/r6rs-ports.c
+++ b/libguile/r6rs-ports.c
@@ -1168,8 +1168,8 @@ SCM_DEFINE (scm_i_make_transcoded_port,
 
   if (scm_is_true (scm_output_port_p (port)))
     mode |= SCM_WRTNG;
-  else if (scm_is_true (scm_input_port_p (port)))
-    mode |=  SCM_RDNG;
+  if (scm_is_true (scm_input_port_p (port)))
+    mode |= SCM_RDNG;
   
   result = make_transcoded_port (port, mode);
 
diff --git a/test-suite/tests/r6rs-ports.test b/test-suite/tests/r6rs-ports.test
index 5b46cccd2..4d1981df2 100644
--- a/test-suite/tests/r6rs-ports.test
+++ b/test-suite/tests/r6rs-ports.test
@@ -919,6 +919,32 @@ not `set-port-position!'"
 \f
 (with-test-prefix "8.2.6  Input and output ports"
 
+  (define (check-transcoded-port-mode make-port pred)
+    (let ((p (make-port "/dev/null" (file-options no-fail))))
+      (dynamic-wind
+        (lambda () #t)
+        (lambda ()
+          (set! p (transcoded-port p (native-transcoder)))
+          (pred p))
+        (lambda () (close-port p)))))
+
+  (pass-if "transcoded-port preserves input mode"
+    (check-transcoded-port-mode open-file-input-port
+                                (lambda (p)
+                                  (and (input-port? p)
+                                       (not (output-port? p))))))
+
+  (pass-if "transcoded-port preserves output mode"
+    (check-transcoded-port-mode open-file-output-port
+                                (lambda (p)
+                                  (and (not (input-port? p))
+                                       (output-port? p)))))
+
+  (pass-if "transcoded-port preserves input/output mode"
+    (check-transcoded-port-mode open-file-input/output-port
+                                (lambda (p)
+                                  (and (input-port? p) (output-port? p)))))
+
   (pass-if "transcoded-port [output]"
     (let ((s "Hello\nÄÖÜ"))
       (bytevector=?
-- 
2.26.1




                 reply	other threads:[~2020-10-04 19:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=20201004193748.277642-1-rlb@defaultvalue.org \
    --to=rlb@defaultvalue.org \
    --cc=guile-devel@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).