Merge branch 'restore-compat-wrappers-names' into C

Merge with the latest master including PR #2371.
This commit is contained in:
Vadim Zeitlin 2022-09-17 14:36:37 +02:00
commit 864f32159a
851 changed files with 21837 additions and 7327 deletions

View file

@ -1,5 +1,5 @@
#ifndef __Lib_allkw_swg__
#define __Lib_allkw_swg__
#ifndef SWIG_INCLUDED_LIB_ALLKW_SWG
#define SWIG_INCLUDED_LIB_ALLKW_SWG
/*
@ -30,4 +30,4 @@
%include <tcl/tclkw.swg>
#endif //__Lib_allkw_swg__
#endif // SWIG_INCLUDED_LIB_ALLKW_SWG

View file

@ -5,6 +5,12 @@
* pointers as arrays.
* ----------------------------------------------------------------------------- */
#ifndef __cplusplus
// C uses free/calloc/malloc
%include "swigfragments.swg"
%fragment("<stdlib.h>");
#endif
/* -----------------------------------------------------------------------------
* %array_functions(TYPE,NAME)
*

View file

@ -4,6 +4,8 @@
* SWIG library file containing macros for manipulating raw C data as strings.
* ----------------------------------------------------------------------------- */
%include <swigfragments.swg>
%{
typedef struct SWIGCDATA {
char *data;
@ -82,7 +84,7 @@ static jbyteArray SWIG_JavaArrayOutCDATA(JNIEnv *jenv, char *result, jsize sz) {
/* -----------------------------------------------------------------------------
* %cdata(TYPE [, NAME])
* %cdata(TYPE [, NAME])
*
* Convert raw C data to a binary string.
* ----------------------------------------------------------------------------- */
@ -121,6 +123,8 @@ SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements);
%cdata(void);
%fragment("<string.h>");
/* Memory move function. Due to multi-argument typemaps this appears to be wrapped as
void memmove(void *data, const char *s); */
void memmove(void *data, const void *indata, int inlen);

View file

@ -5,62 +5,62 @@
/* Typespecs for basic types. */
%typemap(cin) void ":void";
%typemap(cin) void ":void"
%typemap(cin) char ":char";
%typemap(cin) char * ":string";
%typemap(cin) unsigned char ":unsigned-char";
%typemap(cin) signed char ":char";
%typemap(cin) char ":char"
%typemap(cin) char * ":string"
%typemap(cin) unsigned char ":unsigned-char"
%typemap(cin) signed char ":char"
%typemap(cin) short ":short";
%typemap(cin) signed short ":short";
%typemap(cin) unsigned short ":unsigned-short";
%typemap(cin) short ":short"
%typemap(cin) signed short ":short"
%typemap(cin) unsigned short ":unsigned-short"
%typemap(cin) int ":int";
%typemap(cin) signed int ":int";
%typemap(cin) unsigned int ":unsigned-int";
%typemap(cin) int ":int"
%typemap(cin) signed int ":int"
%typemap(cin) unsigned int ":unsigned-int"
%typemap(cin) long ":long";
%typemap(cin) signed long ":long";
%typemap(cin) unsigned long ":unsigned-long";
%typemap(cin) long ":long"
%typemap(cin) signed long ":long"
%typemap(cin) unsigned long ":unsigned-long"
%typemap(cin) long long ":long-long";
%typemap(cin) signed long long ":long-long";
%typemap(cin) unsigned long long ":unsigned-long-long";
%typemap(cin) long long ":long-long"
%typemap(cin) signed long long ":long-long"
%typemap(cin) unsigned long long ":unsigned-long-long"
%typemap(cin) float ":float";
%typemap(cin) double ":double";
%typemap(cin) SWIGTYPE ":pointer";
%typemap(cin) float ":float"
%typemap(cin) double ":double"
%typemap(cin) SWIGTYPE ":pointer"
%typemap(cout) void ":void";
%typemap(cout) void ":void"
%typemap(cout) char ":char";
%typemap(cout) char * ":string";
%typemap(cout) unsigned char ":unsigned-char";
%typemap(cout) signed char ":char";
%typemap(cout) char ":char"
%typemap(cout) char * ":string"
%typemap(cout) unsigned char ":unsigned-char"
%typemap(cout) signed char ":char"
%typemap(cout) short ":short";
%typemap(cout) signed short ":short";
%typemap(cout) unsigned short ":unsigned-short";
%typemap(cout) short ":short"
%typemap(cout) signed short ":short"
%typemap(cout) unsigned short ":unsigned-short"
%typemap(cout) int ":int";
%typemap(cout) signed int ":int";
%typemap(cout) unsigned int ":unsigned-int";
%typemap(cout) int ":int"
%typemap(cout) signed int ":int"
%typemap(cout) unsigned int ":unsigned-int"
%typemap(cout) long ":long";
%typemap(cout) signed long ":long";
%typemap(cout) unsigned long ":unsigned-long";
%typemap(cout) long ":long"
%typemap(cout) signed long ":long"
%typemap(cout) unsigned long ":unsigned-long"
%typemap(cout) long long ":long-long";
%typemap(cout) signed long long ":long-long";
%typemap(cout) unsigned long long ":unsigned-long-long";
%typemap(cout) long long ":long-long"
%typemap(cout) signed long long ":long-long"
%typemap(cout) unsigned long long ":unsigned-long-long"
%typemap(cout) float ":float";
%typemap(cout) double ":double";
%typemap(cout) SWIGTYPE ":pointer";
%typemap(cout) float ":float"
%typemap(cout) double ":double"
%typemap(cout) SWIGTYPE ":pointer"
%typemap(ctype) bool "int";
%typemap(ctype) bool "int"
%typemap(ctype) char, unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
@ -68,9 +68,9 @@
float, double, long double, char *, void *, void,
enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1_ltype";
%typemap(ctype) SWIGTYPE "$&1_type";
%typemap(ctype) SWIGTYPE "$&1_type"
%typemap(in) bool "$1 = (bool)$input;";
%typemap(in) bool "$1 = (bool)$input;"
%typemap(in) char, unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
@ -78,10 +78,10 @@
float, double, long double, char *, void *, void,
enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1 = $input;";
%typemap(in) SWIGTYPE "$1 = *$input;";
%typemap(in) SWIGTYPE "$1 = *$input;"
%typemap(out) void "";
%typemap(out) bool "$result = (int)$1;";
%typemap(out) void ""
%typemap(out) bool "$result = (int)$1;"
%typemap(out) char, unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
@ -90,7 +90,8 @@
enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$result = $1;";
#ifdef __cplusplus
%typemap(out) SWIGTYPE "$result = new $1_type($1);";
%typemap(out) SWIGTYPE
%{ $result = new $1_ltype($1); %}
#else
%typemap(out) SWIGTYPE {
$result = ($&1_ltype) malloc(sizeof($1_type));
@ -113,22 +114,22 @@
SWIGTYPE[ANY], SWIGTYPE { $1 = 1; };
/* This maps C/C++ types to Lisp classes for overload dispatch */
%typemap(lisptype) bool "cl:boolean";
%typemap(lisptype) char "cl:character";
%typemap(lisptype) unsigned char "cl:integer";
%typemap(lisptype) signed char "cl:integer";
%typemap(lisptype) bool "cl:boolean"
%typemap(lisptype) char "cl:character"
%typemap(lisptype) unsigned char "cl:integer"
%typemap(lisptype) signed char "cl:integer"
%typemap(lispclass) bool "t";
%typemap(lispclass) char "cl:character";
%typemap(lispclass) bool "t"
%typemap(lispclass) char "cl:character"
%typemap(lispclass) unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
long, signed long, unsigned long,
enum SWIGTYPE "cl:integer";
/* CLOS methods can't be specialized on single-float or double-float */
%typemap(lispclass) float "cl:number";
%typemap(lispclass) double "cl:number";
%typemap(lispclass) char * "cl:string";
%typemap(lispclass) float "cl:number"
%typemap(lispclass) double "cl:number"
%typemap(lispclass) char * "cl:string"
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
@ -201,15 +202,6 @@
;;;SWIG wrapper code ends here
%}
#ifdef __cplusplus
%typemap(out) SWIGTYPE "$result = new $1_type($1);";
#else
%typemap(out) SWIGTYPE {
$result = ($&1_ltype) malloc(sizeof($1_type));
memmove($result, &$1, sizeof($1_type));
}
#endif
//////////////////////////////////////////////////////////////
/* name conversion for overloaded operators. */

View file

@ -5,6 +5,12 @@
* pointer objects.
* ----------------------------------------------------------------------------- */
#ifndef __cplusplus
// C uses free/calloc/malloc
%include "swigfragments.swg"
%fragment("<stdlib.h>");
#endif
/* -----------------------------------------------------------------------------
* %pointer_class(type,name)
*
@ -55,14 +61,14 @@ NAME() {
return new TYPE();
}
~NAME() {
if ($self) delete $self;
delete $self;
}
#else
NAME() {
return (TYPE *) calloc(1,sizeof(TYPE));
}
~NAME() {
if ($self) free($self);
free($self);
}
#endif
}
@ -114,7 +120,7 @@ static NAME * frompointer(TYPE *t) {
%define %pointer_functions(TYPE,NAME)
%{
static TYPE *new_##NAME() { %}
static TYPE *new_##NAME(void) { %}
#ifdef __cplusplus
%{ return new TYPE(); %}
#else
@ -134,9 +140,9 @@ static TYPE *copy_##NAME(TYPE value) { %}
static void delete_##NAME(TYPE *obj) { %}
#ifdef __cplusplus
%{ if (obj) delete obj; %}
%{ delete obj; %}
#else
%{ if (obj) free(obj); %}
%{ free(obj); %}
#endif
%{}
@ -149,7 +155,7 @@ static TYPE NAME ##_value(TYPE *obj) {
}
%}
TYPE *new_##NAME();
TYPE *new_##NAME(void);
TYPE *copy_##NAME(TYPE value);
void delete_##NAME(TYPE *obj);
void NAME##_assign(TYPE *obj, TYPE value);

View file

@ -32,7 +32,7 @@
%}
%typemap(out, fragment="SWIG_intrusive_deleter") CONST TYPE %{
//plain value(out)
$1_ltype* resultp = new $1_ltype(($1_ltype &)$1);
$1_ltype* resultp = new $1_ltype($1);
intrusive_ptr_add_ref(resultp);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(resultp, SWIG_intrusive_deleter< CONST TYPE >());
%}
@ -372,7 +372,7 @@
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype($1)); %}
// plain pointer
%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{

View file

@ -29,10 +29,10 @@
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype($1)); %}
%typemap(directorin) CONST TYPE
%{ $input = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype((const $1_ltype &)$1)); %}
%{ $input = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype(SWIG_STD_MOVE($1))); %}
%typemap(directorout) CONST TYPE
%{ if (!$input) {
@ -122,7 +122,7 @@
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
%typemap(out, fragment="SWIG_null_deleter") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *
%{ $result = ($1 && *$1) ? new $*1_ltype(*($1_ltype)$1) : 0;
%{ $result = ($1 && *$1) ? new $*1_ltype(*$1) : 0;
if ($owner) delete $1; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *

View file

@ -399,7 +399,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%typemap(out) SWIGTYPE
#ifdef __cplusplus
%{ $result = new $1_ltype((const $1_ltype &)$1); %}
%{ $result = new $1_ltype($1); %}
#else
{
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
@ -409,7 +409,7 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
#endif
%typemap(directorin) SWIGTYPE
%{ $input = (void *)new $1_ltype((const $1_ltype &)$1); %}
%{ $input = (void *)new $1_ltype(SWIG_STD_MOVE($1)); %}
%typemap(csdirectorin) SWIGTYPE "new $&csclassname($iminput, true)"
%typemap(csdirectorout) SWIGTYPE "$&csclassname.getCPtr($cscall).Handle"
@ -420,14 +420,15 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
%}
%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0);
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type is null", 0);
return $null;
} %}
%typemap(in, canthrow=1) SWIGTYPE && %{ $1 = ($1_ltype)$input;
%typemap(in, canthrow=1, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0);
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type is null", 0);
return $null;
} %}
}
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE * %{ $result = (void *)$1; %}
%typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{
char buf[128];
@ -613,7 +614,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
"$csinput"
%typemap(csin) char *, char *&, char[ANY], char[] "$csinput"
%typemap(csin) SWIGTYPE "$&csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "$csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$csclassname.getCPtr($csinput)"
%typemap(csin) SWIGTYPE && "$csclassname.swigRelease($csinput)"
%typemap(csin) SWIGTYPE (CLASS::*) "$csclassname.getCMemberPtr($csinput)"
/* The csout typemap is used for converting function return types from the return type
@ -913,6 +915,19 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef swigRelease($csclassname obj) {
if (obj != null) {
if (!obj.swigCMemOwn)
throw new global::System.ApplicationException("Cannot release ownership as memory is not owned");
global::System.Runtime.InteropServices.HandleRef ptr = obj.swigCPtr;
obj.swigCMemOwn = false;
obj.Dispose();
return ptr;
} else {
return new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
}
%}
// Derived proxy classes
@ -926,6 +941,19 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef swigRelease($csclassname obj) {
if (obj != null) {
if (!obj.swigCMemOwn)
throw new global::System.ApplicationException("Cannot release ownership as memory is not owned");
global::System.Runtime.InteropServices.HandleRef ptr = obj.swigCPtr;
obj.swigCMemOwn = false;
obj.Dispose();
return ptr;
} else {
return new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
}
}
%}
%enddef
@ -945,6 +973,10 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef getCPtr($csclassname obj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
CPTR_VISIBILITY static global::System.Runtime.InteropServices.HandleRef swigRelease($csclassname obj) {
return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
}
%}
%typemap(csbody) TYPE (CLASS::*) %{

View file

@ -335,5 +335,5 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_$module(SWIG_CSharpString
%insert(runtime) %{
/* Contract support */
#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, msg, ""); return nullreturn; } else
#define SWIG_contract_assert(nullreturn, expr, msg) do { if (!(expr)) {SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentOutOfRangeException, msg, ""); return nullreturn; } } while (0)
%}

View file

@ -2,9 +2,9 @@
#define CSHARP_CSHARPKW_SWG_
/* Warnings for C# keywords */
#define CSHARPKW(x) %keywordwarn("'" `x` "' is a C# keyword, renaming to '" `x` "_'",rename="%s_") `x`
#define CSHARPKW(x) %keywordwarn("'" `x` "' is a C# keyword",rename="%s_") `x`
#define CSHARPCLASSKW(x) %keywordwarn("'" `x` "' is a special method name used in the C# wrapper classes, class renamed to '" `x` "_'",%$isclass,rename="%s_") `x`
#define CSHARPCLASSKW(x) %keywordwarn("'" `x` "' is a special method name used in the C# wrapper classes",%$isclass,rename="%s_") `x`
/*
from

View file

@ -16,7 +16,7 @@
%define SWIG_STD_ARRAY_INTERNAL(T, N)
%typemap(csinterfaces) std::array< T, N > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>\n";
%typemap(csinterfaces) std::array< T, N > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>\n"
%proxycode %{
public $csclassname(global::System.Collections.ICollection c) : this() {
if (c == null)

View file

@ -1,25 +1,38 @@
/*
The typemaps here allow handling functions returning std::auto_ptr<>,
which is the most common use of this type. If you have functions taking it
as parameter, these typemaps can't be used for them and you need to do
something else (e.g. use shared_ptr<> which SWIG supports fully).
*/
/* -----------------------------------------------------------------------------
* std_auto_ptr.i
*
* SWIG library file for handling std::auto_ptr.
* Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
* class when returning a std::auto_ptr from a function.
* Memory ownership is passed from the proxy class to the std::auto_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
%typemap (ctype) std::auto_ptr<TYPE > "void *"
%typemap (imtype, out="System.IntPtr") std::auto_ptr<TYPE > "HandleRef"
%typemap (cstype) std::auto_ptr<TYPE > "$typemap(cstype, TYPE)"
%typemap (out) std::auto_ptr<TYPE > %{
$result = (void *)$1.release();
%typemap (ctype) std::auto_ptr< TYPE > "void *"
%typemap (imtype, out="System.IntPtr") std::auto_ptr< TYPE > "global::System.Runtime.InteropServices.HandleRef"
%typemap (cstype) std::auto_ptr< TYPE > "$typemap(cstype, TYPE)"
%typemap(in) std::auto_ptr< TYPE >
%{ $1.reset((TYPE *)$input); %}
%typemap(csin) std::auto_ptr< TYPE > "$typemap(cstype, TYPE).swigRelease($csinput)"
%typemap (out) std::auto_ptr< TYPE > %{
$result = (void *)$1.release();
%}
%typemap(csout, excode=SWIGEXCODE) std::auto_ptr<TYPE > {
System.IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%template() std::auto_ptr<TYPE >;
%typemap(csout, excode=SWIGEXCODE) std::auto_ptr< TYPE > {
System.IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *") std::auto_ptr< TYPE > ""
%template() std::auto_ptr< TYPE >;
%enddef
namespace std {
template <class T> class auto_ptr {};
}
template <class T> class auto_ptr {};
}

View file

@ -19,7 +19,7 @@
// MACRO for use within the std::list class body
%define SWIG_STD_LIST_MINIMUM_INTERNAL(CSINTERFACE, CTYPE...)
%typemap(csinterfaces) std::list< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n";
%typemap(csinterfaces) std::list< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n"
%apply void *VOID_INT_PTR { std::list< CTYPE >::iterator * };

View file

@ -26,7 +26,7 @@
/* K is the C++ key type, T is the C++ value type */
%define SWIG_STD_MAP_INTERNAL(K, T, C)
%typemap(csinterfaces) std::map< K, T, C > "global::System.IDisposable \n , global::System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n";
%typemap(csinterfaces) std::map< K, T, C > "global::System.IDisposable \n , global::System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n"
%proxycode %{
public $typemap(cstype, T) this[$typemap(cstype, K) key] {

View file

@ -28,7 +28,7 @@ namespace std {
template <class T>
class set {
%typemap(csinterfaces) std::set<T> "global::System.IDisposable, global::System.Collections.Generic.ISet<$typemap(cstype, T)>\n";
%typemap(csinterfaces) std::set<T> "global::System.IDisposable, global::System.Collections.Generic.ISet<$typemap(cstype, T)>\n"
%proxycode %{
void global::System.Collections.Generic.ICollection<$typemap(cstype, T)>.Add($typemap(cstype, T) item) {
((global::System.Collections.Generic.ISet<$typemap(cstype, T)>)this).Add(item);

View file

@ -20,7 +20,7 @@ namespace std {
class string;
// string
%typemap(ctype) string "char *"
%typemap(ctype) string "const char *"
%typemap(imtype) string "string"
%typemap(cstype) string "string"
@ -42,7 +42,7 @@ class string;
}
$result.assign($input); %}
%typemap(directorin) string %{ $input = SWIG_csharp_string_callback($1.c_str()); %}
%typemap(directorin) string %{ $input = $1.c_str(); %}
%typemap(csin) string "$csinput"
%typemap(csout, excode=SWIGEXCODE) string {
@ -57,7 +57,7 @@ class string;
return $null; %}
// const string &
%typemap(ctype) const string & "char *"
%typemap(ctype) const string & "const char *"
%typemap(imtype) const string & "string"
%typemap(cstype) const string & "string"
@ -89,7 +89,7 @@ class string;
$1_str = $input;
$result = &$1_str; %}
%typemap(directorin) const string & %{ $input = SWIG_csharp_string_callback($1.c_str()); %}
%typemap(directorin) const string & %{ $input = $1.c_str(); %}
%typemap(csvarin, excode=SWIGEXCODE2) const string & %{
set {

View file

@ -0,0 +1,38 @@
/* -----------------------------------------------------------------------------
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %unique_ptr(TYPE)
%typemap (ctype) std::unique_ptr< TYPE > "void *"
%typemap (imtype, out="System.IntPtr") std::unique_ptr< TYPE > "global::System.Runtime.InteropServices.HandleRef"
%typemap (cstype) std::unique_ptr< TYPE > "$typemap(cstype, TYPE)"
%typemap(in) std::unique_ptr< TYPE >
%{ $1.reset((TYPE *)$input); %}
%typemap(csin) std::unique_ptr< TYPE > "$typemap(cstype, TYPE).swigRelease($csinput)"
%typemap (out) std::unique_ptr< TYPE > %{
$result = (void *)$1.release();
%}
%typemap(csout, excode=SWIGEXCODE) std::unique_ptr< TYPE > {
System.IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *") std::unique_ptr< TYPE > ""
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View file

@ -19,7 +19,7 @@
// MACRO for use within the std::vector class body
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...)
%typemap(csinterfaces) std::vector< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n";
%typemap(csinterfaces) std::vector< CTYPE > "global::System.IDisposable, global::System.Collections.IEnumerable, global::System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n"
%proxycode %{
public $csclassname(global::System.Collections.IEnumerable c) : this() {
if (c == null)
@ -63,7 +63,7 @@
return (int)capacity();
}
set {
if (value < size())
if (value < 0 || ($typemap(cstype, size_t))value < size())
throw new global::System.ArgumentOutOfRangeException("Capacity");
reserve(($typemap(cstype, size_t))value);
}

View file

@ -2,7 +2,9 @@
* std_wstring.i
*
* Typemaps for std::wstring and const std::wstring&
* These are mapped to a C# String and are passed around by value.
* std::wstring is mapped to a C# Unicode string (UTF16) and is passed around by value.
* std::wstring support includes wchar_t as a 2 byte type (Windows) and a 4 byte type
* (most Unix systems).
*
* To use non-const std::wstring references use the following %apply. Note
* that they are passed by value.
@ -15,6 +17,28 @@
#include <string>
%}
%fragment("Swig_csharp_UTF16ToWString", "header") %{
/* For converting from .NET UTF16 (2 byte unicode) strings. wchar_t is 2 bytes on Windows, 4 bytes on Linux. */
static std::wstring Swig_csharp_UTF16ToWString(const unsigned short *str) {
if (sizeof(wchar_t) == 2) {
return std::wstring((wchar_t *)str);
} else {
const unsigned short *pBegin(str);
const unsigned short *ptr(pBegin);
while (*ptr != 0)
++ptr;
std::wstring result;
result.reserve(ptr - pBegin);
while(pBegin != ptr)
result.push_back(*pBegin++);
return result;
}
}
%}
namespace std {
%naturalvar wstring;
@ -22,31 +46,33 @@ namespace std {
class wstring;
// wstring
%typemap(ctype, out="void *") wstring "wchar_t *"
%typemap(ctype, out="void *") wstring "unsigned short *"
%typemap(imtype,
inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
outattributes="[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]"
outattributes="[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
directorinattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
directoroutattributes="[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]"
) wstring "string"
%typemap(cstype) wstring "string"
%typemap(csdirectorin) wstring "$iminput"
%typemap(csdirectorout) wstring "$cscall"
%typemap(in, canthrow=1) wstring
%typemap(in, canthrow=1, fragment="Swig_csharp_UTF16ToWString") wstring
%{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0);
return $null;
}
$1.assign($input); %}
%typemap(out) wstring %{ $result = SWIG_csharp_wstring_callback($1.c_str()); %}
$1 = Swig_csharp_UTF16ToWString($input); %}
%typemap(out) wstring %{ $result = SWIG_csharp_wstring_with_length_callback($1.c_str(), (int)$1.size()); %}
%typemap(directorout, canthrow=1) wstring
%typemap(directorout, canthrow=1) wstring
%{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0);
return $null;
}
$result.assign($input); %}
$result = Swig_csharp_UTF16ToWString($input); %}
%typemap(directorin) wstring %{ $input = SWIG_csharp_wstring_callback($1.c_str()); %}
%typemap(directorin) wstring %{ $input = SWIG_csharp_wstring_with_length_callback($1.c_str(), (int)$1.size()); %}
%typemap(csin) wstring "$csinput"
%typemap(csout, excode=SWIGEXCODE) wstring {
@ -57,29 +83,30 @@ class wstring;
%typemap(typecheck) wstring = wchar_t *;
%typemap(throws, canthrow=1) wstring
%{ std::string message($1.begin(), $1.end());
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, message.c_str());
%{ SWIG_csharp_ApplicationException_callback($1.c_str(), (int)$1.size());
return $null; %}
// const wstring &
%typemap(ctype, out="void *") const wstring & "wchar_t *"
%typemap(ctype, out="void *") const wstring & "unsigned short *"
%typemap(imtype,
inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
outattributes="[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]"
outattributes="[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
directorinattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
directoroutattributes="[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]"
) const wstring & "string"
%typemap(cstype) const wstring & "string"
%typemap(csdirectorin) const wstring & "$iminput"
%typemap(csdirectorout) const wstring & "$cscall"
%typemap(in, canthrow=1) const wstring &
%typemap(in, canthrow=1, fragment="Swig_csharp_UTF16ToWString") const wstring &
%{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0);
return $null;
}
std::wstring $1_str($input);
std::wstring $1_str(Swig_csharp_UTF16ToWString($input));
$1 = &$1_str; %}
%typemap(out) const wstring & %{ $result = SWIG_csharp_wstring_callback($1->c_str()); %}
%typemap(out) const wstring & %{ $result = SWIG_csharp_wstring_with_length_callback($1->c_str(), (int)$1->size()); %}
%typemap(csin) const wstring & "$csinput"
%typemap(csout, excode=SWIGEXCODE) const wstring & {
@ -94,10 +121,10 @@ class wstring;
}
/* possible thread/reentrant code problem */
static std::wstring $1_str;
$1_str = $input;
$1_str = Swig_csharp_UTF16ToWString($input);
$result = &$1_str; %}
%typemap(directorin) const wstring & %{ $input = SWIG_csharp_wstring_callback($1.c_str()); %}
%typemap(directorin) const wstring & %{ $input = SWIG_csharp_wstring_with_length_callback($1.c_str(), (int)$1.size()); %}
%typemap(csvarin, excode=SWIGEXCODE2) const wstring & %{
set {
@ -112,8 +139,7 @@ class wstring;
%typemap(typecheck) const wstring & = wchar_t *;
%typemap(throws, canthrow=1) const wstring &
%{ std::string message($1.begin(), $1.end());
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, message.c_str());
%{ SWIG_csharp_ApplicationException_callback($1.c_str(), (int)$1.size());
return $null; %}
}

16
Lib/csharp/swigmove.i Normal file
View file

@ -0,0 +1,16 @@
/* -----------------------------------------------------------------------------
* swigmove.i
*
* Input typemaps library for implementing full move semantics when passing
* parameters by value.
* ----------------------------------------------------------------------------- */
%typemap(in, canthrow=1, fragment="<memory>") SWIGTYPE MOVE ($&1_type argp)
%{ argp = ($&1_ltype)$input;
if (!argp) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "Attempt to dereference null $1_type", 0);
return $null;
}
SwigValueWrapper< $1_ltype >::reset($1, argp); %}
%typemap(csin) SWIGTYPE MOVE "$&csclassname.swigRelease($csinput)"

