Hi,

At Wed, 16 Apr 2003 04:47:13 +0900,
Lyle Johnson wrote:
> One aspect of this change is still unclear to me: what is now the
> correct way to indicate that an extension class is an abstract class? 
> Previously, SWIG was either redefining 'new' for concrete extension
> classes, or undefining 'new' for abstract extension classes.

Sorry, I missed it.  You can make them abstract by undefining
allocator with rb_undef_alloc_func().

Please replace all STR2CSTR to StringValue, and apply this
patch.


--- Lib/ruby/rubyhead.swg~ Wed Feb 26 04:22:36 2003 +++ Lib/ruby/rubyhead.swg Wed Apr 16 06:11:34 2003 @@ -76,3 +76,26 @@ typedef struct { void (*destroy)(void *); } swig_class; + +/* Don't use for expressions have side effect */ +#ifndef RB_STRING_VALUE +#define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s))) +#endif +#ifndef StringValue +#define StringValue(s) RB_STRING_VALUE(s) +#endif +#ifndef StringValuePtr +#define StringValuePtr(s) RSTRING(RB_STRING_VALUE(s))->ptr +#endif +#ifndef StringValueLen +#define StringValueLen(s) RSTRING(RB_STRING_VALUE(s))->len +#endif +#define SafeStringValue(v) do {\ + StringValue(v);\ + rb_check_safe_str(v);\ +} while (0) + +#ifndef HAVE_RB_DEFINE_ALLOC_FUNC +#define rb_define_alloc_func(klass, func) rb_define_singleton_method(klass, "new", func, -1) +#define rb_undefine_alloc_func(klass) rb_undef_method(CLASS_OF(klass), "new") +#endif --- Source/Modules/ruby.cxx~ Tue Mar 18 01:52:37 2003 +++ Source/Modules/ruby.cxx Wed Apr 16 06:11:48 2003 @@ -479,6 +479,6 @@ public: break; case CONSTRUCTOR_ALLOCATE: - Printv(s, tab4, "rb_define_singleton_method(", klass->vname, - ", \"new\", ", wname, ", -1);\n", NIL); + Printv(s, tab4, "rb_define_alloc_func(", klass->vname, + ", ", wname, ");\n", NIL); Replaceall(klass->init,"$allocator", s); break; @@ -830,5 +830,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 +1331,5 @@ public: String *s = NewString(""); - Printv(s, tab4, "rb_undef_method(CLASS_OF(", klass->vname, - "), \"new\");\n", NIL); + Printv(s, tab4, "rb_undef_alloc_func(", klass->vname, ");\n", NIL); Replaceall(klass->init,"$allocator", s); Replaceall(klass->init,"$initializer", "");
-- Nobu Nakada