Hi,

  It seems that when using SWIG with Ruby, there is a bug that causes a destructor for an object to be called more than once.  If an object is newed

and deleted within C++, but a pointer to that object is returned to Ruby during execution of a Ruby program, the object is deleted twice (once in

C++ and once in Ruby).

The following code recreates the bug.  The resulting core file shows the point of failure in the destructor for class Bar.

Has anyone else encountered this bug when using SWIG?  Is there a way around this problem?  That is, we would like the ability

to delete a object Bar if we create it in Ruby (i.e. bar = Bar.new()).

----------------------------------------- Foo.h

class Bar {
  public:
    int * data;
    Bar() : data (new int) {}
    ~Bar() { delete data; }
};

class Foo {
private:
  Bar *V;
public:
  Foo() : V(new Bar) {}
  ~Foo() { delete V; }
  const Bar *GetBar() { return  V; }
};

----------------------------------------- Foo.i

%module Foo
%{
#include "Foo.h"
%}

class Bar {
public :
  Bar();
  ~Bar();
};

class Foo {
public:
  Foo();
  ~Foo();
  const Bar *GetBar();
}

------------------------------------------- foo.rb

require 'Foo'

f = Foo::Foo.new()
b = f.GetBar()
puts "exiting"

-------------------------------------------- output

exiting
test.rb:5: [BUG] Segmentation fault
ruby 1.6.4 (2001-06-04) [i686-linux]
Aborted

   Thanks,

      Craig

--
___________________________________________________________________________
 Craig Files                                |                  /
  http://fccf0183l.ftc.agilent.com/~cfiles/ |       __o       /
  craig_files / agilent.com                   |       \<,      /
____________________________________________|_____()/ ()____/