Merge from trunk

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@12976 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Vincent Couvert 2012-04-11 20:46:17 +00:00
commit 02d58e0125
99 changed files with 1847 additions and 418 deletions

View file

@ -17,12 +17,6 @@
%{
#include <string>
// #include <vector>
// using std::vector;
using std::string;
%}
// %include <std_vector.i>

View file

@ -83,7 +83,7 @@ static import tango.stdc.stringz;
%pragma(d) imdmodulecode=%{
private class SwigExceptionHelper {
static this() {
swigRegisterExceptionCallbacks(
swigRegisterExceptionCallbacks$module(
&setException,
&setIllegalArgumentException,
&setIllegalElementException,
@ -91,31 +91,31 @@ private class SwigExceptionHelper {
&setNoSuchElementException);
}
static void setException(char* message) {
static void setException(const char* message) {
auto exception = new object.Exception(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setIllegalArgumentException(char* message) {
static void setIllegalArgumentException(const char* message) {
auto exception = new tango.core.Exception.IllegalArgumentException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setIllegalElementException(char* message) {
static void setIllegalElementException(const char* message) {
auto exception = new tango.core.Exception.IllegalElementException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setIOException(char* message) {
static void setIOException(const char* message) {
auto exception = new tango.core.Exception.IOException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setNoSuchElementException(char* message) {
static void setNoSuchElementException(const char* message) {
auto exception = new tango.core.Exception.NoSuchElementException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
@ -174,7 +174,7 @@ private:
alias tango.core.Thread.ThreadLocal!(object.Exception) ThreadLocalData;
static ThreadLocalData m_sPendingException;
}
alias void function(char* message) SwigExceptionCallback;
alias void function(const char* message) SwigExceptionCallback;
%}
#else
%pragma(d) imdmoduleimports=%{
@ -185,7 +185,7 @@ static import std.conv;
private class SwigExceptionHelper {
static this() {
// The D1/Tango version maps C++ exceptions to multiple exception types.
swigRegisterExceptionCallbacks(
swigRegisterExceptionCallbacks$module(
&setException,
&setException,
&setException,
@ -283,7 +283,7 @@ SWIGEXPORT void SWIGRegisterStringCallback_$module(SWIG_DStringHelperCallback ca
%pragma(d) imdmodulecode = %{
private class SwigStringHelper {
static this() {
swigRegisterStringCallback(&createString);
swigRegisterStringCallback$module(&createString);
}
static char* createString(char* cString) {
@ -302,7 +302,7 @@ static import std.string;
%pragma(d) imdmodulecode = %{
private class SwigStringHelper {
static this() {
swigRegisterStringCallback(&createString);
swigRegisterStringCallback$module(&createString);
}
static const(char)* createString(const(char*) cString) {

View file

@ -282,10 +282,10 @@ static this() {
}
//#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
mixin(bindCode("swigRegisterExceptionCallbacks", "SWIGRegisterExceptionCallbacks_$module"));
mixin(bindCode("swigRegisterExceptionCallbacks$module", "SWIGRegisterExceptionCallbacks_$module"));
//#endif // SWIG_D_NO_EXCEPTION_HELPER
//#if !defined(SWIG_D_NO_STRING_HELPER)
mixin(bindCode("swigRegisterStringCallback", "SWIGRegisterStringCallback_$module"));
mixin(bindCode("swigRegisterStringCallback$module", "SWIGRegisterStringCallback_$module"));
//#endif // SWIG_D_NO_STRING_HELPER
$wrapperloaderbindcode
}
@ -296,11 +296,11 @@ extern(C) void function(
SwigExceptionCallback illegalArgumentCallback,
SwigExceptionCallback illegalElementCallback,
SwigExceptionCallback ioCallback,
SwigExceptionCallback noSuchElementCallback) swigRegisterExceptionCallbacks;
SwigExceptionCallback noSuchElementCallback) swigRegisterExceptionCallbacks$module;
//#endif // SWIG_D_NO_EXCEPTION_HELPER
//#if !defined(SWIG_D_NO_STRING_HELPER)
extern(C) void function(SwigStringCallback callback) swigRegisterStringCallback;
extern(C) void function(SwigStringCallback callback) swigRegisterStringCallback$module;
//#endif // SWIG_D_NO_STRING_HELPER
%}

View file

@ -117,6 +117,16 @@ import _ "runtime/cgo"
%}
#else
%insert(go_header) %{
import "syscall"
type _ syscall.Sockaddr
%}
#endif
/* Function pointers are translated by the code in go.cxx into

40
Lib/go/std_list.i Normal file
View file

@ -0,0 +1,40 @@
/* -----------------------------------------------------------------------------
* std_vector.i
* ----------------------------------------------------------------------------- */
%{
#include <list>
#include <stdexcept>
%}
namespace std {
template<class T, class Alloc = allocator<T> >
class list {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef Alloc allocator_type;
list();
size_type size() const;
bool empty() const;
%rename(isEmpty) empty;
void clear();
void push_front(const value_type& x);
void pop_front();
void push_back(const value_type& x);
void pop_back();
void remove(value_type x);
void reverse();
void unique();
void sort();
void merge(list& x);
};
}

View file

@ -28,9 +28,9 @@
/* Array support functions declarations macro */
%define JAVA_ARRAYS_DECL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
%{
int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input);
void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input);
JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz);
static int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input);
static void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input);
static JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz);
%}
%enddef
@ -38,7 +38,7 @@ JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize
%define JAVA_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME)
%{
/* CTYPE[] support */
int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input) {
static int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input) {
int i;
jsize sz;
if (!input) {
@ -63,7 +63,7 @@ int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNI
return 1;
}
void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input) {
static void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input) {
int i;
jsize sz = JCALL1(GetArrayLength, jenv, input);
for (i=0; i<sz; i++)
@ -71,7 +71,7 @@ void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr,
JCALL3(Release##JAVATYPE##ArrayElements, jenv, input, jarr, 0);
}
JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz) {
static JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz) {
JNITYPE *arr;
int i;
JNITYPE##Array jresult = JCALL1(New##JAVATYPE##Array, jenv, sz);

View file

@ -15,6 +15,24 @@ extern "C" {
#include <stdlib.h> /* for malloc */
#include <assert.h> /* for a few sanity tests */
/* -----------------------------------------------------------------------------
* compatibility defines
* ----------------------------------------------------------------------------- */
/* History of Lua C API length functions: In Lua 5.0 (and before?)
there was "lua_strlen". In Lua 5.1, this was renamed "lua_objlen",
but a compatibility define of "lua_strlen" was added. In Lua 5.2,
this function was again renamed, to "lua_rawlen" (to emphasize that
it doesn't call the "__len" metamethod), and the compatibility
define of lua_strlen was removed. All SWIG uses have been updated
to "lua_rawlen", and we add our own defines of that here for older
versions of Lua. */
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501
# define lua_rawlen lua_strlen
#elif LUA_VERSION_NUM == 501
# define lua_rawlen lua_objlen
#endif
/* -----------------------------------------------------------------------------
* global swig types
* ----------------------------------------------------------------------------- */

View file

@ -30,7 +30,11 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
int i;
/* start with global table */
#ifdef LUA_RIDX_GLOBALS
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
#else
lua_pushvalue(L,LUA_GLOBALSINDEX);
#endif
/* SWIG's internal initalisation */
SWIG_InitializeModule((void*)L);
SWIG_PropagateClientData();

View file

@ -298,7 +298,7 @@ parmeters match which function
// special check for a char (string of length 1)
%typecheck(SWIG_TYPECHECK_CHAR,fragment="SWIG_lua_isnilstring") char, const char& {
$1 = SWIG_lua_isnilstring(L,$input) && (lua_strlen(L,$input)==1);
$1 = SWIG_lua_isnilstring(L,$input) && (lua_rawlen(L,$input)==1);
}
%typecheck(SWIG_TYPECHECK_STRING,fragment="SWIG_lua_isnilstring") char *, char[] {

View file

@ -41,18 +41,18 @@ but
Similarly for getting the string
$1 = (char*)lua_tostring(L, $input);
becomes
$1.assign(lua_tostring(L,$input),lua_strlen(L,$input));
$1.assign(lua_tostring(L,$input),lua_rawlen(L,$input));
Not using: lua_tolstring() as this is only found in Lua 5.1 & not 5.0.2
*/
%typemap(in,checkfn="lua_isstring") std::string
%{$1.assign(lua_tostring(L,$input),lua_strlen(L,$input));%}
%{$1.assign(lua_tostring(L,$input),lua_rawlen(L,$input));%}
%typemap(out) std::string
%{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_arg++;%}
%typemap(in,checkfn="lua_isstring") const std::string& (std::string temp)
%{temp.assign(lua_tostring(L,$input),lua_strlen(L,$input)); $1=&temp;%}
%{temp.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); $1=&temp;%}
%typemap(out) const std::string&
%{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}

View file

@ -30,7 +30,7 @@ wchar_t* str2wstr(const char *str, int len)
%typemap(in, checkfn="SWIG_lua_isnilstring", fragment="SWIG_lua_isnilstring") wchar_t *
%{
$1 = str2wstr(lua_tostring( L, $input ),lua_strlen( L, $input ));
$1 = str2wstr(lua_tostring( L, $input ),lua_rawlen( L, $input ));
if ($1==0) {lua_pushfstring(L,"Error in converting to wchar (arg %d)",$input);goto fail;}
%}

View file

@ -63,7 +63,7 @@ namespace swig {
}
}
%fragment("OctSequence_Base","header")
%fragment("OctSequence_Base","header",fragment="<stddef.h>")
{
%#include <functional>

View file

@ -9,7 +9,7 @@
%include <std_common.i>
%fragment("OctSwigIterator","header") {
%fragment("OctSwigIterator","header",fragment="<stddef.h>") {
namespace swig {
struct stop_iteration {
};
@ -113,7 +113,7 @@ namespace swig {
}
}
%fragment("OctSwigIterator_T","header",fragment="OctSwigIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
%fragment("OctSwigIterator_T","header",fragment="<stddef.h>",fragment="OctSwigIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
namespace swig {
template<typename OutIterator>
class OctSwigIterator_T : public OctSwigIterator

View file

@ -111,7 +111,7 @@ class octave_swig_type;
namespace Swig {
class Director;
SWIGRUNTIME void swig_register_director(octave_swig_type *self, void *ptr, Director *d);
//SWIGRUNTIME void swig_register_director(octave_swig_type *self, void *ptr, Director *d);
SWIGRUNTIME void swig_director_destroyed(octave_swig_type *self, Director *d);
SWIGRUNTIME void swig_director_set_self(Director *d, octave_swig_type *self);
@ -400,7 +400,57 @@ namespace Swig {
}
dim_vector dims(void) const {
return dim_vector(1,1);
octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
// Find the __dims__ method of this object
member_value_pair *m = nc_this->find_member("__dims__", false);
if (!m) return dim_vector(1,1);
// Call the __dims__ method of this object
octave_value_list inarg;
inarg.append(nc_this->as_value());
octave_value_list outarg = nc_this->member_invoke(m, inarg, 1);
// __dims__ should return (at least) one output argument
if (outarg.length() < 1) return dim_vector(1,1);
octave_value & out = outarg(0);
// Return value should be cell or matrix of integers
if (out.is_cell()) {
const Cell & c=out.cell_value();
int ndim = c.rows();
if (ndim==1 && c.columns()!=1) ndim = c.columns();
dim_vector d;
d.resize(ndim);
// Fill in dim_vector
for (int k=0;k<ndim;k++) {
const octave_value& obj = c(k);
d.elem(k) = obj.int_value();
// __dims__ should return a cell filled with integers
if (error_state) return dim_vector(1,1);
}
return d;
} else if (out.is_matrix_type() || out.is_real_nd_array() || out.is_numeric_type() ) {
if (out.rows()==1 || out.columns()==1) {
Array<int> a = out.int_vector_value();
if (error_state) return dim_vector(1,1);
dim_vector d;
d.resize(a.numel());
for (int k=0;k<a.numel();k++) {
d.elem(k) = a(k);
}
return d;
} else {
return dim_vector(1,1);
}
} else {
return dim_vector(1,1);
}
}
octave_value as_value() {
@ -703,6 +753,10 @@ namespace Swig {
return as_value();
}
virtual bool is_object() const {
return true;
}
virtual bool is_string() const {
octave_swig_type *nc_this = const_cast < octave_swig_type *>(this);
return !!nc_this->find_member("__str__", false);
@ -950,6 +1004,9 @@ namespace Swig {
octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs)
{ return ptr->subsasgn(ops, idx, rhs); }
virtual bool is_object() const
{ return ptr->is_object(); }
virtual bool is_string() const
{ return ptr->is_string(); }

View file

@ -18,6 +18,10 @@
static void SWIG_init_user(octave_swig_type* module_ns);
#if OCTAVE_API_VERSION_NUMBER>=37
octave_value_list SWIG_atexit_func(const octave_value_list &args, int nargout);
#endif
DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
// determine if module is already loaded
@ -33,7 +37,7 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
if (!already_load) {
// parse command line
const char* usage="usage: " SWIG_name_d " [-global|-noglobal] [-globals <name>]";
const char* usage="usage: " SWIG_name_d " [-global|-noglobal] [-globals {<name>|.}]";
bool global_load=SWIG_global_load;
std::string global_name=SWIG_global_name;
for (int j=0;j<args.length();++j)
@ -65,7 +69,7 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
return octave_value_list();
}
if (!valid_identifier(global_name)) {
if (global_name != "." && !valid_identifier(global_name)) {
std::cerr << "error: " SWIG_name_d ": '" << global_name << "' is not a valid Octave identifier." << std::endl;
return octave_value_list();
}
@ -88,13 +92,23 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
install_builtin_function(swig_this,"swig_this",std::string());
install_builtin_function(swig_subclass,"subclass",std::string());
octave_swig_type* cvar_ns=new octave_swig_type;
for (int j=0;swig_globals[j].name;++j)
if (swig_globals[j].get_method)
cvar_ns->assign(swig_globals[j].name,&swig_globals[j]);
octave_swig_type* cvar_ns=0;
if (global_name != ".") {
cvar_ns=new octave_swig_type;
for (int j=0;swig_globals[j].name;++j)
if (swig_globals[j].get_method)
cvar_ns->assign(swig_globals[j].name,&swig_globals[j]);
}
octave_swig_type* module_ns=new octave_swig_type(0, 0, 0, true);
module_ns->assign(global_name,Swig::swig_value_ref(cvar_ns));
if (global_name != ".") {
module_ns->assign(global_name,Swig::swig_value_ref(cvar_ns));
}
else {
for (int j=0;swig_globals[j].name;++j)
if (swig_globals[j].get_method)
module_ns->assign(swig_globals[j].name,&swig_globals[j]);
}
for (int j=0;swig_globals[j].name;++j)
if (swig_globals[j].method)
module_ns->assign(swig_globals[j].name,&swig_globals[j]);
@ -123,6 +137,12 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
// create global variable containing module
set_global_value(SWIG_name_d,Swig::swig_value_ref(module_ns));
#if OCTAVE_API_VERSION_NUMBER>=37
install_builtin_function(SWIG_atexit_func,"__swig_atexit_" SWIG_name_d "__",std::string());
octave_add_atexit_function("__swig_atexit_" SWIG_name_d "__");
octave_remove_atexit_function("__finish__");
#endif
// return from base frame
#if OCTAVE_API_VERSION_NUMBER<37
curr_sym_tab = prev_sym_tab;
@ -150,14 +170,11 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
// workaround bug in octave where installing global variable of custom type and then
// exiting without explicitly clearing the variable causes octave to segfault.
#if OCTAVE_API_VERSION_NUMBER>=37
struct oct_file_unload {
~oct_file_unload() {
string_vector vars = symbol_table::global_variable_names();
for (int i = 0; i < vars.length(); i++)
symbol_table::clear_global(vars[i]);
}
};
static oct_file_unload __unload;
octave_value_list SWIG_atexit_func(const octave_value_list &args, int nargout) {
symbol_table::clear_global_pattern("*");
symbol_table::clear_functions();
return octave_value();
}
#endif
%}

View file

@ -31,6 +31,37 @@ namespace swig {
}
%enddef
/* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums
is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit
instantiations required using %template). The STL containers define the 'front' method and the typemap
below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the
standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from
required in the generated code for enums. */
%define %traits_enum(Type...)
%fragment("SWIG_Traits_enum_"{Type},"header",
fragment=SWIG_AsVal_frag(int),
fragment=SWIG_From_frag(int),
fragment="StdTraits") {
namespace swig {
template <> struct traits_asval<Type > {
typedef Type value_type;
static int asval(octave_value obj, value_type *val) {
return SWIG_AsVal(int)(obj, (int *)val);
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static octave_value from(const value_type& val) {
return SWIG_From(int)((int)val);
}
};
}
}
%typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%}
%enddef
%include <std/std_common.i>
//

26
Lib/octave/std_list.i Normal file
View file

@ -0,0 +1,26 @@
// Lists
%fragment("StdListTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class T >
struct traits_asptr<std::list<T> > {
static int asptr(const octave_value& obj, std::list<T> **lis) {
return traits_asptr_stdseq<std::list<T> >::asptr(obj, lis);
}
};
template <class T>
struct traits_from<std::list<T> > {
static octave_value *from(const std::list<T> & vec) {
return traits_from_stdseq<std::list<T> >::from(vec);
}
};
}
%}
#define %swig_list_methods(Type...) %swig_sequence_methods(Type)
#define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type);
%include <std/std_list.i>

View file

@ -104,7 +104,7 @@ namespace swig {
}
}
%fragment("SwigPySequence_Base","header")
%fragment("SwigPySequence_Base","header",fragment="<stddef.h>")
{
%#include <functional>

View file

@ -11,7 +11,7 @@
%include <std_common.i>
%fragment("SwigPyIterator","header") {
%fragment("SwigPyIterator","header",fragment="<stddef.h>") {
namespace swig {
struct stop_iteration {
};
@ -139,7 +139,7 @@ namespace swig {
}
}
%fragment("SwigPyIterator_T","header",fragment="SwigPyIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
%fragment("SwigPyIterator_T","header",fragment="<stddef.h>",fragment="SwigPyIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
namespace swig {
template<typename OutIterator>
class SwigPyIterator_T : public SwigPyIterator

View file

@ -429,7 +429,7 @@ SwigPyObject_repr(SwigPyObject *v, PyObject *args)
#endif
{
const char *name = SWIG_TypePrettyName(v->ty);
PyObject *repr = SWIG_Python_str_FromFormat("<Swig Object of type '%s' at %p>", name, (void *)v);
PyObject *repr = SWIG_Python_str_FromFormat("<Swig Object of type '%s' at %p>", (name ? name : "unknown"), (void *)v);
if (v->next) {
# ifdef METH_NOARGS
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next);

View file

@ -33,6 +33,36 @@ namespace swig {
}
%enddef
/* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums
is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit
instantiations required using %template). The STL containers define the 'front' method and the typemap
below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the
standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from
required in the generated code for enums. */
%define %traits_enum(Type...)
%fragment("SWIG_Traits_enum_"{Type},"header",
fragment=SWIG_AsVal_frag(int),
fragment=SWIG_From_frag(int),
fragment="StdTraits") {
namespace swig {
template <> struct traits_asval<Type > {
typedef Type value_type;
static int asval(PyObject *obj, value_type *val) {
return SWIG_AsVal(int)(obj, (int *)val);
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static PyObject *from(const value_type& val) {
return SWIG_From(int)((int)val);
}
};
}
}
%typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%}
%enddef
%include <std/std_common.i>

View file

@ -109,10 +109,21 @@ SWIG_InitializeModule(0);
free($1);
%}
%typemap(freearg, noblock=1) int *OUTPUT,
signed int *OUTPUT,
unsigned int *OUTPUT,
short *OUTPUT,
signed short *OUTPUT,
long *OUTPUT,
signed long *OUTPUT,
long long *OUTPUT,
unsigned long long *OUTPUT,
float *OUTPUT,
double *OUTPUT {}
/* Shoul dwe recycle to make the length correct.
/* Should we recycle to make the length correct.
And warn if length() > the dimension.
*/
%typemap(scheck) SWIGTYPE [ANY] %{
@ -132,8 +143,6 @@ SWIG_InitializeModule(0);
};
%}
%include <typemaps/swigmacros.swg>
%include <typemaps/fragments.swg>
%include <rfragments.swg>
%include <ropers.swg>

View file

@ -8,7 +8,7 @@
%fragment("RSequence_Base","header")
%fragment("StdSequenceTraits","header",fragment="<stddef.h>")
{
%#include <functional>
namespace swig {
@ -133,7 +133,7 @@ namespace swig {
// %swig_sequence_iterator(%arg(Sequence))
%swig_container_methods(%arg(Sequence))
%fragment("RSequence_Base");
%fragment("StdSequenceTraits");
%extend {
value_type pop() throw (std::out_of_range) {

View file

@ -361,6 +361,13 @@ SWIG_R_ConvertPacked(SEXP obj, void *ptr, size_t sz, swig_type_info *ty) {
return SWIG_OK;
}
#ifdef __cplusplus
#include <exception>
#define SWIG_exception_noreturn(code, msg) do { throw std::runtime_error(msg); } while(0)
#else
#define SWIG_exception_noreturn(code, msg) do { return result; } while(0)
#endif
#ifdef __cplusplus
}
#endif

View file

@ -36,8 +36,45 @@
%typemap("rtype") SWIGTYPE & "$R_class";
%typemap("rtype") SWIGTYPE "$&R_class";
%typemap("rtypecheck") int, int &, long, long &,
unsigned char, unsigned char &
%{ (is.integer($arg) || is.numeric($arg)) && length($arg) == 1 %}
%typemap("rtypecheck") int *, long *, unsigned char *
%{ is.integer($arg) || is.numeric($arg) %}
%typemap("rtypecheck") double, double &, float, float &
%{ is.numeric($arg) && length($arg) == 1 %}
%typemap("rtypecheck") double*, float *
%{ is.numeric($arg) %}
%typemap("rtypecheck") bool, bool &
%{ is.logical($arg) && length($arg) == 1 %}
%typemap("rtypecheck") bool *
%{ is.logical($arg) %}
/*
Set up type checks to insure overloading precedence.
We would like non pointer items to shadow pointer items, so that
they get called if length = 1
*/
%typecheck(SWIG_TYPECHECK_BOOL) bool {}
%typecheck(SWIG_TYPECHECK_UINT32) unsigned int {}
%typecheck(SWIG_TYPECHECK_INTEGER) int {}
%typecheck(SWIG_TYPECHECK_FLOAT) float {}
%typecheck(SWIG_TYPECHECK_DOUBLE) double {}
%typecheck(SWIG_TYPECHECK_BOOL_PTR) bool * {}
%typecheck(SWIG_TYPECHECK_INT32_PTR) int * {}
%typecheck(SWIG_TYPECHECK_FLOAT_PTR) float * {}
%typecheck(SWIG_TYPECHECK_DOUBLE_PTR) double * {}
%typecheck(SWIG_TYPECHECK_CHAR_PTR) char * {}
%typecheck(SWIG_TYPECHECK_INT32_ARRAY) int[ANY] {}
%typecheck(SWIG_TYPECHECK_FLOAT_ARRAY) float[ANY] {}
%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY) double [ANY] {}
/* Have to be careful that as(x, "numeric") is different from as.numeric(x).
The latter makes a REALSXP, whereas the former leaves an INTSXP as an
INTSXP.
@ -170,10 +207,11 @@ string &, std::string &
signed long,
signed long &,
unsigned long,
unsigned long &
unsigned long &,
unsigned char *,
unsigned char &
%{ %}
#if 0
Just examining the values for a SWIGTYPE.

View file

@ -1,2 +1,35 @@
%include <rstdcommon.swg>
%include <std/std_common.i>
%define %traits_ptypen(Type...)
%fragment(SWIG_Traits_frag(Type),"header",
fragment=SWIG_AsVal_frag(Type),
fragment=SWIG_From_frag(Type),
fragment="StdTraits") {
namespace swig {
template <> struct traits<Type > {
typedef value_category category;
static const char* type_name() { return #Type; }
};
template <> struct traits_asval<Type > {
typedef Type value_type;
static int asval(SEXP obj, value_type *val) {
return SWIG_AsVal(Type)(obj, val);
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static SEXP from(const value_type& val) {
return SWIG_From(Type)(val);
}
};
}
}
%enddef
//
// Generates the traits for all the known primitive
// C++ types (int, double, ...)
//
%apply_cpptypes(%traits_ptypen);

5
Lib/r/std_list.i Normal file
View file

@ -0,0 +1,5 @@
#define %swig_list_methods(Type...) %swig_sequence_methods(Type)
#define %swig_list_methods_val(Type...) %swig_sequence_methods_val(Type);
%include <std/std_list.i>

View file

@ -1,10 +1,269 @@
%fragment("StdVectorTraits","header")
// R specific swig components
/*
Vectors
Thanks to Richard Beare - richard.beare@ieee.org for StdVectorTraits
*/
%fragment("StdVectorTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
// vectors of doubles
template <>
struct traits_from_ptr<std::vector<double> > {
static SEXP from (std::vector<double > *val, int owner = 0) {
SEXP result;
PROTECT(result = Rf_allocVector(REALSXP, val->size()));
for (unsigned pos = 0; pos < val->size(); pos++)
{
NUMERIC_POINTER(result)[pos] = ((*val)[pos]);
}
UNPROTECT(1);
return(result);
}
};
// vectors of floats
template <>
struct traits_from_ptr<std::vector<float> > {
static SEXP from (std::vector<float > *val, int owner = 0) {
SEXP result;
PROTECT(result = Rf_allocVector(REALSXP, val->size()));
for (unsigned pos = 0; pos < val->size(); pos++)
{
NUMERIC_POINTER(result)[pos] = ((*val)[pos]);
}
UNPROTECT(1);
return(result);
}
};
// vectors of unsigned int
template <>
struct traits_from_ptr<std::vector<unsigned int> > {
static SEXP from (std::vector<unsigned int > *val, int owner = 0) {
SEXP result;
PROTECT(result = Rf_allocVector(INTSXP, val->size()));
for (unsigned pos = 0; pos < val->size(); pos++)
{
INTEGER_POINTER(result)[pos] = ((*val)[pos]);
}
UNPROTECT(1);
return(result);
}
};
// vectors of int
template <>
struct traits_from_ptr<std::vector<int> > {
static SEXP from (std::vector<int > *val, int owner = 0) {
SEXP result;
PROTECT(result = Rf_allocVector(INTSXP, val->size()));
for (unsigned pos = 0; pos < val->size(); pos++)
{
INTEGER_POINTER(result)[pos] = ((*val)[pos]);
}
UNPROTECT(1);
return(result);
}
};
// vectors of bool
template <>
struct traits_from_ptr<std::vector<bool> > {
static SEXP from (std::vector<bool> *val, int owner = 0) {
SEXP result;
PROTECT(result = Rf_allocVector(LGLSXP, val->size()));
for (unsigned pos = 0; pos < val->size(); pos++)
{
LOGICAL_POINTER(result)[pos] = ((*val)[pos]);
}
UNPROTECT(1);
return(result);
//return SWIG_R_NewPointerObj(val, type_info< std::vector<T > >(), owner);
}
};
// vectors of strings
template <>
struct traits_from_ptr<std::vector<std::basic_string<char> > > {
static SEXP from (std::vector<std::basic_string<char> > *val, int owner = 0) {
SEXP result;
PROTECT(result = Rf_allocVector(STRSXP, val->size()));
for (unsigned pos = 0; pos < val->size(); pos++)
{
CHARACTER_POINTER(result)[pos] = Rf_mkChar(((*val)[pos]).c_str());
}
UNPROTECT(1);
return(result);
//return SWIG_R_NewPointerObj(val, type_info< std::vector<T > >(), owner);
}
};
// catch all that does everything with vectors
template <typename T>
struct traits_from_ptr< std::vector< T > > {
static SEXP from (std::vector< T > *val, int owner = 0) {
return SWIG_R_NewPointerObj(val, type_info< std::vector< T > >(), owner);
}
};
template <>
struct traits_asptr < std::vector<double> > {
static int asptr(SEXP obj, std::vector<double> **val) {
std::vector<double> *p;
// not sure how to check the size of the SEXP obj is correct
unsigned int sexpsz = Rf_length(obj);
p = new std::vector<double>(sexpsz);
double *S = NUMERIC_POINTER(obj);
for (unsigned pos = 0; pos < p->size(); pos++)
{
(*p)[pos] = static_cast<double>(S[pos]);
}
int res = SWIG_OK;
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
return res;
}
};
template <>
struct traits_asptr < std::vector<float> > {
static int asptr(SEXP obj, std::vector<float> **val) {
std::vector<float> *p;
// not sure how to check the size of the SEXP obj is correct
unsigned int sexpsz = Rf_length(obj);
p = new std::vector<float>(sexpsz);
double *S = NUMERIC_POINTER(obj);
for (unsigned pos = 0; pos < p->size(); pos++)
{
(*p)[pos] = static_cast<double>(S[pos]);
}
int res = SWIG_OK;
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
return res;
}
};
template <>
struct traits_asptr < std::vector<unsigned int> > {
static int asptr(SEXP obj, std::vector<unsigned int> **val) {
std::vector<unsigned int> *p;
unsigned int sexpsz = Rf_length(obj);
p = new std::vector<unsigned int>(sexpsz);
SEXP coerced;
PROTECT(coerced = Rf_coerceVector(obj, INTSXP));
int *S = INTEGER_POINTER(coerced);
for (unsigned pos = 0; pos < p->size(); pos++)
{
(*p)[pos] = static_cast<unsigned int>(S[pos]);
}
int res = SWIG_OK;
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
UNPROTECT(1);
return res;
}
};
template <>
struct traits_asptr < std::vector<int> > {
static int asptr(SEXP obj, std::vector<int> **val) {
std::vector<int> *p;
// not sure how to check the size of the SEXP obj is correct
int sexpsz = Rf_length(obj);
p = new std::vector<int>(sexpsz);
SEXP coerced;
PROTECT(coerced = Rf_coerceVector(obj, INTSXP));
int *S = INTEGER_POINTER(coerced);
for (unsigned pos = 0; pos < p->size(); pos++)
{
(*p)[pos] = static_cast<int>(S[pos]);
}
int res = SWIG_OK;
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
UNPROTECT(1);
return res;
}
};
// catchall for R to vector conversion
template <typename T>
struct traits_asptr < std::vector<T> > {
static int asptr(SEXP obj, std::vector<T> **val) {
std::vector<T> *p;
Rprintf("my asptr\n");
int res = SWIG_R_ConvertPtr(obj, (void**)&p, type_info< std::vector<T> >(), 0);
if (SWIG_IsOK(res)) {
if (val) *val = p;
}
return res;
}
};
}
%}
#define %swig_vector_methods(Type...) %swig_sequence_methods(Type)
#define %swig_vector_methods_val(Type...) %swig_sequence_methods_val(Type);
%define %traits_type_name(Type...)
%fragment(SWIG_Traits_frag(Type), "header",
fragment="StdTraits",fragment="StdVectorTraits") {
namespace swig {
template <> struct traits< Type > {
typedef pointer_category category;
static const char* type_name() {
return #Type;
}
};
}
}
%enddef
%include <std/std_vector.i>
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<double>)
%traits_type_name(std::vector<double>)
%typemap("rtypecheck") std::vector<double> %{ is.numeric($arg) %}
%typemap("rtype") std::vector<double> "numeric"
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<float>)
%traits_type_name(std::vector<float>)
%typemap("rtypecheck") std::vector<float> %{ is.numeric($arg) %}
%typemap("rtype") std::vector<float> "numeric"
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<bool>);
%traits_type_name(std::vector<bool>);
%typemap("rtypecheck") std::vector<bool> %{ is.logical($arg) %}
%typemap("rtype") std::vector<bool> "logical"
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<int>);
%traits_type_name(std::vector<int>);
%typemap("rtypecheck") std::vector<int>
%{ is.integer($arg) || is.numeric($arg) %}
%typemap("rtype") std::vector<int> "integer"
%typemap("scoercein") std::vector<int> "$input = as.integer($input);";
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<unsigned int>);
%traits_type_name(std::vector<unsigned int>);
%typemap("rtypecheck") std::vector<unsigned int>
%{ is.integer($arg) || is.numeric($arg) %}
%typemap("rtype") std::vector<unsigned int> "integer"
%typemap("scoercein") std::vector<unsigned int> "$input = as.integer($input);";
// we don't want these to be given R classes as they
// have already been turned into R vectors.
%typemap(scoerceout) std::vector<double>,
std::vector<double> *,
std::vector<double> &,
std::vector<bool>,
std::vector<bool> *,
std::vector<bool> &,
std::vector<unsigned int>,
std::vector<unsigned int> *,
std::vector<unsigned int> &
%{ %}
%include <std/std_vector.i>

View file

@ -153,6 +153,7 @@ namespace swig {
}
%fragment("RubySequence_Cont","header",
fragment="<stddef.h>",
fragment="StdTraits",
fragment="RubySequence_Base",
fragment="ConstIterator_T")

View file

@ -12,7 +12,7 @@
%include <std_common.i>
%fragment("ConstIterator","header",fragment="GC_VALUE_definition") {
%fragment("ConstIterator","header",fragment="<stddef.h>",fragment="GC_VALUE_definition") {
namespace swig {
struct stop_iteration {
};
@ -270,7 +270,7 @@ namespace swig {
}
%fragment("ConstIterator_T","header",fragment="ConstIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
%fragment("ConstIterator_T","header",fragment="<stddef.h>",fragment="ConstIterator",fragment="StdTraits",fragment="StdIteratorTraits") {
namespace swig {
/**

View file

@ -34,6 +34,36 @@ namespace swig {
}
%enddef
/* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums
is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit
instantiations required using %template). The STL containers define the 'front' method and the typemap
below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the
standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from
required in the generated code for enums. */
%define %traits_enum(Type...)
%fragment("SWIG_Traits_enum_"{Type},"header",
fragment=SWIG_AsVal_frag(int),
fragment=SWIG_From_frag(int),
fragment="StdTraits") {
namespace swig {
template <> struct traits_asval<Type > {
typedef Type value_type;
static int asval(VALUE obj, value_type *val) {
return SWIG_AsVal(int)(obj, (int *)val);
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static VALUE from(const value_type& val) {
return SWIG_From(int)((int)val);
}
};
}
}
%typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%}
%enddef
%include <std/std_common.i>

View file

@ -2,7 +2,7 @@
Sets
*/
%fragment("StdSetTraits","header",fragment="StdSequenceTraits")
%fragment("StdSetTraits","header",fragment="<stddef.h>",fragment="StdSequenceTraits")
%{
namespace swig {
template <class RubySeq, class T>

View file

@ -30,7 +30,7 @@
%}
%fragment("StdIteratorTraits","header") %{
%fragment("StdIteratorTraits","header",fragment="<stddef.h>") %{
#if defined(__SUNPRO_CC) && defined(_RWSTD_VER)
# if !defined(SWIG_NO_STD_NOITERATOR_TRAITS_STL)
# define SWIG_STD_NOITERATOR_TRAITS_STL

View file

@ -69,6 +69,7 @@ namespace std {
typedef _Alloc allocator_type;
%traits_swigtype(_Tp);
%traits_enum(_Tp);
%fragment(SWIG_Traits_frag(std::vector<_Tp, _Alloc >), "header",
fragment=SWIG_Traits_frag(_Tp),

View file

@ -291,7 +291,7 @@ static int NAME(TYPE x) {
%define %$isextern "match$storage"="extern" %enddef
%define %$ismember "match$ismember"="1" %enddef
%define %$isglobal %not %ismember %enddef
%define %$isglobal %$not %$ismember %enddef
%define %$innamespace "match$parentNode$nodeType"="namespace" %enddef
%define %$ispublic "match$access"="public" %enddef
@ -301,7 +301,7 @@ static int NAME(TYPE x) {
%define %$ismemberget "match$memberget"="1" %enddef
%define %$ismemberset "match$memberset"="1" %enddef
%define %$classname %ismember,match$parentNode$name %enddef
%define %$classname %$ismember,"match$parentNode$name" %enddef
/* -----------------------------------------------------------------------------
* Include all the warnings labels and macros

View file

@ -149,6 +149,10 @@
#endif
%}
%fragment("<stddef.h>", "header") %{
#include <stddef.h>
%}
/* -----------------------------------------------------------------------------
* special macros for fragments
* ----------------------------------------------------------------------------- */

View file

@ -24,7 +24,9 @@
SWIG_CharPtrLen,
SWIG_AsCharPtr,
SWIG_FromCharPtr,
SWIG_AsCharArray)
SWIG_AsCharArray,
SWIG_NewCopyCharArray,
SWIG_DeleteCharArray)
/* in */
@ -38,7 +40,7 @@
$1 = %reinterpret_cast(buf, $1_ltype);
}
%typemap(freearg,noblock=1,match="in") Char *, const Char * {
if (alloc$argnum == SWIG_NEWOBJ) %delete_array(buf$argnum);
if (alloc$argnum == SWIG_NEWOBJ) SWIG_DeleteCharArray(buf$argnum);
}
%typemap(in,noblock=1,fragment=#SWIG_AsCharPtr) Char const*& (int res, Char *buf = 0, int alloc = 0) {
@ -49,7 +51,7 @@
$1 = &buf;
}
%typemap(freearg, noblock=1,match="in") Char const*& {
if (alloc$argnum == SWIG_NEWOBJ) %delete_array(buf$argnum);
if (alloc$argnum == SWIG_NEWOBJ) SWIG_DeleteCharArray(buf$argnum);
}
/* out */
@ -64,7 +66,7 @@
}
%typemap(newfree,noblock=1) Char * {
%delete_array($1);
SWIG_DeleteCharArray($1);
}
/* varin */
@ -75,11 +77,11 @@
if (!SWIG_IsOK(res)) {
%variable_fail(res,"$type","$name");
}
if ($1) %delete_array($1);
if ($1) SWIG_DeleteCharArray($1);
if (alloc == SWIG_NEWOBJ) {
$1 = cptr;
} else {
$1 = csize ? ($1_type)%new_copy_array(cptr, csize, Char) : 0;
$1 = csize ? ($1_type)SWIG_NewCopyCharArray(cptr, csize, Char) : 0;
}
}
@ -92,7 +94,7 @@
if (alloc == SWIG_NEWOBJ) {
$1 = cptr;
} else {
$1 = csize ? ($1_type)%new_copy_array(cptr, csize, Char) : 0;
$1 = csize ? ($1_type)SWIG_NewCopyCharArray(cptr, csize, Char) : 0;
}
}
@ -105,10 +107,10 @@
/* memberin */
%typemap(memberin,noblock=1) Char * {
if ($1) %delete_array($1);
if ($1) SWIG_DeleteCharArray($1);
if ($input) {
size_t size = SWIG_CharPtrLen(%reinterpret_cast($input, const Char *)) + 1;
$1 = ($1_type)%new_copy_array(%reinterpret_cast($input, const Char *), size, Char);
$1 = ($1_type)SWIG_NewCopyCharArray(%reinterpret_cast($input, const Char *), size, Char);
} else {
$1 = 0;
}
@ -117,7 +119,7 @@
%typemap(memberin,noblock=1,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const Char * {
if ($input) {
size_t size = SWIG_CharPtrLen(%reinterpret_cast(%reinterpret_cast($input, const Char *), const Char *)) + 1;
$1 = ($1_type)%new_copy_array($input, size, Char);
$1 = ($1_type)SWIG_NewCopyCharArray($input, size, Char);
} else {
$1 = 0;
}
@ -126,10 +128,10 @@
/* globalin */
%typemap(globalin,noblock=1) Char * {
if ($1) %delete_array($1);
if ($1) SWIG_DeleteCharArray($1);
if ($input) {
size_t size = SWIG_CharPtrLen(%reinterpret_cast(%reinterpret_cast($input, const Char *), const Char *)) + 1;
$1 = ($1_type)%new_copy_array($input, size, Char);
$1 = ($1_type)SWIG_NewCopyCharArray($input, size, Char);
} else {
$1 = 0;
}
@ -138,7 +140,7 @@
%typemap(globalin,noblock=1,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const Char * {
if ($input) {
size_t size = SWIG_CharPtrLen($input) + 1;
$1 = ($1_type)%new_copy_array($input, size, Char);
$1 = ($1_type)SWIG_NewCopyCharArray($input, size, Char);
} else {
$1 = 0;
}
@ -416,7 +418,7 @@
$2 = %numeric_cast(size - 1, $2_ltype);
}
%typemap(freearg,noblock=1,match="in") (Char *STRING, size_t LENGTH) {
if (alloc$argnum == SWIG_NEWOBJ) %delete_array(buf$argnum);
if (alloc$argnum == SWIG_NEWOBJ) SWIG_DeleteCharArray(buf$argnum);
}
/* old 'int' form */
%typemap(in) (Char *STRING, int LENGTH) = (Char *STRING, size_t LENGTH);
@ -436,7 +438,7 @@
$2 = %numeric_cast(size, $2_ltype);
}
%typemap(freearg,noblock=1,match="in") (Char *STRING, size_t SIZE) {
if (alloc$argnum == SWIG_NEWOBJ) %delete_array(buf$argnum);
if (alloc$argnum == SWIG_NEWOBJ) SWIG_DeleteCharArray(buf$argnum);
}
/* old 'int' form */
%typemap(in) (Char *STRING, int SIZE) = (Char *STRING, size_t SIZE);
@ -458,7 +460,7 @@
$1 = %numeric_cast(size - 1, $1_ltype) ;
}
%typemap(freearg, noblock=1, match="in") (size_t LENGTH, Char *STRING) {
if (alloc$argnum == SWIG_NEWOBJ) %delete_array(buf$argnum);
if (alloc$argnum == SWIG_NEWOBJ) SWIG_DeleteCharArray(buf$argnum);
}
/* old 'int' form */
%typemap(in) (int LENGTH, Char *STRING) = (size_t LENGTH, Char *STRING);
@ -477,7 +479,7 @@
$1 = %numeric_cast(size, $1_ltype) ;
}
%typemap(freearg, noblock=1, match="in") (size_t SIZE, Char *STRING) {
if (alloc$argnum == SWIG_NEWOBJ) %delete_array(buf$argnum);
if (alloc$argnum == SWIG_NEWOBJ) SWIG_DeleteCharArray(buf$argnum);
}
/* old 'int' form */
%typemap(in) (int SIZE, Char *STRING) = (size_t SIZE, Char *STRING);
@ -492,11 +494,13 @@
* ------------------------------------------------------------ */
%define %typemaps_string(StringCode, CharCode,
%define %_typemap2_string(StringCode, CharCode,
Char, CharName,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize,
SWIG_CharPtrLen,
SWIG_NewCopyCharArray,
SWIG_DeleteCharArray,
FragLimits, CHAR_MIN, CHAR_MAX)
%fragment("SWIG_From"#CharName"Ptr","header",fragment=#SWIG_FromCharPtrAndSize) {
@ -533,12 +537,12 @@ SWIG_As##CharName##Array(SWIG_Object obj, Char *val, size_t size)
if (csize < size) memset(val + csize, 0, (size - csize)*sizeof(Char));
}
if (alloc == SWIG_NEWOBJ) {
%delete_array(cptr);
SWIG_DeleteCharArray(cptr);
res = SWIG_DelNewMask(res);
}
return res;
}
if (alloc == SWIG_NEWOBJ) %delete_array(cptr);
if (alloc == SWIG_NEWOBJ) SWIG_DeleteCharArray(cptr);
}
return SWIG_TypeError;
}
@ -584,6 +588,51 @@ SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val)
SWIG_CharPtrLen,
SWIG_As##CharName##Ptr,
SWIG_From##CharName##Ptr,
SWIG_As##CharName##Array)
SWIG_As##CharName##Array,
SWIG_NewCopyCharArray,
SWIG_DeleteCharArray)
%enddef
/* ------------------------------------------------------------
* String typemaps and fragments, with default allocators
* ------------------------------------------------------------ */
%define %typemaps_string(StringCode, CharCode,
Char, CharName,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize,
SWIG_CharPtrLen,
FragLimits, CHAR_MIN, CHAR_MAX)
%_typemap2_string(StringCode, CharCode,
Char, CharName,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize,
SWIG_CharPtrLen,
%new_copy_array,
%delete_array,
FragLimits, CHAR_MIN, CHAR_MAX)
%enddef
/* ------------------------------------------------------------
* String typemaps and fragments, with custom allocators
* ------------------------------------------------------------ */
%define %typemaps_string_alloc(StringCode, CharCode,
Char, CharName,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize,
SWIG_CharPtrLen,
SWIG_NewCopyCharArray,
SWIG_DeleteCharArray,
FragLimits, CHAR_MIN, CHAR_MAX)
%_typemap2_string(StringCode, CharCode,
Char, CharName,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize,
SWIG_CharPtrLen,
SWIG_NewCopyCharArray,
SWIG_DeleteCharArray,
FragLimits, CHAR_MIN, CHAR_MAX)
%enddef