Improved ruby trackings across DSOs, removing the
need for -DSWIG_EXTERN. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9699 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
15393d5ead
commit
18f614364f
3 changed files with 27 additions and 23 deletions
|
|
@ -95,3 +95,6 @@
|
||||||
#define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new")
|
#define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Global module used to keep some internal SWIG stuff */
|
||||||
|
static VALUE _mSWIG = Qnil;
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,6 @@ typedef struct {
|
||||||
} swig_class;
|
} swig_class;
|
||||||
|
|
||||||
|
|
||||||
static VALUE _mSWIG = Qnil;
|
|
||||||
static VALUE _cSWIG_Pointer = Qnil;
|
static VALUE _cSWIG_Pointer = Qnil;
|
||||||
static VALUE swig_runtime_data_type_pointer = Qnil;
|
static VALUE swig_runtime_data_type_pointer = Qnil;
|
||||||
|
|
||||||
|
|
@ -196,7 +195,10 @@ SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a new Ruby object */
|
/* Create a new Ruby object */
|
||||||
obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), (own ? VOIDFUNC(sklass->destroy) : (track ? VOIDFUNC(SWIG_RubyRemoveTracking) : 0 )), ptr);
|
obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark),
|
||||||
|
( own ? VOIDFUNC(sklass->destroy) :
|
||||||
|
(track ? VOIDFUNC(SWIG_RubyRemoveTracking) : 0 )
|
||||||
|
), ptr);
|
||||||
|
|
||||||
/* If tracking is on for this class then track this object. */
|
/* If tracking is on for this class then track this object. */
|
||||||
if (track) {
|
if (track) {
|
||||||
|
|
|
||||||
|
|
@ -28,41 +28,40 @@ extern "C" {
|
||||||
# define NUM2SWIG(x) (unsigned long)NUM2LONG(x)
|
# define NUM2SWIG(x) (unsigned long)NUM2LONG(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Global Ruby hash table to store Trackings from C/C++
|
/* Global Ruby hash table to store Trackings from C/C++
|
||||||
structs to Ruby Objects.
|
structs to Ruby Objects.
|
||||||
If you SWIG a library into two different DSO or DLL, make
|
|
||||||
sure to define SWIGEXTERN for all but one of them.
|
|
||||||
This will then create a single hash table for all your
|
|
||||||
library symbols.
|
|
||||||
*/
|
*/
|
||||||
#ifdef SWIGEXTERN
|
static VALUE swig_ruby_trackings = Qnil;
|
||||||
extern VALUE swig_ruby_trackings;
|
|
||||||
#else
|
|
||||||
VALUE swig_ruby_trackings = Qnil;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Global variable that stores a reference to the ruby
|
/* Global variable that stores a reference to the ruby
|
||||||
hash table delete function. */
|
hash table delete function. */
|
||||||
#ifdef SWIGEXTERN
|
static ID swig_ruby_hash_delete;
|
||||||
extern ID swig_ruby_hash_delete;
|
|
||||||
#else
|
|
||||||
ID swig_ruby_hash_delete;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Setup a Ruby hash table to store Trackings */
|
/* Setup a Ruby hash table to store Trackings */
|
||||||
SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) {
|
SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) {
|
||||||
/* Create a ruby hash table to store Trackings from C++
|
/* Create a ruby hash table to store Trackings from C++
|
||||||
objects to Ruby objects. Also make sure to tell
|
objects to Ruby objects. */
|
||||||
the garabage collector about the hash table. */
|
|
||||||
|
/* Try to see if some other .so has already created a
|
||||||
|
tracking hash table, which we keep hidden in an instance var
|
||||||
|
in the SWIG module.
|
||||||
|
This is done to allow multiple DSOs to share the same
|
||||||
|
tracking table.
|
||||||
|
*/
|
||||||
|
ID trackings_id = rb_intern( "trackings" );
|
||||||
|
swig_ruby_trackings = rb_ivar_get( _mSWIG, trackings_id );
|
||||||
|
|
||||||
|
/* No, it hasn't. Create one ourselves */
|
||||||
if ( swig_ruby_trackings == Qnil )
|
if ( swig_ruby_trackings == Qnil )
|
||||||
{
|
{
|
||||||
swig_ruby_trackings = rb_hash_new();
|
swig_ruby_trackings = rb_hash_new();
|
||||||
rb_gc_register_address(&swig_ruby_trackings);
|
rb_ivar_set( _mSWIG, trackings_id, swig_ruby_trackings );
|
||||||
|
|
||||||
/* Now store a reference to the hash table delete function
|
|
||||||
so that we only have to look it up once.*/
|
|
||||||
swig_ruby_hash_delete = rb_intern("delete");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Now store a reference to the hash table delete function
|
||||||
|
so that we only have to look it up once.*/
|
||||||
|
swig_ruby_hash_delete = rb_intern("delete");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a Ruby number to reference a pointer */
|
/* Get a Ruby number to reference a pointer */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue