/[cffi-objects]/package.lisp
ViewVC logotype

Contents of /package.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18 - (show annotations)
Sat Jan 12 21:26:46 2013 UTC (15 months, 1 week ago) by rklochkov
File size: 3560 byte(s)
Added support for MESSAGE-OO and (lisp-name . c-name) syntax for structure fields
1 ;;;;<title> CFFI-Objects</title>
2 ;;;;<author>Roman Klochkov, monk@slavsoft.surgut.ru</author>
3 ;;;;<date>2012</date>
4
5 ;;;; Package definition for cffi-objects,
6 ;;;; that is a CFFI add-on, supporting GLib/GObject/GDK/GTK and similar objects
7
8 ;;;<insert name="introduction"/>
9
10 ;;;[ [[* Package definition *]]
11
12 (in-package #:cl-user)
13
14 #|<doc>
15 We unexport all symbols before [[defpackage]], because
16 CFFI-objects will be a drop-in replacemant for CFFI and I don't
17 want to export by hand all symbols exported by CFFI.
18 |#
19
20 (eval-when (:compile-toplevel :load-toplevel)
21 (let ((p (find-package "CFFI-OBJECTS")))
22 (when p
23 (do-external-symbols (v p)
24 (unexport (list v) p)))))
25
26 (defpackage #:cffi-objects
27 (:use #:common-lisp #:cffi #+message-oo #:message-oo)
28 (:export
29 #:freeable-base
30 ;; slots
31 #:free-from-foreign
32 #:free-to-foreign
33 ;; freeable-base API
34 #:free-sent-if-needed
35 #:free-returned-if-needed
36 #:free-ptr
37 #:free-sent-ptr
38 #:free-returned-ptr
39
40 #:freeable
41 #:freeable-out
42 #:copy-from-foreign
43
44 #:gconstructor
45
46 #:object
47 #:free-after
48 #:find-object
49 #:object-by-id
50 #:initialize
51 #:*objects*
52 #:*objects-ids*
53 #:object-class
54 #:volatile
55 ;; slots
56 #:pointer
57 ;; methods
58 #:free
59
60 #:*array-length*
61 ;; types
62 #:pstring
63 #:pfunction
64 #:cffi-object
65 #:cffi-array
66 #:cffi-null-array
67 #:carray
68 #:null-array
69 #:string-array
70
71 #:cffi-keyword
72 #:cffi-pathname
73 #:cffi-string
74
75 #:struct
76 #:cffi-struct
77 #:new-struct
78 #:free-struct
79
80 #:defcstruct-accessors
81 #:defcstruct*
82 #:defbitaccessors
83
84 ;; not for objects, but useful with cffi
85 #:with-foreign-out
86 #:with-foreign-outs
87 #:with-foreign-outs-list
88
89 ;; for creating object models on top of C objects
90 #:pair
91 #:setf-init
92 #:init-slots
93 #:save-setter
94 #:remove-setter
95 #:clear-setters))
96
97 ;;;<doc> Now simply reexport all CFFI symbols.
98 (eval-when (:compile-toplevel :load-toplevel)
99 (let ((cffi (find-package "CFFI"))
100 (cffi-objects (find-package "CFFI-OBJECTS")))
101 (do-external-symbols (v cffi)
102 (export (list v) cffi-objects))))
103
104 ;;; <define name="introduction">
105 #|<doc>
106 [[* Introduction *]]
107
108 This document describes CFFI-objects: library, that extends CFFI to support
109 structures, objects and reference parameters.
110
111 Other alternatives are Virgil and FSBV/cffi-libffi. Virgil tend to marshall all
112 data back and forth. There are no support for structures as pointers.
113 FSBV is obsoleted by cffi-libffi. Libffi I dislike, because it gives another
114 layer of indirection (so make it slower) without new features (no bit fields
115 in structures).
116
117 So I made my own library. It gives the opportunity for programmer to
118 say which structures should be return values and how to save every
119 particular structure -- as pointer or as a lisp value.
120
121 Example:
122 \begin{alltt}
123 (defcstruct* foo (bar :int) (baz :int))
124 (defvar foo-as-ptr (make-instance 'foo :new-struct t))
125 (defvar foo-as-value (make-instance 'foo))
126
127 (defcfun foo-maker (struct foo))
128 (defcfun proceed-foo :void (param (struct foo :out t)))
129 (defcfun print-foo :void (param (struct foo)))
130 \end{alltt}
131
132 Here you can use either [[foo-as-ptr]] or [[foo-as-value]] in all functions.
133 [[Foo-as-ptr]] is faster, because it shouldn't convert values from Lisp to C
134 and back, but if foreign pointer is not considered stable (may be freed
135 by another c-function) or you don't want to control, when you need
136 to free foreign pointer, you should use [[foo-as-value]].
137
138 \include{redefines}
139 \include{freeable}
140 |#
141 ;;; </define>
142
143
144

  ViewVC Help
Powered by ViewVC 1.1.5