Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /ffi.xmlf [f587e9] .. [9e7c20] Maximize Restore

  Switch to side-by-side view

--- a/ffi.xmlf
+++ b/ffi.xmlf
@@ -1,13 +1,9 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE book [
-<!ENTITY % eclent SYSTEM "ecl.ent">
-%eclent;
-]>
-<book xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en">
-<chapter xml:id="ext.ffi">
+<?xml version="1.0"?><!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+<book lang="en">
+<chapter id="ext.ffi">
  <title>Foreign Function Interface</title>
 
- <section xml:id="ext.ffi.what">
+ <section id="ext.ffi.what">
   <title>What is a FFI?</title>
 
   <para>A Foreign Function Interface, or &FFI; for short, is a means for a
@@ -23,7 +19,7 @@
    <varlistentry>
     <term>Foreign objects management</term>
     <listitem><para>This is the data that the foreign code will use. A &FFI;
-    needs to provide means to buid and manipulate foreign data, with automatic
+    needs to provide means to buid and manipulate foreign data, with atomatic
     conversions to and from lisp data types whenever possible, and it also has
     to deal with issues like garbage collection and
     finalization.</para></listitem>
@@ -54,7 +50,7 @@
   <emphasis>all</emphasis> sections.</para>
  </section>
 
- <section xml:id="ext.ffi.dffi">
+ <section id="ext.ffi.dffi">
   <title>Two kinds of FFI</title>
 
   <para>&ECL; allows for two different appraoches when building a &FFI;. Both
@@ -86,7 +82,7 @@
   </para>
 
   <para>
-  <figure float="1" xml:id="fig.ffi">
+  <figure float="1" id="fig.ffi">
    <title>FFI components</title>
    <mediaobject>
     <imageobject>
@@ -114,7 +110,7 @@
   DFFI by inspecting whether the symbol <symbol>:DFFI</symbol> is present in
   the list from variable <symbol>*FEATURES*</symbol>.</para>
 
-  <table xml:id="table.dffi">
+  <table id="table.dffi">
    <title>DFFI support</title>
    <tgroup cols="3">
     <thead>
@@ -145,7 +141,7 @@
   </table>
  </section>
 
- <section xml:id="ext.ffi.objects">
+ <section id="ext.ffi.objects">
   <title>Foreign objects</title>
 
   <para>While the foreign function invocation protocols differ strongly between
@@ -194,7 +190,7 @@
 </programlisting>
  </section>
 
- <section xml:id="ext.ffi.uffi.and.cffi">
+ <section id="ext.ffi.uffi.and.cffi">
   <title>Higher level interfaces</title>
 
   <para>Up to now we have only discussed vague ideas about how a &FFI; works,
@@ -223,116 +219,24 @@
   <para>In the following two subsections we will discuss two practical examples
   of using the native &UFFI; and the &CFFI; library.</para>
 
-  <section xml:id="ext.ffi.uffi-example">
+  <section id="ext.ffi.uffi-example">
    <title>UFFI example</title>
 
-   <para>The example below shows how to use &UFFI; in an application. There are
-   several important ingredients:
-   <itemizedlist>
-    <listitem><para>You need to specify the libraries you use and do it at the
-    toplevel, so that the compiler may include them at link
-    time.</para></listitem>
-    <listitem><para>Every function you will use has to be declared using
-    <function>uffi:def-function</function>.</para></listitem>
-   </itemizedlist>
-   </para>
 <programlisting>
