guix_mirror_bot pushed a commit to branch master
in repository guix.

commit cf81cfadbd22f70807df57b94afca4507aa71491
Author: Ludovic Courtès <[email protected]>
AuthorDate: Wed Jan 28 15:03:34 2026 +0100

    serialization: Do not require ‘bytevector-slice’.
    
    Commit 40c24a92af2ead4379ea0755304c00fd09c806bf make (guix serialization)
    reliant on ‘bytevector-slice’ from Guile 3.0.9.  However, when pulling from 
an
    old Guix, such as 1.4.0, which runs on 3.0.8, ‘bytevector-slice’ is
    unavailable.  This commit addresses that.
    
    * guix/serialization.scm (sub-bytevector): Reintroduce.
    (read-byte-string): Use it.
    
    Fixes: guix/guix#5978
    Reported-by: Zelphir Kaltstahl <[email protected]>
    Change-Id: I9d0b3b52cd1ec5346780fdb2306c352117cb33e8
    Signed-off-by: Ludovic Courtès <[email protected]>
    Merges: #5991
---
 guix/serialization.scm | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/guix/serialization.scm b/guix/serialization.scm
index 0be97e4ff2..c0f5ee5e86 100644
--- a/guix/serialization.scm
+++ b/guix/serialization.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012-2021, 2025 Ludovic Courtès <[email protected]>
+;;; Copyright © 2012-2021, 2025, 2026 Ludovic Courtès <[email protected]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -20,7 +20,6 @@
   #:autoload   (guix base16) (base16-string->bytevector
                               bytevector->base16-string)
   #:use-module (rnrs bytevectors)
-  #:autoload   (rnrs bytevectors gnu) (bytevector-slice)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9)
   #:use-module (srfi srfi-26)
@@ -30,6 +29,7 @@
   #:use-module ((ice-9 rdelim) #:prefix rdelim:)
   #:use-module (ice-9 match)
   #:use-module (ice-9 ftw)
+  #:autoload   (system foreign) (pointer->bytevector bytevector->pointer)
   #:export (write-value
             read-value
             write-bytevector
@@ -106,6 +106,28 @@
                          (port port)))))
     bv))
 
+(define sub-bytevector
+  ;; 'bytevector-slice' was added in Guile 3.0.9, but this code might be
+  ;; running on older versions of Guile when running 'guix pull' from 1.4.0
+  ;; for instance.
+  (match (and=> (false-if-exception
+              (resolve-interface '(rnrs bytevectors gnu)))
+             (lambda (module)
+               (module-ref module 'bytevector-slice)))
+    (#f
+     (lambda (bv len)
+       "Return a bytevector that aliases the first LEN bytes of BV."
+       (define max (bytevector-length bv))
+       (cond ((= len max) bv)
+             ((< len max)
+              ;; Yes, this is safe because the result of each conversion 
procedure
+              ;; has its life cycle synchronized with that of its argument.
+              (pointer->bytevector (bytevector->pointer bv) len))
+             (else
+              (error "sub-bytevector called to get a super bytevector")))))
+    (slice
+     (cut slice <> 0 <>))))
+
 (define (write-int n p)
   (let ((b (make-bytevector 8 0)))
     (bytevector-u32-set! b 0 n (endianness little))
@@ -153,7 +175,7 @@
          (m   (modulo len 8))
          (pad (if (zero? m) 0 (- 8 m)))
          (bv  (get-bytevector-n* p (+ len pad))))
-    (bytevector-slice bv 0 len)))
+    (sub-bytevector bv len)))
 
 (define (read-string p)
   (utf8->string (read-byte-string p)))

Reply via email to