W3C home > Mailing lists > Public > public-rdf-ruby@w3.org > April 2010

Re: raptor

From: Arto Bendiken <arto.bendiken@gmail.com>
Date: Mon, 5 Apr 2010 15:45:49 +0200
Message-ID: <y2v47fe11b71004050645g974776f2gc8a95e24529b71f2@mail.gmail.com>
To: Damian Steer <d.steer@bristol.ac.uk>
Cc: public-rdf-ruby@w3.org, Dave Beckett <dave@dajobe.org>
Hi Damian,

On Mon, Apr 5, 2010 at 2:39 PM, Damian Steer <d.steer@bristol.ac.uk> wrote:
>
> On 5 Apr 2010, at 02:21, Arto Bendiken wrote:
>>
>> PS. RDF::Raptor 0.2.0, released yesterday, included an initial set of
>> FFI bindings to Raptor, as well as RDF::Reader implementations based
>> on both CLI and FFI. Successfully tested in Ruby 1.8.x, 1.9.x and
>> JRuby 1.4.0. Your contributions in further improving the FFI bindings
>> and helping make this the definitive, canonical Raptor gem for Ruby
>> would be welcomed.
>
> Thanks Arto!
>
> I started my own FFI binding just before the Easter break, and was pleasantly surprised by how straightforward it was. Bit tedious, so I'm happy you've done the hard work :-)

Yes, as you say it's fairly straightforward (for anyone familiar with
C) but somewhat tedious, particularly in that if you make a mistake it
usually means a segfault instead of a stack trace.

There are two parts to the job: first defining the needed `libraptor`
function signatures, struct types, enums, etc., and then building some
higher-level abstractions for making effective use of the low-level
API from Ruby.

Thankfully Ruby's blocks combined with the handy `ensure` keyword make
the latter task easier, simplifying memory management and the like;
while Ruby's closures ensure that callback procs always have access to
their lexical `self` scope if they need it.

It's still quite a bit of code overall, but it is eminently readable
and malleable:

  http://github.com/bendiken/rdf-raptor/blob/master/lib/rdf/raptor/ffi.rb

> There is a tool to generate ffi bindings from swig:
>
> <http://github.com/ffi/ffi-swig-generator>
>
> Which was far from perfect (i.e. the output required some fixes) but might save some work in the long run.

Thanks for the pointer - I didn't know about this tool (I was simply
proceeding by reading the Raptor reference manual), but will check it
out when I next need to expand the FFI bindings.

-- 
Arto Bendiken | @bendiken
Received on Monday, 5 April 2010 13:46:23 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 5 April 2010 13:46:24 GMT