View file

@ -2,37 +2,59 @@
* wchar.i
*
* Typemaps for the wchar_t type
* These are mapped to a C# String and are passed around by value.
* wchar_t * is mapped to a C# Unicode string (UTF16) and is passed around by value.
* wchar_t * support includes wchar_t as a 2 byte type (Windows) and a 4 byte type
* (most Unix systems).
*
* Support code for wide strings can be turned off by defining SWIG_CSHARP_NO_WSTRING_HELPER
*
* ----------------------------------------------------------------------------- */
#if !defined(SWIG_CSHARP_NO_WSTRING_HELPER)
#if !defined(SWIG_CSHARP_WSTRING_HELPER_)
#define SWIG_CSHARP_WSTRING_HELPER_
%fragment("<wchar.h>"); // TODO: %fragment("<wchar.h", "runtime");
%insert(runtime) %{
/* Callback for returning strings to C# without leaking memory */
typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *);
static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL;
typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *, int length);
static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_with_length_callback = NULL;
%}
%insert(header) %{
static void * SWIG_csharp_wstring_callback(const wchar_t *s) {
return SWIG_csharp_wstring_with_length_callback(s, (int)wcslen(s));
}
%}
%pragma(csharp) imclasscode=%{
protected class SWIGWStringHelper {
[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public delegate string SWIGWStringDelegate(global::System.IntPtr message);
static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString);
public delegate string SWIGWStringDelegate(global::System.IntPtr message, int length);
static SWIGWStringDelegate wstringUTF16Delegate = new SWIGWStringDelegate(CreateWStringFromUTF16);
static SWIGWStringDelegate wstringUTF32Delegate = new SWIGWStringDelegate(CreateWStringFromUTF32);
[global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")]
public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringDelegate);
public static extern void SWIGRegisterWStringCallback_$module(SWIGWStringDelegate wstringUTF16Delegate, SWIGWStringDelegate wstringUTF32Delegate);
static string CreateWString([global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]global::System.IntPtr cString) {
return global::System.Runtime.InteropServices.Marshal.PtrToStringUni(cString);
public static string CreateWStringFromUTF16([global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]global::System.IntPtr cString, int length) {
return global::System.Runtime.InteropServices.Marshal.PtrToStringUni(cString, length);
}
public static string CreateWStringFromUTF32([global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]global::System.IntPtr cString, int length) {
if (length == 0)
return string.Empty;
byte[] buffer = new byte[length * 4];
global::System.Runtime.InteropServices.Marshal.Copy(cString, buffer, 0, buffer.Length);
byte[] utf8buffer = global::System.Text.Encoding.Convert(global::System.Text.Encoding.UTF32, global::System.Text.Encoding.UTF8, buffer);
return global::System.Text.Encoding.Default.GetString(utf8buffer);
}
static SWIGWStringHelper() {
SWIGRegisterWStringCallback_$module(wstringDelegate);
SWIGRegisterWStringCallback_$module(wstringUTF16Delegate, wstringUTF32Delegate);
}
}
@ -43,13 +65,78 @@ static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL;
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback) {
SWIG_csharp_wstring_callback = callback;
SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback_utf16, SWIG_CSharpWStringHelperCallback callback_utf32) {
SWIG_csharp_wstring_with_length_callback = sizeof(wchar_t) == 2 ? callback_utf16 : callback_utf32;
}
%}
#endif // SWIG_CSHARP_WSTRING_HELPER_
#endif // SWIG_CSHARP_NO_WSTRING_HELPER
#if !defined(SWIG_CSHARP_NO_WSTRING_EXCEPTION_HELPER)
#if !defined(SWIG_CSHARP_WSTRING_EXCEPTION_HELPER_)
#define SWIG_CSHARP_WSTRING_EXCEPTION_HELPER_
%insert(runtime) %{
/* Callback for returning strings to C# without leaking memory */
typedef void (SWIGSTDCALL* SWIG_CSharpWStringExceptionHelperCallback)(const wchar_t *, int length);
static SWIG_CSharpWStringExceptionHelperCallback SWIG_csharp_ApplicationException_callback = NULL;
%}
%pragma(csharp) imclasscode=%{
protected class SWIGWStringExceptionHelper {
[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public delegate void SWIGWStringExceptionDelegate(global::System.IntPtr message, int length);
static SWIGWStringExceptionDelegate applicationExceptionUTF16Delegate = new SWIGWStringExceptionDelegate(SetPendingApplicationExceptionUTF16);
static SWIGWStringExceptionDelegate applicationExceptionUTF32Delegate = new SWIGWStringExceptionDelegate(SetPendingApplicationExceptionUTF32);
[global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="SWIGRegisterWStringExceptionCallback_$module")]
public static extern void SWIGRegisterWStringExceptionCallback_$module(SWIGWStringExceptionDelegate applicationExceptionUTF16Delegate, SWIGWStringExceptionDelegate applicationExceptionUTF32Delegate);
static string CreateWStringFromUTF16([global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]global::System.IntPtr cString, int length) {
return global::System.Runtime.InteropServices.Marshal.PtrToStringUni(cString, length);
}
public static string CreateWStringFromUTF32([global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]global::System.IntPtr cString, int length) {
if (length == 0)
return string.Empty;
byte[] buffer = new byte[length * 4];
global::System.Runtime.InteropServices.Marshal.Copy(cString, buffer, 0, buffer.Length);
byte[] utf8buffer = global::System.Text.Encoding.Convert(global::System.Text.Encoding.UTF32, global::System.Text.Encoding.UTF8, buffer);
return global::System.Text.Encoding.Default.GetString(utf8buffer);
}
static void SetPendingApplicationExceptionUTF16([global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]global::System.IntPtr cString, int length) {
string message = SWIGWStringHelper.CreateWStringFromUTF16(cString, length);
SWIGPendingException.Set(new global::System.ApplicationException(message, SWIGPendingException.Retrieve()));
}
static void SetPendingApplicationExceptionUTF32([global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]global::System.IntPtr cString, int length) {
string message = SWIGWStringHelper.CreateWStringFromUTF32(cString, length);
SWIGPendingException.Set(new global::System.ApplicationException(message, SWIGPendingException.Retrieve()));
}
static SWIGWStringExceptionHelper() {
SWIGRegisterWStringExceptionCallback_$module(applicationExceptionUTF16Delegate, applicationExceptionUTF32Delegate);
}
}
static protected SWIGWStringExceptionHelper swigWStringExceptionHelper = new SWIGWStringExceptionHelper();
%}
%insert(runtime) %{
#ifdef __cplusplus
extern "C"
#endif
SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringExceptionCallback_$module(SWIG_CSharpWStringExceptionHelperCallback callback_utf16, SWIG_CSharpWStringExceptionHelperCallback callback_utf32) {
SWIG_csharp_ApplicationException_callback = sizeof(wchar_t) == 2 ? callback_utf16 : callback_utf32;
}
%}
#endif // SWIG_CSHARP_WSTRING_EXCEPTION_HELPER_
#endif // SWIG_CSHARP_NO_WSTRING_EXCEPTION_HELPER
// wchar_t
%typemap(ctype) wchar_t "wchar_t"
@ -77,13 +164,64 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStri
%typemap(typecheck) wchar_t = char;
// wchar_t *
%typemap(ctype) wchar_t * "wchar_t *"
%typemap(imtype, inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]", out="global::System.IntPtr" ) wchar_t * "string"
%fragment("Swig_csharp_UTF16ToWCharPtr", "header") %{
/* For converting from .NET UTF16 (2 byte unicode) strings. wchar_t is 2 bytes on Windows, 4 bytes on Linux. */
static wchar_t * Swig_csharp_UTF16ToWCharPtr(const unsigned short *str) {
if (sizeof(wchar_t) == 2) {
return (wchar_t *)str;
} else {
wchar_t *result = 0;
if (str) {
const unsigned short *pBegin(str);
const unsigned short *pEnd(pBegin);
wchar_t *ptr = 0;
while (*pEnd != 0)
++pEnd;
#ifdef __cplusplus
result = ptr = new wchar_t[pEnd - pBegin + 1];
#else
result = ptr = (wchar_t *)malloc(sizeof(wchar_t) * (pEnd - pBegin + 1));
#endif
while(pBegin != pEnd)
*ptr++ = *pBegin++;
*ptr++ = 0;
}
return result;
}
}
%}
%fragment("Swig_csharp_UTF16ToWCharPtrFree", "header") %{
static void Swig_csharp_UTF16ToWCharPtrFree(wchar_t *str) {
if (sizeof(wchar_t) != 2) {
#ifdef __cplusplus
delete [] str;
#else
free(str);
#endif
}
}
%}
%typemap(ctype, out="void *") wchar_t * "unsigned short *"
%typemap(imtype,
inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
outattributes="[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
directorinattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]",
directoroutattributes="[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]"
) wchar_t * "string"
%typemap(cstype) wchar_t * "string"
%typemap(csdirectorin) wchar_t * "$iminput"
%typemap(csdirectorout) wchar_t * "$cscall"
%typemap(csin) wchar_t * "$csinput"
%typemap(csout, excode=SWIGEXCODE) wchar_t * {
string ret = global::System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode
string ret = $imcall;$excode
return ret;
}
%typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{
@ -92,12 +230,109 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStri
} %}
%typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{
get {
string ret = global::System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode
string ret = $imcall;$excode
return ret;
} %}
%typemap(in) wchar_t * %{ $1 = ($1_ltype)$input; %}
%typemap(out) wchar_t * %{ $result = (wchar_t *)$1; %}
%typemap(in, fragment="Swig_csharp_UTF16ToWCharPtr") wchar_t *
%{ $1 = Swig_csharp_UTF16ToWCharPtr($input); %}
%typemap(out) wchar_t * %{ $result = $1 ? SWIG_csharp_wstring_callback($1) : 0; %}
%typemap(freearg, fragment="Swig_csharp_UTF16ToWCharPtrFree") wchar_t *
%{ Swig_csharp_UTF16ToWCharPtrFree($1); %}
%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) wchar_t *
%{ $result = Swig_csharp_UTF16ToWCharPtr($input); %}
%typemap(directorin) wchar_t * %{ $input = SWIG_csharp_wstring_with_length_callback($1, (int)wcslen($1)); %}
%typemap(typecheck) wchar_t * = char *;
%typemap(throws, canthrow=1, fragment="<wchar.h>") wchar_t *
%{ SWIG_csharp_ApplicationException_callback($1, (int)wcslen($1));
return $null; %}
/* Default typemap for handling wchar_t * members (based on char * in swig.swg) */
#ifdef __cplusplus
%typemap(memberin,fragment="<wchar.h>") wchar_t * {
delete [] $1;
if ($input && sizeof(wchar_t) == 2) {
$1 = ($1_type) (new wchar_t[wcslen((const wchar_t *)$input)+1]);
wcscpy((wchar_t *)$1, (const wchar_t *)$input);
} else {
$1 = $input;
$input = 0;
}
}
%typemap(memberin,warning=SWIGWARN_TYPEMAP_WCHARLEAK_MSG,fragment="<wchar.h>") const wchar_t * {
if ($input && sizeof(wchar_t) == 2) {
$1 = ($1_type) (new wchar_t[wcslen((const wchar_t *)$input)+1]);
wcscpy((wchar_t *)$1, (const wchar_t *)$input);
} else {
$1 = $input;
$input = 0;
}
}
%typemap(globalin,fragment="<wchar.h>") wchar_t * {
delete [] $1;
if ($input && sizeof(wchar_t) == 2) {
$1 = ($1_type) (new wchar_t[wcslen((const wchar_t *)$input)+1]);
wcscpy((wchar_t *)$1, (const wchar_t *)$input);
} else {
$1 = $input;
$input = 0;
}
}
%typemap(globalin,warning=SWIGWARN_TYPEMAP_WCHARLEAK_MSG,fragment="<wchar.h>") const wchar_t * {
if ($input && sizeof(wchar_t) == 2) {
$1 = ($1_type) (new wchar_t[wcslen((const wchar_t *)$input)+1]);
wcscpy((wchar_t *)$1, (const wchar_t *)$input);
} else {
$1 = $input;
$input = 0;
}
}
#else
%typemap(memberin,fragment="<wchar.h>") wchar_t * {
free($1);
if ($input && sizeof(wchar_t) == 2) {
$1 = ($1_type) malloc(wcslen((const wchar_t *)$input)+1);
wcscpy((wchar_t *)$1, (const wchar_t *)$input);
} else {
$1 = $input;
$input = 0;
}
}
%typemap(memberin,warning=SWIGWARN_TYPEMAP_WCHARLEAK_MSG,fragment="<wchar.h>") const wchar_t * {
if ($input && sizeof(wchar_t) == 2) {
$1 = ($1_type) malloc(wcslen((const wchar_t *)$input)+1);
wcscpy((wchar_t *)$1, (const wchar_t *)$input);
} else {
$1 = $input;
$input = 0;
}
}
%typemap(globalin,fragment="<wchar.h>") wchar_t * {
free($1);
if ($input && sizeof(wchar_t) == 2) {
$1 = ($1_type) malloc(wcslen((const wchar_t *)$input)+1);
wcscpy((wchar_t *)$1, (const wchar_t *)$input);
} else {
$1 = $input;
$input = 0;
}
}
%typemap(globalin,warning=SWIGWARN_TYPEMAP_WCHARLEAK_MSG,fragment="<wchar.h>") const wchar_t * {
if ($input && sizeof(wchar_t) == 2) {
$1 = ($1_type) malloc(wcslen((const wchar_t *)$input)+1);
wcscpy((wchar_t *)$1, (const wchar_t *)$input);
} else {
$1 = $input;
$input = 0;
}
}
#endif

View file

