From unknown Sat Jun 21 05:16:58 2025 X-Loop: help-debbugs@gnu.org Subject: bug#20200: GUILE 2.0.11: open-bytevector-input-port fails to open in binary mode Resent-From: David Kastrup Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 25 Mar 2015 14:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 20200 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 20200@debbugs.gnu.org X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.142729392732701 (code B ref -1); Wed, 25 Mar 2015 14:33:02 +0000 Received: (at submit) by debbugs.gnu.org; 25 Mar 2015 14:32:07 +0000 Received: from localhost ([127.0.0.1]:36494 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YamLi-0008VH-Ev for submit@debbugs.gnu.org; Wed, 25 Mar 2015 10:32:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53644) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YamLb-0008UR-H2 for submit@debbugs.gnu.org; Wed, 25 Mar 2015 10:32:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YamLR-0004rF-9T for submit@debbugs.gnu.org; Wed, 25 Mar 2015 10:31:50 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamLR-0004rB-7J for submit@debbugs.gnu.org; Wed, 25 Mar 2015 10:31:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamLK-0004tY-QB for bug-guile@gnu.org; Wed, 25 Mar 2015 10:31:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YamLF-0004nv-Pb for bug-guile@gnu.org; Wed, 25 Mar 2015 10:31:38 -0400 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54891) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamLF-0004nd-N1 for bug-guile@gnu.org; Wed, 25 Mar 2015 10:31:33 -0400 Received: from localhost ([127.0.0.1]:33834 helo=lola) by fencepost.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamLF-0004fy-6n for bug-guile@gnu.org; Wed, 25 Mar 2015 10:31:33 -0400 Received: by lola (Postfix, from userid 1000) id C2609EC89C; Wed, 25 Mar 2015 15:31:32 +0100 (CET) From: David Kastrup Date: Wed, 25 Mar 2015 15:31:32 +0100 Message-ID: <871tkd9mij.fsf@fencepost.gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) --=-=-= Content-Type: text/plain Run the following code in an UTF-8 capable locale: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=bad.scm (setlocale LC_ALL "") (use-modules (rnrs io ports) (rnrs bytevectors) (ice-9 format)) (let ((p (open-bytevector-input-port (u8-list->bytevector '(#xc3 #x9f #xc3 #X9f))))) (format #t "~a ~a\n" (port-encoding p) (binary-port? p)) (format #t "#x~x\n" (char->integer (read-char p))) (format #t "~a ~a\n" (port-encoding p) (binary-port? p)) (set-port-encoding! p "ISO-8859-1") (format #t "~a ~a\n" (port-encoding p) (binary-port? p)) (format #t "#x~x\n" (char->integer (read-char p))) (format #t "~a ~a\n" (port-encoding p) (binary-port? p))) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable This results in the output #f #t #xdf #f #t ISO-8859-1 #f #xc3 ISO-8859-1 #f The manual, however, states: -- Scheme Procedure: port-encoding port -- C Function: scm_port_encoding (port) Returns, as a string, the character encoding that PORT uses to interpret its input and output. The value =E2=80=98#f=E2=80=99 is equ= ivalent to =E2=80=98"ISO-8859-1"=E2=80=99. That would appear to be false since the value #f here is treated as equivalent to "UTF-8" rather than "ISO-8859-1". In addition, the manual states -- Scheme Procedure: binary-port? port Return =E2=80=98#t=E2=80=99 if PORT is a "binary port", suitable for b= inary data input/output. Note that internally Guile does not differentiate between binary and textual ports, unlike the R6RS. Thus, this procedure returns true when PORT does not have an associated encoding=E2=80=94i.e., when =E2=80=98(port-encoding PORT)=E2=80=99 is =E2=80=98#f=E2=80=99 (*note = port-encoding: Ports.). This is the case for ports returned by R6RS procedures such as =E2=80=98open-bytevector-input-port=E2=80=99 and =E2=80=98make-custom-= binary-output-port=E2=80=99. However, Guile currently does not prevent use of textual I/O procedures such as =E2=80=98display=E2=80=99 or =E2=80=98read-char=E2= =80=99 with binary ports. Doing so =E2=80=9Cupgrades=E2=80=9D the port from binary to textual, u= nder the ISO-8859-1 encoding. Likewise, Guile does not prevent use of =E2=80=98set-port-encoding!=E2=80=99 on a binary port, which also turn= s it into a =E2=80=9Ctextual=E2=80=9D port. But it would appear that the only way to actually get binary-encoded read-char behavior is to switch the port to textual. While the port is in "binary" mode, it will decode as utf-8 rather than deliver binary data. Also it will not automagically switch itself away from the nominal #f encoding which is not actually present. Putting (with-fluids ((%default-port-encoding #f)) ...) around the open-bytevector-input-port call results in the output #f #t #xc3 ISO-8859-1 #f ISO-8859-1 #f #x9f ISO-8859-1 #f which actually corresponds to the documentation. --=20 David Kastrup --=-=-=-- From unknown Sat Jun 21 05:16:58 2025 X-Loop: help-debbugs@gnu.org Subject: bug#20200: GUILE 2.0.11: open-bytevector-input-port fails to open in binary mode Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 26 Mar 2015 22:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20200 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: David Kastrup Cc: 20200@debbugs.gnu.org Received: via spool by 20200-submit@debbugs.gnu.org id=B20200.142741065232282 (code B ref 20200); Thu, 26 Mar 2015 22:58:01 +0000 Received: (at 20200) by debbugs.gnu.org; 26 Mar 2015 22:57:32 +0000 Received: from localhost ([127.0.0.1]:37666 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YbGiS-0008Oc-20 for submit@debbugs.gnu.org; Thu, 26 Mar 2015 18:57:32 -0400 Received: from world.peace.net ([50.252.239.5]:38829 ident=hope6) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YbGiQ-0008OS-IM for 20200@debbugs.gnu.org; Thu, 26 Mar 2015 18:57:31 -0400 Received: from [10.1.10.78] (helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1YbGiJ-00037a-EU; Thu, 26 Mar 2015 18:57:23 -0400 From: Mark H Weaver References: <871tkd9mij.fsf@fencepost.gnu.org> Date: Thu, 26 Mar 2015 18:57:53 -0400 In-Reply-To: <871tkd9mij.fsf@fencepost.gnu.org> (David Kastrup's message of "Wed, 25 Mar 2015 15:31:32 +0100") Message-ID: <87iodn8iz2.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) David Kastrup writes: > Run the following code in an UTF-8 capable locale: > > (setlocale LC_ALL "") > (use-modules (rnrs io ports) (rnrs bytevectors) (ice-9 format)) > (let ((p (open-bytevector-input-port > (u8-list->bytevector '(#xc3 #x9f #xc3 #X9f))))) > (format #t "~a ~a\n" (port-encoding p) (binary-port? p)) > (format #t "#x~x\n" (char->integer (read-char p))) > (format #t "~a ~a\n" (port-encoding p) (binary-port? p)) > (set-port-encoding! p "ISO-8859-1") > (format #t "~a ~a\n" (port-encoding p) (binary-port? p)) > (format #t "#x~x\n" (char->integer (read-char p))) > (format #t "~a ~a\n" (port-encoding p) (binary-port? p))) > > This results in the output > #f #t > #xdf > #f #t > ISO-8859-1 #f > #xc3 > ISO-8859-1 #f > > The manual, however, states: > > -- Scheme Procedure: port-encoding port > -- C Function: scm_port_encoding (port) > Returns, as a string, the character encoding that PORT uses to > interpret its input and output. The value =E2=80=98#f=E2=80=99 is e= quivalent to > =E2=80=98"ISO-8859-1"=E2=80=99. > > That would appear to be false since the value #f here is treated as > equivalent to "UTF-8" rather than "ISO-8859-1". This is indeed a bug, introduced in Guile 2.0.9. The workaround is to explicitly set the encoding to "ISO-8859-1". Mark From unknown Sat Jun 21 05:16:58 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.503 (Entity 5.503) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: David Kastrup Subject: bug#20200: closed (Re: bug#20200: GUILE 2.0.11: open-bytevector-input-port fails to open in binary mode) Message-ID: References: <87lhigc22j.fsf@netris.org> <871tkd9mij.fsf@fencepost.gnu.org> X-Gnu-PR-Message: they-closed 20200 X-Gnu-PR-Package: guile Reply-To: 20200@debbugs.gnu.org Date: Sat, 28 Mar 2015 20:14:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1427573642-5348-1" This is a multi-part message in MIME format... ------------=_1427573642-5348-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #20200: GUILE 2.0.11: open-bytevector-input-port fails to open in binary mo= de which was filed against the guile package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 20200@debbugs.gnu.org. --=20 20200: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D20200 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1427573642-5348-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 20200-done) by debbugs.gnu.org; 28 Mar 2015 20:13:33 +0000 Received: from localhost ([127.0.0.1]:39114 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ybx6r-0001NN-5B for submit@debbugs.gnu.org; Sat, 28 Mar 2015 16:13:33 -0400 Received: from world.peace.net ([50.252.239.5]:47632 ident=hope6) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ybx6o-0001NF-TI for 20200-done@debbugs.gnu.org; Sat, 28 Mar 2015 16:13:31 -0400 Received: from [10.1.10.78] (helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1Ybx6i-0007qV-V8; Sat, 28 Mar 2015 16:13:25 -0400 From: Mark H Weaver To: David Kastrup Subject: Re: bug#20200: GUILE 2.0.11: open-bytevector-input-port fails to open in binary mode References: <871tkd9mij.fsf@fencepost.gnu.org> <87iodn8iz2.fsf@netris.org> Date: Sat, 28 Mar 2015 16:13:56 -0400 In-Reply-To: <87iodn8iz2.fsf@netris.org> (Mark H. Weaver's message of "Thu, 26 Mar 2015 18:57:53 -0400") Message-ID: <87lhigc22j.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 20200-done Cc: 20200-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Fixed in d574d96f879c147c6c14df43f2e4ff9e8a6876b9, which will be in Guile 2.0.12. I'm closing this bug now. Thanks, Mark ------------=_1427573642-5348-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 25 Mar 2015 14:32:07 +0000 Received: from localhost ([127.0.0.1]:36494 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YamLi-0008VH-Ev for submit@debbugs.gnu.org; Wed, 25 Mar 2015 10:32:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53644) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YamLb-0008UR-H2 for submit@debbugs.gnu.org; Wed, 25 Mar 2015 10:32:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YamLR-0004rF-9T for submit@debbugs.gnu.org; Wed, 25 Mar 2015 10:31:50 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:36894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamLR-0004rB-7J for submit@debbugs.gnu.org; Wed, 25 Mar 2015 10:31:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamLK-0004tY-QB for bug-guile@gnu.org; Wed, 25 Mar 2015 10:31:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YamLF-0004nv-Pb for bug-guile@gnu.org; Wed, 25 Mar 2015 10:31:38 -0400 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54891) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamLF-0004nd-N1 for bug-guile@gnu.org; Wed, 25 Mar 2015 10:31:33 -0400 Received: from localhost ([127.0.0.1]:33834 helo=lola) by fencepost.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamLF-0004fy-6n for bug-guile@gnu.org; Wed, 25 Mar 2015 10:31:33 -0400 Received: by lola (Postfix, from userid 1000) id C2609EC89C; Wed, 25 Mar 2015 15:31:32 +0100 (CET) From: David Kastrup To: bug-guile@gnu.org Subject: GUILE 2.0.11: open-bytevector-input-port fails to open in binary mode Date: Wed, 25 Mar 2015 15:31:32 +0100 Message-ID: <871tkd9mij.fsf@fencepost.gnu.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) --=-=-= Content-Type: text/plain Run the following code in an UTF-8 capable locale: --=-=-= Content-Type: text/plain Content-Disposition: inline; filename=bad.scm (setlocale LC_ALL "") (use-modules (rnrs io ports) (rnrs bytevectors) (ice-9 format)) (let ((p (open-bytevector-input-port (u8-list->bytevector '(#xc3 #x9f #xc3 #X9f))))) (format #t "~a ~a\n" (port-encoding p) (binary-port? p)) (format #t "#x~x\n" (char->integer (read-char p))) (format #t "~a ~a\n" (port-encoding p) (binary-port? p)) (set-port-encoding! p "ISO-8859-1") (format #t "~a ~a\n" (port-encoding p) (binary-port? p)) (format #t "#x~x\n" (char->integer (read-char p))) (format #t "~a ~a\n" (port-encoding p) (binary-port? p))) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable This results in the output #f #t #xdf #f #t ISO-8859-1 #f #xc3 ISO-8859-1 #f The manual, however, states: -- Scheme Procedure: port-encoding port -- C Function: scm_port_encoding (port) Returns, as a string, the character encoding that PORT uses to interpret its input and output. The value =E2=80=98#f=E2=80=99 is equ= ivalent to =E2=80=98"ISO-8859-1"=E2=80=99. That would appear to be false since the value #f here is treated as equivalent to "UTF-8" rather than "ISO-8859-1". In addition, the manual states -- Scheme Procedure: binary-port? port Return =E2=80=98#t=E2=80=99 if PORT is a "binary port", suitable for b= inary data input/output. Note that internally Guile does not differentiate between binary and textual ports, unlike the R6RS. Thus, this procedure returns true when PORT does not have an associated encoding=E2=80=94i.e., when =E2=80=98(port-encoding PORT)=E2=80=99 is =E2=80=98#f=E2=80=99 (*note = port-encoding: Ports.). This is the case for ports returned by R6RS procedures such as =E2=80=98open-bytevector-input-port=E2=80=99 and =E2=80=98make-custom-= binary-output-port=E2=80=99. However, Guile currently does not prevent use of textual I/O procedures such as =E2=80=98display=E2=80=99 or =E2=80=98read-char=E2= =80=99 with binary ports. Doing so =E2=80=9Cupgrades=E2=80=9D the port from binary to textual, u= nder the ISO-8859-1 encoding. Likewise, Guile does not prevent use of =E2=80=98set-port-encoding!=E2=80=99 on a binary port, which also turn= s it into a =E2=80=9Ctextual=E2=80=9D port. But it would appear that the only way to actually get binary-encoded read-char behavior is to switch the port to textual. While the port is in "binary" mode, it will decode as utf-8 rather than deliver binary data. Also it will not automagically switch itself away from the nominal #f encoding which is not actually present. Putting (with-fluids ((%default-port-encoding #f)) ...) around the open-bytevector-input-port call results in the output #f #t #xc3 ISO-8859-1 #f ISO-8859-1 #f #x9f ISO-8859-1 #f which actually corresponds to the documentation. --=20 David Kastrup --=-=-=-- ------------=_1427573642-5348-1--