diff options
author | Mike Pall <mike> | 2011-02-08 01:20:53 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2011-02-08 01:20:53 +0100 |
commit | 2388a7fcc017b9e9a75a4674aa81933b510882f7 (patch) | |
tree | 92dda452c9ae9d1d6cc31c70e4ee418867d665b2 /doc | |
parent | 9c81c81ed518abc61bba64753cc43ff095ff399b (diff) | |
download | luajit-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.html | 91 |
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> |
131 | All explicitly (<tt>ffi.new()</tt> etc.) or implicitly (accessors) | 131 | All explicitly (<tt>ffi.new()</tt>, <tt>ffi.cast()</tt> etc.) or |
132 | created cdata objects are garbage collected. You need to ensure to | 132 | implicitly (accessors) created cdata objects are garbage collected. |
133 | retain valid references to cdata objects somewhere on a Lua stack, an | 133 | You need to ensure to retain valid references to cdata objects |
134 | upvalue or in a Lua table while they are still in use. Once the last | 134 | somewhere on a Lua stack, an upvalue or in a Lua table while they are |
135 | reference to a cdata object is gone, the garbage collector will | 135 | still in use. Once the last reference to a cdata object is gone, the |
136 | automatically free the memory used by it (at the end of the next GC | 136 | garbage collector will automatically free the memory used by it (at |
137 | cycle). | 137 | the end of the next GC cycle). |
138 | </p> | 138 | </p> |
139 | <p> | 139 | <p> |
140 | Please note that pointers themselves are cdata objects, however they | 140 | Please 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> |
178 | Memory areas returned by C functions (e.g. from <tt>malloc()</tt>) | 178 | Memory areas returned by C functions (e.g. from <tt>malloc()</tt>) |
179 | must be manually managed of course. Pointers to cdata objects are | 179 | must be manually managed, of course. Pointers to cdata objects are |
180 | indistinguishable from pointers returned by C functions (which is one | 180 | indistinguishable from pointers returned by C functions (which is one |
181 | of the reasons why the GC cannot follow them). | 181 | of 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> | ||
186 | The initial release of the FFI library has some limitations and is | ||
187 | missing some features. Most of these will be fixed in future releases. | ||
188 | </p> | ||
189 | <p> | ||
190 | <a href="#clang">C language support</a> is | ||
191 | currently incomplete: | ||
192 | </p> | ||
193 | <ul> | ||
194 | <li>C declarations are not passed through a C pre-processor, | ||
195 | yet.</li> | ||
196 | <li>The C parser is able to evaluate most constant expressions | ||
197 | commonly found in C header files. However it doesn't handle the | ||
198 | full range of C expression semantics and may fail for some | ||
199 | obscure constructs.</li> | ||
200 | <li><tt>static const</tt> declarations only work for integer types | ||
201 | up to 32 bits. Neither declaring string constants nor | ||
202 | floating-point constants is supported.</li> | ||
203 | <li>The <tt>long double</tt> C type is parsed correctly, but | ||
204 | there's no support for the related conversions, accesses or | ||
205 | arithmetic operations.</li> | ||
206 | <li>Packed <tt>struct</tt> bitfields that cross container boundaries | ||
207 | are 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, | ||
210 | storing and initializing them are supported, yet.</li> | ||
211 | <li>The <tt>volatile</tt> type qualifier is currently ignored by | ||
212 | compiled code.</li> | ||
213 | <li><a href="ext_ffi_api.html#ffi_cdef">ffi.cdef</a> silently ignores | ||
214 | all redeclarations.</li> | ||
215 | </ul> | ||
216 | <p> | ||
217 | The JIT compiler already handles a large subset of all FFI operations. | ||
218 | It automatically falls back to the interpreter for unimplemented | ||
219 | operations (you can check for this with the | ||
220 | <a href="running.html#opt_j"><tt>-jv</tt></a> command line option). | ||
221 | The following operations are currently not compiled and may exhibit | ||
222 | suboptimal 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 types with a size > 64 bytes or an | ||
232 | alignment > 8 bytes.</li> | ||
233 | <li>Conversions from <tt>lightuserdata</tt> to <tt>void *</tt>.</li> | ||
234 | <li>Pointer differences for element sizes that are not a power of | ||
235 | two.</li> | ||
236 | <li>Calls to non-cdecl or vararg C functions.</li> | ||
237 | <li>Calls to C functions with aggregates passed or returned by | ||
238 | value.</li> | ||
239 | <li>Calls to C functions with 64 bit arguments or return values | ||
240 | on 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> | ||
246 | Other missing features: | ||
247 | </p> | ||
248 | <ul> | ||
249 | <li>Bit operations for 64 bit types.</li> | ||
250 | <li>Arithmetic for <tt>complex</tt> numbers.</li> | ||
251 | <li>User-defined metamethods for C types.</li> | ||
252 | <li>Callbacks from C code to Lua functions.</li> | ||
253 | <li>Atomic handling of <tt>errno</tt>.</li> | ||
254 | <li>Passing structs by value to vararg C functions.</li> | ||
255 | <li><a href="extensions.html#exceptions">C++ exception interoperability<a/> | ||
256 | does not extend to C 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"> |