You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucy.apache.org by Marvin Humphrey <ma...@rectangular.com> on 2012/01/09 22:12:14 UTC

[lucy-dev] Ruby CFBind glue code

Greets,

Now that Logan has gotten the Ruby bindings for CFC fleshed out well enough to
generate all Lucy core code, our next task is to write routines that convert
between Clownfish types and Ruby types.

For instance, here's a function which translates between a CharBuf and a Ruby
String:

    #include "ruby.h"
    #include "ruby/encoding.h"
    // ...

    static rb_encoding *utf8_encoding = (rb_encoding*)-1;

    VALUE
    CFBind_cb_to_str(const cfish_CharBuf *charbuf) {
        if (!charbuf) {
            return Qnil;
        }
        else {
            if (utf8_encoding == (rb_encoding*)-1) {
                utf8_encoding = rb_utf8_encoding();
            }
            const char *ptr = (const char*)Cfish_CB_Get_Ptr8(charbuf);
            long size = (long)Cfish_CB_Get_Size(charbuf);
            return rb_enc_str_new(ptr, size, utf8_encoding);
        }
    }

In Lucy's Perl bindings, these routines live in trunk/perl/xs/XSBind.*.
Eventually, this content should move under clownfish/, but for now, I think it
makes sense for the Ruby files to live at trunk/ruby/src/CFBind.*.

To get started, we should perform the following "svn copy" command:

    svn copy https://svn.apache.org/repos/asf/incubator/lucy/trunk/example-lang/src \
    https://svn.apache.org/repos/asf/incubator/lucy/trunk/ruby/src

More explanatory notes are available in trunk/example-lang/README.

I've opened LUCY-207 to track progress on this task.

Marvin Humphrey


Re: [lucy-dev] Ruby CFBind glue code

Posted by Marvin Humphrey <ma...@rectangular.com>.
On Sat, Jan 14, 2012 at 10:17:01AM -0800, Nathan Kurz wrote:
> On Mon, Jan 9, 2012 at 1:12 PM, Marvin Humphrey <ma...@rectangular.com> wrote:
> > In Lucy's Perl bindings, these routines live in trunk/perl/xs/XSBind.*.
> > Eventually, this content should move under clownfish/, but for now, I think it
> > makes sense for the Ruby files to live at trunk/ruby/src/CFBind.*.
> 
> What's the rationale on waiting to move these to be under Clownfish?

FWIW, it's possible to move them now.  

Currently all C files under trunk/clownfish/ are part of the CFC compiler and
get linked into the monolithic Clownfish::CFC shared object -- which is used
while building Lucy, but not installed.  In contrast, all C files under
trunk/perl/ get linked into the monolithic Lucy shared object, along with
everything under trunk/core/.  Moving the XSBind.*/CFBind.* files under
trunk/clownfish/ would make things a little more complicated in the near term.

At some point in the future, we will be compiling a Clownfish shared object
which will consist of Clownfish::Obj, Clownfish::CharBuf, Clownfish::Hash,
etc.  It will be a dependency for Lucy, so unlike Clownfish::CFC, it will be
installed.  The content currently in XSBind.*/CFBind.* ultimately belongs
there.

The rationale for waiting is that whatever the merits of this refactoring
effort, it's probably not going to get us Ruby bindings any sooner.

> It will certainly work for Logan, but my instinct is that it will be
> easier to get other Ruby programmers involved if they can treat the CF
> bindings as a given, rather than something they have to wrestle with.

+1

> I'd suggest moving them now, and then moving the Perl bindings over as
> soon as the model is established.  Right now Clownfish is a
> significant hurdle to new programmers, and compartmentalizing might
> help overcome this.

OK, we can start by moving all classes under Lucy::Object:: underneath
Clownfish::, with the possible exceptions of I32Array and BitVector which
arguably belong under Lucy::Util::.

For esoteric technical reasons[1], I advocate leaving the files within core/
and trunk/perl/ (and soon trunk/ruby/) until we can actually compile a
seperate Clownfish shared object.  At that point, we can migrate everything
under trunk/clownfish/.

Marvin Humphrey

[1] We'll have to solve some symbol exporting issues that we've been able to
    cheat on so far by compiling everything into a monolithic shared object.
    We'll also have to decide what to do about Serialize() and Deserialize(),
    which currently use Lucy::Store::InStream and Lucy::Store::OutStream --
    will they move too? Will we refactor serialization?  Etc.


Re: [lucy-dev] Ruby CFBind glue code

Posted by Nathan Kurz <na...@verse.com>.
On Mon, Jan 9, 2012 at 1:12 PM, Marvin Humphrey <ma...@rectangular.com> wrote:
> In Lucy's Perl bindings, these routines live in trunk/perl/xs/XSBind.*.
> Eventually, this content should move under clownfish/, but for now, I think it
> makes sense for the Ruby files to live at trunk/ruby/src/CFBind.*.

What's the rationale on waiting to move these to be under Clownfish?
It will certainly work for Logan, but my instinct is that it will be
easier to get other Ruby programmers involved if they can treat the CF
bindings as a given, rather than something they have to wrestle with.
I'd suggest moving them now, and then moving the Perl bindings over as
soon as the model is established.  Right now Clownfish is a
significant hurdle to new programmers, and compartmentalizing might
help overcome this.

--nate