r1555: *** empty log message ***
[uffi.git] / src / objects.cl
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          objects.cl
6 ;;;; Purpose:       UFFI source to handle objects and pointers
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Feb 2002
9 ;;;;
10 ;;;; $Id: objects.cl,v 1.5 2002/03/14 21:03:12 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0)))
20 (in-package :uffi)
21
22 (defmacro allocate-foreign-object (type)
23   #+cmu
24   `(alien:make-alien ,(convert-from-uffi-type type :allocation))
25   #+lispworks
26   `(fli:allocate-foreign-object :type ',(convert-from-uffi-type type :allocate))
27   #+allegro
28   `(ff:allocate-fobject ',(convert-from-uffi-type type :allocate) :c)
29   )
30
31 (defmacro free-foreign-object (obj)
32   #+cmu
33   `(alien:free-alien ,obj)
34   #+lispworks
35   `(fli:free-foreign-object ,obj)
36   #+allegro
37   `(ff:free-fobject ,obj)
38   )
39
40 (defmacro null-pointer-p (obj)
41   #+lispworks `(fli:null-pointer-p ,obj)
42   #+allegro `(zerop ,obj)
43   #+cmu   `(alien:null-alien ,obj)
44   )
45
46
47 (defmacro make-null-pointer (type)
48   #+(or allegro cmu) (declare (ignore type))
49   
50   #+cmu `(system:int-sap 0)
51   #+allegro 0
52   #+lispworks `(fli:make-pointer :address 0 :type ,type)
53   )
54
55 (defmacro deref-pointer (ptr type)
56   "Returns a object pointed"
57   #+(or lispworks cmu) (declare (ignore type))
58   #+cmu  `(alien:deref ,ptr)
59   #+lispworks `(fli:dereference ,ptr)
60   #+allegro `(ff:fslot-value-typed ,type :c ,ptr)
61   )
62
63 (defmacro pointer-address (obj)
64   #+cmu
65   `(system:sap-int (alien:alien-sap ,obj))
66   #+lispworks
67   `(fli:pointer-address ,obj)
68   #+allegro
69   obj
70   )