unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: Mark H Weaver <mhw@netris.org>
Cc: Andy Wingo <wingo@pobox.com>, guile-devel <guile-devel@gnu.org>
Subject: Re: Making custom binary input ports unbuffered
Date: Tue, 21 Jan 2014 11:50:04 +0100	[thread overview]
Message-ID: <87eh41licj.fsf@gnu.org> (raw)
In-Reply-To: <87lhy9ok8e.fsf@netris.org> (Mark H. Weaver's message of "Tue, 21 Jan 2014 02:41:05 -0500")

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

> Here are the same changes adapted for master, where we can put the
> new 'setvbuf' method where it belongs: in the PTOB.

Cool!

Wouldn’t it be easier to just merge stable-2.0 and modify from there?

> From 00ee913e2da658f30d9d8682edfbb9a63719c370 Mon Sep 17 00:00:00 2001
> From: Mark H Weaver <mhw@netris.org>
> Date: Tue, 21 Jan 2014 01:57:31 -0500
> Subject: [PATCH 1/2] Prepare 'setvbuf' to support for non-file ports.
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> Based on a patch for Guile 2.0 by Ludovic Courtès.
>
> * libguile/fports.c (scm_fport_buffer_add): Rename to 'fport_setvbuf'.
>   (fport_setvbuf): Renamed from 'scm_fport_buffer_add'.  Change type of
>   'write_size' argument from 'int' to 'long'.
>   (scm_i_fdes_to_port): Adapt to renamed 'scm_fport_buffer_add'.
>   (scm_make_fptob): Set 'setvbuf' method to 'fport_setvbuf'.
>   (scm_setvbuf): Move to ports.c.
>
> * libguile/ports.c (scm_make_port_type): Initialize 'setvbuf' field.
>   (scm_set_port_setvbuf): New API function.
>   (scm_setvbuf): Moved from fports.c.  Accept any open port, and error
>   out when the ptob's 'setvbuf' field is NULL.  Remove explicit
>   'scm_gc_free' calls.  Call ptob's 'setvbuf' method instead of
>   'scm_fport_buffer_add'.
>
> * libguile/fports.h (scm_setbuf0): Remove prototype for non-existent
>   function.
>   (scm_setvbuf): Move prototype to ports.h.
>
> * libguile/ports.h (scm_t_ptob_descriptor): Add 'setvbuf' member.
>   (scm_set_port_setvbuf): Add prototype.
>   (scm_setvbuf): Move prototype here from fports.h.

Moving ‘setvbuf’ to ports.c also needs to be done in stable-2.0 (and
it’s worth making it in a separate patch, IMO.)

> * libguile/ports-internal.h (struct scm_port_internal): Change
>   'pending_eof' to a 1-bit unsigned char.  Add comment for 'alist'
>   member.
>
> * test-suite/tests/ports.test ("setvbuf")["closed port", "string port"]:
>   New tests.
>
> * doc/ref/api-io.texi (Port Implementation): Document new 'setvbuf'
>   member of ptob, and 'scm_set_port_setvbuf'.

I was wondering if the ‘setvbuf’ method should be exposed at this point,
because I wasn’t 100% sure of the API.  WDYT?

Perhaps it’s also better for a separate patch?

> +@item setvbuf
> +Create read and write buffers for the port with the specified sizes (a
> +size of 0 is for unbuffered ports, which should use the @code{shortbuf}
> +field; a size of -1 means to use the port's preferred buffer size).  It
> +doesn't need to be set unless you wish to support @code{setvbuf}.  Set
> +using
> +
> +@deftypefun void scm_set_port_setvbuf (scm_t_bits tc, void (*setvbuf) (SCM port, long read_size, long write_size))
> +@end deftypefun

I guess the body was meant to go inside @deftypefun.  :-)

> From 6a3feb79b289410a62d2e0c8a70e0ea59d0cf8cd Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
> Date: Tue, 21 Jan 2014 02:28:35 -0500
> Subject: [PATCH 2/2] Custom binary input ports support 'setvbuf'.
>
> Modified-by: Mark H Weaver <mhw@netris.org>
>
> * libguile/r6rs-ports.c (CBIP_BUFFER_SIZE): Adjust comment.  Set to 8KiB.
>   (SCM_SET_CBIP_BYTEVECTOR): New macro.
>   (cbip_setvbuf): New function.
>   (cbip_fill_input): Check whether PORT is buffered.  When unbuffered,
>   check whether BV can hold C_REQUESTED bytes, and allocate a new
>   bytevector if not; copy the data back from BV to c_port->read_pos.
>   Remove 'again' label, and don't loop there.
>   (initialize_custom_binary_input_ports): Set PTOB's 'setvbuf' method.
> * test-suite/tests/r6rs-ports.test ("7.2.7 Input Ports")["custom binary
>   input port unbuffered & 'port-position'", "custom binary input port
>   unbuffered & 'read!' calls", "custom binary input port, unbuffered
>   then buffered", "custom binary input port, buffered then unbuffered"]:
>   New tests.
> * doc/ref/api-io.texi (R6RS Binary Input): Document the buffering of
>   custom binary input ports, and link to 'setvbuf'.

OK.

Thanks for taking care of this!

Ludo’.



  reply	other threads:[~2014-01-21 10:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-14 23:00 Making custom binary input ports unbuffered Ludovic Courtès
2014-01-15  5:43 ` Mark H Weaver
2014-01-15 11:48   ` Ludovic Courtès
2014-01-15 22:51   ` Ludovic Courtès
2014-01-16  0:15     ` Mark H Weaver
2014-01-16 23:00       ` Ludovic Courtès
2014-01-18 21:57         ` Ludovic Courtès
2014-01-21  7:41         ` Mark H Weaver
2014-01-21 10:50           ` Ludovic Courtès [this message]
2014-01-21 14:46             ` Mark H Weaver
2014-01-21 17:37               ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87eh41licj.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.org \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).