From 0e4b239b3e8eb192595d09f72ca9b38f6b65325a Mon Sep 17 00:00:00 2001 From: Gonzalo Garramuno Date: Thu, 3 May 2007 22:08:32 +0000 Subject: [PATCH] Fixed a minor issue in the test-suite regarding trying to compile overloaded functions under C. Fixed refcount test crashing due to autodoc. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9765 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 12 +++++++++++- Source/Modules/ruby.cxx | 43 ++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index dcfa4121a..b9eb83875 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -2,11 +2,20 @@ Version 1.3.32 (in progress) ============================ 05/03/2007: gga + [Ruby] + Applied patch for -minherit bug and exception classes. + This issue should be revisited more closely, as Multiple + Inheritance in Ruby is still problematic. + (patch/bug #1604878) + +05/03/2007: gga + [Ruby] Overloaded functions in ruby will now report to the user the possible prototypes when the user mistypes the number or type of a parameter. 05/03/2007: gga + [Ruby] Forgot to document the bug fixing of an old bug regarding exceptions. (bug #1458247) @@ -82,7 +91,8 @@ Version 1.3.32 (in progress) 05/02/2007: gga [Ruby] Changed the value of SWIG_TYPECHECK_BOOL to be 10000 (ie. higher - than that of all integers). This is because Ruby allows typecasting + than that of all integers). + This is because Ruby allows typecasting integers down to booleans which can make overloaded functions on bools and integers to fail. (bug# 1488142) diff --git a/Source/Modules/ruby.cxx b/Source/Modules/ruby.cxx index 371da411c..e8cda530c 100644 --- a/Source/Modules/ruby.cxx +++ b/Source/Modules/ruby.cxx @@ -232,6 +232,7 @@ private: * ------------------------------------------------------------ */ String *docstring(Node *n, autodoc_t ad_type) { + String *str = Getattr(n, "feature:docstring"); bool have_ds = (str != NULL && Len(str) > 0); bool have_auto = (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc")); @@ -412,13 +413,13 @@ private: n = Getattr(n, "sym:previousSibling"); Node *pn = Swig_methodclass(n); - String* class_name = Copy( Getattr(pn, "sym:name") ); - String* super_names = NewString(""); + String* class_name = Getattr(pn, "sym:name") ; if ( !class_name ) class_name = NewString(""); else { + class_name = Copy(class_name); List *baselist = Getattr(pn, "bases"); if (baselist && Len(baselist)) { Iterator base = First(baselist); @@ -438,7 +439,8 @@ private: String *parent_name = Copy( Getattr(parent, "sym:name") ); if ( !parent_name ) { Node* mod = Getattr(parent, "module"); - parent_name = Copy( Getattr(mod, "name") ); + if ( mod ) + parent_name = Copy( Getattr(mod, "name") ); if ( parent_name ) { (Char(parent_name))[0] = toupper((Char(parent_name))[0]); @@ -1976,13 +1978,15 @@ public: // Constructors will be treated specially const bool isCtor = Cmp(Getattr(sibl,"feature:new"), "1") == 0; - const bool isMethod = Cmp(Getattr(sibl, "ismember"), "1") == 0 && (!isCtor); + const bool isMethod = ( Cmp(Getattr(sibl, "ismember"), "1") == 0 && + (!isCtor) ); // Construct real method name String* methodName = NewString(""); - if ( isMethod ) Printv( methodName, Getattr(parentNode(sibl),"sym:name"), ".", NIL ); + if ( isMethod ) + Printv( methodName, Getattr(parentNode(sibl),"sym:name"), ".", NIL ); Append( methodName, Getattr(sibl,"name" ) ); - if ( isCtor ) Append( methodName, ".new" ); + if ( isCtor ) Append( methodName, ".new" ); // Generate prototype list String *protoTypes = NewString(""); @@ -2001,13 +2005,13 @@ public: Append( protoTypes, ")\\n\"" ); } while ((sibl = Getattr(sibl, "sym:nextSibling"))); - Append(f->code, "fail:\n"); + Append(f->code, "fail:\n{\n"); Printf(f->code, "const char* msg = \"Wrong # of arguments\";\n"); Printf(f->code, "if ( argc <= %d ) msg = \"Wrong arguments\";\n", maxargs); Printf(f->code, "rb_raise(rb_eArgError," "\"%%s for overloaded method '%s'.\\n" " Possible C/C++ prototypes are:\\n\"%s, msg);\n", methodName, protoTypes); - Append(f->code, "return Qnil;\n"); + Append(f->code, "}\nreturn Qnil;\n"); Delete(methodName); Delete(type); @@ -2389,21 +2393,16 @@ public: Printv(klass->type, Getattr(n, "classtype"), NIL); Printv(f_wrappers, "swig_class c", valid_name, ";\n\n", NIL); Printv(klass->init, "\n", tab4, NIL); - 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); + + if (!useGlobalModule) { + Printv(klass->init, klass->vname, " = rb_define_class_under(", modvar, ", \"", klass->name, "\", $super);\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); - } + 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); } SwigType *tt = NewString(name);