diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2022-09-08 19:50:31 +0100 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2022-09-08 19:50:31 +0100 |
commit | c79f7f3d852a051392862f5e960e2614ee58a814 (patch) | |
tree | 3e1edf06725448e7dd7d2968479f4d122f59e0a7 /Lib | |
parent | 7ff686c5c153e8c37a312534280ed09dcbf030ec (diff) | |
parent | 2212af3f4f0906d84ef3aecf4812622af5f3ec7e (diff) | |
download | swig-c79f7f3d852a051392862f5e960e2614ee58a814.tar.gz |
Merge branch 'rvalue-move'
* rvalue-move:
rvalue reference outputs
Remove broken %implicitconv for const SWIGTYPE &&
Remove unnecessary const SWIGTYPE & typemap
Temporarily remove rvalue reference python runtime test
std::auto_ptr emulation fix in test case
Ocaml typemap typo fix
Fix Racket tests using schemerunme directory
Docs on rvalue parameter changes
Test/fixes to handle NULL pointer for unique_ptr/auto_ptr
Octave - SWIG now marshalls a C/C++ NULL pointer into the null matrix, []
Racket - NULL pointer handling
SWIGTYPE && input typemaps now assume object has been moved - Go and OCaml
SWIGTYPE && input typemaps now assume object has been moved
SWIGTYPE && input typemaps now assume object has been moved - Java
Cosmetic stray semi-colon removal after %typemap using quotes
Cosmetic stray semi-colon removal after %typemap
Diffstat (limited to 'Lib')
41 files changed, 293 insertions, 261 deletions
diff --git a/Lib/cffi/cffi.swg b/Lib/cffi/cffi.swg index 205bf7900..b96d3d4fd 100644 --- a/Lib/cffi/cffi.swg +++ b/Lib/cffi/cffi.swg @@ -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, @@ -114,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]) } diff --git a/Lib/csharp/csharp.swg b/Lib/csharp/csharp.swg index 60ab388f3..1f80d12a1 100644 --- a/Lib/csharp/csharp.swg +++ b/Lib/csharp/csharp.swg @@ -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 diff --git a/Lib/csharp/std_array.i b/Lib/csharp/std_array.i index a4f0f9640..6e7fe9eb4 100644 --- a/Lib/csharp/std_array.i +++ b/Lib/csharp/std_array.i @@ -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) diff --git a/Lib/csharp/std_list.i b/Lib/csharp/std_list.i index 674aba0ab..cf6f20238 100644 --- a/Lib/csharp/std_list.i +++ b/Lib/csharp/std_list.i @@ -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 * }; diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index e538a03a1..7a118569a 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -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] { diff --git a/Lib/csharp/std_set.i b/Lib/csharp/std_set.i index 82f010aff..012152260 100644 --- a/Lib/csharp/std_set.i +++ b/Lib/csharp/std_set.i @@ -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); diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index ecb10dfbb..a2add584d 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -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) diff --git a/Lib/d/dswigtype.swg b/Lib/d/dswigtype.swg index 3fb7f6a01..c227519e8 100644 --- a/Lib/d/dswigtype.swg +++ b/Lib/d/dswigtype.swg @@ -122,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;" @@ -157,11 +157,12 @@ * Rvalue reference conversion typemaps. */ -%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_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null"); + SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null"); return $null; - } %} + } + rvrdeleter.reset($1); %} %typemap(out) SWIGTYPE && "$result = (void *)$1;" %typemap(directorin) SWIGTYPE && @@ -182,7 +183,7 @@ %typemap(din, nativepointer="cast(void*)$dinput" -) SWIGTYPE && "$dclassname.swigGetCPtr($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 diff --git a/Lib/go/go.swg b/Lib/go/go.swg index bb7a471cc..348ae5f0d 100644 --- a/Lib/go/go.swg +++ b/Lib/go/go.swg @@ -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; %} diff --git a/Lib/guile/typemaps.i b/Lib/guile/typemaps.i index eb0a41422..37dfaee64 100644 --- a/Lib/guile/typemaps.i +++ b/Lib/guile/typemaps.i @@ -4,17 +4,38 @@ * 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 &, SWIGTYPE [] { $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0); } -%typemap(freearg) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] ""; +%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); @@ -321,14 +342,14 @@ 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) 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. */ @@ -348,13 +369,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;"; /* ------------------------------------------------------------ @@ -372,11 +393,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)) { diff --git a/Lib/java/java.swg b/Lib/java/java.swg index 19198b7b4..8719818bb 100644 --- a/Lib/java/java.swg +++ b/Lib/java/java.swg @@ -692,15 +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; - } %} -%typemap(freearg) SWIGTYPE && %{ delete $1; %}; + } + rvrdeleter.reset($1); %} %typemap(out) SWIGTYPE * %{ *($&1_ltype)&$result = $1; %} %typemap(out, fragment="SWIG_PackData", noblock=1) SWIGTYPE (CLASS::*) { diff --git a/Lib/lua/luatypemaps.swg b/Lib/lua/luatypemaps.swg index 97ecef41e..7d23917ee 100644 --- a/Lib/lua/luatypemaps.swg +++ b/Lib/lua/luatypemaps.swg @@ -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 @@ -248,7 +254,7 @@ $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) diff --git a/Lib/lua/std_auto_ptr.i b/Lib/lua/std_auto_ptr.i index b0978963b..3952d6dd6 100644 --- a/Lib/lua/std_auto_ptr.i +++ b/Lib/lua/std_auto_ptr.i @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ %define %auto_ptr(TYPE) -%typemap(in, checkfn="lua_isuserdata", noblock=1) std::auto_ptr< TYPE > (void *argp = 0, int res = 0) { +%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) { diff --git a/Lib/lua/std_unique_ptr.i b/Lib/lua/std_unique_ptr.i index de84b2497..4c1c1fde5 100644 --- a/Lib/lua/std_unique_ptr.i +++ b/Lib/lua/std_unique_ptr.i @@ -9,7 +9,7 @@ * ----------------------------------------------------------------------------- */ %define %unique_ptr(TYPE) -%typemap(in, checkfn="lua_isuserdata", noblock=1) std::unique_ptr< TYPE > (void *argp = 0, int res = 0) { +%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) { diff --git a/Lib/mzscheme/mzrun.swg b/Lib/mzscheme/mzrun.swg index fed660dfb..57d040812 100644 --- a/Lib/mzscheme/mzrun.swg +++ b/Lib/mzscheme/mzrun.swg @@ -144,16 +144,20 @@ 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; - new_proxy->own = owner & SWIG_POINTER_OWN; - if (new_proxy->own) { - 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 diff --git a/Lib/mzscheme/std_auto_ptr.i b/Lib/mzscheme/std_auto_ptr.i index a903d0063..dd55230b3 100644 --- a/Lib/mzscheme/std_auto_ptr.i +++ b/Lib/mzscheme/std_auto_ptr.i @@ -8,9 +8,6 @@ * C++ layer when passed as a parameter to a wrapped function. * ----------------------------------------------------------------------------- */ -#define %argument_fail(code, type, name, argn) scheme_wrong_type(FUNC_NAME, type, argn, argc, argv); -#define %set_output(obj) $result = obj - %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); diff --git a/Lib/mzscheme/std_unique_ptr.i b/Lib/mzscheme/std_unique_ptr.i index 35386a783..af602c342 100644 --- a/Lib/mzscheme/std_unique_ptr.i +++ b/Lib/mzscheme/std_unique_ptr.i @@ -8,9 +8,6 @@ * C++ layer when passed as a parameter to a wrapped function. * ----------------------------------------------------------------------------- */ -#define %argument_fail(code, type, name, argn) scheme_wrong_type(FUNC_NAME, type, argn, argc, argv); -#define %set_output(obj) $result = obj - %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); diff --git a/Lib/mzscheme/typemaps.i b/Lib/mzscheme/typemaps.i index ebd0f28da..25c7b7707 100644 --- a/Lib/mzscheme/typemaps.i +++ b/Lib/mzscheme/typemaps.i @@ -4,7 +4,7 @@ #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 %argument_fail(code, type, name, argn) scheme_wrong_type(FUNC_NAME, type, argn, argc, argv) #define %as_voidptr(ptr) (void*)(ptr) @@ -72,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 && { @@ -111,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 */ @@ -278,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;"; diff --git a/Lib/ocaml/ocaml.swg b/Lib/ocaml/ocaml.swg index ef0a64c90..703b7e448 100644 --- a/Lib/ocaml/ocaml.swg +++ b/Lib/ocaml/ocaml.swg @@ -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)); @@ -188,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> @@ -310,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 } diff --git a/Lib/octave/octrun.swg b/Lib/octave/octrun.swg index 71a907f9b..2973318c4 100644 --- a/Lib/octave/octrun.swg +++ b/Lib/octave/octrun.swg @@ -1547,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) { diff --git a/Lib/php/const.i b/Lib/php/const.i index 33060dc04..a74af0d78 100644 --- a/Lib/php/const.i +++ b/Lib/php/const.i @@ -54,7 +54,7 @@ } %} -%typemap(classconsttab) SWIGTYPE (CLASS::*) ""; +%typemap(classconsttab) SWIGTYPE (CLASS::*) "" %typemap(consttab) int, unsigned int, @@ -100,4 +100,4 @@ } /* Handled as a global variable. */ -%typemap(consttab) SWIGTYPE (CLASS::*) ""; +%typemap(consttab) SWIGTYPE (CLASS::*) "" diff --git a/Lib/php/php.swg b/Lib/php/php.swg index c2442d24b..04b7075b7 100644 --- a/Lib/php/php.swg +++ b/Lib/php/php.swg @@ -125,14 +125,31 @@ swig_acquire_ownership_obj((void*)$result, own); %} -%typemap(in, phptype="SWIGTYPE") SWIGTYPE &, - SWIGTYPE && +%typemap(in, phptype="SWIGTYPE") SWIGTYPE & %{ if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); return; } %} +%typemap(in, 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) { + zend_type_error("Cannot release ownership as memory is not owned for argument $argnum of $1_descriptor of $symname"); + return; + } else { + zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); + return; + } + } + if (!argp) { + zend_type_error("Invalid null reference for argument $argnum of $1_descriptor of $symname"); + return; + } + $1 = ($1_ltype)argp; + rvrdeleter.reset($1); +%} %typemap(directorout) SWIGTYPE & ($1_ltype tmp), SWIGTYPE && ($1_ltype tmp) @@ -457,7 +474,7 @@ SWIG_SetPointerZval($input, SWIG_as_voidptr(new $1_ltype(SWIG_STD_MOVE($1))), $&1_descriptor, 1); %} -%typemap(out, phptype="void") void ""; +%typemap(out, phptype="void") void "" %typemap(out, phptype="string") char [ANY] { diff --git a/Lib/php/std_auto_ptr.i b/Lib/php/std_auto_ptr.i index 7df497e60..bd07dbdb5 100644 --- a/Lib/php/std_auto_ptr.i +++ b/Lib/php/std_auto_ptr.i @@ -13,10 +13,10 @@ res = SWIG_ConvertPtr(&$input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE); if (!SWIG_IsOK(res)) { if (res == SWIG_ERROR_RELEASE_NOT_OWNED) { - zend_type_error("Cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *' of $symname"); + zend_type_error("Cannot release ownership as memory is not owned for argument $argnum of $descriptor(TYPE *) of $symname"); return; } else { - zend_type_error("Expected TYPE * for argument $argnum of $symname"); + zend_type_error("Expected $descriptor(TYPE *) for argument $argnum of $symname"); return; } } diff --git a/Lib/php/std_string.i b/Lib/php/std_string.i index 8882c0abe..b2039786c 100644 --- a/Lib/php/std_string.i +++ b/Lib/php/std_string.i @@ -86,5 +86,5 @@ namespace std { /* SWIG will apply the non-const typemap above to const string& without * this more specific typemap. */ - %typemap(argout) const string & ""; + %typemap(argout) const string & "" } diff --git a/Lib/php/std_unique_ptr.i b/Lib/php/std_unique_ptr.i index 591f580cb..168273663 100644 --- a/Lib/php/std_unique_ptr.i +++ b/Lib/php/std_unique_ptr.i @@ -13,10 +13,10 @@ res = SWIG_ConvertPtr(&$input, &argp, $descriptor(TYPE *), SWIG_POINTER_RELEASE); if (!SWIG_IsOK(res)) { if (res == SWIG_ERROR_RELEASE_NOT_OWNED) { - zend_type_error("Cannot release ownership as memory is not owned for argument $argnum of type 'TYPE *' of $symname"); + zend_type_error("Cannot release ownership as memory is not owned for argument $argnum of $descriptor(TYPE *) of $symname"); return; } else { - zend_type_error("Expected TYPE * for argument $argnum of $symname"); + zend_type_error("Expected $descriptor(TYPE *) for argument $argnum of $symname"); return; } } diff --git a/Lib/php/typemaps.i b/Lib/php/typemaps.i index 2f7819097..718469edc 100644 --- a/Lib/php/typemaps.i +++ b/Lib/php/typemaps.i @@ -31,8 +31,8 @@ temp = (Z_TYPE($input) == IS_TRUE); $1 = &temp; %} -%typemap(argout) TYPE *INPUT, TYPE &INPUT ""; -%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;"; +%typemap(argout) TYPE *INPUT, TYPE &INPUT "" +%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;" %typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT { zval o; @@ -57,8 +57,8 @@ temp = (TYPE) zval_get_double(&$input); $1 = &temp; %} -%typemap(argout) TYPE *INPUT, TYPE &INPUT ""; -%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;"; +%typemap(argout) TYPE *INPUT, TYPE &INPUT "" +%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;" %typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT { zval o; @@ -82,8 +82,8 @@ temp = (TYPE) zval_get_long(&$input); $1 = &temp; %} -%typemap(argout) TYPE *INPUT, TYPE &INPUT ""; -%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;"; +%typemap(argout) TYPE *INPUT, TYPE &INPUT "" +%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;" %typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT { zval o; diff --git a/Lib/python/pyclasses.swg b/Lib/python/pyclasses.swg index 9d6299ff1..31ebdd2a1 100644 --- a/Lib/python/pyclasses.swg +++ b/Lib/python/pyclasses.swg @@ -43,7 +43,7 @@ namespace swig { %apply PyObject * {SwigPtr_PyObject}; %apply PyObject * const& {SwigPtr_PyObject const&}; - %typemap(typecheck,precedence=SWIG_TYPECHECK_SWIGOBJECT,noblock=1) SwigPtr_PyObject const& "$1 = ($input != 0);"; + %typemap(typecheck,precedence=SWIG_TYPECHECK_SWIGOBJECT,noblock=1) SwigPtr_PyObject const& "$1 = ($input != 0);" /* For output */ diff --git a/Lib/python/pydocs.swg b/Lib/python/pydocs.swg index 1eea41b8d..5a25423d4 100644 --- a/Lib/python/pydocs.swg +++ b/Lib/python/pydocs.swg @@ -2,43 +2,43 @@ // Documentation for use with the autodoc feature. #ifdef SWIG_DOC_DOXYGEN_STYLE -%typemap(doc) SWIGTYPE "@param $1_name $1_type"; -%typemap(doc) SWIGTYPE * "@param $1_name $1_type"; -%typemap(doc) const SWIGTYPE & "@param $1_name $1_type"; -%typemap(doc) const SWIGTYPE && "@param $1_name $1_type"; -%typemap(doc) enum SWIGTYPE "@param $1_name enum $1_type"; - -%typemap(doc) SWIGTYPE *INOUT, SWIGTYPE &INOUT "@param $1_name $1_type (input/output)"; -%typemap(doc) SWIGTYPE *INPUT, SWIGTYPE &INPUT "@param $1_name $1_type (input)"; -%typemap(doc) SWIGTYPE *OUTPUT, SWIGTYPE &OUTPUT "@param $1_name $1_type (output)"; +%typemap(doc) SWIGTYPE "@param $1_name $1_type" +%typemap(doc) SWIGTYPE * "@param $1_name $1_type" +%typemap(doc) const SWIGTYPE & "@param $1_name $1_type" +%typemap(doc) const SWIGTYPE && "@param $1_name $1_type" +%typemap(doc) enum SWIGTYPE "@param $1_name enum $1_type" + +%typemap(doc) SWIGTYPE *INOUT, SWIGTYPE &INOUT "@param $1_name $1_type (input/output)" +%typemap(doc) SWIGTYPE *INPUT, SWIGTYPE &INPUT "@param $1_name $1_type (input)" +%typemap(doc) SWIGTYPE *OUTPUT, SWIGTYPE &OUTPUT "@param $1_name $1_type (output)" #else -%typemap(doc) SWIGTYPE "$1_name: $1_type"; -%typemap(doc) SWIGTYPE * "$1_name: $1_type"; -%typemap(doc) const SWIGTYPE & "$1_name: $1_type"; -%typemap(doc) const SWIGTYPE && "$1_name: $1_type"; -%typemap(doc) enum SWIGTYPE "$1_name: enum $1_type"; - -%typemap(doc) SWIGTYPE *INOUT, SWIGTYPE &INOUT "$1_name: $1_type (input/output)"; -%typemap(doc) SWIGTYPE *INPUT, SWIGTYPE &INPUT "$1_name: $1_type (input)"; -%typemap(doc) SWIGTYPE *OUTPUT, SWIGTYPE &OUTPUT "$1_name: $1_type (output)"; +%typemap(doc) SWIGTYPE "$1_name: $1_type" +%typemap(doc) SWIGTYPE * "$1_name: $1_type" +%typemap(doc) const SWIGTYPE & "$1_name: $1_type" +%typemap(doc) const SWIGTYPE && "$1_name: $1_type" +%typemap(doc) enum SWIGTYPE "$1_name: enum $1_type" + +%typemap(doc) SWIGTYPE *INOUT, SWIGTYPE &INOUT "$1_name: $1_type (input/output)" +%typemap(doc) SWIGTYPE *INPUT, SWIGTYPE &INPUT "$1_name: $1_type (input)" +%typemap(doc) SWIGTYPE *OUTPUT, SWIGTYPE &OUTPUT "$1_name: $1_type (output)" #endif // Types to use in Python documentation for the parameters of the given C++ type. -%typemap(doctype) bool "boolean"; +%typemap(doctype) bool "boolean" %define int_doctype_for_cppint_type(cppint_type) - %typemap(doctype) cppint_type, unsigned cppint_type "int"; + %typemap(doctype) cppint_type, unsigned cppint_type "int" %enddef %formacro(int_doctype_for_cppint_type, short, int, long, long long) -%typemap(doctype) size_t "int"; +%typemap(doctype) size_t "int" -%typemap(doctype) enum SWIGTYPE "int"; +%typemap(doctype) enum SWIGTYPE "int" -%typemap(doctype) float, double, long double "float"; +%typemap(doctype) float, double, long double "float" -%typemap(doctype) char*, std::string "string"; +%typemap(doctype) char*, std::string "string" %typemap(doctype) SWIGTYPE "$1_basetype" %typemap(doctype) SWIGTYPE * "$typemap(doctype, $*1_ltype)" diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index 0eda17cda..0ae25a686 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -83,7 +83,7 @@ { SWIG_PY_POINTER, "$symname", 0, 0, (void *)($value), &$descriptor } %typemap(consttab) SWIGTYPE ((* const)(ANY)) = SWIGTYPE ((*)(ANY)); -%typemap(constcode) SWIGTYPE ((*)(ANY)) ""; +%typemap(constcode) SWIGTYPE ((*)(ANY)) "" %typemap(constcode) SWIGTYPE ((* const)(ANY)) = SWIGTYPE ((*)(ANY)); diff --git a/Lib/r/r.swg b/Lib/r/r.swg index 8cf8cdf53..b1962e5ea 100644 --- a/Lib/r/r.swg +++ b/Lib/r/r.swg @@ -53,7 +53,7 @@ SWIG_InitializeModule(0); assert(all(sapply($input, class) == "$R_class")); %} -%typemap(out) void ""; +%typemap(out) void "" %typemap(in) int *, int[ANY], signed int *, signed int[ANY], diff --git a/Lib/r/rtype.swg b/Lib/r/rtype.swg index 8fe12230b..41f0affe1 100644 --- a/Lib/r/rtype.swg +++ b/Lib/r/rtype.swg @@ -3,26 +3,26 @@ for use in class representations. */ -%typemap("rtype") int, int *, int & "integer"; -%typemap("rtype") long, long *, long & "integer"; -%typemap("rtype") float, float*, float & "numeric"; -%typemap("rtype") double, double*, double & "numeric"; -%typemap("rtype") char *, char ** "character"; -%typemap("rtype") char "character"; -%typemap("rtype") string, string *, string & "character"; -%typemap("rtype") std::string, std::string *, std::string & "character"; -%typemap("rtype") bool, bool * "logical"; -%typemap("rtype") enum SWIGTYPE "character"; -%typemap("rtype") enum SWIGTYPE * "character"; -%typemap("rtype") enum SWIGTYPE *const "character"; -%typemap("rtype") enum SWIGTYPE & "character"; -%typemap("rtype") const enum SWIGTYPE & "character"; -%typemap("rtype") enum SWIGTYPE && "character"; -%typemap("rtype") SWIGTYPE * "$R_class"; -%typemap("rtype") SWIGTYPE *const "$R_class"; -%typemap("rtype") SWIGTYPE & "$R_class"; -%typemap("rtype") SWIGTYPE && "$R_class"; -%typemap("rtype") SWIGTYPE "$&R_class"; +%typemap("rtype") int, int *, int & "integer" +%typemap("rtype") long, long *, long & "integer" +%typemap("rtype") float, float*, float & "numeric" +%typemap("rtype") double, double*, double & "numeric" +%typemap("rtype") char *, char ** "character" +%typemap("rtype") char "character" +%typemap("rtype") string, string *, string & "character" +%typemap("rtype") std::string, std::string *, std::string & "character" +%typemap("rtype") bool, bool * "logical" +%typemap("rtype") enum SWIGTYPE "character" +%typemap("rtype") enum SWIGTYPE * "character" +%typemap("rtype") enum SWIGTYPE *const "character" +%typemap("rtype") enum SWIGTYPE & "character" +%typemap("rtype") const enum SWIGTYPE & "character" +%typemap("rtype") enum SWIGTYPE && "character" +%typemap("rtype") SWIGTYPE * "$R_class" +%typemap("rtype") SWIGTYPE *const "$R_class" +%typemap("rtype") SWIGTYPE & "$R_class" +%typemap("rtype") SWIGTYPE && "$R_class" +%typemap("rtype") SWIGTYPE "$&R_class" %typemap("rtypecheck") int, int &, long, long & %{ (is.integer($arg) || is.numeric($arg)) && length($arg) == 1 %} diff --git a/Lib/r/std_vector.i b/Lib/r/std_vector.i index 4ec51dc91..93d1c6256 100644 --- a/Lib/r/std_vector.i +++ b/Lib/r/std_vector.i @@ -841,7 +841,7 @@ %typemap("rtypecheck") std::vector<double>, std::vector<double> *, std::vector<double> & %{ is.numeric($arg) %} %typemap("rtype") std::vector<double> "numeric" -%typemap("scoercein") std::vector<double>, std::vector<double> *, std::vector<double> & "$input = as.numeric($input);"; +%typemap("scoercein") std::vector<double>, std::vector<double> *, std::vector<double> & "$input = as.numeric($input);" %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<float>) %traits_type_name(std::vector<float>) @@ -857,7 +857,7 @@ %typemap("rtypecheck") std::vector<bool>, std::vector<bool> *, std::vector<bool> & %{ is.logical($arg) %} %typemap("rtype") std::vector<bool> "logical" -%typemap("scoercein") std::vector<bool> , std::vector<bool> & "$input = as.logical($input);"; +%typemap("scoercein") std::vector<bool> , std::vector<bool> & "$input = as.logical($input);" %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<int>); @@ -866,7 +866,7 @@ %{ is.integer($arg) || is.numeric($arg) %} %typemap("rtype") std::vector<int> "integer" -%typemap("scoercein") std::vector<int> , std::vector<int> *, std::vector<int> & "$input = as.integer($input);"; +%typemap("scoercein") std::vector<int> , std::vector<int> *, std::vector<int> & "$input = as.integer($input);" // strings %typemap("rtype") std::vector< std::basic_string<char> >, @@ -974,21 +974,21 @@ std::vector< std::basic_string<char> > *, %typemap("rtypecheck") std::vector<std::vector<int> >, std::vector<std::vector<int> > *, std::vector<std::vector<int> > & %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} %typemap("rtype") std::vector<std::vector<int> >, std::vector<std::vector<int> > *, std::vector<std::vector<int> > & "list" -%typemap("scoercein") std::vector< std::vector<int> >, std::vector<std::vector<int> > *, std::vector<std::vector<int> > & "$input = lapply($input, as.integer);"; +%typemap("scoercein") std::vector< std::vector<int> >, std::vector<std::vector<int> > *, std::vector<std::vector<int> > & "$input = lapply($input, as.integer);" %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<unsigned int> >); %traits_type_name(std::vector< std::vector<unsigned int> >); %typemap("rtypecheck") std::vector<std::vector<unsigned int> >, std::vector<std::vector<unsigned int> > *, std::vector<std::vector<unsigned int> > & %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} %typemap("rtype") std::vector<std::vector<unsigned int> >, std::vector<std::vector<unsigned int> > *, std::vector<std::vector<unsigned int> > & "list" -%typemap("scoercein") std::vector< std::vector<unsigned int> >, std::vector<std::vector<int> > *, std::vector<std::vector<unsigned int> > & "$input = lapply($input, as.integer);"; +%typemap("scoercein") std::vector< std::vector<unsigned int> >, std::vector<std::vector<int> > *, std::vector<std::vector<unsigned int> > & "$input = lapply($input, as.integer);" %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<float> >); %traits_type_name(std::vector< std::vector<float> >); %typemap("rtypecheck") std::vector<std::vector<float> >, std::vector<std::vector<float> > *, std::vector<std::vector<float> > & %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} %typemap("rtype") std::vector<std::vector<float> >, std::vector<std::vector<float> > *, std::vector<std::vector<float> > "list" -%typemap("scoercein") std::vector< std::vector<float> >, std::vector<std::vector<float> > *, std::vector<std::vector<float> > & "$input = lapply($input, as.numeric);"; +%typemap("scoercein") std::vector< std::vector<float> >, std::vector<std::vector<float> > *, std::vector<std::vector<float> > & "$input = lapply($input, as.numeric);" %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<std::vector<double> >); %traits_type_name(std::vector< std::vector<double> >); @@ -1003,7 +1003,7 @@ std::vector< std::basic_string<char> > *, %typemap("rtypecheck") std::vector<std::vector<bool> >, std::vector<std::vector<bool> > *, std::vector<std::vector<bool> > & %{ is.list($arg) && all(sapply($arg , is.integer) || sapply($arg, is.numeric)) %} %typemap("rtype") std::vector<std::vector<bool> >, std::vector<std::vector<bool> > *, std::vector<std::vector<bool> > & "list" -%typemap("scoercein") std::vector< std::vector<bool> >, std::vector<std::vector<bool> > *, std::vector<std::vector<bool> > & "$input = lapply($input, as.logical);"; +%typemap("scoercein") std::vector< std::vector<bool> >, std::vector<std::vector<bool> > *, std::vector<std::vector<bool> > & "$input = lapply($input, as.logical);" // we don't want these to be given R classes as they // have already been turned into R vectors. diff --git a/Lib/ruby/typemaps.i b/Lib/ruby/typemaps.i index 1d28b1318..683436469 100644 --- a/Lib/ruby/typemaps.i +++ b/Lib/ruby/typemaps.i @@ -139,7 +139,7 @@ output values. */ %define OUTPUT_TYPEMAP(type, converter, convtype) -%typemap(in,numinputs=0) type *OUTPUT($*1_ltype temp), type &OUTPUT($*1_ltype temp) "$1 = &temp;"; +%typemap(in,numinputs=0) type *OUTPUT($*1_ltype temp), type &OUTPUT($*1_ltype temp) "$1 = &temp;" %typemap(argout, fragment="output_helper") type *OUTPUT, type &OUTPUT { VALUE o = converter(convtype (*$1)); $result = output_helper($result, o); @@ -161,7 +161,7 @@ OUTPUT_TYPEMAP(double, rb_float_new, (double)); #undef OUTPUT_TYPEMAP -%typemap(in,numinputs=0) bool *OUTPUT(bool temp), bool &OUTPUT(bool temp) "$1 = &temp;"; +%typemap(in,numinputs=0) bool *OUTPUT(bool temp), bool &OUTPUT(bool temp) "$1 = &temp;" %typemap(argout, fragment="output_helper") bool *OUTPUT, bool &OUTPUT { VALUE o = (*$1) ? Qtrue : Qfalse; $result = output_helper($result, o); diff --git a/Lib/swig.swg b/Lib/swig.swg index c9b301426..9148c9153 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -448,9 +448,9 @@ namespace std { /* Set up the typemap for handling new return strings */ #ifdef __cplusplus -%typemap(newfree) char * "delete [] $1;"; +%typemap(newfree) char * "delete [] $1;" #else -%typemap(newfree) char * "free($1);"; +%typemap(newfree) char * "free($1);" #endif /* Default typemap for handling char * members */ diff --git a/Lib/typemaps/cstrings.swg b/Lib/typemaps/cstrings.swg index 0aca61101..42ce4d9bb 100644 --- a/Lib/typemaps/cstrings.swg +++ b/Lib/typemaps/cstrings.swg @@ -59,7 +59,7 @@ %typemap(in,noblock=1,numinputs=0) TYPEMAP (Char temp[MAX+1]) { $1 = ($1_ltype) temp; } -%typemap(freearg,match="in") TYPEMAP ""; +%typemap(freearg,match="in") TYPEMAP "" %typemap(argout,noblock=1,fragment= #SWIG_FromCharPtr ) TYPEMAP { $1[MAX] = 0; %append_output(SWIG_FromCharPtr($1)); @@ -85,7 +85,7 @@ %typemap(in,noblock=1,numinputs=0) TYPEMAP(Char temp[SIZE]) { $1 = ($1_ltype) temp; } -%typemap(freearg,match="in") TYPEMAP ""; +%typemap(freearg,match="in") TYPEMAP "" %typemap(argout,noblock=1,fragment= #SWIG_FromCharPtrAndSize) TYPEMAP { %append_output(SWIG_FromCharPtrAndSize($1,SIZE)); } @@ -122,7 +122,7 @@ temp[n - 1] = 0; $1 = ($1_ltype) temp; } -%typemap(freearg,match="in") TYPEMAP ""; +%typemap(freearg,match="in") TYPEMAP "" %typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP { $1[MAX] = 0; %append_output(SWIG_FromCharPtr($1)); @@ -160,7 +160,7 @@ if (alloc == SWIG_NEWOBJ) %delete_array(t); $1[n-1] = 0; } -%typemap(freearg,match="in") TYPEMAP ""; +%typemap(freearg,match="in") TYPEMAP "" %typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP { %append_output(SWIG_FromCharPtr($1)); %delete_array($1); @@ -247,7 +247,7 @@ %typemap(in,noblock=1,numinputs=0) TYPEMAP($*1_ltype temp = 0) { $1 = &temp; } -%typemap(freearg,match="in") TYPEMAP ""; +%typemap(freearg,match="in") TYPEMAP "" %typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP { if (*$1) { %append_output(SWIG_FromCharPtr(*$1)); @@ -275,7 +275,7 @@ %typemap(in,noblock=1,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) { $1 = &temp; $2 = &tempn; } -%typemap(freearg,match="in") (TYPEMAP,SIZE) ""; +%typemap(freearg,match="in") (TYPEMAP,SIZE) "" %typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize)(TYPEMAP,SIZE) { if (*$1) { %append_output(SWIG_FromCharPtrAndSize(*$1,*$2)); diff --git a/Lib/typemaps/ptrtypes.swg b/Lib/typemaps/ptrtypes.swg index e8439e6dc..ca54fcdc2 100644 --- a/Lib/typemaps/ptrtypes.swg +++ b/Lib/typemaps/ptrtypes.swg @@ -35,7 +35,7 @@ $1 = *ptr; if (SWIG_IsNewObj(res)) %delete(ptr); } - %typemap(freearg) Type ""; + %typemap(freearg) Type "" %typemap(in,fragment=frag) const Type & (int res = SWIG_OLDOBJ) { Type *ptr = (Type *)0; res = asptr_meth($input, &ptr); diff --git a/Lib/typemaps/strings.swg b/Lib/typemaps/strings.swg index 5dd57b93d..1237d98df 100644 --- a/Lib/typemaps/strings.swg +++ b/Lib/typemaps/strings.swg @@ -266,7 +266,7 @@ } $1 = %reinterpret_cast(temp, $1_ltype); } -%typemap(freearg) Char [ANY], const Char [ANY] ""; +%typemap(freearg) Char [ANY], const Char [ANY] "" %typemap(in,noblock=1,fragment=#SWIG_AsCharArray) const Char (&)[ANY] (Char temp[$1_dim0], int res) { @@ -276,7 +276,7 @@ } $1 = &temp; } -%typemap(freearg) const Char (&)[ANY] ""; +%typemap(freearg) const Char (&)[ANY] "" %typemap(out,fragment=#SWIG_FromCharPtrAndSize,fragment=#SWIG_CharBufLen) Char [ANY], const Char[ANY] diff --git a/Lib/typemaps/swigobject.swg b/Lib/typemaps/swigobject.swg index b1e6dc9d8..26c6ba8ed 100644 --- a/Lib/typemaps/swigobject.swg +++ b/Lib/typemaps/swigobject.swg @@ -2,7 +2,7 @@ * Language Object * - Just pass straight through unmodified * ------------------------------------------------------------ */ -%typemap(in) SWIG_Object "$1 = $input;"; +%typemap(in) SWIG_Object "$1 = $input;" %typemap(in,noblock=1) SWIG_Object const & ($*ltype temp) { @@ -30,8 +30,8 @@ #if defined(SWIG_DIRECTOR_TYPEMAPS) -%typemap(directorin) SWIG_Object "$input = $1;"; -%typemap(directorout) SWIG_Object "$result = $input;"; +%typemap(directorin) SWIG_Object "$input = $1;" +%typemap(directorout) SWIG_Object "$result = $input;" #endif /* SWIG_DIRECTOR_TYPEMAPS */ diff --git a/Lib/typemaps/swigtype.swg b/Lib/typemaps/swigtype.swg index 52fac3252..42c9c54eb 100644 --- a/Lib/typemaps/swigtype.swg +++ b/Lib/typemaps/swigtype.swg @@ -9,7 +9,7 @@ } $1 = %reinterpret_cast(argp, $ltype); } -%typemap(freearg) SWIGTYPE * ""; +%typemap(freearg) SWIGTYPE * "" %typemap(in, noblock=1) SWIGTYPE [] (void *argp = 0, int res = 0) { res = SWIG_ConvertPtr($input, &argp,$descriptor, $disown | %convertptr_flags); @@ -18,7 +18,7 @@ } $1 = %reinterpret_cast(argp, $ltype); } -%typemap(freearg) SWIGTYPE [] ""; +%typemap(freearg) SWIGTYPE [] "" %typemap(in, noblock=1) SWIGTYPE *const& (void *argp = 0, int res = 0, $*1_ltype temp) { @@ -29,7 +29,7 @@ temp = %reinterpret_cast(argp, $*ltype); $1 = %reinterpret_cast(&temp, $1_ltype); } -%typemap(freearg) SWIGTYPE *const& ""; +%typemap(freearg) SWIGTYPE *const& "" /* Reference */ @@ -41,7 +41,7 @@ if (!argp) { %argument_nullref("$type", $symname, $argnum); } $1 = %reinterpret_cast(argp, $ltype); } -%typemap(freearg) SWIGTYPE & ""; +%typemap(freearg) SWIGTYPE & "" #if defined(__cplusplus) && defined(%implicitconv_flag) %typemap(in,noblock=1,implicitconv=1) const SWIGTYPE & (void *argp = 0, int res = 0) { @@ -56,51 +56,23 @@ { if (SWIG_IsNewObj(res$argnum)) %delete($1); } -#else -%typemap(in,noblock=1) const SWIGTYPE & (void *argp, int res = 0) { - res = SWIG_ConvertPtr($input, &argp, $descriptor, %convertptr_flags); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (!argp) { %argument_nullref("$type", $symname, $argnum); } - $1 = %reinterpret_cast(argp, $ltype); -} #endif /* Rvalue reference */ -%typemap(in, noblock=1) SWIGTYPE && (void *argp = 0, int res = 0) { - res = SWIG_ConvertPtr($input, &argp, $descriptor, %convertptr_flags); +%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 | %convertptr_flags); if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (!argp) { %argument_nullref("$type", $symname, $argnum); } - $1 = %reinterpret_cast(argp, $ltype); -} -%typemap(freearg) SWIGTYPE && ""; - -#if defined(__cplusplus) && defined(%implicitconv_flag) -%typemap(in,noblock=1,implicitconv=1) const SWIGTYPE && (void *argp = 0, int res = 0) { - res = SWIG_ConvertPtr($input, &argp, $descriptor, %convertptr_flags | %implicitconv_flag); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); - } - if (!argp) { %argument_nullref("$type", $symname, $argnum); } - $1 = %reinterpret_cast(argp, $ltype); -} -%typemap(freearg,noblock=1,match="in",implicitconv=1) const SWIGTYPE && -{ - if (SWIG_IsNewObj(res$argnum)) %delete($1); -} -#else -%typemap(in,noblock=1) const SWIGTYPE && (void *argp, int res = 0) { - res = SWIG_ConvertPtr($input, &argp, $descriptor, %convertptr_flags); - if (!SWIG_IsOK(res)) { - %argument_fail(res, "$type", $symname, $argnum); + if (res == SWIG_ERROR_RELEASE_NOT_OWNED) { + %releasenotowned_fail(res, "$type", $symname, $argnum); + } else { + %argument_fail(res, "$type", $symname, $argnum); + } } if (!argp) { %argument_nullref("$type", $symname, $argnum); } $1 = %reinterpret_cast(argp, $ltype); + rvrdeleter.reset($1); } -#endif +%typemap(freearg) SWIGTYPE && "" /* By value */ #if defined(__cplusplus) && defined(%implicitconv_flag) @@ -395,6 +367,7 @@ int res = SWIG_ConvertPtr($input, &vptr, $descriptor, SWIG_POINTER_NO_NULL); $1 = SWIG_CheckState(res); } + %typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER,noblock=1) const SWIGTYPE && { void *vptr = 0; int res = SWIG_ConvertPtr($input, &vptr, $descriptor, SWIG_POINTER_NO_NULL); diff --git a/Lib/typemaps/valtypes.swg b/Lib/typemaps/valtypes.swg index 11eac5985..f2f34acfc 100644 --- a/Lib/typemaps/valtypes.swg +++ b/Lib/typemaps/valtypes.swg @@ -38,7 +38,7 @@ } $1 = %static_cast(val,$ltype); } - %typemap(freearg) Type ""; + %typemap(freearg) Type "" %typemap(in,noblock=1,fragment=frag) const Type & ($*ltype temp, Type val, int ecode = 0) { ecode = asval_meth($input, &val); if (!SWIG_IsOK(ecode)) { @@ -47,7 +47,7 @@ temp = %static_cast(val, $*ltype); $1 = &temp; } - %typemap(freearg) const Type& ""; + %typemap(freearg) const Type& "" %enddef /* out */ diff --git a/Lib/typemaps/void.swg b/Lib/typemaps/void.swg index bbd68ed87..795992bf4 100644 --- a/Lib/typemaps/void.swg +++ b/Lib/typemaps/void.swg @@ -10,7 +10,7 @@ %argument_fail(res, "$type", $symname, $argnum); } } -%typemap(freearg) void * ""; +%typemap(freearg) void * "" %typemap(in,noblock=1) void * const& ($*ltype temp = 0, int res) { res = SWIG_ConvertPtr($input, %as_voidptrptr(&temp), 0, $disown); @@ -19,7 +19,7 @@ } $1 = &temp; } -%typemap(freearg) void * const& ""; +%typemap(freearg) void * const& "" /* out */ |