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

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)

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

···

--
Posted via http://www.ruby-forum.com/.

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: SWIG and Ruby. 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

···

On Mon, Dec 14, 2009 at 3:49 PM, Matt Bleh <phreakuencies@gmail.com> wrote:

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
--
Posted via http://www.ruby-forum.com/\.

One thing Rice doesn't have that I have been asked about is SWIG's
%trackobject directive: SWIG and Ruby.
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

···

--
Posted via http://www.ruby-forum.com/\.