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

Diff of /package.lisp

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

revision 12 by rklochkov, Sun Aug 12 17:36:30 2012 UTC revision 13 by rklochkov, Sat Dec 22 19:24:45 2012 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 18  Line 26 
26  (defpackage #:cffi-objects  (defpackage #:cffi-objects
27    (:use #:common-lisp #:cffi)    (:use #:common-lisp #:cffi)
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
# Line 55  Line 78 
78     #:new-struct     #:new-struct
79     #:free-struct     #:free-struct
80    
    #:freeable  
    #:freeable-base  
    #:free-sent-if-needed  
    #:free-returned-if-needed  
    #:free-ptr  
    #:freeable-out  
    #:copy-from-foreign  
    #:free-from-foreign  
    #:free-to-foreign  
81    
82     #:defcstruct-accessors     #:defcstruct-accessors
83     #:defcstruct*     #:defcstruct*
# Line 80  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    |#
140    ;;; </define>
141    
142    
143    

Legend:
Removed from v.12  
changed lines
  Added in v.13

  ViewVC Help
Powered by ViewVC 1.1.5