-#|
-Build and load this module with (compile-file "uffi.lsp" :load t)
-|#
-;;
-;; This toplevel statement notifies the compiler that we will
-;; need this shared library at runtime. We do not need this
-;; statement in windows.
-;;
-#-(or ming32 windows)
-(uffi:load-foreign-library #+darwin "/usr/lib/libm.dylib"
-			   #-darwin "/usr/lib/libm.so")
-;;
-;; With this other statement, we import the C function sin(),
-;; which operates on IEEE doubles.
-;;
-(uffi:def-function ("sin" c-sin) ((arg :double))
-                   :returning :double)
-;;
-;; We now use this function and compare with the lisp version.
-;;
-(format t "~%Lisp sin:~t~d~%C sin:~t~d~%Difference:~t~d"
-	(sin 1.0d0) (c-sin 1.0d0) (- (sin 1.0d0) (c-sin 1.0d0)))
+ 
 </programlisting>
   </section>
 
-  <section xml:id="ext.ffi.cffi-example">
+  <section id="ext.ffi.cffi-example">
    <title>CFFI example</title>
 
-   <para>The &CFFI; library is an independent project and it is not shipped
-   with &ECL;. If you wish to use it you can go to their <ulink
-   url="http://www.common-lisp.net/cffi/">homepage</ulink>, download the code
-   and build it using &ASDF;.</para>
-
-   <para>&CFFI; differs slightly from &UFFI; in that functions may be used even
-   without being declared beforehand. This poses a few problems to the &ECL;
-   backend, but hopefully these should have been solved in the latest
-   releases.</para>
 <programlisting>
-#|
-Build and load this module with (compile-file "cffi.lsp" :load t)
-|#
-;;
-;; This toplevel statement notifies the compiler that we will
-;; need this shared library at runtime. We do not need this
-;; statement in windows.
-;;
-#-(or ming32 windows)
-(cffi:load-foreign-library #+darwin "/usr/lib/libm.dylib"
-			   #-darwin "/usr/lib/libm.so")
-;;
-;; With this other statement, we import the C function sin(),
-;; which operates on IEEE doubles.
-;;
-(cffi:defcfun ("sin" c-sin) :double '(:double))
-;;
-;; We now use this function and compare with the lisp version.
-;;
-(format t "~%Lisp sin:~t~d~%C sin:~t~d~%Difference:~t~d"
-	(sin 1.0d0) (c-sin 1.0d0) (- (sin 1.0d0) (c-sin 1.0d0)))
-;;
-;; The following also works: no declaration!
-;;
-(let ((c-cos (cffi:foreign-funcall "cos" :double 1.0d0 :double)))
-   (format t "~%Lisp cos:~t~d~%C cos:~t~d~%Difference:~t~d"
-	(sin 1.0d0) c-sin (- (sin 1.0d0) c-sin)))
-</programlisting>
-  </section>
-
-  <section xml:id="ext.ffi.ecl-example">
-   <title>Low level example</title>
-
-   <para>To compare with the previous pieces of code, we show how the previous
-   programs would be written using <xref linkend="ref.clines"/> and <xref
-   linkend="ref.c-inline"/></para>
-<programlisting>
-#|
-Build and load this module with (compile-file "ecl.lsp" :load t)
-|#
-;;
-;; With this other statement, we import the C function sin(), which
-;; operates on IEEE doubles. Notice that we include the C header to
-;; get the full declaration.
-;;
-(defun c-sin (x)
-  (ffi:clines "#include &lt;math.h&gt;")
-  (ffi:c-inline (x) (:double) :double "sin(#0)" :one-liner t))
-;;
-;; We now use this function and compare with the lisp version.
-;;
-(format t "~%Lisp sin:~t~d~%C sin:~t~d~%Difference:~t~d"
-	(sin 1.0d0) (c-sin 1.0d0) (- (sin 1.0d0) (c-sin 1.0d0)))
+ 
 </programlisting>
   </section>
  </section>
 
- <section xml:id="ext.ffi.dict">
+ <section id="ext.ffi.dict">
   <title>FFI Reference</title>
   <toc/>
 
@@ -340,7 +244,7 @@
 <!-- FFI:CLINES                                                             -->
 <!-- ====================================================================== -->
 
-  <refentry xml:id="ref.clines">
+  <refentry id="ref.clines">
    <refnamediv>
     <refname><function>ffi:clines</function></refname>
     <refpurpose>Insert C declarations and definitions</refpurpose>
@@ -367,9 +271,9 @@
     <title>Description</title>
 
     <para>This special form inserts C code directly in the file that results
-    from compiling lisp sources. Contrary to <xref linkend="ref.c-inline"/>,
-    this function may have no executable statements, accepts no input value and
-    returnsn no value.</para>
+    from compiling lisp sources. It can only appear as a toplevel form and,
+    contrary to <xref linkend="ref.c-inline"/>, it does not accept any input
+    values nor returns any value.</para>
 
     <para>The main use of <function>FFI:CLINES</function> is to declare or
     define C variables and functions that are going to be used later in other
@@ -397,7 +301,7 @@
 <!-- FFI:C-INLINE                                                           -->
 <!-- ====================================================================== -->
 
-  <refentry xml:id="ref.c-inline">
+  <refentry id="ref.c-inline">
    <refnamediv>
     <refname><function>ffi:c-inline</function></refname>
     <refpurpose>Inline C code in a lisp form.</refpurpose>
@@ -412,7 +316,7 @@
       <paramdef>(<parameter>c-type</parameter>*)</paramdef>
       <paramdef><parameter>return-type</parameter></paramdef>
       <paramdef><parameter>C-code</parameter></paramdef>
-      <paramdef>&key;</paramdef>
+      <paramdef>&keys;</paramdef>
       <paramdef><parameter>one-liner</parameter></paramdef>
       <paramdef><parameter>side-effects</parameter></paramdef>
      </funcprototype>