aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorMike Pall <mike>2011-02-08 01:20:53 +0100
committerMike Pall <mike>2011-02-08 01:20:53 +0100
commit2388a7fcc017b9e9a75a4674aa81933b510882f7 (patch)
tree92dda452c9ae9d1d6cc31c70e4ee418867d665b2 /doc
parent9c81c81ed518abc61bba64753cc43ff095ff399b (diff)
downloadluajit-2388a7fcc017b9e9a75a4674aa81933b510882f7.tar.gz
luajit-2388a7fcc017b9e9a75a4674aa81933b510882f7.tar.bz2
luajit-2388a7fcc017b9e9a75a4674aa81933b510882f7.zip
FFI: Document current FFI implementation status.
Diffstat (limited to 'doc')
-rw-r--r--doc/ext_ffi_semantics.html91
1 files changed, 82 insertions, 9 deletions
diff --git a/doc/ext_ffi_semantics.html b/doc/ext_ffi_semantics.html
index 4a1b6c11..9b7cac70 100644
--- a/doc/ext_ffi_semantics.html
+++ b/doc/ext_ffi_semantics.html
@@ -128,13 +128,13 @@ TODO
128 128
129<h2 id="gc">Garbage Collection of cdata Objects</h2> 129<h2 id="gc">Garbage Collection of cdata Objects</h2>
130<p> 130<p>
131All explicitly (<tt>ffi.new()</tt> etc.) or implicitly (accessors) 131All explicitly (<tt>ffi.new()</tt>, <tt>ffi.cast()</tt> etc.) or
132created cdata objects are garbage collected. You need to ensure to 132implicitly (accessors) created cdata objects are garbage collected.
133retain valid references to cdata objects somewhere on a Lua stack, an 133You need to ensure to retain valid references to cdata objects
134upvalue or in a Lua table while they are still in use. Once the last 134somewhere on a Lua stack, an upvalue or in a Lua table while they are
135reference to a cdata object is gone, the garbage collector will 135still in use. Once the last reference to a cdata object is gone, the
136automatically free the memory used by it (at the end of the next GC 136garbage collector will automatically free the memory used by it (at
137cycle). 137the end of the next GC cycle).
138</p> 138</p>
139<p> 139<p>
140Please note that pointers themselves are cdata objects, however they 140Please note that pointers themselves are cdata objects, however they
@@ -176,12 +176,85 @@ ffi.C.printf("integer value: %d\n", ffi.new("int", x)) -- <span style="color:#00
176</pre> 176</pre>
177<p> 177<p>
178Memory areas returned by C functions (e.g. from <tt>malloc()</tt>) 178Memory areas returned by C functions (e.g. from <tt>malloc()</tt>)
179must be manually managed of course. Pointers to cdata objects are 179must be manually managed, of course. Pointers to cdata objects are
180indistinguishable from pointers returned by C functions (which is one 180indistinguishable from pointers returned by C functions (which is one
181of the reasons why the GC cannot follow them). 181of the reasons why the GC cannot follow them).
182</p> 182</p>
183 183
184<h2>TODO</h2> 184<h2 id="status">Current Status</h2>
185<p>
186The initial release of the FFI library has some limitations and is
187missing some features. Most of these will be fixed in future releases.
188</p>
189<p>
190<a href="#clang">C language support</a> is
191currently incomplete:
192</p>
193<ul>
194<li>C&nbsp;declarations are not passed through a C&nbsp;pre-processor,
195yet.</li>
196<li>The C&nbsp;parser is able to evaluate most constant expressions
197commonly found in C&nbsp;header files. However it doesn't handle the
198full range of C&nbsp;expression semantics and may fail for some
199obscure constructs.</li>
200<li><tt>static const</tt> declarations only work for integer types
201up to 32&nbsp;bits. Neither declaring string constants nor
202floating-point constants is supported.</li>
203<li>The <tt>long double</tt> C&nbsp;type is parsed correctly, but
204there's no support for the related conversions, accesses or
205arithmetic operations.</li>
206<li>Packed <tt>struct</tt> bitfields that cross container boundaries
207are not implemented.</li>
208<li>Native vector types may be defined with the GCC <tt>mode</tt> and
209<tt>vector_size</tt> attributes. But no operations other than loading,
210storing and initializing them are supported, yet.</li>
211<li>The <tt>volatile</tt> type qualifier is currently ignored by
212compiled code.</li>
213<li><a href="ext_ffi_api.html#ffi_cdef">ffi.cdef</a> silently ignores
214all redeclarations.</li>
215</ul>
216<p>
217The JIT compiler already handles a large subset of all FFI operations.
218It automatically falls back to the interpreter for unimplemented
219operations (you can check for this with the
220<a href="running.html#opt_j"><tt>-jv</tt></a> command line option).
221The following operations are currently not compiled and may exhibit
222suboptimal performance, especially when used in inner loops:
223</p>
224<ul>
225<li>Array/<tt>struct</tt> copies and bulk initializations.</li>
226<li>Bitfield accesses and initializations.</li>
227<li>Vector operations.</li>
228<li>Lua tables as compound initializers.</li>
229<li>Initialization of nested <tt>struct</tt>/<tt>union</tt> types.</li>
230<li>Allocations of variable-length arrays or structs.</li>
231<li>Allocations of C&nbsp;types with a size &gt; 64&nbsp;bytes or an
232alignment &gt; 8&nbsp;bytes.</li>
233<li>Conversions from <tt>lightuserdata</tt> to <tt>void&nbsp;*</tt>.</li>
234<li>Pointer differences for element sizes that are not a power of
235two.</li>
236<li>Calls to non-cdecl or vararg C&nbsp;functions.</li>
237<li>Calls to C&nbsp;functions with aggregates passed or returned by
238value.</li>
239<li>Calls to C&nbsp;functions with 64 bit arguments or return values
240on 32 bit CPUs.</li>
241<li><tt>tostring()</tt> for cdata types.</li>
242<li>The following <a href="ext_ffi_api.html">ffi.* API</a> functions:
243<tt>ffi.sizeof()</tt>, <tt>ffi.alignof()</tt>, <tt>ffi.offsetof()</tt>.
244</ul>
245<p>
246Other missing features:
247</p>
248<ul>
249<li>Bit operations for 64&nbsp;bit types.</li>
250<li>Arithmetic for <tt>complex</tt> numbers.</li>
251<li>User-defined metamethods for C&nbsp;types.</li>
252<li>Callbacks from C&nbsp;code to Lua functions.</li>
253<li>Atomic handling of <tt>errno</tt>.</li>
254<li>Passing structs by value to vararg C&nbsp;functions.</li>
255<li><a href="extensions.html#exceptions">C++ exception interoperability<a/>
256does not extend to C&nbsp;functions called via the FFI.</li>
257</ul>
185<br class="flush"> 258<br class="flush">
186</div> 259</div>
187<div id="foot"> 260<div id="foot">