Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/fox16_c/FXRbApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* $Id: FXRbApp.cpp 2902 2008-12-11 14:09:20Z lyle $
***********************************************************************/

#include "swigruby.h"
#include "FXRbCommon.h"

#ifdef HAVE_SYS_TIME_H
Expand Down
1 change: 1 addition & 0 deletions ext/fox16_c/FXRbDataTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* $Id: FXRbDataTarget.cpp 2713 2007-11-14 15:27:36Z lyle $
***********************************************************************/

#include "swigruby.h"
#include "FXRbCommon.h"

/**
Expand Down
1 change: 1 addition & 0 deletions ext/fox16_c/FXRbGLViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* $Id: FXRbGLViewer.cpp 2190 2005-08-24 07:58:47Z lyle $
***********************************************************************/

#include "swigruby.h"
#include "FXRbCommon.h"

// Process picks
Expand Down
15 changes: 11 additions & 4 deletions ext/fox16_c/FXRbObjRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
* at "lars@greiz-reinsdorf.de".
***********************************************************************/

#include "swigruby.h"
#include "FXRbCommon.h"
#include "FXRbObjRegistry.h"
#include "swigruby.h"

FXRbObjRegistry::FXRbObjRegistry(){
FXRuby_Objects=st_init_numtable();
Expand Down Expand Up @@ -52,7 +52,7 @@ VALUE FXRbObjRegistry::NewBorrowedObj(void *ptr,swig_type_info* ty){
ObjDesc *desc;

if(FXMALLOC(&desc,ObjDesc,1)){
VALUE obj = SWIG_Ruby_NewPointerObj(ptr,ty,1);
VALUE obj = SWIG_Ruby_NewPointerObj(ptr,ty,SWIG_POINTER_OWN);
FXTRACE((1,"FXRbNewPointerObj(foxObj=%p) => rubyObj=%p (%s)\n",ptr,(void *)obj,safe_rb_obj_classname(obj)));
desc->obj = obj;
desc->type = borrowed;
Expand Down Expand Up @@ -84,7 +84,7 @@ void FXRbObjRegistry::RegisterRubyObj(VALUE rubyObj,const void* foxObj) {
* To avoid double references to the same foxObj from different Ruby objects,
* we decouple the foxObj from previoius ruby object and point to the new one.
*/
DATA_PTR(desc->obj) = 0;
FXRbConvertPtr(desc->obj, NULL, SWIG_POINTER_RELEASE);
desc->obj = rubyObj;
desc->type = own;
} else {
Expand All @@ -107,7 +107,14 @@ void FXRbObjRegistry::UnregisterRubyObj(const void* foxObj, bool alsoOwned){
if(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(&desc))!=0){
if( !alsoOwned && desc->type!=borrowed ) return;
FXTRACE((1,"FXRbUnregisterRubyObj(rubyObj=%p (%s),foxObj=%p)\n",(void *)desc->obj,safe_rb_obj_classname(desc->obj),foxObj));
DATA_PTR(desc->obj)=0;

/* Release unless it's already T_ZOMBIE */
if(RB_TYPE_P(desc->obj, RUBY_T_DATA)) {
int res = SWIG_ConvertPtr(desc->obj, NULL, NULL, SWIG_POINTER_CLEAR);
if (res != SWIG_OK){
rb_bug( "UnregisterRubyObj(rubyObj=%p) error: %d", (void*)desc->obj, res);
}
}
FXFREE(&desc);
st_delete(FXRuby_Objects,reinterpret_cast<st_data_t *>(const_cast<void**>(&foxObj)),reinterpret_cast<st_data_t *>(0));
FXASSERT(st_lookup(FXRuby_Objects,reinterpret_cast<st_data_t>(const_cast<void*>(foxObj)),reinterpret_cast<st_data_t *>(0))==0);
Expand Down
71 changes: 47 additions & 24 deletions ext/fox16_c/FXRuby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
#pragma warning (disable : 4786)
#endif

// SWIG runtime functions we need
#include "swigruby.h"

#include "FXRbCommon.h"
#include "FXRbObjRegistry.h"
#include "impl.h"

// SWIG runtime functions we need
#include "swigruby.h"

#ifdef __CYGWIN__
#include <io.h> // for get_osf_handle()
#endif
Expand Down Expand Up @@ -74,7 +74,7 @@ VALUE FXRbNewPointerObj(void *ptr,swig_type_info* ty){
}

VALUE FXRbNewPointerObjCb(void *ptr,swig_type_info* ty){
return SWIG_Ruby_NewPointerObj(ptr, ty, 1);
return SWIG_Ruby_NewPointerObj(ptr, ty, SWIG_POINTER_OWN);
}


Expand Down Expand Up @@ -842,8 +842,7 @@ void* FXRbGetExpectedData(VALUE recv,FXSelector key,VALUE value){
FXushort id=FXSELID(key);

// Extract the FOX object (the receiver) from this Ruby instance
FXObject* obj;
Data_Get_Struct(recv,FXObject,obj);
FXObject *obj = (FXObject*)FXRbConvertPtr(recv, NULL, 0);

FXASSERT(type!=SEL_NONE);
FXASSERT(type!=SEL_LAST);
Expand Down Expand Up @@ -896,7 +895,7 @@ void* FXRbGetExpectedData(VALUE recv,FXSelector key,VALUE value){
case SEL_DND_MOTION:
case SEL_DND_REQUEST:
case SEL_PICKED:
SWIG_ConvertPtr(value,&ptr,FXRbTypeQuery("FXEvent *"),1);
SWIG_ConvertPtr(value,&ptr,FXRbTypeQuery("FXEvent *"),SWIG_POINTER_DISOWN);
return ptr;
case SEL_IO_READ:
case SEL_IO_WRITE:
Expand Down Expand Up @@ -1072,7 +1071,7 @@ void* FXRbGetExpectedData(VALUE recv,FXSelector key,VALUE value){

if(type==SEL_CHANGED){
if(obj->isMemberOf(FXMETACLASS(FXPicker))){
SWIG_ConvertPtr(value,&ptr,FXRbTypeQuery("FXPoint *"),1);
SWIG_ConvertPtr(value,&ptr,FXRbTypeQuery("FXPoint *"),SWIG_POINTER_DISOWN);
return ptr;
}
if(obj->isMemberOf(FXMETACLASS(FXWindow))){
Expand All @@ -1086,7 +1085,7 @@ void* FXRbGetExpectedData(VALUE recv,FXSelector key,VALUE value){
}

if(type==SEL_DRAGGED){
SWIG_ConvertPtr(value,&ptr,FXRbTypeQuery("FXEvent *"),1);
SWIG_ConvertPtr(value,&ptr,FXRbTypeQuery("FXEvent *"),SWIG_POINTER_DISOWN);
return ptr;
}

Expand Down Expand Up @@ -1300,21 +1299,21 @@ FXGLObject* FXRbCallGLObjectMethod_gvlcb(FXGLObject* recv,const char *func){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),0);
return NIL_P(result) ? 0 : reinterpret_cast<FXGLObject*>(DATA_PTR(result));
return (FXGLObject*)FXRbConvertPtr(result, NULL, 0);
}

FXGLObject* FXRbCallGLObjectMethod_gvlcb(FXGLViewer* recv,const char *func,FXint x,FXint y){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),2,INT2NUM(x),INT2NUM(y));
return NIL_P(result) ? 0 : reinterpret_cast<FXGLObject*>(DATA_PTR(result));
return (FXGLObject*)FXRbConvertPtr(result, NULL, 0);
}

FXGLObject* FXRbCallGLObjectMethod_gvlcb(FXGLObject* recv,const char *func,FXuint* path,FXint n){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),1,FXRbMakeArray(path,n));
return NIL_P(result) ? 0 : reinterpret_cast<FXGLObject*>(DATA_PTR(result));
return (FXGLObject*)FXRbConvertPtr(result, NULL, 0);
}

//----------------------------------------------------------------------
Expand All @@ -1329,7 +1328,8 @@ FXGLObject** FXRbCallGLObjectArrayMethod_gvlcb(FXGLViewer* recv,const char *func
Check_Type(result,T_ARRAY);
if(FXMALLOC(&objects,FXGLObject*,RARRAY_LEN(result)+1)){
for(long i=0; i<RARRAY_LEN(result); i++){
objects[i]=reinterpret_cast<FXGLObject*>(DATA_PTR(rb_ary_entry(result,i)));
VALUE entry = rb_ary_entry(result,i);
objects[i]=(FXGLObject*)FXRbConvertPtr(entry, NULL, 0);
}
objects[RARRAY_LEN(result)]=0;
}
Expand All @@ -1344,14 +1344,14 @@ FXTableItem* FXRbCallTableItemMethod_gvlcb(FXTable* recv,const char *func,const
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),3,to_ruby(text),to_ruby_cb(icon),itemData);
return NIL_P(result)?0:reinterpret_cast<FXTableItem*>(DATA_PTR(result));
return (FXTableItem*)FXRbConvertPtr(result, NULL, 0);
}

FXTableItem* FXRbCallTableItemMethod_gvlcb(FXTable* recv,const char *func,FXint row,FXint col,FXbool notify){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),3,to_ruby(row),to_ruby(col),to_ruby(notify));
return NIL_P(result)?0:reinterpret_cast<FXTableItem*>(DATA_PTR(result));
return (FXTableItem*)FXRbConvertPtr(result, NULL, 0);
}

//----------------------------------------------------------------------
Expand All @@ -1360,7 +1360,7 @@ FXTreeItem* FXRbCallTreeItemMethod_gvlcb(const FXTreeList* recv,const char *func
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),2,INT2NUM(x),INT2NUM(y));
return NIL_P(result) ? 0 : reinterpret_cast<FXTreeItem*>(DATA_PTR(result));
return (FXTreeItem*)FXRbConvertPtr(result, NULL, 0);
}

