[Fxruby-commits] CVS: FXRuby/ext/fox FXRuby.cpp,1.40.2.4,1.40.2.5
Status: Inactive
Brought to you by:
lyle
|
From: Lyle J. <ly...@us...> - 2002-05-24 17:36:19
|
Update of /cvsroot/fxruby/FXRuby/ext/fox
In directory usw-pr-cvs1:/tmp/cvs-serv31799/ext/fox
Modified Files:
Tag: release10
FXRuby.cpp
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.cpp
===================================================================
RCS file: /cvsroot/fxruby/FXRuby/ext/fox/FXRuby.cpp,v
retrieving revision 1.40.2.4
retrieving revision 1.40.2.5
diff -C2 -d -r1.40.2.4 -r1.40.2.5
*** FXRuby.cpp 14 May 2002 14:15:42 -0000 1.40.2.4
--- FXRuby.cpp 24 May 2002 17:36:15 -0000 1.40.2.5
***************
*** 50,60 ****
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);
- }
-
// Wrapper around SWIG_TypeQuery() that caches results for performance
swig_type_info *FXRbTypeQuery(const char *desc){
--- 50,53 ----
***************
*** 160,163 ****
--- 153,157 ----
*/
VALUE FXRbGetRubyObj(const void *foxObj,FXbool searchBoth){
+ FXASSERT(foxObj);
std::map<const void*,VALUE>::const_iterator itr=FXRuby_ObjMap.find(foxObj);
if(itr!=FXRuby_ObjMap.end()){
***************
*** 173,182 ****
}
-
/**
* Return the registered Ruby class instance associated with this
* FOX object, or a new registered instance if not found.
*/
! VALUE FXRbGetRubyObj(const void *foxObj, const char *type){
VALUE rbObj=FXRbGetRubyObj(foxObj,TRUE);
return (rbObj==Qnil) ? FXRbNewPointerObj(const_cast<void*>(foxObj), FXRbTypeQuery(type)) : rbObj;
--- 167,175 ----
}
/**
* Return the registered Ruby class instance associated with this
* FOX object, or a new registered instance if not found.
*/
! VALUE FXRbGetRubyObj(const void *foxObj,const char *type){
VALUE rbObj=FXRbGetRubyObj(foxObj,TRUE);
return (rbObj==Qnil) ? FXRbNewPointerObj(const_cast<void*>(foxObj), FXRbTypeQuery(type)) : rbObj;
***************
*** 443,447 ****
type == SEL_DESELECTED ||
type == SEL_INSERTED ||
! type == SEL_DELETED) return to_ruby((FXTableRange*)ptr);
}
else if(sender->isMemberOf(FXMETACLASS(FXText))){
--- 436,442 ----
type == SEL_DESELECTED ||
type == SEL_INSERTED ||
! type == SEL_DELETED){
! return to_ruby(reinterpret_cast<FXTableRange*>(ptr));
! }
}
else if(sender->isMemberOf(FXMETACLASS(FXText))){
|