diff --git a/CHANGES.current b/CHANGES.current index b9eb83875..495c7ac0c 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,34 @@ Version 1.3.32 (in progress) ============================ +05/04/2007: gga + [Ruby] + Changed STL renames to be global renames. This fixes + STL functions not being renamed when autorename is on. + This is a not a totally perfect work-around, but better. + Someone really needs to fix the template renaming code. + (See bug #1545634) + +05/04/2007 gga + [All] + Changed %rename("%(undercase)s") a little so that single + numbers at the end of a function are not undercased. That is: + getSomething -> get_something + get2D -> get_2d + get234 -> get_234 + BUT: + asFloat2 -> as_float2 + (Bug #1699714) + +05/03/2007: gga + [Ruby] + Made __swigtype__ => @__swigtype__ so it can be accessed + from the scripting language (and follows Ruby's official + documentation, just in case). + Made tracking => @__trackings__ for same reason. + Currently storing ivars without the @ seems valid, but + the PickAxe says this is not correct, so just in case... + 05/03/2007: gga [Ruby] Applied patch for -minherit bug and exception classes. diff --git a/Examples/test-suite/ruby/newobject1_runme.rb b/Examples/test-suite/ruby/newobject1_runme.rb index d1b54306c..cf845b085 100644 --- a/Examples/test-suite/ruby/newobject1_runme.rb +++ b/Examples/test-suite/ruby/newobject1_runme.rb @@ -26,7 +26,7 @@ include Newobject1 GC.track_class = Foo GC.start 100.times { foo1 = Foo.makeFoo; foo2 = foo1.makeMore } -GC.stats +GC.stats if $VERBOSE swig_assert( 'Foo.fooCount == 200', binding, "but is #{Foo.fooCount}" ) GC.start swig_assert( 'Foo.fooCount <= 2', binding, "but is #{Foo.fooCount}" ) diff --git a/Examples/test-suite/ruby/newobject2_runme.rb b/Examples/test-suite/ruby/newobject2_runme.rb index 9765a2162..9f609e8da 100644 --- a/Examples/test-suite/ruby/newobject2_runme.rb +++ b/Examples/test-suite/ruby/newobject2_runme.rb @@ -20,7 +20,7 @@ include Newobject2 GC.track_class = Foo GC.stats 100.times { foo1 = makeFoo } -GC.stats +GC.stats if $VERBOSE swig_assert( 'fooCount == 100', nil, "but is #{fooCount}" ) GC.start swig_assert( 'fooCount <= 1', nil, "but is #{fooCount}" ) diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg index 5ac43f554..61b10c8fb 100644 --- a/Lib/ruby/rubycontainer.swg +++ b/Lib/ruby/rubycontainer.swg @@ -576,15 +576,13 @@ namespace swig %fragment("RubySequence_Base"); - %extend { // Implementing delete requires semantics that go beyond the // default requirements of STD containers. // - // %rename("delete") __del__; - // VALUE __del__( Sequence::value_type e ) { + // VALUE __delete__( Sequence::value_type e ) { // VALUE r = Qnil; // std::size_t len = $self->size(); // std::remove_if( $self->begin(), $self->end(), @@ -651,7 +649,6 @@ namespace swig return r; } - %rename("reject!") reject_bang; %alias reject_bang "delete_if"; Sequence* reject_bang() { if ( !rb_block_given_p() ) diff --git a/Lib/ruby/rubyrun.swg b/Lib/ruby/rubyrun.swg index 090baac65..1af45b3d2 100644 --- a/Lib/ruby/rubyrun.swg +++ b/Lib/ruby/rubyrun.swg @@ -184,7 +184,7 @@ SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags) It might not in cases where methods do things like downcast methods. */ if (obj != Qnil) { - VALUE value = rb_iv_get(obj, "__swigtype__"); + VALUE value = rb_iv_get(obj, "@__swigtype__"); char* type_name = RSTRING_PTR(value); if (strcmp(type->name, type_name) == 0) { @@ -210,7 +210,7 @@ SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags) free((void *) klass_name); obj = Data_Wrap_Struct(klass, 0, 0, ptr); } - rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name)); + rb_iv_set(obj, "@__swigtype__", rb_str_new2(type->name)); return obj; } @@ -222,7 +222,7 @@ SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type) VALUE obj; swig_class *sklass = (swig_class *) type->clientdata; obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0); - rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name)); + rb_iv_set(obj, "@__swigtype__", rb_str_new2(type->name)); return obj; } @@ -230,7 +230,7 @@ SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type) SWIGRUNTIMEINLINE char * SWIG_Ruby_MangleStr(VALUE obj) { - VALUE stype = rb_iv_get(obj, "__swigtype__"); + VALUE stype = rb_iv_get(obj, "@__swigtype__"); return StringValuePtr(stype); } @@ -397,7 +397,7 @@ SWIG_Ruby_SetModule(swig_module_info *pointer) /* This function can be used to check whether a proc or method or similarly callable function has been passed. Usually used in a %typecheck. */ SWIGINTERN -int rb_is_callable( VALUE proc ) +int SWIG_Ruby_isCallable( VALUE proc ) { static VALUE call_id = Qnil; if ( call_id == Qnil ) call_id = rb_intern("call"); diff --git a/Lib/ruby/rubystdcommon.swg b/Lib/ruby/rubystdcommon.swg index d9ee0031e..c953ea86f 100644 --- a/Lib/ruby/rubystdcommon.swg +++ b/Lib/ruby/rubystdcommon.swg @@ -200,3 +200,24 @@ namespace swig { } } +// +// Common renames for STL functions. +// Sadly, SWIG's name matching is still primitive, so: +// +// std::*::push_back is not valid +// +// Also, since these get run inside templates, putting +// the rename inside the template %extend section is no good +// either. +// + +%rename("delete") *::__delete__; +%rename("reject!") *::reject_bang; +%rename("map!") *::map_bang; +%rename("push") *::push_back; +%rename("pop") *::pop_back; +%rename("empty?") *::empty; +%rename("include?" ) *::__contains__ const; +%rename("has_key?" ) *::has_key const; +%alias push "<<"; +%alias push_back "<<"; diff --git a/Lib/ruby/rubytracking.swg b/Lib/ruby/rubytracking.swg index c7fc345e0..03a28d467 100644 --- a/Lib/ruby/rubytracking.swg +++ b/Lib/ruby/rubytracking.swg @@ -49,7 +49,7 @@ SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) { This is done to allow multiple DSOs to share the same tracking table. */ - ID trackings_id = rb_intern( "trackings" ); + ID trackings_id = rb_intern( "@__trackings__" ); VALUE verbose = rb_gv_get("VERBOSE"); rb_gv_set("VERBOSE", Qfalse); swig_ruby_trackings = rb_ivar_get( _mSWIG, trackings_id ); diff --git a/Lib/ruby/rubywstrings.swg b/Lib/ruby/rubywstrings.swg index 69404a34e..bf7e369e1 100644 --- a/Lib/ruby/rubywstrings.swg +++ b/Lib/ruby/rubywstrings.swg @@ -1,3 +1,16 @@ +/** + * @file rubywstrings.swg + * @author + * @date Fri May 4 17:49:40 2007 + * + * @brief Currently, Ruby does not support Unicode or WChar properly, so these + * are still treated as char arrays for now. + * There are other libraries available that add support to this in + * ruby including WString, FXString, etc. + * + * + */ + /* ------------------------------------------------------------ * utility methods for wchar_t strings * ------------------------------------------------------------ */ @@ -6,39 +19,38 @@ SWIGINTERN int SWIG_AsWCharPtrAndSize(VALUE obj, wchar_t **cptr, size_t *psize, int *alloc) { - VALUE tmp = 0; - bool ok = false; - if ( TYPE(obj) == T_STRING ) { - if (cptr) { -// obj = tmp = PyUnicode_FromObject(obj); - rb_notimplement(); - ok = true; - } - } - if (ok) { + return SWIG_AsCharPtrAndSize( obj, (char**)cptr, psize, alloc); +// VALUE tmp = 0; +// bool ok = false; +// if ( TYPE(obj) == T_STRING ) { +// if (cptr) { +// obj = tmp = SWIG_Unicode_FromObject(obj); +// ok = true; +// } +// } +// if (ok) { // int len = PyUnicode_GetSize(obj); - rb_notimplement(); - if (cptr) { - *cptr = %new_array(len + 1, wchar_t); -// PyUnicode_AsWideChar((PyUnicodeObject *)obj, *cptr, len); - rb_notimplement(); - (*cptr)[len] = 0; - } - if (psize) *psize = (size_t) len + 1; - if (alloc) *alloc = cptr ? SWIG_NEWOBJ : 0; - return SWIG_OK; - } else { - swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor(); - if (pwchar_descriptor) { - void * vptr = 0; - if (SWIG_ConvertPtr(obj, &vptr, pwchar_descriptor, 0) == SWIG_OK) { - if (cptr) *cptr = (wchar_t *)vptr; - if (psize) *psize = vptr ? (wcslen((wchar_t *)vptr) + 1) : 0; - return SWIG_OK; - } - } - } - return SWIG_TypeError; +// rb_notimplement(); +// if (cptr) { +// *cptr = %new_array(len + 1, wchar_t); +// SWIG_Unicode_AsWideChar((PyUnicodeObject *)obj, *cptr, len); +// (*cptr)[len] = 0; +// } +// if (psize) *psize = (size_t) len + 1; +// if (alloc) *alloc = cptr ? SWIG_NEWOBJ : 0; +// return SWIG_OK; +// } else { +// swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor(); +// if (pwchar_descriptor) { +// void * vptr = 0; +// if (SWIG_ConvertPtr(obj, &vptr, pwchar_descriptor, 0) == SWIG_OK) { +// if (cptr) *cptr = (wchar_t *)vptr; +// if (psize) *psize = vptr ? (wcslen((wchar_t *)vptr) + 1) : 0; +// return SWIG_OK; +// } +// } +// } +// return SWIG_TypeError; } } @@ -46,18 +58,18 @@ SWIG_AsWCharPtrAndSize(VALUE obj, wchar_t **cptr, size_t *psize, int *alloc) SWIGINTERNINLINE VALUE SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size) { - if (carray) { - if (size > INT_MAX) { - swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor(); - return pwchar_descriptor ? - SWIG_NewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : Qnil; - } else { - rb_notimplement(); - // return PyUnicode_FromWideChar(carray, %numeric_cast(size,int)); - } - } else { - return Qnil; - } + return SWIG_FromCharPtrAndSize( (const char**)cptr, size); +// if (carray) { +// if (size > INT_MAX) { +// swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor(); +// return pwchar_descriptor ? +// SWIG_NewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : Qnil; +// } else { +// return SWIG_Unicode_FromWideChar(carray, %numeric_cast(size,int)); +// } +// } else { +// return Qnil; +// } } } diff --git a/Lib/ruby/std_deque.i b/Lib/ruby/std_deque.i index 17e78efe9..38048aff7 100644 --- a/Lib/ruby/std_deque.i +++ b/Lib/ruby/std_deque.i @@ -21,6 +21,9 @@ } %} +%ignore std::deque::push_back; +%ignore std::deque::pop_back; + #define %swig_deque_methods(Type...) %swig_sequence_methods(Type) #define %swig_deque_methods_val(Type...) %swig_sequence_methods_val(Type); diff --git a/Lib/ruby/std_list.i b/Lib/ruby/std_list.i index adc7d6f49..caeb841a9 100644 --- a/Lib/ruby/std_list.i +++ b/Lib/ruby/std_list.i @@ -21,6 +21,9 @@ } %} +%ignore std::list::push_back; +%ignore std::list::pop_back; + #define %swig_list_methods(Type...) %swig_sequence_methods(Type) #define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type); diff --git a/Lib/ruby/std_map.i b/Lib/ruby/std_map.i index 9ac5e499d..69d71e453 100644 --- a/Lib/ruby/std_map.i +++ b/Lib/ruby/std_map.i @@ -137,8 +137,7 @@ %extend { - %rename("delete") __delitem__; - VALUE __delitem__(const key_type& key) { + VALUE __delete__(const key_type& key) { Map::iterator i = self->find(key); if (i != self->end()) { self->erase(i); @@ -149,7 +148,6 @@ } } - %rename("has_key?") has_key; bool has_key(const key_type& key) const { Map::const_iterator i = self->find(key); return i != self->end(); @@ -306,7 +304,6 @@ return ary; } - %rename("include?") __contains__; bool __contains__(const key_type& key) { return self->find(key) != self->end(); } @@ -399,16 +396,6 @@ %enddef -#if defined(SWIG_RUBY_AUTORENAME) - - %mixin std::map "Enumerable"; - %rename("empty?") std::map::empty; - -#else - - %mixin std::map "Enumerable"; - %rename("empty?") std::map::empty; - -#endif +%mixin std::map "Enumerable"; %include diff --git a/Lib/ruby/std_multimap.i b/Lib/ruby/std_multimap.i index 9f2415df1..b5168bb47 100644 --- a/Lib/ruby/std_multimap.i +++ b/Lib/ruby/std_multimap.i @@ -211,17 +211,7 @@ %enddef -#if defined(SWIG_RUBY_AUTORENAME) - - %mixin std::multimap "Enumerable"; - %rename("empty?") std::multimap::empty; - -#else - - %mixin std::multimap "Enumerable"; - %rename("empty?") std::multimap::empty; - -#endif +%mixin std::multimap "Enumerable"; %include diff --git a/Lib/ruby/std_set.i b/Lib/ruby/std_set.i index a66d037a8..c0f529b9c 100644 --- a/Lib/ruby/std_set.i +++ b/Lib/ruby/std_set.i @@ -45,7 +45,6 @@ return x; } - %rename("include?") __contains__; bool __contains__(const value_type& x) { return self->find(x) != self->end(); } @@ -57,17 +56,7 @@ }; %enddef -#if defined(SWIG_RUBY_AUTORENAME) - - %mixin std::set "Enumerable"; - %rename("empty?") std::set::empty; - -#else - - %mixin std::set "Enumerable"; - %rename("empty?") std::set::empty; - -#endif +%mixin std::set "Enumerable"; %include diff --git a/Lib/ruby/std_string.i b/Lib/ruby/std_string.i index d1c4d8a23..cac4324f0 100644 --- a/Lib/ruby/std_string.i +++ b/Lib/ruby/std_string.i @@ -5,8 +5,5 @@ AUTODOC(substr, "Return a portion of the String"); -%rename("empty?") std::string::empty; -%rename("empty?") std::basic_string::empty; - %include diff --git a/Lib/ruby/std_vector.i b/Lib/ruby/std_vector.i index a5072351c..129676b83 100644 --- a/Lib/ruby/std_vector.i +++ b/Lib/ruby/std_vector.i @@ -34,21 +34,9 @@ %enddef -#if defined(SWIG_RUBY_AUTORENAME) - - %mixin std::vector "Enumerable"; - %rename("empty?") std::vector::empty; - %ignore std::vector::push_back; - %ignore std::vector::pop_back; - -#else - - %mixin std::vector "Enumerable"; - %rename("empty?") std::vector::empty; - %ignore std::vector::push_back; - %ignore std::vector::pop_back; - -#endif +%mixin std::vector "Enumerable"; +%ignore std::vector::push_back; +%ignore std::vector::pop_back; %include diff --git a/Lib/ruby/std_vectora.i b/Lib/ruby/std_vectora.i index 5c8e0ee3f..1708361ef 100644 --- a/Lib/ruby/std_vectora.i +++ b/Lib/ruby/std_vectora.i @@ -28,18 +28,9 @@ #define %swig_vector_methods(Type...) %swig_sequence_methods(Type) #define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type); -#if defined(SWIG_RUBY_AUTORENAME) - - %rename("empty?") std::vector::empty; - %ignore std::vector::push_back; - %ignore std::vector::pop_back; - %alias std::vector::push "<<"; - -#else - %rename("empty?") std::vector::empty; - %ignore std::vector::push_back; - %ignore std::vector::pop_back; - %alias std::vector::push "<<"; -#endif +%mixin std::vector "Enumerable"; +%ignore std::vector::push_back; +%ignore std::vector::pop_back; +%alias std::vector::push "<<"; %include