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#20209: GUILE 2.0.11: crash in set_port_filename_x for bytevector ports Date: Sat, 28 Mar 2015 14:21:00 -0400 Message-ID: <87y4mhasqb.fsf@netris.org> References: <87fv8r1pio.fsf@fencepost.gnu.org> <87egob8irs.fsf@netris.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1427566886 4421 80.91.229.3 (28 Mar 2015 18:21:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 28 Mar 2015 18:21:26 +0000 (UTC) Cc: 20209@debbugs.gnu.org To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=), David Kastrup Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sat Mar 28 19:21:15 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 1YbvM7-0001Q3-Ez for guile-bugs@m.gmane.org; Sat, 28 Mar 2015 19:21:11 +0100 Original-Received: from localhost ([::1]:54890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YbvM6-0005GK-NM for guile-bugs@m.gmane.org; Sat, 28 Mar 2015 14:21:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YbvM3-0005GD-5u for bug-guile@gnu.org; Sat, 28 Mar 2015 14:21:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YbvLz-0002Dg-32 for bug-guile@gnu.org; Sat, 28 Mar 2015 14:21:07 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49290) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YbvLy-0002Db-W4 for bug-guile@gnu.org; Sat, 28 Mar 2015 14:21:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YbvLy-00074k-KA for bug-guile@gnu.org; Sat, 28 Mar 2015 14:21: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: Sat, 28 Mar 2015 18:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20209 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 20209-submit@debbugs.gnu.org id=B20209.142756684027151 (code B ref 20209); Sat, 28 Mar 2015 18:21:02 +0000 Original-Received: (at 20209) by debbugs.gnu.org; 28 Mar 2015 18:20:40 +0000 Original-Received: from localhost ([127.0.0.1]:39066 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YbvLc-00073r-4r for submit@debbugs.gnu.org; Sat, 28 Mar 2015 14:20:40 -0400 Original-Received: from world.peace.net ([50.252.239.5]:47413 ident=hope3) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YbvLZ-00073h-TO for 20209@debbugs.gnu.org; Sat, 28 Mar 2015 14:20:39 -0400 Original-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 1YbvLR-0007OM-DL; Sat, 28 Mar 2015 14:20:29 -0400 In-Reply-To: <87egob8irs.fsf@netris.org> (Mark H. Weaver's message of "Thu, 26 Mar 2015 19:02:15 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (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:7760 Archived-At: Hi Ludovic, There's a problem with the C interfaces for bytevectors and binary ports, introduced in 1ee2c72eafaae5f91f4c899bc4b4853af5c16f28. Neither of those modules are initialized until the associated Scheme modules are loaded, but this is not documented. There are undocumented public C API functions 'scm_init_r6rs_ports' and 'scm_init_bytevectors', but if they are called and the associated Scheme modules (rnrs bytevectors) or (ice-9 binary-ports) are also loaded, then those initialization functions will be called more than once. In the case of 'scm_init_r6rs_ports', the duplicate initialization would cause 'scm_make_port_type' to be called more than once, leading to multiple copies of the same port types to be created. The snarfed code in r6rs-ports.x and bytevectors.x would also be run more than once. I don't know whether these duplicate initializations would cause problems, but it seems like a bad idea. Another issue is that 'scm_init_r6rs_ports' does not call 'scm_init_bytevectors', and yet that module calls C functions from bytevectors.c. For these reasons, I decided against recommending those undocumented initialization functions. Instead, I suggested that David initialize binary ports by loading (ice-9 binary-ports): (void) scm_c_resolve_module ("ice-9 binary-ports"); For Guile 2.0.12, I suggest that we unconditionally do the equivalent of 'scm_init_bytevectors' and 'scm_init_r6rs_ports' during Guile initialization, and make those functions into deprecated no-ops. What do you think? Mark Mark H Weaver writes: > David Kastrup writes: > >> The following code >> >> >> #include >> >> int main() >> { >> scm_init_guile (); >> SCM str = scm_c_make_bytevector (0); >> SCM port = scm_open_bytevector_input_port (str, SCM_UNDEFINED); >> scm_set_port_filename_x (port, scm_from_locale_string ("/usr/local/tmp/lilypond/ly/init.ly")); >> return 0; >> } >> >> >> crashes with the backtrace >> >> Program terminated with signal SIGSEGV, Segmentation fault. >> #0 0xb7699059 in scm_iprlist () from /usr/lib/libguile-2.0.so.22 >> (gdb) bt >> #0 0xb7699059 in scm_iprlist () from /usr/lib/libguile-2.0.so.22 >> #1 0xb7699e95 in ?? () from /usr/lib/libguile-2.0.so.22 >> #2 0xb7699153 in scm_iprlist () from /usr/lib/libguile-2.0.so.22 >> #3 0xb7699e95 in ?? () from /usr/lib/libguile-2.0.so.22 >> #4 0xb7699153 in scm_iprlist () from /usr/lib/libguile-2.0.so.22 >> #5 0xb7699e95 in ?? () from /usr/lib/libguile-2.0.so.22 >> #6 0xb7698ec9 in scm_prin1 () from /usr/lib/libguile-2.0.so.22 >> #7 0xb769a606 in scm_simple_format () from /usr/lib/libguile-2.0.so.22 >> #8 0xb76e5f0b in ?? () from /usr/lib/libguile-2.0.so.22 >> #9 0xb76e6539 in ?? () from /usr/lib/libguile-2.0.so.22 >> #10 0xb76e664c in scm_call_with_vm () from /usr/lib/libguile-2.0.so.22 >> #11 0xb764cc67 in scm_apply () from /usr/lib/libguile-2.0.so.22 >> #12 0xb764e90e in scm_apply_1 () from /usr/lib/libguile-2.0.so.22 >> #13 0xb76cdb7b in scm_throw () from /usr/lib/libguile-2.0.so.22 >> #14 0xb76ce04c in scm_ithrow () from /usr/lib/libguile-2.0.so.22 >> #15 0xb764b6a3 in scm_error_scm () from /usr/lib/libguile-2.0.so.22 >> #16 0xb764b778 in scm_error () from /usr/lib/libguile-2.0.so.22 >> #17 0xb764ba22 in scm_wrong_type_arg () from /usr/lib/libguile-2.0.so.22 >> #18 0xb76927ca in scm_set_port_filename_x () from /usr/lib/libguile-2.0.so.22 >> #19 0x08048723 in main () at nextbug.c:8 >> >> after outputting >> >> guile: uncaught throw to wrong-type-arg: (set-port-filename! Wrong >> type argument in position ~A: ~S (1 (Segmentation fault (core dumped) > > The problem turns out to be that binary ports are not initialized until > the (ice-9 binary-ports) module is loaded. As a result, the port > returned by 'scm_open_bytevector_input_port' has a bad type tag. > > The workaround is to call scm_c_resolve_module ("ice-9 binary-ports") > after initializing Guile before the first call to > 'scm_open_bytevector_input_port'. The following code works: > > #include > > int main() > { > scm_init_guile (); > (void) scm_c_resolve_module ("ice-9 binary-ports"); > SCM str = scm_c_make_bytevector (0); > SCM port = scm_open_bytevector_input_port (str, SCM_UNDEFINED); > scm_set_port_filename_x (port, scm_from_locale_string ("/usr/local/tmp/lilypond/ly/init.ly")); > return 0; > } > > Mark