On 08/01/14 17:15, Josef Reidinger wrote:
We discussing on lunch about various quality of C
bindings ( hating
perl C bindings :) ) and we remembered that duncan do something with
it, but I cannot remember more details. Martin think that FFI is about
making C api better but need to write in C. So I look into it how it
works and are quite surprised that
I was maintaining some rpm bindings that were dated from ruby 1.6 times.
The C code was painful to work with, so I rewrote the whole thing in
pure ruby using ffi.
The API is mostly compatible, but it does not support install operations
yet, and it targets rpm 4.9 only.
1) you write it in ruby
2) is really straight forward
Yes. But you have to be careful, there are some tradeoffs
* if the library API changes your extension will not stop compiling. You
have to have good testcases.
* Some libs are annoying when they use macros in headers, and you can't
* You have to be more careful if you want to support multiple target
libraries. In a C extension it is more straightforward with #ifdef and
version macros/defines. In ruby is the same but you have less
information at your disposal.
* I am not sure if ffi is supported on all architectures. Check for
s390x and others.
3) doesn't work well C++ ( let me fix it if I
understand it wrong ).
The problem is the ABI and name mangling. Even if it worked, you would
be able to call functions, so it would not be an automatic mapping to
rbplusplus is a different approach. They use gcc xml output to have the
class metadata, and then convert that to C++ code, using a library call
rice that wraps the MRI C API in C++. You still need to generate C++ in
order to call C++ code or create a small C library that exposes a plain
C api for the C++ API and then call that from FFI.
Or you can implement the mangling for gcc4 and call C++ directly...
Duncan Mac-Vicar P. - http://www.suse.com/
SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix
Imendörffer, HRB 16746 (AG Nürnberg)
Maxfeldstraße 5, 90409 Nürnberg, Germany
To unsubscribe, e-mail: opensuse-ruby+unsubscribe(a)opensuse.org
To contact the owner, e-mail: opensuse-ruby+owner(a)opensuse.org