Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [ANN] FFI 0.2.0

Reply
Thread Tools

[ANN] FFI 0.2.0

 
 
Wayne Meissner
Guest
Posts: n/a
 
      12-03-2008
Greetings Rubyists.

The JRuby team is proud to announce the release of 0.2.0 of FFI for
Ruby. This release is compatible with the FFI implementation released
in JRuby 1.1.6

Get it via 'gem install ffi' or download the source and/or gem files
from the project page at http://kenai.com/projects/ruby-ffi

Special thanks to:

Yehuda Katz
Luc Heinrich
Andrea Fazzi
Mike Dalessio
Hongli Lai



Highlights of changes since 0.1.1:

- About 25% faster function invocation. This is probably not that
important, since as soon as you start putting significant ruby code
around any native call, the native call overhead becomes a bit of a
wash. Still, the first thing people do is benchmarks, so speeding it
up a bit was probably worth it.

- type definitions for size_t, ssize_t, etc autogenerated when ffi gem
is installed.

- variadic function support (from Luc Heinrich <(E-Mail Removed)>)

- nil can be passed as a string argument (from Luc Heinrich
<(E-Mail Removed)>)

- FFI libraries can now be mixed in to other modules. (from Luc
Heinrich <(E-Mail Removed)>)

- uses system libffi if it is new enough. This really only works
under very recent linux distributions and libffi from macports.

- Better library name mangling. Now when an absolute path is set as
ffi_lib, no name mangling occurs. Also on Linux, if you request 'c'
or 'libc.so' as the library, it is converted into 'libc.so.6'

- Multiple libraries can be specified. This is once again, useful on
linux, where you have to specify the exact version of a library, but
you want it to work on other platforms too. e.g. ffi_lib 'ncurses',
'libncurses.so.5'

- Many, many more specs. Most specs now run against the included
libtest native library. It is still a long way from 100% test
coverage, but its better than 0.1 was.

- Better tainted string handling. All strings originating in native
code - i.e. returned from a function, or obtained from a pointer or
buffer via get_string() are tainted. If a tainted string is passed to
a native function, an error is raised.

- automatic Struct layout. This means you can specify the layout as
an array of name, type pairs and the offset and size will be
automatically calculated.

- Fixed specs and rbxspecs rake targets (Patch from Hongli Lai
<(E-Mail Removed)>)

- FFI.errno will now return the errno set by the last native function call

- Memory allocated for Buffer and MemoryPointer is guaranteed to be at
least 8 byte aligned.

- Integer types are all range checked. i.e. if you try and pass a
value > 127 as a :char parameter, it will raise an error.

- Add compat.h header to deal with ancient (i.e. < 1.8.6) versions of ruby

- Add missing :float and :double Struct member support (Patch from
Andrea Fazzi <(E-Mail Removed)>)

- Reworked get_string and put_string to only handle NUL terminated ascii
strings, and create get_bytes/put_bytes for binary data.

- Per-module/library type definitions/aliases.

- Custom managment of Pointer & Struct lifecycle (from Mike Dalessio)

- Library handle caching (from Luc Heinrich <(E-Mail Removed)>)

 
Reply With Quote
 
 
 
 
Sean O'Halpin
Guest
Posts: n/a
 
      12-03-2008
On Wed, Dec 3, 2008 at 1:09 AM, Wayne Meissner <(E-Mail Removed)> wrote:
> Greetings Rubyists.
>
> The JRuby team is proud to announce the release of 0.2.0 of FFI for
> Ruby. This release is compatible with the FFI implementation released
> in JRuby 1.1.6
>

[snip list of great new features]

FFI is just getting better and better. Thanks for this Wayne and
everyone else who has contributed to it.

Regards,
Sean

 
Reply With Quote
 
 
 
 
Charles Oliver Nutter
Guest
Posts: n/a
 
      12-03-2008
Awesome, and thanks for the continued work in parallel on keeping
JRuby's FFI feature-for-feature compatible

Anyone released any notable FFI-based replacements for C extensions yet?
Sean? ffi-ncurses up for a release soon?