//----------------------------------------------------------------------
Expand All @@ -1369,7 +1369,7 @@ FXFoldingItem* FXRbCallFoldingItemMethod_gvlcb(const FXFoldingList* recv,const c
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),2,INT2NUM(x),INT2NUM(y));
return NIL_P(result) ? 0 : reinterpret_cast<FXFoldingItem*>(DATA_PTR(result));
return (FXFoldingItem*)FXRbConvertPtr(result, NULL, 0);
}

//----------------------------------------------------------------------
Expand All @@ -1378,7 +1378,7 @@ FXFileAssoc* FXRbCallFileAssocMethod_gvlcb(const FXFileDict* recv,const char *fu
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),1,to_ruby(pathname));
return NIL_P(result) ? 0 : reinterpret_cast<FXFileAssoc*>(DATA_PTR(result));
return (FXFileAssoc*)FXRbConvertPtr(result, NULL, 0);
}

//----------------------------------------------------------------------
Expand All @@ -1388,7 +1388,7 @@ FXIcon* FXRbCallIconMethod_gvlcb(const FXTableItem* recv,const char *func){
FXASSERT(!NIL_P(obj));
if(!NIL_P(obj)){
VALUE result=rb_funcall(obj,rb_intern(func),0);
return NIL_P(result) ? 0 : reinterpret_cast<FXIcon*>(DATA_PTR(result));
return (FXIcon*)FXRbConvertPtr(result, NULL, 0);
}
else{
return 0;
Expand All @@ -1401,7 +1401,7 @@ FXWindow* FXRbCallWindowMethod_gvlcb(const FXTableItem* recv,const char *func,FX
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),1,to_ruby_cb(table));
return NIL_P(result) ? 0 : reinterpret_cast<FXWindow*>(DATA_PTR(result));
return (FXWindow*)FXRbConvertPtr(result, NULL, 0);
}

