[ANN] Rice 1.3.0 - Now with full 1.9 support!

J

Jason Roelofs

[Note: parts of this message were removed to make it a legal post.]

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's New?

* Full 1.9 support!
* Cleaned up Rice::Director to be easier to use and support inheritance
nicely (see Documentation)
* Multiple Rice extensions pulled into the same Ruby instance now work
properly


Supported Platforms:

* Linux
* Mac OS X 10.5 and 10.6
* Windows with MinGW / MSYS


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://github.com/jameskilton/rice

Google Groups: http://groups.google.com/group/ruby-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>
#include <rice/Constructor.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(1, 2.0)
 
M

Matt Bleh

Great news! =)
(I'm the one who was bugging you about using RB++/Rice for wrapping GSL,
remember?)

Just a question, how does rice/rb++ handle memory in the GC? I mean,
does it have a one-to-one mapping between wrapped C pointers and
objects? Or will it create a new wrapped object (i.e: different
object_id) every time a to_ruby conversion from a wrapped C++ class is
performed?
I'm asking this since for my project (not the one with GSL, a 3D+physics
simulator which is currently wrapped to ruby with SWIG) it may be an
issue if on every timeframe objects are created and destroyed.

Matt
 
J

Jason Roelofs

[Note: parts of this message were removed to make it a legal post.]

Great news! =)
(I'm the one who was bugging you about using RB++/Rice for wrapping GSL,
remember?)

Just a question, how does rice/rb++ handle memory in the GC? I mean,
does it have a one-to-one mapping between wrapped C pointers and
objects? Or will it create a new wrapped object (i.e: different
object_id) every time a to_ruby conversion from a wrapped C++ class is
performed?
I'm asking this since for my project (not the one with GSL, a 3D+physics
simulator which is currently wrapped to ruby with SWIG) it may be an
issue if on every timeframe objects are created and destroyed.

Matt
AFAIK Rice does a pretty good job of managing object pointers and not
causing an excessive amount of memory thrashing by creating / destroying C++
and Ruby objects, but I've never run any real memory tests against it. I do
know that with my project of wrapping Ogre 3D I have to GC.disable or I get
crashes where memory gets freed before it should (related more to my
wrapping code than Rice itself, I do believe), so there's plenty of work to
do with this before it's rock solid both itself and how people are to use
it.

One thing Rice doesn't have that I have been asked about is SWIG's
%trackobject directive: http://www.swig.org/Doc1.3/Ruby.html#Ruby_nn60. My
plan right now is to let the current features get beat on, and for now spend
time on memory management and some work underneath the covers. If you find
some reproducible memory problems do please create an Issue for it, or a
discussion on the ruby-rice mailing list.

Jason
 
M

Matt Bleh

One thing Rice doesn't have that I have been asked about is SWIG's
%trackobject directive: http://www.swig.org/Doc1.3/Ruby.html#Ruby_nn60.
My
plan right now is to let the current features get beat on, and for now
spend
time on memory management and some work underneath the covers. If you
find
some reproducible memory problems do please create an Issue for it, or a
discussion on the ruby-rice mailing list.

Exactly, in my code I use %trackobjects to do gc_mark on instances of
wrapped objects. Therefore it is all working with GC enabled.

In any case, I agree that Rice should settle now, before adding any more
complicated stuff =) It was just out curiosity that I asked.

Matt
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top