1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: UFFI source to handle objects and pointers
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
10 ;;;; Copyright (c) 2002 Kevin M. Rosenberg
12 ;;;; $Id: objects.cl,v 1.3 2002/03/10 11:13:07 kevin Exp $
14 ;;;; This file is part of the UFFI.
16 ;;;; UFFI is free software; you can redistribute it and/or modify
17 ;;;; it under the terms of the GNU General Public License (version 2) as
18 ;;;; published by the Free Software Foundation.
20 ;;;; UFFI is distributed in the hope that it will be useful,
21 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;;;; GNU General Public License for more details.
25 ;;;; You should have received a copy of the GNU General Public License
26 ;;;; along with UFFI; if not, write to the Free Software
27 ;;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 ;;;; *************************************************************************
30 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
33 (defmacro allocate-foreign-object (type)
35 `(alien:make-alien ,(convert-from-uffi-type type :allocation))
37 `(fli:allocate-foreign-object :type ',(convert-from-uffi-type type :allocate))
39 `(ff:allocate-fobject ',(convert-from-uffi-type type :allocate) :c)
42 (defmacro free-foreign-object (obj)
44 `(alien:free-alien ,obj)
46 `(fli:free-foreign-object ,obj)
48 `(ff:free-fobject ,obj)
51 (defmacro null-pointer-p (obj)
52 #+lispworks `(fli:null-pointer-p ,obj)
53 #+allegro `(zerop ,obj)
54 #+cmu `(alien:null-alien ,obj)
58 (defmacro make-null-pointer (type)
59 #+(or allegro cmu) (declare (ignore type))
61 #+cmu `(system:int-sap 0)
63 #+lispworks `(fli:make-pointer :address 0 :type ',type)
66 (defmacro deref-pointer (ptr type)
67 "Returns a object pointed"
68 #+(or lispworks cmu) (declare (ignore type))
69 #+cmu `(alien:deref ,ptr)
70 #+lispworks `(fli:dereference ,ptr)
71 #+allegro `(ff:fslot-value-typed ,type :c ,ptr)
74 (defmacro pointer-address (obj)
76 `(system:sap-int (alien:alien-sap ,obj))
78 `(fli:pointer-address ,obj)