Hi,

I am working on linking ruby app against this SWIG-generated c++ library.
soon i found out that my simple test program dies with some exceptions
with this library loaded.

I digged this issue and found out that Class.new is undefined by the
c++ library with this line:
"rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new");"
if i am correct, _cSWIG_Pointer is a class object thus JRuby undefines
"Class.new".

I guess it's the c++ library's (or SWIG) problem not JRuby's but its
safer to protect important methods from being undefined from such
calls.

at least for Class (class), following change to module.cpp seems to
work but not sure if this is the best place to handle this.
appreciate your advise on this one.

diff --git a/cext/src/module.cpp b/cext/src/module.cpp
index 48b1531..06201e1 100644
--- a/cext/src/module.cpp
+++ b/cext/src/module.cpp
@@ -152,9 +152,19 @@ rb_define_singleton_method(VALUE object, const
char* meth, VALUE(*fn)(ANYARGS),
     checkExceptions(env);
 }

 extern "C" void
 rb_undef_method(VALUE klass, const char* method)
 {
+    ID nameid=  rb_intern( "name" );
+    VALUE classname = rb_funcall( klass, nameid, 0 );
+    char* classcstr = rb_string_value_ptr( &classname );
+    if( strcmp("Class", classcstr) == 0){
+          //TODO warn "you are not allowed to undef Class method"
+          return;
+    }
     JLocalEnv env;

     jmethodID undef = getMethodID(env, RubyModule_class, "undef",



Obakestar

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to