#778 ruby exceptionclass broken with -minherit

closed
nobody
ruby (61)
5
2007-05-04
2006-11-28
No

In SWIG 1.3.31, it seems that %exceptionclass support is broken when -minherit is in use. Specifically, with -minherit the marked C++ exceptions incorrectly inherit from Object (rb_cObject) instead of a class in Ruby's exception hierarchy (rb_eRuntimeError, by current SWIG convention).

To reproduce this problem, run swig on Examples/ruby/exception_class/example.i with and without the -minherit option and compare the EmptyError proxy's superclass emitted by SWIG in example_wrap.cxx.

The problem seems to be in lines 1752-1765 of Modules/ruby.cxx:
if (multipleInheritance) {
if (!useGlobalModule) {
Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar, ", \"", klass->name, "\", rb_cObject);\n", NIL);
} else {
Printv(klass->init, klass->vname, " = rb_define_class(\"", klass->name, "\", rb_cObject);\n", NIL);
}
Printv(klass->init, klass->mImpl, " = rb_define_module_under(", klass->vname, ", \"Impl\");\n", NIL);
} else {
if (!useGlobalModule) {
Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar, ", \"", klass->name, "\", $super);\n", NIL);
} else {
Printv(klass->init, klass->vname, " = rb_define_class(\"", klass->name, "\", $super);\n", NIL);
}
}

Note that if multipleInheritance is true, the emitted code isn't templatized with $super for the superclass name; instead, it always uses rb_cObject. Is there some obscure reason why the superclass must be Object when -minherit is in use? It seems like this code could be corrected and simplified thus:

if (!useGlobalModule) {
Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar, ", \"", klass->name, "\", $super);\n", NIL);
} else {
Printv(klass->init, klass->vname, " = rb_define_class(\"", klass->name, "\", $super);\n", NIL);
}
if (multipleInheritance) {
Printv(klass->init, klass->mImpl, " = rb_define_module_under(", klass->vname, ", \"Impl\");\n", NIL);
}

Discussion

  • John Whitley

    John Whitley - 2006-12-09

    Logged In: YES
    user_id=649097
    Originator: YES

    FYI, I've applied this patch to my local win32 build of SWIG, and so far all's well.

     
  • William Fulton

    William Fulton - 2007-05-03

    Logged In: YES
    user_id=242951
    Originator: NO

    Add Ruby classification

     
  • William Fulton

    William Fulton - 2007-05-03
    • labels: --> ruby
     
  • Gonzalo Garramuno

    • status: open --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks