From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.lisp.guile.bugs Subject: bug#20200: 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> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1427294016 8379 80.91.229.3 (25 Mar 2015 14:33:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 25 Mar 2015 14:33:36 +0000 (UTC) To: 20200@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Mar 25 15:33:27 2015 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YamMz-0000YS-AN for guile-bugs@m.gmane.org; Wed, 25 Mar 2015 15:33:21 +0100 Original-Received: from localhost ([::1]:39394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamMt-0005Ub-Kg for guile-bugs@m.gmane.org; Wed, 25 Mar 2015 10:33:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamMm-0005UR-Go for bug-guile@gnu.org; Wed, 25 Mar 2015 10:33:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YamMg-0005Aw-R0 for bug-guile@gnu.org; Wed, 25 Mar 2015 10:33:08 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:46718) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YamMg-0005As-OJ for bug-guile@gnu.org; Wed, 25 Mar 2015 10:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YamMg-00004w-Fq for bug-guile@gnu.org; Wed, 25 Mar 2015 10:33:02 -0400 X-Loop: help-debbugs@gnu.org 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: X-Debbugs-Original-To: bug-guile@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.142729392732701 (code B ref -1); Wed, 25 Mar 2015 14:33:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 25 Mar 2015 14:32:07 +0000 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-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 Original-Received: by lola (Postfix, from userid 1000) id C2609EC89C; Wed, 25 Mar 2015 15:31:32 +0100 (CET) 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7755 Archived-At: --=-=-= 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 --=-=-=--