From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: `scm_c_read ()' and `swap_buffer' trick harmful Date: Thu, 20 Nov 2008 14:48:29 +0100 Message-ID: <871vx6ik42.fsf@gnu.org> References: <87vduo92nj.fsf@gnu.org> <49dd78620811200522k315281c8m9d952a17145b2479@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1227188941 15235 80.91.229.12 (20 Nov 2008 13:49:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Nov 2008 13:49:01 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Nov 20 14:50:04 2008 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L39v0-00060Z-3X for guile-devel@m.gmane.org; Thu, 20 Nov 2008 14:50:03 +0100 Original-Received: from localhost ([127.0.0.1]:47969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L39tr-0008Lz-5S for guile-devel@m.gmane.org; Thu, 20 Nov 2008 08:48:51 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L39tk-0008Lc-3T for guile-devel@gnu.org; Thu, 20 Nov 2008 08:48:44 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L39th-0008Kx-UK for guile-devel@gnu.org; Thu, 20 Nov 2008 08:48:42 -0500 Original-Received: from [199.232.76.173] (port=58108 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L39th-0008Ks-HX for guile-devel@gnu.org; Thu, 20 Nov 2008 08:48:41 -0500 Original-Received: from main.gmane.org ([80.91.229.2]:48616 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L39th-0003j6-DO for guile-devel@gnu.org; Thu, 20 Nov 2008 08:48:41 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1L39tc-0002El-JG for guile-devel@gnu.org; Thu, 20 Nov 2008 13:48:36 +0000 Original-Received: from 193.50.110.60 ([193.50.110.60]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 20 Nov 2008 13:48:36 +0000 Original-Received: from ludo by 193.50.110.60 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 20 Nov 2008 13:48:36 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 52 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 193.50.110.60 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 30 Brumaire an 217 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: i686-pc-linux-gnu User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) Cancel-Lock: sha1:4GkUxyAV2QkZJIAW64zZdnulhOk= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:7869 Archived-At: Hello Neil, "Neil Jerram" writes: > 2008/11/15 Ludovic Courtès : >> >> So where to go from here? I think this example shows that the >> `swap_buffer' trick is too risky, unfortunately. Thus, we may need to >> revert it, at least in 1.8. Second, I think that a `read' method as a >> replacement for `fill_input', as I proposed back then [3], would be >> safer; maybe 1.9 would be a nice place to add it. Neil: what do you >> think? > > I think this means we should only do the swap_buffer trick for > unbuffered ports. That would solve the original problem, and avoid > breaking cases like this. In theory, yes. In practice, the notion of "unbuffered port" is ill-defined, I'm afraid. The `SCM_BUF0' flag probably can't be relied on, as it appears to be only really used on `fports.c'. Actually, for some reason (probably copy & paste), make_cbip() creates ports with "SCM_OPN | SCM_RDNG | SCM_BUF0", although `SCM_BUF0' is probably not needed. So I think "unbuffered port" means "read_buf_size <= 1". > It _could_ be argued that cbip_fill_input() should take more care to > use the port's actual current buffer. e.g. it should construct a new > R6RS bytevector around the current port->read_buf, and pass that to > the read! procedure. But I'm not going to argue that, because the > generalization of that would be to say that C code that implements a > buffered port cannot assume that the buffer stays as originally set; > and, with hindsight, it seems that C code _should_ be able to rely on > this. (Plus constructing a new bytevector would probably be bad for > performance.) Exactly: it's nice to be able to avoid the allocation of a new bytevector. > I recall you queried before whether we should apply this fix to > buffered ports too, and I confidently said yes; sorry about that! No problem. The port "API" exposes too much internals, which makes it hard to change it without breaking existing code. > Do you agree that doing the trick only for unbuffered ports would be a > good approach? If so I'll see what that means in terms of code. I think it *should* work, provided `SCM_BUF0' isn't relied on (at least for the particular case I'm interested in...). Thanks! Ludo'.