- 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
;;;;
;;;; 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.
;;;;
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)
;;;;
;;;; 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.
;;;;
((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_")))
;;;;
;;;; 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.
;;;;
(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)
;;;;
;;;; 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.
;;;;
'((* . :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))
;;;;
;;;; 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.
;;;;
#+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
#+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
)
-(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)
)
;;;;
;;;; 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.
;;;;
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)
;;;;
;;;; 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.
;;;;
((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_")))
;;;;
;;;; 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.
;;;;
(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)