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

Diff of /package.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by rklochkov, Mon Feb 20 18:55:20 2012 UTC revision 18 by rklochkov, Sat Jan 12 21:26:46 2013 UTC
# Line 1  Line 1 
1  ;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-  ;;;;<title> CFFI-Objects</title>
2  ;;;  ;;;;<author>Roman Klochkov, monk@slavsoft.surgut.ru</author>
3  ;;; package.lisp --- Package definition for cffi-object  ;;;;<date>2012</date>
4  ;;;  
5  ;;; Copyright (C) 2007, Roman Klochkov <monk@slavsoft.surgut.ru>  ;;;; Package definition for cffi-objects,
6  ;;;  ;;;; that is a CFFI add-on, supporting GLib/GObject/GDK/GTK and similar objects
7  ;;; This library is a CFFI add-on, that support  
8  ;;;    GLib/GObject/GDK/GTK and similar objects  ;;;<insert name="introduction"/>
9    
10    ;;;[ [[* Package definition *]]
11    
12  (in-package #:cl-user)  (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)  (eval-when (:compile-toplevel :load-toplevel)
21    (let ((p (find-package "CFFI-OBJECTS")))    (let ((p (find-package "CFFI-OBJECTS")))
22      (when p      (when p
# Line 16  Line 24 
24          (unexport (list v) p)))))          (unexport (list v) p)))))
25    
26  (defpackage #:cffi-objects  (defpackage #:cffi-objects
27    (:use #:common-lisp #:cffi)    (:use #:common-lisp #:cffi #+message-oo #:message-oo)
28    (:export    (: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     #:gconstructor
45    
46     #:object     #:object
47       #:free-after
48     #:find-object     #:find-object
49     #:object-by-id     #:object-by-id
50       #:initialize
51     #:*objects*     #:*objects*
52     #:*objects-ids*     #:*objects-ids*
53     #:object-class     #:object-class
# Line 32  Line 57 
57     ;; methods     ;; methods
58     #:free     #:free
59    
   
60     #:*array-length*     #:*array-length*
61     ;; types     ;; types
62     #:pstring     #:pstring
# Line 44  Line 68 
68     #:null-array     #:null-array
69     #:string-array     #:string-array
70    
71       #:cffi-keyword
72       #:cffi-pathname
73       #:cffi-string
74    
75     #:struct     #:struct
76  ;   #:cffi-struct     #:cffi-struct
77     #:new-struct     #:new-struct
78     #:free-struct     #:free-struct
79    
    #:freeable  
    #:freeable-base  
    #:free-sent-if-needed  
    #:free-returned-if-needed  
    #:free-ptr  
    #:freeable-out  
    #:copy-from-foreign  
   
80     #:defcstruct-accessors     #:defcstruct-accessors
81     #:defcstruct*     #:defcstruct*
82     #:defbitaccessors     #:defbitaccessors
83    
84       ;; not for objects, but useful with cffi
85     #:with-foreign-out     #:with-foreign-out
86     #:with-foreign-outs     #:with-foreign-outs
87     #:with-foreign-outs-list     #:with-foreign-outs-list
88    
89       ;; for creating object models on top of C objects
90     #:pair     #:pair
91     #:setf-init     #:setf-init
92     #:init-slots     #:init-slots
# Line 72  Line 94 
94     #:remove-setter     #:remove-setter
95     #:clear-setters))     #:clear-setters))
96    
97    ;;;<doc> Now simply reexport all CFFI symbols.
98  (eval-when (:compile-toplevel :load-toplevel)  (eval-when (:compile-toplevel :load-toplevel)
99    (let ((cffi (find-package "CFFI"))    (let ((cffi (find-package "CFFI"))
100          (cffi-objects (find-package "CFFI-OBJECTS")))          (cffi-objects (find-package "CFFI-OBJECTS")))
101      (do-external-symbols (v cffi)      (do-external-symbols (v cffi)
       (export (list v) cffi-objects))))  
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    

Legend:
Removed from v.2  
changed lines
  Added in v.18

  ViewVC Help
Powered by ViewVC 1.1.5