[ANN] Rice 1.0.0 - Ruby Interface for C++ Extensions

J

Jason Roelofs

Rice: Ruby Interface for C++ Extensions
========================================

What is Rice?

Rice is a C++ interface to Ruby's C API. It provides a type-safe and
exception-safe interface in order to make embedding Ruby and writing
Ruby extensions with C++ easier. It is similar to Boost.Python in many
ways, but also attempts to provide an object-oriented interface to all
of the Ruby C API.

What Rice gives you:
* A simple C++-based syntax for wrapping and defining classes
* Automatic conversion of exceptions between C++ and Ruby
* Smart pointers for handling garbage collection
* Wrappers for most builtin types to simplify calling code

Documentation: http://rice.rubyforge.org
Project Page: http://rubyforge.org/projects/rice


How do you get Rice?

gem install rice

Note: Rice does require a C++ compiler. See the Documentation page for
more details.


How simple of a syntax?

wrapper.cpp

#include "rice/Class.hpp"

class MyWrapper {
public:
MyWrapper() { }

void doThis() { }
int doThat(int a, float b) { }
};

extern "C"
void Init_wrapper()
{
define_class<MyWrapper>("MyWrapper")
.define_constructor(Constructor<MyWrapper>())
.define_method("do_this", &MyWrapper::doThis)
.define_method("do_that", &MyWrapper::doThat);
}

extconf.rb

require 'mkmf-rice'
create_makefile("wrapper")

test.rb

require 'wrapper'
c = MyWrapper.new
c.do_this
c.do_that

Building Ruby extensions have never been so easy!
 
R

Rados³aw Bu³at

SSBoYXZlIGVycm9yIGR1cmluZyBpbnN0YWxsYXRpb24gcHJvY2VzczoKL3Vzci9iaW4vbGQ6IC4u
Ly4uL3JpY2UvbGlicmljZS5hKENsYXNzLm8pOiByZWxvY2F0aW9uIFJfWDg2XzY0XzMyCmFnYWlu
c3QgYGEgbG9jYWwgc3ltYm9sJyBjYW4gbm90IGJlIHVzZWQgd2hlbiBtYWtpbmcgYSBzaGFyZWQg
b2JqZWN0OwpyZWNvbXBpbGUgd2l0aCAtZlBJQwoKSSdtIG9uIDY0Yml0IGFyY2hpdGVjdHVyZS4K
ClNob3VsZCBJIGZpbGUgYSBidWcgb24gcnVieWZvcmdlPwoKLS0gClJhZG9zs2F3IEJ1s2F0Cgpo
dHRwOi8vcmFkYXJlay5qb2dnZXIucGwgLSBt82ogYmxvZwo=
 
J

Jason Roelofs

MjAwOC8yLzExIFJhZG9zs2F3IEJ1s2F0IDxyYWRlay5idWxhdEBnbWFpbC5jb20+Ogo+IEkgaGF2
ZSBlcnJvciBkdXJpbmcgaW5zdGFsbGF0aW9uIHByb2Nlc3M6Cj4gL3Vzci9iaW4vbGQ6IC4uLy4u
L3JpY2UvbGlicmljZS5hKENsYXNzLm8pOiByZWxvY2F0aW9uIFJfWDg2XzY0XzMyCj4gYWdhaW5z
dCBgYSBsb2NhbCBzeW1ib2wnIGNhbiBub3QgYmUgdXNlZCB3aGVuIG1ha2luZyBhIHNoYXJlZCBv
YmplY3Q7Cj4gcmVjb21waWxlIHdpdGggLWZQSUMKPgo+IEknbSBvbiA2NGJpdCBhcmNoaXRlY3R1
cmUuCj4KPiBTaG91bGQgSSBmaWxlIGEgYnVnIG9uIHJ1Ynlmb3JnZT8KPgo+IC0tCj4gUmFkb3Oz
YXcgQnWzYXQKPgo+IGh0dHA6Ly9yYWRhcmVrLmpvZ2dlci5wbCAtIG3zaiBibG9nCj4KClllYWgs
IGdvIGFoZWFkIGFuZCBmaWxlIGEgYnVnLiBQbGVhc2UgaW5jbHVkZSB5b3VyIHN5c3RlbSBpbmZv
cm1hdGlvbgppbmNsdWRpbmcgZ2NjIHZlcnNpb24uCgpUaGFua3MKCkphc29uCg==
 
P

Paul Brannan

I have error during installation process:
/usr/bin/ld: ../../rice/librice.a(Class.o): relocation R_X86_64_32
against `a local symbol' can not be used when making a shared object;
recompile with -fPIC

I can reproduce this on SuSE 10.1 x86_x64. I'll see what I can do about
fixing it.

We should have been using the fPIC flag all along, since we're building
shared objects.

Paul
 
P

Paul Brannan

We should have been using the fPIC flag all along, since we're building
shared objects.

Here's a patch which you should be able to apply to the tarball:

Index: test/Makefile.am
===================================================================
--- test/Makefile.am (revision 173)
+++ test/Makefile.am (working copy)
@@ -32,6 +32,9 @@
-I.. \
$(RUBY_CPPFLAGS)

+AM_CXXLAGS = \
+ $(RUBY_CXXFLAGS)
+
AM_LDFLAGS = \
$(RUBY_LDFLAGS) \
-L../rice
@@ -41,4 +44,3 @@
$(RUBY_LIBS) \
$(RUBY_LIBRUBYARG)

-
Index: rice/Makefile.am
===================================================================
--- rice/Makefile.am (revision 173)
+++ rice/Makefile.am (working copy)
@@ -110,3 +110,5 @@

AM_CPPFLAGS = @RUBY_CPPFLAGS@

+AM_CXXFLAGS = @RUBY_CXXFLAGS@
+
Index: ruby.ac
===================================================================
--- ruby.ac (revision 173)
+++ ruby.ac (working copy)
@@ -23,6 +23,7 @@
RUBY_CONFIG_ARCHDIR=`RUBY_CONFIG(archdir)`
RUBY_CONFIG_LIBDIR=`RUBY_CONFIG(libdir)`
RUBY_CONFIG_BINDIR=`RUBY_CONFIG(bindir)`
+RUBY_CONFIG_CFLAGS=`RUBY_CONFIG(CFLAGS)`
RUBY_CONFIG_LIBS=`RUBY_CONFIG(LIBS)`
RUBY_CONFIG_DLDLIBS=`RUBY_CONFIG(DLDLIBS)`
RUBY_CONFIG_LDFLAGS=`RUBY_CONFIG(LDFLAGS)`
@@ -32,6 +33,12 @@
RUBY_CPPFLAGS="-I${RUBY_CONFIG_ARCHDIR}"
AC_SUBST(RUBY_CPPFLAGS)

+RUBY_CFLAGS="${RUBY_CONFIG_CFLAGS}"
+AC_SUBST(RUBY_CFLAGS)
+
+RUBY_CXXFLAGS="${RUBY_CONFIG_CFLAGS}"
+AC_SUBST(RUBY_CXXFLAGS)
+
RUBY_LDFLAGS="-L${RUBY_ARCHDIR} -L${RUBY_CONFIG_LIBDIR} ${RUBY_LDFLAGS}"
AC_SUBST(RUBY_LDFLAGS)


Rice and the samples now build fine, though two unit tests still fail:

To_From_Ruby:int_from_ruby: integer -4611686018427387904 too small to convert to `int'
To_From_Ruby:unsigned_int_from_ruby: integer 13835058055282163712 too big to convert to `unsigned int'

We will be sure to test x86_64 better for the next release.

Paul
 

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

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top