incubator-lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marvin Humphrey (JIRA)" <>
Subject [jira] Updated: (LUCY-27) Boilerplater Perl bindings
Date Thu, 03 Sep 2009 17:16:57 GMT


Marvin Humphrey updated LUCY-27:


Boilerplater::Binding::Perl::TypeMap's purpose is to create code fragments
which translate Boilerplater objects and C primitives to Perl 5 data types and
back again.

Translating C primitive types is reasonably straightforward.  (At least, it's
reasonably straightforward in the context of XS, Perl 5's voluminous,
macro-tastic C API.) Here's example code for round-tripping an i32_t through a
Perl scalar and back to C:

chy_i32_t twenty = 20;
SV *twenty_sv = newSViv(twenty);
twenty = SvIV(twenty_sv);

Wrapping and unwrapping most object types with Perl scalars is reasonably
straightforward as well from the perspective of TypeMap, because the
complexity is hidden behind function calls and the only tricky bit is the

SV *query_sv = XSBind_bp_to_perl(query);
query = (lucy_Query*)XSBind_perl_to_bp(query_sv);

XSBind_bp_to_perl and XSBind_perl_to_bp are pretty sophisticated, recursing
into complex data structures and translating Perl hashes and arrays to Hash
and VArray objects... but that's a topic for another time.  

One aspect of TypeMap that is not straightforward is handling of string
arguments.  The algorithm TypeMap and XSBind use is described at

The last item of note about TypeMap is that it generates the 'typemap' file
needed by XS on the fly, creating individual mappings for each Lucy class.
This allows us to perform "isa" tests which pass subclasses but deny other
Lucy objects -- for instance, if a method expects a Lexicon, supplying a
SegLexicon would work but supplying an Indexer or a CharBuf would fail.  And
since we perform this argument checking at the binding boundary, we don't need
to implement it in the core C functions, keeping them as lightweight as

> Boilerplater Perl bindings
> --------------------------
>                 Key: LUCY-27
>                 URL:
>             Project: Lucy
>          Issue Type: Sub-task
>          Components: Boilerplater
>            Reporter: Marvin Humphrey
>         Attachments:
> Iterate over the classes, methods, etc. in a Boilerplater::Hierarchy, 
> auto-generating binding code to bridge Perl-space and C-space.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message