guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/01: guix: Simplify and robustify lzread!.


From: guix-commits
Subject: 01/01: guix: Simplify and robustify lzread!.
Date: Tue, 7 May 2019 12:44:42 -0400 (EDT)

ambrevar pushed a commit to branch master
in repository guix.

commit ecfc54403e2a1934b4f6e84ddad429b7970091fa
Author: Pierre Neidhardt <address@hidden>
Date:   Tue May 7 18:40:40 2019 +0200

    guix: Simplify and robustify lzread!.
    
    * guix/lzlib.scm (lzread!): Do it.
    
    Previously lzread! would fail if COUNT was bigger
    than (lz-decompress-write-size).  This is possible if a previous call to
    lzread! didn't empty the LZ_decompress input buffer (e.g. BV was too small 
to
    fit all the data).
---
 guix/lzlib.scm | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/guix/lzlib.scm b/guix/lzlib.scm
index d596f0d..a6dac46 100644
--- a/guix/lzlib.scm
+++ b/guix/lzlib.scm
@@ -491,27 +491,19 @@ perhaps not yet read."
 
 
 ;; High level functions.
-(define %lz-decompress-input-buffer-size (* 64 1024))
-
 (define* (lzread! decoder file-port bv
                   #:optional (start 0) (count (bytevector-length bv)))
   "Read up to COUNT bytes from FILE-PORT into BV at offset START.  Return the
 number of uncompressed bytes actually read; it is zero if COUNT is zero or if
 the end-of-stream has been reached."
   ;; WARNING: Because we don't alternate between lz-reads and lz-writes, we 
can't
-  ;; process more than %lz-decompress-input-buffer-size from the file-port.
-  (when (> count %lz-decompress-input-buffer-size)
-    (set! count %lz-decompress-input-buffer-size))
-  (let* ((written 0)
-         (read 0)
-         (file-bv (get-bytevector-n file-port count)))
+  ;; process more than lz-decompress-write-size from the file-port.
+  (when (> count (lz-decompress-write-size decoder))
+    (set! count (lz-decompress-write-size decoder)))
+  (let ((file-bv (get-bytevector-n file-port count)))
     (unless (eof-object? file-bv)
-      (begin
-        (while (and (< 0 (lz-decompress-write-size decoder))
-                    (< written (bytevector-length file-bv)))
-          (set! written (+ written
-                           (lz-decompress-write decoder file-bv written
-                                                (- (bytevector-length file-bv) 
written)))))))
+      (lz-decompress-write decoder file-bv 0 (bytevector-length file-bv))))
+  (let ((read 0))
     (let loop ((rd 0))
       (if (< start (bytevector-length bv))
           (begin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]