From 64ab5edeb7412c897f089b7765bec5f24f981b47 Mon Sep 17 00:00:00 2001 From: Kevin Rosenberg Date: Tue, 20 Apr 2010 12:31:37 -0600 Subject: [PATCH] Version 2.0.0 for new API foreign encoding functions * uffi.asdf: Update version so libraries using UFFI can depend on verson 2.0 for new foreign encoding conversions. * src/i18n.lisp: Add null-terminate to STRING-TO-OCTETS * tests/i18n.lisp: Add new tests --- ChangeLog | 8 ++++++++ debian/changelog | 7 +++++++ debian/source/format | 1 + src/i18n.lisp | 35 ++++++++++++++++++++++++----------- tests/i18n.lisp | 16 ++++++++++++++-- uffi.asd | 2 +- 6 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 debian/source/format diff --git a/ChangeLog b/ChangeLog index 109b613..c138d54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-04-20 Kevin Rosenberg + * Version 2.0.0 + * uffi.asdf: Update version so libraries using UFFI + can depend on verson 2.0 for new foreign encoding + conversions. + * src/i18n.lisp: Add null-terminate to STRING-TO-OCTETS + * tests/i18n.lisp: Add new tests + 2010-02-11 Kevin Rosenberg * Version 1.8.6 * src/strings.lisp: Standards on :encoding keyword diff --git a/debian/changelog b/debian/changelog index d503c7e..6749dc3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +cl-uffi (2.0.0-1) unstable; urgency=low + + * Update upstream version for ASDF version dependency checking + * Switch to dpkg-source 3.0 (quilt) format + + -- Kevin M. Rosenberg Tue, 20 Apr 2010 12:11:34 -0600 + cl-uffi (1.8.6-1) unstable; urgency=low * New upstream diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/src/i18n.lisp b/src/i18n.lisp index ca2c1b4..2de8234 100644 --- a/src/i18n.lisp +++ b/src/i18n.lisp @@ -58,7 +58,7 @@ encoding.") (defun lookup-foreign-encoding (normalized) (cdr (assoc normalized *foreign-encoding-mapping* :test 'eql))) -(defmacro string-to-octets (str &key encoding) +(defmacro string-to-octets (str &key encoding null-terminate) (declare (ignorable encoding)) #-(or allegro lispworks openmcl sbcl) (map-into (make-array (length str) :element-type '(unsigned-byte 8)) @@ -67,31 +67,44 @@ encoding.") #+allegro (let ((fe (gensym "FE-")) (ife (gensym "IFE-")) - (s (gensym "STR-"))) + (s (gensym "STR-")) + (nt (gensym "NT-"))) `(let* ((,fe (or ,encoding *default-foreign-encoding*)) (,ife (when ,fe (lookup-foreign-encoding ,fe))) - (,s ,str)) + (,s ,str) + (,nt ,null-terminate)) (values (if ,ife - (excl:string-to-octets ,s :external-format ,ife :null-terminate nil) - (excl:string-to-octets ,s :null-terminate nil))))) + (excl:string-to-octets ,s :external-format ,ife :null-terminate ,nt) + (excl:string-to-octets ,s :null-terminate ,nt))))) #+(or lispworks openmcl) ;; simply reading each char-code from the LENGTH of string handles multibyte characters ;; just fine in testing LW 6.0 and CCL 1.4 - (map-into (make-array (length str) :element-type '(unsigned-byte 8)) - #'char-code str) + (let ((len (gensym "LEN-")) + (out (gensym "OUT-"))) + `(let ((,len (length ,str))) + (if (,null-terminate) + (progn + (let ((,out (map-into (make-array (1+ ,len) :element-type '(unsigned-byte 8)) + #'char-code ,str))) + (setf (char ,out ,len) 0) + ,out)) + (map-into (make-array len :element-type '(unsigned-byte 8)) + #'char-code str)))) #+sbcl (let ((fe (gensym "FE-")) (ife (gensym "IFE-")) - (s (gensym "STR-"))) + (s (gensym "STR-")) + (nt (gensym "NT-"))) `(let* ((,fe (or ,encoding *default-foreign-encoding*)) (,ife (when ,fe (lookup-foreign-encoding ,fe))) - (,s ,str)) + (,s ,str) + (,nt ,null-terminate)) (if ,ife - (sb-ext:string-to-octets ,s :external-format ,ife) - (sb-ext:string-to-octets ,s)))) + (sb-ext:string-to-octets ,s :external-format ,ife :null-terminate ,nt) + (sb-ext:string-to-octets ,s :null-terminate ,nt)))) ) diff --git a/tests/i18n.lisp b/tests/i18n.lisp index 911e41f..af99be9 100644 --- a/tests/i18n.lisp +++ b/tests/i18n.lisp @@ -25,15 +25,27 @@ (uffi:string-to-octets "abc") #(97 98 99)) -;; Below is UTF-8 encoded, 27 octets / 20 lisp characters (deftest :i18n/sto/4 + (uffi:string-to-octets "abc" :null-terminate t) + #(97 98 99 0)) + +;; Below is UTF-8 encoded, 27 octets / 20 lisp characters +(deftest :i18n/sto/5 (uffi:string-to-octets "Iñtërnâtiônàlizætiøn" :encoding :utf-8) #(73 195 177 116 195 171 114 110 195 162 116 105 195 180 110 195 160 108 105 122 195 166 116 105 195 184 110)) -(deftest :i18n/sto/5 +(deftest :i18n/sto/6 + (uffi:string-to-octets "Iñtërnâtiônàlizætiøn" :encoding :utf-8 :null-terminate t) + #(73 195 177 116 195 171 114 110 195 162 116 105 195 180 110 195 160 108 105 122 195 166 116 105 195 184 110 0)) + +(deftest :i18n/lsto/1 (length (uffi:string-to-octets "Iñtërnâtiônàlizætiøn" :encoding :utf-8)) 27) +(deftest :i18n/lsto/2 + (length (uffi:string-to-octets "Iñtërnâtiônàlizætiøn" :encoding :utf-8 :null-terminate t)) + 28) + (deftest :i18n/feoc/1 (uffi:foreign-encoded-octet-count "") 0) diff --git a/uffi.asd b/uffi.asd index d5bf7f7..5eea1a8 100644 --- a/uffi.asd +++ b/uffi.asd @@ -18,7 +18,7 @@ (defsystem uffi :name "uffi" :author "Kevin Rosenberg " - :version "1.7.2" + :version "2.0.0" :maintainer "Kevin M. Rosenberg " :licence "Lessor Lisp General Public License" :description "Universal Foreign Function Library for Common Lisp" -- 2.34.1