From debbugs-submit-bounces@debbugs.gnu.org Sun Mar 10 14:06:33 2019 Received: (at submit) by debbugs.gnu.org; 10 Mar 2019 18:06:33 +0000 Received: from localhost ([127.0.0.1]:38310 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h32qG-0006Wo-Ht for submit@debbugs.gnu.org; Sun, 10 Mar 2019 14:06:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51014) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h32qC-0006WP-Sy for submit@debbugs.gnu.org; Sun, 10 Mar 2019 14:06:30 -0400 Received: from lists.gnu.org ([209.51.188.17]:37613) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h32q7-0000Yt-Pf for submit@debbugs.gnu.org; Sun, 10 Mar 2019 14:06:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h32q4-0005Va-EW for guix-patches@gnu.org; Sun, 10 Mar 2019 14:06:23 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,RCVD_IN_DNSWL_NONE, URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h32m8-0006RO-VE for guix-patches@gnu.org; Sun, 10 Mar 2019 14:02:20 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:55831) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h32m8-0006OZ-KC for guix-patches@gnu.org; Sun, 10 Mar 2019 14:02:16 -0400 X-Originating-IP: 90.92.41.33 Received: from localhost.localdomain (lfbn-1-12225-33.w90-92.abo.wanadoo.fr [90.92.41.33]) (Authenticated sender: mail@ambrevar.xyz) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id E15351BF206 for ; Sun, 10 Mar 2019 18:02:09 +0000 (UTC) From: Pierre Neidhardt To: guix-patches@gnu.org Subject: [PATCH 1/2] Add (guix lzlib). Date: Sun, 10 Mar 2019 19:02:09 +0100 Message-Id: <20190310180209.11578-1-mail@ambrevar.xyz> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.70.183.201 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: submit 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 (-) * guix/lzlib.scm, tests/lzlib.scm: New files. * Makefile.am (MODULES): Add guix/lzlib.scm. (SCM_TESTS): Add tests/lzlib.scm. * m4/guix.m4 (GUIX_LIBLZ_LIBDIR): New macro. * configure.ac (LIBLZ_LIBDIR): Use it. Define and substitute 'LIBLZ'. * guix/config.scm.in (%liblz): New variable. --- Makefile.am | 2 + configure.ac | 11 + guix/config.scm.in | 7 +- guix/lzlib.scm | 592 +++++++++++++++++++++++++++++++++++++++++++++ m4/guix.m4 | 12 + tests/lzlib.scm | 62 +++++ 6 files changed, 685 insertions(+), 1 deletion(-) create mode 100644 guix/lzlib.scm create mode 100644 tests/lzlib.scm diff --git a/Makefile.am b/Makefile.am index cf35770ba7..fd48c57a8d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -101,6 +101,7 @@ MODULES = \ guix/cve.scm \ guix/workers.scm \ guix/zlib.scm \ + guix/lzlib.scm \ guix/build-system.scm \ guix/build-system/android-ndk.scm \ guix/build-system/ant.scm \ @@ -389,6 +390,7 @@ SCM_TESTS = \ tests/cve.scm \ tests/workers.scm \ tests/zlib.scm \ + tests/lzlib.scm \ tests/file-systems.scm \ tests/uuid.scm \ tests/system.scm \ diff --git a/configure.ac b/configure.ac index 5d70de4beb..edfe807ddd 100644 --- a/configure.ac +++ b/configure.ac @@ -258,6 +258,17 @@ AC_MSG_CHECKING([for zlib's shared library name]) AC_MSG_RESULT([$LIBZ]) AC_SUBST([LIBZ]) +dnl Library name of lzlib suitable for 'dynamic-link'. +GUIX_LIBLZ_LIBDIR([liblz_libdir]) +if test "x$liblz_libdir" = "x"; then + LIBLZ="liblz" +else + LIBLZ="$liblz_libdir/liblz" +fi +AC_MSG_CHECKING([for lzlib's shared library name]) +AC_MSG_RESULT([$LIBLZ]) +AC_SUBST([LIBLZ]) + dnl Check for Guile-SSH, for the (guix ssh) module. GUIX_CHECK_GUILE_SSH AM_CONDITIONAL([HAVE_GUILE_SSH], diff --git a/guix/config.scm.in b/guix/config.scm.in index d2ec9921c6..0808947ddd 100644 --- a/guix/config.scm.in +++ b/guix/config.scm.in @@ -37,7 +37,8 @@ %libz %gzip %bzip2 - %xz)) + %xz + %liblz)) ;;; Commentary: ;;; @@ -103,4 +104,8 @@ (define %xz "@XZ@") +(define %liblz + ;; TODO: Set this dynamically. + "/gnu/store/8db7vivi8p9mpkbphb8xy8gh2bkwc4iz-lzlib-1.11/lib/liblz") + ;;; config.scm ends here diff --git a/guix/lzlib.scm b/guix/lzlib.scm new file mode 100644 index 0000000000..abab3f761c --- /dev/null +++ b/guix/lzlib.scm @@ -0,0 +1,592 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Pierre Neidhardt +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix lzlib) + #:use-module (rnrs bytevectors) + #:use-module (rnrs arithmetic bitwise) + #:use-module (ice-9 binary-ports) + #:use-module (ice-9 match) + #:use-module (system foreign) + #:use-module (guix config) + #:export (lzlib-available? + make-lzip-input-port + make-lzip-output-port + call-with-lzip-input-port + call-with-lzip-output-port + %default-member-length-limit + %default-compression-level)) + +;;; Commentary: +;;; +;;; Bindings to the lzlib / liblz API. +;;; +;;; Code: + +(define %lzlib + ;; File name of lzlib's shared library. When updating via 'guix pull', + ;; '%liblz' might be undefined so protect against it. + (delay (dynamic-link (if (defined? '%liblz) + %liblz + "liblz")))) + +(define (lzlib-available?) + "Return true if lzlib is available, #f otherwise." + (false-if-exception (force %lzlib))) + +(define (lzlib-procedure ret name parameters) + "Return a procedure corresponding to C function NAME in liblz, or #f if +either lzlib or the function could not be found." + (match (false-if-exception (dynamic-func name (force %lzlib))) + ((? pointer? ptr) + (pointer->procedure ret ptr parameters)) + (#f + #f))) + +(define-wrapped-pointer-type + ;; Scheme counterpart of the 'LZ_Decoder' opaque type. + lz-decoder? + pointer->lz-decoder + lz-decoder->pointer + (lambda (obj port) + (format port "#" + (number->string (object-address obj) 16)))) + +(define-wrapped-pointer-type + ;; Scheme counterpart of the 'LZ_Encoder' opaque type. + lz-encoder? + pointer->lz-encoder + lz-encoder->pointer + (lambda (obj port) + (format port "#" + (number->string (object-address obj) 16)))) + +(define %error-number-ok + ;; TODO: How do we get the values of a C enum? + 0) + + +;; Compression bindings. + +(define lz-compress-open + (let ((proc (lzlib-procedure '* "LZ_compress_open" (list int int uint64)))) + ;; TODO: member-size default is INT64_MAX. Is there a better way to do this with Guile? + (lambda* (dictionary-size match-length-limit #:optional (member-size #x7FFFFFFFFFFFFFFF)) + "Initializes the internal stream state for compression and returns a +pointer that can only be used as the encoder argument for the other +lz-compress functions, or a null pointer if the encoder could not be +allocated. + +See the manual: (lzlib) Compression functions." + (let ((encoder-ptr (proc dictionary-size match-length-limit member-size))) + (if (not (= (lz-compress-error encoder-ptr) -1)) + (pointer->lz-encoder encoder-ptr) + (throw 'lzlib-error 'lz-compress-open)))))) + +(define lz-compress-close + (let ((proc (lzlib-procedure int "LZ_compress_close" '(*)))) + (lambda (encoder) + "Close encoder. ENCODER can no longer be used as an argument to any +lz-compress function. " + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (= ret -1) + (throw 'lzlib-error 'lz-compress-close ret) + ret))))) + +(define lz-compress-finish + (let ((proc (lzlib-procedure int "LZ_compress_finish" '(*)))) + (lambda (encoder) + "Use this function to tell that all the data for this member have +already been written (with the `lz-compress-write' function). It is safe to +call `lz-compress-finish' as many times as needed. After all the produced +compressed data have been read with `lz-compress-read' and +`lz-compress-member-finished?' returns #t, a new member can be started with +'lz-compress-restart-member'." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (when (= ret -1) + (throw 'lzlib-error 'lz-compress-finish (lz-compress-error encoder))))))) + +(define lz-compress-restart-member + (let ((proc (lzlib-procedure int "LZ_compress_restart_member" (list '* uint64)))) + (lambda (encoder member-size) + "Use this function to start a new member in a multimember data stream. +Call this function only after `lz-compress-member-finished?' indicates that the +current member has been fully read (with the `lz-compress-read' function)." + (let ((ret (proc (lz-encoder->pointer encoder) member-size))) + (when (= ret -1) + (throw 'lzlib-error 'lz-compress-restart-member + (lz-compress-error encoder))))))) + +(define lz-compress-sync-flush + (let ((proc (lzlib-procedure int "LZ_compress_sync_flush" (list '*)))) + (lambda (encoder) + "Use this function to make available to `lz-compress-read' all the data +already written with the `LZ-compress-write' function. First call +`lz-compress-sync-flush'. Then call 'lz-compress-read' until it returns 0. + +Repeated use of `LZ-compress-sync-flush' may degrade compression ratio, +so use it only when needed. " + (let ((ret (proc (lz-encoder->pointer encoder)))) + (when (= ret -1) + (throw 'lzlib-error 'lz-compress-sync-flush + (lz-compress-error encoder))))))) + +(define lz-compress-read + (let ((proc (lzlib-procedure int "LZ_compress_read" (list '* '* int)))) + (lambda* (encoder lzfile-bv #:optional (start 0) (count (bytevector-length lzfile-bv))) + "Read up to COUNT bytes from the encoder stream, storing the results in LZFILE-BV. +Return the number of uncompressed bytes written, a strictly positive integer." + (let ((ret (proc (lz-encoder->pointer encoder) + (bytevector->pointer lzfile-bv start) + count))) + (if (= ret -1) + (throw 'lzlib-error 'lz-compress-read (lz-compress-error encoder)) + ret))))) + +(define lz-compress-write + (let ((proc (lzlib-procedure int "LZ_compress_write" (list '* '* int)))) + (lambda* (encoder bv #:optional (start 0) (count (bytevector-length bv))) + "Write up to COUNT bytes from BV to the encoder stream. Return the +number of uncompressed bytes written, a strictly positive integer." + (let ((ret (proc (lz-encoder->pointer encoder) + (bytevector->pointer bv start) + count))) + (if (< ret 0) + (throw 'lzlib-error 'lz-compress-write (lz-compress-error encoder)) + ret))))) + +(define lz-compress-write-size + (let ((proc (lzlib-procedure int "LZ_compress_write_size" '(*)))) + (lambda (encoder) + "The maximum number of bytes that can be immediately written through the +`lz-compress-write' function. + +It is guaranteed that an immediate call to `lz-compress-write' will accept a +SIZE up to the returned number of bytes. " + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (= ret -1) + (throw 'lzlib-error 'lz-compress-write-size (lz-compress-error encoder)) + ret))))) + +(define lz-compress-error + (let ((proc (lzlib-procedure int "LZ_compress_errno" '(*)))) + (lambda (encoder) + "ENCODER can be a Scheme object or a pointer." + (let* ((error-number (proc (if (lz-encoder? encoder) + (lz-encoder->pointer encoder) + encoder)))) + error-number)))) + +(define lz-compress-finished? + (let ((proc (lzlib-procedure int "LZ_compress_finished" '(*)))) + (lambda (encoder) + "Return #t if all the data have been read and `lz-compress-close' can +be safely called. Otherwise return #f." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (match ret + (1 #t) + (0 #f) + (_ (throw 'lzlib-error 'lz-compress-finished? (lz-compress-error encoder)))))))) + +(define lz-compress-member-finished? + (let ((proc (lzlib-procedure int "LZ_compress_member_finished" '(*)))) + (lambda (encoder) + "Return #t if the current member, in a multimember data stream, has +been fully read and 'lz-compress-restart-member' can be safely called. +Otherwise return #f." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (match ret + (1 #t) + (0 #f) + (_ (throw 'lzlib-error 'lz-compress-member-finished? (lz-compress-error encoder)))))))) + +(define lz-compress-data-position + (let ((proc (lzlib-procedure uint64 "LZ_compress_data_position" '(*)))) + (lambda (encoder) + "Return the number of input bytes already compressed in the current +member." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (= ret -1) + (throw 'lzlib-error 'lz-compress-data-position + (lz-compress-error encoder)) + ret))))) + +(define lz-compress-member-position + (let ((proc (lzlib-procedure uint64 "LZ_compress_member_position" '(*)))) + (lambda (encoder) + "Return the number of compressed bytes already produced, but perhaps +not yet read, in the current member." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (= ret -1) + (throw 'lzlib-error 'lz-compress-member-position + (lz-compress-error encoder)) + ret))))) + +(define lz-compress-total-in-size + (let ((proc (lzlib-procedure uint64 "LZ_compress_total_in_size" '(*)))) + (lambda (encoder) + "Return the total number of input bytes already compressed." + (let ((ret (proc (lz-encoder->pointer encoder)))) + + (if (= ret -1) + (throw 'lzlib-error 'lz-compress-total-in-size + (lz-compress-error encoder)) + ret))))) + +(define lz-compress-total-out-size + (let ((proc (lzlib-procedure uint64 "LZ_compress_total_out_size" '(*)))) + (lambda (encoder) + "Return the total number of compressed bytes already produced, but +perhaps not yet read." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (= ret -1) + (throw 'lzlib-error 'lz-compress-total-out-size + (lz-compress-error encoder)) + ret))))) + + +;; Decompression bindings. + +(define lz-decompress-open + (let ((proc (lzlib-procedure '* "LZ_decompress_open" '()))) + (lambda () + "Initializes the internal stream state for decompression and returns a +pointer that can only be used as the decoder argument for the other +lz-decompress functions, or a null pointer if the decoder could not be +allocated. + +See the manual: (lzlib) Decompression functions." + (let ((decoder-ptr (proc))) + (if (not (= (lz-decompress-error decoder-ptr) -1)) + (pointer->lz-decoder decoder-ptr) + (throw 'lzlib-error 'lz-decompress-open)))))) + +(define lz-decompress-close + (let ((proc (lzlib-procedure int "LZ_decompress_close" '(*)))) + (lambda (decoder) + "Close decoder. DECODER can no longer be used as an argument to any +lz-decompress function. " + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (= ret -1) + (throw 'lzlib-error 'lz-decompress-close ret) + ret))))) + +(define lz-decompress-finish + (let ((proc (lzlib-procedure int "LZ_decompress_finish" '(*)))) + (lambda (decoder) + "Use this function to tell that all the data for this stream +have already been written (with the `lz-decompress-write' function). It is +safe to call `lz-decompress-finish' as many times as needed." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (when (= ret -1) + (throw 'lzlib-error 'lz-decompress-finish (lz-decompress-error decoder))))))) + +(define lz-decompress-reset + (let ((proc (lzlib-procedure int "LZ_decompress_reset" '(*)))) + (lambda (decoder) + "Resets the internal state of DECODER as it was just after opening it +with the `lz-decompress-open' function. Data stored in the internal buffers +is discarded. Position counters are set to 0." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (when (= ret -1) + (throw 'lzlib-error 'lz-decompress-reset + (lz-decompress-error decoder))))))) + +(define lz-decompress-sync-to-member + (let ((proc (lzlib-procedure int "LZ_decompress_sync_to_member" '(*)))) + (lambda (decoder) + "Resets the error state of DECODER and enters a search state that lasts +until a new member header (or the end of the stream) is found. After a +successful call to `lz-decompress-sync-to-member', data written with +`lz-decompress-write' will be consumed and 'lz-decompress-read' will return 0 +until a header is found. + +This function is useful to discard any data preceding the first member, or to +discard the rest of the current member, for example in case of a data +error. If the decoder is already at the beginning of a member, this function +does nothing." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (when (= ret -1) + (throw 'lzlib-error 'lz-decompress-sync-to-member + (lz-decompress-error decoder))))))) + +(define lz-decompress-read + (let ((proc (lzlib-procedure int "LZ_decompress_read" (list '* '* int)))) + (lambda* (decoder file-bv #:optional (start 0) (count (bytevector-length file-bv))) + "Read up to COUNT bytes from the decoder stream, storing the results in FILE-BV. +Return the number of uncompressed bytes written, a strictly positive integer." + (let ((ret (proc (lz-decoder->pointer decoder) + (bytevector->pointer file-bv start) + count))) + (if (< ret 0) + (throw 'lzlib-error 'lz-decompress-read (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-write + (let ((proc (lzlib-procedure int "LZ_decompress_write" (list '* '* int)))) + (lambda* (decoder bv #:optional (start 0) (count (bytevector-length bv))) + "Write up to COUNT bytes from BV to the decoder stream. Return the +number of uncompressed bytes written, a strictly positive integer." + (let ((ret (proc (lz-decoder->pointer decoder) + (bytevector->pointer bv start) + count))) + (if (< ret 0) + (throw 'lzlib-error 'lz-decompress-write (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-write-size + (let ((proc (lzlib-procedure int "LZ_decompress_write_size" '(*)))) + (lambda (decoder) + "Return the maximum number of bytes that can be immediately written +through the `lz-decompress-write' function. + +It is guaranteed that an immediate call to `lz-decompress-write' will accept a +SIZE up to the returned number of bytes. " + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (= ret -1) + (throw 'lzlib-error 'lz-decompress-write-size (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-error + (let ((proc (lzlib-procedure int "LZ_decompress_errno" '(*)))) + (lambda (decoder) + "DECODER can be a Scheme object or a pointer." + (let* ((error-number (proc (if (lz-decoder? decoder) + (lz-decoder->pointer decoder) + decoder)))) + error-number)))) + +(define lz-decompress-finished? + (let ((proc (lzlib-procedure int "LZ_decompress_finished" '(*)))) + (lambda (decoder) + "Return #t if all the data have been read and `lz-decompress-close' can +be safely called. Otherwise return #f." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (match ret + (1 #t) + (0 #f) + (_ (throw 'lzlib-error 'lz-decompress-finished? (lz-decompress-error encoder)))))))) + +(define lz-decompress-member-finished? + (let ((proc (lzlib-procedure int "LZ_decompress_member_finished" '(*)))) + (lambda (decoder) + "Return #t if the current member, in a multimember data stream, has +been fully read and `lz-decompress-restart-member' can be safely called. +Otherwise return #f." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (match ret + (1 #t) + (0 #f) + (_ (throw 'lzlib-error 'lz-decompress-finished? (lz-decompress-error encoder)))))))) + +(define lz-decompress-member-version + (let ((proc (lzlib-procedure int "LZ_decompress_member_version" '(*)))) + (lambda (decoder) + (let ((ret (proc (lz-decoder->pointer decoder)))) + "Return the version of current member from member header." + (if (= ret -1) + (throw 'lzlib-error 'lz-decompress-data-position + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-dictionary-size + (let ((proc (lzlib-procedure int "LZ_decompress_dictionary_size" '(*)))) + (lambda (decoder) + (let ((ret (proc (lz-decoder->pointer decoder)))) + "Return the dictionary size of current member from member header." + (if (= ret -1) + (throw 'lzlib-error 'lz-decompress-member-position + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-data-crc + (let ((proc (lzlib-procedure unsigned-int "LZ_decompress_data_crc" '(*)))) + (lambda (decoder) + (let ((ret (proc (lz-decoder->pointer decoder)))) + "Return the 32 bit Cyclic Redundancy Check of the data decompressed +from the current member. The returned value is valid only when +`lz-decompress-member-finished' returns #t. " + (if (= ret -1) + (throw 'lzlib-error 'lz-decompress-member-position + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-data-position + (let ((proc (lzlib-procedure uint64 "LZ_decompress_data_position" '(*)))) + (lambda (decoder) + "Return the number of decompressed bytes already produced, but perhaps +not yet read, in the current member." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (= ret -1) + (throw 'lzlib-error 'lz-decompress-data-position + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-member-position + (let ((proc (lzlib-procedure uint64 "LZ_decompress_member_position" '(*)))) + (lambda (decoder) + "Return the number of input bytes already decompressed in the current +member." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (= ret -1) + (throw 'lzlib-error 'lz-decompress-member-position + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-total-in-size + (let ((proc (lzlib-procedure uint64 "LZ_decompress_total_in_size" '(*)))) + (lambda (decoder) + (let ((ret (proc (lz-decoder->pointer decoder)))) + "Return the total number of input bytes already compressed." + (if (= ret -1) + (throw 'lzlib-error 'lz-decompress-total-in-size + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-total-out-size + (let ((proc (lzlib-procedure uint64 "LZ_decompress_total_out_size" '(*)))) + (lambda (decoder) + (let ((ret (proc (lz-decoder->pointer decoder)))) + "Return the total number of compressed bytes already produced, but +perhaps not yet read." + (if (= ret -1) + (throw 'lzlib-error 'lz-decompress-total-out-size + (lz-decompress-error decoder)) + ret))))) + + +;; High level functions. + +(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." + (let* ((written 0) + (read 0) + (chunk (* 64 1024)) + (file-bv (get-bytevector-n file-port count))) + (if (eof-object? file-bv) + 0 + (begin + (while (and (< 0 (lz-decompress-write-size decoder)) + (< written (bytevector-length file-bv))) + (set! written (lz-decompress-write decoder file-bv written (- (bytevector-length file-bv) written)))) + ;; TODO: When should we call `lz-decompress-finish'? + ;; (lz-decompress-finish decoder) + ;; TODO: Loop? + (set! read (lz-decompress-read decoder bv start + (- (bytevector-length bv) start))) + read)))) + +(define* (lzwrite encoder bv lz-port + #:optional (start 0) (count (bytevector-length bv))) + "Write up to COUNT bytes from BV at offset START into LZ-PORT. Return +the number of uncompressed bytes written, a strictly positive integer." + (let ((written 0) + (read 0)) + (while (and (< 0 (lz-compress-write-size encoder)) + (< written count)) + (set! written (lz-compress-write encoder bv (+ start written) (- count written)))) + (lz-compress-finish encoder) + ;; TODO: Better loop? + (let ((lz-bv (make-bytevector written))) + (let loop ((rd 0)) + (set! rd (lz-compress-read encoder lz-bv 0 (bytevector-length lz-bv))) + (put-bytevector lz-port lz-bv 0 rd) + (set! read (+ read rd)) + (unless (= rd 0) + (loop rd)))) + ;; TODO: Return written (uncompressed) or read (compressed)? + written)) + + +;;; +;;; Port interface. +;;; + +;; Alist of (levels (dictionary-size match-length-limit)). 0 is the fastest. +;; See bbexample.c in lzlib's source. +(define %compression-levels + `((0 (65535 16)) + (1 (,(bitwise-arithmetic-shift-left 1 20) 5)) + (2 (,(bitwise-arithmetic-shift-left 3 19) 6)) + (3 (,(bitwise-arithmetic-shift-left 1 21) 8)) + (4 (,(bitwise-arithmetic-shift-left 3 20) 12)) + (5 (,(bitwise-arithmetic-shift-left 1 22) 20)) + (6 (,(bitwise-arithmetic-shift-left 1 23) 36)) + (7 (,(bitwise-arithmetic-shift-left 1 24) 68)) + (8 (,(bitwise-arithmetic-shift-left 3 23) 132)) + (9 (,(bitwise-arithmetic-shift-left 1 25) 273)))) + +(define %default-compression-level + 6) + +(define* (make-lzip-input-port port) + "Return an input port that decompresses data read from PORT, a file port. +PORT is automatically closed when the resulting port is closed." + (define decoder (lz-decompress-open)) + + (define (read! bv start count) + (lzread! decoder port bv start count)) + + (make-custom-binary-input-port "lzip-input" read! #f #f + (lambda () + (close-port port)))) + +(define* (make-lzip-output-port port + #:key + (level %default-compression-level)) + "Return an output port that compresses data at the given LEVEL, using PORT, +a file port, as its sink. PORT is automatically closed when the resulting +port is closed." + (define encoder (apply lz-compress-open + (car (assoc-ref %compression-levels level)))) + + (define (write! bv start count) + (lzwrite encoder bv port start count)) + + (make-custom-binary-output-port "lzip-output" write! #f #f + (lambda () + (close-port port)))) + +(define* (call-with-lzip-input-port port proc) + "Call PROC with a port that wraps PORT and decompresses data read from it. +PORT is closed upon completion." + (let ((lzip (make-lzip-input-port port))) + (dynamic-wind + (const #t) + (lambda () + (proc lzip)) + (lambda () + (close-port lzip))))) + +(define* (call-with-lzip-output-port port proc + #:key + (level %default-compression-level)) + "Call PROC with an output port that wraps PORT and compresses data. PORT is +close upon completion." + (let ((lzip (make-lzip-output-port port + #:level level))) + (dynamic-wind + (const #t) + (lambda () + (proc lzip)) + (lambda () + (close-port lzip))))) + +;;; lzlib.scm ends here diff --git a/m4/guix.m4 b/m4/guix.m4 index 5c846f7618..59156733b2 100644 --- a/m4/guix.m4 +++ b/m4/guix.m4 @@ -312,6 +312,18 @@ AC_DEFUN([GUIX_LIBZ_LIBDIR], [ $1="$guix_cv_libz_libdir" ]) +dnl GUIX_LIBLZ_LIBDIR VAR +dnl +dnl Attempt to determine liblz's LIBDIR; store the result in VAR. +AC_DEFUN([GUIX_LIBLZ_LIBDIR], [ + AC_REQUIRE([PKG_PROG_PKG_CONFIG]) + AC_CACHE_CHECK([lzlib's library directory], + [guix_cv_liblz_libdir], + dnl TODO: This fails because lzlib has no pkg-config. + [guix_cv_liblz_libdir="`$PKG_CONFIG lzlib --variable=libdir 2> /dev/null`"]) + $1="$guix_cv_liblz_libdir" +]) + dnl GUIX_CURRENT_LOCALSTATEDIR dnl dnl Determine the localstatedir of an existing Guix installation and set diff --git a/tests/lzlib.scm b/tests/lzlib.scm new file mode 100644 index 0000000000..7f28ac04ec --- /dev/null +++ b/tests/lzlib.scm @@ -0,0 +1,62 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Pierre Neidhardt +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (test-lzlib) + #:use-module (guix lzlib) + #:use-module (guix tests) + #:use-module (srfi srfi-64) + #:use-module (rnrs bytevectors) + #:use-module (rnrs io ports) + #:use-module (ice-9 match)) + +;; Test the (guix lzlib) module. + +(unless (lzlib-available?) + (exit 77)) + +(test-begin "lzlib") + +(test-assert "compression/decompression pipe" + (let ((data (random-bytevector (+ (random 10000) + (* 20 1024))))) + (match (pipe) + ((parent . child) + (match (primitive-fork) + (0 ;compress + (dynamic-wind + (const #t) + (lambda () + (close-port parent) + (call-with-lzip-output-port child + (lambda (port) + (put-bytevector port data)))) + (lambda () + (primitive-exit 0)))) + (pid ;decompress + (begin + (close-port child) + (let ((received (call-with-lzip-input-port parent + (lambda (port) + (get-bytevector-all port))))) + (match (waitpid pid) + ((_ . status) + (and (zero? status) + (port-closed? parent) + (bytevector=? received data)))))))))))) + +(test-end) -- 2.20.1 From debbugs-submit-bounces@debbugs.gnu.org Sun Mar 10 14:09:11 2019 Received: (at 34807) by debbugs.gnu.org; 10 Mar 2019 18:09:11 +0000 Received: from localhost ([127.0.0.1]:38316 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h32sp-0006bg-0v for submit@debbugs.gnu.org; Sun, 10 Mar 2019 14:09:11 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:38865) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h32sm-0006bW-Q2 for 34807@debbugs.gnu.org; Sun, 10 Mar 2019 14:09:09 -0400 X-Originating-IP: 90.92.41.33 Received: from localhost.localdomain (lfbn-1-12225-33.w90-92.abo.wanadoo.fr [90.92.41.33]) (Authenticated sender: mail@ambrevar.xyz) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 63E45240005 for <34807@debbugs.gnu.org>; Sun, 10 Mar 2019 18:09:05 +0000 (UTC) From: Pierre Neidhardt To: 34807@debbugs.gnu.org Subject: [PATCH 2/2] dir-locals.el: Add 'call-with-lzip-input-port' and 'call-with-lzip-output-port' keywords. Date: Sun, 10 Mar 2019 19:09:05 +0100 Message-Id: <20190310180905.14459-1-mail@ambrevar.xyz> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 34807 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.7 (-) * .dir-locals.el: Add indentation rules for 'call-with-lzip-input-port' and 'call-with-lzip-output-port'. --- .dir-locals.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.dir-locals.el b/.dir-locals.el index 550e06ef09..f1196fd781 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -53,6 +53,8 @@ (eval . (put 'call-with-decompressed-port 'scheme-indent-function 2)) (eval . (put 'call-with-gzip-input-port 'scheme-indent-function 1)) (eval . (put 'call-with-gzip-output-port 'scheme-indent-function 1)) + (eval . (put 'call-with-lzip-input-port 'scheme-indent-function 1)) + (eval . (put 'call-with-lzip-output-port 'scheme-indent-function 1)) (eval . (put 'signature-case 'scheme-indent-function 1)) (eval . (put 'emacs-batch-eval 'scheme-indent-function 0)) (eval . (put 'emacs-batch-edit-file 'scheme-indent-function 1)) -- 2.20.1 From debbugs-submit-bounces@debbugs.gnu.org Fri Mar 22 17:35:23 2019 Received: (at 34807) by debbugs.gnu.org; 22 Mar 2019 21:35:23 +0000 Received: from localhost ([127.0.0.1]:54778 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h7Row-00015x-JT for submit@debbugs.gnu.org; Fri, 22 Mar 2019 17:35:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54413) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1h7Rou-00015g-CJ for 34807@debbugs.gnu.org; Fri, 22 Mar 2019 17:35:21 -0400 Received: from fencepost.gnu.org ([209.51.188.10]:38373) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7Roh-0007Gc-HE; Fri, 22 Mar 2019 17:35:11 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=51478 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1h7Roe-0007Hv-KT; Fri, 22 Mar 2019 17:35:07 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Pierre Neidhardt Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). References: <20190310180209.11578-1-mail@ambrevar.xyz> Date: Fri, 22 Mar 2019 22:35:02 +0100 In-Reply-To: <20190310180209.11578-1-mail@ambrevar.xyz> (Pierre Neidhardt's message of "Sun, 10 Mar 2019 19:02:09 +0100") Message-ID: <8736ne3855.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (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] X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 34807 Cc: 34807@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, Pierre Neidhardt skribis: > * guix/lzlib.scm, tests/lzlib.scm: New files. > * Makefile.am (MODULES): Add guix/lzlib.scm. > (SCM_TESTS): Add tests/lzlib.scm. > * m4/guix.m4 (GUIX_LIBLZ_LIBDIR): New macro. > * configure.ac (LIBLZ_LIBDIR): Use it. Define and substitute > 'LIBLZ'. > * guix/config.scm.in (%liblz): New variable. This looks really nice! Please update =E2=80=98make-config.scm=E2=80=99 in (guix self) so that it d= efines =E2=80=98%liblz=E2=80=99 as well (setting it to #f for now). > +(define %liblz > + ;; TODO: Set this dynamically. > + "/gnu/store/8db7vivi8p9mpkbphb8xy8gh2bkwc4iz-lzlib-1.11/lib/liblz") You can already put "@LIBLZ@" here. > +(define %lzlib > + ;; File name of lzlib's shared library. When updating via 'guix pull', > + ;; '%liblz' might be undefined so protect against it. Updating =E2=80=98make-config.scm=E2=80=99 will fix it. > +(define %error-number-ok > + ;; TODO: How do we get the values of a C enum? See the thread on guix-devel. > +(define lz-compress-open > + (let ((proc (lzlib-procedure '* "LZ_compress_open" (list int int uint6= 4)))) > + ;; TODO: member-size default is INT64_MAX. Is there a better way to= do this with Guile? > + (lambda* (dictionary-size match-length-limit #:optional (member-size= #x7FFFFFFFFFFFFFFF)) You could write (- (expt 2 63) 1) I guess for clarity, but what you wrote i= s OK. Is it also the case on 32-bit platforms? > +(define lz-compress-finish > + (let ((proc (lzlib-procedure int "LZ_compress_finish" '(*)))) > + (lambda (encoder) > + "Use this function to tell that all the data for this member have > +already been written (with the `lz-compress-write' function). It is saf= e to > +call `lz-compress-finish' as many times as needed. After all the produc= ed > +compressed data have been read with `lz-compress-read' and > +`lz-compress-member-finished?' returns #t, a new member can be started w= ith > +'lz-compress-restart-member'." For docstrings, the convention in GNU and Guix is to use the imperative tense and to explicitly refer to the arguments there, like: "Tell ENCODER that all the data for this member have alrady been written. =E2=80=A6" (Same for the other docstrings that start with =E2=80=9CUse this function.= =E2=80=9D) > +(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. Retur= n the > +number of uncompressed bytes actually read; it is zero if COUNT is zero = or if > +the end-of-stream has been reached." > + (let* ((written 0) > + (read 0) > + (chunk (* 64 1024)) > + (file-bv (get-bytevector-n file-port count))) > + (if (eof-object? file-bv) > + 0 > + (begin > + (while (and (< 0 (lz-decompress-write-size decoder)) > + (< written (bytevector-length file-bv))) > + (set! written (lz-decompress-write decoder file-bv written (= - (bytevector-length file-bv) written)))) > + ;; TODO: When should we call `lz-decompress-finish'? > + ;; (lz-decompress-finish decoder) > + ;; TODO: Loop? > + (set! read (lz-decompress-read decoder bv start > + (- (bytevector-length bv) start= ))) It=E2=80=99s worth figuring out. :-) Are there examples or the code of the actual =E2=80=98lzip=E2=80=99 command= that could help? > +dnl GUIX_LIBLZ_LIBDIR VAR > +dnl > +dnl Attempt to determine liblz's LIBDIR; store the result in VAR. > +AC_DEFUN([GUIX_LIBLZ_LIBDIR], [ > + AC_REQUIRE([PKG_PROG_PKG_CONFIG]) > + AC_CACHE_CHECK([lzlib's library directory], > + [guix_cv_liblz_libdir], > + dnl TODO: This fails because lzlib has no pkg-config. > + [guix_cv_liblz_libdir=3D"`$PKG_CONFIG lzlib --variable=3Dlibdir 2> /= dev/null`"]) > + $1=3D"$guix_cv_liblz_libdir" > +]) I think you could do something like this in the body of =E2=80=98AC_CACHE_C= HECK=E2=80=99 (untested): old_LIBS=3D"$LIBS" LIBS=3D"-llz" AC_LINK_IFELSE([LZ_decompress_open();], [guix_cv_libz_libdir=3D"`ldd conftest$EXEEXT | grep liblz | sed '-es/.*= =3D> \(.*\) .*$/\1/g'`"]) LIBS=3D"$old_LIBS" Regarding testing, it=E2=80=99s easy to get this sort of binding subtly wro= ng IME. :-) I=E2=80=99d suggest looking at things like: 1. Passing short input bytevectors, large input bytevectors, and input that=E2=80=99s equal to liblz=E2=80=99s internal buffer size or off by= one. 2. File descriptors: strace guile while doing =E2=80=98call-with-lzip-input-port=E2=80=99 and =E2=80=98call-with-lzi= p-output-port=E2=80=99 and make sure that file descriptors are not left open and are not closed prematurely either. (This is particularly important for long-running processes like =E2=80=98guix publish=E2=80=99.) But overall, modulo the small issues above, it looks pretty much ready to me. Thank you! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Wed May 01 12:47:12 2019 Received: (at 34807) by debbugs.gnu.org; 1 May 2019 16:47:12 +0000 Received: from localhost ([127.0.0.1]:44743 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLsO0-0007fc-IF for submit@debbugs.gnu.org; Wed, 01 May 2019 12:47:12 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:44817) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hLsNy-0007fT-Ed for 34807@debbugs.gnu.org; Wed, 01 May 2019 12:47:11 -0400 X-Originating-IP: 80.215.236.231 Received: from mimimi (unknown [80.215.236.231]) (Authenticated sender: pierre@atlas.engineer) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id BD7D41BF206; Wed, 1 May 2019 16:46:46 +0000 (UTC) From: Pierre Neidhardt To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). In-Reply-To: <8736ne3855.fsf@gnu.org> References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> Date: Wed, 01 May 2019 18:46:44 +0200 Message-ID: <87pnp2f7gr.fsf@ambrevar.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 34807 Cc: 34807@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.7 (-) --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, thanks for the review. I've worked on it and I've managed to address almost all issues. Now I'm stuck with the stream decompression. Lzip expects some special terminating bytes for each member. In tests/lzlib.scm, we produce a compressed stream and decompress it in parallel. But more often than not, before the compression is done, the decompression will exhaust the port's byte and terminate prematurely. I don't know what to do in this case. From the Guile manual: =2D-8<---------------cut here---------------start------------->8--- -- Scheme Procedure: make-custom-binary-input-port id read! get-position set-position! close Return a new custom binary input port(1) named ID (a string) whose input is drained by invoking READ! and passing it a bytevector, an index where bytes should be written, and the number of bytes to read. The =E2=80=98read!=E2=80=99 procedure must return an integer in= dicating the number of bytes read, or =E2=80=980=E2=80=99 to indicate the end-of-fi= le. =2D-8<---------------cut here---------------end--------------->8--- The decompression will sometime decompress 0 byte (when it's faster then the compression). But if I return 0 in lzread!, then the custom port will be closed too early, before we could decompress the terminating bytes. Is there a way to wait on the port instead of reading 0 bytes? Note that lzip can test whether the decompressed stream is terminated or not with lz-decompress-member-finished?. =2D-=20 Pierre Neidhardt https://ambrevar.xyz/ --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlzJzXQACgkQm9z0l6S7 zH9DHwf/f18i31x68XJTME8Z2Tcy13hblXWurKUUbOUshDslmqLlydtO4nm+Twsq qs7JbN9uZwW5zbFYkwS/1O3COGWWx4m1DpScdzwBPPkY1cQn8RLq5cwe4BJJW8tK ElgGZrP2OlR5r4G0z/w5sw5kFZneUXqgv+6Dejkkvo0j+NhRlr2v6FTFZt7oekJY fUBDX0GUMAuPhQMO0Fsq17SfIIqY7mX4ARGINXCOy3Aoa2O7odqxgAxb9Gxo6U6E qBbpWmqvrFDl7CgFN4S1UH9w2PxqJcvIb429SUxcORxdKNNSmWXJROCUroiHEctB Q0YcKbPWBGVFInlLwv+x6neJxLKTrw== =FUaa -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu May 02 05:16:37 2019 Received: (at 34807) by debbugs.gnu.org; 2 May 2019 09:16:37 +0000 Received: from localhost ([127.0.0.1]:45583 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hM7pU-0001iV-NU for submit@debbugs.gnu.org; Thu, 02 May 2019 05:16:37 -0400 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:51675) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hM7pR-0001iK-Uc for 34807@debbugs.gnu.org; Thu, 02 May 2019 05:16:35 -0400 X-Originating-IP: 92.169.116.19 Received: from bababa (lfbn-1-4117-19.w92-169.abo.wanadoo.fr [92.169.116.19]) (Authenticated sender: pierre@atlas.engineer) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 0298920026; Thu, 2 May 2019 09:16:30 +0000 (UTC) From: Pierre Neidhardt To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). In-Reply-To: <87pnp2f7gr.fsf@ambrevar.xyz> References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> Date: Thu, 02 May 2019 11:16:29 +0200 Message-ID: <8736lxdxn6.fsf@ambrevar.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 34807 Cc: 34807@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.7 (-) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable OK, I think I've figured it out. The issue above was a red herring. I think I've got it to work, I need to do more testing though. Stay tuned. =2D-=20 Pierre Neidhardt https://ambrevar.xyz/ --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlzKtW0ACgkQm9z0l6S7 zH++NQf/dub6Ala3RQ5sxDY/NvrrEAGhGg4Q6Ge59ocPc1mhOkIvtdPIzNvThJbB Sq85TV9rdE3W+m5dpJ1VBT4SRpjO9hjuWr54EfqZjl3x6hNI0h2W9enbDyyVHCI4 y/vaqCvB28QrebZZUKeTS9jDzvio5ePGx32C9biAxfbF10f615ciVmCHUuFVJBNU UhjYuTHDWJOrWXgLwmUBxYC9p7MfKHfNBf9s1r0hIj9LMsdwdU9pzgfa1hu0Z8w/ je2ne2iSgvgn3PgjqwBQtglX/LytUUDw+/p7fLXZ4IZbCCf5zURE+3to2Mv8cdVR 0sH0RJ8mGr2Z9uDz9HQ/PDGcuaDY5w== =uC39 -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat May 04 05:12:03 2019 Received: (at 34807) by debbugs.gnu.org; 4 May 2019 09:12:03 +0000 Received: from localhost ([127.0.0.1]:50365 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMqiA-0001EV-NP for submit@debbugs.gnu.org; Sat, 04 May 2019 05:12:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34857) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMqi9-0001E2-DY for 34807@debbugs.gnu.org; Sat, 04 May 2019 05:12:02 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hMqi3-0002Js-9n; Sat, 04 May 2019 05:11:55 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=35176 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hMqi2-0005nM-Sf; Sat, 04 May 2019 05:11:55 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Pierre Neidhardt Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> <8736lxdxn6.fsf@ambrevar.xyz> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 15 =?utf-8?Q?Flor=C3=A9al?= an 227 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, 04 May 2019 11:11:52 +0200 In-Reply-To: <8736lxdxn6.fsf@ambrevar.xyz> (Pierre Neidhardt's message of "Thu, 02 May 2019 11:16:29 +0200") Message-ID: <87lfzm7fdz.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (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] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 34807 Cc: 34807@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: -3.3 (---) Hi, Pierre Neidhardt skribis: > OK, I think I've figured it out. The issue above was a red herring. > I think I've got it to work, I need to do more testing though. > Stay tuned. OK. :-) Good to see progress on this front! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sat May 04 06:23:35 2019 Received: (at 34807) by debbugs.gnu.org; 4 May 2019 10:23:35 +0000 Received: from localhost ([127.0.0.1]:50421 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMrpM-0002uf-Ap for submit@debbugs.gnu.org; Sat, 04 May 2019 06:23:35 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:47451) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hMrpH-0002uP-BI for 34807@debbugs.gnu.org; Sat, 04 May 2019 06:23:30 -0400 X-Originating-IP: 92.169.116.19 Received: from bababa (lfbn-1-4117-19.w92-169.abo.wanadoo.fr [92.169.116.19]) (Authenticated sender: pierre@atlas.engineer) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id CB9D11C0009; Sat, 4 May 2019 10:23:23 +0000 (UTC) From: Pierre Neidhardt To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). In-Reply-To: <87lfzm7fdz.fsf@gnu.org> References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> <8736lxdxn6.fsf@ambrevar.xyz> <87lfzm7fdz.fsf@gnu.org> Date: Sat, 04 May 2019 12:23:23 +0200 Message-ID: <878svm5xic.fsf@ambrevar.xyz> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 34807 Cc: 34807@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.7 (-) --=-=-= Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" --==-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Right on time, I just finished it! =2D I've been in touch with Antonio, Lzip's maintainer, for more than a week and now I'm confident that I have a decent understanding of the library. =2D Your m4 suggestion didn't work. I've included a comment. We need to fix it before merging. I'm not the right person for this job I'm afraid :p Ludo? =2D The convenience functions do not support multi-member archives. Multi-member archives are mostly useful for parallelization, but we don't use that in Guix, so it's OK. Should it be required some day, we would need to implement it, which requires a little bit more work. I've documented all that. =2D The implementation of lzread! is subpar because I understood a subtlety a bit too late. But that's alright, it does not affect performance nor reliability. =2D I've included 11 tests covering all your suggestions. =2D I haven't strace'd the Guile process. The code regarding ports is identical to zlib.scm, so it's unlikely there would be an issue in this area. I have never done this before, so out of curiosity, how do you run a specific Guix tests without going through `make'? Next steps? :D =2D-=20 Pierre Neidhardt https://ambrevar.xyz/ --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlzNaBsACgkQm9z0l6S7 zH/jeAf/XG6RbQmhxE0WiuACQ4nKreuKP9JGIjSkwevj81alGAQKTgdO+gsEomDs 2CePmNW0H5o74H8/bRMNGnyO9OvgF/ufZ2KlD8l/FQQDMDdTaWl9Sd7Vs091aVYi hrav1ERNOGWe9fzkR6zDPUbH0xSohLJ/TxNUsz1KHyaEtgudEvTK3iK6Fv6vnuey bZZGAZaxETi+Ebq1p7vynkgH1BkyBjPHyUXZivjMSBEnEnLUPQeMkPFLCabY2TXz l8Zd84Zw6L6nF8WpCRzM7vAbqPytHlNOIDAdanjCj55ye330nqA4mgX7xkCRz4EF T8gDdMNE2j5N61rPM+L3ahvDc9uL+A== =y3Ea -----END PGP SIGNATURE----- --==-=-=-- --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-Add-guix-lzlib.patch Content-Transfer-Encoding: quoted-printable >From 6407597ce2855b87849ba0b2c3866b8a75fca9b3 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Fri, 8 Mar 2019 19:02:59 +0100 Subject: [PATCH 1/2] Add (guix lzlib). * guix/lzlib.scm, tests/lzlib.scm: New files. * Makefile.am (MODULES): Add guix/lzlib.scm. (SCM_TESTS): Add tests/lzlib.scm. * m4/guix.m4 (GUIX_LIBLZ_LIBDIR): New macro. * configure.ac (LIBLZ_LIBDIR): Use it. Define and substitute 'LIBLZ'. * guix/config.scm.in (%liblz): New variable. --- Makefile.am | 2 + configure.ac | 11 + guix/config.scm.in | 8 +- guix/lzlib.scm | 633 +++++++++++++++++++++++++++++++++++++++++++++ guix/self.scm | 3 +- m4/guix.m4 | 17 ++ tests/lzlib.scm | 108 ++++++++ 7 files changed, 780 insertions(+), 2 deletions(-) create mode 100644 guix/lzlib.scm create mode 100644 tests/lzlib.scm diff --git a/Makefile.am b/Makefile.am index 36f3bc5c27..232550069f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -103,6 +103,7 @@ MODULES =3D \ guix/cve.scm \ guix/workers.scm \ guix/zlib.scm \ + guix/lzlib.scm \ guix/build-system.scm \ guix/build-system/android-ndk.scm \ guix/build-system/ant.scm \ @@ -404,6 +405,7 @@ SCM_TESTS =3D \ tests/cve.scm \ tests/workers.scm \ tests/zlib.scm \ + tests/lzlib.scm \ tests/file-systems.scm \ tests/uuid.scm \ tests/system.scm \ diff --git a/configure.ac b/configure.ac index 7e7ae02730..ee7aa25742 100644 --- a/configure.ac +++ b/configure.ac @@ -250,6 +250,17 @@ AC_MSG_CHECKING([for zlib's shared library name]) AC_MSG_RESULT([$LIBZ]) AC_SUBST([LIBZ]) =20 +dnl Library name of lzlib suitable for 'dynamic-link'. +GUIX_LIBLZ_LIBDIR([liblz_libdir]) +if test "x$liblz_libdir" =3D "x"; then + LIBLZ=3D"liblz" +else + LIBLZ=3D"$liblz_libdir/liblz" +fi +AC_MSG_CHECKING([for lzlib's shared library name]) +AC_MSG_RESULT([$LIBLZ]) +AC_SUBST([LIBLZ]) + dnl Check for Guile-SSH, for the (guix ssh) module. GUIX_CHECK_GUILE_SSH AM_CONDITIONAL([HAVE_GUILE_SSH], diff --git a/guix/config.scm.in b/guix/config.scm.in index 247b15ed81..cd7036ca7e 100644 --- a/guix/config.scm.in +++ b/guix/config.scm.in @@ -36,7 +36,8 @@ %libz %gzip %bzip2 - %xz)) + %xz + %liblz)) =20 ;;; Commentary: ;;; @@ -99,4 +100,9 @@ (define %xz "@XZ@") =20 +(define %liblz + ;; TODO: Set this dynamically. + ;; "@LIBLZ@" + "/gnu/store/8db7vivi8p9mpkbphb8xy8gh2bkwc4iz-lzlib-1.11/lib/liblz") + ;;; config.scm ends here diff --git a/guix/lzlib.scm b/guix/lzlib.scm new file mode 100644 index 0000000000..d596f0d95d --- /dev/null +++ b/guix/lzlib.scm @@ -0,0 +1,633 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2019 Pierre Neidhardt +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix lzlib) + #:use-module (rnrs bytevectors) + #:use-module (rnrs arithmetic bitwise) + #:use-module (ice-9 binary-ports) + #:use-module (ice-9 match) + #:use-module (system foreign) + #:use-module (guix config) + #:export (lzlib-available? + make-lzip-input-port + make-lzip-output-port + call-with-lzip-input-port + call-with-lzip-output-port + %default-member-length-limit + %default-compression-level)) + +;;; Commentary: +;;; +;;; Bindings to the lzlib / liblz API. Some convenience functions are also +;;; provided (see the export). +;;; +;;; While the bindings are complete, the convenience functions only support +;;; single member archives. To decompress single member archives, we loop +;;; until lz-decompress-read returns 0. This is simpler. To support mult= iple +;;; members properly, we need (among others) to call lz-decompress-finish = and +;;; loop over lz-decompress-read until lz-decompress-finished? returns #t. +;;; Otherwise a multi-member archive starting with an empty member would o= nly +;;; decompress the empty member and stop there, resulting in truncated out= put. + +;;; Code: + +(define %lzlib + ;; File name of lzlib's shared library. When updating via 'guix pull', + ;; '%liblz' might be undefined so protect against it. + (delay (dynamic-link (if (defined? '%liblz) + %liblz + "liblz")))) + +(define (lzlib-available?) + "Return true if lzlib is available, #f otherwise." + (false-if-exception (force %lzlib))) + +(define (lzlib-procedure ret name parameters) + "Return a procedure corresponding to C function NAME in liblz, or #f if +either lzlib or the function could not be found." + (match (false-if-exception (dynamic-func name (force %lzlib))) + ((? pointer? ptr) + (pointer->procedure ret ptr parameters)) + (#f + #f))) + +(define-wrapped-pointer-type + ;; Scheme counterpart of the 'LZ_Decoder' opaque type. + lz-decoder? + pointer->lz-decoder + lz-decoder->pointer + (lambda (obj port) + (format port "#" + (number->string (object-address obj) 16)))) + +(define-wrapped-pointer-type + ;; Scheme counterpart of the 'LZ_Encoder' opaque type. + lz-encoder? + pointer->lz-encoder + lz-encoder->pointer + (lambda (obj port) + (format port "#" + (number->string (object-address obj) 16)))) + +;; From lzlib.h +(define %error-number-ok 0) +(define %error-number-bad-argument 1) +(define %error-number-mem-error 2) +(define %error-number-sequence-error 3) +(define %error-number-header-error 4) +(define %error-number-unexpected-eof 5) +(define %error-number-data-error 6) +(define %error-number-library-error 7) + + +;; Compression bindings. + +(define lz-compress-open + (let ((proc (lzlib-procedure '* "LZ_compress_open" (list int int uint64)= )) + ;; member-size is an "unsigned long long", and the C standard guar= antees + ;; a minimum range of 0..2^64-1. + (unlimited-size (- (expt 2 64) 1))) + (lambda* (dictionary-size match-length-limit #:optional (member-size u= nlimited-size)) + "Initialize the internal stream state for compression and returns a +pointer that can only be used as the encoder argument for the other +lz-compress functions, or a null pointer if the encoder could not be +allocated. + +See the manual: (lzlib) Compression functions." + (let ((encoder-ptr (proc dictionary-size match-length-limit member-s= ize))) + (if (not (=3D (lz-compress-error encoder-ptr) -1)) + (pointer->lz-encoder encoder-ptr) + (throw 'lzlib-error 'lz-compress-open)))))) + +(define lz-compress-close + (let ((proc (lzlib-procedure int "LZ_compress_close" '(*)))) + (lambda (encoder) + "Close encoder. ENCODER can no longer be used as an argument to any +lz-compress function. " + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-compress-close ret) + ret))))) + +(define lz-compress-finish + (let ((proc (lzlib-procedure int "LZ_compress_finish" '(*)))) + (lambda (encoder) + "Tell that all the data for this member have already been written (w= ith +the `lz-compress-write' function). It is safe to call `lz-compress-finish= ' as +many times as needed. After all the produced compressed data have been re= ad +with `lz-compress-read' and `lz-compress-member-finished?' returns #t, a n= ew +member can be started with 'lz-compress-restart-member'." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-compress-finish (lz-compress-error enc= oder)) + ret))))) + +(define lz-compress-restart-member + (let ((proc (lzlib-procedure int "LZ_compress_restart_member" (list '* u= int64)))) + (lambda (encoder member-size) + "Start a new member in a multimember data stream. +Call this function only after `lz-compress-member-finished?' indicates tha= t the +current member has been fully read (with the `lz-compress-read' function)." + (let ((ret (proc (lz-encoder->pointer encoder) member-size))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-compress-restart-member + (lz-compress-error encoder)) + ret))))) + +(define lz-compress-sync-flush + (let ((proc (lzlib-procedure int "LZ_compress_sync_flush" (list '*)))) + (lambda (encoder) + "Make available to `lz-compress-read' all the data already written w= ith +the `LZ-compress-write' function. First call `lz-compress-sync-flush'. T= hen +call 'lz-compress-read' until it returns 0. + +Repeated use of `LZ-compress-sync-flush' may degrade compression ratio, +so use it only when needed. " + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-compress-sync-flush + (lz-compress-error encoder)) + ret))))) + +(define lz-compress-read + (let ((proc (lzlib-procedure int "LZ_compress_read" (list '* '* int)))) + (lambda* (encoder lzfile-bv #:optional (start 0) (count (bytevector-le= ngth lzfile-bv))) + "Read up to COUNT bytes from the encoder stream, storing the results= in LZFILE-BV. +Return the number of uncompressed bytes written, a strictly positive integ= er." + (let ((ret (proc (lz-encoder->pointer encoder) + (bytevector->pointer lzfile-bv start) + count))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-compress-read (lz-compress-error encod= er)) + ret))))) + +(define lz-compress-write + (let ((proc (lzlib-procedure int "LZ_compress_write" (list '* '* int)))) + (lambda* (encoder bv #:optional (start 0) (count (bytevector-length bv= ))) + "Write up to COUNT bytes from BV to the encoder stream. Return the +number of uncompressed bytes written, a strictly positive integer." + (let ((ret (proc (lz-encoder->pointer encoder) + (bytevector->pointer bv start) + count))) + (if (< ret 0) + (throw 'lzlib-error 'lz-compress-write (lz-compress-error enco= der)) + ret))))) + +(define lz-compress-write-size + (let ((proc (lzlib-procedure int "LZ_compress_write_size" '(*)))) + (lambda (encoder) + "The maximum number of bytes that can be immediately written through= the +`lz-compress-write' function. + +It is guaranteed that an immediate call to `lz-compress-write' will accept= a +SIZE up to the returned number of bytes. " + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-compress-write-size (lz-compress-error= encoder)) + ret))))) + +(define lz-compress-error + (let ((proc (lzlib-procedure int "LZ_compress_errno" '(*)))) + (lambda (encoder) + "ENCODER can be a Scheme object or a pointer." + (let* ((error-number (proc (if (lz-encoder? encoder) + (lz-encoder->pointer encoder) + encoder)))) + error-number)))) + +(define lz-compress-finished? + (let ((proc (lzlib-procedure int "LZ_compress_finished" '(*)))) + (lambda (encoder) + "Return #t if all the data have been read and `lz-compress-close' can +be safely called. Otherwise return #f." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (match ret + (1 #t) + (0 #f) + (_ (throw 'lzlib-error 'lz-compress-finished? (lz-compress-error= encoder)))))))) + +(define lz-compress-member-finished? + (let ((proc (lzlib-procedure int "LZ_compress_member_finished" '(*)))) + (lambda (encoder) + "Return #t if the current member, in a multimember data stream, has +been fully read and 'lz-compress-restart-member' can be safely called. +Otherwise return #f." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (match ret + (1 #t) + (0 #f) + (_ (throw 'lzlib-error 'lz-compress-member-finished? (lz-compres= s-error encoder)))))))) + +(define lz-compress-data-position + (let ((proc (lzlib-procedure uint64 "LZ_compress_data_position" '(*)))) + (lambda (encoder) + "Return the number of input bytes already compressed in the current +member." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-compress-data-position + (lz-compress-error encoder)) + ret))))) + +(define lz-compress-member-position + (let ((proc (lzlib-procedure uint64 "LZ_compress_member_position" '(*)))) + (lambda (encoder) + "Return the number of compressed bytes already produced, but perhaps +not yet read, in the current member." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-compress-member-position + (lz-compress-error encoder)) + ret))))) + +(define lz-compress-total-in-size + (let ((proc (lzlib-procedure uint64 "LZ_compress_total_in_size" '(*)))) + (lambda (encoder) + "Return the total number of input bytes already compressed." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-compress-total-in-size + (lz-compress-error encoder)) + ret))))) + +(define lz-compress-total-out-size + (let ((proc (lzlib-procedure uint64 "LZ_compress_total_out_size" '(*)))) + (lambda (encoder) + "Return the total number of compressed bytes already produced, but +perhaps not yet read." + (let ((ret (proc (lz-encoder->pointer encoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-compress-total-out-size + (lz-compress-error encoder)) + ret))))) + + +;; Decompression bindings. + +(define lz-decompress-open + (let ((proc (lzlib-procedure '* "LZ_decompress_open" '()))) + (lambda () + "Initializes the internal stream state for decompression and returns= a +pointer that can only be used as the decoder argument for the other +lz-decompress functions, or a null pointer if the decoder could not be +allocated. + +See the manual: (lzlib) Decompression functions." + (let ((decoder-ptr (proc))) + (if (not (=3D (lz-decompress-error decoder-ptr) -1)) + (pointer->lz-decoder decoder-ptr) + (throw 'lzlib-error 'lz-decompress-open)))))) + +(define lz-decompress-close + (let ((proc (lzlib-procedure int "LZ_decompress_close" '(*)))) + (lambda (decoder) + "Close decoder. DECODER can no longer be used as an argument to any +lz-decompress function. " + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-close ret) + ret))))) + +(define lz-decompress-finish + (let ((proc (lzlib-procedure int "LZ_decompress_finish" '(*)))) + (lambda (decoder) + "Tell that all the data for this stream have already been written (w= ith +the `lz-decompress-write' function). It is safe to call +`lz-decompress-finish' as many times as needed." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-finish (lz-decompress-error= decoder)) + ret))))) + +(define lz-decompress-reset + (let ((proc (lzlib-procedure int "LZ_decompress_reset" '(*)))) + (lambda (decoder) + "Reset the internal state of DECODER as it was just after opening it +with the `lz-decompress-open' function. Data stored in the internal buffe= rs +is discarded. Position counters are set to 0." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-reset + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-sync-to-member + (let ((proc (lzlib-procedure int "LZ_decompress_sync_to_member" '(*)))) + (lambda (decoder) + "Reset the error state of DECODER and enters a search state that las= ts +until a new member header (or the end of the stream) is found. After a +successful call to `lz-decompress-sync-to-member', data written with +`lz-decompress-write' will be consumed and 'lz-decompress-read' will retur= n 0 +until a header is found. + +This function is useful to discard any data preceding the first member, or= to +discard the rest of the current member, for example in case of a data +error. If the decoder is already at the beginning of a member, this funct= ion +does nothing." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-sync-to-member + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-read + (let ((proc (lzlib-procedure int "LZ_decompress_read" (list '* '* int)))) + (lambda* (decoder file-bv #:optional (start 0) (count (bytevector-leng= th file-bv))) + "Read up to COUNT bytes from the decoder stream, storing the results= in FILE-BV. +Return the number of uncompressed bytes written, a non-negative positive i= nteger." + (let ((ret (proc (lz-decoder->pointer decoder) + (bytevector->pointer file-bv start) + count))) + (if (< ret 0) + (throw 'lzlib-error 'lz-decompress-read (lz-decompress-error d= ecoder)) + ret))))) + +(define lz-decompress-write + (let ((proc (lzlib-procedure int "LZ_decompress_write" (list '* '* int))= )) + (lambda* (decoder bv #:optional (start 0) (count (bytevector-length bv= ))) + "Write up to COUNT bytes from BV to the decoder stream. Return the +number of uncompressed bytes written, a non-negative integer." + (let ((ret (proc (lz-decoder->pointer decoder) + (bytevector->pointer bv start) + count))) + (if (< ret 0) + (throw 'lzlib-error 'lz-decompress-write (lz-decompress-error = decoder)) + ret))))) + +(define lz-decompress-write-size + (let ((proc (lzlib-procedure int "LZ_decompress_write_size" '(*)))) + (lambda (decoder) + "Return the maximum number of bytes that can be immediately written +through the `lz-decompress-write' function. + +It is guaranteed that an immediate call to `lz-decompress-write' will acce= pt a +SIZE up to the returned number of bytes. " + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-write-size (lz-decompress-e= rror decoder)) + ret))))) + +(define lz-decompress-error + (let ((proc (lzlib-procedure int "LZ_decompress_errno" '(*)))) + (lambda (decoder) + "DECODER can be a Scheme object or a pointer." + (let* ((error-number (proc (if (lz-decoder? decoder) + (lz-decoder->pointer decoder) + decoder)))) + error-number)))) + +(define lz-decompress-finished? + (let ((proc (lzlib-procedure int "LZ_decompress_finished" '(*)))) + (lambda (decoder) + "Return #t if all the data have been read and `lz-decompress-close' = can +be safely called. Otherwise return #f." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (match ret + (1 #t) + (0 #f) + (_ (throw 'lzlib-error 'lz-decompress-finished? (lz-decompress-e= rror decoder)))))))) + +(define lz-decompress-member-finished? + (let ((proc (lzlib-procedure int "LZ_decompress_member_finished" '(*)))) + (lambda (decoder) + "Return #t if the current member, in a multimember data stream, has +been fully read and `lz-decompress-restart-member' can be safely called. +Otherwise return #f." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (match ret + (1 #t) + (0 #f) + (_ (throw 'lzlib-error 'lz-decompress-member-finished? (lz-decom= press-error decoder)))))))) + +(define lz-decompress-member-version + (let ((proc (lzlib-procedure int "LZ_decompress_member_version" '(*)))) + (lambda (decoder) + (let ((ret (proc (lz-decoder->pointer decoder)))) + "Return the version of current member from member header." + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-data-position + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-dictionary-size + (let ((proc (lzlib-procedure int "LZ_decompress_dictionary_size" '(*)))) + (lambda (decoder) + (let ((ret (proc (lz-decoder->pointer decoder)))) + "Return the dictionary size of current member from member header." + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-member-position + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-data-crc + (let ((proc (lzlib-procedure unsigned-int "LZ_decompress_data_crc" '(*))= )) + (lambda (decoder) + (let ((ret (proc (lz-decoder->pointer decoder)))) + "Return the 32 bit Cyclic Redundancy Check of the data decompressed +from the current member. The returned value is valid only when +`lz-decompress-member-finished' returns #t. " + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-member-position + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-data-position + (let ((proc (lzlib-procedure uint64 "LZ_decompress_data_position" '(*)))) + (lambda (decoder) + "Return the number of decompressed bytes already produced, but perha= ps +not yet read, in the current member." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-data-position + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-member-position + (let ((proc (lzlib-procedure uint64 "LZ_decompress_member_position" '(*)= ))) + (lambda (decoder) + "Return the number of input bytes already decompressed in the current +member." + (let ((ret (proc (lz-decoder->pointer decoder)))) + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-member-position + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-total-in-size + (let ((proc (lzlib-procedure uint64 "LZ_decompress_total_in_size" '(*)))) + (lambda (decoder) + (let ((ret (proc (lz-decoder->pointer decoder)))) + "Return the total number of input bytes already compressed." + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-total-in-size + (lz-decompress-error decoder)) + ret))))) + +(define lz-decompress-total-out-size + (let ((proc (lzlib-procedure uint64 "LZ_decompress_total_out_size" '(*))= )) + (lambda (decoder) + (let ((ret (proc (lz-decoder->pointer decoder)))) + "Return the total number of compressed bytes already produced, but +perhaps not yet read." + (if (=3D ret -1) + (throw 'lzlib-error 'lz-decompress-total-out-size + (lz-decompress-error decoder)) + ret))))) + + +;; 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, w= e 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))) + (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))))))) + (let loop ((rd 0)) + (if (< start (bytevector-length bv)) + (begin + (set! rd (lz-decompress-read decoder bv start (- (bytevector-l= ength bv) start))) + (set! start (+ start rd)) + (set! read (+ read rd))) + (set! rd 0)) + (unless (=3D rd 0) + (loop rd))) + read)) + +(define* (lzwrite encoder bv lz-port + #:optional (start 0) (count (bytevector-length bv))) + "Write up to COUNT bytes from BV at offset START into LZ-PORT. Return +the number of uncompressed bytes written, a non-negative integer." + (let ((written 0) + (read 0)) + (while (and (< 0 (lz-compress-write-size encoder)) + (< written count)) + (set! written (+ written + (lz-compress-write encoder bv (+ start written) (- = count written))))) + (when (=3D written 0) + (lz-compress-finish encoder)) + (let ((lz-bv (make-bytevector written))) + (let loop ((rd 0)) + (set! rd (lz-compress-read encoder lz-bv 0 (bytevector-length lz-b= v))) + (put-bytevector lz-port lz-bv 0 rd) + (set! read (+ read rd)) + (unless (=3D rd 0) + (loop rd)))) + ;; `written' is the total byte count of uncompressed data. + written)) + + +;;; +;;; Port interface. +;;; + +;; Alist of (levels (dictionary-size match-length-limit)). 0 is the faste= st. +;; See bbexample.c in lzlib's source. +(define %compression-levels + `((0 (65535 16)) + (1 (,(bitwise-arithmetic-shift-left 1 20) 5)) + (2 (,(bitwise-arithmetic-shift-left 3 19) 6)) + (3 (,(bitwise-arithmetic-shift-left 1 21) 8)) + (4 (,(bitwise-arithmetic-shift-left 3 20) 12)) + (5 (,(bitwise-arithmetic-shift-left 1 22) 20)) + (6 (,(bitwise-arithmetic-shift-left 1 23) 36)) + (7 (,(bitwise-arithmetic-shift-left 1 24) 68)) + (8 (,(bitwise-arithmetic-shift-left 3 23) 132)) + (9 (,(bitwise-arithmetic-shift-left 1 25) 273)))) + +(define %default-compression-level + 6) + +(define* (make-lzip-input-port port) + "Return an input port that decompresses data read from PORT, a file port. +PORT is automatically closed when the resulting port is closed." + (define decoder (lz-decompress-open)) + + (define (read! bv start count) + (lzread! decoder port bv start count)) + + (make-custom-binary-input-port "lzip-input" read! #f #f + (lambda () + (lz-decompress-close decoder) + (close-port port)))) + +(define* (make-lzip-output-port port + #:key + (level %default-compression-level)) + "Return an output port that compresses data at the given LEVEL, using PO= RT, +a file port, as its sink. PORT is automatically closed when the resulting +port is closed." + (define encoder (apply lz-compress-open + (car (assoc-ref %compression-levels level)))) + + (define (write! bv start count) + (lzwrite encoder bv port start count)) + + (make-custom-binary-output-port "lzip-output" write! #f #f + (lambda () + (lz-compress-finish encoder) + ;; "lz-read" the trailing metadata add= ed by `lz-compress-finish'. + (let ((lz-bv (make-bytevector (* 64 10= 24)))) + (let loop ((rd 0)) + (set! rd (lz-compress-read encoder= lz-bv 0 (bytevector-length lz-bv))) + (put-bytevector port lz-bv 0 rd) + (unless (=3D rd 0) + (loop rd)))) + (lz-compress-close encoder) + (close-port port)))) + +(define* (call-with-lzip-input-port port proc) + "Call PROC with a port that wraps PORT and decompresses data read from i= t. +PORT is closed upon completion." + (let ((lzip (make-lzip-input-port port))) + (dynamic-wind + (const #t) + (lambda () + (proc lzip)) + (lambda () + (close-port lzip))))) + +(define* (call-with-lzip-output-port port proc + #:key + (level %default-compression-level)) + "Call PROC with an output port that wraps PORT and compresses data. POR= T is +close upon completion." + (let ((lzip (make-lzip-output-port port + #:level level))) + (dynamic-wind + (const #t) + (lambda () + (proc lzip)) + (lambda () + (close-port lzip))))) + +;;; lzlib.scm ends here diff --git a/guix/self.scm b/guix/self.scm index 68b87051e9..ff6b7765dd 100644 --- a/guix/self.scm +++ b/guix/self.scm @@ -969,7 +969,8 @@ Info manual." =20 (define %libz #+(and zlib - (file-append zlib "/lib/libz")))) + (file-append zlib "/lib/libz"))) + (define %liblz #f)) =20 ;; Guile 2.0 *requires* the 'define-module' to be at the ;; top-level or the 'toplevel-ref' in the resulting .go fil= e are diff --git a/m4/guix.m4 b/m4/guix.m4 index 5c846f7618..78cc3777f8 100644 --- a/m4/guix.m4 +++ b/m4/guix.m4 @@ -312,6 +312,23 @@ AC_DEFUN([GUIX_LIBZ_LIBDIR], [ $1=3D"$guix_cv_libz_libdir" ]) =20 +dnl GUIX_LIBLZ_LIBDIR VAR +dnl +dnl Attempt to determine liblz's LIBDIR; store the result in VAR. +AC_DEFUN([GUIX_LIBLZ_LIBDIR], [ + AC_REQUIRE([PKG_PROG_PKG_CONFIG]) + AC_CACHE_CHECK([lzlib's library directory], + [guix_cv_liblz_libdir], + [guix_cv_liblz_libdir=3D"`$PKG_CONFIG lzlib --variable=3Dlibdir 2> /de= v/null`"]) + dnl TODO: lzlib has no pkg-config so we need the following trick to fi= nd its directory. + dnl old_LIBS=3D"$LIBS" + dnl LIBS=3D"-llz" + dnl AC_LINK_IFELSE([LZ_decompress_open();], + dnl [guix_cv_libz_libdir=3D"`ldd conftest$EXEEXT | grep liblz | sed = '-es/.*=3D> \([^ ]*\).*$/\1/g'`"]) + dnl LIBS=3D"$old_LIBS" + $1=3D"$guix_cv_liblz_libdir" +]) + dnl GUIX_CURRENT_LOCALSTATEDIR dnl dnl Determine the localstatedir of an existing Guix installation and set diff --git a/tests/lzlib.scm b/tests/lzlib.scm new file mode 100644 index 0000000000..a6631ce91c --- /dev/null +++ b/tests/lzlib.scm @@ -0,0 +1,108 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2019 Pierre Neidhardt +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (test-lzlib) + #:use-module (guix lzlib) + #:use-module (guix tests) + #:use-module (srfi srfi-64) + #:use-module (rnrs bytevectors) + #:use-module (rnrs io ports) + #:use-module (ice-9 match)) + +;; Test the (guix lzlib) module. + +(unless (lzlib-available?) + (exit 77)) + +(test-begin "lzlib") + +(define (compress-and-decompress data) + "DATA must be a bytevector." + (pk "Uncompressed bytes:" (bytevector-length data)) + (match (pipe) + ((parent . child) + (match (primitive-fork) + (0 ;compress + (dynamic-wind + (const #t) + (lambda () + (close-port parent) + (call-with-lzip-output-port child + (lambda (port) + (put-bytevector port data)))) + (lambda () + (primitive-exit 0)))) + (pid ;decompress + (begin + (close-port child) + (let ((received (call-with-lzip-input-port parent + (lambda (port) + (get-bytevector-all port))))) + (match (waitpid pid) + ((_ . status) + (pk "Status" status) + (pk "Length data" (bytevector-length data) "received" (byte= vector-length received)) + ;; The following loop is a debug helper. + (let loop ((i 0)) + (if (and (< i (bytevector-length received)) + (=3D (bytevector-u8-ref received i) + (bytevector-u8-ref data i))) + (loop (+ 1 i)) + (pk "First diff at index" i))) + (and (zero? status) + (port-closed? parent) + (bytevector=3D? received data))))))))))) + +(test-assert "null bytevector" + (compress-and-decompress (make-bytevector (+ (random 100000) + (* 20 1024))))) + +(test-assert "random bytevector" + (compress-and-decompress (random-bytevector (+ (random 100000) + (* 20 1024))))) +(test-assert "small bytevector" + (compress-and-decompress (random-bytevector 127))) + +(test-assert "1 bytevector" + (compress-and-decompress (random-bytevector 1))) + +(test-assert "Bytevector of size relative to Lzip internal buffers (2 * di= ctionary)" + (compress-and-decompress + (random-bytevector + (* 2 (car (car (assoc-ref (@@ (guix lzlib) %compression-levels) + (@@ (guix lzlib) %default-compression-level)= ))))))) + +(test-assert "Bytevector of size relative to Lzip internal buffers (64KiB)" + (compress-and-decompress (random-bytevector (* 64 1024)))) + +(test-assert "Bytevector of size relative to Lzip internal buffers (64KiB-= 1)" + (compress-and-decompress (random-bytevector (1- (* 64 1024))))) + +(test-assert "Bytevector of size relative to Lzip internal buffers (64KiB+= 1)" + (compress-and-decompress (random-bytevector (1+ (* 64 1024))))) + +(test-assert "Bytevector of size relative to Lzip internal buffers (1MiB)" + (compress-and-decompress (random-bytevector (* 1024 1024)))) + +(test-assert "Bytevector of size relative to Lzip internal buffers (1MiB-1= )" + (compress-and-decompress (random-bytevector (1- (* 1024 1024))))) + +(test-assert "Bytevector of size relative to Lzip internal buffers (1MiB+1= )" + (compress-and-decompress (random-bytevector (1+ (* 1024 1024))))) + +(test-end) --=20 2.21.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-dir-locals.el-Add-call-with-lzip-input-port-and-call.patch >From 7dd8f4207657ae7ad178c21a45f74bef6cc0a314 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Sun, 10 Mar 2019 16:40:41 +0100 Subject: [PATCH 2/2] dir-locals.el: Add 'call-with-lzip-input-port' and 'call-with-lzip-output-port' keywords. * .dir-locals.el: Add indentation rules for 'call-with-lzip-input-port' and 'call-with-lzip-output-port'. --- .dir-locals.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.dir-locals.el b/.dir-locals.el index 550e06ef09..f1196fd781 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -53,6 +53,8 @@ (eval . (put 'call-with-decompressed-port 'scheme-indent-function 2)) (eval . (put 'call-with-gzip-input-port 'scheme-indent-function 1)) (eval . (put 'call-with-gzip-output-port 'scheme-indent-function 1)) + (eval . (put 'call-with-lzip-input-port 'scheme-indent-function 1)) + (eval . (put 'call-with-lzip-output-port 'scheme-indent-function 1)) (eval . (put 'signature-case 'scheme-indent-function 1)) (eval . (put 'emacs-batch-eval 'scheme-indent-function 0)) (eval . (put 'emacs-batch-edit-file 'scheme-indent-function 1)) -- 2.21.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat May 04 17:09:50 2019 Received: (at 34807) by debbugs.gnu.org; 4 May 2019 21:09:50 +0000 Received: from localhost ([127.0.0.1]:52462 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hN1un-0005M5-Ss for submit@debbugs.gnu.org; Sat, 04 May 2019 17:09:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57503) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hN1um-0005Lt-BY for 34807@debbugs.gnu.org; Sat, 04 May 2019 17:09:48 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:34271) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hN1ug-0000om-O1; Sat, 04 May 2019 17:09:42 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=36674 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hN1ug-00047C-Aq; Sat, 04 May 2019 17:09:42 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Pierre Neidhardt Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> <8736lxdxn6.fsf@ambrevar.xyz> <87lfzm7fdz.fsf@gnu.org> <878svm5xic.fsf@ambrevar.xyz> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 15 =?utf-8?Q?Flor=C3=A9al?= an 227 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, 04 May 2019 23:09:40 +0200 In-Reply-To: <878svm5xic.fsf@ambrevar.xyz> (Pierre Neidhardt's message of "Sat, 04 May 2019 12:23:23 +0200") Message-ID: <87ef5e0vvv.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (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] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 34807 Cc: 34807@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: -3.3 (---) Hello! Pierre Neidhardt skribis: > Right on time, I just finished it! > > - I've been in touch with Antonio, Lzip's maintainer, for more than a > week and now I'm confident that I have a decent understanding of the > library. > > - Your m4 suggestion didn't work. I've included a comment. We need to > fix it before merging. I'm not the right person for this job I'm > afraid :p Ludo? Sure, I can do it. > - The convenience functions do not support multi-member archives. > Multi-member archives are mostly useful for parallelization, but we > don't use that in Guix, so it's OK. Should it be required some day, > we would need to implement it, which requires a little bit more work. > I've documented all that. > > - The implementation of lzread! is subpar because I understood a > subtlety a bit too late. But that's alright, it does not affect > performance nor reliability. > > - I've included 11 tests covering all your suggestions. > > - I haven't strace'd the Guile process. The code regarding ports is > identical to zlib.scm, so it's unlikely there would be an issue in > this area. I have never done this before, so out of curiosity, how do > you run a specific Guix tests without going through `make'? > > Next steps? :D This looks all good to me! I was about to apply it and add the Autoconf machinery, but I thought we could also make it a separate project that could be beneficial to other Guilers out there (like we did with Guile-Gcrypt and Guile-Git). Incidentally that would also avoid the need for adding the =E2=80=98%liblz= =E2=80=99 variable in (guix config), which simplifies things a bit. WDYT? If you want to take that route, I=E2=80=99m happy to help with the Autotools machinery (or you could use =E2=80=98hall=E2=80=99 from the =E2=80=98guile-= hall=E2=80=99 package to do that for you.) If you don=E2=80=99t feel like taking that route (or at least not yet ;-)), that=E2=80=99s OK for me too, I don=E2=80=99t feel strongly either way. Thoughts? Thank you! Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Sat May 04 17:39:45 2019 Received: (at 34807) by debbugs.gnu.org; 4 May 2019 21:39:45 +0000 Received: from localhost ([127.0.0.1]:52529 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hN2Nl-00067Y-6Z for submit@debbugs.gnu.org; Sat, 04 May 2019 17:39:45 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:57071) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hN2Nh-00067N-SE for 34807@debbugs.gnu.org; Sat, 04 May 2019 17:39:43 -0400 Received: from bababa (lfbn-1-4117-19.w92-169.abo.wanadoo.fr [92.169.116.19]) (Authenticated sender: pierre@atlas.engineer) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 3CF94100002; Sat, 4 May 2019 21:39:38 +0000 (UTC) From: Pierre Neidhardt To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). In-Reply-To: <87ef5e0vvv.fsf@gnu.org> References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> <8736lxdxn6.fsf@ambrevar.xyz> <87lfzm7fdz.fsf@gnu.org> <878svm5xic.fsf@ambrevar.xyz> <87ef5e0vvv.fsf@gnu.org> Date: Sat, 04 May 2019 23:39:37 +0200 Message-ID: <87o94h527a.fsf@ambrevar.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 34807 Cc: 34807@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.7 (-) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi! It's definitely the ideal route. Something like guile-compress or guile-archive, with a high-level abstraction for a collection of bindings including zlib and lzlib for now. Sadly I don't have the time for it at the moment. Unless you do (:p) I suggest we add a TODO item and keep it for later. Regarding guix publish and the farms, what shall we do? =2D-=20 Pierre Neidhardt https://ambrevar.xyz/ --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlzOBpkACgkQm9z0l6S7 zH9TFAf9EwoeU8kQ2MPm9cWE5Vt5WZVZtJOTpUk8aqR4s3X3yza5Z0SGnRquxzqV EYBi2+9ZgAbVAKaXh5OuqTgoBpgcE4c0kHWOBi75KVJCkOoheWmC4gyFOfTmFkGi 9EMdbRf0BIczDMbbvc7ev2skIX5FbpDvcySMKs/Wnnvr5FXU57iPXoUJpb0KUg0d RsgMg+tXq108GyTrBYHIdShXGGVqyQfRGCl8mUNxsXDHfu7EQDlBHIdrzQAK3YlO o8a0PMDmFcUaaPvVAf674JajrXe3apGKwzhsViWvkDrmxxWPtQ9DAThNV3KRqq0+ 0OgbC/B37Ydg/PvzaRj20D7ighgVIg== =ZAOL -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon May 06 17:18:59 2019 Received: (at 34807) by debbugs.gnu.org; 6 May 2019 21:18:59 +0000 Received: from localhost ([127.0.0.1]:57613 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNl0f-0002RL-Ec for submit@debbugs.gnu.org; Mon, 06 May 2019 17:18:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47217) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNl0a-0002R3-Ft for 34807@debbugs.gnu.org; Mon, 06 May 2019 17:18:52 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:46978) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNl0U-0002Ur-Ax; Mon, 06 May 2019 17:18:42 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=58962 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hNl0T-0006n4-Bu; Mon, 06 May 2019 17:18:41 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Pierre Neidhardt Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> <8736lxdxn6.fsf@ambrevar.xyz> <87lfzm7fdz.fsf@gnu.org> <878svm5xic.fsf@ambrevar.xyz> <87ef5e0vvv.fsf@gnu.org> <87o94h527a.fsf@ambrevar.xyz> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 17 =?utf-8?Q?Flor=C3=A9al?= an 227 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: Mon, 06 May 2019 23:18:38 +0200 In-Reply-To: <87o94h527a.fsf@ambrevar.xyz> (Pierre Neidhardt's message of "Sat, 04 May 2019 23:39:37 +0200") Message-ID: <87a7fzffip.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 34807 Cc: 34807@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 Hi Pierre, Pierre Neidhardt skribis: > It's definitely the ideal route. Something like guile-compress or > guile-archive, with a high-level abstraction for a collection of > bindings including zlib and lzlib for now. > > Sadly I don't have the time for it at the moment. Unless you do (:p) I > suggest we add a TODO item and keep it for later. Sounds good! Below are the Autoconf-related changes I made. Committed! We=E2=80=99ll take care of (guix self) when (guix lzlib) is actually used by other parts of the code. > Regarding guix publish and the farms, what shall we do? I think we should arrange for the client part, =E2=80=98guix substitute=E2= =80=99, to be ready to lzip-decode as soon as it talks to an lzip-capable server. Then we should add support in =E2=80=98guix publish=E2=80=99. At some late= r point, we=E2=80=99d deploy it on the build farms. For this migration to be incremental, we need (1) clients to be able to transparently switch to lzip when it=E2=80=99s available, and (2) servers t= o be able to produce both lzip archives (for new clients) and gzip archives (for old clients) during the transition period. That=E2=80=99s a bit of work in =E2=80=98guix publish=E2=80=99. It=E2=80= =99ll be extra CPU and storage usage on the build farm since during the transition period it=E2=80=99d hav= e to produce and store both gzip and lzip archives for each store item. I don=E2=80=99t really see any way around that, though. A difficulty is that narinfos currently include a fixed compression scheme: --8<---------------cut here---------------start------------->8--- $ wget -q -O - https://ci.guix.info/nrkm1683p1cqnkcmhlmhiig9q9qd7xqh.narinf= o | head -3 StorePath: /gnu/store/nrkm1683p1cqnkcmhlmhiig9q9qd7xqh-sed-4.5 URL: nar/gzip/nrkm1683p1cqnkcmhlmhiig9q9qd7xqh-sed-4.5 Compression: gzip --8<---------------cut here---------------end--------------->8--- So, depending on the client, =E2=80=98guix publish=E2=80=99 should return e= ither a narinfo-for-gzip or a narinfo-for-lzip. To make it possible, new clients could send an extra HTTP header, say =E2=80=98X-Guix-Compression=E2= =80=99, that would specify their preferred compression method(s). =E2=80=98guix publish= =E2=80=99 would take that into account when replying. How does that sound? Thanks, Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable diff --git a/configure.ac b/configure.ac index ee7aa25742..3918550a79 100644 --- a/configure.ac +++ b/configure.ac @@ -251,14 +251,13 @@ AC_MSG_RESULT([$LIBZ]) AC_SUBST([LIBZ]) =20 dnl Library name of lzlib suitable for 'dynamic-link'. -GUIX_LIBLZ_LIBDIR([liblz_libdir]) -if test "x$liblz_libdir" =3D "x"; then +GUIX_LIBLZ_FILE_NAME([LIBLZ]) +if test "x$LIBLZ" =3D "x"; then LIBLZ=3D"liblz" else - LIBLZ=3D"$liblz_libdir/liblz" + # Strip the .so or .so.1 extension since that's what 'dynamic-link' expe= cts. + LIBLZ=3D"`echo $LIBLZ | sed -es'/\.so\(\.[[0-9.]]\+\)\?//g'`" fi -AC_MSG_CHECKING([for lzlib's shared library name]) -AC_MSG_RESULT([$LIBLZ]) AC_SUBST([LIBLZ]) =20 dnl Check for Guile-SSH, for the (guix ssh) module. diff --git a/guix/config.scm.in b/guix/config.scm.in index cd7036ca7e..0ada0f3c38 100644 --- a/guix/config.scm.in +++ b/guix/config.scm.in @@ -34,10 +34,10 @@ =20 %system %libz + %liblz %gzip %bzip2 - %xz - %liblz)) + %xz)) =20 ;;; Commentary: ;;; @@ -91,6 +91,9 @@ (define %libz "@LIBZ@") =20 +(define %liblz + "@LIBLZ@") + (define %gzip "@GZIP@") =20 @@ -100,9 +103,4 @@ (define %xz "@XZ@") =20 -(define %liblz - ;; TODO: Set this dynamically. - ;; "@LIBLZ@" - "/gnu/store/8db7vivi8p9mpkbphb8xy8gh2bkwc4iz-lzlib-1.11/lib/liblz") - ;;; config.scm ends here diff --git a/guix/self.scm b/guix/self.scm index 983f3514d3..74ea65240c 100644 --- a/guix/self.scm +++ b/guix/self.scm @@ -925,6 +925,7 @@ Info manual." %store-database-directory %config-directory %libz + ;; TODO: %liblz %gzip %bzip2 %xz)) @@ -971,8 +972,7 @@ Info manual." =20 (define %libz #+(and zlib - (file-append zlib "/lib/libz"))) - (define %liblz #f)) + (file-append zlib "/lib/libz")))) =20 ;; Guile 2.0 *requires* the 'define-module' to be at the ;; top-level or the 'toplevel-ref' in the resulting .go fil= e are diff --git a/m4/guix.m4 b/m4/guix.m4 index 78cc3777f8..d0c5ec0f08 100644 --- a/m4/guix.m4 +++ b/m4/guix.m4 @@ -1,5 +1,5 @@ dnl GNU Guix --- Functional package management for GNU -dnl Copyright =C2=A9 2012, 2013, 2014, 2015, 2016, 2018 Ludovic Court=C3= =A8s +dnl Copyright =C2=A9 2012, 2013, 2014, 2015, 2016, 2018, 2019 Ludovic Cour= t=C3=A8s dnl Copyright =C2=A9 2014 Mark H Weaver dnl Copyright =C2=A9 2017 Efraim Flashner dnl @@ -312,20 +312,18 @@ AC_DEFUN([GUIX_LIBZ_LIBDIR], [ $1=3D"$guix_cv_libz_libdir" ]) =20 -dnl GUIX_LIBLZ_LIBDIR VAR +dnl GUIX_LIBLZ_FILE_NAME VAR dnl -dnl Attempt to determine liblz's LIBDIR; store the result in VAR. -AC_DEFUN([GUIX_LIBLZ_LIBDIR], [ +dnl Attempt to determine liblz's absolute file name; store the result in V= AR. +AC_DEFUN([GUIX_LIBLZ_FILE_NAME], [ AC_REQUIRE([PKG_PROG_PKG_CONFIG]) - AC_CACHE_CHECK([lzlib's library directory], + AC_CACHE_CHECK([lzlib's file name], [guix_cv_liblz_libdir], - [guix_cv_liblz_libdir=3D"`$PKG_CONFIG lzlib --variable=3Dlibdir 2> /de= v/null`"]) - dnl TODO: lzlib has no pkg-config so we need the following trick to fi= nd its directory. - dnl old_LIBS=3D"$LIBS" - dnl LIBS=3D"-llz" - dnl AC_LINK_IFELSE([LZ_decompress_open();], - dnl [guix_cv_libz_libdir=3D"`ldd conftest$EXEEXT | grep liblz | sed = '-es/.*=3D> \([^ ]*\).*$/\1/g'`"]) - dnl LIBS=3D"$old_LIBS" + [old_LIBS=3D"$LIBS" + LIBS=3D"-llz" + AC_LINK_IFELSE([AC_LANG_SOURCE([int main () { return LZ_decompress_op= en(); }])], + [guix_cv_liblz_libdir=3D"`ldd conftest$EXEEXT | grep liblz | sed '-= es/.*=3D> \(.*\) .*$/\1/g'`"]) + LIBS=3D"$old_LIBS"]) $1=3D"$guix_cv_liblz_libdir" ]) =20 diff --git a/tests/lzlib.scm b/tests/lzlib.scm index a6631ce91c..cf53a9417d 100644 --- a/tests/lzlib.scm +++ b/tests/lzlib.scm @@ -26,8 +26,11 @@ =20 ;; Test the (guix lzlib) module. =20 -(unless (lzlib-available?) - (exit 77)) +(define-syntax-rule (test-assert* description exp) + (begin + (unless (lzlib-available?) + (test-skip 1)) + (test-assert description exp))) =20 (test-begin "lzlib") =20 @@ -68,41 +71,41 @@ (port-closed? parent) (bytevector=3D? received data))))))))))) =20 -(test-assert "null bytevector" +(test-assert* "null bytevector" (compress-and-decompress (make-bytevector (+ (random 100000) (* 20 1024))))) =20 -(test-assert "random bytevector" +(test-assert* "random bytevector" (compress-and-decompress (random-bytevector (+ (random 100000) (* 20 1024))))) -(test-assert "small bytevector" +(test-assert* "small bytevector" (compress-and-decompress (random-bytevector 127))) =20 -(test-assert "1 bytevector" +(test-assert* "1 bytevector" (compress-and-decompress (random-bytevector 1))) =20 -(test-assert "Bytevector of size relative to Lzip internal buffers (2 * di= ctionary)" +(test-assert* "Bytevector of size relative to Lzip internal buffers (2 * d= ictionary)" (compress-and-decompress (random-bytevector (* 2 (car (car (assoc-ref (@@ (guix lzlib) %compression-levels) (@@ (guix lzlib) %default-compression-level)= ))))))) =20 -(test-assert "Bytevector of size relative to Lzip internal buffers (64KiB)" +(test-assert* "Bytevector of size relative to Lzip internal buffers (64KiB= )" (compress-and-decompress (random-bytevector (* 64 1024)))) =20 -(test-assert "Bytevector of size relative to Lzip internal buffers (64KiB-= 1)" +(test-assert* "Bytevector of size relative to Lzip internal buffers (64KiB= -1)" (compress-and-decompress (random-bytevector (1- (* 64 1024))))) =20 -(test-assert "Bytevector of size relative to Lzip internal buffers (64KiB+= 1)" +(test-assert* "Bytevector of size relative to Lzip internal buffers (64KiB= +1)" (compress-and-decompress (random-bytevector (1+ (* 64 1024))))) =20 -(test-assert "Bytevector of size relative to Lzip internal buffers (1MiB)" +(test-assert* "Bytevector of size relative to Lzip internal buffers (1MiB)" (compress-and-decompress (random-bytevector (* 1024 1024)))) =20 -(test-assert "Bytevector of size relative to Lzip internal buffers (1MiB-1= )" +(test-assert* "Bytevector of size relative to Lzip internal buffers (1MiB-= 1)" (compress-and-decompress (random-bytevector (1- (* 1024 1024))))) =20 -(test-assert "Bytevector of size relative to Lzip internal buffers (1MiB+1= )" +(test-assert* "Bytevector of size relative to Lzip internal buffers (1MiB+= 1)" (compress-and-decompress (random-bytevector (1+ (* 1024 1024))))) =20 (test-end) --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Mon May 06 19:28:22 2019 Received: (at 34807) by debbugs.gnu.org; 6 May 2019 23:28:22 +0000 Received: from localhost ([127.0.0.1]:57760 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNn1y-0001Wa-DZ for submit@debbugs.gnu.org; Mon, 06 May 2019 19:28:22 -0400 Received: from tobias.gr ([80.241.217.52]:57014) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNn1t-0001WM-4E for 34807@debbugs.gnu.org; Mon, 06 May 2019 19:28:21 -0400 Received: by tobias.gr (OpenSMTPD) with ESMTP id 5155bda5; Mon, 6 May 2019 23:28:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=tobias.gr; h=from:to:cc :subject:references:in-reply-to:date:message-id:mime-version :content-type; s=2018; i=me@tobias.gr; bh=rlgNfBo9lR14dcLB22UVCY F6zCXiZk+OhwaUollIQig=; b=ND/2tA0kbxhipQCtOply99bBS5yS3isyepOb9V Of33LR7a4VjSDMHjCcqGAD+hybHjv3HXQvhyDM8ZGiJmPkzzchvf8OTuRB2vglT+ fT85D8LT1WrYVwpNcmn3wD9YWeymfk0IKT4CBFkv5jzGf78NzpMA7Cgo3VEFBFjk zrQqIGXCVmYg78gGivUBgVeAas8SJho9+N53WawUx+g8a4FL1VlyI8N7KXdeGN/E baeW7nKaNelLTMyvRn4HQP7A6Q1/ty3BI2izppGM0vvNt5IqH+fYIYw2vtBj1pLk A89RbcQVGeb3MEIV/xRYdHvy2eYm0Cn/l9RkZG9CgZ2OqQcA== Received: by submission.tobias.gr (OpenSMTPD) with ESMTPSA id 7c658bcd (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256:NO); Mon, 6 May 2019 23:28:10 +0000 (UTC) From: Tobias Geerinckx-Rice To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> <8736lxdxn6.fsf@ambrevar.xyz> <87lfzm7fdz.fsf@gnu.org> <878svm5xic.fsf@ambrevar.xyz> <87ef5e0vvv.fsf@gnu.org> <87o94h527a.fsf@ambrevar.xyz> <87a7fzffip.fsf@gnu.org> In-reply-to: <87a7fzffip.fsf@gnu.org> Date: Tue, 07 May 2019 01:28:09 +0200 Message-ID: <87v9ynf9iu.fsf@nckx> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 34807 Cc: Pierre Neidhardt , 34807@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: -3.3 (---) --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Ludo', Ludovic Court=C3=A8s wrote: > So, depending on the client, =E2=80=98guix publish=E2=80=99 should return= either=20 > a > narinfo-for-gzip or a narinfo-for-lzip. To make it possible,=20 > new > clients could send an extra HTTP header, say=20 > =E2=80=98X-Guix-Compression=E2=80=99, that > would specify their preferred compression method(s). =E2=80=98guix=20 > publish=E2=80=99 > would take that into account when replying. There's a standard[0] HTTP header for that: =E2=80=98Accept-Encoding=E2=80= =99. Unfortunately (and for reasons that I cannot fathom), it doesn't=20 use standard MIME types, but pseudostandard strings like =E2=80=98gzip=E2= =80=99=20 and =E2=80=98br=E2=80=99. We can boldly add =E2=80=98lzip=E2=80=99 to that= :-) Similarly, servers can send =E2=80=98Content-Encoding=E2=80=99[1] HTTP head= ers,=20 but I don't see a need for it here. Kind regards, T G-R [0]:=20 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding [1]:=20 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEARYKAB0WIQT12iAyS4c9C3o4dnINsP+IT1VteQUCXNDDCQAKCRANsP+IT1Vt efyOAPkBiYUZx40xk8eKEOJnDH2nvES6mx695c5hyWuKutqVcAEAiGbLbXrxylsN H/EkvEUOrKKkgjof1fH2zksp4TYwkgM= =MOcO -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue May 07 03:02:50 2019 Received: (at 34807) by debbugs.gnu.org; 7 May 2019 07:02:50 +0000 Received: from localhost ([127.0.0.1]:58127 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNu7m-0007tt-Jf for submit@debbugs.gnu.org; Tue, 07 May 2019 03:02:50 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:54337) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNu7k-0007tk-23 for 34807@debbugs.gnu.org; Tue, 07 May 2019 03:02:49 -0400 X-Originating-IP: 92.169.116.19 Received: from bababa (lfbn-1-4117-19.w92-169.abo.wanadoo.fr [92.169.116.19]) (Authenticated sender: pierre@atlas.engineer) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id C80981C0016; Tue, 7 May 2019 07:02:43 +0000 (UTC) From: Pierre Neidhardt To: Tobias Geerinckx-Rice , Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). In-Reply-To: <87v9ynf9iu.fsf@nckx> References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> <8736lxdxn6.fsf@ambrevar.xyz> <87lfzm7fdz.fsf@gnu.org> <878svm5xic.fsf@ambrevar.xyz> <87ef5e0vvv.fsf@gnu.org> <87o94h527a.fsf@ambrevar.xyz> <87a7fzffip.fsf@gnu.org> <87v9ynf9iu.fsf@nckx> Date: Tue, 07 May 2019 09:02:41 +0200 Message-ID: <87d0ku21da.fsf@ambrevar.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 34807 Cc: 34807@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.7 (-) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable All good. I'm very busy (with Next browser) these days, so I won't have much time. Maybe I can give (1) a shot (lzip-decoding for clients), don't think I'll have time for the guix publish part before a while. Anyone? =2D-=20 Pierre Neidhardt https://ambrevar.xyz/ --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlzRLZEACgkQm9z0l6S7 zH9vJgf/QSKbMMCL/lT3IgOtbMcjAbwlvB9542NeLXrrA5vFEO/1x413K56whXy6 bW0k+oWT1JTwlNnyE1vzX7aZ1bwydEU5Vb59N6553sdnxH1BChreyZRbGYCLdzfu 0lNNX7eAS5mu9MP+7NiDasnDER+Mj+wVHhimr45DOvCFd21AYUiidB+NvekFn0us 4F9E1RCd/+Hs9s5BcLb5v5FvYq9LKDPnzJYhKmbIp4a8YbPW3954/e7PU6V4wlyR Cn9HW5ZBJevYhPU2HMY+wTtTYD0JlDnJYEtXmK53z1tK8Al6XR4mg0vXpSrvPAxR Q2P1eqK0R1OToEWelzbgiVr6AZnIgQ== =JbeX -----END PGP SIGNATURE----- --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Tue May 07 04:19:30 2019 Received: (at 34807) by debbugs.gnu.org; 7 May 2019 08:19:30 +0000 Received: from localhost ([127.0.0.1]:58171 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNvJx-0001YN-QN for submit@debbugs.gnu.org; Tue, 07 May 2019 04:19:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43341) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hNvJu-0001Y7-Ut for 34807@debbugs.gnu.org; Tue, 07 May 2019 04:19:28 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55560) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNvJo-0007wF-T8; Tue, 07 May 2019 04:19:20 -0400 Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=38512 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hNvJo-0008Si-Ht; Tue, 07 May 2019 04:19:20 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Tobias Geerinckx-Rice Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> <8736lxdxn6.fsf@ambrevar.xyz> <87lfzm7fdz.fsf@gnu.org> <878svm5xic.fsf@ambrevar.xyz> <87ef5e0vvv.fsf@gnu.org> <87o94h527a.fsf@ambrevar.xyz> <87a7fzffip.fsf@gnu.org> <87v9ynf9iu.fsf@nckx> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 18 =?utf-8?Q?Flor=C3=A9al?= an 227 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: Tue, 07 May 2019 10:19:19 +0200 In-Reply-To: <87v9ynf9iu.fsf@nckx> (Tobias Geerinckx-Rice's message of "Tue, 07 May 2019 01:28:09 +0200") Message-ID: <87sgtq8yns.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (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] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 34807 Cc: Pierre Neidhardt , 34807@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: -3.3 (---) Tobias Geerinckx-Rice skribis: > Ludovic Court=C3=A8s wrote: >> So, depending on the client, =E2=80=98guix publish=E2=80=99 should retur= n either a >> narinfo-for-gzip or a narinfo-for-lzip. To make it possible, new >> clients could send an extra HTTP header, say =E2=80=98X-Guix-Compression= =E2=80=99, >> that >> would specify their preferred compression method(s). =E2=80=98guix publ= ish=E2=80=99 >> would take that into account when replying. > > There's a standard[0] HTTP header for that: =E2=80=98Accept-Encoding=E2= =80=99. > > Unfortunately (and for reasons that I cannot fathom), it doesn't use > standard MIME types, but pseudostandard strings like =E2=80=98gzip=E2=80= =99 and =E2=80=98br=E2=80=99. > We can boldly add =E2=80=98lzip=E2=80=99 to that :-) Well, that=E2=80=99s why I thought about using a new header. :-) Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Tue May 07 11:44:32 2019 Received: (at 34807-done) by debbugs.gnu.org; 7 May 2019 15:44:32 +0000 Received: from localhost ([127.0.0.1]:59368 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO2Gd-0004t5-PV for submit@debbugs.gnu.org; Tue, 07 May 2019 11:44:32 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51151) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO2Gb-0004sq-6x for 34807-done@debbugs.gnu.org; Tue, 07 May 2019 11:44:29 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:33347) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hO2GS-00040T-FU; Tue, 07 May 2019 11:44:20 -0400 Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=39972 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1hO2GQ-0006hr-Kj; Tue, 07 May 2019 11:44:19 -0400 From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: Pierre Neidhardt Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> <8736lxdxn6.fsf@ambrevar.xyz> <87lfzm7fdz.fsf@gnu.org> <878svm5xic.fsf@ambrevar.xyz> <87ef5e0vvv.fsf@gnu.org> <87o94h527a.fsf@ambrevar.xyz> <87a7fzffip.fsf@gnu.org> <87v9ynf9iu.fsf@nckx> <87d0ku21da.fsf@ambrevar.xyz> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 18 =?utf-8?Q?Flor=C3=A9al?= an 227 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: Tue, 07 May 2019 17:44:16 +0200 In-Reply-To: <87d0ku21da.fsf@ambrevar.xyz> (Pierre Neidhardt's message of "Tue, 07 May 2019 09:02:41 +0200") Message-ID: <87lfzi46cv.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (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] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 34807-done Cc: 34807-done@debbugs.gnu.org, Tobias Geerinckx-Rice 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: -3.3 (---) Pierre Neidhardt skribis: > I'm very busy (with Next browser) these days, so I won't have much time. > Maybe I can give (1) a shot (lzip-decoding for clients), don't think > I'll have time for the guix publish part before a while. I=E2=80=99ll take a look at it, probably after 1.0.1. Anyway, we can close this issue and open new ones for the remaining bits. Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Tue May 07 11:51:35 2019 Received: (at 34807-done) by debbugs.gnu.org; 7 May 2019 15:51:35 +0000 Received: from localhost ([127.0.0.1]:59377 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO2NT-00055o-7d for submit@debbugs.gnu.org; Tue, 07 May 2019 11:51:35 -0400 Received: from relay1-d.mail.gandi.net ([217.70.183.193]:49337) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hO2NQ-00055d-91 for 34807-done@debbugs.gnu.org; Tue, 07 May 2019 11:51:33 -0400 X-Originating-IP: 92.169.116.19 Received: from bababa (lfbn-1-4117-19.w92-169.abo.wanadoo.fr [92.169.116.19]) (Authenticated sender: pierre@atlas.engineer) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 99C8724000F; Tue, 7 May 2019 15:51:29 +0000 (UTC) From: Pierre Neidhardt To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#34807] [PATCH 1/2] Add (guix lzlib). In-Reply-To: <87lfzi46cv.fsf@gnu.org> References: <20190310180209.11578-1-mail@ambrevar.xyz> <8736ne3855.fsf@gnu.org> <87pnp2f7gr.fsf@ambrevar.xyz> <8736lxdxn6.fsf@ambrevar.xyz> <87lfzm7fdz.fsf@gnu.org> <878svm5xic.fsf@ambrevar.xyz> <87ef5e0vvv.fsf@gnu.org> <87o94h527a.fsf@ambrevar.xyz> <87a7fzffip.fsf@gnu.org> <87v9ynf9iu.fsf@nckx> <87d0ku21da.fsf@ambrevar.xyz> <87lfzi46cv.fsf@gnu.org> Date: Tue, 07 May 2019 17:51:28 +0200 Message-ID: <875zqmz2in.fsf@ambrevar.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 34807-done Cc: 34807-done@debbugs.gnu.org, Tobias Geerinckx-Rice 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.7 (-) --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable OK, feel free to open the corresponding issues and forward me the messages, I'll see what I can do. =2D-=20 Pierre Neidhardt https://ambrevar.xyz/ --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEUPM+LlsMPZAEJKvom9z0l6S7zH8FAlzRqYAACgkQm9z0l6S7 zH9eXAf/V+YARTZ3Cuqgo+yL9klqbaQIb5cjqjo4+MwqNpoNZWDz0k4r6mWV0j0u zUDFd2LV4nM3W/PlWVOaqjFUYdWG5QQ09YCDFId56SqdkrmijmkpoScbox4+WYI+ l/014PHrXoc0Ps2L4jdUtghRQw6ATw6Wzt/dSv5Vlb8TUN4eNaUWR+GD3xXqh0O1 HhEvo7hRbYsufz4Noc/wUcIabzQDNarA1o84BgYgdLmRd/o4A89/L/iimQx+F0sn 2B2019ybZE8QkqsQkzlxBAQo26CpJP9AnSHolXCQ/IZU8LKD1uDvnpHQSYFsrJsp JYjqi5gitRivwAjX9k80xCe6H4KaEA== =GZlO -----END PGP SIGNATURE----- --=-=-=-- From unknown Thu Jul 31 07:32:41 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 05 Jun 2019 11:24:04 +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