//----------------------------------------------------------------------
Expand All @@ -1411,7 +1411,7 @@ FXRangef FXRbCallRangeMethod_gvlcb(FXObject* recv,const char *func){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),0);
return *reinterpret_cast<FXRangef*>(DATA_PTR(result));
return *(FXRangef*)FXRbConvertPtr(result, NULL, 0);
}

//----------------------------------------------------------------------
Expand Down Expand Up @@ -1606,11 +1606,34 @@ FXbool FXRbGLViewer::sortProc(FXfloat*& buffer,FXint& used,FXint& size){
* FXRbConvertPtr() is just a wrapper around SWIG_ConvertPtr().
*/

void* FXRbConvertPtr(VALUE obj,swig_type_info* ty){
void* FXRbConvertPtr(VALUE obj,swig_type_info* ty, int flags){
void *ptr;
SWIG_ConvertPtr(obj,&ptr,ty,1);
return ptr;
int res = SWIG_ConvertPtr(obj,&ptr,ty,flags);
if( res == SWIG_OK ) return ptr;
#ifdef HAVE_RB_DURING_GC
if( rb_during_gc() ){
rb_bug( "FXRbConvertPtr got wrong argument type rubyObj=%p", (void*)obj);
}
#endif
if( res == SWIG_ERROR_RELEASE_NOT_OWNED ){
rb_raise( rb_eTypeError, "clean and disown of non-owned object is not allowed: %" PRIsVALUE, obj);
}
if( res == SWIG_NullReferenceError ){
rb_raise( rb_eTypeError, "object can not be NULL: %" PRIsVALUE, obj);
}
if( res == SWIG_ObjectPreviouslyDeletedError ){
if(ty){
rb_raise( rb_eTypeError, "the object has already been deleted: %" PRIsVALUE, ((swig_class *) (ty->clientdata))->klass);
} else {
rb_raise( rb_eTypeError, "the object has already been deleted");
}
}
if(ty){
rb_raise( rb_eTypeError, "wrong argument type %" PRIsVALUE ", expected kind of %" PRIsVALUE, rb_obj_class(obj), ((swig_class *) (ty->clientdata))->klass );
} else {
rb_raise( rb_eTypeError, "wrong argument type %" PRIsVALUE, rb_obj_class(obj) );
}
}


// Returns an FXInputHandle for this Ruby file object
Expand Down
3 changes: 2 additions & 1 deletion ext/fox16_c/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def install
if enable_config("debug")
$CPPFLAGS += " -ggdb"
$LDFLAGS += " -ggdb"
$CPPFLAGS += " -DRUBY_DEBUG=1" # define RUBY_DEBUG otherwise ruby/assert.h defines NDEBUG
else
$CPPFLAGS += " -DNDEBUG"
end
Expand All @@ -366,7 +367,7 @@ def install
if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc/
$CXXFLAGS += " -Wno-unused-function"
$CXXFLAGS += " -Wno-maybe-uninitialized"
$CXXFLAGS += " -Wno-attribute-warning -Wno-deprecated-declarations"
$CXXFLAGS += " -Wno-attribute-warning"
end

# Last step: build the makefile
Expand Down
1 change: 1 addition & 0 deletions ext/fox16_c/gvl_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
*/

#include "swigruby.h"
#include "FXRbCommon.h"

#ifdef HAVE___THREAD
Expand Down
1 change: 1 addition & 0 deletions ext/fox16_c/impl.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "swigruby.h"
#include "FXRbCommon.h"
/* Start stub implementations for class FXMemoryBuffer */

Expand Down
2 changes: 1 addition & 1 deletion ext/fox16_c/include/FXRbDCWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FXRbDCWindow : public FXDCWindow {

// Helper for FXDCWindow initialization block
static VALUE endit(VALUE obj){
FXDCWindow* dc=reinterpret_cast<FXDCWindow*>(DATA_PTR(obj));
FXDCWindow* dc=(FXDCWindow*)FXRbConvertPtr(obj, NULL, 0);
FXASSERT(dc!=0);
dc->end();
return Qnil;
Expand Down
12 changes: 6 additions & 6 deletions ext/fox16_c/include/FXRuby.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static int FXSWIG_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flag
template <class TYPE>
VALUE showHelper(VALUE self, int argc, VALUE *argv, TYPE *p, swig_type_info *typeinfo) {
TYPE *win;
FXSWIG_ConvertPtr(self,(void**)&win,typeinfo,1);
FXSWIG_ConvertPtr(self,(void**)&win,typeinfo,SWIG_POINTER_DISOWN);
if (argc == 0) {
win->_show();
}
Expand All @@ -73,7 +73,7 @@ bool FXRbIsInGC(const void* ptr);
swig_type_info *FXRbTypeQuery(const char *name);

// Wrapper around SWIG_ConvertPtr()
void* FXRbConvertPtr(VALUE obj,swig_type_info* typeinfo);
void* FXRbConvertPtr(VALUE obj,swig_type_info* typeinfo, int flags);

// Returns an FXInputHandle for this Ruby file object
FXInputHandle FXRbGetReadFileHandle(VALUE obj,FXuint mode);
Expand Down Expand Up @@ -694,15 +694,15 @@ FXIcon* FXRbCallIconMethod_gvlcb(const FXIconSource *recv,const char *func,TYPE1
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),2,to_ruby(arg1),to_ruby(arg2));
return NIL_P(result) ? 0 : reinterpret_cast<FXIcon*>(DATA_PTR(result));
return (FXIcon*)FXRbConvertPtr(result, NULL, 0);
}

template<class TYPE1, class TYPE2, class TYPE3, class TYPE4>
FXIcon* FXRbCallIconMethod_gvlcb(const FXIconSource *recv,const char *func,TYPE1& arg1,TYPE2 arg2,TYPE3 arg3,const TYPE4& arg4){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),4,to_ruby(arg1),to_ruby(arg2),to_ruby(arg3),to_ruby(arg4));
return NIL_P(result) ? 0 : reinterpret_cast<FXIcon*>(DATA_PTR(result));
return (FXIcon*)FXRbConvertPtr(result, NULL, 0);
}

// Call functions with FXImage* return value
Expand All @@ -711,15 +711,15 @@ FXImage* FXRbCallImageMethod_gvlcb(const FXIconSource *recv,const char *func,TYP
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),2,to_ruby(arg1),to_ruby(arg2));
return NIL_P(result) ? 0 : reinterpret_cast<FXImage*>(DATA_PTR(result));
return (FXImage*)FXRbConvertPtr(result, NULL, 0);
}