@ -23,10 +23,10 @@
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype($1)); %}
%typemap(directorin) CONST TYPE
%{ $input = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype((const $1_ltype &)$1)); %}
%{ $input = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype(SWIG_STD_MOVE($1))); %}
%typemap(directorout) CONST TYPE
%{ if (!$input) {
@ -116,7 +116,7 @@
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
%typemap(out, fragment="SWIG_null_deleter") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *
%{ $result = ($1 && *$1) ? new $*1_ltype(*($1_ltype)$1) : 0;
%{ $result = ($1 && *$1) ? new $*1_ltype(*$1) : 0;
if ($owner) delete $1; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *

View file

@ -54,14 +54,14 @@ NAME() {
return new TYPE();
}
~NAME() {
if (self) delete self;
delete self;
}
#else
NAME() {
return (TYPE *) calloc(1,sizeof(TYPE));
}
~NAME() {
if (self) free(self);
free(self);
}
#endif
}
@ -133,9 +133,9 @@ static TYPE *copy_##NAME(TYPE value) { %}
static void delete_##NAME(TYPE *self) { %}
#ifdef __cplusplus
%{ if (self) delete self; %}
%{ delete self; %}
#else
%{ if (self) free(self); %}
%{ free(self); %}
#endif
%{}

View file

@ -76,6 +76,19 @@ public static void* swigGetCPtr(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr;
}
public static void* swigRelease(typeof(this) obj) {
if (obj !is null) {
if (!obj.swigCMemOwn)
throw new Exception("Cannot release ownership as memory is not owned");
void* ptr = obj.swigCPtr;
obj.swigCMemOwn = false;
obj.dispose();
return ptr;
} else {
return null;
}
}
mixin $imdmodule.SwigOperatorDefinitions;
%}
@ -92,6 +105,19 @@ public static void* swigGetCPtr(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr;
}
public static void* swigRelease(typeof(this) obj) {
if (obj !is null) {
if (!obj.swigCMemOwn)
throw new Exception("Cannot release ownership as memory is not owned");
void* ptr = obj.swigCPtr;
obj.swigCMemOwn = false;
obj.dispose();
return ptr;
} else {
return null;
}
}
mixin $imdmodule.SwigOperatorDefinitions;
%}
@ -100,7 +126,7 @@ mixin $imdmodule.SwigOperatorDefinitions;
* Type wrapper classes.
*/
%typemap(dbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{
%typemap(dbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] %{
private void* swigCPtr;
public this(void* cObject, bool futureUse) {
@ -115,6 +141,10 @@ public static void* swigGetCPtr(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr;
}
public static void* swigRelease(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr;
}
mixin $imdmodule.SwigOperatorDefinitions;
%}

View file

@ -12,7 +12,7 @@
#include <stdio.h>
/* Contract support. */
#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } else
#define SWIG_contract_assert(nullreturn, expr, msg) do { if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } } while (0)
%}

View file

@ -2,7 +2,7 @@
#define D_DKW_SWG_
/* Warnings for D keywords */
#define DKEYWORD(x) %keywordwarn("'" `x` "' is a D keyword, renaming to '_" `x` "'",rename="_%s") `x`
#define DKEYWORD(x) %keywordwarn("'" `x` "' is a D keyword",rename="_%s") `x`
// Source: http://www.digitalmars.com/d/{1.0,2.0}/lex.html and
DKEYWORD(Error);

View file

@ -20,6 +20,10 @@
%typemap(imtype) SWIGTYPE & "void*"
%typemap(dtype, nativepointer="$dtype") SWIGTYPE & "$dclassname"
%typemap(ctype) SWIGTYPE && "void *"
%typemap(imtype) SWIGTYPE && "void*"
%typemap(dtype, nativepointer="$dtype") SWIGTYPE && "$dclassname"
%typemap(ctype) SWIGTYPE *const& "void *"
%typemap(imtype) SWIGTYPE *const& "void*"
%typemap(dtype) SWIGTYPE *const& "$*dclassname"
@ -28,6 +32,7 @@
SWIGTYPE,
SWIGTYPE *,
SWIGTYPE &,
SWIGTYPE &&,
SWIGTYPE [],
SWIGTYPE *const&
""
@ -47,7 +52,7 @@
%typemap(out) SWIGTYPE
#ifdef __cplusplus
%{ $result = new $1_ltype((const $1_ltype &)$1); %}
%{ $result = new $1_ltype($1); %}
#else
{
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
@ -57,7 +62,7 @@
#endif
%typemap(directorin) SWIGTYPE
"$input = (void *)new $1_ltype((const $1_ltype &)$1);"
"$input = (void *)new $1_ltype(SWIG_STD_MOVE($1));"
%typemap(directorout) SWIGTYPE
%{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type");
@ -117,7 +122,7 @@
%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null");
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null");
return $null;
} %}
%typemap(out) SWIGTYPE & "$result = (void *)$1;"
@ -148,6 +153,44 @@
}
/*
* Rvalue reference conversion typemaps.
*/
%typemap(in, canthrow=1, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = ($1_ltype)$input;
if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null");
return $null;
}
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE && "$result = (void *)$1;"
%typemap(directorin) SWIGTYPE &&
"$input = ($1_ltype) &$1;"
%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE &&
%{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type");
return $null;
}
$result = ($1_ltype)$input; %}
%typemap(ddirectorin,
nativepointer="cast($dtype)$winput"
) SWIGTYPE && "new $dclassname($winput, false)"
%typemap(ddirectorout,
nativepointer="cast(void*)$dcall"
) SWIGTYPE && "$dclassname.swigGetCPtr($dcall)"
%typemap(din,
nativepointer="cast(void*)$dinput"
) SWIGTYPE && "$dclassname.swigRelease($dinput)"
%typemap(dout, excode=SWIGEXCODE,
nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}") SWIGTYPE && {
$dclassname ret = new $dclassname($imcall, $owner);$excode
return ret;
}
/*
* Array conversion typemaps.
*/
@ -164,6 +207,7 @@
// Treat references to arrays like references to a single element.
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) }
/*

42
Lib/d/std_auto_ptr.i Normal file
View file

@ -0,0 +1,42 @@
/* -----------------------------------------------------------------------------
* std_auto_ptr.i
*
* SWIG library file for handling std::auto_ptr.
* Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
* class when returning a std::auto_ptr from a function.
* Memory ownership is passed from the proxy class to the std::auto_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
%typemap (ctype) std::auto_ptr< TYPE > "void *"
%typemap (imtype) std::auto_ptr< TYPE > "void*"
%typemap (dtype) std::auto_ptr< TYPE > "$typemap(dtype, TYPE)"
%typemap(in) std::auto_ptr< TYPE >
%{ $1.reset((TYPE *)$input); %}
%typemap(din,
nativepointer="cast(void*)$dinput"
) std::auto_ptr< TYPE > "$typemap(dtype, TYPE).swigRelease($dinput)"
%typemap (out) std::auto_ptr< TYPE > %{
$result = (void *)$1.release();
%}
%typemap(dout, excode=SWIGEXCODE,
nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}"
) std::auto_ptr< TYPE > {
void* cPtr = $imcall;
$typemap(dtype, TYPE) ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *") std::auto_ptr< TYPE > ""
%template() std::auto_ptr< TYPE >;
%enddef
namespace std {
template <class T> class auto_ptr {};
}

42
Lib/d/std_unique_ptr.i Normal file
View file

@ -0,0 +1,42 @@
/* -----------------------------------------------------------------------------
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %unique_ptr(TYPE)
%typemap (ctype) std::unique_ptr< TYPE > "void *"
%typemap (imtype) std::unique_ptr< TYPE > "void*"
%typemap (dtype) std::unique_ptr< TYPE > "$typemap(dtype, TYPE)"
%typemap(in) std::unique_ptr< TYPE >
%{ $1.reset((TYPE *)$input); %}
%typemap(din,
nativepointer="cast(void*)$dinput"
) std::unique_ptr< TYPE > "$typemap(dtype, TYPE).swigRelease($dinput)"
%typemap (out) std::unique_ptr< TYPE > %{
$result = (void *)$1.release();
%}
%typemap(dout, excode=SWIGEXCODE,
nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}"
) std::unique_ptr< TYPE > {
void* cPtr = $imcall;
$typemap(dtype, TYPE) ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *") std::unique_ptr< TYPE > ""
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

16
Lib/d/swigmove.i Normal file
View file

@ -0,0 +1,16 @@
/* -----------------------------------------------------------------------------
* swigmove.i
*
* Input typemaps library for implementing full move semantics when passing
* parameters by value.
* ----------------------------------------------------------------------------- */
%typemap(in, canthrow=1) SWIGTYPE MOVE ($&1_type argp)
%{ argp = ($&1_ltype)$input;
if (!argp) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type");
return $null;
}
SwigValueWrapper< $1_ltype >::reset($1, argp); %}
%typemap(din) SWIGTYPE MOVE "$dclassname.swigRelease($dinput)"

View file

@ -14,14 +14,14 @@
#ifdef SWIGPHP
%{
#if PHP_MAJOR >= 8
# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8 code == SWIG_ValueError ? zend_ce_value_error :
#if PHP_MAJOR_VERSION >= 8
# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8(code) code == SWIG_ValueError ? zend_ce_value_error :
#else
# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8
# define SWIG_HANDLE_VALUE_ERROR_FOR_PHP8(code)
#endif
#define SWIG_exception(code, msg) do { zend_throw_exception( \
code == SWIG_TypeError ? zend_ce_type_error : \
SWIG_HANDLE_VALUE_ERROR_FOR_PHP8 \
SWIG_HANDLE_VALUE_ERROR_FOR_PHP8(code) \
code == SWIG_DivisionByZero ? zend_ce_division_by_zero_error : \
code == SWIG_SyntaxError ? zend_ce_parse_error : \
code == SWIG_OverflowError ? zend_ce_arithmetic_error : \

View file

@ -388,8 +388,9 @@
%typemap(gotype) SWIGTYPE &&
%{$gotypename%}
%typemap(in) SWIGTYPE &&
%{ $1 = *($&1_ltype)&$input; %}
%typemap(in, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter)
%{ $1 = *($&1_ltype)&$input;
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE &&
%{ *($&1_ltype)&$result = $1; %}
@ -453,9 +454,12 @@
%}
%typemap(freearg)
char *, char *&, char[ANY], char[]
char *, char[ANY], char[]
%{ free($1); %}
%typemap(freearg) char *&
%{ free(temp$argnum); %}
%typemap(out,fragment="AllocateString")
char *, char *&, char[ANY], char[]
%{ $result = Swig_AllocateString((char*)$1, $1 ? strlen((char*)$1) : 0); %}
@ -520,6 +524,44 @@
$2 = ($2_ltype)$input.n;
%}
/* The int & type needs to convert to intgo. */
%typemap(gotype) int & "*int"
%typemap(in) int & (int e)
%{
e = (int)*$input;
$1 = &e;
%}
%typemap(out) int &
%{ $result = new intgo(*$1); %}
%typemap(argout) int &
%{ *$input = (intgo)e$argnum; %}
%typemap(goout) int & ""
%typemap(directorin) int & (intgo e)
%{
e = (intgo)$1;
$input = &e;
%}
%typemap(godirectorin) int & ""
%typemap(directorout) int &
%{
$*1_ltype f = ($*1_ltype)*$input;
$result = ($1_ltype)&f;
%}
%typemap(directorargout) int &
%{ $1 = (int)*$input; %}
%typemap(argout) const int & ""
%typemap(directorargout) const int & ""
/* Enums. We can't do the right thing for enums in typemap(gotype) so
we deliberately don't define them. The right thing would be to
capitalize the name. This is instead done in go.cxx. */
@ -552,10 +594,7 @@
%typemap(godirectorin) enum SWIGTYPE & ""
%typemap(directorout) enum SWIGTYPE &
%{
$*1_ltype f = ($*1_ltype)*$input;
$result = ($1_ltype)&f;
%}
%{ $result = $input; %}
/* Arbitrary type. This is a type passed by value in the C/C++ code.
We convert it to a pointer for the Go code. Note that all basic
@ -587,7 +626,7 @@
%typemap(goout) SWIGTYPE ""
%typemap(directorin) SWIGTYPE
%{ $input = new $1_ltype((const $1_ltype &)$1); %}
%{ $input = new $1_ltype(SWIG_STD_MOVE($1)); %}
%typemap(godirectorin) SWIGTYPE ""

View file

@ -1,6 +1,6 @@
/* Rename keywords. */
#define GOKW(x) %keywordwarn("'" `x` "' is a Go keyword, renaming to 'X"`x`"'",rename="X%s") `x`
#define GOKW(x) %keywordwarn("'" `x` "' is a Go keyword",rename="X%s") `x`
#define GOBN(x) %builtinwarn("'" `x` "' conflicts with a built-in name in Go") "::"`x`
GOKW(break);

View file

@ -24,6 +24,7 @@ static void* Swig_malloc(int c) {
%}
%insert(cgo_comment_typedefs) %{
#include <stddef.h>
#include <stdint.h>
%}
@ -149,6 +150,17 @@ type _swig_fnptr *byte
type _swig_memberptr *byte
%}
/* Convert a Go interface value into a C++ pointer. */
%insert(go_header) %{
func getSwigcptr(v interface { Swigcptr() uintptr }) uintptr {
if v == nil {
return 0
}
return v.Swigcptr()
}
%}
/* For directors we need C++ to track a Go pointer. Since we can't
pass a Go pointer into C++, we use a map to track the pointers on
the Go side. */

43
Lib/go/std_array.i Normal file
View file

@ -0,0 +1,43 @@
/* -----------------------------------------------------------------------------
* std_array.i
* ----------------------------------------------------------------------------- */
%include <std_common.i>
namespace std {
template<class T, size_t N> class array {
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;
array();
array(const array& other);
size_type size() const;
%rename(isEmpty) empty;
bool empty() const;
void fill(const T& u);
%extend {
const_reference get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("array index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("array index out of range");
}
}
};
}

View file

@ -88,4 +88,69 @@ class string;
%typemap(godirectorin,fragment="CopyString") const string &
%{ $result = swigCopyString($input) %}
%typemap(gotype) string * "*string"
%typemap(in) string * (string temp)
%{
if ($input) {
temp.assign($input->p, $input->n);
$1 = &temp;
} else
$1 = 0;
%}
%typemap(godirectorout) string *
%{
if $input != nil {
p := Swig_malloc(len(*$input))
s := (*[1<<30]byte)(unsafe.Pointer(p))[:len(*$input)]
copy(s, *$input)
$result = (*string)(unsafe.Pointer(&s))
} else {
$result = nil
}
%}
%typemap(directorout) string * (string temp)
%{
temp.assign($input->p, $input->n);
$result = &temp;
free($input.p);
%}
%typemap(out,fragment="AllocateString") string * (_gostring_ temp)
%{
temp = Swig_AllocateString($1->data(), $1->length());
$result = &temp;
%}
%typemap(goout,fragment="CopyString") string *
%{ *$result = swigCopyString(*$1) %}
%typemap(directorin,fragment="AllocateString") string * (_gostring_ temp)
%{
if ($1) {
temp = Swig_AllocateString($1->data(), $1->length());
$input = &temp;
} else
$input = 0;
%}
%typemap(godirectorin,fragment="CopyString") string *
%{ *$result = swigCopyString(*$input); %}
%typemap(argout,fragment="AllocateString") string *
%{
if ($1)
*$input = Swig_AllocateString($1->data(), $1->length());
%}
%typemap(goargout,fragment="CopyString") string *
%{
if $input != nil {
*$1 = swigCopyString(*$input)
}
%}
}

15
Lib/go/swigmove.i Normal file
View file

@ -0,0 +1,15 @@
/* -----------------------------------------------------------------------------
* swigmove.i
*
* Input typemaps library for implementing full move semantics when passing
* parameters by value.
* ----------------------------------------------------------------------------- */
%typemap(in) SWIGTYPE MOVE ($&1_type argp)
%{
argp = ($&1_ltype)$input;
if (argp == NULL) {
_swig_gopanic("Attempt to dereference null $1_type");
}
SwigValueWrapper< $1_ltype >::reset($1, argp);
%}

View file

