From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.bugs Subject: bug#18520: string ports should not have an encoding Date: Tue, 23 Sep 2014 18:01:28 +0200 Message-ID: <87tx3yfhrb.fsf@gnu.org> References: <87iokgmttc.fsf@fencepost.gnu.org> <87mw9rq20u.fsf@gnu.org> <87sijjlqx0.fsf@fencepost.gnu.org> <87sijjmvlr.fsf@gnu.org> <87bnq7lgg9.fsf@fencepost.gnu.org> <87d2anl79a.fsf@gnu.org> <87tx3zjod1.fsf@fencepost.gnu.org> <87egv2pwv5.fsf@gnu.org> <87lhpak8ye.fsf@fencepost.gnu.org> <87bnq6oelf.fsf@gnu.org> <87h9zyk0wo.fsf@fencepost.gnu.org> <87tx3yjzzw.fsf@gnu.org> <87d2amjxq9.fsf@fencepost.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1411488426 5908 80.91.229.3 (23 Sep 2014 16:07:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 23 Sep 2014 16:07:06 +0000 (UTC) Cc: 18520@debbugs.gnu.org To: David Kastrup Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Tue Sep 23 18:06:59 2014 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 1XWSXq-0002QM-T4 for guile-bugs@m.gmane.org; Tue, 23 Sep 2014 18:02:27 +0200 Original-Received: from localhost ([::1]:54193 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWSXp-0004WO-I7 for guile-bugs@m.gmane.org; Tue, 23 Sep 2014 12:02:25 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38909) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWSXd-0004Mo-W7 for bug-guile@gnu.org; Tue, 23 Sep 2014 12:02:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XWSXX-0005ru-Uj for bug-guile@gnu.org; Tue, 23 Sep 2014 12:02:13 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:58565) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWSXX-0005ou-Ro for bug-guile@gnu.org; Tue, 23 Sep 2014 12:02:07 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XWSXS-00068Q-7Y for bug-guile@gnu.org; Tue, 23 Sep 2014 12:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 23 Sep 2014 16:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18520 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 18520-submit@debbugs.gnu.org id=B18520.141148809223546 (code B ref 18520); Tue, 23 Sep 2014 16:02:02 +0000 Original-Received: (at 18520) by debbugs.gnu.org; 23 Sep 2014 16:01:32 +0000 Original-Received: from localhost ([127.0.0.1]:50129 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XWSWx-00067h-Dw for submit@debbugs.gnu.org; Tue, 23 Sep 2014 12:01:31 -0400 Original-Received: from hera.aquilenet.fr ([141.255.128.1]:56945) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XWSWu-00065W-6R for 18520@debbugs.gnu.org; Tue, 23 Sep 2014 12:01:29 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id D30053B12; Tue, 23 Sep 2014 18:01:26 +0200 (CEST) Original-Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X807WdqRWyhb; Tue, 23 Sep 2014 18:01:26 +0200 (CEST) Original-Received: from pluto (pluto.bordeaux.inria.fr [193.50.110.57]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 95CF43A00; Tue, 23 Sep 2014 18:01:26 +0200 (CEST) X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 2 =?UTF-8?Q?Vend=C3=A9miaire?= an 223 de la =?UTF-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu In-Reply-To: <87d2amjxq9.fsf@fencepost.gnu.org> (David Kastrup's message of "Tue, 23 Sep 2014 15:02:54 +0200") User-Agent: Gnus/5.130011 (Ma Gnus v0.11) Emacs/24.3 (gnu/linux) 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:7584 Archived-At: David Kastrup skribis: > They result in code like > > // we do our own utf8 encoding and verification in the parser, so we > // use the no-conversion equivalent of latin1 > SCM str =3D scm_from_latin1_string (c_str ()); > scm_dynwind_begin ((scm_t_dynwind_flags)0); > // Why doesn't scm_set_port_encoding_x work here? > scm_dynwind_fluid (ly_lily_module_constant ("%default-port-encoding"), = SCM_BOOL_F); > str_port_ =3D scm_open_input_string (str); > scm_dynwind_end (); > scm_set_port_filename_x (str_port_, ly_string2scm (name_)); > } So here =E2=80=98c_str=E2=80=99 returns a char * that is a UTF-8-encoded st= ring, right? In that case, it should be enough to do: /* Get a Scheme string from its UTF-8 representation. */ str =3D scm_from_utf8_string (c_str ()); /* Create an input string port. =E2=80=98read-char=E2=80=99 & co. will r= eturn each character from STR, one at a time. */ str_port =3D open_input_string (str); scm_set_port_filename_x (str_port, file); As long as textual I/O procedures are used on =E2=80=98str_port=E2=80=99, t= here=E2=80=99s no need to worry about its encoding. Now, to be able to use =E2=80=98ftell=E2=80=99 and assume it returns the po= sition as a number of bytes in the UTF-8 sequence, something like this should work (for 2.0; for 2.2 nothing special is needed): /* Get a Scheme string from its UTF-8 representation. */ str =3D scm_from_utf8_string (c_str ()); scm_dynwind_begin (0); /* Make sure the following string port uses UTF-8 as the internal encoding of its buffer. */ scm_dynwind_fluid (scm_public_ref ("guile", "%default-port-encoding"), scm_from_latin1_string ("UTF-8")); /* Create an input string port. =E2=80=98read-char=E2=80=99 & co. will r= eturn each character from STR, one at a time. */ str_port =3D open_input_string (str); scm_dynwind_end (); scm_set_port_filename_x (str_port, file); Does this help for LilyPond? Ludo=E2=80=99.