From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:57547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVHp5-0005Wu-Iz for guix-patches@gnu.org; Mon, 27 May 2019 11:46:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVHp4-0003pA-LH for guix-patches@gnu.org; Mon, 27 May 2019 11:46:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40284) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hVHp4-0003p2-Io for guix-patches@gnu.org; Mon, 27 May 2019 11:46:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hVHp4-0001MU-Gh for guix-patches@gnu.org; Mon, 27 May 2019 11:46:02 -0400 Subject: [bug#35880] [PATCH 1/7] lzlib: Add 'make-lzip-input-port/compressed'. Resent-Message-ID: From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <20190524134238.22802-1-ludo@gnu.org> <87d0k6o3am.fsf@ambrevar.xyz> <87ftp1m1te.fsf@gnu.org> Date: Mon, 27 May 2019 17:45:21 +0200 In-Reply-To: <87ftp1m1te.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sun, 26 May 2019 21:51:41 +0200") Message-ID: <87blznsxym.fsf@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Pierre Neidhardt Cc: 35880@debbugs.gnu.org Ludovic Court=C3=A8s skribis: > Pierre Neidhardt skribis: [...] >>> +(define (lzwrite! encoder source source-offset source-count >>> + target target-offset target-count) >>> + "Write up to SOURCE-COUNT bytes from SOURCE to ENCODER, and read up = to >>> +TARGET-COUNT bytes into TARGET at TARGET-OFFSET. Return two values: t= he >>> +number of bytes read from SOURCE, and the number of bytes written to T= ARGET." >>> + (define read >>> + (if (< 0 (lz-compress-write-size encoder)) >>> + (match (lz-compress-write encoder source source-offset source-= count) >>> + (0 (lz-compress-finish encoder) 0) >>> + (n n)) >>> + 0)) >>> + >>> + (let loop () >>> + (match (lz-compress-read encoder target target-offset target-count) >>> + (0 (loop)) >>> + (written (values read written))))) >> >> Why looping on 0? If there is no byte to read, wouldn't this loop indef= initely? > > Hmm, good point. The idea is that =E2=80=98lzwrite!=E2=80=99 should retu= rn 0 only on > end-of-file, but then the loop should include reading more from SOURCE. > I=E2=80=99ll follow up on this one. I noticed that =E2=80=98lz-compress-read=E2=80=99 is documented to return a= =E2=80=9Cstrictly positive integer=E2=80=9D, so I=E2=80=99m changing it to this: --8<---------------cut here---------------start------------->8--- (define (lzwrite! encoder source source-offset source-count target target-offset target-count) "Write up to SOURCE-COUNT bytes from SOURCE to ENCODER, and read up to TARGET-COUNT bytes into TARGET at TARGET-OFFSET. Return two values: the number of bytes read from SOURCE, and the non-zero number of bytes written = to TARGET." (define read (if (< 0 (lz-compress-write-size encoder)) (match (lz-compress-write encoder source source-offset source-count) (0 (lz-compress-finish encoder) 0) (n n)) 0)) (define written ;; Note: 'lz-compress-read' promises to return a non-zero integer. (lz-compress-read encoder target target-offset target-count)) (values read written)) --8<---------------cut here---------------end--------------->8--- Let me know what you think! Ludo=E2=80=99.