massive typemap unification
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7676 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
0a405b10e8
commit
1c7c9e44f7
144 changed files with 6378 additions and 7248 deletions
1
SWIG/Lib/ruby/cdata.i
Normal file
1
SWIG/Lib/ruby/cdata.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/cdata.swg>
|
||||
137
SWIG/Lib/ruby/cstring.i
Normal file
137
SWIG/Lib/ruby/cstring.i
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* cstring.i
|
||||
* $Header$
|
||||
*
|
||||
* Author(s): David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* This file provides typemaps and macros for dealing with various forms
|
||||
* of C character string handling. The primary use of this module
|
||||
* is in returning character data that has been allocated or changed in
|
||||
* some way.
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cstring_input_binary(TYPEMAP, SIZE)
|
||||
*
|
||||
* Macro makes a function accept binary string data along with
|
||||
* a size.
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cstring_bounded_output(TYPEMAP, MAX)
|
||||
*
|
||||
* This macro is used to return a NULL-terminated output string of
|
||||
* some maximum length. For example:
|
||||
*
|
||||
* %cstring_bounded_output(Char *outx, 512);
|
||||
* void foo(Char *outx) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cstring_chunk_output(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro is used to return a chunk of binary string data.
|
||||
* Embedded NULLs are okay. For example:
|
||||
*
|
||||
* %cstring_chunk_output(Char *outx, 512);
|
||||
* void foo(Char *outx) {
|
||||
* memmove(outx, somedata, 512);
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cstring_bounded_mutable(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro is used to wrap a string that's going to mutate.
|
||||
*
|
||||
* %cstring_bounded_mutable(Char *in, 512);
|
||||
* void foo(in *x) {
|
||||
* while (*x) {
|
||||
* *x = toupper(*x);
|
||||
* x++;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cstring_mutable(TYPEMAP [, expansion])
|
||||
*
|
||||
* This macro is used to wrap a string that will mutate in place.
|
||||
* It may change size up to a user-defined expansion.
|
||||
*
|
||||
* %cstring_mutable(Char *in);
|
||||
* void foo(in *x) {
|
||||
* while (*x) {
|
||||
* *x = toupper(*x);
|
||||
* x++;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cstring_output_maxsize(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro returns data in a string of some user-defined size.
|
||||
*
|
||||
* %cstring_output_maxsize(Char *outx, int max) {
|
||||
* void foo(Char *outx, int max) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cstring_output_withsize(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro is used to return Character data along with a size
|
||||
* parameter.
|
||||
*
|
||||
* %cstring_output_maxsize(Char *outx, int *max) {
|
||||
* void foo(Char *outx, int *max) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* *max = strlen(outx);
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cstring_output_allocate(TYPEMAP, RELEASE)
|
||||
*
|
||||
* This macro is used to return Character data that was
|
||||
* allocated with new or malloc.
|
||||
*
|
||||
* %cstring_output_allocated(Char **outx, free($1));
|
||||
* void foo(Char **outx) {
|
||||
* *outx = (Char *) malloc(512);
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cstring_output_allocate_size(TYPEMAP, SIZE, RELEASE)
|
||||
*
|
||||
* This macro is used to return Character data that was
|
||||
* allocated with new or malloc.
|
||||
*
|
||||
* %cstring_output_allocated(Char **outx, int *sz, free($1));
|
||||
* void foo(Char **outx, int *sz) {
|
||||
* *outx = (Char *) malloc(512);
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* *sz = strlen(outx);
|
||||
* }
|
||||
*/
|
||||
|
||||
%include <typemaps/cstring.swg>
|
||||
%include <rubystrings.swg>
|
||||
|
||||
%typemap_cstrings(%cstring,
|
||||
char,
|
||||
SWIG_AsCharPtr,
|
||||
SWIG_AsCharPtrAndSize,
|
||||
SWIG_FromCharPtr,
|
||||
SWIG_FromCharPtrAndSize);
|
||||
|
||||
|
|
@ -20,42 +20,94 @@ namespace Swig {
|
|||
int argc;
|
||||
VALUE *argv;
|
||||
};
|
||||
|
||||
|
||||
/* Base class for director exceptions */
|
||||
class DirectorException {
|
||||
protected:
|
||||
VALUE swig_error;
|
||||
protected:
|
||||
DirectorException(VALUE error=Qnil) : swig_error(error) {}
|
||||
public:
|
||||
VALUE getType() const {
|
||||
return CLASS_OF(swig_error);
|
||||
protected:
|
||||
VALUE swig_error;
|
||||
std::string swig_msg;
|
||||
protected:
|
||||
DirectorException(VALUE error)
|
||||
: swig_error(error)
|
||||
{
|
||||
}
|
||||
|
||||
DirectorException(VALUE error, const char* hdr, const char* msg ="")
|
||||
: swig_error(error), swig_msg(hdr) {
|
||||
if (strlen(msg)) {
|
||||
swig_msg += " ";
|
||||
swig_msg += msg;
|
||||
}
|
||||
VALUE getError() const {
|
||||
return swig_error;
|
||||
if (swig_msg.size()) {
|
||||
VALUE str = rb_str_new2(swig_msg.c_str());
|
||||
swig_error = rb_exc_new3(error, str);
|
||||
} else {
|
||||
swig_error = error;
|
||||
}
|
||||
virtual ~DirectorException() {}
|
||||
}
|
||||
public:
|
||||
VALUE getType() const {
|
||||
return CLASS_OF(swig_error);
|
||||
}
|
||||
VALUE getError() const {
|
||||
return swig_error;
|
||||
}
|
||||
virtual ~DirectorException() {}
|
||||
};
|
||||
|
||||
|
||||
/* Type mismatch in the return value from a Ruby method call */
|
||||
class DirectorTypeMismatchException : public Swig::DirectorException {
|
||||
public:
|
||||
DirectorTypeMismatchException(const char *msg="") {
|
||||
VALUE str = rb_str_new2("Swig director type mismatch: ");
|
||||
rb_str_concat(str, rb_str_new2(msg));
|
||||
swig_error = rb_exc_new3(rb_eTypeError, str);
|
||||
}
|
||||
public:
|
||||
DirectorTypeMismatchException(VALUE error, const char *msg="")
|
||||
: Swig::DirectorException(error, "Swig director type mismatch", msg)
|
||||
{
|
||||
}
|
||||
|
||||
DirectorTypeMismatchException(const char *msg="")
|
||||
: Swig::DirectorException(rb_eTypeError, "Swig director type mismatch", msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void raise(VALUE error, const char *msg) {
|
||||
throw DirectorTypeMismatchException(error, msg);
|
||||
}
|
||||
|
||||
static void raise(const char *msg) {
|
||||
throw DirectorTypeMismatchException(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/* Any Ruby exception that occurs during a director method call */
|
||||
class DirectorMethodException : public Swig::DirectorException {
|
||||
public:
|
||||
DirectorMethodException(VALUE error) : Swig::DirectorException(error) {}
|
||||
public:
|
||||
DirectorMethodException(VALUE error)
|
||||
: Swig::DirectorException(error) {
|
||||
}
|
||||
|
||||
DirectorMethodException(const char* msg = "")
|
||||
: Swig::DirectorException(rb_eRuntimeError, "Swig director method error", msg) {
|
||||
}
|
||||
|
||||
static void raise(VALUE error)
|
||||
{
|
||||
throw DirectorMethodException(error);
|
||||
}
|
||||
};
|
||||
|
||||
/* Attempted to call a pure virtual method via a director method */
|
||||
class DirectorPureVirtualException : public Swig::DirectorException {};
|
||||
class DirectorPureVirtualException : public Swig::DirectorException
|
||||
{
|
||||
public:
|
||||
DirectorPureVirtualException(const char* msg = "")
|
||||
: DirectorException(rb_eRuntimeError, "Swig director pure virtal method called", msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void raise(const char *msg)
|
||||
{
|
||||
throw DirectorPureVirtualException(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/* Simple thread abstraction for pthreads on win32 */
|
||||
#ifdef __THREAD__
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
// Helper function for Array output
|
||||
|
||||
%fragment("output_helper", "header") %{
|
||||
static VALUE output_helper(VALUE target, VALUE o) {
|
||||
if (NIL_P(target)) {
|
||||
target = o;
|
||||
} else {
|
||||
if (TYPE(target) != T_ARRAY) {
|
||||
VALUE o2 = target;
|
||||
target = rb_ary_new();
|
||||
rb_ary_push(target, o2);
|
||||
}
|
||||
rb_ary_push(target, o);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
%}
|
||||
|
|
@ -1,47 +1,53 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
/* -----------------------------------------------------------------------------
|
||||
* ruby.swg
|
||||
*
|
||||
* Ruby configuation file.
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
%runtime "rubyhead.swg"
|
||||
%runtime "swigrun.swg" /* Common C API type-checking code */
|
||||
%runtime "rubytracking.swg" /* API for tracking C++ classes to Ruby objects */
|
||||
%runtime "rubydef.swg"
|
||||
|
||||
%insert(initbeforefunc) "swiginit.swg"
|
||||
|
||||
#define %alias %feature("alias")
|
||||
#define %freefunc %feature("freefunc")
|
||||
#define %markfunc %feature("markfunc")
|
||||
#define %mixin %feature("mixin")
|
||||
#define %predicate %feature("predicate", "1")
|
||||
#define %trackobjects %feature("trackobjects")
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SWIGTYPE typemaps
|
||||
* Ruby configuration module.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "rubyswigtype.swg"
|
||||
/* -----------------------------------------------------------------------------
|
||||
* The runtime part
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <rubyruntime.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Special user directives
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <rubyuserdir.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Inner macros
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <rubymacros.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Error manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <rubyerrors.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Look for user fragments file. If not found, include empty system one.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include "rubyfragments.swg"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Typemap specializations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "rubyvoid.swg"
|
||||
%include "rubyobject.swg"
|
||||
%include "rubystrings.swg"
|
||||
%include "rubyprimtypes.swg"
|
||||
%include "rubymisctypes.swg"
|
||||
%include "rubyenum.swg"
|
||||
%include <rubytypemaps.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Overloaded operator support
|
||||
* ------------------------------------------------------------ */
|
||||
%include "rubyopers.swg"
|
||||
%include <rubyopers.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Warnings for Ruby keywords
|
||||
* Warnings for Python keywords
|
||||
* ------------------------------------------------------------ */
|
||||
%include "rubykw.swg"
|
||||
%include <rubykw.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The Python initialization function
|
||||
* ------------------------------------------------------------ */
|
||||
%include <rubyinit.swg>
|
||||
|
||||
|
||||
|
|
|
|||
27
SWIG/Lib/ruby/rubyapi.swg
Normal file
27
SWIG/Lib/ruby/rubyapi.swg
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Ruby API portion that goes into the runtime
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SWIGINTERN VALUE
|
||||
SWIG_Ruby_AppendResult(VALUE target, VALUE o) {
|
||||
if (NIL_P(target)) {
|
||||
target = o;
|
||||
} else {
|
||||
if (TYPE(target) != T_ARRAY) {
|
||||
VALUE o2 = target;
|
||||
target = rb_ary_new();
|
||||
rb_ary_push(target, o2);
|
||||
}
|
||||
rb_ary_push(target, o);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1,267 +0,0 @@
|
|||
/* Common SWIG API */
|
||||
#define SWIG_ConvertPtr(obj, pp, type, flags) \
|
||||
SWIG_Ruby_ConvertPtr(obj, pp, type, flags)
|
||||
#define SWIG_NewPointerObj(p, type, flags) \
|
||||
SWIG_Ruby_NewPointerObj(p, type, flags)
|
||||
#define SWIG_MustGetPtr(p, type, argnum, flags) \
|
||||
SWIG_Ruby_MustGetPtr(p, type, argnum, flags)
|
||||
#define SWIG_GetModule(clientdata) \
|
||||
SWIG_Ruby_GetModule()
|
||||
#define SWIG_SetModule(clientdata, pointer) \
|
||||
SWIG_Ruby_SetModule(pointer)
|
||||
|
||||
/* Ruby-specific SWIG API */
|
||||
|
||||
#define SWIG_InitRuntime() \
|
||||
SWIG_Ruby_InitRuntime()
|
||||
#define SWIG_define_class(ty) \
|
||||
SWIG_Ruby_define_class(ty)
|
||||
#define SWIG_NewClassInstance(value, ty) \
|
||||
SWIG_Ruby_NewClassInstance(value, ty)
|
||||
#define SWIG_MangleStr(value) \
|
||||
SWIG_Ruby_MangleStr(value)
|
||||
#define SWIG_CheckConvert(value, ty) \
|
||||
SWIG_Ruby_CheckConvert(value, ty)
|
||||
#define SWIG_NewPackedObj(ptr, sz, ty) \
|
||||
SWIG_Ruby_NewPackedObj(ptr, sz, ty)
|
||||
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) \
|
||||
SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags)
|
||||
|
||||
/* rubydef.swg */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static VALUE _mSWIG = Qnil;
|
||||
static VALUE _cSWIG_Pointer = Qnil;
|
||||
static VALUE swig_runtime_data_type_pointer = Qnil;
|
||||
|
||||
/* Initialize Ruby runtime support */
|
||||
static void
|
||||
SWIG_Ruby_InitRuntime(void)
|
||||
{
|
||||
if (_mSWIG == Qnil) {
|
||||
_mSWIG = rb_define_module("SWIG");
|
||||
}
|
||||
}
|
||||
|
||||
/* Define Ruby class for C type */
|
||||
static void
|
||||
SWIG_Ruby_define_class(swig_type_info *type)
|
||||
{
|
||||
VALUE klass;
|
||||
char *klass_name = (char *) malloc(4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
if (NIL_P(_cSWIG_Pointer)) {
|
||||
_cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject);
|
||||
rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new");
|
||||
}
|
||||
klass = rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer);
|
||||
free((void *) klass_name);
|
||||
}
|
||||
|
||||
/* Create a new pointer object */
|
||||
static VALUE
|
||||
SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
|
||||
{
|
||||
int own = flags & SWIG_POINTER_OWN;
|
||||
int track = flags & SWIG_TRACK_OBJECTS;
|
||||
|
||||
char *klass_name;
|
||||
swig_class *sklass;
|
||||
VALUE klass;
|
||||
VALUE obj;
|
||||
|
||||
if (!ptr)
|
||||
return Qnil;
|
||||
|
||||
/* Have we already wrapped this pointer? */
|
||||
if (track) {
|
||||
obj = SWIG_RubyInstanceFor(ptr);
|
||||
if (obj != Qnil) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
if (type->clientdata) {
|
||||
sklass = (swig_class *) type->clientdata;
|
||||
obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), (own ? VOIDFUNC(sklass->destroy) : 0), ptr);
|
||||
} else {
|
||||
klass_name = (char *) malloc(4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
klass = rb_const_get(_mSWIG, rb_intern(klass_name));
|
||||
free((void *) klass_name);
|
||||
obj = Data_Wrap_Struct(klass, 0, 0, ptr);
|
||||
}
|
||||
rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
|
||||
|
||||
/* Keep track of this object if necessary */
|
||||
if (track) {
|
||||
SWIG_RubyAddTracking(ptr, obj);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* Create a new class instance (always owned) */
|
||||
static VALUE
|
||||
SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type)
|
||||
{
|
||||
VALUE obj;
|
||||
swig_class *sklass = (swig_class *) type->clientdata;
|
||||
obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0);
|
||||
rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* Get type mangle from class name */
|
||||
static SWIGINLINE char *
|
||||
SWIG_Ruby_MangleStr(VALUE obj)
|
||||
{
|
||||
VALUE stype = rb_iv_get(obj, "__swigtype__");
|
||||
return StringValuePtr(stype);
|
||||
}
|
||||
|
||||
/* Convert a pointer value */
|
||||
static int
|
||||
SWIG_Ruby_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flags)
|
||||
{
|
||||
char *c;
|
||||
swig_cast_info *tc;
|
||||
|
||||
/* Grab the pointer */
|
||||
if (NIL_P(obj)) {
|
||||
*ptr = 0;
|
||||
return 0;
|
||||
} else {
|
||||
Data_Get_Struct(obj, void, *ptr);
|
||||
}
|
||||
|
||||
/* Check to see if the input object is giving up ownership
|
||||
of the underlying C struct or C++ object. If so then we
|
||||
need to reset the destructor since the Ruby object no
|
||||
longer owns the underlying C++ object.*/
|
||||
if (flags & SWIG_POINTER_DISOWN) {
|
||||
if (flags & SWIG_TRACK_OBJECTS) {
|
||||
/* We are tracking objects. Thus we change the destructor
|
||||
* to SWIG_RubyRemoveTracking. This allows us to
|
||||
* remove the mapping from the C++ to Ruby object
|
||||
* when the Ruby object is garbage collected. If we don't
|
||||
* do this, then it is possible we will return a reference
|
||||
* to a Ruby object that no longer exists thereby crashing Ruby. */
|
||||
RDATA(obj)->dfree = SWIG_RubyRemoveTracking;
|
||||
} else {
|
||||
RDATA(obj)->dfree = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Do type-checking if type info was provided */
|
||||
if (ty) {
|
||||
if (ty->clientdata) {
|
||||
if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
|
||||
if (*ptr == 0)
|
||||
rb_raise(rb_eRuntimeError, "This %s already released", ty->str);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((c = SWIG_MangleStr(obj)) == NULL) {
|
||||
if (flags & SWIG_POINTER_EXCEPTION)
|
||||
rb_raise(rb_eTypeError, "Expected %s", ty->str);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) {
|
||||
if (flags & SWIG_POINTER_EXCEPTION)
|
||||
rb_raise(rb_eTypeError, "Expected %s", ty->str);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
*ptr = SWIG_TypeCast(tc, *ptr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Convert a pointer value, signal an exception on a type mismatch */
|
||||
static SWIGINLINE void *
|
||||
SWIG_Ruby_MustGetPtr(VALUE obj, swig_type_info *ty, int argnum, int flags)
|
||||
{
|
||||
void *result;
|
||||
SWIG_ConvertPtr(obj, &result, ty, flags | SWIG_POINTER_EXCEPTION);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Check convert */
|
||||
static SWIGINLINE int
|
||||
SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty)
|
||||
{
|
||||
char *c = SWIG_MangleStr(obj);
|
||||
if (!c)
|
||||
return 0;
|
||||
return SWIG_TypeCheck(c,ty) != 0;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) {
|
||||
char result[1024];
|
||||
char *r = result;
|
||||
if ((2*sz + 1 + strlen(type->name)) > 1000) return 0;
|
||||
*(r++) = '_';
|
||||
r = SWIG_PackData(r, ptr, sz);
|
||||
strcpy(r, type->name);
|
||||
return rb_str_new2(result);
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
static void
|
||||
SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags) {
|
||||
swig_cast_info *tc;
|
||||
const char *c;
|
||||
|
||||
if (TYPE(obj) != T_STRING) goto type_error;
|
||||
c = StringValuePtr(obj);
|
||||
/* Pointer values must start with leading underscore */
|
||||
if (*c != '_') goto type_error;
|
||||
c++;
|
||||
c = SWIG_UnpackData(c, ptr, sz);
|
||||
if (ty) {
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) goto type_error;
|
||||
}
|
||||
return;
|
||||
|
||||
type_error:
|
||||
|
||||
if (flags) {
|
||||
if (ty) {
|
||||
rb_raise(rb_eTypeError, "Type error. Expected %s", ty->name);
|
||||
} else {
|
||||
rb_raise(rb_eTypeError, "Expected a pointer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static swig_module_info *SWIG_Ruby_GetModule() {
|
||||
VALUE pointer;
|
||||
swig_module_info *ret = 0;
|
||||
|
||||
/* first check if pointer already created */
|
||||
pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
|
||||
if (pointer != Qnil) {
|
||||
Data_Get_Struct(pointer, swig_module_info, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void SWIG_Ruby_SetModule(swig_module_info *pointer) {
|
||||
/* register a new class */
|
||||
VALUE cl = rb_define_class("swig_runtime_data", rb_cObject);
|
||||
/* create and store the structure pointer to a global variable */
|
||||
swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer);
|
||||
rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* Enums
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* --- Input typemaps --- */
|
||||
%typemap(in) enum SWIGTYPE "$1 = ($1_ltype) NUM2INT($input);";
|
||||
|
||||
%typemap(in) const enum SWIGTYPE & ($*1_ltype temp)
|
||||
"temp = ($*1_ltype) NUM2INT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
|
||||
%typemap(directorout) enum SWIGTYPE "$result = ($1_ltype) NUM2INT($input);";
|
||||
%typemap(directorout,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const enum SWIGTYPE &
|
||||
%{ static $*1_ltype temp = ($*1_ltype) NUM2INT($input);
|
||||
$result = &temp; %}
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
%typemap(out) enum SWIGTYPE "$result = INT2NUM($1);";
|
||||
|
||||
%typemap(out) const enum SWIGTYPE & "$result = INT2NUM((long) *($1));";
|
||||
|
||||
%typemap(directorin) enum SWIGTYPE "$input = INT2NUM($1);";
|
||||
%typemap(directorin) const enum SWIGTYPE& "$input = INT2NUM($1);";
|
||||
|
||||
/* --- Variable Input --- */
|
||||
|
||||
%{
|
||||
static void SWIG_AsVal(VALUE obj, int *val)
|
||||
{
|
||||
*val = (int) NUM2INT(obj);
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(varin) enum SWIGTYPE {
|
||||
if (sizeof(int) != sizeof($1)) {
|
||||
rb_raise(rb_eTypeError, "enum variable '$name' can not be set.");
|
||||
}
|
||||
SWIG_AsVal($input, (int *)(void *) &$1);
|
||||
}
|
||||
|
||||
/* --- Variable Output --- */
|
||||
|
||||
%typemap(varout) enum SWIGTYPE "$result = INT2NUM($1);";
|
||||
|
||||
/* --- Constants --- */
|
||||
%typemap(constant) enum SWIGTYPE "rb_define_const($module,\"$symname\", INT2NUM($1));";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER) enum SWIGTYPE, const enum SWIGTYPE &
|
||||
{
|
||||
$1 = ((TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) enum SWIGTYPE
|
||||
"(void)$1; rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(INT2NUM($1))));"
|
||||
|
||||
61
SWIG/Lib/ruby/rubyerrors.swg
Normal file
61
SWIG/Lib/ruby/rubyerrors.swg
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* error manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
%insert("header") %{
|
||||
|
||||
SWIGINTERN VALUE
|
||||
SWIG_Ruby_ErrorType(int SWIG_code) {
|
||||
switch (SWIG_code) {
|
||||
case SWIG_MemoryError:
|
||||
return rb_eNoMemError;
|
||||
break;
|
||||
case SWIG_IOError:
|
||||
return rb_eIOError;
|
||||
break;
|
||||
case SWIG_RuntimeError:
|
||||
return rb_eRuntimeError;
|
||||
break;
|
||||
case SWIG_IndexError:
|
||||
return rb_eIndexError;
|
||||
break;
|
||||
case SWIG_TypeError:
|
||||
return rb_eTypeError;
|
||||
break;
|
||||
case SWIG_DivisionByZero:
|
||||
return rb_eZeroDivError;
|
||||
break;
|
||||
case SWIG_OverflowError:
|
||||
return rb_eRangeError;
|
||||
break;
|
||||
case SWIG_SyntaxError:
|
||||
return rb_eSyntaxError;
|
||||
break;
|
||||
case SWIG_ValueError:
|
||||
return rb_eArgError;
|
||||
break;
|
||||
case SWIG_SystemError:
|
||||
return rb_eFatal;
|
||||
break;
|
||||
case SWIG_AttributeError:
|
||||
return rb_eRuntimeError;
|
||||
break;
|
||||
case SWIG_UnknownError:
|
||||
return rb_eRuntimeError;
|
||||
break;
|
||||
default:
|
||||
return rb_eRuntimeError;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SWIGINTERN void
|
||||
SWIG_Ruby_SetErrorMsg(VALUE type, const char *msg) {
|
||||
rb_raise(type, msg);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
23
SWIG/Lib/ruby/rubyfragments.swg
Normal file
23
SWIG/Lib/ruby/rubyfragments.swg
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
|
||||
Create a file with this name, 'fragments.i', in your working
|
||||
directory and add all the %fragments you want to take precedence
|
||||
over the ones defined by default by swig.
|
||||
|
||||
For example, if you add:
|
||||
|
||||
%fragment(SWIG_AsVal_frag(int),"header") {
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_AsVal(int)(PyObject *obj, int *val)
|
||||
{
|
||||
<your code here>;
|
||||
}
|
||||
}
|
||||
|
||||
this will replace the code used to retreive an integer value for all
|
||||
the typemaps that need it, including:
|
||||
|
||||
int, std::vector<int>, std::list<std::pair<int,int> >, etc.
|
||||
|
||||
|
||||
*/
|
||||
1
SWIG/Lib/ruby/rubyinit.swg
Normal file
1
SWIG/Lib/ruby/rubyinit.swg
Normal file
|
|
@ -0,0 +1 @@
|
|||
%insert(initbeforefunc) "swiginit.swg"
|
||||
1
SWIG/Lib/ruby/rubymacros.swg
Normal file
1
SWIG/Lib/ruby/rubymacros.swg
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/swigmacros.swg>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* --- ANSI/Posix C/C++ types ---
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%apply unsigned long { size_t };
|
||||
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* VALUE - Just pass straight through unmodified
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
typedef unsigned long VALUE;
|
||||
|
||||
%typemap(in) VALUE "$1 = $input;";
|
||||
%typemap(out) VALUE "$result = $1;";
|
||||
|
||||
%typemap(directorin) VALUE "$input = $1;";
|
||||
%typemap(directorout) VALUE "$result = $input;";
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) VALUE "$1 = ($input != T_NONE);";
|
||||
|
|
@ -1,257 +1,317 @@
|
|||
%include <typemaps/primtypes.swg>
|
||||
|
||||
/* Macro for 'signed long' derived types */
|
||||
|
||||
%define %type_slong(Type, Frag, Min, Max)
|
||||
%derived_type_from(long, Type)
|
||||
%signed_derived_type_asval(long, Type, Frag, Min, Max)
|
||||
%enddef
|
||||
|
||||
/* Macro for 'unsigned long' derived types */
|
||||
|
||||
%define %type_ulong(Type, Frag, Max)
|
||||
%derived_type_from(unsigned long, Type)
|
||||
%unsigned_derived_type_asval(unsigned long, Type, Frag, Max)
|
||||
%enddef
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Primitive Types
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* --- Input Values --- */
|
||||
|
||||
%typemap(in) int "$1 = NUM2INT($input);";
|
||||
%typemap(in) unsigned int "$1 = NUM2UINT($input);";
|
||||
%typemap(in) short "$1 = NUM2SHRT($input);";
|
||||
%typemap(in) unsigned short "$1 = NUM2USHRT($input);";
|
||||
%typemap(in) long "$1 = NUM2LONG($input);";
|
||||
%typemap(in) unsigned long "$1 = NUM2ULONG($input);";
|
||||
%typemap(in) signed char "$1 = ($1_ltype) NUM2INT($input);";
|
||||
%typemap(in) unsigned char "$1 = ($1_ltype) NUM2INT($input);";
|
||||
%typemap(in) char "$1 = NUM2CHR($input);";
|
||||
%typemap(in) float, double "$1 = ($1_ltype) NUM2DBL($input);";
|
||||
%typemap(in) bool "$1 = RTEST($input);";
|
||||
|
||||
/* Long long */
|
||||
|
||||
%typemap(in) long long "$1 = ($1_ltype) NUM2LL($input);";
|
||||
%typemap(in) unsigned long long "$1 = ($1_ltype) NUM2ULL($input);";
|
||||
|
||||
/* Const primitive references. Passed by value */
|
||||
|
||||
%typemap(in) const int & (int temp),
|
||||
const signed char & (signed char temp),
|
||||
const unsigned char & (unsigned char temp)
|
||||
"temp = ($*1_ltype) NUM2INT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const short & (short temp)
|
||||
"temp = ($*1_ltype) NUM2SHRT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const long & (long temp)
|
||||
"temp = ($*1_ltype) NUM2LONG($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned int & (unsigned int temp)
|
||||
"temp = ($*1_ltype) NUM2UINT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned short & (unsigned short temp)
|
||||
"temp = ($*1_ltype) NUM2USHRT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned long & (unsigned long temp)
|
||||
"temp = ($*1_ltype) NUM2ULONG($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const bool & (bool temp)
|
||||
"temp = ($*1_ltype) RTEST($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const float & (float temp),
|
||||
const double & (double temp)
|
||||
"temp = ($*1_ltype) NUM2DBL($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const long long & ($*1_ltype temp)
|
||||
"temp = ($*1_ltype) NUM2LL($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned long long & ($*1_ltype temp)
|
||||
"temp = ($*1_ltype) NUM2ULL($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const char &(char temp) {
|
||||
char *stemp = StringValuePtr($input);
|
||||
temp = *stemp;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
|
||||
%typemap(out) int, short, long, signed char
|
||||
"$result = INT2NUM($1);";
|
||||
|
||||
%typemap(out) unsigned int, unsigned short, unsigned long, unsigned char
|
||||
"$result = UINT2NUM($1);";
|
||||
|
||||
/* Long long */
|
||||
|
||||
%typemap(out) long long "$result = LL2NUM($1);";
|
||||
%typemap(out) unsigned long long "$result = ULL2NUM($1);";
|
||||
|
||||
/* Floating point output values */
|
||||
%typemap(out) double, float
|
||||
"$result = rb_float_new($1);";
|
||||
|
||||
/* Boolean */
|
||||
%typemap(out) bool
|
||||
"$result = $1 ? Qtrue : Qfalse;";
|
||||
|
||||
/* References to primitive types. Return by value */
|
||||
|
||||
%typemap(out) const int &,
|
||||
const short &,
|
||||
const long &,
|
||||
const signed char &
|
||||
"$result = INT2NUM((long) *($1));";
|
||||
|
||||
%typemap(out) const unsigned int &,
|
||||
const unsigned short &,
|
||||
const unsigned long &,
|
||||
const unsigned char &
|
||||
"$result = UINT2NUM((unsigned long) *($1));";
|
||||
|
||||
%typemap(out) const bool &
|
||||
"$result = *($1) ? Qtrue : Qfalse;";
|
||||
|
||||
%typemap(out) const float &, const double &
|
||||
"$result = rb_float_new((double) *($1));";
|
||||
|
||||
%typemap(out) const long long &
|
||||
"$result = LL2NUM(*($1));";
|
||||
|
||||
%typemap(out) const unsigned long long &
|
||||
"$result = ULL2NUM(*($1));";
|
||||
|
||||
/* --- Variable Input --- */
|
||||
|
||||
%typemap(varin) int "$1 = NUM2INT($input);";
|
||||
%typemap(varin) unsigned int "$1 = NUM2UINT($input);";
|
||||
%typemap(varin) short "$1 = NUM2SHRT($input);";
|
||||
%typemap(varin) unsigned short "$1 = NUM2USHRT($input);";
|
||||
%typemap(varin) long "$1 = NUM2LONG($input);";
|
||||
%typemap(varin) unsigned long "$1 = NUM2ULONG($input);";
|
||||
%typemap(varin) signed char "$1 = (signed char) NUM2INT($input);";
|
||||
%typemap(varin) unsigned char "$1 = (unsigned char) NUM2INT($input);";
|
||||
%typemap(varin) char "$1 = NUM2CHR($input);";
|
||||
%typemap(varin) float, double "$1 = ($1_ltype) NUM2DBL($input);";
|
||||
%typemap(varin) bool "$1 = RTEST($input);";
|
||||
|
||||
%typemap(varin) long long "$1 = NUM2LL($input);";
|
||||
%typemap(varin) unsigned long long "$1 = NUM2ULL($input);";
|
||||
|
||||
/* --- Variable Output --- */
|
||||
|
||||
%typemap(varout) int, short, long, signed char
|
||||
"$result = INT2NUM($1);";
|
||||
|
||||
%typemap(varout) unsigned int, unsigned short, unsigned long, unsigned char
|
||||
"$result = UINT2NUM($1);";
|
||||
|
||||
%typemap(varout) long long "$result = LL2NUM($1);";
|
||||
%typemap(varout) unsigned long long "$result = ULL2NUM($1);";
|
||||
|
||||
/* Floats and doubles */
|
||||
%typemap(varout) double, float
|
||||
"$result = rb_float_new($1);";
|
||||
|
||||
/* Boolean */
|
||||
%typemap(varout) bool
|
||||
"$result = $1 ? Qtrue : Qfalse;";
|
||||
|
||||
/* --- Constants --- */
|
||||
|
||||
%typemap(constant) int, short, long, signed char
|
||||
"rb_define_const($module,\"$symname\", INT2NUM($1));";
|
||||
|
||||
%typemap(constant) unsigned int, unsigned short, unsigned long, unsigned char
|
||||
"rb_define_const($module,\"$symname\", UINT2NUM($1));";
|
||||
|
||||
%typemap(constant) long long
|
||||
"rb_define_const($module,\"$symname\", LL2NUM($1));";
|
||||
|
||||
%typemap(constant) unsigned long long
|
||||
"rb_define_const($module,\"$symname\", ULL2NUM($1));";
|
||||
|
||||
%typemap(constant) double, float
|
||||
"rb_define_const($module,\"$symname\", rb_float_new($1));";
|
||||
|
||||
%typemap(constant) bool
|
||||
"rb_define_const($module,\"$symname\", ($1 ? Qtrue : Qfalse));";
|
||||
|
||||
/* directorin typemaps */
|
||||
|
||||
%typemap(directorin) int , const int& "$input = INT2NUM($1);";
|
||||
%typemap(directorin) short , const short& "$input = INT2NUM($1);";
|
||||
%typemap(directorin) long , const long& "$input = LONG2NUM($1);";
|
||||
%typemap(directorin) signed char , const signed char& "$input = INT2NUM($1);";
|
||||
%typemap(directorin) float , const float& "$input = rb_float_new($1);";
|
||||
%typemap(directorin) double , const double& "$input = rb_float_new($1);";
|
||||
%typemap(directorin) bool , const bool& "$input = $1 ? Qtrue : Qfalse;";
|
||||
%typemap(directorin) unsigned int , const unsigned int& "$input = UINT2NUM($1);";
|
||||
%typemap(directorin) unsigned short, const unsigned short& "$input = UINT2NUM($1);";
|
||||
%typemap(directorin) unsigned long , const unsigned long& "$input = ULONG2NUM($1);";
|
||||
%typemap(directorin) unsigned char , const unsigned char& "$input = UINT2NUM($1);";
|
||||
|
||||
/* --- directorout typemaps --- */
|
||||
|
||||
%define DIRECTOROUT_TYPEMAP(type, converter)
|
||||
%typemap(directorargout) type *DIRECTOROUT "*$result = (type) converter($input);";
|
||||
%typemap(directorout) type "$result = (type) converter($input);";
|
||||
%typemap(directorout) const type& {
|
||||
$basetype temp = converter($input);
|
||||
$result = &temp;
|
||||
}
|
||||
%typemap(directorout) type &DIRECTOROUT = type
|
||||
%enddef
|
||||
|
||||
DIRECTOROUT_TYPEMAP(char, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(unsigned char, NUM2UINT);
|
||||
DIRECTOROUT_TYPEMAP(short, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(unsigned short, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(int, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(unsigned int, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(long, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(unsigned long, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(long long, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(unsigned long long, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(float, NUM2DBL);
|
||||
DIRECTOROUT_TYPEMAP(double, NUM2DBL);
|
||||
DIRECTOROUT_TYPEMAP(bool, RTEST);
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_BOOL) bool {
|
||||
$1 = ($input == Qtrue || $input == Qfalse) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER)
|
||||
int, short, long,
|
||||
unsigned int, unsigned short, unsigned long,
|
||||
signed char, unsigned char,
|
||||
long long, unsigned long long,
|
||||
const int &, const short &, const long &,
|
||||
const unsigned int &, const unsigned short &, const unsigned long &,
|
||||
const long long &, const unsigned long long &
|
||||
%fragment("SWIG_ruby_failed","header")
|
||||
{
|
||||
$1 = ((TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0;
|
||||
SWIGINTERN VALUE
|
||||
SWIG_ruby_failed()
|
||||
{
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_DOUBLE)
|
||||
float, double,
|
||||
const float &, const double &
|
||||
|
||||
/* boolean */
|
||||
|
||||
%fragment(SWIG_From_frag(bool),"header") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(bool)(bool value)
|
||||
{
|
||||
$1 = ((TYPE($input) == T_FLOAT) || (TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0;
|
||||
return value ? Qtrue : Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(bool),"header",
|
||||
fragment=SWIG_AsVal_frag(int)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(bool)(VALUE obj, bool *val)
|
||||
{
|
||||
if (obj == Qtrue) {
|
||||
if (val) *val = true;
|
||||
return SWIG_OK;
|
||||
} else if (obj == Qfalse) {
|
||||
if (val) *val = false;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
int res = 0;
|
||||
if (SWIG_AsVal(int)(obj, &res) == SWIG_OK) {
|
||||
if (val) *val = res ? true : false;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* signed/unsigned char */
|
||||
|
||||
%type_slong(signed char, "<limits.h>", SCHAR_MIN, SCHAR_MAX)
|
||||
%type_ulong(unsigned char, "<limits.h>", UCHAR_MAX)
|
||||
|
||||
/* short/unsigned short */
|
||||
|
||||
%type_slong(short, "<limits.h>", SHRT_MIN, SHRT_MAX)
|
||||
%type_ulong(unsigned short, "<limits.h>", USHRT_MAX)
|
||||
|
||||
/* int/unsigned int */
|
||||
|
||||
%type_slong(int, "<limits.h>", INT_MIN, INT_MAX)
|
||||
%type_ulong(unsigned int, "<limits.h>", UINT_MAX)
|
||||
|
||||
/* signed/unsigned wchar_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
%type_slong(signed wchar_t, "<wchar.h>", WCHAR_MIN, WCHAR_MAX)
|
||||
%type_ulong(unsigned wchar_t, "<wchar.h>", UWCHAR_MAX)
|
||||
#endif
|
||||
|
||||
/* long */
|
||||
|
||||
%fragment(SWIG_From_frag(long),"header",
|
||||
fragment="<limits.h>") {
|
||||
SWIG_define(SWIG_From_dec(long), LONG2NUM)
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long),"header",fragment="SWIG_ruby_failed") {
|
||||
SWIGINTERN VALUE SWIG_num2long(VALUE *args)
|
||||
{
|
||||
*((long *)(args[1])) = NUM2LONG(args[0]);
|
||||
return args[0];
|
||||
}
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(long)(VALUE obj, long* val)
|
||||
{
|
||||
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
|
||||
long v;
|
||||
VALUE a[2] = { obj, (VALUE)(&v) };
|
||||
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_num2long), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* unsigned long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long),"header",
|
||||
fragment=SWIG_From_frag(long)) {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(unsigned long)(unsigned long value)
|
||||
{
|
||||
return ULONG2NUM(value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long),"header",fragment="SWIG_ruby_failed") {
|
||||
SWIGINTERN VALUE SWIG_num2ulong(VALUE *args)
|
||||
{
|
||||
*((unsigned long *)(args[1])) = NUM2ULONG(args[0]);
|
||||
return args[0];
|
||||
}
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long)(VALUE obj, unsigned long *val)
|
||||
{
|
||||
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
|
||||
unsigned long v;
|
||||
VALUE a[2] = { obj, (VALUE)(&v) };
|
||||
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_num2ulong), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* long long */
|
||||
|
||||
%fragment(SWIG_From_frag(long long),"header",
|
||||
fragment=SWIG_From_frag(long),
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(long long)(long long value)
|
||||
{
|
||||
return LL2NUM(value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long long),"header",fragment="SWIG_ruby_failed") {
|
||||
SWIGINTERN VALUE SWIG_num2longlong(VALUE *args)
|
||||
{
|
||||
*((long long *)(args[1])) = NUM2LL(args[0]);
|
||||
return args[0];
|
||||
}
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(long long)(VALUE obj, long long *val)
|
||||
{
|
||||
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
|
||||
long long v;
|
||||
VALUE a[2] = { obj, (VALUE)(&v) };
|
||||
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_num2longlong), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* unsigned long long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long long),"header",
|
||||
fragment=SWIG_From_frag(long long),
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(unsigned long long)(unsigned long long value)
|
||||
{
|
||||
return ULL2NUM(value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long long),"header",fragment="SWIG_ruby_failed") {
|
||||
SWIGINTERN VALUE SWIG_num2ulonglong(VALUE *args)
|
||||
{
|
||||
*((unsigned long long *)(args[1])) = NUM2ULL(args[0]);
|
||||
return args[0];
|
||||
}
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long long)(VALUE obj, unsigned long long *val)
|
||||
{
|
||||
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
|
||||
unsigned long long v;
|
||||
VALUE a[2] = { obj, (VALUE)(&v) };
|
||||
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_num2ulonglong), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* float */
|
||||
|
||||
%derived_type_from(double, float)
|
||||
%signed_derived_type_asval(double, float, "<float.h>", -FLT_MAX, FLT_MAX)
|
||||
|
||||
/* double */
|
||||
|
||||
%fragment(SWIG_From_frag(double),"header") {
|
||||
SWIG_define(SWIG_From_dec(double), rb_float_new)
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(double),"header",fragment="SWIG_ruby_failed") {
|
||||
SWIGINTERN VALUE SWIG_num2dbl(VALUE *args)
|
||||
{
|
||||
*((double *)(args[1])) = NUM2DBL(args[0]);
|
||||
return args[0];
|
||||
}
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(double)(VALUE obj, double *val)
|
||||
{
|
||||
if (obj != Qnil &&((TYPE(obj) == T_FLOAT) || (TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
|
||||
double v;
|
||||
VALUE a[2] = { obj, (VALUE)(&v) };
|
||||
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_num2dbl), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* char */
|
||||
|
||||
%fragment(SWIG_From_frag(char),"header") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(char)(char c)
|
||||
{
|
||||
return rb_str_new(&c,1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(char),"header",
|
||||
fragment="SWIG_AsCharArray",
|
||||
fragment=SWIG_AsVal_frag(signed char)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(char)(VALUE obj, char *val)
|
||||
{
|
||||
signed char v;
|
||||
if (SWIG_AsVal(signed char)(obj, &v) == SWIG_OK) {
|
||||
if (val) *val = (char)(v);
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (SWIG_AsCharArray(obj, val, 1) == SWIG_OK) {
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* wchar_t */
|
||||
|
||||
|
||||
%fragment(SWIG_From_frag(wchar_t),"header",
|
||||
fragment=SWIG_From_frag(char),
|
||||
fragment=SWIG_From_frag(long)) {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(wchar_t)(wchar_t c)
|
||||
{
|
||||
if (CHAR_MIN <= v && v <= CHAR_MAX) {
|
||||
return SWIG_From(char)((char)c);
|
||||
} else {
|
||||
return SWIG_From(long)((long)c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(wchar_t),"header",
|
||||
fragment="SWIG_AsWCharArray",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(wchar_t)(VALUE obj, wchar_t *val)
|
||||
{
|
||||
char v;
|
||||
if (SWIG_AsVal(char)(obj, &v) == SWIG_OK) {
|
||||
if (val) *val = (wchar_t)(v);
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
long v;
|
||||
if (SWIG_AsVal(long)(obj, &v) == SWIG_OK) {
|
||||
if (WCHAR_MIN <= v && v <= WCHAR_MAX) {
|
||||
if (val) *val = (wchar_t)(v);
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling
|
||||
* Apply the primitive typemap for all the types with checkcode
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) int,
|
||||
long,
|
||||
short,
|
||||
unsigned int,
|
||||
unsigned long,
|
||||
unsigned short {
|
||||
rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(INT2NUM($1))));
|
||||
}
|
||||
|
||||
%apply_checkctypes(%typemap_primitive)
|
||||
|
|
|
|||
289
SWIG/Lib/ruby/rubyrun.swg
Normal file
289
SWIG/Lib/ruby/rubyrun.swg
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
/***********************************************************************
|
||||
* rubyrun.swg
|
||||
*
|
||||
* This file contains the runtime support for Ruby modules
|
||||
* and includes code for managing global variables and pointer
|
||||
* type checking.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
/* for raw pointers */
|
||||
#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Ruby_ConvertPtr(obj, pptr, type, flags)
|
||||
#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Ruby_NewPointerObj(ptr, type, flags)
|
||||
|
||||
/* for raw packed data */
|
||||
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags)
|
||||
#define SWIG_NewPackedObj(ptr, sz, type, flags) SWIG_Ruby_NewPackedObj(ptr, sz, type)
|
||||
|
||||
/* for class or struct pointers */
|
||||
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_Ruby_ConvertPtr(obj, pptr, type, flags)
|
||||
#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_Ruby_NewPointerObj(ptr, type, flags)
|
||||
|
||||
/* for C or C++ function pointers */
|
||||
#define SWIG_ConvertFunctionPtr(obj, pptr, type, flags) SWIG_Ruby_ConvertPtr(obj, pptr, type, flags)
|
||||
#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Ruby_NewPointerObj(ptr, type, 0)
|
||||
|
||||
/* for C++ member pointers, ie, member methods */
|
||||
#define SWIG_ConvertMember(obj, ptr, sz, ty, flags) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags)
|
||||
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type)
|
||||
|
||||
|
||||
/* Runtime API */
|
||||
#define SWIG_GetModule(clientdata) SWIG_Ruby_GetModule()
|
||||
#define SWIG_SetModule(clientdata, pointer) SWIG_Ruby_SetModule(pointer)
|
||||
|
||||
/* Ruby-specific SWIG API */
|
||||
|
||||
#define SWIG_InitRuntime() SWIG_Ruby_InitRuntime()
|
||||
#define SWIG_define_class(ty) SWIG_Ruby_define_class(ty)
|
||||
#define SWIG_NewClassInstance(value, ty) SWIG_Ruby_NewClassInstance(value, ty)
|
||||
#define SWIG_MangleStr(value) SWIG_Ruby_MangleStr(value)
|
||||
#define SWIG_CheckConvert(value, ty) SWIG_Ruby_CheckConvert(value, ty)
|
||||
|
||||
/* Error manipulation */
|
||||
#define SWIG_ERROR -1
|
||||
#define SWIG_fail return Qnil
|
||||
#define SWIG_var_fail return Qnil
|
||||
|
||||
#define SWIG_error(code, msg) SWIG_Ruby_SetErrorMsg(SWIG_Ruby_ErrorType(code), msg)
|
||||
#define SWIG_exception(code, msg) do { SWIG_error(code, msg); SWIG_fail; } while (0)
|
||||
#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_error(SWIG_RuntimeError, msg); SWIG_fail; } else
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Flags for new pointer objects */
|
||||
#define SWIG_TRACK_OBJECTS 0x4
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* pointers/data manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct {
|
||||
VALUE klass;
|
||||
VALUE mImpl;
|
||||
void (*mark)(void *);
|
||||
void (*destroy)(void *);
|
||||
} swig_class;
|
||||
|
||||
|
||||
static VALUE _mSWIG = Qnil;
|
||||
static VALUE _cSWIG_Pointer = Qnil;
|
||||
static VALUE swig_runtime_data_type_pointer = Qnil;
|
||||
|
||||
/* Initialize Ruby runtime support */
|
||||
SWIGRUNTIME void
|
||||
SWIG_Ruby_InitRuntime(void)
|
||||
{
|
||||
if (_mSWIG == Qnil) {
|
||||
_mSWIG = rb_define_module("SWIG");
|
||||
}
|
||||
}
|
||||
|
||||
/* Define Ruby class for C type */
|
||||
SWIGRUNTIME void
|
||||
SWIG_Ruby_define_class(swig_type_info *type)
|
||||
{
|
||||
VALUE klass;
|
||||
char *klass_name = (char *) malloc(4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
if (NIL_P(_cSWIG_Pointer)) {
|
||||
_cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject);
|
||||
rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new");
|
||||
}
|
||||
klass = rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer);
|
||||
free((void *) klass_name);
|
||||
}
|
||||
|
||||
/* Create a new pointer object */
|
||||
SWIGRUNTIME VALUE
|
||||
SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
|
||||
{
|
||||
int own = flags & SWIG_POINTER_OWN;
|
||||
int track = flags & SWIG_TRACK_OBJECTS;
|
||||
|
||||
char *klass_name;
|
||||
swig_class *sklass;
|
||||
VALUE klass;
|
||||
VALUE obj;
|
||||
|
||||
if (!ptr)
|
||||
return Qnil;
|
||||
|
||||
/* Have we already wrapped this pointer? */
|
||||
if (track) {
|
||||
obj = SWIG_RubyInstanceFor(ptr);
|
||||
if (obj != Qnil) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
if (type->clientdata) {
|
||||
sklass = (swig_class *) type->clientdata;
|
||||
obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), (own ? VOIDFUNC(sklass->destroy) : 0), ptr);
|
||||
} else {
|
||||
klass_name = (char *) malloc(4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
klass = rb_const_get(_mSWIG, rb_intern(klass_name));
|
||||
free((void *) klass_name);
|
||||
obj = Data_Wrap_Struct(klass, 0, 0, ptr);
|
||||
}
|
||||
rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
|
||||
|
||||
/* Keep track of this object if necessary */
|
||||
if (track) {
|
||||
SWIG_RubyAddTracking(ptr, obj);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* Create a new class instance (always owned) */
|
||||
SWIGRUNTIME VALUE
|
||||
SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type)
|
||||
{
|
||||
VALUE obj;
|
||||
swig_class *sklass = (swig_class *) type->clientdata;
|
||||
obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0);
|
||||
rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* Get type mangle from class name */
|
||||
SWIGRUNTIMEINLINE char *
|
||||
SWIG_Ruby_MangleStr(VALUE obj)
|
||||
{
|
||||
VALUE stype = rb_iv_get(obj, "__swigtype__");
|
||||
return StringValuePtr(stype);
|
||||
}
|
||||
|
||||
/* Convert a pointer value */
|
||||
SWIGRUNTIME int
|
||||
SWIG_Ruby_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flags)
|
||||
{
|
||||
char *c;
|
||||
swig_cast_info *tc;
|
||||
|
||||
/* Grab the pointer */
|
||||
if (NIL_P(obj)) {
|
||||
*ptr = 0;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (TYPE(obj) != T_DATA) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
Data_Get_Struct(obj, void, *ptr);
|
||||
}
|
||||
|
||||
|
||||
/* Check to see if the input object is giving up ownership
|
||||
of the underlying C struct or C++ object. If so then we
|
||||
need to reset the destructor since the Ruby object no
|
||||
longer owns the underlying C++ object.*/
|
||||
if (flags & SWIG_POINTER_DISOWN) {
|
||||
if (flags & SWIG_TRACK_OBJECTS) {
|
||||
/* We are tracking objects. Thus we change the destructor
|
||||
* to SWIG_RubyRemoveTracking. This allows us to
|
||||
* remove the mapping from the C++ to Ruby object
|
||||
* when the Ruby object is garbage collected. If we don't
|
||||
* do this, then it is possible we will return a reference
|
||||
* to a Ruby object that no longer exists thereby crashing Ruby. */
|
||||
RDATA(obj)->dfree = SWIG_RubyRemoveTracking;
|
||||
} else {
|
||||
RDATA(obj)->dfree = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Do type-checking if type info was provided */
|
||||
if (ty) {
|
||||
if (ty->clientdata) {
|
||||
if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
|
||||
if (*ptr == 0) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
if ((c = SWIG_MangleStr(obj)) == NULL) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
*ptr = SWIG_TypeCast(tc, *ptr);
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* Check convert */
|
||||
SWIGRUNTIMEINLINE int
|
||||
SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty)
|
||||
{
|
||||
char *c = SWIG_MangleStr(obj);
|
||||
if (!c) return 0;
|
||||
return SWIG_TypeCheck(c,ty) != 0;
|
||||
}
|
||||
|
||||
SWIGRUNTIME VALUE
|
||||
SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) {
|
||||
char result[1024];
|
||||
char *r = result;
|
||||
if ((2*sz + 1 + strlen(type->name)) > 1000) return 0;
|
||||
*(r++) = '_';
|
||||
r = SWIG_PackData(r, ptr, sz);
|
||||
strcpy(r, type->name);
|
||||
return rb_str_new2(result);
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
SWIGRUNTIME int
|
||||
SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags) {
|
||||
swig_cast_info *tc;
|
||||
const char *c;
|
||||
|
||||
if (TYPE(obj) != T_STRING) goto type_error;
|
||||
c = StringValuePtr(obj);
|
||||
/* Pointer values must start with leading underscore */
|
||||
if (*c != '_') goto type_error;
|
||||
c++;
|
||||
c = SWIG_UnpackData(c, ptr, sz);
|
||||
if (ty) {
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) goto type_error;
|
||||
}
|
||||
return SWIG_OK;
|
||||
|
||||
type_error:
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
SWIGRUNTIME swig_module_info *
|
||||
SWIG_Ruby_GetModule()
|
||||
{
|
||||
VALUE pointer;
|
||||
swig_module_info *ret = 0;
|
||||
|
||||
/* first check if pointer already created */
|
||||
pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
|
||||
if (pointer != Qnil) {
|
||||
Data_Get_Struct(pointer, swig_module_info, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SWIGRUNTIME void
|
||||
SWIG_Ruby_SetModule(swig_module_info *pointer)
|
||||
{
|
||||
/* register a new class */
|
||||
VALUE cl = rb_define_class("swig_runtime_data", rb_cObject);
|
||||
/* create and store the structure pointer to a global variable */
|
||||
swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer);
|
||||
rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,28 +1,5 @@
|
|||
/* ruby.swg */
|
||||
/* Implementation : RUBY */
|
||||
#define SWIGRUBY 1
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
/* Flags for pointer conversion */
|
||||
#define SWIG_POINTER_EXCEPTION 0x1
|
||||
#define SWIG_POINTER_OWN 0x1
|
||||
#define SWIG_POINTER_DISOWN 0x2
|
||||
#define SWIG_TRACK_OBJECTS 0x4
|
||||
|
||||
#define NUM2USHRT(n) (\
|
||||
(0 <= NUM2UINT(n) && NUM2UINT(n) <= USHRT_MAX)\
|
||||
? (unsigned short) NUM2UINT(n) \
|
||||
: (rb_raise(rb_eArgError, "integer %d out of range of `unsigned short'",\
|
||||
NUM2UINT(n)), (short)0)\
|
||||
)
|
||||
|
||||
#define NUM2SHRT(n) (\
|
||||
(SHRT_MIN <= NUM2INT(n) && NUM2INT(n) <= SHRT_MAX)\
|
||||
? (short)NUM2INT(n)\
|
||||
: (rb_raise(rb_eArgError, "integer %d out of range of `short'",\
|
||||
NUM2INT(n)), (short)0)\
|
||||
)
|
||||
%insert(runtime) %{
|
||||
#include <ruby.h>
|
||||
|
||||
/* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */
|
||||
#ifndef NUM2LL
|
||||
|
|
@ -79,13 +56,6 @@
|
|||
# define VOIDFUNC(f) (f)
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
VALUE klass;
|
||||
VALUE mImpl;
|
||||
void (*mark)(void *);
|
||||
void (*destroy)(void *);
|
||||
} swig_class;
|
||||
|
||||
/* Don't use for expressions have side effect */
|
||||
#ifndef RB_STRING_VALUE
|
||||
#define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s)))
|
||||
|
|
@ -111,7 +81,9 @@ typedef struct {
|
|||
#define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new")
|
||||
#endif
|
||||
|
||||
/* Contract support */
|
||||
|
||||
#define SWIG_contract_assert(expr, msg) if (!(expr)) { rb_raise(rb_eRuntimeError, (char *) msg ); } else
|
||||
%}
|
||||
|
||||
%runtime "swigrun.swg" /* Common C API type-checking code */
|
||||
%runtime "rubytracking.swg" /* API for tracking C++ classes to Ruby objects */
|
||||
%runtime "rubyrun.swg"
|
||||
%runtime "rubyapi.swg"
|
||||
|
|
@ -1,125 +1,60 @@
|
|||
/* --- Input Values --- */
|
||||
|
||||
%typemap(in) char * "$1 = StringValuePtr($input);";
|
||||
%typemap(in) char [ANY] "$1 = StringValuePtr($input);";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* String & length
|
||||
* utility methods for char strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(in) (int LENGTH, char *STRING) {
|
||||
$1 = ($1_ltype) StringValueLen($input);
|
||||
$2 = ($2_ltype) StringValuePtr($input);
|
||||
}
|
||||
|
||||
%typemap(in) (char *STRING, int LENGTH) {
|
||||
$1 = ($1_ltype) StringValuePtr($input);
|
||||
$2 = ($2_ltype) StringValueLen($input);
|
||||
}
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
|
||||
/* Single char */
|
||||
%typemap(out) char "$result = rb_str_new(&$1,1);";
|
||||
%typemap(out) const char & "$result = rb_str_new($1, 1);";
|
||||
|
||||
/* C string */
|
||||
%typemap(out) char * "$result = rb_str_new2($1);";
|
||||
|
||||
/* Special typemap for character array return values */
|
||||
%typemap(out) char [ANY], const char [ANY] "$result = rb_str_new2($1);";
|
||||
|
||||
/* --- Variable Input --- */
|
||||
|
||||
/* A string */
|
||||
#ifdef __cplusplus
|
||||
|
||||
%typemap(varin) char * {
|
||||
char *temp = (char *) StringValuePtr($input);
|
||||
if ($1) delete [] $1;
|
||||
$1 = ($type) new char[strlen(temp)+1];
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
|
||||
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
|
||||
char *temp = (char *) StringValuePtr($input);
|
||||
$1 = ($type) new char[strlen(temp)+1];
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
%typemap(varin) char * {
|
||||
char *temp = (char *) StringValuePtr($input);
|
||||
if ($1) free((char*) $1);
|
||||
$1 = ($type) malloc(strlen(temp)+1);
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
|
||||
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
|
||||
char *temp = (char *) StringValuePtr($input);
|
||||
$1 = ($type) malloc(strlen(temp)+1);
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* Special case for string array variables */
|
||||
%typemap(varin,
|
||||
warning="462:Unable to set variable of type char []") char[]
|
||||
%fragment("SWIG_AsCharPtrAndSize","header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
rb_raise(rb_eTypeError, "C/C++ variable '$name' is read-only.");
|
||||
static swig_type_info* pchar_info = 0;
|
||||
char* vptr = 0;
|
||||
if (!pchar_info) pchar_info = SWIG_TypeQuery("char *");
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_info, 0) == SWIG_OK) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (TYPE(obj) == T_STRING) {
|
||||
char *cstr = rb_string_value_ptr(&(obj));
|
||||
size_t size = RSTRING(obj)->len + 1;
|
||||
if (cptr) {
|
||||
if (alloc) {
|
||||
if (*alloc == SWIG_NEWOBJ) {
|
||||
*cptr = SWIG_new_copy_array(cstr, size, char);
|
||||
} else {
|
||||
*cptr = cstr;
|
||||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (psize) *psize = size;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(varin) char[ANY] "strncpy($1,StringValuePtr($input),$1_dim0);";
|
||||
|
||||
/* --- Variable Output --- */
|
||||
|
||||
/* Character */
|
||||
%typemap(varout) char "$result = rb_str_new(&$1,1);";
|
||||
|
||||
/* C string */
|
||||
%typemap(varout) char * "$result = rb_str_new2($1);";
|
||||
|
||||
/* Special typemap for character array return values */
|
||||
%typemap(varout) char [ANY], const char [ANY] "$result = rb_str_new2($1);";
|
||||
|
||||
/* --- Constants --- */
|
||||
|
||||
%typemap(constant) char {
|
||||
char temp = $1;
|
||||
rb_define_const($module,"$symname", rb_str_new(&temp,1));
|
||||
%fragment("SWIG_FromCharPtrAndSize","header") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
||||
{
|
||||
if (carray) {
|
||||
if (size > LONG_MAX) {
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(carray,char *), SWIG_TypeQuery("char *"), 0);
|
||||
} else {
|
||||
return rb_str_new(carray, SWIG_numeric_cast(size,long));
|
||||
}
|
||||
} else {
|
||||
return Qnil;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(constant) char *
|
||||
"rb_define_const($module,\"$symname\", rb_str_new2($1));";
|
||||
|
||||
/* directorin typemaps */
|
||||
|
||||
%typemap(directorin) char * "$input = rb_str_new2($1);";
|
||||
|
||||
/* directorout typemaps */
|
||||
|
||||
%typemap(directorout) char * "$result = STR2CSTR($1);";
|
||||
%typemap(directorout) const char * "$result = STR2CSTR($1);";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_CHAR) char {
|
||||
$1 = (TYPE($input) == T_STRING && (RSTRING($input)->len == 1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_STRING) char * {
|
||||
$1 = (TYPE($input) == T_STRING) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling
|
||||
* The plain char * handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) char * {
|
||||
rb_raise(rb_eRuntimeError, $1);
|
||||
}
|
||||
|
||||
%include <typemaps/strings.swg>
|
||||
%typemap_string(char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen)
|
||||
|
|
|
|||
|
|
@ -1,162 +0,0 @@
|
|||
/* --- Input typemaps --- */
|
||||
|
||||
%typemap(in) SWIGTYPE *,
|
||||
SWIGTYPE []
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, $disown);"
|
||||
|
||||
%typemap(in) SWIGTYPE *DISOWN
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN);"
|
||||
|
||||
/* Additional check for null references */
|
||||
%typemap(in) SWIGTYPE &
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, $disown); if ($1 == NULL) rb_raise(rb_eTypeError, \"null reference\");"
|
||||
|
||||
/* Object passed by value. Convert to a pointer */
|
||||
%typemap(in) SWIGTYPE {
|
||||
$&1_ltype ptr;
|
||||
SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, $disown);
|
||||
if (ptr) $1 = *ptr;
|
||||
}
|
||||
|
||||
/* Pointer to a class member */
|
||||
%typemap(in) SWIGTYPE (CLASS::*) "SWIG_ConvertPacked($input, (void *) &$1, sizeof($1_type), $1_descriptor, $disown);";
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
|
||||
/* Pointers, references, and arrays */
|
||||
%typemap(out) SWIGTYPE*, SWIGTYPE &, SWIGTYPE []
|
||||
"$result = SWIG_NewPointerObj((void *) $1, $1_descriptor,$owner);";
|
||||
|
||||
/* Dynamic casts */
|
||||
|
||||
%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
|
||||
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1);
|
||||
$result = SWIG_NewPointerObj((void *) $1, ty,$owner);
|
||||
}
|
||||
|
||||
/* Member pointer */
|
||||
%typemap(out) SWIGTYPE (CLASS::*) "$result = SWIG_NewPackedObj((void *) &$1, sizeof($1_type), $1_descriptor);";
|
||||
|
||||
/* Primitive types--return by value */
|
||||
%typemap(out) SWIGTYPE
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = new $1_ltype(($1_ltype &)$1);
|
||||
$result = SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1);
|
||||
}
|
||||
#else
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = ($&1_ltype) malloc(sizeof($1_type));
|
||||
memmove(resultptr, &$1, sizeof($1_type));
|
||||
$result = SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --- Variable Input --- */
|
||||
|
||||
%typemap(varin) SWIGTYPE [ANY] {
|
||||
void *temp;
|
||||
int ii;
|
||||
$1_basetype *b = 0;
|
||||
if ((SWIG_ConvertPtr($input,(void **) &temp, $1_descriptor, 0)) == -1) {
|
||||
rb_raise(rb_eTypeError, "C variable '$name ($1_ltype)'");
|
||||
}
|
||||
b = ($1_basetype *) $1;
|
||||
for (ii = 0; ii < $1_size; ii++) b[ii] = *(($1_basetype *) temp + ii);
|
||||
}
|
||||
|
||||
%typemap(varin,warning="462: Unable to set dimensionless array variable") SWIGTYPE [] {
|
||||
rb_raise(rb_eTypeError, "C/C++ variable '$name' is readonly");
|
||||
}
|
||||
|
||||
/* Typemaps for pointers. Note: the SWIG run-time type checker works
|
||||
even if a pointer happens to be mapped to a Ruby class */
|
||||
|
||||
%typemap(varin) SWIGTYPE *
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);"
|
||||
|
||||
%typemap(varin) SWIGTYPE & {
|
||||
void *temp;
|
||||
SWIG_ConvertPtr($input, (void **) &temp, $1_descriptor, 1);
|
||||
$1 = *($1_ltype) temp;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE {
|
||||
$&1_ltype ptr;
|
||||
SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 1);
|
||||
if (ptr) $1 = *ptr;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE (CLASS::*) {
|
||||
char temp[sizeof($1_type)];
|
||||
SWIG_ConvertPacked($input, (void *) temp, sizeof($1_type), $1_descriptor, 1);
|
||||
memmove((void *) &$1, temp, sizeof($1_type));
|
||||
}
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
|
||||
/* Pointers, references, and arrays */
|
||||
%typemap(varout) SWIGTYPE*, SWIGTYPE []
|
||||
"$result = SWIG_NewPointerObj((void *) $1, $1_descriptor,0);";
|
||||
|
||||
%typemap(varout) SWIGTYPE &
|
||||
"$result = SWIG_NewPointerObj((void *) &$1, $1_descriptor,0);";
|
||||
|
||||
/* Copy by value */
|
||||
%typemap(varout) SWIGTYPE "$result = SWIG_NewPointerObj((void *) &$1, $&1_descriptor, 0);";
|
||||
|
||||
/* Member pointer */
|
||||
%typemap(varout) SWIGTYPE (CLASS::*) "$result = SWIG_NewPackedObj((void *) &$1, sizeof($1_type), $1_descriptor);";
|
||||
|
||||
/* --- Constants --- */
|
||||
|
||||
%typemap(constant) SWIGTYPE*, SWIGTYPE &, SWIGTYPE []
|
||||
"rb_define_const($module,\"$symname\", SWIG_NewPointerObj((void *) $1, $1_descriptor,0));";
|
||||
|
||||
%typemap(constant) SWIGTYPE "rb_define_const($module,\"$symname\", SWIG_NewPointerObj((void *) &$1, $&1_descriptor, 0));";
|
||||
|
||||
%typemap(constant) SWIGTYPE (CLASS::*) "rb_define_const($module, \"$symname\", SWIG_NewPackedObj((void *) &$1, sizeof($type), $1_descriptor));";
|
||||
|
||||
/* --- directorin typemaps --- */
|
||||
|
||||
%typemap(directorin) SWIGTYPE*
|
||||
"$input = SWIG_NewPointerObj((void *) $1, $1_descriptor,0);";
|
||||
|
||||
%typemap(directorin) SWIGTYPE
|
||||
"$input = SWIG_NewPointerObj((void *) &$1, $1_descriptor,0);";
|
||||
|
||||
%typemap(directorin) SWIGTYPE&
|
||||
"$input = SWIG_NewPointerObj((void *) &$1, $1_descriptor,0);";
|
||||
|
||||
|
||||
/* --- directorout typemaps --- */
|
||||
%typemap(directorout) SWIGTYPE *,
|
||||
SWIGTYPE &,
|
||||
SWIGTYPE []
|
||||
"if ((SWIG_ConvertPtr($input,(void **) &$result, $descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
|
||||
void *ptr;
|
||||
$1 = (NIL_P($input) || (TYPE($input) == T_DATA && SWIG_ConvertPtr($input, &ptr, $&1_descriptor, 0) != -1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
|
||||
void *ptr;
|
||||
$1 = (NIL_P($input) || (TYPE($input) == T_DATA && SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0) != -1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling.
|
||||
* Note that in Ruby, we can only raise an exception class and
|
||||
* not some arbitrary object as in Python.
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) SWIGTYPE, SWIGTYPE *, SWIGTYPE [ANY], SWIGTYPE &
|
||||
"(void)$1; rb_raise(rb_eRuntimeError, \"$1_type\");";
|
||||
|
||||
|
|
@ -7,109 +7,120 @@
|
|||
* garbage collector.
|
||||
************************************************************************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Global Ruby hash table to store Trackings from C/C++
|
||||
structs to Ruby Objects. */
|
||||
static VALUE swig_ruby_trackings;
|
||||
|
||||
/* Setup a Ruby hash table to store Trackings */
|
||||
static void SWIG_RubyInitializeTrackings() {
|
||||
/* 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);
|
||||
SWIGRUNTIME void SWIG_RubyInitializeTrackings() {
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/* Get a Ruby number to reference a pointer */
|
||||
static VALUE SWIG_RubyPtrToReference(void* ptr) {
|
||||
/* We cast the pointer to an unsigned long
|
||||
and then store a reference to it using
|
||||
a Ruby number object. */
|
||||
SWIGRUNTIME VALUE SWIG_RubyPtrToReference(void* ptr) {
|
||||
/* We cast the pointer to an unsigned long
|
||||
and then store a reference to it using
|
||||
a Ruby number object. */
|
||||
|
||||
/* Convert the pointer to a Ruby number */
|
||||
unsigned long value = (unsigned long) ptr;
|
||||
return LONG2NUM(value);
|
||||
/* Convert the pointer to a Ruby number */
|
||||
unsigned long value = (unsigned long) ptr;
|
||||
return LONG2NUM(value);
|
||||
}
|
||||
|
||||
/* Get a Ruby number to reference an object */
|
||||
static VALUE SWIG_RubyObjectToReference(VALUE object) {
|
||||
/* We cast the object to an unsigned long
|
||||
and then store a reference to it using
|
||||
a Ruby number object. */
|
||||
SWIGRUNTIME VALUE SWIG_RubyObjectToReference(VALUE object) {
|
||||
/* We cast the object to an unsigned long
|
||||
and then store a reference to it using
|
||||
a Ruby number object. */
|
||||
|
||||
/* Convert the Object to a Ruby number */
|
||||
unsigned long value = (unsigned long) object;
|
||||
return LONG2NUM(value);
|
||||
/* Convert the Object to a Ruby number */
|
||||
unsigned long value = (unsigned long) object;
|
||||
return LONG2NUM(value);
|
||||
}
|
||||
|
||||
/* Get a Ruby object from a previously stored reference */
|
||||
static VALUE SWIG_RubyReferenceToObject(VALUE reference) {
|
||||
/* The provided Ruby number object is a reference
|
||||
to the Ruby object we want.*/
|
||||
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;
|
||||
/* First convert the Ruby number to a C number */
|
||||
unsigned long value = NUM2LONG(reference);
|
||||
return (VALUE) value;
|
||||
}
|
||||
|
||||
/* Add a Tracking from a C/C++ struct to a Ruby object */
|
||||
static void SWIG_RubyAddTracking(void* ptr, VALUE object) {
|
||||
/* In a Ruby hash table we store the pointer and
|
||||
the associated Ruby object. The trick here is
|
||||
that we cannot store the Ruby object directly - if
|
||||
we do then it cannot be garbage collected. So
|
||||
instead we typecast it as a unsigned long and
|
||||
convert it to a Ruby number object.*/
|
||||
SWIGRUNTIME void SWIG_RubyAddTracking(void* ptr, VALUE object) {
|
||||
/* In a Ruby hash table we store the pointer and
|
||||
the associated Ruby object. The trick here is
|
||||
that we cannot store the Ruby object directly - if
|
||||
we do then it cannot be garbage collected. So
|
||||
instead we typecast it as a unsigned long and
|
||||
convert it to a Ruby number object.*/
|
||||
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
|
||||
/* Get a reference to the Ruby object as a Ruby number */
|
||||
VALUE value = SWIG_RubyObjectToReference(object);
|
||||
/* Get a reference to the Ruby object as a Ruby number */
|
||||
VALUE value = SWIG_RubyObjectToReference(object);
|
||||
|
||||
/* Store the mapping to the global hash table. */
|
||||
rb_hash_aset(swig_ruby_trackings, key, value);
|
||||
rb_hash_aset(swig_ruby_trackings, key, value);
|
||||
}
|
||||
|
||||
/* Get the Ruby object that owns the specified C/C++ struct */
|
||||
static VALUE SWIG_RubyInstanceFor(void* ptr) {
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
SWIGRUNTIME VALUE SWIG_RubyInstanceFor(void* ptr) {
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
|
||||
/* Now lookup the value stored in the global hash table */
|
||||
VALUE value = rb_hash_aref(swig_ruby_trackings, key);
|
||||
/* Now lookup the value stored in the global hash table */
|
||||
VALUE value = rb_hash_aref(swig_ruby_trackings, key);
|
||||
|
||||
if (value == Qnil) {
|
||||
/* No object exists - return nil. */
|
||||
return Qnil;
|
||||
}
|
||||
else {
|
||||
/* Convert this value to Ruby object */
|
||||
return SWIG_RubyReferenceToObject(value);
|
||||
}
|
||||
if (value == Qnil) {
|
||||
/* No object exists - return nil. */
|
||||
return Qnil;
|
||||
}
|
||||
else {
|
||||
/* Convert this value to Ruby object */
|
||||
return SWIG_RubyReferenceToObject(value);
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove a Tracking from a C/C++ struct to a Ruby object */
|
||||
static void SWIG_RubyRemoveTracking(void* ptr) {
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
SWIGRUNTIME void SWIG_RubyRemoveTracking(void* ptr) {
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
|
||||
/* Define delete method - in C++ this could be marked as
|
||||
static but unfortunately not in C. */
|
||||
VALUE delete_function = rb_intern("delete");
|
||||
/* Define delete method - in C++ this could be marked as
|
||||
static but unfortunately not in C. */
|
||||
VALUE delete_function = rb_intern("delete");
|
||||
|
||||
/* Delete the object from the hash table by calling Ruby's
|
||||
do this we need to call the Hash.delete method.*/
|
||||
rb_funcall(swig_ruby_trackings, delete_function, 1, key);
|
||||
/* Delete the object from the hash table by calling Ruby's
|
||||
do this we need to call the Hash.delete method.*/
|
||||
rb_funcall(swig_ruby_trackings, delete_function, 1, key);
|
||||
}
|
||||
|
||||
/* This is a helper method that unlinks a Ruby object from its
|
||||
underlying C++ object. This is needed if the lifetime of the
|
||||
Ruby object is longer than the C++ object */
|
||||
static void SWIG_RubyUnlinkObjects(void* ptr) {
|
||||
VALUE object = SWIG_RubyInstanceFor(ptr);
|
||||
SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) {
|
||||
VALUE object = SWIG_RubyInstanceFor(ptr);
|
||||
|
||||
if (object != Qnil) {
|
||||
DATA_PTR(object) = 0;
|
||||
}
|
||||
if (object != Qnil) {
|
||||
DATA_PTR(object) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
45
SWIG/Lib/ruby/rubytypemaps.swg
Normal file
45
SWIG/Lib/ruby/rubytypemaps.swg
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Typemap specializations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* directors are supported in Python */
|
||||
#ifndef SWIG_DIRECTOR_TYPEMAPS
|
||||
#define SWIG_DIRECTOR_TYPEMAPS
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Basic definitions
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%define_swig_object(VALUE)
|
||||
|
||||
#define SWIG_SetResultObj(obj) $result = obj
|
||||
#define SWIG_AppendResultObj(obj) $result = SWIG_Ruby_AppendResult($result, obj)
|
||||
#define SWIG_SetConstantObj(name, obj) rb_define_const($module, name, obj);
|
||||
#define SWIG_NoneObject() Qnil
|
||||
|
||||
/* error manipulation */
|
||||
#define SWIG_ErrorType(code) SWIG_Ruby_ErrorType(code)
|
||||
#define SWIG_SetErrorObj(code, obj) SWIG_Ruby_SetErrorMsg(SWIG_ErrorType(code),obj)
|
||||
#define SWIG_SetErrorMsg(code, msg) SWIG_Ruby_SetErrorMsg(SWIG_ErrorType(code),msg)
|
||||
#define SWIG_ExceptionObj(d, type, obj) rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(obj)))
|
||||
#define SWIG_DirOutFail(code, msg) Swig::DirectorTypeMismatchException::raise(SWIG_ErrorType(code), msg)
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* All the typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "rubyfragments.swg"
|
||||
|
||||
%include <typemaps/swigtype.swg>
|
||||
%include <typemaps/void.swg>
|
||||
%include <typemaps/valtypes.swg>
|
||||
%include <typemaps/ptrtypes.swg>
|
||||
%include <typemaps/swigobject.swg>
|
||||
%include <typemaps/inoutlist.swg>
|
||||
%include <rubyprimtypes.swg>
|
||||
%include <rubystrings.swg>
|
||||
%include <typemaps/misctypes.swg>
|
||||
%include <typemaps/enumint.swg>
|
||||
|
||||
6
SWIG/Lib/ruby/rubyuserdir.swg
Normal file
6
SWIG/Lib/ruby/rubyuserdir.swg
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#define %alias %feature("alias")
|
||||
#define %freefunc %feature("freefunc")
|
||||
#define %markfunc %feature("markfunc")
|
||||
#define %mixin %feature("mixin")
|
||||
#define %predicate %feature("predicate", "1")
|
||||
#define %trackobjects %feature("trackobjects")
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* Void * - Accepts any kind of pointer
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* in */
|
||||
|
||||
%typemap(in) void *
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, 0, SWIG_POINTER_EXCEPTION|$disown);";
|
||||
|
||||
/* out */
|
||||
|
||||
%typemap(out) void "$result = Qnil;";
|
||||
|
||||
/* varin */
|
||||
|
||||
%typemap(varin) void *
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, 0, 1);";
|
||||
|
||||
/* varout */
|
||||
|
||||
%typemap(varout) void "$result = Qnil;";
|
||||
|
||||
/* directorout */
|
||||
|
||||
%typemap(directorout) void * "if ((SWIG_ConvertPtr($input,(void **) &$result, 0, SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
|
||||
|
||||
/* typecheck */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
|
||||
void *ptr;
|
||||
$1 = (NIL_P($input) || (TYPE($input) == T_DATA && SWIG_ConvertPtr($input, &ptr, 0, 0) != -1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
74
SWIG/Lib/ruby/rubywstrings.swg
Normal file
74
SWIG/Lib/ruby/rubywstrings.swg
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* ------------------------------------------------------------
|
||||
* utility methods for wchar_t strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
Ruby doesn't support the wchar_t, so, we need to use an 'opaque' type.
|
||||
*/
|
||||
|
||||
%types(ruby_wchar_array *);
|
||||
|
||||
%fragment("ruby_wchar_array","header",fragment="<wchar.h>") {
|
||||
struct ruby_wchar_array {
|
||||
wchar_t *cptr;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
SWIGINTERN get_ruby_wchar_array_info() {
|
||||
static swig_type_info* ruby_wchar_array_info = 0;
|
||||
if (!ruby_wchar_array_info) ruby_wchar_array_info = SWIG_TypeQuery("ruby_wchar_array *");
|
||||
return ruby_wchar_array_info;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_AsWCharPtrAndSize","header",fragment="ruby_wchar_array") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
|
||||
{
|
||||
static swig_type_info* ptr_wchar_info = 0;
|
||||
wchar_t * vptr = 0;
|
||||
if (!ptr_wchar_info) ptr_wchar_info = SWIG_TypeQuery("wchar_t *");
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, ptr_wchar_info, 0) != SWIG_OK) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (wcslen(vptr) + 1) : 0;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
ruby_wchar_array *vptr = 0;
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, get_ruby_wchar_array_info(), 0) != SWIG_OK) {
|
||||
if (cptr) *cptr = vptr->cptr;
|
||||
if (psize) *psize = vprtr->size;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromWCharPtrAndSize","header",fragment="ruby_wchar_array") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
|
||||
{
|
||||
ruby_wchar_array *vptr = SWIG_new(ruby_wchar_array);
|
||||
vptr->cptr = carray;
|
||||
vptr->size = size;
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(carray,wchar_t *), get_ruby_wchar_array_info(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromWCharPtr","header",fragment="<wchar.h>") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_FromWCharPtr(const wchar_t * carray)
|
||||
{
|
||||
static swig_type_info* wchar_ptr_info = 0;
|
||||
if (!wchar_array_info) wchar_ptr_info = SWIG_TypeQuery("wchar_t *");
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(carray,wchar_t *), wchar_ptr_info, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The plain wchar_t * handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%include <typemaps/strbase.swg>
|
||||
%typemap_string(wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, wcslen);
|
||||
|
||||
|
|
@ -1,86 +1,30 @@
|
|||
//
|
||||
// SWIG typemaps for std::string
|
||||
// Luigi Ballabio
|
||||
// Apr 8, 2002
|
||||
// std::string
|
||||
//
|
||||
// Ruby implementation
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::string is typemapped by value
|
||||
// This can prevent exporting methods which return a string
|
||||
// in order for the user to modify it.
|
||||
// However, I think I'll wait until someone asks for it...
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%include exception.i
|
||||
#ifndef SWIG_STD_BASIC_STRING
|
||||
#define SWIG_STD_STRING
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
// Ruby wants class names to start with a capital letter
|
||||
%rename(String) string;
|
||||
class string;
|
||||
|
||||
/* Overloading check */
|
||||
%typemap(typecheck) string = char *;
|
||||
%typemap(typecheck) const string & = char *;
|
||||
|
||||
%typemap(in) string {
|
||||
if (TYPE($input) == T_STRING) {
|
||||
$1 = std::string(StringValuePtr($input));
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "not a string");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) const string & (std::string temp) {
|
||||
if (TYPE($input) == T_STRING) {
|
||||
temp = std::string(StringValuePtr($input));
|
||||
$1 = &temp;
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "not a string");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) string {
|
||||
$result = rb_str_new2($1.c_str());
|
||||
}
|
||||
|
||||
%typemap(out) const string & {
|
||||
$result = rb_str_new2($1->c_str());
|
||||
}
|
||||
|
||||
%typemap(directorin) string, const string &, string & {
|
||||
$input = rb_str_new2($1_name.c_str());
|
||||
}
|
||||
|
||||
%typemap(directorin) string *, const string * {
|
||||
$input = rb_str_new2($1_name->c_str());
|
||||
}
|
||||
|
||||
%typemap(directorout) string {
|
||||
if (TYPE($input) == T_STRING)
|
||||
$result = std::string(StringValuePtr($input));
|
||||
else
|
||||
throw Swig::DirectorTypeMismatchException("string expected");
|
||||
}
|
||||
|
||||
%typemap(directorout,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const string & {
|
||||
if (TYPE($input) == T_STRING) {
|
||||
static std::string temp = std::string(StringValuePtr($input));
|
||||
$result = &temp;
|
||||
} else {
|
||||
throw Swig::DirectorTypeMismatchException("string expected");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(throws) string, const string &
|
||||
"rb_raise(rb_eRuntimeError, $1.c_str());";
|
||||
|
||||
%typemap(throws) string *, const string *
|
||||
"rb_raise(rb_eRuntimeError, $1->c_str());";
|
||||
namespace std
|
||||
{
|
||||
class string;
|
||||
}
|
||||
|
||||
%include <typemaps/std_string.swg>
|
||||
%include <rubystrings.swg>
|
||||
|
||||
%std_string_asptr(std::string, char, SWIG_AsCharPtrAndSize)
|
||||
%std_string_from(std::string, SWIG_FromCharPtrAndSize)
|
||||
%std_string_asval(std::string)
|
||||
|
||||
%typemap_asptrfromn(SWIG_CCode(STRING), std::string);
|
||||
|
||||
#else
|
||||
|
||||
%include <std/std_string.i>
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,441 +1 @@
|
|||
//
|
||||
// typemaps for Ruby
|
||||
//
|
||||
// $Header$
|
||||
//
|
||||
// Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||
// Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
||||
//
|
||||
// Masaki Fukushima
|
||||
//
|
||||
|
||||
/*
|
||||
The SWIG typemap library provides a language independent mechanism for
|
||||
supporting output arguments, input values, and other C function
|
||||
calling mechanisms. The primary use of the library is to provide a
|
||||
better interface to certain C function--especially those involving
|
||||
pointers.
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Pointer handling
|
||||
//
|
||||
// These mappings provide support for input/output arguments and common
|
||||
// uses for C/C++ pointers.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// INPUT typemaps.
|
||||
// These remap a C pointer to be an "INPUT" value which is passed by value
|
||||
// instead of reference.
|
||||
|
||||
/*
|
||||
The following methods can be applied to turn a pointer into a simple
|
||||
"input" value. That is, instead of passing a pointer to an object,
|
||||
you would use a real value instead.
|
||||
|
||||
int *INPUT
|
||||
short *INPUT
|
||||
long *INPUT
|
||||
long long *INPUT
|
||||
unsigned int *INPUT
|
||||
unsigned short *INPUT
|
||||
unsigned long *INPUT
|
||||
unsigned long long *INPUT
|
||||
unsigned char *INPUT
|
||||
bool *INPUT
|
||||
float *INPUT
|
||||
double *INPUT
|
||||
|
||||
To use these, suppose you had a C function like this :
|
||||
|
||||
double fadd(double *a, double *b) {
|
||||
return *a+*b;
|
||||
}
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include typemaps.i
|
||||
double fadd(double *INPUT, double *INPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%apply double *INPUT { double *a, double *b };
|
||||
double fadd(double *a, double *b);
|
||||
|
||||
*/
|
||||
|
||||
%define INPUT_TYPEMAP(type, converter)
|
||||
%typemap(in) type *INPUT($*1_ltype temp), type &INPUT($*1_ltype temp)
|
||||
{
|
||||
temp = ($*1_ltype) converter($input);
|
||||
$1 = &temp;
|
||||
}
|
||||
%typemap(typecheck) type *INPUT = type;
|
||||
%typemap(typecheck) type &INPUT = type;
|
||||
%enddef
|
||||
|
||||
INPUT_TYPEMAP(float, NUM2DBL);
|
||||
INPUT_TYPEMAP(double, NUM2DBL);
|
||||
INPUT_TYPEMAP(int, NUM2INT);
|
||||
INPUT_TYPEMAP(short, NUM2SHRT);
|
||||
INPUT_TYPEMAP(long, NUM2LONG);
|
||||
INPUT_TYPEMAP(long long, NUM2LL);
|
||||
INPUT_TYPEMAP(unsigned int, NUM2UINT);
|
||||
INPUT_TYPEMAP(unsigned short, NUM2USHRT);
|
||||
INPUT_TYPEMAP(unsigned long, NUM2ULONG);
|
||||
INPUT_TYPEMAP(unsigned long long, NUM2ULL);
|
||||
INPUT_TYPEMAP(unsigned char, NUM2UINT);
|
||||
INPUT_TYPEMAP(signed char, NUM2INT);
|
||||
INPUT_TYPEMAP(bool, RTEST);
|
||||
|
||||
#undef INPUT_TYPEMAP
|
||||
|
||||
// OUTPUT typemaps. These typemaps are used for parameters that
|
||||
// are output only. The output value is appended to the result as
|
||||
// a array element.
|
||||
|
||||
/*
|
||||
The following methods can be applied to turn a pointer into an "output"
|
||||
value. When calling a function, no input value would be given for
|
||||
a parameter, but an output value would be returned. In the case of
|
||||
multiple output values, they are returned in the form of a Ruby Array.
|
||||
|
||||
int *OUTPUT
|
||||
short *OUTPUT
|
||||
long *OUTPUT
|
||||
long long *OUTPUT
|
||||
unsigned int *OUTPUT
|
||||
unsigned short *OUTPUT
|
||||
unsigned long *OUTPUT
|
||||
unsigned long long *OUTPUT
|
||||
unsigned char *OUTPUT
|
||||
bool *OUTPUT
|
||||
float *OUTPUT
|
||||
double *OUTPUT
|
||||
|
||||
For example, suppose you were trying to wrap the modf() function in the
|
||||
C math library which splits x into integral and fractional parts (and
|
||||
returns the integer part in one of its parameters).K:
|
||||
|
||||
double modf(double x, double *ip);
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include typemaps.i
|
||||
double modf(double x, double *OUTPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%apply double *OUTPUT { double *ip };
|
||||
double modf(double x, double *ip);
|
||||
|
||||
The Ruby output of the function would be a Array containing both
|
||||
output values.
|
||||
*/
|
||||
|
||||
%include "fragments.i"
|
||||
|
||||
%define OUTPUT_TYPEMAP(type, converter, convtype)
|
||||
%typemap(in,numinputs=0) type *OUTPUT($*1_ltype temp), type &OUTPUT($*1_ltype temp) "$1 = &temp;";
|
||||
%typemap(argout, fragment="output_helper") type *OUTPUT, type &OUTPUT {
|
||||
VALUE o = converter(convtype (*$1));
|
||||
$result = output_helper($result, o);
|
||||
}
|
||||
%enddef
|
||||
|
||||
OUTPUT_TYPEMAP(int, INT2NUM, (int));
|
||||
OUTPUT_TYPEMAP(short, INT2NUM, (int));
|
||||
OUTPUT_TYPEMAP(long, INT2NUM, (long));
|
||||
OUTPUT_TYPEMAP(long long, LL2NUM, (long long));
|
||||
OUTPUT_TYPEMAP(unsigned int, UINT2NUM, (unsigned int));
|
||||
OUTPUT_TYPEMAP(unsigned short, UINT2NUM, (unsigned int));
|
||||
OUTPUT_TYPEMAP(unsigned long, UINT2NUM, (unsigned long));
|
||||
OUTPUT_TYPEMAP(unsigned long long, ULL2NUM, (unsigned long long));
|
||||
OUTPUT_TYPEMAP(unsigned char, UINT2NUM, (unsigned int));
|
||||
OUTPUT_TYPEMAP(signed char, INT2NUM, (int));
|
||||
OUTPUT_TYPEMAP(float, rb_float_new, (double));
|
||||
OUTPUT_TYPEMAP(double, rb_float_new, (double));
|
||||
|
||||
#undef OUTPUT_TYPEMAP
|
||||
|
||||
%typemap(in,numinputs=0) bool *OUTPUT(bool temp), bool &OUTPUT(bool temp) "$1 = &temp;";
|
||||
%typemap(argout, fragment="output_helper") bool *OUTPUT, bool &OUTPUT {
|
||||
VALUE o = (*$1) ? Qtrue : Qfalse;
|
||||
$result = output_helper($result, o);
|
||||
}
|
||||
|
||||
// INOUT
|
||||
// Mappings for an argument that is both an input and output
|
||||
// parameter
|
||||
|
||||
/*
|
||||
The following methods can be applied to make a function parameter both
|
||||
an input and output value. This combines the behavior of both the
|
||||
"INPUT" and "OUTPUT" methods described earlier. Output values are
|
||||
returned in the form of a Ruby array.
|
||||
|
||||
int *INOUT
|
||||
short *INOUT
|
||||
long *INOUT
|
||||
long long *INOUT
|
||||
unsigned int *INOUT
|
||||
unsigned short *INOUT
|
||||
unsigned long *INOUT
|
||||
unsigned long long *INOUT
|
||||
unsigned char *INOUT
|
||||
bool *INOUT
|
||||
float *INOUT
|
||||
double *INOUT
|
||||
|
||||
For example, suppose you were trying to wrap the following function :
|
||||
|
||||
void neg(double *x) {
|
||||
*x = -(*x);
|
||||
}
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include typemaps.i
|
||||
void neg(double *INOUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include typemaps.i
|
||||
%apply double *INOUT { double *x };
|
||||
void neg(double *x);
|
||||
|
||||
Unlike C, this mapping does not directly modify the input value (since
|
||||
this makes no sense in Ruby). Rather, the modified input value shows
|
||||
up as the return value of the function. Thus, to apply this function
|
||||
to a Ruby variable you might do this :
|
||||
|
||||
x = neg(x)
|
||||
|
||||
Note : previous versions of SWIG used the symbol 'BOTH' to mark
|
||||
input/output arguments. This is still supported, but will be slowly
|
||||
phased out in future releases.
|
||||
|
||||
*/
|
||||
|
||||
%typemap(in) int *INOUT = int *INPUT;
|
||||
%typemap(in) short *INOUT = short *INPUT;
|
||||
%typemap(in) long *INOUT = long *INPUT;
|
||||
%typemap(in) long long *INOUT = long long *INPUT;
|
||||
%typemap(in) unsigned *INOUT = unsigned *INPUT;
|
||||
%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
|
||||
%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
|
||||
%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
|
||||
%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
|
||||
%typemap(in) signed char *INOUT = signed char *INPUT;
|
||||
%typemap(in) bool *INOUT = bool *INPUT;
|
||||
%typemap(in) float *INOUT = float *INPUT;
|
||||
%typemap(in) double *INOUT = double *INPUT;
|
||||
|
||||
%typemap(in) int &INOUT = int &INPUT;
|
||||
%typemap(in) short &INOUT = short &INPUT;
|
||||
%typemap(in) long &INOUT = long &INPUT;
|
||||
%typemap(in) long long &INOUT = long long &INPUT;
|
||||
%typemap(in) unsigned &INOUT = unsigned &INPUT;
|
||||
%typemap(in) unsigned short &INOUT = unsigned short &INPUT;
|
||||
%typemap(in) unsigned long &INOUT = unsigned long &INPUT;
|
||||
%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
|
||||
%typemap(in) unsigned char &INOUT = unsigned char &INPUT;
|
||||
%typemap(in) signed char &INOUT = signed char &INPUT;
|
||||
%typemap(in) bool &INOUT = bool &INPUT;
|
||||
%typemap(in) float &INOUT = float &INPUT;
|
||||
%typemap(in) double &INOUT = double &INPUT;
|
||||
|
||||
%typemap(argout) int *INOUT = int *OUTPUT;
|
||||
%typemap(argout) short *INOUT = short *OUTPUT;
|
||||
%typemap(argout) long *INOUT = long *OUTPUT;
|
||||
%typemap(argout) long long *INOUT = long long *OUTPUT;
|
||||
%typemap(argout) unsigned *INOUT = unsigned *OUTPUT;
|
||||
%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
|
||||
%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
|
||||
%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
|
||||
%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
|
||||
%typemap(argout) signed char *INOUT = signed char *OUTPUT;
|
||||
%typemap(argout) bool *INOUT = bool *OUTPUT;
|
||||
%typemap(argout) float *INOUT = float *OUTPUT;
|
||||
%typemap(argout) double *INOUT = double *OUTPUT;
|
||||
|
||||
%typemap(argout) int &INOUT = int &OUTPUT;
|
||||
%typemap(argout) short &INOUT = short &OUTPUT;
|
||||
%typemap(argout) long &INOUT = long &OUTPUT;
|
||||
%typemap(argout) long long &INOUT = long long &OUTPUT;
|
||||
%typemap(argout) unsigned &INOUT = unsigned &OUTPUT;
|
||||
%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
|
||||
%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
|
||||
%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
|
||||
%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
|
||||
%typemap(argout) signed char &INOUT = signed char &OUTPUT;
|
||||
%typemap(argout) bool &INOUT = bool &OUTPUT;
|
||||
%typemap(argout) float &INOUT = float &OUTPUT;
|
||||
%typemap(argout) double &INOUT = double &OUTPUT;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Special types
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
The typemaps.i library also provides the following mappings :
|
||||
|
||||
struct timeval *
|
||||
time_t
|
||||
|
||||
Ruby has builtin class Time. INPUT/OUTPUT typemap for timeval and
|
||||
time_t is provided.
|
||||
|
||||
int PROG_ARGC
|
||||
char **PROG_ARGV
|
||||
|
||||
Some C function receive argc and argv from C main function.
|
||||
This typemap provides ignore typemap which pass Ruby ARGV contents
|
||||
as argc and argv to C function.
|
||||
*/
|
||||
|
||||
|
||||
// struct timeval *
|
||||
%{
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
struct timeval rb_time_timeval(VALUE);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
%typemap(in) struct timeval *INPUT (struct timeval temp)
|
||||
{
|
||||
if (NIL_P($input))
|
||||
$1 = NULL;
|
||||
else {
|
||||
temp = rb_time_timeval($input);
|
||||
$1 = &temp;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in,numinputs=0) struct timeval *OUTPUT(struct timeval temp)
|
||||
{
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(argout) struct timeval *OUTPUT
|
||||
{
|
||||
$result = rb_time_new($1->tv_sec, $1->tv_usec);
|
||||
}
|
||||
|
||||
%typemap(out) struct timeval *
|
||||
{
|
||||
$result = rb_time_new($1->tv_sec, $1->tv_usec);
|
||||
}
|
||||
|
||||
%typemap(out) struct timespec *
|
||||
{
|
||||
$result = rb_time_new($1->tv_sec, $1->tv_nsec / 1000);
|
||||
}
|
||||
|
||||
// time_t
|
||||
%typemap(in) time_t
|
||||
{
|
||||
if (NIL_P($input))
|
||||
$1 = (time_t)-1;
|
||||
else
|
||||
$1 = NUM2LONG(rb_funcall($input, rb_intern("tv_sec"), 0));
|
||||
}
|
||||
|
||||
%typemap(out) time_t
|
||||
{
|
||||
$result = rb_time_new($1, 0);
|
||||
}
|
||||
|
||||
// argc and argv
|
||||
%typemap(in,numinputs=0) int PROG_ARGC {
|
||||
$1 = RARRAY(rb_argv)->len + 1;
|
||||
}
|
||||
|
||||
%typemap(in,numinputs=0) char **PROG_ARGV {
|
||||
int i, n;
|
||||
VALUE ary = rb_eval_string("[$0] + ARGV");
|
||||
n = RARRAY(ary)->len;
|
||||
$1 = (char **)malloc(n + 1);
|
||||
for (i = 0; i < n; i++) {
|
||||
VALUE v = rb_obj_as_string(RARRAY(ary)->ptr[i]);
|
||||
$1[i] = (char *)malloc(RSTRING(v)->len + 1);
|
||||
strcpy($1[i], RSTRING(v)->ptr);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(freearg) char **PROG_ARGV {
|
||||
int i, n = RARRAY(rb_argv)->len + 1;
|
||||
for (i = 0; i < n; i++) free($1[i]);
|
||||
free($1);
|
||||
}
|
||||
|
||||
// FILE *
|
||||
%{
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "rubyio.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
%typemap(in) FILE *READ {
|
||||
OpenFile *of;
|
||||
GetOpenFile($input, of);
|
||||
rb_io_check_readable(of);
|
||||
$1 = GetReadFile(of);
|
||||
rb_read_check($1);
|
||||
}
|
||||
|
||||
%typemap(in) FILE *READ_NOCHECK {
|
||||
OpenFile *of;
|
||||
GetOpenFile($input, of);
|
||||
rb_io_check_readable(of);
|
||||
$1 = GetReadFile(of);
|
||||
}
|
||||
|
||||
%typemap(in) FILE *WRITE {
|
||||
OpenFile *of;
|
||||
GetOpenFile($input, of);
|
||||
rb_io_check_writable(of);
|
||||
$1 = GetWriteFile(of);
|
||||
}
|
||||
|
||||
/* Overloading information */
|
||||
|
||||
%typemap(typecheck) double *INOUT = double;
|
||||
%typemap(typecheck) signed char *INOUT = signed char;
|
||||
%typemap(typecheck) unsigned char *INOUT = unsigned char;
|
||||
%typemap(typecheck) unsigned long *INOUT = unsigned long;
|
||||
%typemap(typecheck) unsigned long long *INOUT = unsigned long long;
|
||||
%typemap(typecheck) unsigned short *INOUT = unsigned short;
|
||||
%typemap(typecheck) unsigned int *INOUT = unsigned int;
|
||||
%typemap(typecheck) long *INOUT = long;
|
||||
%typemap(typecheck) long long *INOUT = long long;
|
||||
%typemap(typecheck) short *INOUT = short;
|
||||
%typemap(typecheck) int *INOUT = int;
|
||||
%typemap(typecheck) float *INOUT = float;
|
||||
|
||||
%typemap(typecheck) double &INOUT = double;
|
||||
%typemap(typecheck) signed char &INOUT = signed char;
|
||||
%typemap(typecheck) unsigned char &INOUT = unsigned char;
|
||||
%typemap(typecheck) unsigned long &INOUT = unsigned long;
|
||||
%typemap(typecheck) unsigned long long &INOUT = unsigned long long;
|
||||
%typemap(typecheck) unsigned short &INOUT = unsigned short;
|
||||
%typemap(typecheck) unsigned int &INOUT = unsigned int;
|
||||
%typemap(typecheck) long &INOUT = long;
|
||||
%typemap(typecheck) long long &INOUT = long long;
|
||||
%typemap(typecheck) short &INOUT = short;
|
||||
%typemap(typecheck) int &INOUT = int;
|
||||
%typemap(typecheck) float &INOUT = float;
|
||||
|
||||
%include <typemaps/typemaps.swg>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue