Update of /cvsroot/fxruby/FXRuby/ext/fox/include
In directory usw-pr-cvs1:/tmp/cvs-serv31799/ext/fox/include
Modified Files:
Tag: release10
FXRuby.h
Log Message:
Removed the typemaps for FXTableRange and FXTablePos output values which
would previously have tried to look up existing Ruby references to the
same C++ pointers and return those. This practice (which works fine in
most cases) was leading to an obscure bug (see SF Bug #560128). The sequence
of events would go something like this:
1. We create a Ruby FXTableRange instance associated with the C++
FXTableRange instance which lives at memory location 'x'.
2. We next attempt to create a Ruby FXTablePos instance associated
with the C++ FXTablePos instance which is the first member of the
previous FXTableRange struct. Since it's the first member, its
memory address is the same as that of the FXTableRange itself.
3. We look up the address of this FXTablePos object and of course the
address *is* already there; we stored it when we looked up the
enclosing FXTableRange object. So we return a reference to that
FXTableRange instead of a new reference to an FXTablePos.
For now, I've just modified the typemaps for these two structs so that
you always get a new reference (i.e. it doesn't attempt to look up
previously returned refs.) But since this could happen again the correct
fix is probably to store both the pointer and the type in our hash table
to be more safe.
Index: FXRuby.h
===================================================================
RCS file: /cvsroot/fxruby/FXRuby/ext/fox/include/FXRuby.h,v
retrieving revision 1.21.2.4
retrieving revision 1.21.2.5
diff -C2 -d -r1.21.2.4 -r1.21.2.5
*** FXRuby.h 14 May 2002 14:16:03 -0000 1.21.2.4
--- FXRuby.h 24 May 2002 17:36:16 -0000 1.21.2.5
***************
*** 31,34 ****
--- 31,41 ----
struct swig_type_info;
+ // SWIG runtime functions we need
+ extern "C" {
+ swig_type_info * SWIG_TypeQuery(const char *);
+ VALUE SWIG_NewPointerObj(void *ptr, swig_type_info *type, int own);
+ void * SWIG_ConvertPtr(VALUE obj, swig_type_info *ty);
+ }
+
// Helper for overloaded show() functions
template <class TYPE>
***************
*** 232,240 ****
inline VALUE to_ruby(FXTablePos* p){
! return FXRbNewPointerObj(static_cast<void*>(p),FXRbTypeQuery("FXTablePos *"));
}
inline VALUE to_ruby(FXTableRange* r){
! return FXRbNewPointerObj(static_cast<void*>(r),FXRbTypeQuery("FXTableRange *"));
}
--- 239,249 ----
inline VALUE to_ruby(FXTablePos* p){
! // return FXRbNewPointerObj(static_cast<void*>(p),FXRbTypeQuery("FXTablePos *"));
! return SWIG_NewPointerObj(static_cast<void*>(p),FXRbTypeQuery("FXTablePos *"),0);
}
inline VALUE to_ruby(FXTableRange* r){
! // return FXRbNewPointerObj(static_cast<void*>(r),FXRbTypeQuery("FXTableRange *"));
! return SWIG_NewPointerObj(static_cast<void*>(r),FXRbTypeQuery("FXTableRange *"),0);
}
|