X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fobjects.lisp;h=6c8a5b651c439e3e4be97a45eaf5d0bc989bff76;hb=9ca3cce60961b1fd140467a233700a08e7ef65b1;hp=1510d246ccb5a6a139bd6361dbd8e59ad1570afe;hpb=66f5a25945b334732c2420fbe73b389e89de1669;p=uffi.git diff --git a/src/objects.lisp b/src/objects.lisp index 1510d24..6c8a5b6 100644 --- a/src/objects.lisp +++ b/src/objects.lisp @@ -18,21 +18,21 @@ (in-package #:uffi) -(defun size-of-foreign-type (type) - #+lispworks (fli:size-of type) - #+allegro (ff:sizeof-fobject type) - #+(or cmu scl) (ash (eval `(alien:alien-size ,type)) -3) ;; convert from bits to bytes - #+sbcl (ash (eval `(sb-alien:alien-size ,type)) -3) ;; convert from bits to bytes - #+clisp (values (ffi:size-of type)) - #+(and mcl (not openmcl)) - (let ((mcl-type (ccl:find-mactype type nil t))) - (if mcl-type - (ccl::mactype-record-size mcl-type) - (ccl::record-descriptor-length (ccl:find-record-descriptor type t t)))) ;error if not a record - #+openmcl (ccl::%foreign-type-or-record-size type :bytes) - ) - - +(eval-when (:compile-toplevel :load-toplevel :execute) + (defun size-of-foreign-type (type) + #+lispworks (fli:size-of type) + #+allegro (ff:sizeof-fobject type) + #+(or cmu scl) (ash (eval `(alien:alien-size ,type)) -3) ;; convert from bits to bytes + #+sbcl (ash (eval `(sb-alien:alien-size ,type)) -3) ;; convert from bits to bytes + #+clisp (values (ffi:size-of type)) + #+(and mcl (not openmcl)) + (let ((mcl-type (ccl:find-mactype type nil t))) + (if mcl-type + (ccl::mactype-record-size mcl-type) + (ccl::record-descriptor-length (ccl:find-record-descriptor type t t)))) ;error if not a record + #+openmcl (ccl::%foreign-type-or-record-size type :bytes) + )) + (defmacro allocate-foreign-object (type &optional (size :unspecified)) "Allocates an instance of TYPE. If size is specified, then allocate an array of TYPE with size SIZE. The TYPE parameter is evaluated." @@ -132,13 +132,14 @@ an array of TYPE with size SIZE. The TYPE parameter is evaluated." #+(or (and mcl (not openmcl))) obj #+(or allegro cmu sbcl scl openmcl) `(code-char ,obj) ;; lispworks varies whether deref'ing array vs. slot access of a char - #+lispworks - `(if (characterp ,obj) ,obj (code-char ,obj))) + #+lispworks `(if (characterp ,obj) ,obj (code-char ,obj))) (defmacro ensure-char-integer (obj) #+(or (and mcl (not openmcl))) `(char-code ,obj) #+(or allegro cmu sbcl scl openmcl) obj - `(if (characterp ,obj) (char-code ,obj) ,obj)) + ;; lispworks varies whether deref'ing array vs. slot access of a char + #+lispworks + `(if (integerp ,obj) ,obj (char-code ,obj))) (defmacro ensure-char-storable (obj) #+(or lispworks (and mcl (not openmcl))) obj