GNU bug report logs - #10616
flush procedure for soft ports isn't called

Previous Next

Package: guile;

Reported by: Ian Price <ianprice90 <at> googlemail.com>

Date: Thu, 26 Jan 2012 22:19:01 UTC

Severity: normal

Done: Mark H Weaver <mhw <at> netris.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 10616 in the body.
You can then email your comments to 10616 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#10616; Package guile. (Thu, 26 Jan 2012 22:19:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ian Price <ianprice90 <at> googlemail.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Thu, 26 Jan 2012 22:19:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ian Price <ianprice90 <at> googlemail.com>
To: bug-guile <bug-guile <at> gnu.org>
Subject: flush procedure for soft ports isn't called
Date: Thu, 26 Jan 2012 22:10:37 +0000
Hi guilers,

I've noticed when trying to use soft ports that the 3rd procedure in the
vector doesn't get called when I use `force-output'. The simplest
example follows

scheme@(guile−user)> (let* ((port (make-soft-port
                                   (vector #f #f (lambda () 'flushed) #f #f)
                                   "rw")))
                       (force-output port))
scheme@(guile−user)> 

I have no issues with the other procedures. This is on current stable,
on 32 bit x86 running Fedora 16. More complicated examples available on
request.

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"




Information forwarded to bug-guile <at> gnu.org:
bug#10616; Package guile. (Fri, 27 Jan 2012 05:53:02 GMT) Full text and rfc822 format available.

Message #8 received at 10616 <at> debbugs.gnu.org (full text, mbox):

From: Ian Price <ianprice90 <at> googlemail.com>
To: 10616 <at> debbugs.gnu.org
Subject: Re: bug#10616: flush procedure for soft ports isn't called
Date: Fri, 27 Jan 2012 05:44:59 +0000
Ian Price <ianprice90 <at> googlemail.com> writes:

> scheme@(guile−user)> (let* ((port (make-soft-port
>                                    (vector #f #f (lambda () 'flushed) #f #f)
>                                    "rw")))
>                        (force-output port))
> scheme@(guile−user)> 

Yak, this example is a horrible one, since force-output doesn't return
the return value of the procedure anyway, but if you try replacing it
with (lambda () (throw 'wontthrow)), and you'll see it doesn't error

In sf_flush in libguile/vports.c, there is a test
  if (pt->write_pos > pt->write_buf)
which some printf debugging tells me is never true, in fact, those
values never change, no matter how much I write to the port. Some food
for thought while I grapple with how the ports code is supposed to work.

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"




Information forwarded to bug-guile <at> gnu.org:
bug#10616; Package guile. (Fri, 27 Jan 2012 06:36:01 GMT) Full text and rfc822 format available.

Message #11 received at 10616 <at> debbugs.gnu.org (full text, mbox):

From: Ian Price <ianprice90 <at> googlemail.com>
To: 10616 <at> debbugs.gnu.org
Subject: Re: bug#10616: flush procedure for soft ports isn't called
Date: Fri, 27 Jan 2012 06:27:47 +0000
Ian Price <ianprice90 <at> googlemail.com> writes:

> Yak, this example is a horrible one, since force-output doesn't return
> the return value of the procedure anyway, but if you try replacing it
> with (lambda () (throw 'wontthrow)), and you'll see it doesn't error
>
> In sf_flush in libguile/vports.c, there is a test
>   if (pt->write_pos > pt->write_buf)
> which some printf debugging tells me is never true, in fact, those
> values never change, no matter how much I write to the port. Some food
> for thought while I grapple with how the ports code is supposed to work.

OK, so as I understand it, this is supposed to check if there has been a
write to the port. And the buffer will have at most one character in it
because it is set up that way in scm_port_non_buffer.

I notice that sf_write doesn't update this buffer, but instead just
calls the write procedure directly. In that case, it makes sense that
the value isn't changing, and therefore maybe I should just change
sf_flush into a wrapper for the flush procedure?

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"




Information forwarded to bug-guile <at> gnu.org:
bug#10616; Package guile. (Fri, 27 Jan 2012 06:53:02 GMT) Full text and rfc822 format available.

Message #14 received at 10616 <at> debbugs.gnu.org (full text, mbox):

From: Ian Price <ianprice90 <at> googlemail.com>
To: 10616 <at> debbugs.gnu.org
Subject: Re: bug#10616: flush procedure for soft ports isn't called
Date: Fri, 27 Jan 2012 06:44:52 +0000
[Message part 1 (text/plain, inline)]
Ian Price <ianprice90 <at> googlemail.com> writes:

> I notice that sf_write doesn't update this buffer, but instead just
> calls the write procedure directly. In that case, it makes sense that
> the value isn't changing, and therefore maybe I should just change
> sf_flush into a wrapper for the flush procedure?

I decided to go ahead and do this. Patch attached. Test case missing as
is traditional for soft ports :), though in all seriousness, soft ports
have been around for ages, and this lack of testing for it is, unsettling.

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"

[~/src/guile/0001-Fix-flush-on-soft-ports-so-that-it-actually-runs.patch (message/external-body, inline)]

[Message part 3 (text/x-patch, inline)]


Information forwarded to bug-guile <at> gnu.org:
bug#10616; Package guile. (Fri, 27 Jan 2012 20:38:02 GMT) Full text and rfc822 format available.

Message #17 received at 10616 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Ian Price <ianprice90 <at> googlemail.com>
Cc: 10616 <at> debbugs.gnu.org
Subject: Re: bug#10616: flush procedure for soft ports isn't called
Date: Fri, 27 Jan 2012 21:36:17 +0100
Hi Ian,

I fail to see the patch, and to retrieve it from
<http://bugs.gnu.org/10616>.  Could you resend it inline?

Thanks!

Ludo’.




Information forwarded to bug-guile <at> gnu.org:
bug#10616; Package guile. (Fri, 27 Jan 2012 21:00:02 GMT) Full text and rfc822 format available.

Message #20 received at 10616 <at> debbugs.gnu.org (full text, mbox):

From: Ian Price <ianprice90 <at> googlemail.com>
To: ludo <at> gnu.org (Ludovic Courtès)
Cc: 10616 <at> debbugs.gnu.org
Subject: Re: bug#10616: flush procedure for soft ports isn't called
Date: Fri, 27 Jan 2012 20:51:52 +0000
[Message part 1 (text/plain, inline)]
ludo <at> gnu.org (Ludovic Courtès) writes:

> Hi Ian,
>
> I fail to see the patch, and to retrieve it from
> <http://bugs.gnu.org/10616>.  Could you resend it inline?
Bah, that's twice this has happened recently.

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"

[0001-Fix-flush-on-soft-ports-so-that-it-actually-runs.patch (text/x-patch, inline)]
From 8a9524014ce85fb34fe5cfd7a2667395ce0cdf5d Mon Sep 17 00:00:00 2001
From: Ian Price <ianprice90 <at> googlemail.com>
Date: Fri, 27 Jan 2012 06:38:09 +0000
Subject: [PATCH] Fix flush on soft ports, so that it actually runs.

* libguile/vports.c (sf_flush): Remove conditional testing the
  position in the port's write_buf, as it is no longer used.
---
 libguile/vports.c |   18 ++++--------------
 1 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/libguile/vports.c b/libguile/vports.c
index 5178d79..75e7df3 100644
--- a/libguile/vports.c
+++ b/libguile/vports.c
@@ -56,21 +56,11 @@ sf_flush (SCM port)
   scm_t_port *pt = SCM_PTAB_ENTRY (port);
   SCM stream = SCM_PACK (pt->stream);
 
-  if (pt->write_pos > pt->write_buf)
-    {
-      /* write the byte. */
-      scm_call_1 (SCM_SIMPLE_VECTOR_REF (stream, 0),
-		  SCM_MAKE_CHAR (*pt->write_buf));
-      pt->write_pos = pt->write_buf;
-  
-      /* flush the output.  */
-      {
-	SCM f = SCM_SIMPLE_VECTOR_REF (stream, 2);
+  SCM f = SCM_SIMPLE_VECTOR_REF (stream, 2);
+
+  if (scm_is_true (f))
+    scm_call_0 (f);
 
-	if (scm_is_true (f))
-	  scm_call_0 (f);
-      }
-    }
 }
 
 static void
-- 
1.7.7.6


Reply sent to Mark H Weaver <mhw <at> netris.org>:
You have taken responsibility. (Thu, 08 Mar 2012 05:11:01 GMT) Full text and rfc822 format available.

Notification sent to Ian Price <ianprice90 <at> googlemail.com>:
bug acknowledged by developer. (Thu, 08 Mar 2012 05:11:02 GMT) Full text and rfc822 format available.

Message #25 received at 10616-done <at> debbugs.gnu.org (full text, mbox):

From: Mark H Weaver <mhw <at> netris.org>
To: Ian Price <ianprice90 <at> googlemail.com>
Cc: 10616-done <at> debbugs.gnu.org
Subject: Re: bug#10616: flush procedure for soft ports isn't called
Date: Thu, 08 Mar 2012 00:06:38 -0500
Hi Ian,

Ian Price <ianprice90 <at> googlemail.com> writes:
> From 8a9524014ce85fb34fe5cfd7a2667395ce0cdf5d Mon Sep 17 00:00:00 2001
> From: Ian Price <ianprice90 <at> googlemail.com>
> Date: Fri, 27 Jan 2012 06:38:09 +0000
> Subject: [PATCH] Fix flush on soft ports, so that it actually runs.
>
> * libguile/vports.c (sf_flush): Remove conditional testing the
>   position in the port's write_buf, as it is no longer used.
> ---
>  libguile/vports.c |   18 ++++--------------
>  1 files changed, 4 insertions(+), 14 deletions(-)
>
> diff --git a/libguile/vports.c b/libguile/vports.c
> index 5178d79..75e7df3 100644
> --- a/libguile/vports.c
> +++ b/libguile/vports.c
> @@ -56,21 +56,11 @@ sf_flush (SCM port)
>    scm_t_port *pt = SCM_PTAB_ENTRY (port);
>    SCM stream = SCM_PACK (pt->stream);
>  
> -  if (pt->write_pos > pt->write_buf)
> -    {
> -      /* write the byte. */
> -      scm_call_1 (SCM_SIMPLE_VECTOR_REF (stream, 0),
> -		  SCM_MAKE_CHAR (*pt->write_buf));
> -      pt->write_pos = pt->write_buf;
> -  
> -      /* flush the output.  */
> -      {
> -	SCM f = SCM_SIMPLE_VECTOR_REF (stream, 2);
> +  SCM f = SCM_SIMPLE_VECTOR_REF (stream, 2);
> +
> +  if (scm_is_true (f))
> +    scm_call_0 (f);
>  
> -	if (scm_is_true (f))
> -	  scm_call_0 (f);
> -      }
> -    }
>  }
>  
>  static void

Applied, thanks!

     Mark




Information forwarded to bug-guile <at> gnu.org:
bug#10616; Package guile. (Thu, 08 Mar 2012 13:55:03 GMT) Full text and rfc822 format available.

Message #28 received at 10616 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Ian Price <ianprice90 <at> googlemail.com>
Cc: 10616 <at> debbugs.gnu.org
Subject: Re: bug#10616: flush procedure for soft ports isn't called
Date: Thu, 08 Mar 2012 14:53:32 +0100
Hello!

Ian Price <ianprice90 <at> googlemail.com> skribis:

>  
> -  if (pt->write_pos > pt->write_buf)
> -    {
> -      /* write the byte. */
> -      scm_call_1 (SCM_SIMPLE_VECTOR_REF (stream, 0),
> -		  SCM_MAKE_CHAR (*pt->write_buf));
> -      pt->write_pos = pt->write_buf;
> -  
> -      /* flush the output.  */
> -      {
> -	SCM f = SCM_SIMPLE_VECTOR_REF (stream, 2);
> +  SCM f = SCM_SIMPLE_VECTOR_REF (stream, 2);
> +
> +  if (scm_is_true (f))
> +    scm_call_0 (f);
>  
> -	if (scm_is_true (f))
> -	  scm_call_0 (f);
> -      }
> -    }
>  }

It’s a bit late to reply (sorry, Ian!), but the reason it took me so
long, is that I wanted to understand the rationale for the ‘if’, and the
implications of dropping it (which I never got around to, as you can
see.  ;-))

Mark: what’s your take on this?  I’m especially concerned with
undesirable side effects in user code.

Thanks,
Ludo’.




Information forwarded to bug-guile <at> gnu.org:
bug#10616; Package guile. (Fri, 09 Mar 2012 07:47:02 GMT) Full text and rfc822 format available.

Message #31 received at 10616 <at> debbugs.gnu.org (full text, mbox):

From: Mark H Weaver <mhw <at> netris.org>
To: ludo <at> gnu.org (Ludovic Courtès)
Cc: Ian Price <ianprice90 <at> googlemail.com>, 10616 <at> debbugs.gnu.org
Subject: Re: bug#10616: flush procedure for soft ports isn't called
Date: Thu, 08 Mar 2012 10:39:31 -0500
ludo <at> gnu.org (Ludovic Courtès) writes:

> Ian Price <ianprice90 <at> googlemail.com> skribis:
>
>>  
>> -  if (pt->write_pos > pt->write_buf)
>> -    {
>> -      /* write the byte. */
>> -      scm_call_1 (SCM_SIMPLE_VECTOR_REF (stream, 0),
>> -		  SCM_MAKE_CHAR (*pt->write_buf));
>> -      pt->write_pos = pt->write_buf;
>> -  
>> -      /* flush the output.  */
>> -      {
>> -	SCM f = SCM_SIMPLE_VECTOR_REF (stream, 2);
>> +  SCM f = SCM_SIMPLE_VECTOR_REF (stream, 2);
>> +
>> +  if (scm_is_true (f))
>> +    scm_call_0 (f);
>>  
>> -	if (scm_is_true (f))
>> -	  scm_call_0 (f);
>> -      }
>> -    }
>>  }
>
> It’s a bit late to reply (sorry, Ian!), but the reason it took me so
> long, is that I wanted to understand the rationale for the ‘if’, and the
> implications of dropping it (which I never got around to, as you can
> see.  ;-))
>
> Mark: what’s your take on this?  I’m especially concerned with
> undesirable side effects in user code.

