[ANN] FFI 0.2.0

W

Wayne Meissner

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 <[email protected]>)

- nil can be passed as a string argument (from Luc Heinrich
<[email protected]>)

- FFI libraries can now be mixed in to other modules. (from Luc
Heinrich <[email protected]>)

- 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
<[email protected]>)

- 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 <[email protected]>)

- 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 <[email protected]>)
 
S

Sean O'Halpin

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
 
C

Charles Oliver Nutter

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?
 
S

Sean O'Halpin

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
 
C

Charles Oliver Nutter

Sean said:
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
 
M

marc

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.
 
C

Charles Oliver Nutter

marc said:
Wayne Meissner said...

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, [ :pointer, :pointer ], :int
attach_function :qsort, [ :pointer, :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-for-ruby-now-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!
 
C

Charles Oliver Nutter

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
 
S

Saji N. Hameed

* 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

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

saji
--
 
C

Charles Oliver Nutter

Saji said:
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
 
H

Heesob Park

Charles said:
* 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
I want to use FFI instead of Win32API or win32-api.

But I cannot install FFI on Windows.

What's the plan for Windows support?

Regards,

Park Heesob
 
L

Luc Heinrich

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

* It's actually supported and evolving.
* It's based on libffi which is already used in similar situations in =20=

other languages so the foundations are more solid, more tested, =20
support more platform and are more likely to get fixes and improvements.
Wayne may have some other points...maybe it's faster?

About 4 times faster than DL in my tests.

--=20
Luc Heinrich - (e-mail address removed)
 
W

Wayne Meissner

2008/12/4 Charles Oliver Nutter said:
* FFI works on JRuby and Rubinius as well as MRI and 1.9
* The API is nicer (imho)

Those are the major user-visible reasons. There are other reasons,
like the ones Luc mentioned.
 
C

Charles Oliver Nutter

My Rubyforge project request was accepted. You can find all about
Frusdl 0.0.1 here:
http://frusdl.rubyforge.org/

It's yet untested on jruby, as I'm waiting for the 1.16 release. And
it's meagerly documented,
no unit test, etc, etc, but I'm sticking to "release early, release
often here". I hope it's
of interest or use to someone out there.

JRuby 1.1.6RC1 is out, so now's a great time to try it :)

www.jruby.org

- Charlie
 
G

Gregory Seidman

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 [...]
Highlights of changes since 0.1.1:
[...]
- variadic function support (from Luc Heinrich <[email protected]>)
[...]

I have been waiting for that feature. Is there a code example of setting up
a variadic function somewhere?

--Greg
 
C

Charles Oliver Nutter

Gregory 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 [...]
Highlights of changes since 0.1.1:
[...]
- variadic function support (from Luc Heinrich <[email protected]>)
[...]

I have been waiting for that feature. Is there a code example of setting up
a variadic function somewhere?

There's a pretty good collection of specs; that's probably your best bet
for examples right now, until users start adding examples to the wiki.

https://kenai.com/hg/ruby-ffi~mercurial/file/9132d4854b79/specs/variadic_spec.rb

- Charlie
 
C

Charles Oliver Nutter

Charles said:
Gregory 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 [...]
Highlights of changes since 0.1.1:
[...]
- variadic function support (from Luc Heinrich <[email protected]>)
[...]

I have been waiting for that feature. Is there a code example of
setting up
a variadic function somewhere?

There's a pretty good collection of specs; that's probably your best bet
for examples right now, until users start adding examples to the wiki.

https://kenai.com/hg/ruby-ffi~mercurial/file/9132d4854b79/specs/variadic_spec.rb

Better URL (still learning hg myself):

https://kenai.com/hg/ruby-ffi~mercurial/file/tip/specs/variadic_spec.rb
 
L

Luc Heinrich

I have been waiting for that feature. Is there a code example of =20
setting up
a variadic function somewhere?

Here's a very simply one:

require "rubygems"
require "ffi"

module Test
extend FFI::Library
attach_function :printf, [:string, :varargs], :int
end

Test.printf("The answer is %d\n", :int, 42)
Test.printf("The sum of %.1f and %.1f is %.1f\n", :double, =20
2.5, :double, 1.5, :double, 4.0)

--=20
Luc Heinrich - (e-mail address removed)
 
P

Paul Brannan

I'm getting an error trying to install the gem for ffi 0.2.0. Am I
doing something wrong?

[pbrannan@zem rubygems-1.3.1]$ sudo gem install ffi
Building native extensions. This could take a while...
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.

rake RUBYARCHDIR=/usr/local/lib/ruby/gems/1.8/gems/ffi-0.2.0/lib RUBYLIBDIR=/usr/local/lib/ruby/gems/1.8/gems/ffi-0.2.0/lib
<internal:gem_prelude>:236:in `push_gem_version_on_load_path': undefined method `<=>' for nil:NilClass (NoMethodError)
from <internal:gem_prelude>:10:in `gem'
from /usr/local/bin/rake:18:in `<main>'


Gem files will remain installed in /usr/local/lib/ruby/gems/1.8/gems/ffi-0.2.0 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.8/gems/ffi-0.2.0/gen/gem_make.out
/usr/local/lib/ruby/1.8/rdoc/parsers/parse_c.rb:204: warning: method redefined; discarding old progress
[pbrannan@zem rubygems-1.3.1]$ gem --version
1.3.1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] ffi 0.5.0 0
[ANN] ffi-swig-generator 0.3.0 0
[ANN] ffi-swig-generator 0.2.1 0
[ANN] ffi-ncurses version 0.3.0 7
[ANN] ffi-ncurses 0.3.3 21
[ANN] ffi-wiiuse 0.1.0 1
[ANN] ffi-opengl 0.1.0 2
FreeImage-FFI 0

Members online

No members online now.

Forum statistics

Threads
473,790
Messages
2,569,637
Members
45,346
Latest member
EstebanCoa

Latest Threads

Top