@ -2,6 +2,12 @@
* guile_scm_run.swg
* ----------------------------------------------------------------------------- */
#if __GNUC__ >= 10
#if defined(__cplusplus)
#pragma GCC diagnostic ignored "-Wvolatile" /* For 'volatile SCM *' in at least Guile 3.0 and earlier */
#endif
#endif
#include <libguile.h>
#include <stdio.h>
#include <string.h>
@ -65,10 +71,12 @@ typedef struct swig_guile_clientdata {
#define SWIG_IsPointer(object) \
SWIG_Guile_IsPointer(object)
#define SWIG_contract_assert(expr, msg) \
if (!(expr)) \
scm_error(scm_from_locale_symbol("swig-contract-assertion-failed"), \
(char *) FUNC_NAME, (char *) msg, \
SCM_EOL, SCM_BOOL_F); else
do { \
if (!(expr)) \
scm_error(scm_from_locale_symbol("swig-contract-assertion-failed"), \
(char *) FUNC_NAME, (char *) msg, \
SCM_EOL, SCM_BOOL_F); \
} while (0)
/* for C++ member pointers, ie, member methods */
#define SWIG_ConvertMember(obj, ptr, sz, ty) \
@ -110,6 +118,8 @@ static SCM swig_symbol = SCM_EOL;
( !scm_is_null(x) && SCM_INSTANCEP(x) && scm_is_true(scm_slot_exists_p(x, swig_symbol)) \
? scm_slot_ref(x, swig_symbol) : (x) )
SWIGINTERN void SWIG_Guile_MarkPointerNoncollectable(SCM s);
SWIGINTERN SCM
SWIG_Guile_NewPointerObj(void *ptr, swig_type_info *type, int owner)
{
@ -123,7 +133,7 @@ SWIG_Guile_NewPointerObj(void *ptr, swig_type_info *type, int owner)
else
SCM_NEWSMOB2(smob, swig_tag, ptr, (void *) type);
if (!cdata || SCM_NULLP(cdata->goops_class) || swig_make_func == SCM_EOL ) {
if (!cdata || scm_is_null(cdata->goops_class) || swig_make_func == SCM_EOL ) {
return smob;
} else {
/* the scm_make() C function only handles the creation of gf,
@ -143,7 +153,7 @@ SWIGINTERN unsigned long
SWIG_Guile_PointerAddress(SCM object)
{
SCM smob = SWIG_Guile_GetSmob(object);
if (SCM_NULLP(smob)) return 0;
if (scm_is_null(smob)) return 0;
else if (SCM_SMOB_PREDICATE(swig_tag, smob)
|| SCM_SMOB_PREDICATE(swig_collectable_tag, smob)
|| SCM_SMOB_PREDICATE(swig_destroyed_tag, smob)) {
@ -156,7 +166,7 @@ SWIGINTERN swig_type_info *
SWIG_Guile_PointerType(SCM object)
{
SCM smob = SWIG_Guile_GetSmob(object);
if (SCM_NULLP(smob)) return NULL;
if (scm_is_null(smob)) return NULL;
else if (SCM_SMOB_PREDICATE(swig_tag, smob)
|| SCM_SMOB_PREDICATE(swig_collectable_tag, smob)
|| SCM_SMOB_PREDICATE(swig_destroyed_tag, smob)) {
@ -183,8 +193,9 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
swig_cast_info *cast;
swig_type_info *from;
SCM smob = SWIG_Guile_GetSmob(s);
int ret = SWIG_ERROR;
if (SCM_NULLP(smob)) {
if (scm_is_null(smob)) {
*result = NULL;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
#if SCM_MAJOR_VERSION >= 2
@ -195,22 +206,36 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
} else if (SWIG_Guile_IsValidSmob(smob)) {
from = (swig_type_info *) SCM_CELL_WORD_2(smob);
if (!from) return SWIG_ERROR;
if ((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) {
if ((SCM_CELL_TYPE(smob) == swig_collectable_tag && SCM_CELL_WORD_1(smob) == 0) || SCM_CELL_TYPE(smob) == swig_tag) {
return SWIG_ERROR_RELEASE_NOT_OWNED;
}
}
if (type) {
cast = SWIG_TypeCheckStruct(from, type);
if (cast) {
int newmemory = 0;
*result = SWIG_TypeCast(cast, (void *) SCM_CELL_WORD_1(smob), &newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */
return SWIG_OK;
ret = SWIG_OK;
} else {
return SWIG_ERROR;
}
} else {
*result = (void *) SCM_CELL_WORD_1(smob);
return SWIG_OK;
ret = SWIG_OK;
}
if (flags & SWIG_POINTER_DISOWN) {
SWIG_Guile_MarkPointerNoncollectable(smob);
}
if (flags & SWIG_POINTER_CLEAR) {
SCM_SET_CELL_WORD_1(smob, 0);
}
}
return SWIG_ERROR;
return ret;
}
SWIGINTERNINLINE void *
@ -250,7 +275,7 @@ SWIGINTERN void
SWIG_Guile_MarkPointerNoncollectable(SCM s)
{
SCM smob = SWIG_Guile_GetSmob(s);
if (!SCM_NULLP(smob)) {
if (!scm_is_null(smob)) {
if (SWIG_Guile_IsValidSmob(smob)) {
SCM_SET_CELL_TYPE(smob, swig_tag);
}
@ -263,7 +288,7 @@ SWIGINTERN void
SWIG_Guile_MarkPointerDestroyed(SCM s)
{
SCM smob = SWIG_Guile_GetSmob(s);
if (!SCM_NULLP(smob)) {
if (!scm_is_null(smob)) {
if (SWIG_Guile_IsValidSmob(smob)) {
SCM_SET_CELL_TYPE(smob, swig_destroyed_tag);
}
@ -484,20 +509,20 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest,
int i;
int num_args_passed = 0;
for (i = 0; i<reqargs; i++) {
if (!SCM_CONSP(rest))
if (!scm_is_pair(rest))
scm_wrong_num_args(scm_from_utf8_string(procname ? (char *) procname : "unknown procedure"));
*dest++ = SCM_CAR(rest);
rest = SCM_CDR(rest);
num_args_passed++;
}
for (i = 0; i<optargs && SCM_CONSP(rest); i++) {
for (i = 0; i<optargs && scm_is_pair(rest); i++) {
*dest++ = SCM_CAR(rest);
rest = SCM_CDR(rest);
num_args_passed++;
}
for (; i<optargs; i++)
*dest++ = SCM_UNDEFINED;
if (!SCM_NULLP(rest))
if (!scm_is_null(rest))
scm_wrong_num_args(scm_from_utf8_string(procname ? (char *) procname : "unknown procedure"));
return num_args_passed;
}

View file

@ -107,7 +107,7 @@
(size_t VECTORLENINPUT, C_TYPE *VECTORINPUT),
(int LISTLENINPUT, C_TYPE *LISTINPUT),
(size_t LISTLENINPUT, C_TYPE *LISTINPUT)
{if ($2!=NULL) SWIG_free($2);}
{SWIG_free($2);}
%enddef
@ -173,7 +173,7 @@
(int *LISTLENOUTPUT, C_TYPE **LISTOUTPUT),
(size_t *LISTLENOUTPUT, C_TYPE **LISTOUTPUT)
{
if ((*$2)!=NULL) free(*$2);
free(*$2);
}
%enddef
@ -231,7 +231,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, stri
if ((*$2)!=NULL) {
int i;
for (i = 0; i < *$1; i++) {
if ((*$2)[i] != NULL) free((*$2)[i]);
free((*$2)[i]);
}
free(*$2);
}
@ -249,7 +249,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, stri
if (($2)!=NULL) {
int i;
for (i = 0; i< $1; i++)
if (($2)[i] != NULL) free(($2)[i]);
free(($2)[i]);
free($2);
}
}
@ -360,7 +360,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, stri
const C_TYPE *PARALLEL_VECTORINPUT,
C_TYPE *PARALLEL_LISTINPUT,
const C_TYPE *PARALLEL_LISTINPUT
{if ($1!=NULL) SWIG_free($1);}
{SWIG_free($1);}
%enddef
@ -422,7 +422,7 @@ TYPEMAP_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02scm, stri
%typemap(freearg) C_TYPE **PARALLEL_VECTOROUTPUT,
C_TYPE **PARALLEL_LISTOUTPUT
{
if ((*$1)!=NULL) free(*$1);
free(*$1);
}
%enddef
@ -471,7 +471,7 @@ TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02
if (($1)!=NULL) {
int i;
for (i = 0; i<*_global_list_length; i++)
if (($1)[i] != NULL) SWIG_free(($1)[i]);
SWIG_free(($1)[i]);
SWIG_free($1);
}
}
@ -482,7 +482,7 @@ TYPEMAP_PARALLEL_LIST_VECTOR_INPUT_OUTPUT(const char *, SWIG_scm2str, SWIG_str02
if ((*$1)!=NULL) {
int i;
for (i = 0; i<_global_arraylentemp; i++)
if ((*$1)[i] != NULL) free((*$1)[i]);
free((*$1)[i]);
free(*$1);
}
}

39
Lib/guile/std_auto_ptr.i Normal file
View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_auto_ptr.i
*
* SWIG library file for handling std::auto_ptr.
* Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
* class when returning a std::auto_ptr from a function.
* Memory ownership is passed from the proxy class to the std::auto_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
%typemap(in, noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
scm_misc_error(FUNC_NAME, "Cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *'", SCM_EOL);
} else {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::auto_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN));
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::auto_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::auto_ptr< TYPE >;
%enddef
namespace std {
template <class T> class auto_ptr {};
}

View file

@ -19,7 +19,7 @@ std::string SWIG_scm2string(SCM x) {
char* temp;
temp = SWIG_scm2str(x);
std::string s(temp);
if (temp) SWIG_free(temp);
SWIG_free(temp);
return s;
}
%}

View file

@ -30,7 +30,7 @@ namespace std {
if (scm_is_string($input)) {
tempptr = SWIG_scm2str($input);
$1.assign(tempptr);
if (tempptr) SWIG_free(tempptr);
SWIG_free(tempptr);
} else {
SWIG_exception(SWIG_TypeError, "string expected");
}
@ -40,7 +40,7 @@ namespace std {
if (scm_is_string($input)) {
tempptr = SWIG_scm2str($input);
temp.assign(tempptr);
if (tempptr) SWIG_free(tempptr);
SWIG_free(tempptr);
$1 = &temp;
} else {
SWIG_exception(SWIG_TypeError, "string expected");
@ -51,7 +51,7 @@ namespace std {
if (scm_is_string($input)) {
tempptr = SWIG_scm2str($input);
$1 = new $*1_ltype(tempptr);
if (tempptr) SWIG_free(tempptr);
SWIG_free(tempptr);
} else {
SWIG_exception(SWIG_TypeError, "string expected");
}
@ -73,7 +73,7 @@ namespace std {
if (scm_is_string($input)) {
char *tempptr = SWIG_scm2str($input);
$1.assign(tempptr);
if (tempptr) SWIG_free(tempptr);
SWIG_free(tempptr);
} else {
SWIG_exception(SWIG_TypeError, "string expected");
}

View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
scm_misc_error(FUNC_NAME, "Cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *'", SCM_EOL);
} else {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN));
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::unique_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

19
Lib/guile/swigmove.i Normal file
View file

@ -0,0 +1,19 @@
/* -----------------------------------------------------------------------------
* swigmove.i
*
* Input typemaps library for implementing full move semantics when passing
* parameters by value.
* ----------------------------------------------------------------------------- */
%typemap(in, noblock=1) SWIGTYPE MOVE (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $&1_descriptor, SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
%releasenotowned_fail(res, "$1_type", $symname, $argnum);
} else {
%argument_fail(res, "$1_type", $symname, $argnum);
}
}
if (!argp) { %argument_nullref("$1_type", $symname, $argnum); }
SwigValueWrapper< $1_ltype >::reset($1, ($&1_type)argp);
}

View file

@ -4,8 +4,6 @@
#ifdef SWIGGUILE_SCM
/* Hook the runtime module initialization
into the shared initialization function SWIG_Guile_Init. */
%runtime %{
/* Hook the runtime module initialization
into the shared initialization function SWIG_Guile_Init. */

View file

@ -4,17 +4,43 @@
* Guile-specific typemaps
* ----------------------------------------------------------------------------- */
/* These are defined with a view to eventually merging with those defined for other target languages in swigtypemaps.swg and exception.swg */
#define %set_output(obj) $result = obj
#define %set_varoutput(obj) $result = obj
#define %argument_fail(_code, _type, _name, _argn) scm_wrong_type_arg((char *) FUNC_NAME, _argn, $input)
#define %as_voidptr(ptr) (void*)(ptr)
#define %argument_nullref(_type, _name, _argn) scm_misc_error(FUNC_NAME, "invalid null reference for argument " #_argn " of type '" _type "'", SCM_EOL)
#define %releasenotowned_fail(_code, _type, _name, _argn) scm_misc_error(FUNC_NAME, "cannot release ownership as memory is not owned for argument " #_argn " of type '" _type "'", SCM_EOL)
/* Pointers */
%typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] {
%typemap(in) SWIGTYPE *, SWIGTYPE [] {
$1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0);
}
%typemap(freearg) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "";
%typemap(in) SWIGTYPE & ($1_ltype argp) {
argp = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0);
if (!argp) { %argument_nullref("$1_type", $symname, $argnum); }
$1 = argp;
}
%typemap(in, noblock=1, fragment="<memory>") SWIGTYPE && (void *argp = 0, int res = 0, std::unique_ptr<$*1_ltype> rvrdeleter) {
res = SWIG_ConvertPtr($input, &argp, $descriptor, SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
%releasenotowned_fail(res, "$1_type", $symname, $argnum);
} else {
%argument_fail(res, "$1_type", $symname, $argnum);
}
}
if (!argp) { %argument_nullref("$1_type", $symname, $argnum); }
$1 = ($1_ltype)argp;
rvrdeleter.reset($1);
}
%typemap(freearg) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] ""
%typemap(in) void * {
$1 = ($1_ltype)SWIG_MustGetPtr($input, NULL, $argnum, 0);
}
%typemap(freearg) void * "";
%typemap(freearg) void * ""
%typemap(varin) SWIGTYPE * {
$1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0);
@ -115,8 +141,9 @@
/* Pass-by-value */
%typemap(in) SWIGTYPE($&1_ltype argp) {
%typemap(in) SWIGTYPE ($&1_ltype argp) {
argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0);
if (!argp) { %argument_nullref("$1_type", $symname, $argnum); }
$1 = *argp;
}
@ -130,7 +157,7 @@
#ifdef __cplusplus
{
$&1_ltype resultptr;
resultptr = new $1_ltype((const $1_ltype &) $1);
resultptr = new $1_ltype($1);
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1);
}
#else
@ -145,8 +172,7 @@
%typemap(varout) SWIGTYPE
#ifdef __cplusplus
{
$&1_ltype resultptr;
resultptr = new $1_ltype((const $1_ltype&) $1);
$&1_ltype resultptr = ($&1_ltype)&$1;
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0);
}
#else
@ -322,19 +348,19 @@ SIMPLE_MAP(unsigned long long, scm_to_ulong_long, scm_from_ulong_long, integer);
/* SWIG_scm2str makes a malloc'ed copy of the string, so get rid of it after
the function call. */
%typemap (freearg) char * "if (must_free$argnum && $1) SWIG_free($1);";
%typemap (freearg) char **INPUT, char **BOTH "if (must_free$argnum && (*$1)) SWIG_free(*$1);"
%typemap (freearg) char * "if (must_free$argnum) SWIG_free($1);"
%typemap (freearg) char **INPUT, char **BOTH "if (must_free$argnum) SWIG_free(*$1);"
%typemap (freearg) char **OUTPUT "SWIG_free(*$1);"
/* But this shall not apply if we try to pass a single char by
reference. */
%typemap (freearg) char *OUTPUT, char *BOTH "";
%typemap (freearg) char *OUTPUT, char *BOTH ""
/* If we set a string variable, delete the old result first, unless const. */
%typemap (varin) char * {
if ($1) free($1);
free($1);
$1 = ($1_ltype) SWIG_scm2str($input);
}
@ -349,13 +375,13 @@ SIMPLE_MAP(unsigned long long, scm_to_ulong_long, scm_from_ulong_long, integer);
/* Void */
%typemap (out,doc="") void "gswig_result = SCM_UNSPECIFIED;";
%typemap (out,doc="") void "gswig_result = SCM_UNSPECIFIED;"
/* SCM is passed through */
typedef unsigned long SCM;
%typemap (in) SCM "$1=$input;";
%typemap (out) SCM "$result=$1;";
%typemap (in) SCM "$1=$input;"
%typemap (out) SCM "$result=$1;"
%typecheck(SWIG_TYPECHECK_POINTER) SCM "$1=1;";
/* ------------------------------------------------------------
@ -373,11 +399,6 @@ typedef unsigned long SCM;
* taken from typemaps/swigtype.swg
* ------------------------------------------------------------ */
#define %set_output(obj) $result = obj
#define %set_varoutput(obj) $result = obj
#define %argument_fail(code, type, name, argn) scm_wrong_type_arg((char *) FUNC_NAME, argn, $input);
#define %as_voidptr(ptr) (void*)(ptr)
%typemap(in) SWIGTYPE (CLASS::*) {
int res = SWIG_ConvertMember($input, %as_voidptr(&$1), sizeof($1), $descriptor);
if (!SWIG_IsOK(res)) {
@ -426,7 +447,7 @@ typedef unsigned long SCM;
%typecheck(SWIG_TYPECHECK_BOOL)
bool, bool&, const bool&
{
$1 = SCM_BOOLP($input) ? 1 : 0;
$1 = scm_is_bool($input) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_DOUBLE)

View file

@ -33,7 +33,7 @@
%}
%typemap(out, fragment="SWIG_intrusive_deleter") CONST TYPE %{
//plain value(out)
$1_ltype* resultp = new $1_ltype(($1_ltype &)$1);
$1_ltype* resultp = new $1_ltype($1);
intrusive_ptr_add_ref(resultp);
*(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(resultp, SWIG_intrusive_deleter< CONST TYPE >());
%}
@ -342,7 +342,7 @@
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype($1)); %}
// plain pointer
%typemap(in) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{

View file

@ -29,11 +29,11 @@
}
$1 = *argp; %}
%typemap(out) CONST TYPE
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
%{ *(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype($1)); %}
%typemap(directorin,descriptor="L$packagepath/$&javaclassname;") CONST TYPE
%{ $input = 0;
*((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype((const $1_ltype &)$1)); %}
*((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > **)&$input) = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype(SWIG_STD_MOVE($1))); %}
%typemap(directorout) CONST TYPE
%{ if (!$input) {

View file

@ -51,6 +51,10 @@ SWIGINTERN int Swig::GetThreadName(char *name, size_t len) {
#endif
#if defined(SWIG_JAVA_DETACH_ON_THREAD_END)
#include <pthread.h>
#endif
namespace Swig {
/* Java object wrapper */
@ -133,6 +137,19 @@ namespace Swig {
}
}
#if defined(SWIG_JAVA_DETACH_ON_THREAD_END)
static void detach(void *jvm) {
static_cast<JavaVM *>(jvm)->DetachCurrentThread();
}
static void make_detach_key() {
pthread_key_create(&detach_key_, detach);
}
/* thread-local key to register a destructor */
static pthread_key_t detach_key_;
#endif
private:
/* pointer to Java object */
jobject jthis_;
@ -140,6 +157,10 @@ namespace Swig {
bool weak_global_;
};
#if defined(SWIG_JAVA_DETACH_ON_THREAD_END)
pthread_key_t JObjectWrapper::detach_key_;
#endif
/* Local JNI reference deleter */
class LocalRefGuard {
JNIEnv *jenv_;
@ -201,9 +222,19 @@ namespace Swig {
#else
director_->swig_jvm_->AttachCurrentThread(jenv, &args);
#endif
#if defined(SWIG_JAVA_DETACH_ON_THREAD_END)
// At least on Android 6, detaching after every call causes a memory leak.
// Instead, register a thread desructor and detach only when the thread ends.
// See https://developer.android.com/training/articles/perf-jni#threads
static pthread_once_t once = PTHREAD_ONCE_INIT;
pthread_once(&once, JObjectWrapper::make_detach_key);
pthread_setspecific(JObjectWrapper::detach_key_, director->swig_jvm_);
#endif
}
~JNIEnvWrapper() {
#if !defined(SWIG_JAVA_NO_DETACH_CURRENT_THREAD)
#if !defined(SWIG_JAVA_DETACH_ON_THREAD_END) && !defined(SWIG_JAVA_NO_DETACH_CURRENT_THREAD)
// Some JVMs, eg jdk-1.4.2 and lower on Solaris have a bug and crash with the DetachCurrentThread call.
// However, without this call, the JVM hangs on exit when the thread was not created by the JVM and creates a memory leak.
if (env_status == JNI_EDETACHED)

View file

@ -665,7 +665,7 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
%typemap(out) SWIGTYPE
#ifdef __cplusplus
%{ *($&1_ltype*)&$result = new $1_ltype((const $1_ltype &)$1); %}
%{ *($&1_ltype*)&$result = new $1_ltype($1); %}
#else
{
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
@ -676,7 +676,7 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
%typemap(directorin,descriptor="L$packagepath/$&javaclassname;") SWIGTYPE
%{ $input = 0;
*(($&1_ltype*)&$input) = new $1_ltype((const $1_ltype &)$1); %}
*(($&1_ltype*)&$input) = new $1_ltype(SWIG_STD_MOVE($1)); %}
%typemap(javadirectorin) SWIGTYPE "new $&javaclassname($jniinput, true)"
%typemap(javadirectorout) SWIGTYPE "$&javaclassname.getCPtr($javacall)"
@ -692,14 +692,15 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
}
%typemap(in) SWIGTYPE & %{ $1 = *($&1_ltype)&$input;
if (!$1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type is null");
return $null;
} %}
%typemap(in) SWIGTYPE && %{ $1 = *($&1_ltype)&$input;
%typemap(in, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = *($&1_ltype)&$input;
if (!$1) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type is null");
return $null;
} %}
}
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE *
%{ *($&1_ltype)&$result = $1; %}
%typemap(out, fragment="SWIG_PackData", noblock=1) SWIGTYPE (CLASS::*) {
@ -1101,7 +1102,8 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
jobjectArray
"$javainput"
%typemap(javain) SWIGTYPE "$&javaclassname.getCPtr($javainput)"
%typemap(javain) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] "$javaclassname.getCPtr($javainput)"
%typemap(javain) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$javaclassname.getCPtr($javainput)"
%typemap(javain) SWIGTYPE && "$javaclassname.swigRelease($javainput)"
%typemap(javain) SWIGTYPE (CLASS::*) "$javaclassname.getCMemberPtr($javainput)"
/* The javaout typemap is used for converting function return types from the return type
@ -1216,6 +1218,18 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
CPTR_VISIBILITY static long swigRelease($javaclassname obj) {
long ptr = 0;
if (obj != null) {
if (!obj.swigCMemOwn)
throw new RuntimeException("Cannot release ownership as memory is not owned");
ptr = obj.swigCPtr;
obj.swigCMemOwn = false;
obj.delete();
}
return ptr;
}
%}
// Derived proxy classes
@ -1230,6 +1244,18 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
CPTR_VISIBILITY static long swigRelease($javaclassname obj) {
long ptr = 0;
if (obj != null) {
if (!obj.swigCMemOwn)
throw new RuntimeException("Cannot release ownership as memory is not owned");
ptr = obj.swigCPtr;
obj.swigCMemOwn = false;
obj.delete();
}
return ptr;
}
%}
%enddef
@ -1249,6 +1275,10 @@ Swig::LocalRefGuard $1_refguard(jenv, $input); }
CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
CPTR_VISIBILITY static long swigRelease($javaclassname obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
%}
%typemap(javabody) TYPE (CLASS::*) %{

View file

@ -87,5 +87,5 @@ static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionC
%insert(runtime) %{
/* Contract support */
#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
#define SWIG_contract_assert(nullreturn, expr, msg) do { if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } } while (0)
%}

View file

@ -2,7 +2,7 @@
#define JAVA_JAVAKW_SWG_
/* Warnings for Java keywords */
#define JAVAKW(x) %keywordwarn("'" `x` "' is a java keyword, renaming to '_"`x`"'",rename="_%s") `x`
#define JAVAKW(x) %keywordwarn("'" `x` "' is a java keyword",rename="_%s") `x`
/*
from

View file

@ -1,27 +1,41 @@
/*
The typemaps here allow handling functions returning std::auto_ptr<>,
which is the most common use of this type. If you have functions taking it
as parameter, these typemaps can't be used for them and you need to do
something else (e.g. use shared_ptr<> which SWIG supports fully).
*/
/* -----------------------------------------------------------------------------
* std_auto_ptr.i
*
* SWIG library file for handling std::auto_ptr.
* Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
* class when returning a std::auto_ptr from a function.
* Memory ownership is passed from the proxy class to the std::auto_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
%typemap (jni) std::auto_ptr<TYPE > "jlong"
%typemap (jtype) std::auto_ptr<TYPE > "long"
%typemap (jstype) std::auto_ptr<TYPE > "$typemap(jstype, TYPE)"
%typemap (out) std::auto_ptr<TYPE > %{
jlong lpp = 0;
*(TYPE**) &lpp = $1.release();
$result = lpp;
%typemap (jni) std::auto_ptr< TYPE > "jlong"
%typemap (jtype) std::auto_ptr< TYPE > "long"
%typemap (jstype) std::auto_ptr< TYPE > "$typemap(jstype, TYPE)"
%typemap(in) std::auto_ptr< TYPE > (TYPE *auto_temp)
%{ auto_temp = *(TYPE **)&$input;
$1.reset(auto_temp); %}
%typemap(javain) std::auto_ptr< TYPE > "$typemap(jstype, TYPE).swigRelease($javainput)"
%typemap (out) std::auto_ptr< TYPE > %{
jlong lpp = 0;
*(TYPE **) &lpp = $1.release();
$result = lpp;
%}
%typemap(javaout) std::auto_ptr<TYPE > {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%template() std::auto_ptr<TYPE >;
%typemap(javaout) std::auto_ptr< TYPE > {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *") std::auto_ptr< TYPE > ""
%template() std::auto_ptr< TYPE >;
%enddef
namespace std {
template <class T> class auto_ptr {};
}
template <class T> class auto_ptr {};
}

41
Lib/java/std_unique_ptr.i Normal file
View file

@ -0,0 +1,41 @@
/* -----------------------------------------------------------------------------
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %unique_ptr(TYPE)
%typemap (jni) std::unique_ptr< TYPE > "jlong"
%typemap (jtype) std::unique_ptr< TYPE > "long"
%typemap (jstype) std::unique_ptr< TYPE > "$typemap(jstype, TYPE)"
%typemap(in) std::unique_ptr< TYPE > (TYPE *unique_temp)
%{ unique_temp = *(TYPE **)&$input;
$1.reset(unique_temp); %}
%typemap(javain) std::unique_ptr< TYPE > "$typemap(jstype, TYPE).swigRelease($javainput)"
%typemap (out) std::unique_ptr< TYPE > %{
jlong lpp = 0;
*(TYPE **) &lpp = $1.release();
$result = lpp;
%}
%typemap(javaout) std::unique_ptr< TYPE > {
long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true);
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *") std::unique_ptr< TYPE > ""
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View file

@ -60,7 +60,7 @@ class wstring;
%}
%typemap(directorin,descriptor="Ljava/lang/String;") wstring %{
jsize $1_len = $1.length();
jsize $1_len = (jsize)$1.length();
jchar *$1_conv_buf = new jchar[$1_len];
for (jsize i = 0; i < $1_len; ++i) {
$1_conv_buf[i] = (jchar)$1[i];
@ -71,7 +71,7 @@ class wstring;
%}
%typemap(out) wstring
%{jsize $1_len = $1.length();
%{jsize $1_len = (jsize)$1.length();
jchar *conv_buf = new jchar[$1_len];
for (jsize i = 0; i < $1_len; ++i) {
conv_buf[i] = (jchar)$1[i];
@ -88,9 +88,12 @@ class wstring;
//%typemap(typecheck) wstring = wchar_t *;
%typemap(throws) wstring
%{ std::string message($1.begin(), $1.end());
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
return $null; %}
%{std::string message($1.size(), '\0');
for (size_t i = 0; i < $1.size(); ++i) {
message[i] = (char)$1[i];
}
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
return $null; %}
// const wstring &
%typemap(jni) const wstring & "jstring"
@ -138,7 +141,7 @@ class wstring;
jenv->ReleaseStringChars($input, $1_pstr); %}
%typemap(directorin,descriptor="Ljava/lang/String;") const wstring & %{
jsize $1_len = $1.length();
jsize $1_len = (jsize)$1.length();
jchar *$1_conv_buf = new jchar[$1_len];
for (jsize i = 0; i < $1_len; ++i) {
$1_conv_buf[i] = (jchar)($1)[i];
@ -149,7 +152,7 @@ class wstring;
%}
%typemap(out) const wstring &
%{jsize $1_len = $1->length();
%{jsize $1_len = (jsize)$1->length();
jchar *conv_buf = new jchar[$1_len];
for (jsize i = 0; i < $1_len; ++i) {
conv_buf[i] = (jchar)(*$1)[i];
@ -166,9 +169,12 @@ class wstring;
//%typemap(typecheck) const wstring & = wchar_t *;
%typemap(throws) const wstring &
%{ std::string message($1.begin(), $1.end());
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
return $null; %}
%{std::string message($1.size(), '\0');
for (size_t i = 0; i < $1.size(); ++i) {
message[i] = (char)$1[i];
}
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
return $null; %}
}

View file

@ -40,7 +40,7 @@
%typemap(javadirectorout) CTYPE *const& "$javacall.$*interfacename_GetInterfaceCPtr()"
%typemap(directorin,descriptor="L$packagepath/$&javainterfacename;") CTYPE
%{ $input = 0;
*(($&1_ltype*)&$input) = new $1_ltype((const $1_ltype &)$1); %}
*(($&1_ltype*)&$input) = new $1_ltype(SWIG_STD_MOVE($1)); %}
%typemap(directorin,descriptor="L$packagepath/$javainterfacename;") CTYPE *, CTYPE []
%{ *(($&1_ltype)&$input) = ($1_ltype) $1; %}
%typemap(directorin,descriptor="L$packagepath/$javainterfacename;") CTYPE &

16
Lib/java/swigmove.i Normal file
View file

@ -0,0 +1,16 @@
/* -----------------------------------------------------------------------------
* swigmove.i
*
* Input typemaps library for implementing full move semantics when passing
* parameters by value.
* ----------------------------------------------------------------------------- */
%typemap(in) SWIGTYPE MOVE ($&1_type argp)
%{ argp = *($&1_ltype*)&$input;
if (!argp) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
return $null;
}
SwigValueWrapper< $1_ltype >::reset($1, argp); %}
%typemap(javain) SWIGTYPE MOVE "$&javaclassname.swigRelease($javainput)"

View file

@ -122,7 +122,7 @@ SWIGRUNTIME int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef ob
}
assert(ptr);
*ptr = NULL;
if (cdata->info == info) {
if (!info || cdata->info == info) {
*ptr = cdata->swigCObject;
} else {
swig_cast_info *tc = SWIG_TypeCheckStruct(cdata->info, info);
@ -135,8 +135,15 @@ SWIGRUNTIME int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef ob
}
}
if (flags & SWIG_POINTER_DISOWN) {
cdata->swigCMemOwn = false;
if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !cdata->swigCMemOwn) {
return SWIG_ERROR_RELEASE_NOT_OWNED;
} else {
if (flags & SWIG_POINTER_DISOWN) {
cdata->swigCMemOwn = false;
}
if (flags & SWIG_POINTER_CLEAR) {
cdata->swigCObject = 0;
}
}
return SWIG_OK;

