Fixed ruby's newobject1 and newobject2 demos.

Added swig_assert.rb and started using it in some tests.
Added my patches to ruby.cxx, rubyrun.swg, rubystrings.swg
and rubytracking.swg [see: sourceforge]



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9691 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Gonzalo Garramuno 2007-04-28 04:20:28 +00:00
commit 4b8d11d0e2
111 changed files with 1309 additions and 50 deletions

View file

@ -82,6 +82,35 @@ static VALUE _mSWIG = Qnil;
static VALUE _cSWIG_Pointer = Qnil;
static VALUE swig_runtime_data_type_pointer = Qnil;
/*
If your swig extension is to be run within an embedded ruby and has
director callbacks, you should set RUBY_EMBEDDED. This will reset
ruby's stack frame on each entry point from the main program the first
time a virtual director function is invoked (in a non-recursive way).
If this is not done, you run the risk of trashing the stack.
*/
#ifndef RUBY_INIT_STACK
extern void Init_stack(VALUE* addr);
# define RUBY_INIT_STACK \
VALUE variable_in_this_stack_frame; \
Init_stack(&variable_in_this_stack_frame);
#endif
#ifdef RUBY_EMBEDDED
# define SWIG_INIT_STACK \
if ( !swig_virtual_calls ) { RUBY_INIT_STACK } \
++swig_virtual_calls;
# define SWIG_RELEASE_STACK --swig_virtual_calls;
static unsigned int swig_virtual_calls = 0;
#else
# define SWIG_INIT_STACK
# define SWIG_RELEASE_STACK
#endif
SWIGRUNTIME VALUE
getExceptionClass(void) {
static int init = 0;
@ -136,7 +165,7 @@ SWIGRUNTIME VALUE
SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
{
int own = flags & SWIG_POINTER_OWN;
int track;
char *klass_name;
swig_class *sklass;
VALUE klass;
@ -149,7 +178,8 @@ SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
sklass = (swig_class *) type->clientdata;
/* Are we tracking this class and have we already returned this Ruby object? */
if (sklass->trackObjects) {
track = sklass->trackObjects;
if (track) {
obj = SWIG_RubyInstanceFor(ptr);
/* Check the object's type and make sure it has the correct type.
@ -166,10 +196,10 @@ SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
}
/* Create a new Ruby object */
obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), (own ? VOIDFUNC(sklass->destroy) : 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 (sklass->trackObjects) {
if (track) {
SWIG_RubyAddTracking(ptr, obj);
}
} else {

View file

@ -7,11 +7,11 @@ SWIGINTERN int
SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)
{
if (TYPE(obj) == T_STRING) {
#if defined(StringValuePtr)
char *cstr = rb_string_value_ptr(&(obj));
#else
%#if defined(StringValuePtr)
char *cstr = StringValuePtr(obj);
%#else
char *cstr = STR2CSTR(obj);
#endif
%#endif
size_t size = RSTRING_LEN(obj) + 1;
if (cptr) {
if (alloc) {

View file

@ -14,26 +14,55 @@
extern "C" {
#endif
#if SIZEOF_OFF_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
# define SWIG2NUM(v) LL2NUM((unsigned long long)v)
#elif SIZEOF_OFF_T == SIZEOF_LONG
# define SWIG2NUM(v) LONG2NUM((unsigned long)v)
#else
# define SWIG2NUM(v) INT2NUM((unsigned long)v)
#endif
#if defined(HAVE_LONG_LONG) && SIZEOF_OFF_T > SIZEOF_LONG
# define NUM2SWIG(x) ((off_t)NUM2LL(x))
#else
# define NUM2SWIG(x) (unsigned long)NUM2LONG(x)
#endif
/* Global Ruby hash table to store Trackings from C/C++
structs to Ruby Objects. */
static VALUE swig_ruby_trackings;
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
extern VALUE swig_ruby_trackings;
#else
VALUE swig_ruby_trackings = Qnil;
#endif
/* Global variable that stores a reference to the ruby
hash table delete function. */
static ID swig_ruby_hash_delete = 0;
#ifdef SWIGEXTERN
extern ID swig_ruby_hash_delete;
#else
ID swig_ruby_hash_delete;
#endif
/* Setup a Ruby hash table to store Trackings */
SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) {
/* Create a ruby hash table to store Trackings from C++
objects to Ruby objects. Also make sure to tell
the garabage collector about the hash table. */
swig_ruby_trackings = rb_hash_new();
rb_gc_register_address(&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");
if ( swig_ruby_trackings == Qnil )
{
swig_ruby_trackings = rb_hash_new();
rb_gc_register_address(&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");
}
}
/* Get a Ruby number to reference a pointer */
@ -43,8 +72,7 @@ SWIGRUNTIME VALUE SWIG_RubyPtrToReference(void* ptr) {
a Ruby number object. */
/* Convert the pointer to a Ruby number */
unsigned long value = (unsigned long) ptr;
return LONG2NUM(value);
return SWIG2NUM(ptr);
}
/* Get a Ruby number to reference an object */
@ -54,8 +82,7 @@ SWIGRUNTIME VALUE SWIG_RubyObjectToReference(VALUE object) {
a Ruby number object. */
/* Convert the Object to a Ruby number */
unsigned long value = (unsigned long) object;
return LONG2NUM(value);
return SWIG2NUM(object);
}
/* Get a Ruby object from a previously stored reference */
@ -63,9 +90,8 @@ SWIGRUNTIME VALUE SWIG_RubyReferenceToObject(VALUE reference) {
/* The provided Ruby number object is a reference
to the Ruby object we want.*/
/* First convert the Ruby number to a C number */
unsigned long value = NUM2LONG(reference);
return (VALUE) value;
/* Convert the Ruby number to a Ruby object */
return NUM2SWIG(reference);
}
/* Add a Tracking from a C/C++ struct to a Ruby object */