From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 10 10:02:35 2018 Received: (at submit) by debbugs.gnu.org; 10 Jan 2018 15:02:35 +0000 Received: from localhost ([127.0.0.1]:51143 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZHtj-0002NE-Aq for submit@debbugs.gnu.org; Wed, 10 Jan 2018 10:02:35 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50500) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZHtg-0002N1-W4 for submit@debbugs.gnu.org; Wed, 10 Jan 2018 10:02:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZHtV-0004OW-QS for submit@debbugs.gnu.org; Wed, 10 Jan 2018 10:02:27 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:43297) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eZHtV-0004ON-O6 for submit@debbugs.gnu.org; Wed, 10 Jan 2018 10:02:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41402) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eZHtR-0007UK-IE for bug-guile@gnu.org; Wed, 10 Jan 2018 10:02:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eZHtN-0004FX-LI for bug-guile@gnu.org; Wed, 10 Jan 2018 10:02:17 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:40526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eZHtN-0004EZ-Fe for bug-guile@gnu.org; Wed, 10 Jan 2018 10:02:13 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id E2BDD10862; Wed, 10 Jan 2018 16:02:11 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HxCHz-pPuV4G; Wed, 10 Jan 2018 16:02:11 +0100 (CET) Received: from ribbon (unknown [IPv6:2a01:e0a:1d:7270:af76:b9b:ca24:c465]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 259B9107B9; Wed, 10 Jan 2018 16:02:11 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: bug-guile@gnu.org Subject: 'get-bytevector-some' returns only 1 byte from unbuffered ports X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 21 =?utf-8?Q?Niv=C3=B4se?= an 226 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Wed, 10 Jan 2018 16:02:10 +0100 Message-ID: <87zi5lrc3x.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit Cc: Andy Wingo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) As discussed on IRC, =E2=80=98get-bytevector-some=E2=80=99 returns only 1 b= yte from unbuffered ports: --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> (call-with-input-string "foo" (lambda (port) (setvbuf port _IONBF) (get-bytevector-some port))) $11 =3D #vu8(102) scheme@(guile-user)> (version) $12 =3D "2.2.3" --8<---------------cut here---------------end--------------->8--- Strictly speaking it=E2=80=99s valid, but in practice it=E2=80=99s not very= useful. AFAICS, we lack a way to do the equivalent of: read (fd, buf, sizeof buf); =E2=80=98get-bytevector-n!=E2=80=99 is different because it blocks until it= has read COUNT bytes or EOF is reached. So =E2=80=98get-bytevector-some=E2=80=99 co= uld play this role, but it doesn=E2=80=99t. Thoughts? Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 10 10:59:36 2018 Received: (at 30066) by debbugs.gnu.org; 10 Jan 2018 15:59:36 +0000 Received: from localhost ([127.0.0.1]:51190 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZImu-0003n5-CP for submit@debbugs.gnu.org; Wed, 10 Jan 2018 10:59:36 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:53600) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZImr-0003mv-3e for 30066@debbugs.gnu.org; Wed, 10 Jan 2018 10:59:34 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id A2C6F100F8; Wed, 10 Jan 2018 16:59:31 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ko28KrS6z37x; Wed, 10 Jan 2018 16:59:30 +0100 (CET) Received: from ribbon (unknown [IPv6:2a01:e0a:1d:7270:af76:b9b:ca24:c465]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 8F938100EE; Wed, 10 Jan 2018 16:59:30 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: 30066@debbugs.gnu.org Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> Date: Wed, 10 Jan 2018 16:59:29 +0100 In-Reply-To: <87zi5lrc3x.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Wed, 10 Jan 2018 16:02:10 +0100") Message-ID: <87tvvtr9ge.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30066 Cc: Andy Wingo X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable ludo@gnu.org (Ludovic Court=C3=A8s) skribis: > As discussed on IRC, =E2=80=98get-bytevector-some=E2=80=99 returns only 1= byte from > unbuffered ports: Here=E2=80=99s a tentative fix. WDYT? Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable diff --git a/libguile/ports.c b/libguile/ports.c index 72bb73a01..002dd1433 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2001, 2003-2004, 2006-2017 +/* Copyright (C) 1995-2001, 2003-2004, 2006-2018 * Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or @@ -1543,7 +1543,9 @@ scm_peek_byte_or_eof (SCM port) return peek_byte_or_eof (port, &buf, &cur); } =20 -static size_t +/* Like read(2), read *up to* COUNT bytes from PORT into DST, starting + at OFFSET. Return 0 upon EOF. */ +size_t scm_i_read_bytes (SCM port, SCM dst, size_t start, size_t count) { size_t filled; diff --git a/libguile/ports.h b/libguile/ports.h index d131db5be..7aeacc8f9 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -4,7 +4,7 @@ #define SCM_PORTS_H =20 /* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, - * 2006, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundati= on, Inc. + * 2006, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2018 Free Software Fo= undation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -69,6 +69,7 @@ SCM_INTERNAL SCM scm_i_port_weak_set; #define SCM_OPOUTPORTP(x) (SCM_OPPORTP (x) && SCM_OUTPUT_PORT_P (x)) #define SCM_OPENP(x) (SCM_OPPORTP (x)) #define SCM_CLOSEDP(x) (!SCM_OPENP (x)) +#define SCM_UNBUFFEREDP(x) (SCM_PORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_BU= F0)) #define SCM_CLR_PORT_OPEN_FLAG(p) \ SCM_SET_CELL_WORD_0 ((p), SCM_CELL_WORD_0 (p) & ~SCM_OPN) #ifdef BUILDING_LIBGUILE @@ -185,6 +186,8 @@ SCM_API int scm_get_byte_or_eof (SCM port); SCM_API int scm_peek_byte_or_eof (SCM port); SCM_API size_t scm_c_read (SCM port, void *buffer, size_t size); SCM_API size_t scm_c_read_bytes (SCM port, SCM dst, size_t start, size_t c= ount); +SCM_INTERNAL size_t scm_i_read_bytes (SCM port, SCM dst, size_t start, + size_t count); SCM_API scm_t_wchar scm_getc (SCM port); SCM_API SCM scm_read_char (SCM port); =20 diff --git a/libguile/r6rs-ports.c b/libguile/r6rs-ports.c index e944c7aab..a3a67f3ca 100644 --- a/libguile/r6rs-ports.c +++ b/libguile/r6rs-ports.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009, 2010, 2011, 2013-2015 Free Software Foundation, Inc. +/* Copyright (C) 2009, 2010, 2011, 2013-2015, 2018 Free Software Foundatio= n, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -487,16 +487,33 @@ SCM_DEFINE (scm_get_bytevector_some, "get-bytevector-= some", 1, 0, 0, =20 SCM_VALIDATE_BINARY_INPUT_PORT (1, port); =20 - buf =3D scm_fill_input (port, 0, &cur, &avail); - if (avail =3D=3D 0) + if (SCM_UNBUFFEREDP (port)) { - scm_port_buffer_set_has_eof_p (buf, SCM_BOOL_F); - return SCM_EOF_VAL; + size_t read; + + bv =3D scm_c_make_bytevector (4096); + read =3D scm_i_read_bytes (port, bv, 0, SCM_BYTEVECTOR_LENGTH (bv)); + + if (read =3D=3D 0) + return SCM_EOF_VAL; + else if (read < SCM_BYTEVECTOR_LENGTH (bv)) + return scm_c_shrink_bytevector (bv, read); + else + return bv; } + else + { + buf =3D scm_fill_input (port, 0, &cur, &avail); + if (avail =3D=3D 0) + { + scm_port_buffer_set_has_eof_p (buf, SCM_BOOL_F); + return SCM_EOF_VAL; + } =20 - bv =3D scm_c_make_bytevector (avail); - scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv), - avail, cur, avail); + bv =3D scm_c_make_bytevector (avail); + scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (= bv), + avail, cur, avail); + } =20 return bv; } diff --git a/test-suite/tests/r6rs-ports.test b/test-suite/tests/r6rs-ports= .test index ba3131f2e..7450b7217 100644 --- a/test-suite/tests/r6rs-ports.test +++ b/test-suite/tests/r6rs-ports.test @@ -1,6 +1,6 @@ ;;;; r6rs-ports.test --- R6RS I/O port tests. -*- coding: utf-8; -*- ;;;; -;;;; Copyright (C) 2009-2012, 2013-2015 Free Software Foundation, Inc. +;;;; Copyright (C) 2009-2012, 2013-2015, 2018 Free Software Foundation, In= c. ;;;; Ludovic Court=C3=A8s ;;;; ;;;; This library is free software; you can redistribute it and/or @@ -183,6 +183,15 @@ (equal? (bytevector->u8-list bv) (map char->integer (string->list str)))))) =20 + (pass-if-equal "get-bytevector-some [unbuffered port]" + (string->utf8 "Hello, world!") + ;; 'get-bytevector-some' used to return a single byte, see + ;; . + (call-with-input-string "Hello, world!" + (lambda (port) + (setvbuf port _IONBF) + (get-bytevector-some port)))) + (pass-if "get-bytevector-all" (let* ((str "GNU Guile") (index 0) --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 10 11:32:14 2018 Received: (at 30066) by debbugs.gnu.org; 10 Jan 2018 16:32:14 +0000 Received: from localhost ([127.0.0.1]:51215 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZJIU-0004an-G0 for submit@debbugs.gnu.org; Wed, 10 Jan 2018 11:32:14 -0500 Received: from pb-sasl2.pobox.com ([64.147.108.67]:51125 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZJIT-0004ad-3u for 30066@debbugs.gnu.org; Wed, 10 Jan 2018 11:32:13 -0500 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 40832C0626; Wed, 10 Jan 2018 11:32:12 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=kSiE7kI4R3VS 3RaHrdw1RM+ft8c=; b=rinpMSt3L/oqdUB8ksAj1r+dP59NOyDbgyESMXSaSauI HrSIy5hC7f1Zi+FxJnzUMvNj2O5Ru8u2flF3/cb+xgetQSBhYQwPjTnGsUX+ZvYQ p4QcD7IRtoHuyVLAdRWcDaCcjMYqAZFgtpKN6qdxEYsbvdZI8pyF5p7NipLgrIA= Received: from pb-sasl2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 2915DC0624; Wed, 10 Jan 2018 11:32:12 -0500 (EST) Received: from rusty (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl2.pobox.com (Postfix) with ESMTPSA id 170C1C0623; Wed, 10 Jan 2018 11:32:10 -0500 (EST) From: Andy Wingo To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> Date: Wed, 10 Jan 2018 17:32:04 +0100 In-Reply-To: <87tvvtr9ge.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Wed, 10 Jan 2018 16:59:29 +0100") Message-ID: <87fu7dptdn.fsf@igalia.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pobox-Relay-ID: CED2A196-F623-11E7-BD1C-EA54894C8D7C-02397024!pb-sasl2.pobox.com X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 30066 Cc: 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.7 (/) On Wed 10 Jan 2018 16:59, ludo@gnu.org (Ludovic Court=C3=A8s) writes: > ludo@gnu.org (Ludovic Court=C3=A8s) skribis: > >> As discussed on IRC, =E2=80=98get-bytevector-some=E2=80=99 returns only = 1 byte from >> unbuffered ports: > > Here=E2=80=99s a tentative fix. WDYT? Thanks! Needs a little work though :) Comments inline. > --- a/libguile/ports.h > +++ b/libguile/ports.h > @@ -69,6 +69,7 @@ SCM_INTERNAL SCM scm_i_port_weak_set; > #define SCM_OPOUTPORTP(x) (SCM_OPPORTP (x) && SCM_OUTPUT_PORT_P (x)) > #define SCM_OPENP(x) (SCM_OPPORTP (x)) > #define SCM_CLOSEDP(x) (!SCM_OPENP (x)) > +#define SCM_UNBUFFEREDP(x) (SCM_PORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_= BUF0)) > #define SCM_CLR_PORT_OPEN_FLAG(p) \ > SCM_SET_CELL_WORD_0 ((p), SCM_CELL_WORD_0 (p) & ~SCM_OPN) > #ifdef BUILDING_LIBGUILE Please guard this under #ifdef BUILDING_LIBGUILE. > @@ -487,16 +487,33 @@ SCM_DEFINE (scm_get_bytevector_some, "get-bytevecto= r-some", 1, 0, 0, >=20=20 > SCM_VALIDATE_BINARY_INPUT_PORT (1, port); >=20=20 > - buf =3D scm_fill_input (port, 0, &cur, &avail); > - if (avail =3D=3D 0) > + if (SCM_UNBUFFEREDP (port)) > { > - scm_port_buffer_set_has_eof_p (buf, SCM_BOOL_F); > - return SCM_EOF_VAL; > + size_t read; > + > + bv =3D scm_c_make_bytevector (4096); > + read =3D scm_i_read_bytes (port, bv, 0, SCM_BYTEVECTOR_LENGTH (bv)= ); > + > + if (read =3D=3D 0) > + return SCM_EOF_VAL; > + else if (read < SCM_BYTEVECTOR_LENGTH (bv)) > + return scm_c_shrink_bytevector (bv, read); > + else > + return bv; > } > + else > + { > + buf =3D scm_fill_input (port, 0, &cur, &avail); > + if (avail =3D=3D 0) > + { > + scm_port_buffer_set_has_eof_p (buf, SCM_BOOL_F); > + return SCM_EOF_VAL; > + } >=20=20 > - bv =3D scm_c_make_bytevector (avail); > - scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv= ), > - avail, cur, avail); > + bv =3D scm_c_make_bytevector (avail); > + scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS= (bv), > + avail, cur, avail); > + } >=20=20 > return bv; > } There are tabs in your code; would you mind doing only spaces? A port being unbuffered doesn't mean that it has no bytes in its buffer. In particular, scm_unget_bytes may put bytes back into the buffer. Or, peek-u8 might fill this buffer with one byte. Also, they port may have buffered write bytes (could be the port has write buffering but no read buffering). In that case (pt->rw_random) you need to scm_flush(). I suggest taking the buffered bytes from the read buffer, if any. Then if the port is unbuffered, make a bytevector and call scm_i_read_bytes; otherwise do the scm_fill_input path that's there already. One more thing, if the port goes EOF, you need to scm_port_buffer_set_has_eof_p. Regards, Andy From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 10 11:58:38 2018 Received: (at 30066) by debbugs.gnu.org; 10 Jan 2018 16:58:38 +0000 Received: from localhost ([127.0.0.1]:51226 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZJi2-0005Et-Gu for submit@debbugs.gnu.org; Wed, 10 Jan 2018 11:58:38 -0500 Received: from mail-yb0-f176.google.com ([209.85.213.176]:37318) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZJi1-0005Ef-EL for 30066@debbugs.gnu.org; Wed, 10 Jan 2018 11:58:37 -0500 Received: by mail-yb0-f176.google.com with SMTP id p83so1272860yba.4 for <30066@debbugs.gnu.org>; Wed, 10 Jan 2018 08:58:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=CrBwAVjyo+fphgT+M+EGeujjK0c30jGFk19XpcvHmAg=; b=Sl7/jqXdgYB62ddc4ElQDr8TyjV63xk0KFvyEQ08MmCmRocK1RYumjD8DNgfhauCnM 8PuguX/CS1ztiXC/yFvLNUZyZKPmBfVDpn4tSo/gV+NtrrwMNoIrrMKnfAmKr2KNPYpg J9fwOjDjs9VqrO4J7urEUWX6sYj7ol88BzR88CLuH7k3h2K0lD9UgIO1XhsWzBVb8SSM KFW7+eV/kwanYru3UDMhwSQKrlE13UwX7AR1HNwPuXjckz66orhvNk++yA7Qj83poX9g Ff2DlJ9ToP1smG15HVV7wFvnZzZSWh+Ai2MUZpuk41Ql2oOeU5TC1q84ao1zZ3eOMG8h bXQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=CrBwAVjyo+fphgT+M+EGeujjK0c30jGFk19XpcvHmAg=; b=U08OxN9e8za9n4VL6YH/7S3fR2R4Umy8tbM1LqZCpDVuaF6u1wCDVhepBA8XjzAGM+ UbxDY3zdwjXwWC07NXYHgp1m0Mi7QBf/tUPsdBsjLJJNiCy9rGe134MB23KBoEQW+nbT 2suEDlZPTEOG6CyDnBQwbhIpuar0/kxPH963Ubt1CL6xS0K9pzC49ZRlotsK3kH7roc4 5WInKmzhq7BDQaamEwMxGnNix+6RrpnIHT3vlmvMjlohErZYqBHmBQdPooJ+9FJWuyQt 8zhWqedvrdKBSmgYBtqlQLBw8W8ImKvOiuc79b20NERe/wUzq9dHOWJMpil9skysTjYh SVdQ== X-Gm-Message-State: AKGB3mKG81mqkFzSteM2B1wh12SoBFMOqevx3hKi6+WsT1rUmfRYaT5s 39exzlqGAKK2SUhwSUyijuy6/guN6W3A3KNxrpE= X-Google-Smtp-Source: ACJfBoswuk/Hmq4OVL302o1y/DdeUkWXtO14b3cXRHBcGb/XaJti0rgKHFA466wo4fUS/lWU4DimtBzMaOHEaG5PYAQ= X-Received: by 10.37.130.9 with SMTP id q9mr17369329ybk.397.1515603511837; Wed, 10 Jan 2018 08:58:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.11.137 with HTTP; Wed, 10 Jan 2018 08:58:31 -0800 (PST) In-Reply-To: <87fu7dptdn.fsf@igalia.com> References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> From: Nala Ginrut Date: Thu, 11 Jan 2018 00:58:31 +0800 Message-ID: Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports To: Andy Wingo Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 30066 Cc: =?UTF-8?Q?Ludovic_Court=C3=A8s?= , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) hi Andy and Ludo! What if developers enabled suspendable-ports and set the port to non-blocki= ng? For example, in the non-blocking asynchronous server, I registered read/write waiter for suspendable-ports. And save delimited-continuations then yield the current task. In this situation, get-bytevector-n! will read n bytes with several times yielding by the registered read-writer, from the caller's perspective, get-bytevector-n! will return n bytes finally no matter how many times it's yielded. But how about the get-bytevector-some? Should it block just once and return the first time read m bytes then return? Thanks! On Thu, Jan 11, 2018 at 12:32 AM, Andy Wingo wrote: > On Wed 10 Jan 2018 16:59, ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> ludo@gnu.org (Ludovic Court=C3=A8s) skribis: >> >>> As discussed on IRC, =E2=80=98get-bytevector-some=E2=80=99 returns only= 1 byte from >>> unbuffered ports: >> >> Here=E2=80=99s a tentative fix. WDYT? > > Thanks! Needs a little work though :) Comments inline. > >> --- a/libguile/ports.h >> +++ b/libguile/ports.h >> @@ -69,6 +69,7 @@ SCM_INTERNAL SCM scm_i_port_weak_set; >> #define SCM_OPOUTPORTP(x) (SCM_OPPORTP (x) && SCM_OUTPUT_PORT_P (x)) >> #define SCM_OPENP(x) (SCM_OPPORTP (x)) >> #define SCM_CLOSEDP(x) (!SCM_OPENP (x)) >> +#define SCM_UNBUFFEREDP(x) (SCM_PORTP (x) && (SCM_CELL_WORD_0 (x) & SCM= _BUF0)) >> #define SCM_CLR_PORT_OPEN_FLAG(p) \ >> SCM_SET_CELL_WORD_0 ((p), SCM_CELL_WORD_0 (p) & ~SCM_OPN) >> #ifdef BUILDING_LIBGUILE > > Please guard this under #ifdef BUILDING_LIBGUILE. > >> @@ -487,16 +487,33 @@ SCM_DEFINE (scm_get_bytevector_some, "get-bytevect= or-some", 1, 0, 0, >> >> SCM_VALIDATE_BINARY_INPUT_PORT (1, port); >> >> - buf =3D scm_fill_input (port, 0, &cur, &avail); >> - if (avail =3D=3D 0) >> + if (SCM_UNBUFFEREDP (port)) >> { >> - scm_port_buffer_set_has_eof_p (buf, SCM_BOOL_F); >> - return SCM_EOF_VAL; >> + size_t read; >> + >> + bv =3D scm_c_make_bytevector (4096); >> + read =3D scm_i_read_bytes (port, bv, 0, SCM_BYTEVECTOR_LENGTH (bv= )); >> + >> + if (read =3D=3D 0) >> + return SCM_EOF_VAL; >> + else if (read < SCM_BYTEVECTOR_LENGTH (bv)) >> + return scm_c_shrink_bytevector (bv, read); >> + else >> + return bv; >> } >> + else >> + { >> + buf =3D scm_fill_input (port, 0, &cur, &avail); >> + if (avail =3D=3D 0) >> + { >> + scm_port_buffer_set_has_eof_p (buf, SCM_BOOL_F); >> + return SCM_EOF_VAL; >> + } >> >> - bv =3D scm_c_make_bytevector (avail); >> - scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (b= v), >> - avail, cur, avail); >> + bv =3D scm_c_make_bytevector (avail); >> + scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENT= S (bv), >> + avail, cur, avail); >> + } >> >> return bv; >> } > > There are tabs in your code; would you mind doing only spaces? > > A port being unbuffered doesn't mean that it has no bytes in its > buffer. In particular, scm_unget_bytes may put bytes back into the > buffer. Or, peek-u8 might fill this buffer with one byte. > > Also, they port may have buffered write bytes (could be the port has > write buffering but no read buffering). In that case (pt->rw_random) > you need to scm_flush(). > > I suggest taking the buffered bytes from the read buffer, if any. Then > if the port is unbuffered, make a bytevector and call scm_i_read_bytes; > otherwise do the scm_fill_input path that's there already. > > One more thing, if the port goes EOF, you need to > scm_port_buffer_set_has_eof_p. > > Regards, > > Andy > > > From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 10 12:26:18 2018 Received: (at 30066) by debbugs.gnu.org; 10 Jan 2018 17:26:18 +0000 Received: from localhost ([127.0.0.1]:51240 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZK8n-0005tw-Cq for submit@debbugs.gnu.org; Wed, 10 Jan 2018 12:26:18 -0500 Received: from pb-sasl1.pobox.com ([64.147.108.66]:59184 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZK8l-0005tn-2s for 30066@debbugs.gnu.org; Wed, 10 Jan 2018 12:26:15 -0500 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 4D5C5B98C7; Wed, 10 Jan 2018 12:26:14 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=k1N9mLuFfgQJ0sljN65quZ/pkSg=; b=ANEFya Xnw5ZkxXmbzEyUnQ5x1bqE7mVltaxOllW81Yhu0ZIOT8gckg8XkuMO7uzNJpyuA3 6KdwddgL5Wgc3DZhB9s4MHNdwNOoM/MrHMBvHfeF+ITQOiNZJmtbYSbbteyoh2el 8lOuvyEjAotORO1Crb3l03hKDt+XjQvUT4zo0= Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 459C4B98C6; Wed, 10 Jan 2018 12:26:14 -0500 (EST) Received: from rusty (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 7F852B98C5; Wed, 10 Jan 2018 12:26:13 -0500 (EST) From: Andy Wingo To: Nala Ginrut Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> Date: Wed, 10 Jan 2018 18:26:06 +0100 In-Reply-To: (Nala Ginrut's message of "Thu, 11 Jan 2018 00:58:31 +0800") Message-ID: <87bmi1pqvl.fsf@igalia.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 5B763796-F62B-11E7-A21E-ABEFD5707B88-02397024!pb-sasl1.pobox.com X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 30066 Cc: Ludovic =?utf-8?Q?Court=C3=A8s?= , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.7 (/) On Wed 10 Jan 2018 17:58, Nala Ginrut writes: > hi Andy and Ludo! > > What if developers enabled suspendable-ports and set the port to non-blocking? > For example, in the non-blocking asynchronous server, I registered > read/write waiter for suspendable-ports. And save > delimited-continuations then yield the current task. > In this situation, get-bytevector-n! will read n bytes with several > times yielding by the registered read-writer, from the caller's > perspective, get-bytevector-n! will return n bytes finally no matter > how many times it's yielded. > But how about the get-bytevector-some? Should it block just once and > return the first time read m bytes then return? I think this is right. At most one block. FWIW we'd need to add support for get-bytevector-some to (ice-9 suspendable-ports) to get this to work. Andy From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 10 12:43:42 2018 Received: (at 30066) by debbugs.gnu.org; 10 Jan 2018 17:43:42 +0000 Received: from localhost ([127.0.0.1]:51251 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZKPe-0006Is-Id for submit@debbugs.gnu.org; Wed, 10 Jan 2018 12:43:42 -0500 Received: from mail-yb0-f181.google.com ([209.85.213.181]:33743) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZKPc-0006If-OE for 30066@debbugs.gnu.org; Wed, 10 Jan 2018 12:43:40 -0500 Received: by mail-yb0-f181.google.com with SMTP id f16so7745248ybn.0 for <30066@debbugs.gnu.org>; Wed, 10 Jan 2018 09:43:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=TgDC9JPEYHxMx3GEzToqqh74Kpi5g7+XI6LFgwMvzlg=; b=gkJuetutAuuVRraYqMuhwf2OTYlFtRDN+bHKm4eoWUOCErL0dCOEPNMrQakIO4zW2h FtWCukFASWiWGL6T7bkaWq6oZDB7XcfeY5Om4rZO+3/TJ5VGHa66grUYeb84g/XsODru RQxn1HPZqTfQLGkkY03zYgQk3+/aSnNXnuowKZz3fhNTCZvPLT+ocF3fBvQRAIOv+GfV p9f5Ba6RDrI7Wy/XQwRlxMs/30eEKeCJ08UNwigijkeBjdGWEEVk90wf+FyXzSVygK4H TkUWtzajXFtgC6zW7/oRb4czaZOiV/rq2WVJ6q54a0nFv9Y5A1h0I0ss8ln/48VUJ1ru ysWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=TgDC9JPEYHxMx3GEzToqqh74Kpi5g7+XI6LFgwMvzlg=; b=ba/5RLjz6WXNxki/6TuAZ8DiHDamXSZ0ZdXPYv8LHyWB8NBDuS1ulM9v6mgf7bIYC3 uW4uKgIsKRA4phw4BHGehfvnbYVoeqYZYKAx9o9RIEHKQ2GAP75XtuU+6Q0hzYEI3fvU DiDY+2/kflEYCTYgr3RVkiqgpPaPUvGmcsLQJXAlp2oToHA2h4hQLdZChPm8GgxWqfXz LLvTDMlTWiaF9+GU5gqnu+l2YxEuxtyQ0sg9HOS5XebhZLKzZmIf0FhDe6Et/CnK0YSC aesZLTcGW6Q6mQBhsk15w6kIGUJOY+TnR0YMDM9RshHidB64HLBqeEgngJTtWuha9wib gwXw== X-Gm-Message-State: AKGB3mJsahr20V4WyIkzaDQYajK8DVLs4WR3kJ0yjvXIpQbFli0s7j5n 7O/8d0YM/sq+Oi7/PQPT944cFs5IzQkKaa6x3CY= X-Google-Smtp-Source: ACJfBou6hItuIBeoHlNiBIdLKQZuA9rFxTTK4h2tnc37p0f0Io1nODAYTTmjfHOfig6Kw7z7KutGcn4KgQkvvlXXs78= X-Received: by 10.37.172.97 with SMTP id r33mr18186065ybd.93.1515606215024; Wed, 10 Jan 2018 09:43:35 -0800 (PST) MIME-Version: 1.0 Received: by 10.37.11.137 with HTTP; Wed, 10 Jan 2018 09:43:34 -0800 (PST) In-Reply-To: <87bmi1pqvl.fsf@igalia.com> References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> <87bmi1pqvl.fsf@igalia.com> From: Nala Ginrut Date: Thu, 11 Jan 2018 01:43:34 +0800 Message-ID: Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports To: Andy Wingo Content-Type: text/plain; charset="UTF-8" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 30066 Cc: =?UTF-8?Q?Ludovic_Court=C3=A8s?= , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) Ah, thanks for that work! On Thu, Jan 11, 2018 at 1:26 AM, Andy Wingo wrote: > On Wed 10 Jan 2018 17:58, Nala Ginrut writes: > >> hi Andy and Ludo! >> >> What if developers enabled suspendable-ports and set the port to non-blocking? >> For example, in the non-blocking asynchronous server, I registered >> read/write waiter for suspendable-ports. And save >> delimited-continuations then yield the current task. >> In this situation, get-bytevector-n! will read n bytes with several >> times yielding by the registered read-writer, from the caller's >> perspective, get-bytevector-n! will return n bytes finally no matter >> how many times it's yielded. >> But how about the get-bytevector-some? Should it block just once and >> return the first time read m bytes then return? > > I think this is right. At most one block. FWIW we'd need to add > support for get-bytevector-some to (ice-9 suspendable-ports) to get this > to work. > > Andy From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 11 09:34:23 2018 Received: (at 30066) by debbugs.gnu.org; 11 Jan 2018 14:34:23 +0000 Received: from localhost ([127.0.0.1]:51777 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZdvy-0007j9-IT for submit@debbugs.gnu.org; Thu, 11 Jan 2018 09:34:22 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:32812) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZdvw-0007j0-IR for 30066@debbugs.gnu.org; Thu, 11 Jan 2018 09:34:21 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 8839F103AB; Thu, 11 Jan 2018 15:34:19 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id szhPfqFjpm8o; Thu, 11 Jan 2018 15:34:18 +0100 (CET) Received: from ribbon (unknown [193.50.110.92]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 3E126101D9; Thu, 11 Jan 2018 15:34:18 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: Andy Wingo Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 22 =?utf-8?Q?Niv=C3=B4se?= an 226 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Thu, 11 Jan 2018 15:34:17 +0100 In-Reply-To: <87fu7dptdn.fsf@igalia.com> (Andy Wingo's message of "Wed, 10 Jan 2018 17:32:04 +0100") Message-ID: <87o9m08nx2.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30066 Cc: 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, Andy Wingo skribis: > There are tabs in your code; would you mind doing only spaces? > > A port being unbuffered doesn't mean that it has no bytes in its > buffer. In particular, scm_unget_bytes may put bytes back into the > buffer. Or, peek-u8 might fill this buffer with one byte. > > Also, they port may have buffered write bytes (could be the port has > write buffering but no read buffering). In that case (pt->rw_random) > you need to scm_flush(). > > I suggest taking the buffered bytes from the read buffer, if any. Then > if the port is unbuffered, make a bytevector and call scm_i_read_bytes; > otherwise do the scm_fill_input path that's there already. > > One more thing, if the port goes EOF, you need to > scm_port_buffer_set_has_eof_p. I think the attached patch addresses these issues. WDYT? Thanks for the review! Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-get-bytevector-some-reads-as-much-as-possible-withou.patch Content-Transfer-Encoding: quoted-printable Content-Description: the patch >From d3a60bac6c6aae62ced6eec21b3865caaab83bb8 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Ludovic=3D20Court=3DC3=3DA8s?=3D Date: Thu, 11 Jan 2018 15:29:55 +0100 Subject: [PATCH] 'get-bytevector-some' reads as much as possible without blocking. Fixes . * libguile/ports.c (scm_i_read_bytes): Remove 'static' keyword. * libguile/ports.h (SCM_UNBUFFEREDP): New macro. (scm_i_read_bytes): New declaration. * libguile/r6rs-ports.c (scm_get_bytevector_some): When PORT is unbuffered, invoke 'scm_i_read_bytes' to read as much as we can. * test-suite/tests/r6rs-ports.test ("8.2.8 Binary Input") ["get-bytevector-some [unbuffered port]"] ["get-bytevector-some [unbuffered port, lookahead-u8]"] ["get-bytevector-some [unbuffered port, unget-bytevector]"]: New tests. --- libguile/ports.c | 6 ++++-- libguile/ports.h | 7 ++++++- libguile/r6rs-ports.c | 34 ++++++++++++++++++++++++++++------ test-suite/tests/r6rs-ports.test | 36 ++++++++++++++++++++++++++++++++++-- 4 files changed, 72 insertions(+), 11 deletions(-) diff --git a/libguile/ports.c b/libguile/ports.c index 72bb73a01..002dd1433 100644 --- a/libguile/ports.c +++ b/libguile/ports.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2001, 2003-2004, 2006-2017 +/* Copyright (C) 1995-2001, 2003-2004, 2006-2018 * Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or @@ -1543,7 +1543,9 @@ scm_peek_byte_or_eof (SCM port) return peek_byte_or_eof (port, &buf, &cur); } =20 -static size_t +/* Like read(2), read *up to* COUNT bytes from PORT into DST, starting + at OFFSET. Return 0 upon EOF. */ +size_t scm_i_read_bytes (SCM port, SCM dst, size_t start, size_t count) { size_t filled; diff --git a/libguile/ports.h b/libguile/ports.h index d131db5be..3fe64c27d 100644 --- a/libguile/ports.h +++ b/libguile/ports.h @@ -4,7 +4,7 @@ #define SCM_PORTS_H =20 /* Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, - * 2006, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundati= on, Inc. + * 2006, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2018 Free Software Fo= undation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -71,7 +71,10 @@ SCM_INTERNAL SCM scm_i_port_weak_set; #define SCM_CLOSEDP(x) (!SCM_OPENP (x)) #define SCM_CLR_PORT_OPEN_FLAG(p) \ SCM_SET_CELL_WORD_0 ((p), SCM_CELL_WORD_0 (p) & ~SCM_OPN) + #ifdef BUILDING_LIBGUILE +#define SCM_UNBUFFEREDP(x) \ + (SCM_PORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_BUF0)) #define SCM_PORT_FINALIZING_P(x) \ (SCM_CELL_WORD_0 (x) & SCM_F_PORT_FINALIZING) #define SCM_SET_PORT_FINALIZING(p) \ @@ -185,6 +188,8 @@ SCM_API int scm_get_byte_or_eof (SCM port); SCM_API int scm_peek_byte_or_eof (SCM port); SCM_API size_t scm_c_read (SCM port, void *buffer, size_t size); SCM_API size_t scm_c_read_bytes (SCM port, SCM dst, size_t start, size_t c= ount); +SCM_INTERNAL size_t scm_i_read_bytes (SCM port, SCM dst, size_t start, + size_t count); SCM_API scm_t_wchar scm_getc (SCM port); SCM_API SCM scm_read_char (SCM port); =20 diff --git a/libguile/r6rs-ports.c b/libguile/r6rs-ports.c index e944c7aab..a3d638ca0 100644 --- a/libguile/r6rs-ports.c +++ b/libguile/r6rs-ports.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2009, 2010, 2011, 2013-2015 Free Software Foundation, Inc. +/* Copyright (C) 2009, 2010, 2011, 2013-2015, 2018 Free Software Foundatio= n, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -481,9 +481,9 @@ SCM_DEFINE (scm_get_bytevector_some, "get-bytevector-so= me", 1, 0, 0, "position to point just past these bytes.") #define FUNC_NAME s_scm_get_bytevector_some { - SCM buf; + SCM buf, bv; size_t cur, avail; - SCM bv; + const size_t max_buffer_size =3D 4096; =20 SCM_VALIDATE_BINARY_INPUT_PORT (1, port); =20 @@ -494,9 +494,31 @@ SCM_DEFINE (scm_get_bytevector_some, "get-bytevector-s= ome", 1, 0, 0, return SCM_EOF_VAL; } =20 - bv =3D scm_c_make_bytevector (avail); - scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv), - avail, cur, avail); + if (SCM_UNBUFFEREDP (port) && (avail < max_buffer_size)) + { + /* PORT is unbuffered. Read as much as possible from PORT. */ + size_t read; + + bv =3D scm_c_make_bytevector (max_buffer_size); + scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (= bv), + avail, cur, avail); + + read =3D scm_i_read_bytes (port, bv, avail, + SCM_BYTEVECTOR_LENGTH (bv) - avail); + + if (read =3D=3D 0) + scm_port_buffer_set_has_eof_p (buf, SCM_BOOL_F); + + if (read + avail < SCM_BYTEVECTOR_LENGTH (bv)) + bv =3D scm_c_shrink_bytevector (bv, read + avail); + } + else + { + /* Return what's already buffered. */ + bv =3D scm_c_make_bytevector (avail); + scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (= bv), + avail, cur, avail); + } =20 return bv; } diff --git a/test-suite/tests/r6rs-ports.test b/test-suite/tests/r6rs-ports= .test index ba3131f2e..d5476f20e 100644 --- a/test-suite/tests/r6rs-ports.test +++ b/test-suite/tests/r6rs-ports.test @@ -1,6 +1,6 @@ ;;;; r6rs-ports.test --- R6RS I/O port tests. -*- coding: utf-8; -*- ;;;; -;;;; Copyright (C) 2009-2012, 2013-2015 Free Software Foundation, Inc. +;;;; Copyright (C) 2009-2012, 2013-2015, 2018 Free Software Foundation, In= c. ;;;; Ludovic Court=C3=A8s ;;;; ;;;; This library is free software; you can redistribute it and/or @@ -26,7 +26,8 @@ #:use-module (rnrs io ports) #:use-module (rnrs io simple) #:use-module (rnrs exceptions) - #:use-module (rnrs bytevectors)) + #:use-module (rnrs bytevectors) + #:use-module ((ice-9 binary-ports) #:select (unget-bytevector))) =20 (define-syntax pass-if-condition (syntax-rules () @@ -183,6 +184,37 @@ (equal? (bytevector->u8-list bv) (map char->integer (string->list str)))))) =20 + (pass-if-equal "get-bytevector-some [unbuffered port]" + (string->utf8 "Hello, world!") + ;; 'get-bytevector-some' used to return a single byte, see + ;; . + (call-with-input-string "Hello, world!" + (lambda (port) + (setvbuf port _IONBF) + (get-bytevector-some port)))) + + (pass-if-equal "get-bytevector-some [unbuffered port, lookahead-u8]" + (string->utf8 "Hello, world!") + (call-with-input-string "Hello, world!" + (lambda (port) + (setvbuf port _IONBF) + + ;; 'lookahead-u8' fills in PORT's 1-byte buffer. Yet, + ;; 'get-bytevector-some' should return the whole thing. + (and (eqv? (lookahead-u8 port) (char->integer #\H)) + (get-bytevector-some port))))) + + (pass-if-equal "get-bytevector-some [unbuffered port, unget-bytevector]" + (string->utf8 "Hello") + (call-with-input-string "Hello, world!" + (lambda (port) + (setvbuf port _IONBF) + ;; 'unget-bytevector' fills the putback buffer, and + ;; 'get-bytevector-some' should get data from there. + (unget-bytevector port (get-bytevector-all port) + 0 5) + (get-bytevector-some port)))) + (pass-if "get-bytevector-all" (let* ((str "GNU Guile") (index 0) --=20 2.15.1 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 11 14:57:25 2018 Received: (at 30066) by debbugs.gnu.org; 11 Jan 2018 19:57:25 +0000 Received: from localhost ([127.0.0.1]:52482 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZiya-0006uV-12 for submit@debbugs.gnu.org; Thu, 11 Jan 2018 14:57:25 -0500 Received: from world.peace.net ([50.252.239.5]:59574) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZiyY-0006uI-HN for 30066@debbugs.gnu.org; Thu, 11 Jan 2018 14:57:22 -0500 Received: from [98.216.255.118] (helo=yeeloong) by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1eZiyS-0000hc-40; Thu, 11 Jan 2018 14:57:16 -0500 From: Mark H Weaver To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> <87o9m08nx2.fsf@gnu.org> Date: Thu, 11 Jan 2018 14:55:07 -0500 In-Reply-To: <87o9m08nx2.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Thu, 11 Jan 2018 15:34:17 +0100") Message-ID: <87fu7cf9wk.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 30066 Cc: Andy Wingo , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) Hi Ludovic, ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Andy Wingo skribis: > >> I suggest taking the buffered bytes from the read buffer, if any. Then >> if the port is unbuffered, make a bytevector and call scm_i_read_bytes; >> otherwise do the scm_fill_input path that's there already. >> >> One more thing, if the port goes EOF, you need to >> scm_port_buffer_set_has_eof_p. > > I think the attached patch addresses these issues. WDYT? [...] > diff --git a/libguile/r6rs-ports.c b/libguile/r6rs-ports.c > index e944c7aab..a3d638ca0 100644 > --- a/libguile/r6rs-ports.c > +++ b/libguile/r6rs-ports.c > @@ -1,4 +1,4 @@ > -/* Copyright (C) 2009, 2010, 2011, 2013-2015 Free Software Foundation, I= nc. > +/* Copyright (C) 2009, 2010, 2011, 2013-2015, 2018 Free Software Foundat= ion, Inc. > * > * This library is free software; you can redistribute it and/or > * modify it under the terms of the GNU Lesser General Public License > @@ -481,9 +481,9 @@ SCM_DEFINE (scm_get_bytevector_some, "get-bytevector-= some", 1, 0, 0, > "position to point just past these bytes.") > #define FUNC_NAME s_scm_get_bytevector_some > { > - SCM buf; > + SCM buf, bv; > size_t cur, avail; > - SCM bv; > + const size_t max_buffer_size =3D 4096; >=20=20 > SCM_VALIDATE_BINARY_INPUT_PORT (1, port); >=20=20 > @@ -494,9 +494,31 @@ SCM_DEFINE (scm_get_bytevector_some, "get-bytevector= -some", 1, 0, 0, > return SCM_EOF_VAL; > } >=20=20 > - bv =3D scm_c_make_bytevector (avail); > - scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS (bv= ), > - avail, cur, avail); > + if (SCM_UNBUFFEREDP (port) && (avail < max_buffer_size)) > + { > + /* PORT is unbuffered. Read as much as possible from PORT. */ > + size_t read; > + > + bv =3D scm_c_make_bytevector (max_buffer_size); > + scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENTS= (bv), > + avail, cur, avail); > + > + read =3D scm_i_read_bytes (port, bv, avail, > + SCM_BYTEVECTOR_LENGTH (bv) - avail); Here's the R6RS specification for 'get-bytevector-some': "Reads from BINARY-INPUT-PORT, blocking as necessary, until bytes are available from BINARY-INPUT-PORT or until an end of file is reached. If bytes become available, 'get-bytevector-some' returns a freshly allocated bytevector containing the initial available bytes (at least one), and it updates BINARY-INPUT-PORT to point just past these bytes. If no input bytes are seen before an end of file is reached, the end-of-file object is returned." By my reading of this, we should block only if necessary to ensure that we return at least one byte (or EOF). In other words, if we can return at least one byte (or EOF), then we must not block, which means that we must not initiate another 'read'. Out of curiosity, is there a reason why you're using an unbuffered port in your use case? Mark From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 11 16:02:35 2018 Received: (at 30066) by debbugs.gnu.org; 11 Jan 2018 21:02:35 +0000 Received: from localhost ([127.0.0.1]:52533 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZjzf-0008Rr-2r for submit@debbugs.gnu.org; Thu, 11 Jan 2018 16:02:35 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:35224) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZjzc-0008Rj-LS for 30066@debbugs.gnu.org; Thu, 11 Jan 2018 16:02:33 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 0D8F7106B0; Thu, 11 Jan 2018 22:02:32 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2TKaHFTprSfH; Thu, 11 Jan 2018 22:02:31 +0100 (CET) Received: from ribbon (unknown [IPv6:2a01:e0a:1d:7270:af76:b9b:ca24:c465]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B7343F53A; Thu, 11 Jan 2018 22:02:30 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: Mark H Weaver Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> <87o9m08nx2.fsf@gnu.org> <87fu7cf9wk.fsf@netris.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 22 =?utf-8?Q?Niv=C3=B4se?= an 226 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Thu, 11 Jan 2018 22:02:29 +0100 In-Reply-To: <87fu7cf9wk.fsf@netris.org> (Mark H. Weaver's message of "Thu, 11 Jan 2018 14:55:07 -0500") Message-ID: <87po6gnm6y.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30066 Cc: Andy Wingo , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Hello, Mark H Weaver skribis: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: [...] >> + if (SCM_UNBUFFEREDP (port) && (avail < max_buffer_size)) >> + { >> + /* PORT is unbuffered. Read as much as possible from PORT. */ >> + size_t read; >> + >> + bv =3D scm_c_make_bytevector (max_buffer_size); >> + scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTENT= S (bv), >> + avail, cur, avail); >> + >> + read =3D scm_i_read_bytes (port, bv, avail, >> + SCM_BYTEVECTOR_LENGTH (bv) - avail); > > Here's the R6RS specification for 'get-bytevector-some': > > "Reads from BINARY-INPUT-PORT, blocking as necessary, until bytes are > available from BINARY-INPUT-PORT or until an end of file is reached. > If bytes become available, 'get-bytevector-some' returns a freshly > allocated bytevector containing the initial available bytes (at least > one), and it updates BINARY-INPUT-PORT to point just past these > bytes. If no input bytes are seen before an end of file is reached, > the end-of-file object is returned." > > By my reading of this, we should block only if necessary to ensure that > we return at least one byte (or EOF). In other words, if we can return > at least one byte (or EOF), then we must not block, which means that we > must not initiate another 'read'. Indeed. So perhaps the condition above should be changed to: if (SCM_UNBUFFEREDP (port) && (avail =3D=3D 0)) ? > Out of curiosity, is there a reason why you're using an unbuffered port > in your use case? It=E2=80=99s to implement redirect =C3=A0 la socat: https://git.savannah.gnu.org/cgit/guix.git/commit/?id=3D17af5d51de7c40756= a4a39d336f81681de2ba447 Thanks, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Thu Jan 11 16:56:14 2018 Received: (at 30066) by debbugs.gnu.org; 11 Jan 2018 21:56:14 +0000 Received: from localhost ([127.0.0.1]:52600 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZkpa-00056E-38 for submit@debbugs.gnu.org; Thu, 11 Jan 2018 16:56:14 -0500 Received: from world.peace.net ([50.252.239.5]:60040) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZkpX-000560-Ti for 30066@debbugs.gnu.org; Thu, 11 Jan 2018 16:56:12 -0500 Received: from [98.216.255.118] (helo=jojen) by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1eZkpR-0001Ol-Mo; Thu, 11 Jan 2018 16:56:05 -0500 From: Mark H Weaver To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> <87o9m08nx2.fsf@gnu.org> <87fu7cf9wk.fsf@netris.org> <87po6gnm6y.fsf@gnu.org> Date: Thu, 11 Jan 2018 16:55:38 -0500 In-Reply-To: <87po6gnm6y.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Thu, 11 Jan 2018 22:02:29 +0100") Message-ID: <87a7xkxdph.fsf@netris.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 30066 Cc: Andy Wingo , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Mark H Weaver skribis: > >> ludo@gnu.org (Ludovic Court=C3=A8s) writes: > > [...] > >>> + if (SCM_UNBUFFEREDP (port) && (avail < max_buffer_size)) >>> + { >>> + /* PORT is unbuffered. Read as much as possible from PORT. */ >>> + size_t read; >>> + >>> + bv =3D scm_c_make_bytevector (max_buffer_size); >>> + scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTEN= TS (bv), >>> + avail, cur, avail); >>> + >>> + read =3D scm_i_read_bytes (port, bv, avail, >>> + SCM_BYTEVECTOR_LENGTH (bv) - avail); >> >> Here's the R6RS specification for 'get-bytevector-some': >> >> "Reads from BINARY-INPUT-PORT, blocking as necessary, until bytes are >> available from BINARY-INPUT-PORT or until an end of file is reached. >> If bytes become available, 'get-bytevector-some' returns a freshly >> allocated bytevector containing the initial available bytes (at least >> one), and it updates BINARY-INPUT-PORT to point just past these >> bytes. If no input bytes are seen before an end of file is reached, >> the end-of-file object is returned." >> >> By my reading of this, we should block only if necessary to ensure that >> we return at least one byte (or EOF). In other words, if we can return >> at least one byte (or EOF), then we must not block, which means that we >> must not initiate another 'read'. > > Indeed. So perhaps the condition above should be changed to: > > if (SCM_UNBUFFEREDP (port) && (avail =3D=3D 0)) > > ? That won't work, because the earlier call to 'scm_fill_input' will have already initiated a 'read' if the buffer was empty. The read buffer size will determine the maximum number of bytes read, which will be 1 in the case of an unbuffered port. So, at the point of this condition, 'avail =3D=3D 0' will occur only if EOF was encountered, in which case you must return EOF without attempting another 'read'. In order to avoid unnecessary blocking, there must be only one 'read' call, and it must be initiated only if the buffer was already empty. So, in order to accomplish your goal here, I don't see how you can use 'scm_fill_input', unless you temporarily increase the size of the read buffer beforehand. Instead, I think you need to first check if the read buffer contains any bytes. If so, empty the buffer and return them. If the buffer is empty, the next thing to check is 'scm_port_buffer_has_eof_p'. If it's set, then clear that flag and return EOF. Otherwise, if the buffer is empty and 'scm_port_buffer_has_eof_p' is false, then you must do what 'scm_fill_input' would have done, except using your larger buffer instead of the port's internal read buffer. In particular, you must first switch the port to "reading" mode, flushing the write buffer if 'rw_random' is set. Also, I'd prefer to move this code to ports.c in order to avoid adding more internal declarations to ports.h and changing more functions from 'static' to global functions. >> Out of curiosity, is there a reason why you're using an unbuffered port >> in your use case? > > It=E2=80=99s to implement redirect =C3=A0 la socat: > > https://git.savannah.gnu.org/cgit/guix.git/commit/?id=3D17af5d51de7c407= 56a4a39d336f81681de2ba447 Why is an unbuffered port being used here? Can we change it to a buffered port? Mark From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 12 04:01:20 2018 Received: (at 30066) by debbugs.gnu.org; 12 Jan 2018 09:01:20 +0000 Received: from localhost ([127.0.0.1]:52848 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZvDE-0005VF-7X for submit@debbugs.gnu.org; Fri, 12 Jan 2018 04:01:20 -0500 Received: from pb-sasl2.pobox.com ([64.147.108.67]:52798 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZvDC-0005V7-CD for 30066@debbugs.gnu.org; Fri, 12 Jan 2018 04:01:19 -0500 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 82CB6A682A; Fri, 12 Jan 2018 04:01:16 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=otxt7qNJ5vso fCUj7AJtbx1bc7g=; b=VIAaH0nBLXoFtxFyERyfdn5bgXFjPCIvWTwvCl3qN4v/ RspeZP46i7TcifUfeLPdaRIRh3xiE6f1X5DXs8qU8AluHwa9tf6uJn/NCkyXPU+u ukhNTpxWLNxEtLtd76jXzLxIf5F1lG2FEHMnptYj6yc7ZInPufv/mSV/j18owKU= Received: from pb-sasl2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 68890A6826; Fri, 12 Jan 2018 04:01:16 -0500 (EST) Received: from rusty (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl2.pobox.com (Postfix) with ESMTPSA id 7BF2FA6822; Fri, 12 Jan 2018 04:01:15 -0500 (EST) From: Andy Wingo To: Mark H Weaver Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> <87o9m08nx2.fsf@gnu.org> <87fu7cf9wk.fsf@netris.org> <87po6gnm6y.fsf@gnu.org> <87a7xkxdph.fsf@netris.org> Date: Fri, 12 Jan 2018 10:01:11 +0100 In-Reply-To: <87a7xkxdph.fsf@netris.org> (Mark H. Weaver's message of "Thu, 11 Jan 2018 16:55:38 -0500") Message-ID: <87373bpi20.fsf@igalia.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pobox-Relay-ID: 2541A2D0-F777-11E7-B790-EA54894C8D7C-02397024!pb-sasl2.pobox.com X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 30066 Cc: Ludovic =?utf-8?Q?Court=C3=A8s?= , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.7 (/) On Thu 11 Jan 2018 22:55, Mark H Weaver writes: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> Mark H Weaver skribis: >> >>> ludo@gnu.org (Ludovic Court=C3=A8s) writes: >> >> [...] >> >>>> + if (SCM_UNBUFFEREDP (port) && (avail < max_buffer_size)) >>>> + { >>>> + /* PORT is unbuffered. Read as much as possible from PORT. */ >>>> + size_t read; >>>> + >>>> + bv =3D scm_c_make_bytevector (max_buffer_size); >>>> + scm_port_buffer_take (buf, (scm_t_uint8 *) SCM_BYTEVECTOR_CONTE= NTS (bv), >>>> + avail, cur, avail); >>>> + >>>> + read =3D scm_i_read_bytes (port, bv, avail, >>>> + SCM_BYTEVECTOR_LENGTH (bv) - avail); >>> >>> Here's the R6RS specification for 'get-bytevector-some': >>> >>> "Reads from BINARY-INPUT-PORT, blocking as necessary, until bytes are >>> available from BINARY-INPUT-PORT or until an end of file is reached. >>> If bytes become available, 'get-bytevector-some' returns a freshly >>> allocated bytevector containing the initial available bytes (at least >>> one), and it updates BINARY-INPUT-PORT to point just past these >>> bytes. If no input bytes are seen before an end of file is reached, >>> the end-of-file object is returned." >>> >>> By my reading of this, we should block only if necessary to ensure that >>> we return at least one byte (or EOF). In other words, if we can return >>> at least one byte (or EOF), then we must not block, which means that we >>> must not initiate another 'read'. >> >> Indeed. So perhaps the condition above should be changed to: >> >> if (SCM_UNBUFFEREDP (port) && (avail =3D=3D 0)) >> >> ? > > That won't work, because the earlier call to 'scm_fill_input' will have > already initiated a 'read' if the buffer was empty. The read buffer > size will determine the maximum number of bytes read, which will be 1 in > the case of an unbuffered port. So, at the point of this condition, > 'avail =3D=3D 0' will occur only if EOF was encountered, in which case you > must return EOF without attempting another 'read'. > > In order to avoid unnecessary blocking, there must be only one 'read' > call, and it must be initiated only if the buffer was already empty. > > So, in order to accomplish your goal here, I don't see how you can use > 'scm_fill_input', unless you temporarily increase the size of the read > buffer beforehand. > > Instead, I think you need to first check if the read buffer contains any > bytes. If so, empty the buffer and return them. If the buffer is > empty, the next thing to check is 'scm_port_buffer_has_eof_p'. If it's > set, then clear that flag and return EOF. > > Otherwise, if the buffer is empty and 'scm_port_buffer_has_eof_p' is > false, then you must do what 'scm_fill_input' would have done, except > using your larger buffer instead of the port's internal read buffer. In > particular, you must first switch the port to "reading" mode, flushing > the write buffer if 'rw_random' is set. > > Also, I'd prefer to move this code to ports.c in order to avoid adding > more internal declarations to ports.h and changing more functions from > 'static' to global functions. I agree with Mark here -- thanks for the close review. >>> Out of curiosity, is there a reason why you're using an unbuffered port >>> in your use case? >> >> It=E2=80=99s to implement redirect =C3=A0 la socat: >> >> https://git.savannah.gnu.org/cgit/guix.git/commit/?id=3D17af5d51de7c40= 756a4a39d336f81681de2ba447 > > Why is an unbuffered port being used here? Can we change it to a > buffered port? This was also a question I had! If you make it a buffered port at 4096 bytes (for example), then get-bytevector-some works exactly like you want it to, no? Andy From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 12 05:15:14 2018 Received: (at 30066) by debbugs.gnu.org; 12 Jan 2018 10:15:14 +0000 Received: from localhost ([127.0.0.1]:52889 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZwMj-0007Cq-TR for submit@debbugs.gnu.org; Fri, 12 Jan 2018 05:15:14 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:39994) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZwMh-0007Cg-0h for 30066@debbugs.gnu.org; Fri, 12 Jan 2018 05:15:12 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 19AA4109DD; Fri, 12 Jan 2018 11:15:10 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xbJTJyxqKG-o; Fri, 12 Jan 2018 11:15:09 +0100 (CET) Received: from ribbon (unknown [193.50.110.92]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 32CBE101EA; Fri, 12 Jan 2018 11:15:09 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: Andy Wingo Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> <87o9m08nx2.fsf@gnu.org> <87fu7cf9wk.fsf@netris.org> <87po6gnm6y.fsf@gnu.org> <87a7xkxdph.fsf@netris.org> <87373bpi20.fsf@igalia.com> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 23 =?utf-8?Q?Niv=C3=B4se?= an 226 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Fri, 12 Jan 2018 11:15:08 +0100 In-Reply-To: <87373bpi20.fsf@igalia.com> (Andy Wingo's message of "Fri, 12 Jan 2018 10:01:11 +0100") Message-ID: <87o9lzs7rn.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30066 Cc: Mark H Weaver , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Andy Wingo skribis: > On Thu 11 Jan 2018 22:55, Mark H Weaver writes: [...] >>>> Out of curiosity, is there a reason why you're using an unbuffered port >>>> in your use case? >>> >>> It=E2=80=99s to implement redirect =C3=A0 la socat: >>> >>> https://git.savannah.gnu.org/cgit/guix.git/commit/?id=3D17af5d51de7c4= 0756a4a39d336f81681de2ba447 >> >> Why is an unbuffered port being used here? Can we change it to a >> buffered port? > > This was also a question I had! If you make it a buffered port at 4096 > bytes (for example), then get-bytevector-some works exactly like you > want it to, no? It might work, but that=E2=80=99s more by chance no? I mean, if we declare the port as buffered, then we give the I/O routines the =E2=80=9Cright=E2=80=9D to fill in that buffer. WDYT? Thanks, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 12 05:33:43 2018 Received: (at 30066) by debbugs.gnu.org; 12 Jan 2018 10:33:43 +0000 Received: from localhost ([127.0.0.1]:52910 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZwed-0007e7-56 for submit@debbugs.gnu.org; Fri, 12 Jan 2018 05:33:43 -0500 Received: from pb-sasl2.pobox.com ([64.147.108.67]:58861 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eZwea-0007dx-Mf for 30066@debbugs.gnu.org; Fri, 12 Jan 2018 05:33:41 -0500 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 2C42FA6CC2; Fri, 12 Jan 2018 05:33:40 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=c1OzBnN1HF+g CrWIIAvALFWJNAc=; b=Sx/R9ppn3d0siOi7vU/fDB6GxJvzZWsP2OkPJD2vQwYQ hygcSI0VBritAPjDM1xI/7b1fKgXzmeGZ8IJadPBRKVP5LkYxtKLrv7SaNnxOn9y v+qOxRYQoMUNNIpMSjJvOIum40HsN4dgWE6KlsjkGq90h8aHQ8W5LG/N1S//E/o= Received: from pb-sasl2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 2502EA6CC1; Fri, 12 Jan 2018 05:33:40 -0500 (EST) Received: from rusty (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl2.pobox.com (Postfix) with ESMTPSA id 6A9B3A6CC0; Fri, 12 Jan 2018 05:33:39 -0500 (EST) From: Andy Wingo To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> <87o9m08nx2.fsf@gnu.org> <87fu7cf9wk.fsf@netris.org> <87po6gnm6y.fsf@gnu.org> <87a7xkxdph.fsf@netris.org> <87373bpi20.fsf@igalia.com> <87o9lzs7rn.fsf@gnu.org> Date: Fri, 12 Jan 2018 11:33:32 +0100 In-Reply-To: <87o9lzs7rn.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Fri, 12 Jan 2018 11:15:08 +0100") Message-ID: <87mv1jnz7n.fsf@igalia.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pobox-Relay-ID: 0DB33CA2-F784-11E7-9571-EA54894C8D7C-02397024!pb-sasl2.pobox.com X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 30066 Cc: Mark H Weaver , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.7 (/) On Fri 12 Jan 2018 11:15, ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Andy Wingo skribis: > >> On Thu 11 Jan 2018 22:55, Mark H Weaver writes: > > [...] > >>>>> Out of curiosity, is there a reason why you're using an unbuffered po= rt >>>>> in your use case? >>>> >>>> It=E2=80=99s to implement redirect =C3=A0 la socat: >>>> >>>> https://git.savannah.gnu.org/cgit/guix.git/commit/?id=3D17af5d51de7c= 40756a4a39d336f81681de2ba447 >>> >>> Why is an unbuffered port being used here? Can we change it to a >>> buffered port? >> >> This was also a question I had! If you make it a buffered port at 4096 >> bytes (for example), then get-bytevector-some works exactly like you >> want it to, no? > > It might work, but that=E2=80=99s more by chance no? No, it is reliable. get-bytevector-some on a buffered port must either return all the buffered bytes or perform exactly one read (up to the buffer size) and either return those bytes or EOF. As far as I understand, that is exactly what you want. Using buffered ports has two additional advantages: you get to specify the read size, and returned bytevectors can be allocated to precisely the right size (no need to overallocate then truncate). Andy From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 13 15:53:43 2018 Received: (at 30066) by debbugs.gnu.org; 13 Jan 2018 20:53:43 +0000 Received: from localhost ([127.0.0.1]:55164 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eaSo9-0007FJ-FV for submit@debbugs.gnu.org; Sat, 13 Jan 2018 15:53:43 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:52428) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eaSo7-0007FB-2c for 30066@debbugs.gnu.org; Sat, 13 Jan 2018 15:53:40 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id E9EB910A6A; Sat, 13 Jan 2018 21:53:36 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id u3Lj3GCz0_DO; Sat, 13 Jan 2018 21:53:36 +0100 (CET) Received: from ribbon (unknown [IPv6:2a01:e0a:1d:7270:af76:b9b:ca24:c465]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B06CD10845; Sat, 13 Jan 2018 21:53:35 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: Andy Wingo Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> <87o9m08nx2.fsf@gnu.org> <87fu7cf9wk.fsf@netris.org> <87po6gnm6y.fsf@gnu.org> <87a7xkxdph.fsf@netris.org> <87373bpi20.fsf@igalia.com> <87o9lzs7rn.fsf@gnu.org> <87mv1jnz7n.fsf@igalia.com> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 24 =?utf-8?Q?Niv=C3=B4se?= an 226 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Sat, 13 Jan 2018 21:53:34 +0100 In-Reply-To: <87mv1jnz7n.fsf@igalia.com> (Andy Wingo's message of "Fri, 12 Jan 2018 11:33:32 +0100") Message-ID: <87zi5hmqep.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30066 Cc: Mark H Weaver , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) Hey, Andy Wingo skribis: > On Fri 12 Jan 2018 11:15, ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> Andy Wingo skribis: >> >>> On Thu 11 Jan 2018 22:55, Mark H Weaver writes: >> >> [...] >> >>>>>> Out of curiosity, is there a reason why you're using an unbuffered p= ort >>>>>> in your use case? >>>>> >>>>> It=E2=80=99s to implement redirect =C3=A0 la socat: >>>>> >>>>> https://git.savannah.gnu.org/cgit/guix.git/commit/?id=3D17af5d51de7= c40756a4a39d336f81681de2ba447 >>>> >>>> Why is an unbuffered port being used here? Can we change it to a >>>> buffered port? >>> >>> This was also a question I had! If you make it a buffered port at 4096 >>> bytes (for example), then get-bytevector-some works exactly like you >>> want it to, no? >> >> It might work, but that=E2=80=99s more by chance no? > > No, it is reliable. get-bytevector-some on a buffered port must either > return all the buffered bytes or perform exactly one read (up to the > buffer size) and either return those bytes or EOF. As far as I > understand, that is exactly what you want. Indeed, that works well, thanks! So, after all, problem solved? I think the confusion for me comes from the fact that we don=E2=80=99t have= a FILE*/fd distinction like in C. It=E2=80=99s as if we were always using FI= LE* in the sense that I=E2=80=99m never sure what=E2=80=99s going to happen or = whether a particular behavior can be relied on. Thank you, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 16 08:19:55 2018 Received: (at 30066) by debbugs.gnu.org; 16 Feb 2018 13:19:55 +0000 Received: from localhost ([127.0.0.1]:45786 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1emfvf-0000ly-IG for submit@debbugs.gnu.org; Fri, 16 Feb 2018 08:19:55 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:34488) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1emfvd-0000lq-Iv for 30066@debbugs.gnu.org; Fri, 16 Feb 2018 08:19:54 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 10BF1115E9; Fri, 16 Feb 2018 14:19:53 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tTXtc7xcc0wY; Fri, 16 Feb 2018 14:19:51 +0100 (CET) Received: from ribbon (unknown [193.50.110.160]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 520C7FB09; Fri, 16 Feb 2018 14:19:51 +0100 (CET) From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: Andy Wingo Subject: Re: bug#30066: 'get-bytevector-some' returns only 1 byte from unbuffered ports References: <87zi5lrc3x.fsf@gnu.org> <87tvvtr9ge.fsf@gnu.org> <87fu7dptdn.fsf@igalia.com> <87o9m08nx2.fsf@gnu.org> <87fu7cf9wk.fsf@netris.org> <87po6gnm6y.fsf@gnu.org> <87a7xkxdph.fsf@netris.org> <87373bpi20.fsf@igalia.com> <87o9lzs7rn.fsf@gnu.org> <87mv1jnz7n.fsf@igalia.com> <87zi5hmqep.fsf@gnu.org> Date: Fri, 16 Feb 2018 14:19:50 +0100 In-Reply-To: <87zi5hmqep.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sat, 13 Jan 2018 21:53:34 +0100") Message-ID: <87sha1nkax.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: 30066 Cc: Mark H Weaver , 30066@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) ludo@gnu.org (Ludovic Court=C3=A8s) skribis: > Andy Wingo skribis: > >> On Fri 12 Jan 2018 11:15, ludo@gnu.org (Ludovic Court=C3=A8s) writes: >> >>> Andy Wingo skribis: >>> >>>> On Thu 11 Jan 2018 22:55, Mark H Weaver writes: >>> >>> [...] >>> >>>>>>> Out of curiosity, is there a reason why you're using an unbuffered = port >>>>>>> in your use case? >>>>>> >>>>>> It=E2=80=99s to implement redirect =C3=A0 la socat: >>>>>> >>>>>> https://git.savannah.gnu.org/cgit/guix.git/commit/?id=3D17af5d51de= 7c40756a4a39d336f81681de2ba447 >>>>> >>>>> Why is an unbuffered port being used here? Can we change it to a >>>>> buffered port? >>>> >>>> This was also a question I had! If you make it a buffered port at 4096 >>>> bytes (for example), then get-bytevector-some works exactly like you >>>> want it to, no? >>> >>> It might work, but that=E2=80=99s more by chance no? >> >> No, it is reliable. get-bytevector-some on a buffered port must either >> return all the buffered bytes or perform exactly one read (up to the >> buffer size) and either return those bytes or EOF. As far as I >> understand, that is exactly what you want. > > Indeed, that works well, thanks! So, after all, problem solved? I=E2=80=99m closing this as not-a-bug. Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Fri Feb 16 08:19:57 2018 Received: (at control) by debbugs.gnu.org; 16 Feb 2018 13:19:58 +0000 Received: from localhost ([127.0.0.1]:45789 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1emfvh-0000mD-Ql for submit@debbugs.gnu.org; Fri, 16 Feb 2018 08:19:57 -0500 Received: from hera.aquilenet.fr ([185.233.100.1]:34494) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1emfvg-0000m6-US for control@debbugs.gnu.org; Fri, 16 Feb 2018 08:19:57 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 806891168C for ; Fri, 16 Feb 2018 14:19:56 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ayr45t9aHg8u for ; Fri, 16 Feb 2018 14:19:56 +0100 (CET) Received: from ribbon (unknown [193.50.110.160]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 0805BFB09 for ; Fri, 16 Feb 2018 14:19:56 +0100 (CET) Date: Fri, 16 Feb 2018 14:19:55 +0100 Message-Id: <87r2plnkas.fsf@gnu.org> To: control@debbugs.gnu.org From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: control message for bug #30066 MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 1.0 (+) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) tags 30066 notabug close 30066 From unknown Mon Jun 23 04:15:32 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 17 Mar 2018 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator