I noticed that the Ruby test cases that deal with
abstract classes, or classes without constructors, fail
when using Ruby 1.8.
Setup - Windows XP, the VC build of Ruby 1.8.2 and
MingW to compile SWIG and run the test cases
Cause - The spirit of the test cases is correct, they
make sure that you can't create an instance of a class
that is abstract or does not have a construtor. I
would guess they were developed against Ruby 1.6.
However, Ruby 1.8 changes the way objects are
constructed by introducing a function called
rb_allocate which is used to allocate memory for the
SWIG supports both the old style and new style of
creating Ruby objects. In the new style, if a class is
abstract then SWIG undefines the rb_allocate method -
thus making it impossible to create an instance of the
If you look at the test cases, you'll see they catch
one of two Ruby exceptions - NameError and
NoConstructorError - when trying to construct an
abstract class or a class with no constructor.
However, in Ruby 1.8 with the SWIG bindings (thus
rb_allocate is undefined), the exception that is thrown
is TypeError, with the full message being:
TypeError: allocator undefined for
Thus I've updated the test cases to make an additional
check for this exception. With this change, all the
tests run successfully against the latest version of
SWIG in CVS (as of Sept. 13, 2005).