View file

@ -75,6 +75,7 @@ SWIG_JSC_FromCharPtrAndSize(JSContextRef context, const char* carray, size_t siz
}
%define %_typemap2_string(StringCode, CharCode,
WarningLeakMsg,
Char, CharName,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize,
@ -166,6 +167,7 @@ SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val)
%_typemap_string(StringCode,
Char,
WarningLeakMsg,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize,
SWIG_CharPtrLen,

View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_auto_ptr.i
*
* SWIG library file for handling std::auto_ptr.
* Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
* class when returning a std::auto_ptr from a function.
* Memory ownership is passed from the proxy class to the std::auto_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
%typemap(in, noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
%releasenotowned_fail(res, "TYPE *", $symname, $argnum);
} else {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::auto_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::auto_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::auto_ptr< TYPE >;
%enddef
namespace std {
template <class T> class auto_ptr {};
}

View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
%releasenotowned_fail(res, "TYPE *", $symname, $argnum);
} else {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::unique_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View file

@ -0,0 +1 @@
%include <typemaps/swigmove.swg>

View file

@ -72,7 +72,7 @@ multiple output values, they are returned in the form of a Python tuple.
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:
returns the integer part in one of its parameters) :
double modf(double x, double *ip);

View file

@ -105,17 +105,10 @@ fail:
%{
if(args.Length() == $jsargcount) {
errorHandler.err.Clear();
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
self = $jswrapper(args, errorHandler);
if(errorHandler.err.IsEmpty()) {
SWIGV8_ESCAPE(self);
}
#else
$jswrapper(args, errorHandler);
if(errorHandler.err.IsEmpty()) {
return;
}
#endif
}
%}
@ -127,22 +120,8 @@ fail:
%fragment ("js_dtor", "templates")
%{
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
static void $jswrapper(v8::Persistent< v8::Value > object, void *parameter) {
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
static void $jswrapper(v8::Isolate *isolate, v8::Persistent<v8::Value> object, void *parameter) {
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
static void $jswrapper(v8::Isolate *isolate, v8::Persistent<v8::Object> *object, SWIGV8_Proxy *proxy) {
#elif (V8_MAJOR_VERSION-0) < 5
static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data) {
v8::Local<v8::Object> object = data.GetValue();
static void $jswrapper(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
SWIGV8_Proxy *proxy = data.GetParameter();
#else
static void $jswrapper(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
SWIGV8_Proxy *proxy = data.GetParameter();
#endif
if(proxy->swigCMemOwn && proxy->swigCObject) {
#ifdef SWIGRUNTIME_DEBUG
@ -151,20 +130,6 @@ static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &dat
$jsfree proxy->swigCObject;
}
delete proxy;
#if (V8_MAJOR_VERSION-0) < 5
object.Clear();
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
object.Dispose();
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
object.Dispose(isolate);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100)
object->Dispose(isolate);
#elif (V8_MAJOR_VERSION-0) < 5
object->Dispose();
#endif
}
%}
@ -176,40 +141,14 @@ static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &dat
* ----------------------------------------------------------------------------- */
%fragment ("js_dtoroverride", "templates")
%{
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
static void $jswrapper(v8::Persistent<v8::Value> object, void *parameter) {
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
static void $jswrapper(v8::Isolate *isolate, v8::Persistent<v8::Value> object, void *parameter) {
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
static void $jswrapper(v8::Isolate *isolate, v8::Persistent< v8::Object> *object, SWIGV8_Proxy *proxy) {
#elif (V8_MAJOR_VERSION-0) < 5
static void $jswrapper(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data) {
v8::Local<v8::Object> object = data.GetValue();
SWIGV8_Proxy *proxy = data.GetParameter();
#else
static void $jswrapper(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
SWIGV8_Proxy *proxy = data.GetParameter();
#endif
if(proxy->swigCMemOwn && proxy->swigCObject) {
$jstype arg1 = ($jstype)proxy->swigCObject;
${destructor_action}
}
delete proxy;
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
object.Dispose();
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
object.Dispose(isolate);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100)
object->Dispose(isolate);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
object->Dispose();
#elif (V8_MAJOR_VERSION-0) < 5
object.Clear();
#endif
}
%}
@ -221,11 +160,7 @@ static void $jswrapper(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
* ----------------------------------------------------------------------------- */
%fragment("js_getter", "templates")
%{
#if (V8_MAJOR_VERSION-0) < 5
static SwigV8ReturnValue $jswrapper(v8::Local<v8::String> property, const SwigV8PropertyCallbackInfo &info) {
#else
static SwigV8ReturnValue $jswrapper(v8::Local<v8::Name> property, const SwigV8PropertyCallbackInfo &info) {
#endif
SWIGV8_HANDLESCOPE();
SWIGV8_VALUE jsresult;
@ -247,11 +182,7 @@ fail:
* ----------------------------------------------------------------------------- */
%fragment("js_setter", "templates")
%{
#if (V8_MAJOR_VERSION-0) < 5
static void $jswrapper(v8::Local<v8::String> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid &info) {
#else
static void $jswrapper(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid &info) {
#endif
SWIGV8_HANDLESCOPE();
$jslocals
@ -344,17 +275,10 @@ fail:
if(args.Length() == $jsargcount) {
errorHandler.err.Clear();
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
jsresult = $jswrapper(args, errorHandler);
if(errorHandler.err.IsEmpty()) {
SWIGV8_ESCAPE(jsresult);
}
#else
$jswrapper(args, errorHandler);
if(errorHandler.err.IsEmpty()) {
return;
}
#endif
}
%}
@ -394,15 +318,11 @@ fail:
%{
if (SWIGTYPE_p$jsbaseclass->clientdata && !(static_cast<SWIGV8_ClientData *>(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ.IsEmpty()))
{
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
$jsmangledname_class->Inherit(static_cast<SWIGV8_ClientData *>(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ);
#else
$jsmangledname_class->Inherit(
v8::Local<v8::FunctionTemplate>::New(
v8::Isolate::GetCurrent(),
static_cast<SWIGV8_ClientData *>(SWIGTYPE_p$jsbaseclass->clientdata)->class_templ)
);
#endif
#ifdef SWIGRUNTIME_DEBUG
printf("Inheritance successful $jsmangledname $jsbaseclass\n");
@ -425,10 +345,7 @@ fail:
SWIGV8_FUNCTION_TEMPLATE $jsmangledname_class_0 = SWIGV8_CreateClassTemplate("$jsname");
$jsmangledname_class_0->SetCallHandler($jsctor);
$jsmangledname_class_0->Inherit($jsmangledname_class);
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
$jsmangledname_class_0->SetHiddenPrototype(true);
v8::Handle<v8::Object> $jsmangledname_obj = $jsmangledname_class_0->GetFunction();
#elif (SWIG_V8_VERSION < 0x0704)
#if (SWIG_V8_VERSION < 0x0704)
$jsmangledname_class_0->SetHiddenPrototype(true);
v8::Local<v8::Object> $jsmangledname_obj = $jsmangledname_class_0->GetFunction();
#else
@ -444,12 +361,7 @@ fail:
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_class", "templates")
%{
#if (V8_MAJOR_VERSION-0) < 5
$jsparent_obj->Set(SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj);
#else
SWIGV8_MAYBE_CHECK($jsparent_obj->Set(context, SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj));
#endif
%}
/* -----------------------------------------------------------------------------
@ -469,11 +381,7 @@ fail:
* ----------------------------------------------------------------------------- */
%fragment("jsv8_register_namespace", "templates")
%{
#if (V8_MAJOR_VERSION-0) < 5
$jsparent_obj->Set(SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj);
#else
SWIGV8_MAYBE_CHECK($jsparent_obj->Set(context, SWIGV8_SYMBOL_NEW("$jsname"), $jsmangledname_obj));
#endif
%}
/* -----------------------------------------------------------------------------

View file

@ -1,22 +1,9 @@
%insert(runtime) %{
// Note: since 3.19 there are new CallBack types, since 03.21.9 the old ones have been removed
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
typedef v8::InvocationCallback SwigV8FunctionCallback;
typedef v8::AccessorGetter SwigV8AccessorGetterCallback;
typedef v8::AccessorSetter SwigV8AccessorSetterCallback;
typedef v8::AccessorInfo SwigV8PropertyCallbackInfoVoid;
#elif (V8_MAJOR_VERSION-0) < 5
typedef v8::FunctionCallback SwigV8FunctionCallback;
typedef v8::AccessorGetterCallback SwigV8AccessorGetterCallback;
typedef v8::AccessorSetterCallback SwigV8AccessorSetterCallback;
typedef v8::PropertyCallbackInfo<void> SwigV8PropertyCallbackInfoVoid;
#else
typedef v8::FunctionCallback SwigV8FunctionCallback;
typedef v8::AccessorNameGetterCallback SwigV8AccessorGetterCallback;
typedef v8::AccessorNameSetterCallback SwigV8AccessorSetterCallback;
typedef v8::PropertyCallbackInfo<void> SwigV8PropertyCallbackInfoVoid;
#endif
/**
* Creates a class template for a class with specified initialization function.
@ -62,11 +49,7 @@ SWIGRUNTIME void SWIGV8_AddMemberVariable(SWIGV8_FUNCTION_TEMPLATE class_templ,
*/
SWIGRUNTIME void SWIGV8_AddStaticFunction(SWIGV8_OBJECT obj, const char* symbol,
const SwigV8FunctionCallback& _func, v8::Local<v8::Context> context) {
#if (V8_MAJOR_VERSION-0) < 5
obj->Set(SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction());
#else
SWIGV8_MAYBE_CHECK(obj->Set(context, SWIGV8_SYMBOL_NEW(symbol), SWIGV8_FUNCTEMPLATE_NEW(_func)->GetFunction(context).ToLocalChecked()));
#endif
}
/**
@ -75,27 +58,15 @@ SWIGRUNTIME void SWIGV8_AddStaticFunction(SWIGV8_OBJECT obj, const char* symbol,
SWIGRUNTIME void SWIGV8_AddStaticVariable(SWIGV8_OBJECT obj, const char* symbol,
SwigV8AccessorGetterCallback getter, SwigV8AccessorSetterCallback setter,
v8::Local<v8::Context> context) {
#if (V8_MAJOR_VERSION-0) < 5
obj->SetAccessor(SWIGV8_SYMBOL_NEW(symbol), getter, setter);
#else
SWIGV8_MAYBE_CHECK(obj->SetAccessor(context, SWIGV8_SYMBOL_NEW(symbol), getter, setter));
#endif
}
#if (V8_MAJOR_VERSION-0) < 5
SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::String> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid& info)
#else
SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::Name> property, v8::Local<v8::Value> value, const SwigV8PropertyCallbackInfoVoid& info)
#endif
{
char buffer[256];
char msg[512];
int res;
#if (V8_MAJOR_VERSION-0) < 5
property->WriteUtf8(buffer, 256);
res = sprintf(msg, "Tried to write read-only variable: %s.", buffer);
#else
v8::Local<v8::String> sproperty;
if (property->ToString(SWIGV8_CURRENT_CONTEXT()).ToLocal(&sproperty)) {
SWIGV8_WRITE_UTF8(sproperty, buffer, 256);
@ -104,7 +75,6 @@ SWIGRUNTIME void JS_veto_set_variable(v8::Local<v8::Name> property, v8::Local<v8
else {
res = -1;
}
#endif
if(res<0) {
SWIG_exception(SWIG_ERROR, "Tried to write read-only variable.");

View file

@ -9,25 +9,17 @@ SWIG_V8_SetModule(v8::Local<v8::Context> context, swig_module_info *swig_module)
v8::Local<v8::Object> global_obj = context->Global();
v8::Local<v8::External> mod = SWIGV8_EXTERNAL_NEW(swig_module);
assert(!mod.IsEmpty());
#if (V8_MAJOR_VERSION-0) < 5
global_obj->SetHiddenValue(SWIGV8_STRING_NEW("swig_module_info_data"), mod);
#else
v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("swig_module_info_data"));
global_obj->SetPrivate(context, privateKey, mod);
#endif
}
SWIGRUNTIME swig_module_info *
SWIG_V8_GetModule(v8::Local<v8::Context> context) {
v8::Local<v8::Object> global_obj = context->Global();
#if (V8_MAJOR_VERSION-0) < 5
v8::Local<v8::Value> moduleinfo = global_obj->GetHiddenValue(SWIGV8_STRING_NEW("swig_module_info_data"));
#else
v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("swig_module_info_data"));
v8::Local<v8::Value> moduleinfo;
if (!global_obj->GetPrivate(context, privateKey).ToLocal(&moduleinfo))
return 0;
#endif
if (moduleinfo.IsEmpty() || moduleinfo->IsNull() || moduleinfo->IsUndefined())
{

View file

@ -4,56 +4,26 @@
* Useful table of versions: https://nodejs.org/en/download/releases/
* ---------------------------------------------------------------------------*/
// First v8 version that uses "SetWeak" and not "MakeWeak"
#define SWIGV8_SETWEAK_VERSION 0x032224
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031803)
#define SWIGV8_STRING_NEW2(cstr, len) v8::String::New(cstr, len)
#elif (SWIG_V8_VERSION < 0x0704)
#if (SWIG_V8_VERSION < 0x0704)
#define SWIGV8_STRING_NEW2(cstr, len) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), cstr, v8::String::kNormalString, len)
#else
#define SWIGV8_STRING_NEW2(cstr, len) (v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), cstr, v8::NewStringType::kNormal, len)).ToLocalChecked()
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
typedef v8::Handle<v8::Value> SwigV8ReturnValue;
typedef v8::Arguments SwigV8Arguments;
typedef v8::AccessorInfo SwigV8PropertyCallbackInfo;
#define SWIGV8_RETURN(val) return scope.Close(val)
#define SWIGV8_RETURN_INFO(val, info) return scope.Close(val)
#else
typedef void SwigV8ReturnValue;
typedef v8::FunctionCallbackInfo<v8::Value> SwigV8Arguments;
typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo;
#define SWIGV8_RETURN(val) args.GetReturnValue().Set(val); return
#define SWIGV8_RETURN_INFO(val, info) info.GetReturnValue().Set(val); return
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032117)
#define SWIGV8_HANDLESCOPE() v8::HandleScope scope
#define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope
#define SWIGV8_ESCAPE(val) return scope.Close(val)
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032224)
#define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent());
#define SWIGV8_HANDLESCOPE_ESC() v8::HandleScope scope(v8::Isolate::GetCurrent());
#define SWIGV8_ESCAPE(val) return scope.Close(val)
#else
#define SWIGV8_HANDLESCOPE() v8::HandleScope scope(v8::Isolate::GetCurrent());
#define SWIGV8_HANDLESCOPE_ESC() v8::EscapableHandleScope scope(v8::Isolate::GetCurrent());
#define SWIGV8_ESCAPE(val) return scope.Escape(val)
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032224)
#define SWIGV8_ADJUST_MEMORY(size) v8::V8::AdjustAmountOfExternalAllocatedMemory(size)
#define SWIGV8_CURRENT_CONTEXT() v8::Context::GetCurrent()
#define SWIGV8_THROW_EXCEPTION(err) v8::ThrowException(err)
#define SWIGV8_STRING_NEW(str) v8::String::New(str)
#define SWIGV8_SYMBOL_NEW(sym) v8::String::NewSymbol(sym)
#else
#define SWIGV8_ADJUST_MEMORY(size) v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(size)
#define SWIGV8_CURRENT_CONTEXT() v8::Isolate::GetCurrent()->GetCurrentContext()
#define SWIGV8_THROW_EXCEPTION(err) v8::Isolate::GetCurrent()->ThrowException(err)
#if (SWIG_V8_VERSION < 0x0704)
#define SWIGV8_STRING_NEW(str) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str, v8::String::kNormalString)
#define SWIGV8_SYMBOL_NEW(sym) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sym, v8::String::kNormalString)
@ -61,37 +31,13 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo;
#define SWIGV8_STRING_NEW(str) (v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str, v8::NewStringType::kNormal)).ToLocalChecked()
#define SWIGV8_SYMBOL_NEW(sym) (v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), sym, v8::NewStringType::kNormal)).ToLocalChecked()
#endif
#endif
#if (V8_MAJOR_VERSION-0) < 5
#define SWIGV8_MAYBE_CHECK(maybe) maybe
#elif (SWIG_V8_VERSION < 0x0704)
#if (SWIG_V8_VERSION < 0x0704)
#define SWIGV8_MAYBE_CHECK(maybe) maybe.FromJust()
#else
#define SWIGV8_MAYBE_CHECK(maybe) maybe.Check()
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032318)
#define SWIGV8_ARRAY_NEW(size) v8::Array::New(size)
#define SWIGV8_BOOLEAN_NEW(bool) v8::Boolean::New(bool)
#define SWIGV8_EXTERNAL_NEW(val) v8::External::New(val)
#define SWIGV8_FUNCTEMPLATE_NEW(func) v8::FunctionTemplate::New(func)
#define SWIGV8_FUNCTEMPLATE_NEW_VOID() v8::FunctionTemplate::New()
#define SWIGV8_INT32_NEW(num) v8::Int32::New(num)
#define SWIGV8_INTEGER_NEW(num) v8::Integer::New(num)
#define SWIGV8_INTEGER_NEW_UNS(num) v8::Integer::NewFromUnsigned(num)
#define SWIGV8_NUMBER_NEW(num) v8::Number::New(num)
#define SWIGV8_OBJECT_NEW() v8::Object::New()
#define SWIGV8_UNDEFINED() v8::Undefined()
#define SWIGV8_ARRAY v8::Handle<v8::Array>
#define SWIGV8_FUNCTION_TEMPLATE v8::Handle<v8::FunctionTemplate>
#define SWIGV8_OBJECT v8::Handle<v8::Object>
#define SWIGV8_OBJECT_TEMPLATE v8::Handle<v8::ObjectTemplate>
#define SWIGV8_VALUE v8::Handle<v8::Value>
#define SWIGV8_NULL() v8::Null()
#define SWIGV8_ARRAY_GET(array, index) (array)->Get(index)
#define SWIGV8_ARRAY_SET(array, index, value) (array)->Set(index, value)
#else
#define SWIGV8_ARRAY_NEW(size) v8::Array::New(v8::Isolate::GetCurrent(), size)
#define SWIGV8_BOOLEAN_NEW(bool) v8::Boolean::New(v8::Isolate::GetCurrent(), bool)
#define SWIGV8_EXTERNAL_NEW(val) v8::External::New(v8::Isolate::GetCurrent(), val)
@ -111,17 +57,10 @@ typedef v8::PropertyCallbackInfo<v8::Value> SwigV8PropertyCallbackInfo;
#define SWIGV8_NULL() v8::Null(v8::Isolate::GetCurrent())
#define SWIGV8_ARRAY_GET(array, index) (array)->Get(SWIGV8_CURRENT_CONTEXT(), index).ToLocalChecked()
#define SWIGV8_ARRAY_SET(array, index, value) SWIGV8_MAYBE_CHECK((array)->Set(SWIGV8_CURRENT_CONTEXT(), index, value))
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
#define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ = v8::Persistent<v8::FunctionTemplate>::New(class);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
#define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ = v8::Persistent<v8::FunctionTemplate>::New(v8::Isolate::GetCurrent(), class);
#else
#define SWIGV8_SET_CLASS_TEMPL(class_templ, class) class_templ.Reset(v8::Isolate::GetCurrent(), class);
#endif
#if (V8_MAJOR_VERSION-0) < 6 || (SWIG_V8_VERSION < 0x0608)
#if SWIG_V8_VERSION < 0x0608
#define SWIGV8_TO_OBJECT(handle) (handle)->ToObject()
#define SWIGV8_TO_STRING(handle) (handle)->ToString()
#define SWIGV8_NUMBER_VALUE(handle) (handle)->NumberValue()
@ -208,23 +147,8 @@ public:
};
~SWIGV8_Proxy() {
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
handle.ClearWeak();
handle.Dispose();
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100)
handle.ClearWeak(v8::Isolate::GetCurrent());
handle.Dispose(v8::Isolate::GetCurrent());
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
handle.ClearWeak();
handle.Dispose();
#else
handle.ClearWeak();
handle.Reset();
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
handle.Clear();
#endif
SWIGV8_ADJUST_MEMORY(-SWIGV8_AVG_OBJ_SIZE);
}
@ -239,17 +163,7 @@ class SWIGV8_ClientData {
public:
v8::Persistent<v8::FunctionTemplate> class_templ;
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
void (*dtor) (v8::Persistent< v8::Value> object, void *parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Value> object, void *parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
void (*dtor) (v8::Isolate *isolate, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy);
#elif (V8_MAJOR_VERSION-0) < 5
void (*dtor) (const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data);
#else
void (*dtor) (const v8::WeakCallbackInfo<SWIGV8_Proxy> &data);
#endif
};
SWIGRUNTIME v8::Persistent<v8::FunctionTemplate> SWIGV8_SWIGTYPE_Proxy_class_templ;
@ -259,17 +173,12 @@ SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(SWIGV8_OBJECT objRef, void **ptr, swi
if(objRef->InternalFieldCount() < 1) return SWIG_ERROR;
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511)
v8::Handle<v8::Value> cdataRef = objRef->GetInternalField(0);
SWIGV8_Proxy *cdata = static_cast<SWIGV8_Proxy *>(v8::External::Unwrap(cdataRef));
#else
SWIGV8_Proxy *cdata = static_cast<SWIGV8_Proxy *>(objRef->GetAlignedPointerFromInternalField(0));
#endif
if(cdata == NULL) {
return SWIG_ERROR;
}
if(cdata->info != info) {
if(info && cdata->info != info) {
swig_cast_info *tc = SWIG_TypeCheckStruct(cdata->info, info);
if (!tc && cdata->info->name) {
tc = SWIG_TypeCheck(cdata->info->name, info);
@ -285,29 +194,22 @@ SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(SWIGV8_OBJECT objRef, void **ptr, swi
*ptr = cdata->swigCObject;
}
if(flags & SWIG_POINTER_DISOWN) {
cdata->swigCMemOwn = false;
if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !cdata->swigCMemOwn) {
return SWIG_ERROR_RELEASE_NOT_OWNED;
} else {
if (flags & SWIG_POINTER_DISOWN) {
cdata->swigCMemOwn = false;
}
if (flags & SWIG_POINTER_CLEAR) {
cdata->swigCObject = 0;
}
}
return SWIG_OK;
}
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Persistent< v8::Value > object, void *parameter) {
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Value > object, void *parameter) {
SWIGV8_Proxy *proxy = static_cast<SWIGV8_Proxy *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(v8::Isolate *, v8::Persistent< v8::Object > *object, SWIGV8_Proxy *proxy) {
#elif (V8_MAJOR_VERSION-0) < 5
SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackData<v8::Object, SWIGV8_Proxy> &data) {
SWIGV8_Proxy *proxy = data.GetParameter();
#else
SWIGRUNTIME void SWIGV8_Proxy_DefaultDtor(const v8::WeakCallbackInfo<SWIGV8_Proxy> &data) {
SWIGV8_Proxy *proxy = data.GetParameter();
#endif
delete proxy;
}
@ -319,12 +221,7 @@ SWIGRUNTIME int SWIG_V8_GetInstancePtr(SWIGV8_VALUE valRef, void **ptr) {
if(objRef->InternalFieldCount() < 1) return SWIG_ERROR;
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511)
v8::Handle<v8::Value> cdataRef = objRef->GetInternalField(0);
SWIGV8_Proxy *cdata = static_cast<SWIGV8_Proxy *>(v8::External::Unwrap(cdataRef));
#else
SWIGV8_Proxy *cdata = static_cast<SWIGV8_Proxy *>(objRef->GetAlignedPointerFromInternalField(0));
#endif
if(cdata == NULL) {
return SWIG_ERROR;
@ -341,58 +238,17 @@ SWIGRUNTIME void SWIGV8_SetPrivateData(SWIGV8_OBJECT obj, void *ptr, swig_type_i
cdata->swigCMemOwn = (flags & SWIG_POINTER_OWN) ? 1 : 0;
cdata->info = info;
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511)
obj->SetPointerInInternalField(0, cdata);
#else
obj->SetAlignedPointerInInternalField(0, cdata);
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
cdata->handle = v8::Persistent<v8::Object>::New(obj);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
cdata->handle = v8::Persistent<v8::Object>::New(v8::Isolate::GetCurrent(), obj);
#else
cdata->handle.Reset(v8::Isolate::GetCurrent(), obj);
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
// clientdata must be set for owned data as we need to register the dtor
if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
cdata->handle.MakeWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
} else {
cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor);
}
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031918)
if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
} else {
cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, SWIGV8_Proxy_DefaultDtor);
}
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
cdata->handle.MakeWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
} else {
cdata->handle.MakeWeak(cdata, SWIGV8_Proxy_DefaultDtor);
}
#elif (V8_MAJOR_VERSION-0) < 5
if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
cdata->handle.SetWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor);
} else {
cdata->handle.SetWeak(cdata, SWIGV8_Proxy_DefaultDtor);
}
#else
if(cdata->swigCMemOwn && (SWIGV8_ClientData*)info->clientdata) {
cdata->handle.SetWeak(cdata, ((SWIGV8_ClientData*)info->clientdata)->dtor, v8::WeakCallbackType::kParameter);
} else {
cdata->handle.SetWeak(cdata, SWIGV8_Proxy_DefaultDtor, v8::WeakCallbackType::kParameter);
}
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
cdata->handle.MarkIndependent();
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100)
cdata->handle.MarkIndependent(v8::Isolate::GetCurrent());
#elif (SWIG_V8_VERSION < 0x0704)
#if (SWIG_V8_VERSION < 0x0704)
cdata->handle.MarkIndependent();
// Looks like future versions do not require that anymore:
// https://monorail-prod.appspot.com/p/chromium/issues/detail?id=923361#c11
@ -420,21 +276,10 @@ SWIGRUNTIME SWIGV8_VALUE SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info,
SWIGV8_FUNCTION_TEMPLATE class_templ;
if (ptr == NULL) {
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
SWIGV8_ESCAPE(SWIGV8_NULL());
#else
v8::Local<v8::Primitive> result = SWIGV8_NULL();
SWIGV8_ESCAPE(result);
#endif
}
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
if(info->clientdata != 0) {
class_templ = ((SWIGV8_ClientData*) info->clientdata)->class_templ;
} else {
class_templ = SWIGV8_SWIGTYPE_Proxy_class_templ;
}
#else
v8::Isolate *isolate = v8::Isolate::GetCurrent();
if(info->clientdata != 0) {
@ -442,13 +287,8 @@ SWIGRUNTIME SWIGV8_VALUE SWIG_V8_NewPointerObj(void *ptr, swig_type_info *info,
} else {
class_templ = v8::Local<v8::FunctionTemplate>::New(isolate, SWIGV8_SWIGTYPE_Proxy_class_templ);
}
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
v8::Local<v8::Object> result = class_templ->InstanceTemplate()->NewInstance();
#else
v8::Local<v8::Object> result = class_templ->InstanceTemplate()->NewInstance(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked();
#endif
SWIGV8_SetPrivateData(result, ptr, info, flags);
@ -543,14 +383,10 @@ int SwigV8Packed_Check(SWIGV8_VALUE valRef) {
SWIGV8_OBJECT objRef = SWIGV8_TO_OBJECT(valRef);
if(objRef->InternalFieldCount() < 1) return false;
#if (V8_MAJOR_VERSION-0) < 5
v8::Handle<v8::Value> flag = objRef->GetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__"));
#else
v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("__swig__packed_data__"));
v8::Local<v8::Value> flag;
if (!objRef->GetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey).ToLocal(&flag))
return false;
#endif
return (flag->IsBoolean() && SWIGV8_BOOLEAN_VALUE(flag));
}
@ -563,12 +399,7 @@ swig_type_info *SwigV8Packed_UnpackData(SWIGV8_VALUE valRef, void *ptr, size_t s
SWIGV8_OBJECT objRef = SWIGV8_TO_OBJECT(valRef);
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511)
v8::Handle<v8::Value> cdataRef = objRef->GetInternalField(0);
sobj = static_cast<SwigV8PackedData*>(v8::External::Unwrap(cdataRef));
#else
sobj = static_cast<SwigV8PackedData*>(objRef->GetAlignedPointerFromInternalField(0));
#endif
if (sobj == NULL || sobj->size != size) return 0;
memcpy(ptr, sobj->data, size);
return sobj->type;
@ -591,38 +422,9 @@ int SWIGV8_ConvertPacked(SWIGV8_VALUE valRef, void *ptr, size_t sz, swig_type_in
return SWIG_OK;
}
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Persistent< v8::Value > object, void *parameter) {
SwigV8PackedData *cdata = static_cast<SwigV8PackedData *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent<v8::Value> object, void *parameter) {
SwigV8PackedData *cdata = static_cast<SwigV8PackedData *>(parameter);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
SWIGRUNTIME void _wrap_SwigV8PackedData_delete(v8::Isolate *isolate, v8::Persistent<v8::Object> *object, SwigV8PackedData *cdata) {
#elif (V8_MAJOR_VERSION-0) < 5
SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackData<v8::Object, SwigV8PackedData> &data) {
v8::Local<v8::Object> object = data.GetValue();
SwigV8PackedData *cdata = data.GetParameter();
#else
SWIGRUNTIME void _wrap_SwigV8PackedData_delete(const v8::WeakCallbackInfo<SwigV8PackedData> &data) {
SwigV8PackedData *cdata = data.GetParameter();
#endif
delete cdata;
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
object.Clear();
object.Dispose();
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
object.Clear();
object.Dispose(isolate);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100)
object->Dispose(isolate);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
object->Dispose();
#elif (V8_MAJOR_VERSION-0) < 5
object.Clear();
#endif
}
SWIGRUNTIME
@ -633,46 +435,16 @@ SWIGV8_VALUE SWIGV8_NewPackedObj(void *data, size_t size, swig_type_info *type)
// v8::Handle<v8::Object> obj = SWIGV8_OBJECT_NEW();
v8::Local<v8::Object> obj = SWIGV8_OBJECT_NEW();
#if (V8_MAJOR_VERSION-0) < 5
obj->SetHiddenValue(SWIGV8_STRING_NEW("__swig__packed_data__"), SWIGV8_BOOLEAN_NEW(true));
#else
v8::Local<v8::Private> privateKey = v8::Private::ForApi(v8::Isolate::GetCurrent(), SWIGV8_STRING_NEW("__swig__packed_data__"));
obj->SetPrivate(SWIGV8_CURRENT_CONTEXT(), privateKey, SWIGV8_BOOLEAN_NEW(true));
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031511)
obj->SetPointerInInternalField(0, cdata);
#else
obj->SetAlignedPointerInInternalField(0, cdata);
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
cdata->handle = v8::Persistent<v8::Object>::New(obj);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031900)
cdata->handle = v8::Persistent<v8::Object>::New(v8::Isolate::GetCurrent(), obj);
#else
cdata->handle.Reset(v8::Isolate::GetCurrent(), obj);
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031918)
cdata->handle.MakeWeak(v8::Isolate::GetCurrent(), cdata, _wrap_SwigV8PackedData_delete);
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < SWIGV8_SETWEAK_VERSION)
cdata->handle.MakeWeak(cdata, _wrap_SwigV8PackedData_delete);
#elif (V8_MAJOR_VERSION-0) < 5
cdata->handle.SetWeak(cdata, _wrap_SwigV8PackedData_delete);
// v8::V8::SetWeak(&cdata->handle, cdata, _wrap_SwigV8PackedData_delete);
#else
cdata->handle.SetWeak(cdata, _wrap_SwigV8PackedData_delete, v8::WeakCallbackType::kParameter);
#endif
#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031710)
cdata->handle.MarkIndependent();
#elif (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x032100)
cdata->handle.MarkIndependent(v8::Isolate::GetCurrent());
#elif (SWIG_V8_VERSION < 0x0704)
#if (SWIG_V8_VERSION < 0x0704)
cdata->handle.MarkIndependent();
// Looks like future versions do not require that anymore:
// https://monorail-prod.appspot.com/p/chromium/issues/detail?id=923361#c11

View file

@ -7,36 +7,8 @@
// ----------------
//
// v8 added version macros V8_MAJOR_VERSION, V8_MINOR_VERSION, V8_BUILD_NUMBER
// and V8_PATCH_LEVEL in version 4.3.0. SWIG generated code uses these if
// they are defined - to support earlier versions you can specify the V8 version
// in use via the command line when you run SWIG:
//
// swig -c++ -javascript -v8 -DV8_VERSION=0x032530 example.i
//
// Or code in the interface file using SWIG_V8_VERSION:
//
// %begin %{#define SWIG_V8_VERSION 0x031110%}
//
// This is specified as a hex constant, but the constant is read as pairs of
// decimal digits, so for V8 3.25.30 use constant 0x032530. This scheme can't
// represent components > 99, but this constant is only useful for V8 < 4.3.0,
// and no V8 versions from that era had a component > 99.
%define %swig_v8_define_version(version)
%insert("runtime") %{
#ifndef SWIG_V8_VERSION
#define SWIG_V8_VERSION version
#endif
%}
%enddef
#ifdef V8_VERSION
%swig_v8_define_version(V8_VERSION)
#else
// HACK: defining a default version
%swig_v8_define_version(0x031110)
#endif
// and V8_PATCH_LEVEL in version 4.3.0. SWIG doesn't support anything that
// old so SWIG generated code can rely on these.
// Node support
// ------------
@ -56,10 +28,11 @@
%insert(runtime) %{
#include <v8.h>
#if defined(V8_MAJOR_VERSION) && defined(V8_MINOR_VERSION)
#undef SWIG_V8_VERSION
#define SWIG_V8_VERSION (V8_MAJOR_VERSION * 256 + V8_MINOR_VERSION)
#endif
#define SWIG_V8_VERSION ((V8_MAJOR_VERSION / 10) * 4096 + \
(V8_MAJOR_VERSION % 10) * 256 + \
(V8_MINOR_VERSION / 10) * 16 + \
(V8_MINOR_VERSION % 10))
#include <errno.h>
#include <limits.h>

View file

@ -7,11 +7,7 @@ SWIGINTERN int
SWIG_AsCharPtrAndSize(SWIGV8_VALUE valRef, char** cptr, size_t* psize, int *alloc)
{
if(valRef->IsString()) {
%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
v8::Handle<v8::String> js_str = v8::Handle<v8::String>::Cast(valRef);
%#else
v8::Local<v8::String> js_str = v8::Local<v8::String>::Cast(valRef);
%#endif
size_t len = SWIGV8_UTF8_LENGTH(js_str) + 1;
char* cstr = (char*) %new_array(len, char);
@ -53,11 +49,7 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
// TODO: handle extra long strings
return SWIGV8_UNDEFINED();
} else {
%#if (V8_MAJOR_VERSION-0) < 4 && (SWIG_V8_VERSION < 0x031903)
v8::Handle<v8::String> js_str = SWIGV8_STRING_NEW2(carray, size);
%#else
v8::Local<v8::String> js_str = SWIGV8_STRING_NEW2(carray, size);
%#endif
return js_str;
}
} else {

View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_auto_ptr.i
*
* SWIG library file for handling std::auto_ptr.
* Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
* class when returning a std::auto_ptr from a function.
* Memory ownership is passed from the proxy class to the std::auto_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
%typemap(in, noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
%releasenotowned_fail(res, "TYPE *", $symname, $argnum);
} else {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::auto_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::auto_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::auto_ptr< TYPE >;
%enddef
namespace std {
template <class T> class auto_ptr {};
}

View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
%releasenotowned_fail(res, "TYPE *", $symname, $argnum);
} else {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::unique_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

View file

@ -0,0 +1 @@
%include <typemaps/swigmove.swg>

View file

@ -72,7 +72,7 @@ multiple output values, they are returned in the form of a Python tuple.
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:
returns the integer part in one of its parameters) :
double modf(double x, double *ip);

57
Lib/lua/argcargv.i Normal file
View file

@ -0,0 +1,57 @@
/* ------------------------------------------------------------
* SWIG library containing argc and argv multi-argument typemaps
Use it as follows:
%apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) }
extern int mainApp(size_t argc, const char **argv);
then from lua:
args = { "arg0", "arg1" }
mainApp(args)
* ------------------------------------------------------------ */
%{
SWIGINTERN int SWIG_argv_size(lua_State* L, int index) {
int n=0;
while(1){
lua_rawgeti(L,index,n+1);
if (lua_isnil(L,-1))
break;
++n;
lua_pop(L,1);
}
lua_pop(L,1);
return n;
}
%}
%typemap(in) (int ARGC, char **ARGV) {
if (lua_istable(L,$input)) {
int i, size = SWIG_argv_size(L,$input);
$1 = ($1_ltype) size;
$2 = (char **) malloc((size+1)*sizeof(char *));
for (i = 0; i < size; i++) {
lua_rawgeti(L,$input,i+1);
if (lua_isnil(L,-1))
break;
$2[i] = (char *)lua_tostring(L, -1);
lua_pop(L,1);
}
$2[i]=NULL;
} else {
$1 = 0; $2 = 0;
lua_pushstring(L,"Expecting argv array");
lua_error(L);
}
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
$1 = lua_istable(L,$input);
}
%typemap(freearg) (int ARGC, char **ARGV) {
free((char *) $2);
}

View file

@ -151,7 +151,7 @@ The python/lua ones are great, but C++ ones I don't like
(mainly because I cannot get the stack trace out of it)
Therefore I have not bothered to try doing much in this
Therefore currently its just enough to get a few test cases running ok
Therefore currently it's just enough to get a few test cases running ok
note: if you wish to throw anything related to std::exception
use %include <std_except.i> instead
@ -191,7 +191,7 @@ use %include <std_except.i> instead
Throwing object is a serious problem:
Assuming some code throws a 'FooBar'
There are a few options:
- return a pointer to it: but its unclear how long this will last for.
- return a pointer to it: but it's unclear how long this will last for.
- return a copy of it: but not all objects are copyable
(see exception_partial_info in the test suite for a case where you cannot do this)
- convert to a string & throw that
@ -213,7 +213,7 @@ SWIG_fail;%}
// %apply SWIGTYPE EXCEPTION_BY_VAL {FooBar};
// %apply SWIGTYPE& EXCEPTION_BY_VAL {FooBar&}; // note: need & twice
%typemap(throws) SWIGTYPE EXCEPTION_BY_VAL
%{SWIG_NewPointerObj(L,(void *)new $1_ltype(($1_ltype &) $1),$&1_descriptor,1);
%{SWIG_NewPointerObj(L,(void *)new $1_ltype($1),$&1_descriptor,1);
SWIG_fail;%}
// similar for object reference
@ -224,7 +224,7 @@ SWIG_fail;%}
// note: no support for object pointers
// its not clear how long the pointer is valid for, therefore not supporting it
// it's not clear how long the pointer is valid for, therefore not supporting it
/* -----------------------------------------------------------------------------
* extras

View file

@ -17,7 +17,7 @@ note: it should be passed by value, not byref or as a pointer.
The SWIGLUA_FN holds a pointer to the lua_State, and the stack index where the function is held.
The macro SWIGLUA_FN_GET() will put a copy of the lua function at the top of the stack.
After that its fairly simple to write the rest of the code (assuming know how to use lua),
After that it's fairly simple to write the rest of the code (assuming know how to use lua),
just push the parameters, call the function and return the result.
int my_func(int a, int b, SWIGLUA_FN fn)

View file

@ -2,7 +2,7 @@
Warnings for Lua keywords, built-in names and bad names.
*/
#define LUAKW(x) %keywordwarn("'" `x` "' is a Lua keyword, renaming to 'c_" `x` "'", rename="c_%s") `x`
#define LUAKW(x) %keywordwarn("'" `x` "' is a Lua keyword", rename="c_%s") `x`
#define LUABN(x) %namewarn(%warningmsg(SWIGWARN_PARSE_BUILTIN_NAME, "'" `x` "' conflicts with a basic function in Lua"), %$not %$ismember) `x`
/*

View file

@ -307,7 +307,7 @@ typedef struct {
/* Contract support */
#define SWIG_contract_assert(expr, msg) \
if (!(expr)) { SWIG_Lua_pusherrstring(L, (char *) msg); goto fail; } else
do { if (!(expr)) { SWIG_Lua_pusherrstring(L, (char *) msg); goto fail; } } while (0)
/* helper #defines */
@ -826,7 +826,7 @@ SWIGINTERN int SWIG_Lua_class_do_get_item(lua_State *L, swig_type_info *type, i
/* NEW: looks for the __getitem() fn
this is a user provided get fn */
SWIG_Lua_get_table(L,"__getitem"); /* find the __getitem fn */
if (lua_iscfunction(L,-1)) /* if its there */
if (lua_iscfunction(L,-1)) /* if it's there */
{ /* found it so call the fn & return its value */
lua_pushvalue(L,substack_start+1); /* the userdata */
lua_pushvalue(L,substack_start+2); /* the parameter */
@ -883,7 +883,7 @@ SWIGINTERN int SWIG_Lua_class_do_get(lua_State *L, swig_type_info *type, int SW
lua_pushvalue(L,substack_start+2); /* key */
lua_rawget(L,-2); /* look for the fn */
lua_remove(L,-2); /* stack tidy, remove .fn table */
if (lua_isfunction(L,-1)) /* note: if its a C function or lua function */
if (lua_isfunction(L,-1)) /* note: if it's a C function or lua function */
{ /* found it so return the fn & let lua call it */
lua_remove(L,-2); /* stack tidy, remove metatable */
if(ret)
@ -966,7 +966,7 @@ SWIGINTERN int SWIG_Lua_class_do_set(lua_State *L, swig_type_info *type, int fi
/* NEW: looks for the __setitem() fn
this is a user provided set fn */
SWIG_Lua_get_table(L,"__setitem"); /* find the fn */
if (lua_iscfunction(L,-1)) /* if its there */
if (lua_iscfunction(L,-1)) /* if it's there */
{ /* found it so call the fn & return its value */
lua_pushvalue(L,substack_start+1); /* the userdata */
lua_pushvalue(L,substack_start+2); /* the parameter */
@ -1343,7 +1343,7 @@ SWIGINTERN void SWIG_Lua_add_class_instance_details(lua_State *L, swig_lua_clas
SWIGRUNTIME int SWIG_Lua_resolve_metamethod(lua_State *L); /*forward declaration*/
/* The real function that resolves a metamethod.
* Function searches given class and all it's bases(recursively) for first instance of something that is
* Function searches given class and all its bases (recursively) for first instance of something that is
* not equal to SWIG_Lua_resolve_metamethod. (Almost always this 'something' is actual metamethod implementation
* and it is a SWIG-generated C function.). It returns value on the top of the L and there is no garbage below the
* answer.
@ -1757,6 +1757,7 @@ SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *t
(if possible) */
SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type_info *type,int flags)
{
int ret = SWIG_ERROR;
swig_lua_userdata *usr;
swig_cast_info *cast;
/* special case: lua nil => NULL pointer */
@ -1773,30 +1774,41 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type
usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
if (usr)
{
if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !usr->own)
{
return SWIG_ERROR_RELEASE_NOT_OWNED;
}
if (flags & SWIG_POINTER_DISOWN) /* must disown the object */
{
usr->own=0;
usr->own = 0;
}
if (!type) /* special cast void*, no casting fn */
{
*ptr=usr->ptr;
return SWIG_OK; /* ok */
ret = SWIG_OK;
}
cast=SWIG_TypeCheckStruct(usr->type,type); /* performs normal type checking */
if (cast)
else
{
int newmemory = 0;
*ptr=SWIG_TypeCast(cast,usr->ptr,&newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */
return SWIG_OK; /* ok */
cast=SWIG_TypeCheckStruct(usr->type,type); /* performs normal type checking */
if (cast)
{
int newmemory = 0;
*ptr=SWIG_TypeCast(cast,usr->ptr,&newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */
ret = SWIG_OK;
}
}
if ((ret == SWIG_OK) && (flags & SWIG_POINTER_CLEAR))
{
usr->ptr = 0;
}
}
return SWIG_ERROR; /* error */
return ret;
}
SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State *L,int index,swig_type_info *type,int flags,
int argnum,const char *func_name){
void *result;
void *result = 0;
if (!SWIG_IsOK(SWIG_ConvertPtr(L,index,&result,type,flags))){
luaL_error (L,"Error in %s, expected a %s at argument number %d\n",
func_name,(type && type->str)?type->str:"void*",argnum);

View file

@ -24,7 +24,7 @@
// additional check for unsigned numbers, to not permit negative input
%typemap(in,checkfn="lua_isnumber") unsigned int,
unsigned short, unsigned long, unsigned char
%{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative")
%{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative");
$1 = ($type)lua_tonumber(L, $input);%}
%typemap(out) int,short,long,
@ -43,7 +43,7 @@ $1 = ($type)lua_tonumber(L, $input);%}
%{ temp=($*1_ltype)lua_tonumber(L,$input); $1=&temp;%}
%typemap(in,checkfn="lua_isnumber") const unsigned int&($*1_ltype temp)
%{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative")
%{SWIG_contract_assert((lua_tonumber(L,$input)>=0),"number must not be negative");
temp=($*1_ltype)lua_tonumber(L,$input); $1=&temp;%}
%typemap(out) const int&, const unsigned int&
@ -151,11 +151,17 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
}
%}
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE&&
%{
if (!SWIG_IsOK(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,$disown))){
SWIG_fail_ptr("$symname",$argnum,$descriptor);
%typemap(in,checkfn="lua_isuserdata",fragment="<memory>") SWIGTYPE&& (void *argp = 0, int res = 0, std::unique_ptr<$*1_ltype> rvrdeleter) %{
res = SWIG_ConvertPtr(L, $input, &argp, $descriptor, SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
lua_pushfstring(L, "Cannot release ownership as memory is not owned for argument $argnum of type '$1_type' in $symname"); SWIG_fail;
} else {
SWIG_fail_ptr("$symname", $argnum, $descriptor);
}
}
$1 = ($1_ltype)argp;
rvrdeleter.reset($1);
%}
// out is simple
@ -217,7 +223,7 @@ $1=($1_ltype)&temp;%}
#ifdef __cplusplus
%typemap(out) SWIGTYPE
{
$&1_ltype resultptr = new $1_ltype((const $1_ltype &) $1);
$&1_ltype resultptr = new $1_ltype($1);
SWIG_NewPointerObj(L,(void *) resultptr,$&1_descriptor,1); SWIG_arg++;
}
#else
@ -248,11 +254,11 @@ $1=($1_ltype)&temp;%}
// void (must be empty without the SWIG_arg++)
%typemap(out) void "";
%typemap(out) void ""
/* void* is a special case
A function void fn(void*) should take any kind of pointer as a parameter (just like C/C++ does)
but if its an output, then it should be wrapped like any other SWIG object (using default typemap)
but if it's an output, then it should be wrapped like any other SWIG object (using default typemap)
*/
%typemap(in,checkfn="SWIG_isptrtype") void*
%{$1=($1_ltype)SWIG_MustGetPtr(L,$input,0,0,$argnum,"$symname");%}
@ -285,7 +291,7 @@ parameters match which function
// unfortunately lua only considers one type of number
// so all numbers (int,float,double) match
// you could add an advanced fn to get type & check if its integral
// you could add an advanced fn to get type & check if it's integral
%typecheck(SWIG_TYPECHECK_INTEGER)
int, short, long,
unsigned int, unsigned short, unsigned long,
@ -396,7 +402,7 @@ parameters match which function
* Specials
* ----------------------------------------------------------------------------- */
// swig::LANGUAGE_OBJ was added to allow containers of native objects
// however its rather difficult to do this in lua, as you cannot hold pointers
// however it's rather difficult to do this in lua, as you cannot hold pointers
// to native objects (they are held in the interpreter)
// therefore for now: just ignoring this feature
#ifdef __cplusplus

39
Lib/lua/std_auto_ptr.i Normal file
View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_auto_ptr.i
*
* SWIG library file for handling std::auto_ptr.
* Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
* class when returning a std::auto_ptr from a function.
* Memory ownership is passed from the proxy class to the std::auto_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
%typemap(in, checkfn="SWIG_isptrtype", noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr(L, $input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
lua_pushfstring(L, "Cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *' in $symname"); SWIG_fail;
} else {
SWIG_fail_ptr("$symname", $argnum, $descriptor(TYPE *));
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::auto_ptr< TYPE > %{
SWIG_NewPointerObj(L, $1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN); SWIG_arg++;
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::auto_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr(L, $input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::auto_ptr< TYPE >;
%enddef
namespace std {
template <class T> class auto_ptr {};
}

39
Lib/lua/std_unique_ptr.i Normal file
View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %unique_ptr(TYPE)
%typemap(in, checkfn="SWIG_isptrtype", noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr(L, $input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
lua_pushfstring(L, "Cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *' in $symname"); SWIG_fail;
} else {
SWIG_fail_ptr("$symname", $argnum, $descriptor(TYPE *));
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::unique_ptr< TYPE > %{
SWIG_NewPointerObj(L, $1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN); SWIG_arg++;
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::unique_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr(L, $input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

18
Lib/lua/swigmove.i Normal file
View file

@ -0,0 +1,18 @@
/* -----------------------------------------------------------------------------
* swigmove.i
*
* Input typemaps library for implementing full move semantics when passing
* parameters by value.
* ----------------------------------------------------------------------------- */
%typemap(in, checkfn="lua_isuserdata", noblock=1) SWIGTYPE MOVE (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr(L, $input, &argp, $&1_descriptor, SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
lua_pushfstring(L, "Cannot release ownership as memory is not owned for argument $argnum of type '$1_type' in $symname"); SWIG_fail;
} else {
SWIG_fail_ptr("$symname", $argnum, $&1_descriptor);
}
}
SwigValueWrapper< $1_ltype >::reset($1, ($&1_type)argp);
}

View file

@ -28,7 +28,7 @@ The basic code looks like this:
However the code below is a mixture of #defines & such, so nowhere as easy to read
To make you code work correctly its not just a matter of %including this file
To make you code work correctly it's not just a matter of %including this file
You also have to give SWIG the hints on which to use where
eg
@ -77,7 +77,7 @@ SWIG_NUMBER_TYPEMAP(enum SWIGTYPE);
// also for long longs's
SWIG_NUMBER_TYPEMAP(long long); SWIG_NUMBER_TYPEMAP(unsigned long long); SWIG_NUMBER_TYPEMAP(signed long long);
// note we dont do char, as a char* is probably a string not a ptr to a single char
// note we don't do char, as a char* is probably a string not a ptr to a single char
// similar for booleans
%typemap(in,checkfn="lua_isboolean") bool *INPUT(bool temp), bool &INPUT(bool temp)
@ -188,16 +188,6 @@ int SWIG_read_NAME_num_array(lua_State* L,int index,TYPE *array,int size);
*/
/* Reported that you don't need to check for NULL for delete & free
There probably is some compiler that its not true for, so the code is left here just in case.
#ifdef __cplusplus
#define SWIG_ALLOC_ARRAY(TYPE,LEN) new TYPE[LEN]
#define SWIG_FREE_ARRAY(PTR) if(PTR){delete[] PTR;}
#else
#define SWIG_ALLOC_ARRAY(TYPE,LEN) (TYPE *)malloc(LEN*sizeof(TYPE))
#define SWIG_FREE_ARRAY(PTR) if(PTR){free(PTR);}
#endif
*/
%{
#ifdef __cplusplus /* generic alloc/dealloc fns*/
#define SWIG_ALLOC_ARRAY(TYPE,LEN) new TYPE[LEN]

View file

@ -23,12 +23,14 @@ extern "C" {
SWIG_MzScheme_MustGetPtr(s, type, argnum, flags, FUNC_NAME, argc, argv)
#define SWIG_contract_assert(expr,msg) \
if (!(expr)) { \
char *m=(char *) scheme_malloc(strlen(msg)+1000); \
sprintf(m,"SWIG contract, assertion failed: function=%s, message=%s", \
(char *) FUNC_NAME,(char *) msg); \
scheme_signal_error(m); \
}
do { \
if (!(expr)) { \
char *m=(char *) scheme_malloc(strlen(msg)+1000); \
sprintf(m,"SWIG contract, assertion failed: function=%s, message=%s", \
(char *) FUNC_NAME,(char *) msg); \
scheme_signal_error(m); \
} \
} while (0)
/* Runtime API */
#define SWIG_GetModule(clientdata) SWIG_MzScheme_GetModule((Scheme_Env *)(clientdata))
@ -123,6 +125,7 @@ struct swig_mz_proxy {
Scheme_Type mztype;
swig_type_info *type;
void *object;
int own;
};
static Scheme_Type swig_type;
@ -133,7 +136,7 @@ mz_free_swig(void *p, void *data) {
if (SCHEME_NULLP((Scheme_Object*)p) || SCHEME_TYPE((Scheme_Object*)p) != swig_type)
return;
if (proxy->type) {
if (proxy->type->clientdata) {
if (proxy->type->clientdata && proxy->own) {
((Scheme_Prim *)proxy->type->clientdata)(1, (Scheme_Object **)&proxy);
}
}
@ -141,42 +144,61 @@ mz_free_swig(void *p, void *data) {
static Scheme_Object *
SWIG_MzScheme_NewPointerObj(void *ptr, swig_type_info *type, int owner) {
struct swig_mz_proxy *new_proxy;
new_proxy = (struct swig_mz_proxy *) scheme_malloc(sizeof(struct swig_mz_proxy));
new_proxy->mztype = swig_type;
new_proxy->type = type;
new_proxy->object = ptr;
if (owner) {
scheme_add_finalizer(new_proxy, mz_free_swig, NULL);
if (ptr) {
struct swig_mz_proxy *new_proxy;
new_proxy = (struct swig_mz_proxy *) scheme_malloc(sizeof(struct swig_mz_proxy));
new_proxy->mztype = swig_type;
new_proxy->type = type;
new_proxy->object = ptr;
new_proxy->own = owner & SWIG_POINTER_OWN;
if (new_proxy->own) {
scheme_add_finalizer(new_proxy, mz_free_swig, NULL);
}
return (Scheme_Object *) new_proxy;
} else {
return scheme_make_null();
}
return (Scheme_Object *) new_proxy;
}
static int
SWIG_MzScheme_ConvertPtr(Scheme_Object *s, void **result, swig_type_info *type, int flags) {
swig_cast_info *cast;
int ret = SWIG_ERROR;
if (SCHEME_NULLP(s)) {
*result = NULL;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
} else if (SCHEME_TYPE(s) == swig_type) {
struct swig_mz_proxy *proxy = (struct swig_mz_proxy *) s;
if ((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE && !proxy->own) {
return SWIG_ERROR_RELEASE_NOT_OWNED;
}
if (type) {
cast = SWIG_TypeCheckStruct(proxy->type, type);
if (cast) {
int newmemory = 0;
*result = SWIG_TypeCast(cast, proxy->object, &newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */
return 0;
ret = SWIG_OK;
} else {
return 1;
return SWIG_ERROR;
}
} else {
*result = proxy->object;
return 0;
ret = SWIG_OK;
}
if (flags & SWIG_POINTER_DISOWN) {
scheme_subtract_finalizer(proxy, mz_free_swig, NULL);
proxy->own = 0;
}
if (flags & SWIG_POINTER_CLEAR) {
proxy->object = 0;
}
}
return 1;
return ret;
}
static SWIGINLINE void *

View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_auto_ptr.i
*
* SWIG library file for handling std::auto_ptr.
* Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
* class when returning a std::auto_ptr from a function.
* Memory ownership is passed from the proxy class to the std::auto_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
%typemap(in, noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
scheme_signal_error(FUNC_NAME ": cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *'");
} else {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::auto_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN));
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::auto_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::auto_ptr< TYPE >;
%enddef
namespace std {
template <class T> class auto_ptr {};
}

View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_unique_ptr.i
*
* SWIG library file for handling std::unique_ptr.
* Memory ownership is passed from the std::unique_ptr C++ layer to the proxy
* class when returning a std::unique_ptr from a function.
* Memory ownership is passed from the proxy class to the std::unique_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %unique_ptr(TYPE)
%typemap(in, noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
scheme_signal_error(FUNC_NAME ": cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *'");
} else {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::unique_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN));
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::unique_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::unique_ptr< TYPE >;
%enddef
namespace std {
template <class T> class unique_ptr {};
}

19
Lib/mzscheme/swigmove.i Normal file
View file

@ -0,0 +1,19 @@
/* -----------------------------------------------------------------------------
* swigmove.i
*
* Input typemaps library for implementing full move semantics when passing
* parameters by value.
* ----------------------------------------------------------------------------- */
%typemap(in, noblock=1) SWIGTYPE MOVE (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $&1_descriptor, SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
scheme_signal_error(FUNC_NAME ": cannot release ownership as memory is not owned for argument $argnum of type '$1_type'");
} else {
%argument_fail(res, "$1_type", $symname, $argnum);
}
}
if (argp == NULL) scheme_signal_error(FUNC_NAME ": swig-type-error (null reference)");
SwigValueWrapper< $1_ltype >::reset($1, ($&1_type)argp);
}

View file

@ -2,6 +2,12 @@
* typemaps.i
* ----------------------------------------------------------------------------- */
#define %set_output(obj) $result = obj
#define %set_varoutput(obj) $result = obj
#define %argument_fail(code, type, name, argn) scheme_wrong_type(FUNC_NAME, type, argn, argc, argv)
#define %as_voidptr(ptr) (void*)(ptr)
/* The MzScheme module handles all types uniformly via typemaps. Here
are the definitions. */
@ -66,9 +72,23 @@
#ifdef __cplusplus
%typemap(in) SWIGTYPE &, SWIGTYPE && {
%typemap(in) SWIGTYPE & {
$1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum, 0);
if ($1 == NULL) scheme_signal_error("swig-type-error (null reference)");
if ($1 == NULL) scheme_signal_error(FUNC_NAME ": swig-type-error (null reference)");
}
%typemap(in, noblock=1, fragment="<memory>") SWIGTYPE && (void *argp = 0, int res = 0, std::unique_ptr<$*1_ltype> rvrdeleter) {
res = SWIG_ConvertPtr($input, &argp, $descriptor, SWIG_POINTER_RELEASE);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
scheme_signal_error(FUNC_NAME ": cannot release ownership as memory is not owned for argument $argnum of type '$1_type'");
} else {
%argument_fail(res, "$1_type", $symname, $argnum);
}
}
if (argp == NULL) scheme_signal_error(FUNC_NAME ": swig-type-error (null reference)");
$1 = ($1_ltype)argp;
rvrdeleter.reset($1);
}
%typemap(out) SWIGTYPE &, SWIGTYPE && {
@ -105,8 +125,8 @@
$1 = ($1_type) SWIG_convert_int($input);
}
%typemap(out) enum SWIGTYPE "$result = scheme_make_integer_value($1);";
%typemap(varout) enum SWIGTYPE "$result = scheme_make_integer_value($1);";
%typemap(out) enum SWIGTYPE "$result = scheme_make_integer_value($1);"
%typemap(varout) enum SWIGTYPE "$result = scheme_make_integer_value($1);"
/* Pass-by-value */
@ -127,7 +147,7 @@
#ifdef __cplusplus
{
$&1_ltype resultptr;
resultptr = new $1_ltype(($1_ltype &) $1);
resultptr = new $1_ltype($1);
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1);
}
#else
@ -143,7 +163,7 @@
#ifdef __cplusplus
{
$&1_ltype resultptr;
resultptr = new $1_ltype(($1_ltype &) $1);
resultptr = new $1_ltype($1);
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0);
}
#else
@ -272,12 +292,12 @@ REF_MAP(double, SCHEME_REALP, scheme_real_to_double,
/* Void */
%typemap(out) void "$result = scheme_void;";
%typemap(out) void "$result = scheme_void;"
/* Pass through Scheme_Object * */
%typemap (in) Scheme_Object * "$1=$input;";
%typemap (out) Scheme_Object * "$result=$1;";
%typemap (in) Scheme_Object * "$1=$input;"
%typemap (out) Scheme_Object * "$result=$1;"
%typecheck(SWIG_TYPECHECK_POINTER) Scheme_Object * "$1=1;";
@ -291,7 +311,6 @@ REF_MAP(double, SCHEME_REALP, scheme_real_to_double,
// $2 = ($2_ltype) temp;
//}
/* ------------------------------------------------------------
* Typechecking rules
* ------------------------------------------------------------ */

View file

@ -40,9 +40,10 @@
$1 = ($ltype) caml_ptr_val($input,$1_descriptor);
}
%typemap(in) SWIGTYPE && {
%typemap(in, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{
$1 = ($ltype) caml_ptr_val($input,$1_descriptor);
}
rvrdeleter.reset($1);
%}
%typemap(varin) SWIGTYPE & {
$1 = *(($ltype) caml_ptr_val($input,$1_descriptor));
@ -93,10 +94,14 @@
$1 = *(($&1_ltype) caml_ptr_val($input,$&1_descriptor)) ;
}
%typemap(varout) SWIGTYPE {
$result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)&$1, $&1_descriptor);
}
#ifdef __cplusplus
%typemap(out) SWIGTYPE {
$&1_ltype temp = new $ltype((const $1_ltype &) $1);
$&1_ltype temp = new $1_ltype($1);
$result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)temp, $&1_descriptor);
}
@ -110,8 +115,12 @@
#endif
%typemap(varout) SWIGTYPE * {
$result = SWIG_Ocaml_ptr_to_val("create_$ntype_from_ptr", (void *)$1, $1_descriptor);
}
%typemap(directorin) SWIGTYPE {
$&ltype temp = new $ltype((const $ltype &)$1);
$&ltype temp = new $1_ltype(SWIG_STD_MOVE($1));
swig_result = SWIG_Ocaml_ptr_to_val("create_$ltype_from_ptr", (void *)temp, $&1_descriptor);
args = caml_list_append(args, swig_result);
}
@ -180,12 +189,12 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val);
/* Void */
%typemap(out) void "$result = Val_unit;";
%typemap(out) void "$result = Val_unit;"
/* Pass through value */
%typemap (in) CAML_VALUE "$1=$input;";
%typemap (out) CAML_VALUE "$result=$1;";
%typemap (in) CAML_VALUE "$1=$input;"
%typemap (out) CAML_VALUE "$result=$1;"
#if 0
%include <carray.i>
@ -302,7 +311,7 @@ SIMPLE_MAP(unsigned long long,caml_val_ulong,caml_long_val);
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
%apply SWIGTYPE && { SWIGTYPE ((&)[ANY]) }
%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) }
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }

View file

@ -369,7 +369,7 @@ extern "C" {
if( !p || len < 0 ) CAMLreturn(caml_val_ptr( (void *)p, 0 ));
vv = caml_swig_alloc(1,C_string);
SWIG_Store_field(vv,0,caml_alloc_string(len));
memcpy(String_val(SWIG_Field(vv,0)),p,len);
memcpy(Bp_val(SWIG_Field(vv,0)),p,len);
CAMLreturn(vv);
}

View file

@ -164,7 +164,7 @@ SWIGINTERN void SWIG_OCamlThrowException(SWIG_OCamlExceptionCodes code, const ch
CAMLreturn0;
}
#define SWIG_contract_assert(expr, msg) if(!(expr)) {SWIG_OCamlThrowException(SWIG_OCamlRuntimeException, msg);}
#define SWIG_contract_assert(expr, msg) do { if(!(expr)) {SWIG_OCamlThrowException(SWIG_OCamlRuntimeException, msg);} } while (0)
SWIGINTERN int
SWIG_GetPtr(void *source, void **result, swig_type_info *type, swig_type_info *result_type);

View file

@ -83,10 +83,22 @@ class wstring;
$result = caml_val_string_len($1.c_str(),$1.size());
}
%typemap(varout) string {
$result = caml_val_string_len($1.c_str(),$1.size());
}
%typemap(out) string * {
$result = caml_val_string_len((*$1).c_str(),(*$1).size());
}
%typemap(varout) string * {
$result = caml_val_string_len((*$1).c_str(),(*$1).size());
}
%typemap(typecheck) string, const string & = char *;
%typemap(throws) string, const string & "SWIG_OCamlThrowException(SWIG_OCamlRuntimeException, $1.c_str());"
}
#ifdef ENABLE_CHARPTR_ARRAY

11
Lib/ocaml/swigmove.i Normal file
View file

@ -0,0 +1,11 @@
/* -----------------------------------------------------------------------------
* swigmove.i
*
* Input typemaps library for implementing full move semantics when passing
* parameters by value.
* ----------------------------------------------------------------------------- */
%typemap(in, noblock=1) SWIGTYPE MOVE (void *argp = 0) {
argp1 = ($&1_ltype) caml_ptr_val($input,$&1_descriptor);
SwigValueWrapper< $1_ltype >::reset($1, ($&1_type)argp);
}

44
Lib/octave/argcargv.i Normal file
View file

@ -0,0 +1,44 @@
/* ------------------------------------------------------------
* SWIG library containing argc and argv multi-argument typemaps
* ------------------------------------------------------------ */
%typemap(in) (int ARGC, char **ARGV) {
if ($input.is_scalar_type()) {
$1 = 0; $2 = NULL;
%argument_fail(SWIG_TypeError, "'int ARGC, char **ARGV' is not a list", $symname, $argnum);
}
octave_value_list list = $input.list_value();
int i, len = list.length();
$1 = ($1_ltype) len;
$2 = (char **) malloc((len+1)*sizeof(char *));
for (i = 0; i < len; i++) {
if (!list(i).is_string()) {
$1 = 0;
%argument_fail(SWIG_TypeError, "'int ARGC, char **ARGV' use a non-string", $symname, $argnum);
}
$2[i] = (char *)list(i).string_value().c_str();
}
$2[i] = NULL;
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
$1 = 0;
const octave_value& ov = $input;
if (!ov.is_scalar_type()) {
octave_value_list list = ov.list_value();
int i, len = list.length();
$1 = 1;
for (i = 0; i < len; i++) {
if (!list(i).is_string()) {
$1 = 0;
break;
}
}
}
}
%typemap(freearg) (int ARGC, char **ARGV) {
if ($2 != NULL) {
free((void *)$2);
}
}

View file

@ -35,7 +35,7 @@
}
}
%typemap(out) CONST TYPE {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1));
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype($1));
%set_output(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
@ -54,12 +54,12 @@
}
}
%typemap(varout) CONST TYPE {
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1));
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartresult = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype($1));
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(smartresult), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN));
}
%typemap(directorin,noblock=1) CONST TYPE (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
smartarg = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1));
smartarg = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(SWIG_STD_MOVE($1)));
$input = SWIG_NewPointerObj(%as_voidptr(smartarg), $descriptor(SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > *), SWIG_POINTER_OWN | %newpointer_flags);
%}
%typemap(directorout,noblock=1) CONST TYPE (void *swig_argp, int swig_res = 0) {

View file

@ -569,8 +569,17 @@ namespace swig {
} else {
return octseq.check() ? SWIG_OK : SWIG_ERROR;
}
} catch (std::exception& e) {
}
%#if SWIG_OCTAVE_PREREQ(6,0,0)
catch (octave::execution_exception& exec) {
}
%#endif
catch (std::exception& e) {
%#if SWIG_OCTAVE_PREREQ(6,0,0)
if (seq) // Know that octave is not in an error state
%#else
if (seq&&!error_state)
%#endif
error("swig type error: %s",e.what());
return SWIG_ERROR;
}