template<class TYPE1, class TYPE2, class TYPE3, class TYPE4>
FXImage* FXRbCallImageMethod_gvlcb(const FXIconSource *recv,const char *func,TYPE1& arg1,TYPE2 arg2,TYPE3 arg3,const TYPE4& arg4){
VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,rb_intern(func),4,to_ruby(arg1),to_ruby(arg2),to_ruby(arg3),to_ruby(arg4));
return NIL_P(result) ? 0 : reinterpret_cast<FXImage*>(DATA_PTR(result));
return (FXImage*)FXRbConvertPtr(result, NULL, 0);
}

// Call functions with "FXWindow*" return value
Expand Down
1 change: 1 addition & 0 deletions ext/fox16_c/make_impl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def end_class

fcpp = File.new('impl.cpp', 'wb')
finc = File.new('./include/inlinestubs.h', 'wb')
fcpp.puts '#include "swigruby.h"'
fcpp.puts '#include "FXRbCommon.h"'
Dir.glob("./include/FX*.h").sort.each do |file|
unless file =~ /BitmapView/
Expand Down
1 change: 1 addition & 0 deletions ext/fox16_c/markfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* $Id: markfuncs.cpp 2928 2008-12-29 19:16:57Z lyle $
***********************************************************************/

#include "swigruby.h"
#include "FXRbCommon.h"

#ifdef MARK
Expand Down
1 change: 1 addition & 0 deletions ext/fox16_c/unregisterOwnedObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* but which have somehow been "exposed" to the Ruby layer.
*/

#include "swigruby.h"
#include "FXRbCommon.h"

void FXRbHeader::unregisterOwnedObjects(FXHeader *self)
Expand Down
Loading
Loading