From: Kevin M. Rosenberg Date: Mon, 9 Dec 2002 16:30:20 +0000 (+0000) Subject: r3593: *** empty log message *** X-Git-Tag: v1.6.1~246 X-Git-Url: http://git.kpe.io/?a=commitdiff_plain;ds=sidebyside;h=276c8f34b3070db313908a6d49a1ada16923fc21;p=uffi.git r3593: *** empty log message *** --- diff --git a/debian/changelog b/debian/changelog index b8f46d3..1df933a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +cl-uffi (1.2.1-1) unstable; urgency=low + + * Add uncompression test + + -- Kevin M. Rosenberg Mon, 9 Dec 2002 09:05:52 -0700 + cl-uffi (1.2.0-1) unstable; urgency=low * Fixes in allocate-foreign-object and deref-array for allegro diff --git a/doc/html.tar.gz b/doc/html.tar.gz index 31797e6..e45c514 100644 Binary files a/doc/html.tar.gz and b/doc/html.tar.gz differ diff --git a/doc/uffi.pdf b/doc/uffi.pdf index 7caca46..2c121f7 100644 Binary files a/doc/uffi.pdf and b/doc/uffi.pdf differ diff --git a/examples/compress.lisp b/examples/compress.lisp index e5140ae..1229be5 100644 --- a/examples/compress.lisp +++ b/examples/compress.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Feb 2002 ;;;; -;;;; $Id: compress.lisp,v 1.2 2002/12/03 06:58:39 kevin Exp $ +;;;; $Id: compress.lisp,v 1.3 2002/12/09 16:30:20 kevin Exp $ ;;;; ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -63,6 +63,33 @@ (uffi:free-foreign-object destlen) (uffi:free-foreign-object dest))))))) +(uffi:def-function ("uncompress" c-uncompress) + ((dest (* :unsigned-char)) + (destlen (* :long)) + (source :cstring) + (source-len :long)) + :returning :int + :module "zlib") + +(defun uncompress (source) + (let* ((sourcelen (length source)) + (destsize 200000) ;adjust as needed + (dest (uffi:allocate-foreign-string destsize :unsigned t)) + (destlen (uffi:allocate-foreign-object :long))) + (setf (uffi:deref-pointer destlen :long) destsize) + (uffi:with-cstring (source-native source) + (let ((result (c-uncompress dest destlen source-native sourcelen)) + (newdestlen (uffi:deref-pointer destlen :long))) + (unwind-protect + (if (zerop result) + (uffi:convert-from-foreign-string + dest + :length newdestlen + :null-terminated-p nil) + (error "zlib error, code ~D" result)) + (progn + (uffi:free-foreign-object destlen) + (uffi:free-foreign-object dest))))))) #+examples-uffi (progn @@ -76,6 +103,17 @@ (print-results "test") (print-results "test2"))) +#+test-uffi +(progn + (flet ((test-compress (str) + (multiple-value-bind (compressed len) (compress str) + (multiple-value-bind (uncompressed len2) (uncompress compressed) + (util.test:test str uncompressed :test #'string= + :fail-info "Error uncompressing a compressed string"))))) + (test-compress "") + (test-compress "test") + (test-compress "test2"))) + ;; Results of the above on my system: ;; (compress "") => 789c300001,8 ;; (compress "test") => 789c2b492d2e1045d1c1,12 diff --git a/examples/union.lisp b/examples/union.lisp index 5b22be2..2e186d8 100644 --- a/examples/union.lisp +++ b/examples/union.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Mar 2002 ;;;; -;;;; $Id: union.lisp,v 1.2 2002/12/03 06:58:39 kevin Exp $ +;;;; $Id: union.lisp,v 1.3 2002/12/09 16:30:20 kevin Exp $ ;;;; ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -29,7 +29,7 @@ (let ((u (uffi:allocate-foreign-object 'tunion1))) (setf (uffi:get-slot-value u 'tunion1 'uint) ;; little endian - #-(or sparc sparc-v9 powerpc ppc little-endian) + #-(or sparc sparc-v9 powerpc ppc big-endian) (+ (* 1 (char-code #\A)) (* 256 (char-code #\B)) (* 65536 (char-code #\C)) diff --git a/tests/compress.lisp b/tests/compress.lisp index e5140ae..1229be5 100644 --- a/tests/compress.lisp +++ b/tests/compress.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Feb 2002 ;;;; -;;;; $Id: compress.lisp,v 1.2 2002/12/03 06:58:39 kevin Exp $ +;;;; $Id: compress.lisp,v 1.3 2002/12/09 16:30:20 kevin Exp $ ;;;; ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -63,6 +63,33 @@ (uffi:free-foreign-object destlen) (uffi:free-foreign-object dest))))))) +(uffi:def-function ("uncompress" c-uncompress) + ((dest (* :unsigned-char)) + (destlen (* :long)) + (source :cstring) + (source-len :long)) + :returning :int + :module "zlib") + +(defun uncompress (source) + (let* ((sourcelen (length source)) + (destsize 200000) ;adjust as needed + (dest (uffi:allocate-foreign-string destsize :unsigned t)) + (destlen (uffi:allocate-foreign-object :long))) + (setf (uffi:deref-pointer destlen :long) destsize) + (uffi:with-cstring (source-native source) + (let ((result (c-uncompress dest destlen source-native sourcelen)) + (newdestlen (uffi:deref-pointer destlen :long))) + (unwind-protect + (if (zerop result) + (uffi:convert-from-foreign-string + dest + :length newdestlen + :null-terminated-p nil) + (error "zlib error, code ~D" result)) + (progn + (uffi:free-foreign-object destlen) + (uffi:free-foreign-object dest))))))) #+examples-uffi (progn @@ -76,6 +103,17 @@ (print-results "test") (print-results "test2"))) +#+test-uffi +(progn + (flet ((test-compress (str) + (multiple-value-bind (compressed len) (compress str) + (multiple-value-bind (uncompressed len2) (uncompress compressed) + (util.test:test str uncompressed :test #'string= + :fail-info "Error uncompressing a compressed string"))))) + (test-compress "") + (test-compress "test") + (test-compress "test2"))) + ;; Results of the above on my system: ;; (compress "") => 789c300001,8 ;; (compress "test") => 789c2b492d2e1045d1c1,12 diff --git a/tests/union.lisp b/tests/union.lisp index 5b22be2..2e186d8 100644 --- a/tests/union.lisp +++ b/tests/union.lisp @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Mar 2002 ;;;; -;;;; $Id: union.lisp,v 1.2 2002/12/03 06:58:39 kevin Exp $ +;;;; $Id: union.lisp,v 1.3 2002/12/09 16:30:20 kevin Exp $ ;;;; ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; @@ -29,7 +29,7 @@ (let ((u (uffi:allocate-foreign-object 'tunion1))) (setf (uffi:get-slot-value u 'tunion1 'uint) ;; little endian - #-(or sparc sparc-v9 powerpc ppc little-endian) + #-(or sparc sparc-v9 powerpc ppc big-endian) (+ (* 1 (char-code #\A)) (* 256 (char-code #\B)) (* 65536 (char-code #\C))