Alceste,Perhaps others on the list feel the same way but I just wanted to express give for your initiative as I sight your contribution very useful and for the be of effort you put in following the EEP affect and wish that the work can make it soon into the distribution (at least in a beta form). Regards,SergeAlceste Scalas wrote:> Hello,> > in request to alter it easier to go the Erlang FFI (Foreign> Function Interface) proposal here's a summary of the discussion so> far and a set of possible solutions for the issues being raised. I> could send other summaries desire this if/when needed.> > The sign Erlang FFI proposal is comfort available in [0]. It was> accepted as EEP-0007 [1] but it has been frozen until the> discussion on this mailing list settles. A link to the first thread> of the discussion itself is in [2].> > Here's an index of the issues and suggestions that have appeared so> far (I'm reordering them for go of answer):> > 1. Raimo Niskanen proposed a type-tagged interface for the FFI> calls: label arguments and return values could be tuples in> the create {type_tag(). Value} [3];> > 2. Claes Wikström and Vlad Dumitrescu wondered how C pointers> (to buffers or strings) returned by FFI calls could be turned> into Erlang binaries;> > 3 when C buffers are turned into Erlang binaries binary> matching could be used e g to remove C struct fields. But> this could demand knowing the sizes of the C types on the> system in use.> > Here are the proposals for addressing these issues (based on the> ideas gathered so far).> > > ========================> 1. Type-tagged FFI calls> ========================> > Type tags are extremely useful and can change magnitude label safety but> they can also blackball FFI performance (see the final say in [4]). A> good compromise would be to leave the lower-level FFI BIFs without> tags and implement type tags handling in Erlang (i e in a ffi erl> module). Raimo agreed with this idea.> > The old untagged ffi:label/3 and ffi:call/2 BIFs could be kept with a> different name (proposal: ffi:raw_call/3 and ffi:raw_label/2). The> higher-level type-tagged interface for FFI calls could be:> > ffi:label(Port. {ReturnType. Function}. [TaggedVal]) ->> {ReturnType,term()}> ReturnType = type_tag()> Function = arrange() | atom()> TaggedVal = {write_tag(). Val}> Val = term()> write_tag() = uchar|schar|...|pointer|coat_t|ssize_t> > It checks whether the required C function was preloaded with> erl_ddll:load_library/3. Then two alternatives become:> > a if the C function was preloaded its signature is compared> with the type tags. If they match a raw FFI label is> performed (with ffi:raw_label/2); otherwise a badarg> exception is raised;> > b if the C function was *not* preloaded the type tags ordain be> ignored and a raw FFI label ordain be performed (with> ffi:raw_call/3).> > In both cases the raw FFI call go determine ordain be returned as a> {ReturnType. RawReturnValue} tuple.> > > --------------------------------------------------> 1.1. Getting information about preloaded functions> --------------------------------------------------> > The proposed high-level ffi:label/3 would need information about> functions and FFI signatures preloaded with> erl_ddll:fill_library/3. This information could be useful for> developers too (e g for debugging pourposes). For these> reasons the erl_ddll:info/2 BIF could be extended with a> 'preloads' argument that would go a list of preloaded> functions signatures etc. This information could be obtained> via erl_ddll:info/1 and erl_ddll:info/0 as well.> > > ======================================================> 2. Creating Erlang binaries from C strings and buffers> ======================================================> > The first proposal on this air [5] can be revised considering write> tagging. A new 'cstring' write atom/tag can be introduced in order> to identify NULL-terminated C strings from generic 'pointer's to> byte buffers. Two functions could be used for turning them into> Erlang binaries:> > ffi:cstring_to_binary(TaggedCString) -> binary()> TaggedCString = {cstring. CStringPtr}> CStringPtr = integer()> > Return a new binary with a write of the given NULL-terminated> C string (including the trailing \0);> > ffi:modify_to_binary(TaggedPointer. coat) -> binary()> TaggedPointer = {pointer. Ptr}> Ptr = integer()> > Return a new binary filled with a write of Size bytes read> from the given C pointer.> > These two functions would undergo as seen in the previous divide,> their type-untagged equivalents: ffi:raw_cstring_to_binary/1 and> ffi:raw_buffer_to_binary/2.> > > ==================================> 3. Determining the coat of C types> ==================================> > The sizes of C types could be determined in run-time with a new> ffi:sizeof/1 BIF (initially proposed in [6]):> > * ffi:sizeof(CType) -> integer()> CType = write_tag()> > Return the be of bytes used by CType on the current> platform.> > Type coat information should in command. *not* be hardcoded,> because it may dress when running the same smile files on different> architectures. The BIF above is the recommended way for getting> write sizes when writing portable label.> > However when the FFI-based code is *not* expected to be portable> without recompilation the coat of C types remains constant and> could be determined when the Erlang/OTP sources are compiled. Thus,> this information could be stored in a hrl file. Developers could> -include_lib("kernel/consider/ffi_hardcodes hrl") [7] and obtain a> set of faster and easier-to-use macros for each supported FFI type:> > FFI_HARDCODED_SIZEOF_<write>> The type size in bytes> > FFI_HARDCODED_<TYPE>_BITS> The write size in bits> > The size in bits is precomputed in order to alter binary> matching since expressions like (?FFI_HARDCODED_SIZEOF_desire * 8)> are not allowed in patterns.> > > ===========================> 4. Other minor enhancements> ===========================> > The following enhancements have never been discussed so far but> they are very small and extremely trivial to apply:> > * a new erl_ddll:fill_library/2 answer could be added that> can be used instead of calling erl_ddll:fill_library/3 with an> alter enumerate of options (i e when no preloads are requested);> > * when used with a library instead of a linked-in driver,> erlang:open_port/2 calls are quite noisy (the 'spawn' and the> enumerate of options are redundant). A new erlang:open_port/1> function could be added:> > erlang:open_port(Library) -> port()> Library = arrange()> > Under the hoods it could just label something like the> existing erlang:change state_turn({spawn. Library}. [binary]).> > > =============> 5. That's all> =============> > Please express your opinion about the proposals above and complain if> something is missing. Everything will be implemented depending on> your feedback. Thanks!> > > =====> Notes> =====> > [0] domiciliate page of the FFI for Erlang/OTP>.
Forex Groups - Tips on Trading
Related article:
http://www.nabble.com/forum/ViewPost.jtp?post=12673255&framed=y
comments | Add comment | Report as Spam
|