Wayne Meissner wrote:
> Greetings Rubyists.
>
> The JRuby team is proud to announce the release of 0.2.0 of FFI for
> Ruby. This release is compatible with the FFI implementation released
> in JRuby 1.1.6
>
> Get it via 'gem install ffi' or download the source and/or gem files
> from the project page at http://kenai.com/projects/ruby-ffi
>
> Special thanks to:
>
> Yehuda Katz
> Luc Heinrich
> Andrea Fazzi
> Mike Dalessio
> Hongli Lai
>
>
>
> Highlights of changes since 0.1.1:
>
> - About 25% faster function invocation. This is probably not that
> important, since as soon as you start putting significant ruby code
> around any native call, the native call overhead becomes a bit of a
> wash. Still, the first thing people do is benchmarks, so speeding it
> up a bit was probably worth it.
>
> - type definitions for size_t, ssize_t, etc autogenerated when ffi gem
> is installed.
>
> - variadic function support (from Luc Heinrich <(E-Mail Removed)>)
>
> - nil can be passed as a string argument (from Luc Heinrich
> <(E-Mail Removed)>)
>
> - FFI libraries can now be mixed in to other modules. (from Luc
> Heinrich <(E-Mail Removed)>)
>
> - uses system libffi if it is new enough. This really only works
> under very recent linux distributions and libffi from macports.
>
> - Better library name mangling. Now when an absolute path is set as
> ffi_lib, no name mangling occurs. Also on Linux, if you request 'c'
> or 'libc.so' as the library, it is converted into 'libc.so.6'
>
> - Multiple libraries can be specified. This is once again, useful on
> linux, where you have to specify the exact version of a library, but
> you want it to work on other platforms too. e.g. ffi_lib 'ncurses',
> 'libncurses.so.5'
>
> - Many, many more specs. Most specs now run against the included
> libtest native library. It is still a long way from 100% test
> coverage, but its better than 0.1 was.
>
> - Better tainted string handling. All strings originating in native
> code - i.e. returned from a function, or obtained from a pointer or
> buffer via get_string() are tainted. If a tainted string is passed to
> a native function, an error is raised.
>
> - automatic Struct layout. This means you can specify the layout as
> an array of name, type pairs and the offset and size will be
> automatically calculated.
>
> - Fixed specs and rbxspecs rake targets (Patch from Hongli Lai
> <(E-Mail Removed)>)
>
> - FFI.errno will now return the errno set by the last native function call
>
> - Memory allocated for Buffer and MemoryPointer is guaranteed to be at
> least 8 byte aligned.
>
> - Integer types are all range checked. i.e. if you try and pass a
> value > 127 as a :char parameter, it will raise an error.
>
> - Add compat.h header to deal with ancient (i.e. < 1.8.6) versions of ruby
>
> - Add missing :float and :double Struct member support (Patch from
> Andrea Fazzi <(E-Mail Removed)>)
>
> - Reworked get_string and put_string to only handle NUL terminated ascii
> strings, and create get_bytes/put_bytes for binary data.
>
> - Per-module/library type definitions/aliases.
>
> - Custom managment of Pointer & Struct lifecycle (from Mike Dalessio)
>
> - Library handle caching (from Luc Heinrich <(E-Mail Removed)>)
>



 
Reply With Quote
 
Sean O'Halpin
Guest
Posts: n/a
 
      12-03-2008
On Wed, Dec 3, 2008 at 3:42 AM, Charles Oliver Nutter
<(E-Mail Removed)> wrote:
> Anyone released any notable FFI-based replacements for C extensions yet?
> Sean? ffi-ncurses up for a release soon?


Hi Charles,

I reckon I'll get a first cut at a gem out this week (even though it's
by no means complete).

