2 Commits 2e89f7f3a6 ... a70ff61063

Author SHA1 Message Date
  Ludovic Courtès a70ff61063 'uncompress' and 'compress' throw to 'zlib-error. 3 years ago
  Ludovic Courtès 4da4ecd1ce Fix 'uncompress' and 'compress' on 32-bit platforms. 3 years ago
1 changed files with 9 additions and 6 deletions
  1. 9 6
      zlib.scm

+ 9 - 6
zlib.scm

@@ -353,7 +353,8 @@ require PORT to be a file port."
 ;; the returned data to. This procedure saves me a few keystrokes when
 ;; fetching that value.
 (define (buffer-length bv)
-  (bytevector-u64-native-ref bv 0))
+  (bytevector-uint-ref bv 0
+                       (native-endianness) (sizeof unsigned-long)))
 
 (define (uncompress bv)
   "Uncompresses bytevector and returns a bytevector containing
@@ -361,7 +362,8 @@ the uncompressed data."
   (define (try-uncompress length)
     (let* ((dest (make-bytevector (* (sizeof uint8) length)))
            (dest-length (make-bytevector (sizeof unsigned-long))))
-      (bytevector-u64-native-set! dest-length 0 length)
+      (bytevector-uint-set! dest-length 0 length
+                            (native-endianness) (sizeof unsigned-long))
       (values (%uncompress (bytevector->pointer dest)
                    (bytevector->pointer dest-length)
                    (bytevector->pointer bv)
@@ -380,7 +382,7 @@ the uncompressed data."
     ;; I don't like the idea of a potentially unbounded loop that
     ;; keeps allocating larger and larger chunks of memory.
     (if (> tries 10)
-        (throw 'zlib-uncompress-error)
+        (throw 'zlib-error 'uncompress 0)
         (receive (ret-code uncompressed-data)
             (try-uncompress length)
           ;; return code -5 means that destination buffer was too small.
@@ -390,7 +392,7 @@ the uncompressed data."
                 ((= ret-code 0)
                  uncompressed-data)
                 (else
-                 (throw 'zlib-uncompress-error)))))))
+                 (throw 'zlib-error 'uncompress ret-code)))))))
 
 (define (compress bv)
   "Compresses bytevector and returns a bytevector containing the compressed data."
@@ -399,7 +401,8 @@ the uncompressed data."
          (dest-bv        (make-bytevector dest-length))
          (dest-length-bv (make-bytevector (sizeof unsigned-long)))
          (ret-code       0))
-    (bytevector-u64-native-set! dest-length-bv 0 dest-length)
+    (bytevector-uint-set! dest-length-bv 0 dest-length
+                          (native-endianness) (sizeof unsigned-long))
     (set! ret-code
           (%compress (bytevector->pointer dest-bv)
                      (bytevector->pointer dest-length-bv)
@@ -408,7 +411,7 @@ the uncompressed data."
     (if (= ret-code 0)
         (bytevector-copy-region dest-bv 0
                                 (buffer-length dest-length-bv))
-        (throw 'zlib-compress-error))))
+        (throw 'zlib-error 'compress ret-code))))
 
 (define %default-adler32 (%adler32 0 %null-pointer 0))
 (define %default-crc32   (%crc32   0 %null-pointer 0))