From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.bugs Subject: bug#20109: Incompatible API change in 2.0 series for string port encoding Date: Mon, 16 Mar 2015 16:46:47 -0400 Message-ID: <87vbi0zn48.fsf@netris.org> References: <87mw3eh04z.fsf@fencepost.gnu.org> <87zj7cznb5.fsf@netris.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1426538856 14828 80.91.229.3 (16 Mar 2015 20:47:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 16 Mar 2015 20:47:36 +0000 (UTC) Cc: 20109@debbugs.gnu.org To: David Kastrup Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Mon Mar 16 21:47:24 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 1YXbuw-0007M8-PO for guile-bugs@m.gmane.org; Mon, 16 Mar 2015 21:47:18 +0100 Original-Received: from localhost ([::1]:51601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXbuw-00017l-AW for guile-bugs@m.gmane.org; Mon, 16 Mar 2015 16:47:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXbuq-00017a-AL for bug-guile@gnu.org; Mon, 16 Mar 2015 16:47:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YXbug-0000tO-NA for bug-guile@gnu.org; Mon, 16 Mar 2015 16:47:12 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:50408) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YXbug-0000tI-JV for bug-guile@gnu.org; Mon, 16 Mar 2015 16:47:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YXbug-00023B-Al for bug-guile@gnu.org; Mon, 16 Mar 2015 16:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Mon, 16 Mar 2015 20:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20109 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 20109-submit@debbugs.gnu.org id=B20109.14265388007850 (code B ref 20109); Mon, 16 Mar 2015 20:47:02 +0000 Original-Received: (at 20109) by debbugs.gnu.org; 16 Mar 2015 20:46:40 +0000 Original-Received: from localhost ([127.0.0.1]:48976 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YXbuK-00022X-BT for submit@debbugs.gnu.org; Mon, 16 Mar 2015 16:46:40 -0400 Original-Received: from world.peace.net ([50.252.239.5]:60365) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YXbuI-00022P-M8 for 20109@debbugs.gnu.org; Mon, 16 Mar 2015 16:46:39 -0400 Original-Received: from c-98-217-13-77.hsd1.ma.comcast.net ([98.217.13.77] helo=jojen) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1YXbuB-0003mD-V2; Mon, 16 Mar 2015 16:46:32 -0400 In-Reply-To: <87zj7cznb5.fsf@netris.org> (Mark H. Weaver's message of "Mon, 16 Mar 2015 16:42:38 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (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:7751 Archived-At: Mark H Weaver writes: > David Kastrup writes: > >> In 2.0.9, the following patch/code for getting what amounts to a binary >> string port worked. >> >> commit 7f7a124d3470b0d566f796e88f4e2ad5aa043f16 >> Author: David Kastrup >> Date: Sun Sep 21 18:40:06 2014 +0200 >> >> Source_file::init_port: Keep GUILEv2 from redecoding string input >> >> diff --git a/lily/source-file.cc b/lily/source-file.cc >> index 1118b9d..75ed0d9 100644 >> --- a/lily/source-file.cc >> +++ b/lily/source-file.cc >> @@ -152,7 +152,11 @@ Source_file::init_port () >> // we do our own utf8 encoding and verification in the parser, so we >> // use the no-conversion equivalent of latin1 >> SCM str = scm_from_latin1_string (c_str ()); >> - str_port_ = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG, __FUNCTION__); >> + 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_ = scm_open_input_string (str); >> + scm_dynwind_end (); >> scm_set_port_filename_x (str_port_, ly_string2scm (name_)); >> } > > This hack of giving Guile a buffer containing UTF-8, but claiming that > it is Latin-1, is not good. It will cause Guile to see non-ASCII > characters as garbage. However, if you insist on doing this, I would > suggest using a bytevector input port instead, like this: (untested) > > char *buf = c_str (); > SCM bv = scm_c_make_bytevector (strlen (buf) + 1); > strcpy (SCM_BYTEVECTOR_CONTENTS (bv), buf); > str_port_ = scm_open_bytevector_input_port (bv, SCM_UNDEFINED); Sorry, the NUL terminator should not be included: char *buf = c_str (); size_t len = strlen (buf); SCM bv = scm_c_make_bytevector (len); memcpy (SCM_BYTEVECTOR_CONTENTS (bv), buf, len); str_port_ = scm_open_bytevector_input_port (bv, SCM_UNDEFINED); Mark