From: nobu.nokada@... Date: 2003-04-16T02:17:09+09:00 Subject: Re: rb_class_new_instance behaves strange Hi, At Wed, 16 Apr 2003 01:45:49 +0900, Lyle Johnson wrote: > So far, I've purposely avoided making any changes to support Ruby's > new allocation scheme since (at least in its initial implementation in > Ruby 1.7.x) there seemed to be some problems. There's also the issue > of backwards compatibility with Ruby versions 1.6.x and earlier. If > SWIG is to generate code that will compile under both Ruby 1.6 and > Ruby 1.8, there will presumably need to be a compile-time check of the > Ruby version number. 1.8 defines HAVE_RB_DEFINE_ALLOC_FUNC for that purpose. --- Source/Modules/ruby.cxx~ Tue Mar 18 01:52:37 2003 +++ Source/Modules/ruby.cxx Wed Apr 16 02:03:09 2003 @@ -479,6 +479,11 @@ public: break; case CONSTRUCTOR_ALLOCATE: + Printv(s, "#ifdef HAVE_RB_DEFINE_ALLOC_FUNC\n", NIL); + Printv(s, tab4, "rb_define_alloc_func(", klass->vname, + ", ", wname, ");\n", NIL); + Printv(s, "#else\n", NIL); Printv(s, tab4, "rb_define_singleton_method(", klass->vname, ", \"new\", ", wname, ", -1);\n", NIL); + Printv(s, "#endif\n", NIL); Replaceall(klass->init,"$allocator", s); break; @@ -830,5 +835,7 @@ public: need_result = 1; Printf(f->code, "VALUE vresult = SWIG_NewClassInstance(self, SWIGTYPE%s);\n", Char(SwigType_manglestr(t))); + Printf(f->code, "#ifndef HAVE_RB_DEFINE_ALLOC_FUNC\n"); Printf(f->code, "rb_obj_call_init(vresult, argc, argv);\n"); + Printf(f->code, "#endif\n"); } else if (current == CONSTRUCTOR_INITIALIZE) { need_result = 1; @@ -1329,6 +1336,8 @@ public: String *s = NewString(""); + Printv(s, "#ifndef HAVE_RB_DEFINE_ALLOC_FUNC\n", NIL); Printv(s, tab4, "rb_undef_method(CLASS_OF(", klass->vname, "), \"new\");\n", NIL); + Printv(s, "#endif\n", NIL); Replaceall(klass->init,"$allocator", s); Replaceall(klass->init,"$initializer", ""); -- Nobu Nakada