As the lib needs features from ffi 0.2.0, it won't work with JRuby
1.1.5 (but hey, 1.1.6 is just around the corner, no?

Regards,
Sean

 
Reply With Quote
 
Charles Oliver Nutter
Guest
Posts: n/a
 
      12-03-2008
Sean O'Halpin wrote:
> On Wed, Dec 3, 2008 at 3:42 AM, Charles Oliver Nutter
> <(E-Mail Removed)> wrote:
>> Anyone released any notable FFI-based replacements for C extensions yet?
>> Sean? ffi-ncurses up for a release soon?

>
> Hi Charles,
>
> I reckon I'll get a first cut at a gem out this week (even though it's
> by no means complete).
>
> As the lib needs features from ffi 0.2.0, it won't work with JRuby
> 1.1.5 (but hey, 1.1.6 is just around the corner, no?


RC tomorrow, final 1.1.6 sometime next week!

- Charlie

 
Reply With Quote
 
marc
Guest
Posts: n/a
 
      12-03-2008
Wayne Meissner said...
> Greetings Rubyists.
>
> The JRuby team is proud to announce the release of 0.2.0 of FFI for
> Ruby. This release is compatible with the FFI implementation released
> in JRuby 1.1.6
>
> Get it via 'gem install ffi' or download the source and/or gem files
> from the project page at http://kenai.com/projects/ruby-ffi


Just a suggestion, but I think it would be worth adding a note about
what FFI is.

--
Cheers,
Marc


 
Reply With Quote
 
Charles Oliver Nutter
Guest
Posts: n/a
 
      12-03-2008
marc wrote:
> Wayne Meissner said...
>> Greetings Rubyists.
>>
>> The JRuby team is proud to announce the release of 0.2.0 of FFI for
>> Ruby. This release is compatible with the FFI implementation released
>> in JRuby 1.1.6
>>
>> Get it via 'gem install ffi' or download the source and/or gem files
>> from the project page at http://kenai.com/projects/ruby-ffi

>
> Just a suggestion, but I think it would be worth adding a note about
> what FFI is.


Here's the text of my 0.1.1 announcement, which ought to clear things up
Perhaps the main paragraph should be included in future release
announcements too?

---
The JRuby team is proud to announce the release of FFI for Ruby 1.8.6/7
and 1.9!

FFI (gem install ffi) is a library for programmatically loading dynamic
libraries, binding functions within them, and calling those functions
from Ruby code. Here's a quick sample of binding and calling the getpid
C library function:


require 'ffi'

module GetPid
extend FFI::Library

attach_function :getpid, [], :uint
end

puts GetPid.getpid


Here's another, calling qsort and passing a Ruby block as a C callback:


require 'ffi'

module LibC
extend FFI::Library
callback :qsort_cmp, [ ointer, ointer ], :int
attach_function :qsort, [ ointer, :int, :int, :qsort_cmp ], :int
end

p = MemoryPointer.new(:int, 2)
p.put_array_of_int32(0, [ 2, 1 ])
puts "Before qsort #{p.get_array_of_int32(0, 2).join(', ')}"
LibC.qsort(p, 2, 4) do |p1, p2|
i1 = p1.get_int32(0)
i2 = p2.get_int32(0)
i1 < i2 ? -1 : i1 > i2 ? 1 : 0
end
puts "After qsort #{p.get_array_of_int32(0, 2).join(', ')}"


I posted a blog entry with a longer description of the library,
additional examples, and links to some other documentation and posts.
Docs are a little slim at this point, so feel free to experiment and
update the JRuby wiki page:

http://blog.headius.com/2008/10/ffi-...available.html

I'm sure docs from here will filter back into the library and out into
the general cosmos.

Finally, there's no need to write a C extension to call C libraries, and
the same FFI code will work in Ruby 1.8.6/7, Ruby 1.9, JRuby 1.1.4+, and
Rubinius (though Rubinius has no callback support yet).

Don't be an extension stooge! Use FFI!

 
Reply With Quote
 
Charles Oliver Nutter
Guest
Posts: n/a
 
      12-03-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I'm currently seting up a rubyforge project for the SDL, SGE,
> SDL_image, SDL_mixer, SDL_ttf and SDL_mixer
> bindings I wrote called Frusdl, short for FFI Ruby SDL. I'll probably
> release the 0.0.1 version when the project is
> approved by the Rubyforge admins.


Ahh, now that sounds cool I hope you'll have some small demo apps to
go with it.

> For advancing Frusdl, I could probably use a few pointers on how to
> implement callbacks, if you forgive the pun. ^_^
> Currently, I don't understand how to use them.


There should be an example of calling qsort in the gem, does that help?

- Charlie

 
Reply With Quote
 
Saji N. Hameed
Guest
Posts: n/a
 
      12-04-2008
* Wayne Meissner <(E-Mail Removed)> [2008-12-03 10:09:03 +0900]:

> Greetings Rubyists.
>
> The JRuby team is proud to announce the release of 0.2.0 of FFI for
> Ruby. This release is compatible with the FFI implementation released
> in JRuby 1.1.6


Just started learning about Ruby/DL - what are the most significant
advantages of FFI over Ruby/DL ?

saji
--



 
Reply With Quote
 
Charles Oliver Nutter
Guest
Posts: n/a
 
      12-04-2008
Saji N. Hameed wrote:
> * Wayne Meissner <(E-Mail Removed)> [2008-12-03 10:09:03 +0900]:
>
>> Greetings Rubyists.
>>
>> The JRuby team is proud to announce the release of 0.2.0 of FFI for
>> Ruby. This release is compatible with the FFI implementation released
>> in JRuby 1.1.6

>
> Just started learning about Ruby/DL - what are the most significant
> advantages of FFI over Ruby/DL ?


* FFI works on JRuby and Rubinius as well as MRI and 1.9
* The API is nicer (imho)

Wayne may have some other points...maybe it's faster?

- Charlie

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANN] FFI madness! Rubygame 2.6, Ruby-SDL-FFI 0.1, and Nice-FFI 0.2released John Croisant Ruby 0 10-25-2009 08:38 PM
Standardizing FFI based wrappers Luc Heinrich Ruby 7 12-15-2008 08:39 PM
[ANN] FFI 0.1.1 (Foreign Function Interface) for Ruby 1.8.6/7 and1.9 Charles Oliver Nutter Ruby 60 12-03-2008 02:29 AM
C FFI: easy conversion from list to argv? Burton Samograd Python 1 04-17-2006 06:59 PM
FFI against VHDL for test-benches Spur VHDL 4 09-15-2003 09:20 AM



Advertisments