View file

@ -9,8 +9,8 @@
// g++ -c -include octheaders.hpp ...
//
#if !defined(_SWIG_OCTAVE_OCTHEADERS_HPP)
#define _SWIG_OCTAVE_OCTHEADERS_HPP
#if !defined(SWIG_OCTAVE_OCTHEADERS_HPP)
#define SWIG_OCTAVE_OCTHEADERS_HPP
// Required C++ headers
#include <cstdlib>
@ -127,4 +127,4 @@
#include <octave/call-stack.h>
#endif
#endif // !defined(_SWIG_OCTAVE_OCTHEADERS_HPP)
#endif // !defined(SWIG_OCTAVE_OCTHEADERS_HPP)

View file

@ -171,7 +171,16 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
octave_function* function_value(bool = false) { return this; }
#if SWIG_OCTAVE_PREREQ(6,0,0)
octave_value_list call(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) {
return execute(tw,nargout,args);
}
#endif
#if SWIG_OCTAVE_PREREQ(6,0,0)
octave_value_list execute(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) {
#else
octave_value_list call(octave::tree_evaluator& tw, int nargout = 0, const octave_value_list& args = octave_value_list()) {
#endif
octave_value_list all_args;
all_args.append(first_args);
all_args.append(args);
@ -223,7 +232,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
const swig_type_info *construct_type; // type of special type object
std::vector < type_ptr_pair > types; // our c++ base classes
int own; // whether we call c++ destructors when we die
int thisown; // whether we call c++ destructors when we die
typedef std::pair < const swig_octave_member *, octave_value > member_value_pair;
typedef std::map < std::string, member_value_pair > member_map;
@ -403,7 +412,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
octave_swig_type(void *_ptr = 0, const swig_type_info *_type = 0, int _own = 0,
bool _always_static = false)
: module(0), construct_type(_ptr ? 0 : _type), own(_own),
: module(0), construct_type(_ptr ? 0 : _type), thisown(_own),
always_static(_always_static) {
if (_type || _ptr)
types.push_back(std::make_pair(_type, _ptr));
@ -417,7 +426,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
}
~octave_swig_type() {
if (own) {
if (thisown) {
++count;
for (unsigned int j = 0; j < types.size(); ++j) {
if (!types[j].first || !types[j].first->clientdata)
@ -456,10 +465,20 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
// Fill in dim_vector
for (int k=0;k<ndim;k++) {
const octave_value& obj = c(k);
#if SWIG_OCTAVE_PREREQ(6,0,0)
try {
d.elem(k) = obj.int_value();
}
catch (octave::execution_exception& oee) {
// __dims__ should return a cell filled with integers
return dim_vector(1,1);
}
#else
d.elem(k) = obj.int_value();
// __dims__ should return a cell filled with integers
if (error_state) return dim_vector(1,1);
#endif
}
return d;
#if SWIG_OCTAVE_PREREQ(4,4,0)
@ -468,8 +487,18 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
} else if (out.is_matrix_type() || out.is_numeric_type() ) {
#endif
if (out.rows()==1 || out.columns()==1) {
#if SWIG_OCTAVE_PREREQ(6,0,0)
Array<int> a;
try {
a = out.int_vector_value();
}
catch (octave::execution_exception& oee) {
return dim_vector(1,1);
}
#else
Array<int> a = out.int_vector_value();
if (error_state) return dim_vector(1,1);
#endif
dim_vector d;
d.resize(a.numel() < 2 ? 2 : a.numel());
d(0) = d(1) = 1;
@ -530,7 +559,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
}
void merge(octave_swig_type &rhs) {
rhs.own = 0;
rhs.thisown = 0;
for (unsigned int j = 0; j < rhs.types.size(); ++j) {
assert(!rhs.types[j].second.destroyed);
#ifdef SWIG_DIRECTORS
@ -553,35 +582,56 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
swig_member_const_iterator swig_members_begin() { return members.begin(); }
swig_member_const_iterator swig_members_end() { return members.end(); }
int cast(void **vptr, swig_type_info *type, int *_own, int flags) {
int cast(void **vptr, swig_type_info *type, int *own, int flags) {
int res = SWIG_ERROR;
if (_own)
*_own = own;
if (flags &SWIG_POINTER_DISOWN)
own = 0;
int clear_pointer = 0;
if (own)
*own = 0;
if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !thisown) {
return SWIG_ERROR_RELEASE_NOT_OWNED;
} else {
if (own)
*own = *own | thisown;
if (flags & SWIG_POINTER_DISOWN) {
thisown = 0;
}
if (flags & SWIG_POINTER_CLEAR) {
clear_pointer = 1;
}
}
if (!type && types.size()) {
if(vptr)
if (vptr) {
*vptr = types[0].second.ptr;
if (clear_pointer)
types[0].second.ptr = 0;
}
return SWIG_OK;
}
for (unsigned int j = 0; j < types.size(); ++j)
if (type == types[j].first) {
if(vptr)
if (vptr) {
*vptr = types[j].second.ptr;
if (clear_pointer)
types[j].second.ptr = 0;
}
return SWIG_OK;
}
for (unsigned int j = 0; j < types.size(); ++j) {
swig_cast_info *tc = SWIG_TypeCheck(types[j].first->name, type);
if (!tc)
continue;
if(vptr) {
if (vptr) {
int newmemory = 0;
*vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory);
if (newmemory == SWIG_CAST_NEW_MEMORY) {
assert(_own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
if (_own)
*_own = *_own | SWIG_CAST_NEW_MEMORY;
}
if (newmemory == SWIG_CAST_NEW_MEMORY) {
assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
if (own)
*own = *own | SWIG_CAST_NEW_MEMORY;
}
if (clear_pointer)
types[j].second.ptr = 0;
}
res = SWIG_OK;
break;
@ -590,7 +640,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
}
bool is_owned() const {
return own;
return thisown;
}
#ifdef SWIG_DIRECTORS
@ -631,7 +681,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
return true;
}
#if SWIG_OCTAVE_PREREQ(6,0,0)
virtual bool isstruct() const {
#else
virtual bool is_map() const {
#endif
return true;
}
@ -779,7 +833,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
return as_value();
}
#if SWIG_OCTAVE_PREREQ(4,4,0)
virtual bool isobject() const {
#else
virtual bool is_object() const {
#endif
return true;
}
@ -874,7 +932,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
}
virtual bool load_binary (std::istream& is, bool swap,
oct_mach_info::float_format fmt) {
#if SWIG_OCTAVE_PREREQ(6,0,0)
octave::mach_info::float_format fmt) {
#else
oct_mach_info::float_format fmt) {
#endif
return true;
}
@ -1084,8 +1146,13 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
bool is_defined() const
{ return ptr->is_defined(); }
#if SWIG_OCTAVE_PREREQ(6,0,0)
virtual bool isstruct() const
{ return ptr->isstruct(); }
#else
virtual bool is_map() const
{ return ptr->is_map(); }
#endif
virtual octave_value subsref(const std::string &ops, const std::list < octave_value_list > &idx)
{ return ptr->subsref(ops, idx); }
@ -1096,8 +1163,13 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
octave_value subsasgn(const std::string &ops, const std::list < octave_value_list > &idx, const octave_value &rhs)
{ return ptr->subsasgn(ops, idx, rhs); }
#if SWIG_OCTAVE_PREREQ(4,4,0)
virtual bool isobject() const
{ return ptr->isobject(); }
#else
virtual bool is_object() const
{ return ptr->is_object(); }
#endif
virtual bool is_string() const
{ return ptr->is_string(); }
@ -1142,7 +1214,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
{ return ptr->save_binary(os, save_as_floats); }
virtual bool load_binary (std::istream& is, bool swap,
oct_mach_info::float_format fmt)
#if SWIG_OCTAVE_PREREQ(6,0,0)
octave::mach_info::float_format fmt)
#else
oct_mach_info::float_format fmt)
#endif
{ return ptr->load_binary(is, swap, fmt); }
#if defined (HAVE_HDF5)
@ -1178,6 +1254,10 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
#endif
{ return ptr->print(os, pr_as_read_syntax); }
#if SWIG_OCTAVE_PREREQ(4,4,0)
static void set_type_id(int type_id) { t_id=type_id; }
#endif
virtual type_conv_info numeric_conversion_function(void) const {
return octave_base_value::type_conv_info (default_numeric_conversion_function,
octave_scalar::static_type_id ());
@ -1257,7 +1337,11 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
}
virtual bool load_binary (std::istream& is, bool swap,
oct_mach_info::float_format fmt) {
#if SWIG_OCTAVE_PREREQ(6,0,0)
octave::mach_info::float_format fmt) {
#else
oct_mach_info::float_format fmt) {
#endif
return true;
}
@ -1285,6 +1369,10 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
# endif
#endif
#if SWIG_OCTAVE_PREREQ(4,4,0)
static void set_type_id(int type_id) { t_id=type_id; }
#endif
private:
#if !SWIG_OCTAVE_PREREQ(4,0,0)
DECLARE_OCTAVE_ALLOCATOR;
@ -1459,12 +1547,15 @@ octave_value_typeinfo::register_binary_op(octave_value::op_##name,tid1,tid2,swig
SWIGRUNTIME octave_value SWIG_Octave_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
int own = (flags &SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
if (ptr) {
#ifdef SWIG_DIRECTORS
Swig::Director *d = Swig::get_rtdir(ptr);
if (d && Swig::swig_director_get_self(d))
return Swig::swig_director_get_self(d)->as_value();
Swig::Director *d = Swig::get_rtdir(ptr);
if (d && Swig::swig_director_get_self(d))
return Swig::swig_director_get_self(d)->as_value();
#endif
return Swig::swig_value_ref(new octave_swig_type(ptr, type, own));
return Swig::swig_value_ref(new octave_swig_type(ptr, type, own));
}
return octave_value(Matrix()); // null matrix
}
SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void **ptr, swig_type_info *type, int flags, int *own) {
@ -1507,16 +1598,24 @@ SWIGRUNTIMEINLINE void SWIG_Octave_SetConstant(octave_swig_type *module_ns, cons
}
SWIGRUNTIMEINLINE octave_value SWIG_Octave_GetGlobalValue(std::string name) {
#if SWIG_OCTAVE_PREREQ(6,0,0)
octave::interpreter *interp = octave::interpreter::the_interpreter ();
return interp->global_varval(name);
#else
#if SWIG_OCTAVE_PREREQ(4,4,0)
octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table();
return symtab.global_varval(name);
#else
return get_global_value(name, true);
#endif
#endif
}
SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value& value) {
#if SWIG_OCTAVE_PREREQ(4,4,0)
#if SWIG_OCTAVE_PREREQ(6,0,0)
octave::interpreter *interp = octave::interpreter::the_interpreter ();
interp->global_assign(name, value);
#elif SWIG_OCTAVE_PREREQ(4,4,0)
octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table();
symtab.global_assign(name, value);
#else
@ -1526,10 +1625,20 @@ SWIGRUNTIME void SWIG_Octave_SetGlobalValue(std::string name, const octave_value
SWIGRUNTIME void SWIG_Octave_LinkGlobalValue(std::string name) {
#if SWIG_OCTAVE_PREREQ(4,4,0)
octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table();
octave::symbol_scope symscope = octave::interpreter::the_interpreter()->get_current_scope();
#if SWIG_OCTAVE_PREREQ(6,0,0)
octave::interpreter *interp = octave::interpreter::the_interpreter ();
interp->assign(name, interp->global_varval(name));
octave::tree_evaluator& tree_eval = interp->get_evaluator();
octave::call_stack& callStack = tree_eval.get_call_stack();
std::shared_ptr<octave::stack_frame> stackFrame = callStack.get_current_stack_frame();
octave::symbol_record sym=symscope.lookup_symbol(name);
stackFrame->mark_global(sym);
#else
octave::symbol_table& symtab = octave::interpreter::the_interpreter()->get_symbol_table();
symscope.assign(name, symtab.global_varval(name));
symscope.mark_global(name);
#endif
#else
#if !SWIG_OCTAVE_PREREQ(3,2,0)
link_to_global_variable(curr_sym_tab->lookup(name, true));

View file

@ -19,7 +19,8 @@ static bool SWIG_init_user(octave_swig_type* module_ns);
SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) {
bool retn = false;
{
#if SWIG_OCTAVE_PREREQ(4,2,0)
#if SWIG_OCTAVE_PREREQ(6,0,0)
#elif SWIG_OCTAVE_PREREQ(4,2,0)
octave::unwind_protect frame;
frame.protect_var(discard_error_messages); discard_error_messages = true;
frame.protect_var(discard_warning_messages); discard_warning_messages = true;
@ -62,7 +63,8 @@ SWIGINTERN bool SWIG_Octave_LoadModule(std::string name) {
SWIGINTERN bool SWIG_Octave_InstallFunction(octave_function *octloadfcn, std::string name) {
bool retn = false;
{
#if SWIG_OCTAVE_PREREQ(4,2,0)
#if SWIG_OCTAVE_PREREQ(6,0,0)
#elif SWIG_OCTAVE_PREREQ(4,2,0)
octave::unwind_protect frame;
frame.protect_var(discard_error_messages); discard_error_messages = true;
frame.protect_var(discard_warning_messages); discard_warning_messages = true;
@ -295,9 +297,11 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) {
for (int i = 0; i < types.numel(); ++i) {
if (types(i) == octave_swig_ref::static_type_name()) {
register_octave_swig_ref = false;
octave_swig_ref::set_type_id(i);
}
if (types(i) == octave_swig_packed::static_type_name()) {
register_octave_swig_packed = false;
octave_swig_packed::set_type_id(i);
}
}
if (register_octave_swig_ref) {
@ -314,7 +318,11 @@ DEFUN_DLD( SWIG_name, args, nargout, SWIG_name_usage ) {
SWIG_InitializeModule(0);
SWIG_PropagateClientData();
#if SWIG_OCTAVE_PREREQ(4,4,0)
#if SWIG_OCTAVE_PREREQ(6,0,0)
octave::tree_evaluator& tree_eval = octave::interpreter::the_interpreter()->get_evaluator();
octave::call_stack& stack = tree_eval.get_call_stack();
octave_function *me = stack.current_function();
#elif SWIG_OCTAVE_PREREQ(4,4,0)
octave::call_stack& stack = octave::interpreter::the_interpreter()->get_call_stack();
octave_function *me = stack.current();
#else

39
Lib/octave/std_auto_ptr.i Normal file
View file

@ -0,0 +1,39 @@
/* -----------------------------------------------------------------------------
* std_auto_ptr.i
*
* SWIG library file for handling std::auto_ptr.
* Memory ownership is passed from the std::auto_ptr C++ layer to the proxy
* class when returning a std::auto_ptr from a function.
* Memory ownership is passed from the proxy class to the std::auto_ptr in the
* C++ layer when passed as a parameter to a wrapped function.
* ----------------------------------------------------------------------------- */
%define %auto_ptr(TYPE)
%typemap(in, noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) {
res = SWIG_ConvertPtr($input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE | %convertptr_flags);
if (!SWIG_IsOK(res)) {
if (res == SWIG_ERROR_RELEASE_NOT_OWNED) {
%releasenotowned_fail(res, "TYPE *", $symname, $argnum);
} else {
%argument_fail(res, "TYPE *", $symname, $argnum);
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::auto_ptr< TYPE > %{
%set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags));
%}
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *", noblock=1) std::auto_ptr< TYPE > {
void *vptr = 0;
int res = SWIG_ConvertPtr($input, &vptr, $descriptor(TYPE *), 0);
$1 = SWIG_CheckState(res);
}
%template() std::auto_ptr< TYPE >;
%enddef
namespace std {
template <class T> class auto_ptr {};
}

Some files were not shown because too many files have changed in this diff Show more