I searched libguile for occurrences of 'write_pos' and 'write_buf', and
convinced myself that Ian's analysis was indeed correct.  The write
buffer is not used by the core ports code.  Writes are forwarded
directly to the write function of the specific port type, which may use
the write buffer if it wishes to, but need not.  The write buffer is
used only by certain types of ports: currently string ports and file
ports.  It is not used by soft ports.

    Thanks,
      Mark




Information forwarded to bug-guile <at> gnu.org:
bug#10616; Package guile. (Sat, 10 Mar 2012 22:45:01 GMT) Full text and rfc822 format available.

Message #34 received at 10616 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Mark H Weaver <mhw <at> netris.org>
Cc: Ian Price <ianprice90 <at> googlemail.com>, 10616 <at> debbugs.gnu.org
Subject: Re: bug#10616: flush procedure for soft ports isn't called
Date: Sat, 10 Mar 2012 23:14:39 +0100
Hi Mark,

Mark H Weaver <mhw <at> netris.org> skribis:

> ludo <at> gnu.org (Ludovic Courtès) writes:
>
>> Ian Price <ianprice90 <at> googlemail.com> skribis:
>>
>>>  
>>> -  if (pt->write_pos > pt->write_buf)
>>> -    {
>>> -      /* write the byte. */
>>> -      scm_call_1 (SCM_SIMPLE_VECTOR_REF (stream, 0),
>>> -		  SCM_MAKE_CHAR (*pt->write_buf));
>>> -      pt->write_pos = pt->write_buf;
>>> -  
>>> -      /* flush the output.  */
>>> -      {
>>> -	SCM f = SCM_SIMPLE_VECTOR_REF (stream, 2);
>>> +  SCM f = SCM_SIMPLE_VECTOR_REF (stream, 2);
>>> +
>>> +  if (scm_is_true (f))
>>> +    scm_call_0 (f);
>>>  
>>> -	if (scm_is_true (f))
>>> -	  scm_call_0 (f);
>>> -      }
>>> -    }
>>>  }
>>
>> It’s a bit late to reply (sorry, Ian!), but the reason it took me so
>> long, is that I wanted to understand the rationale for the ‘if’, and the
>> implications of dropping it (which I never got around to, as you can
>> see.  ;-))
>>
>> Mark: what’s your take on this?  I’m especially concerned with
>> undesirable side effects in user code.
>
> I searched libguile for occurrences of 'write_pos' and 'write_buf', and
> convinced myself that Ian's analysis was indeed correct.  The write
> buffer is not used by the core ports code.  Writes are forwarded
> directly to the write function of the specific port type, which may use
> the write buffer if it wishes to, but need not.  The write buffer is
> used only by certain types of ports: currently string ports and file
> ports.  It is not used by soft ports.

OK.  Thanks for the detailed analysis!

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 08 Apr 2012 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 13 years and 131 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.