From: Kevin M. Rosenberg Date: Sun, 10 Mar 2002 05:13:09 +0000 (+0000) Subject: r1526: *** empty log message *** X-Git-Tag: v1.6.1~622 X-Git-Url: http://git.kpe.io/?a=commitdiff_plain;ds=sidebyside;h=a6a97b850359b8b6bfce65ee9a8ee78552e4907e;p=uffi.git r1526: *** empty log message *** --- diff --git a/ChangeLog b/ChangeLog index 1000077..0be07ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,7 +3,9 @@ - Fixed bug in def-function for Lispworks - Fixed error in +null-c-string-pointer+ name - Fixed error in (make-null-pointer) for Lispworks - - Fixed error in strtol example + - Reworked Lispwork c-strings to be (* :char) rather than + the implementation default of (* (:unsigned :char)) to be + consistent with CMUCL 8 Mar 2002 - Added ZIP file output with LF->CRLF translations to distribution diff --git a/doc/uffi.pdf b/doc/uffi.pdf index f100f70..7236b52 100644 Binary files a/doc/uffi.pdf and b/doc/uffi.pdf differ diff --git a/examples/compress.cl b/examples/compress.cl index 1ef513d..640ce26 100644 --- a/examples/compress.cl +++ b/examples/compress.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: compress.cl,v 1.3 2002/03/10 04:15:33 kevin Exp $ +;;;; $Id: compress.cl,v 1.4 2002/03/10 05:09:00 kevin Exp $ ;;;; ;;;; This file is part of UFFI. ;;;; @@ -45,7 +45,7 @@ and the numbe of compressed bytes" (let* ((sourcelen (length source)) (destsize (+ 12 (ceiling (* sourcelen 1.01)))) - (dest (uffi:allocate-foreign-string destsize)) + (dest (uffi:allocate-foreign-string destsize :unsigned t)) (destlen (uffi:allocate-foreign-object :long))) (setf (uffi:deref-pointer destlen :long) destsize) (uffi:with-c-string (source-native source) diff --git a/examples/getenv.cl b/examples/getenv.cl index 347a22f..2f83426 100644 --- a/examples/getenv.cl +++ b/examples/getenv.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: getenv.cl,v 1.3 2002/03/10 04:15:33 kevin Exp $ +;;;; $Id: getenv.cl,v 1.4 2002/03/10 05:13:09 kevin Exp $ ;;;; ;;;; This file is part of UFFI. ;;;; @@ -34,20 +34,17 @@ ((name :c-string)) :returning :c-string) -(defun getenv (key) +(defun my-getenv (key) "Returns an environment variable, or NIL if it does not exist" (check-type key string) (uffi:with-c-string (key-native key) (let ((value-c-string (c-getenv key-native))) (uffi:convert-from-c-string value-c-string)))) -(format t "~&Environment value for USER key: ~A" (getenv "USER")) -(format t "~&Environment value for _FOO_ key: ~A" (getenv "_FOO_")) - #+test-uffi (progn (flet ((print-results (str) - (format t "~&(getenv ~S) => ~S" str (getenv str)))) + (format t "~&(getenv ~S) => ~S" str (my-getenv str)))) (print-results "USER") (print-results "_FOO_"))) diff --git a/examples/strtol.cl b/examples/strtol.cl index 387d23b..9813160 100644 --- a/examples/strtol.cl +++ b/examples/strtol.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: strtol.cl,v 1.4 2002/03/10 04:36:04 kevin Exp $ +;;;; $Id: strtol.cl,v 1.5 2002/03/10 05:09:00 kevin Exp $ ;;;; ;;;; This file is part of UFFI. ;;;; @@ -29,14 +29,14 @@ (in-package :cl-user) -(uffi:def-type char-ptr (* :unsigned-char)) +(uffi:def-type char-ptr (* :char)) ;; This example does not use :c-string to pass the input string since ;; the routine needs to do pointer arithmetic to see how many characters ;; were parsed (uffi:def-function ("strtol" c-strtol) - ((nptr (* :unsigned-char)) + ((nptr (* :char)) (endptr (* char-ptr)) (base :int)) :returning :long) diff --git a/src/immediates.cl b/src/immediates.cl index b22a47b..62e216f 100644 --- a/src/immediates.cl +++ b/src/immediates.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: immediates.cl,v 1.1 2002/03/09 19:55:33 kevin Exp $ +;;;; $Id: immediates.cl,v 1.2 2002/03/10 05:09:00 kevin Exp $ ;;;; ;;;; This file is part of the UFFI. ;;;; @@ -111,7 +111,7 @@ supports this." '((* . :pointer) (:void . :void) (:short . :short) (:pointer-void . (:pointer :void)) - (:c-string . (:pointer (:unsigned :char))) + (:c-string . (:pointer :char)) (:char . :char) (:unsigned-char . (:unsigned :char)) (:int . :int) (:unsigned-int . (:unsigned :int)) (:long . :long) (:unsigned-long . (:unsigned :long)) diff --git a/src/strings.cl b/src/strings.cl index 0cbf721..0e1e20d 100644 --- a/src/strings.cl +++ b/src/strings.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: strings.cl,v 1.2 2002/03/10 00:11:47 kevin Exp $ +;;;; $Id: strings.cl,v 1.3 2002/03/10 05:09:00 kevin Exp $ ;;;; ;;;; This file is part of the UFFI. ;;;; @@ -53,7 +53,9 @@ that CMU automatically converts strings from c-calls." #+lispworks `(if (null ,obj) +null-c-string-pointer+ - (fli:convert-to-foreign-string ,obj)) + (fli:make-pointer + :address (fli:pointer-address (fli:convert-to-foreign-string ,obj)) + :type :char)) #+allegro `(if (null ,obj) 0 @@ -102,7 +104,9 @@ that CMU automatically converts strings from c-calls." #+lispworks `(if (null ,obj) +null-c-string-pointer+ - (fli:convert-to-foreign-string ,obj)) + (fli:make-pointer + :address (fli:pointer-address (fli:convert-to-foreign-string ,obj)) + :type :char)) #+allegro `(if (null ,obj) 0 @@ -124,13 +128,22 @@ that CMU automatically converts strings from c-calls." ) -(defmacro allocate-foreign-string (size) +(defmacro allocate-foreign-string (size &key (unsigned nil)) #+cmu (let ((array-def (gensym))) `(let ((,array-def (list 'alien:array 'c-call:char ,size))) - (eval `(alien:cast (alien:make-alien ,,array-def) (* (alien:unsigned 8)))))) + (eval `(alien:cast (alien:make-alien ,,array-def) + ,(if ,unsigned + '(* (alien:unsigned 8)) + '(* (alien:signed 8))))))) #+lispworks - `(fli:allocate-foreign-object :type '(:unsigned :char) :nelems ,size) + `(fli:allocate-foreign-object :type + ,(if unsigned + ''(:unsigned :char) + :char) + :nelems ,size) + #+allegro + (declare (ignore unsigned)) #+allegro `(ff:allocate-fobject :char :c ,size) ) diff --git a/tests/compress.cl b/tests/compress.cl index 1ef513d..640ce26 100644 --- a/tests/compress.cl +++ b/tests/compress.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: compress.cl,v 1.3 2002/03/10 04:15:33 kevin Exp $ +;;;; $Id: compress.cl,v 1.4 2002/03/10 05:09:00 kevin Exp $ ;;;; ;;;; This file is part of UFFI. ;;;; @@ -45,7 +45,7 @@ and the numbe of compressed bytes" (let* ((sourcelen (length source)) (destsize (+ 12 (ceiling (* sourcelen 1.01)))) - (dest (uffi:allocate-foreign-string destsize)) + (dest (uffi:allocate-foreign-string destsize :unsigned t)) (destlen (uffi:allocate-foreign-object :long))) (setf (uffi:deref-pointer destlen :long) destsize) (uffi:with-c-string (source-native source) diff --git a/tests/getenv.cl b/tests/getenv.cl index 347a22f..2f83426 100644 --- a/tests/getenv.cl +++ b/tests/getenv.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: getenv.cl,v 1.3 2002/03/10 04:15:33 kevin Exp $ +;;;; $Id: getenv.cl,v 1.4 2002/03/10 05:13:09 kevin Exp $ ;;;; ;;;; This file is part of UFFI. ;;;; @@ -34,20 +34,17 @@ ((name :c-string)) :returning :c-string) -(defun getenv (key) +(defun my-getenv (key) "Returns an environment variable, or NIL if it does not exist" (check-type key string) (uffi:with-c-string (key-native key) (let ((value-c-string (c-getenv key-native))) (uffi:convert-from-c-string value-c-string)))) -(format t "~&Environment value for USER key: ~A" (getenv "USER")) -(format t "~&Environment value for _FOO_ key: ~A" (getenv "_FOO_")) - #+test-uffi (progn (flet ((print-results (str) - (format t "~&(getenv ~S) => ~S" str (getenv str)))) + (format t "~&(getenv ~S) => ~S" str (my-getenv str)))) (print-results "USER") (print-results "_FOO_"))) diff --git a/tests/strtol.cl b/tests/strtol.cl index 387d23b..9813160 100644 --- a/tests/strtol.cl +++ b/tests/strtol.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: strtol.cl,v 1.4 2002/03/10 04:36:04 kevin Exp $ +;;;; $Id: strtol.cl,v 1.5 2002/03/10 05:09:00 kevin Exp $ ;;;; ;;;; This file is part of UFFI. ;;;; @@ -29,14 +29,14 @@ (in-package :cl-user) -(uffi:def-type char-ptr (* :unsigned-char)) +(uffi:def-type char-ptr (* :char)) ;; This example does not use :c-string to pass the input string since ;; the routine needs to do pointer arithmetic to see how many characters ;; were parsed (uffi:def-function ("strtol" c-strtol) - ((nptr (* :unsigned-char)) + ((nptr (* :char)) (endptr (* char-ptr)) (base :int)) :returning :long)