;;;; Programmer: Kevin M. Rosenberg
;;;; Date Started: Feb 2002
;;;;
-;;;; $Id: objects.cl,v 1.24 2002/09/30 07:51:01 kevin Exp $
+;;;; $Id: objects.cl,v 1.25 2002/09/30 08:50:00 kevin Exp $
;;;;
;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
;;;;
(declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
(in-package :uffi)
+(defun size-of-foreign-type (type)
+ #+lispworks (fli:size-of type)
+ #+allegro (ff:sizeof-fobject type)
+ #+cmu (alien:alien-size type)
+ #+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."
#+mcl `(ccl:%null-ptr-p ,obj)
)
-(defmacro size-of-foreign-type (type)
- #+lispworks `(fli:size-of ,type)
- #+allegro `(ff:sizeof-fobject ,type)
- #+cmu `(alien:alien-size ,type)
- #+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
- #+opencml `(ccl::%foreign-type-or-record-size ,type :bytes)
- )
-
-
(defmacro make-null-pointer (type)
#+(or allegro cmu mcl) (declare (ignore type))
,@body)
)
-#+mcl
-(defmacro with-foreign-object ((var type) &rest body)
- `(with-foreign-objects ((,var ,type))
- ,@body))
-
#-mcl
(defmacro with-foreign-objects (bindings &rest body)
(if bindings
(push (list (first spec) (* count (size-of-foreign-type type))) params))
`(ccl:%stack-block ,params ,@body)))
+#+mcl
+(defmacro with-foreign-object ((var type) &rest body)
+ `(with-foreign-objects ((,var ,type))
+ ,@body))
+