Update swig, fix warnings, upgrade to 4.1.0 release (#315)

This commit is contained in:
James Chen 2022-11-18 09:48:59 +08:00 committed by GitHub
parent 16e8e7f1ea
commit 749af5630c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
498 changed files with 9120 additions and 5058 deletions

Binary file not shown.

View File

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

View File

@ -1,294 +0,0 @@
/* Define a C preprocessor symbol that can be used in interface files
to distinguish between the SWIG language modules. */
#define SWIG_CFFI
/* Typespecs for basic types. */
%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) 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) 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) float ":float";
%typemap(cin) double ":double";
%typemap(cin) SWIGTYPE ":pointer";
%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) 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) 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) float ":float";
%typemap(cout) double ":double";
%typemap(cout) SWIGTYPE ":pointer";
%typemap(ctype) bool "int";
%typemap(ctype) char, unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
long, signed long, unsigned long,
float, double, long double, char *, void *, void,
enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1_ltype";
%typemap(ctype) SWIGTYPE "$&1_type";
%typemap(in) bool "$1 = (bool)$input;";
%typemap(in) char, unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
long, signed long, unsigned long,
float, double, long double, char *, void *, void,
enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$1 = $input;";
%typemap(in) SWIGTYPE "$1 = *$input;";
%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,
long, signed long, unsigned long,
float, double, long double, char *, void *,
enum SWIGTYPE, SWIGTYPE *,
SWIGTYPE[ANY], SWIGTYPE &, SWIGTYPE && "$result = $1;";
#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
%typecheck(SWIG_TYPECHECK_BOOL) bool { $1 = 1; };
%typecheck(SWIG_TYPECHECK_CHAR) char { $1 = 1; };
%typecheck(SWIG_TYPECHECK_FLOAT) float { $1 = 1; };
%typecheck(SWIG_TYPECHECK_DOUBLE) double { $1 = 1; };
%typecheck(SWIG_TYPECHECK_STRING) char * { $1 = 1; };
%typecheck(SWIG_TYPECHECK_INTEGER)
unsigned char, signed char,
short, signed short, unsigned short,
int, signed int, unsigned int,
long, signed long, unsigned long,
enum SWIGTYPE { $1 = 1; };
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&,
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(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";
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) }
/* const pointers */
%apply SWIGTYPE * { SWIGTYPE *const }
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
%{
#ifdef __cplusplus
# define EXTERN extern "C"
#else
# define EXTERN extern
#endif
#define EXPORT EXTERN SWIGEXPORT
#include <string.h>
%}
%insert("swiglisp") %{
;;;SWIG wrapper code starts here
(cl:defmacro defanonenum (cl:&body enums)
"Converts anonymous enums to defconstants."
`(cl:progn ,@(cl:loop for value in enums
for index = 0 then (cl:1+ index)
when (cl:listp value) do (cl:setf index (cl:second value)
value (cl:first value))
collect `(cl:defconstant ,value ,index))))
(cl:eval-when (:compile-toplevel :load-toplevel)
(cl:unless (cl:fboundp 'swig-lispify)
(cl:defun swig-lispify (name flag cl:&optional (package cl:*package*))
(cl:labels ((helper (lst last rest cl:&aux (c (cl:car lst)))
(cl:cond
((cl:null lst)
rest)
((cl:upper-case-p c)
(helper (cl:cdr lst) 'upper
(cl:case last
((lower digit) (cl:list* c #\- rest))
(cl:t (cl:cons c rest)))))
((cl:lower-case-p c)
(helper (cl:cdr lst) 'lower (cl:cons (cl:char-upcase c) rest)))
((cl:digit-char-p c)
(helper (cl:cdr lst) 'digit
(cl:case last
((upper lower) (cl:list* c #\- rest))
(cl:t (cl:cons c rest)))))
((cl:char-equal c #\_)
(helper (cl:cdr lst) '_ (cl:cons #\- rest)))
(cl:t
(cl:error "Invalid character: ~A" c)))))
(cl:let ((fix (cl:case flag
((constant enumvalue) "+")
(variable "*")
(cl:t ""))))
(cl:intern
(cl:concatenate
'cl:string
fix
(cl:nreverse (helper (cl:concatenate 'cl:list name) cl:nil cl:nil))
fix)
package))))))
;;;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. */
#ifdef __cplusplus
%rename(__add__) *::operator+;
%rename(__pos__) *::operator+();
%rename(__pos__) *::operator+() const;
%rename(__sub__) *::operator-;
%rename(__neg__) *::operator-() const;
%rename(__neg__) *::operator-();
%rename(__mul__) *::operator*;
%rename(__deref__) *::operator*();
%rename(__deref__) *::operator*() const;
%rename(__div__) *::operator/;
%rename(__mod__) *::operator%;
%rename(__logxor__) *::operator^;
%rename(__logand__) *::operator&;
%rename(__logior__) *::operator|;
%rename(__lognot__) *::operator~();
%rename(__lognot__) *::operator~() const;
%rename(__not__) *::operator!();
%rename(__not__) *::operator!() const;
%rename(__assign__) *::operator=;
%rename(__add_assign__) *::operator+=;
%rename(__sub_assign__) *::operator-=;
%rename(__mul_assign__) *::operator*=;
%rename(__div_assign__) *::operator/=;
%rename(__mod_assign__) *::operator%=;
%rename(__logxor_assign__) *::operator^=;
%rename(__logand_assign__) *::operator&=;
%rename(__logior_assign__) *::operator|=;
%rename(__lshift__) *::operator<<;
%rename(__lshift_assign__) *::operator<<=;
%rename(__rshift__) *::operator>>;
%rename(__rshift_assign__) *::operator>>=;
%rename(__eq__) *::operator==;
%rename(__ne__) *::operator!=;
%rename(__lt__) *::operator<;
%rename(__gt__) *::operator>;
%rename(__lte__) *::operator<=;
%rename(__gte__) *::operator>=;
%rename(__and__) *::operator&&;
%rename(__or__) *::operator||;
%rename(__preincr__) *::operator++();
%rename(__postincr__) *::operator++(int);
%rename(__predecr__) *::operator--();
%rename(__postdecr__) *::operator--(int);
%rename(__comma__) *::operator,();
%rename(__comma__) *::operator,() const;
%rename(__member_ref__) *::operator->;
%rename(__member_func_ref__) *::operator->*;
%rename(__funcall__) *::operator();
%rename(__aref__) *::operator[];
#endif
%{
#ifdef __cplusplus
# define EXTERN extern "C"
#else
# define EXTERN extern
#endif
#define EXPORT EXTERN SWIGEXPORT
#include <string.h>
#include <stdlib.h>
%}

View File

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

View File

@ -29,10 +29,10 @@
} }
$1 = *argp; %} $1 = *argp; %}
%typemap(out) CONST TYPE %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 %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 %typemap(directorout) CONST TYPE
%{ if (!$input) { %{ if (!$input) {
@ -122,7 +122,7 @@
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull) %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
%{ $1 = $input ? ($1_ltype)$input : &tempnull; %} %{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
%typemap(out, fragment="SWIG_null_deleter") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %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; %} if ($owner) delete $1; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %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 %typemap(out) SWIGTYPE
#ifdef __cplusplus #ifdef __cplusplus
%{ $result = new $1_ltype((const $1_ltype &)$1); %} %{ $result = new $1_ltype($1); %}
#else #else
{ {
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype)); $&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 #endif
%typemap(directorin) SWIGTYPE %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(csdirectorin) SWIGTYPE "new $&csclassname($iminput, true)"
%typemap(csdirectorout) SWIGTYPE "$&csclassname.getCPtr($cscall).Handle" %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; %typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if (!$1) { if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type is null", 0);
return $null; 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) { if (!$1) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type type is null", 0); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "$1_type is null", 0);
return $null; return $null;
} %} }
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE * %{ $result = (void *)$1; %} %typemap(out) SWIGTYPE * %{ $result = (void *)$1; %}
%typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{ %typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{
char buf[128]; char buf[128];
@ -613,7 +614,8 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
"$csinput" "$csinput"
%typemap(csin) char *, char *&, char[ANY], char[] "$csinput" %typemap(csin) char *, char *&, char[ANY], char[] "$csinput"
%typemap(csin) SWIGTYPE "$&csclassname.getCPtr($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)" %typemap(csin) SWIGTYPE (CLASS::*) "$csclassname.getCMemberPtr($csinput)"
/* The csout typemap is used for converting function return types from the return type /* 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) { 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; 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 // 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) { 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; 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 %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) { 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; 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::*) %{ %typemap(csbody) TYPE (CLASS::*) %{

View File

@ -16,7 +16,7 @@
%define SWIG_STD_ARRAY_INTERNAL(T, N) %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 %{ %proxycode %{
public $csclassname(global::System.Collections.ICollection c) : this() { public $csclassname(global::System.Collections.ICollection c) : this() {
if (c == null) if (c == null)

View File

@ -1,22 +1,35 @@
/* /* -----------------------------------------------------------------------------
The typemaps here allow handling functions returning std::auto_ptr<>, * std_auto_ptr.i
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 * SWIG library file for handling std::auto_ptr.
something else (e.g. use shared_ptr<> which SWIG supports fully). * 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) %define %auto_ptr(TYPE)
%typemap (ctype) std::auto_ptr< TYPE > "void *" %typemap (ctype) std::auto_ptr< TYPE > "void *"
%typemap (imtype, out="System.IntPtr") std::auto_ptr<TYPE > "HandleRef" %typemap (imtype, out="System.IntPtr") std::auto_ptr< TYPE > "global::System.Runtime.InteropServices.HandleRef"
%typemap (cstype) std::auto_ptr< TYPE > "$typemap(cstype, TYPE)" %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 > %{ %typemap (out) std::auto_ptr< TYPE > %{
$result = (void *)$1.release(); $result = (void *)$1.release();
%} %}
%typemap(csout, excode=SWIGEXCODE) std::auto_ptr< TYPE > { %typemap(csout, excode=SWIGEXCODE) std::auto_ptr< TYPE > {
System.IntPtr cPtr = $imcall; System.IntPtr cPtr = $imcall;
$typemap(cstype, TYPE) ret = (cPtr == System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode $typemap(cstype, TYPE) ret = (cPtr == System.IntPtr.Zero) ? null : new $typemap(cstype, TYPE)(cPtr, true);$excode
return ret; return ret;
} }
%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER, equivalent="TYPE *") std::auto_ptr< TYPE > ""
%template() std::auto_ptr< TYPE >; %template() std::auto_ptr< TYPE >;
%enddef %enddef

View File

@ -19,7 +19,7 @@
// MACRO for use within the std::list class body // MACRO for use within the std::list class body
%define SWIG_STD_LIST_MINIMUM_INTERNAL(CSINTERFACE, CTYPE...) %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 * }; %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 */ /* K is the C++ key type, T is the C++ value type */
%define SWIG_STD_MAP_INTERNAL(K, T, C) %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 %{ %proxycode %{
public $typemap(cstype, T) this[$typemap(cstype, K) key] { public $typemap(cstype, T) this[$typemap(cstype, K) key] {

View File

@ -28,7 +28,7 @@ namespace std {
template <class T> template <class T>
class set { 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 %{ %proxycode %{
void global::System.Collections.Generic.ICollection<$typemap(cstype, T)>.Add($typemap(cstype, T) item) { 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); ((global::System.Collections.Generic.ISet<$typemap(cstype, T)>)this).Add(item);

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 // MACRO for use within the std::vector class body
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE, CTYPE...) %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 %{ %proxycode %{
public $csclassname(global::System.Collections.IEnumerable c) : this() { public $csclassname(global::System.Collections.IEnumerable c) : this() {
if (c == null) if (c == null)

View File

@ -2,7 +2,9 @@
* std_wstring.i * std_wstring.i
* *
* Typemaps for std::wstring and const std::wstring& * 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 * To use non-const std::wstring references use the following %apply. Note
* that they are passed by value. * that they are passed by value.
@ -15,6 +17,28 @@
#include <string> #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 { namespace std {
%naturalvar wstring; %naturalvar wstring;
@ -22,31 +46,33 @@ namespace std {
class wstring; class wstring;
// wstring // wstring
%typemap(ctype, out="void *") wstring "wchar_t *" %typemap(ctype, out="void *") wstring "unsigned short *"
%typemap(imtype, %typemap(imtype,
inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]", 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" ) wstring "string"
%typemap(cstype) wstring "string" %typemap(cstype) wstring "string"
%typemap(csdirectorin) wstring "$iminput" %typemap(csdirectorin) wstring "$iminput"
%typemap(csdirectorout) wstring "$cscall" %typemap(csdirectorout) wstring "$cscall"
%typemap(in, canthrow=1) wstring %typemap(in, canthrow=1, fragment="Swig_csharp_UTF16ToWString") wstring
%{ if (!$input) { %{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0);
return $null; return $null;
} }
$1.assign($input); %} $1 = Swig_csharp_UTF16ToWString($input); %}
%typemap(out) wstring %{ $result = SWIG_csharp_wstring_callback($1.c_str()); %} %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) { %{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0);
return $null; 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(csin) wstring "$csinput"
%typemap(csout, excode=SWIGEXCODE) wstring { %typemap(csout, excode=SWIGEXCODE) wstring {
@ -57,29 +83,30 @@ class wstring;
%typemap(typecheck) wstring = wchar_t *; %typemap(typecheck) wstring = wchar_t *;
%typemap(throws, canthrow=1) wstring %typemap(throws, canthrow=1) wstring
%{ std::string message($1.begin(), $1.end()); %{ SWIG_csharp_ApplicationException_callback($1.c_str(), (int)$1.size());
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, message.c_str());
return $null; %} return $null; %}
// const wstring & // const wstring &
%typemap(ctype, out="void *") const wstring & "wchar_t *" %typemap(ctype, out="void *") const wstring & "unsigned short *"
%typemap(imtype, %typemap(imtype,
inattributes="[global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]", 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" ) const wstring & "string"
%typemap(cstype) const wstring & "string" %typemap(cstype) const wstring & "string"
%typemap(csdirectorin) const wstring & "$iminput" %typemap(csdirectorin) const wstring & "$iminput"
%typemap(csdirectorout) const wstring & "$cscall" %typemap(csdirectorout) const wstring & "$cscall"
%typemap(in, canthrow=1) const wstring & %typemap(in, canthrow=1, fragment="Swig_csharp_UTF16ToWString") const wstring &
%{ if (!$input) { %{ if (!$input) {
SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0); SWIG_CSharpSetPendingExceptionArgument(SWIG_CSharpArgumentNullException, "null wstring", 0);
return $null; return $null;
} }
std::wstring $1_str($input); std::wstring $1_str(Swig_csharp_UTF16ToWString($input));
$1 = &$1_str; %} $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(csin) const wstring & "$csinput"
%typemap(csout, excode=SWIGEXCODE) const wstring & { %typemap(csout, excode=SWIGEXCODE) const wstring & {
@ -94,10 +121,10 @@ class wstring;
} }
/* possible thread/reentrant code problem */ /* possible thread/reentrant code problem */
static std::wstring $1_str; static std::wstring $1_str;
$1_str = $input; $1_str = Swig_csharp_UTF16ToWString($input);
$result = &$1_str; %} $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 & %{ %typemap(csvarin, excode=SWIGEXCODE2) const wstring & %{
set { set {
@ -112,8 +139,7 @@ class wstring;
%typemap(typecheck) const wstring & = wchar_t *; %typemap(typecheck) const wstring & = wchar_t *;
%typemap(throws, canthrow=1) const wstring & %typemap(throws, canthrow=1) const wstring &
%{ std::string message($1.begin(), $1.end()); %{ SWIG_csharp_ApplicationException_callback($1.c_str(), (int)$1.size());
SWIG_CSharpSetPendingException(SWIG_CSharpApplicationException, message.c_str());
return $null; %} return $null; %}
} }

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,58 @@
* wchar.i * wchar.i
* *
* Typemaps for the wchar_t type * 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 * 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_NO_WSTRING_HELPER)
#if !defined(SWIG_CSHARP_WSTRING_HELPER_) #if !defined(SWIG_CSHARP_WSTRING_HELPER_)
#define SWIG_CSHARP_WSTRING_HELPER_ #define SWIG_CSHARP_WSTRING_HELPER_
%fragment("<wchar.h>"); // TODO: %fragment("<wchar.h", "runtime");
%insert(runtime) %{ %insert(runtime) %{
/* Callback for returning strings to C# without leaking memory */ /* Callback for returning strings to C# without leaking memory */
typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *); typedef void * (SWIGSTDCALL* SWIG_CSharpWStringHelperCallback)(const wchar_t *, int length);
static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL; 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=%{ %pragma(csharp) imclasscode=%{
protected class SWIGWStringHelper { protected class SWIGWStringHelper {
[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)] [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public delegate string SWIGWStringDelegate(global::System.IntPtr message); public delegate string SWIGWStringDelegate(global::System.IntPtr message, int length);
static SWIGWStringDelegate wstringDelegate = new SWIGWStringDelegate(CreateWString); static SWIGWStringDelegate wstringUTF16Delegate = new SWIGWStringDelegate(CreateWStringFromUTF16);
static SWIGWStringDelegate wstringUTF32Delegate = new SWIGWStringDelegate(CreateWStringFromUTF32);
[global::System.Runtime.InteropServices.DllImport("$dllimport", EntryPoint="SWIGRegisterWStringCallback_$module")] [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) { 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); 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);
return global::System.Text.Encoding.UTF32.GetString(buffer);
} }
static SWIGWStringHelper() { static SWIGWStringHelper() {
SWIGRegisterWStringCallback_$module(wstringDelegate); SWIGRegisterWStringCallback_$module(wstringUTF16Delegate, wstringUTF32Delegate);
} }
} }
@ -43,13 +64,76 @@ static SWIG_CSharpWStringHelperCallback SWIG_csharp_wstring_callback = NULL;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
#endif #endif
SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback) { SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStringHelperCallback callback_utf16, SWIG_CSharpWStringHelperCallback callback_utf32) {
SWIG_csharp_wstring_callback = callback; SWIG_csharp_wstring_with_length_callback = sizeof(wchar_t) == 2 ? callback_utf16 : callback_utf32;
} }
%} %}
#endif // SWIG_CSHARP_WSTRING_HELPER_ #endif // SWIG_CSHARP_WSTRING_HELPER_
#endif // SWIG_CSHARP_NO_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];
return global::System.Text.Encoding.UTF32.GetString(buffer);
}
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 // wchar_t
%typemap(ctype) wchar_t "wchar_t" %typemap(ctype) wchar_t "wchar_t"
@ -77,13 +161,64 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStri
%typemap(typecheck) wchar_t = char; %typemap(typecheck) wchar_t = char;
// wchar_t * // 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(cstype) wchar_t * "string"
%typemap(csdirectorin) wchar_t * "$iminput"
%typemap(csdirectorout) wchar_t * "$cscall"
%typemap(csin) wchar_t * "$csinput" %typemap(csin) wchar_t * "$csinput"
%typemap(csout, excode=SWIGEXCODE) wchar_t * { %typemap(csout, excode=SWIGEXCODE) wchar_t * {
string ret = global::System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode string ret = $imcall;$excode
return ret; return ret;
} }
%typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{ %typemap(csvarin, excode=SWIGEXCODE2) wchar_t * %{
@ -92,12 +227,109 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterWStringCallback_$module(SWIG_CSharpWStri
} %} } %}
%typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{ %typemap(csvarout, excode=SWIGEXCODE2) wchar_t * %{
get { get {
string ret = global::System.Runtime.InteropServices.Marshal.PtrToStringUni($imcall);$excode string ret = $imcall;$excode
return ret; return ret;
} %} } %}
%typemap(in) wchar_t * %{ $1 = ($1_ltype)$input; %} %typemap(in, fragment="Swig_csharp_UTF16ToWCharPtr") wchar_t *
%typemap(out) wchar_t * %{ $result = (wchar_t *)$1; %} %{ $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(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; %} $1 = *argp; %}
%typemap(out) CONST TYPE %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 %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 %typemap(directorout) CONST TYPE
%{ if (!$input) { %{ if (!$input) {
@ -116,7 +116,7 @@
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull) %typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
%{ $1 = $input ? ($1_ltype)$input : &tempnull; %} %{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
%typemap(out, fragment="SWIG_null_deleter") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %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; %} if ($owner) delete $1; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * %typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *

View File

@ -76,6 +76,19 @@ public static void* swigGetCPtr(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr; 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; mixin $imdmodule.SwigOperatorDefinitions;
%} %}
@ -92,6 +105,19 @@ public static void* swigGetCPtr(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr; 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; mixin $imdmodule.SwigOperatorDefinitions;
%} %}
@ -100,7 +126,7 @@ mixin $imdmodule.SwigOperatorDefinitions;
* Type wrapper classes. * Type wrapper classes.
*/ */
%typemap(dbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{ %typemap(dbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] %{
private void* swigCPtr; private void* swigCPtr;
public this(void* cObject, bool futureUse) { public this(void* cObject, bool futureUse) {
@ -115,6 +141,10 @@ public static void* swigGetCPtr(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr; return (obj is null) ? null : obj.swigCPtr;
} }
public static void* swigRelease(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr;
}
mixin $imdmodule.SwigOperatorDefinitions; mixin $imdmodule.SwigOperatorDefinitions;
%} %}

View File

@ -52,7 +52,7 @@
%typemap(out) SWIGTYPE %typemap(out) SWIGTYPE
#ifdef __cplusplus #ifdef __cplusplus
%{ $result = new $1_ltype((const $1_ltype &)$1); %} %{ $result = new $1_ltype($1); %}
#else #else
{ {
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype)); $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
@ -62,7 +62,7 @@
#endif #endif
%typemap(directorin) SWIGTYPE %typemap(directorin) SWIGTYPE
"$input = (void *)new $1_ltype((const $1_ltype &)$1);" "$input = (void *)new $1_ltype(SWIG_STD_MOVE($1));"
%typemap(directorout) SWIGTYPE %typemap(directorout) SWIGTYPE
%{ if (!$input) { %{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type"); SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type");
@ -122,7 +122,7 @@
%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input; %typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if (!$1) { if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null"); SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null");
return $null; return $null;
} %} } %}
%typemap(out) SWIGTYPE & "$result = (void *)$1;" %typemap(out) SWIGTYPE & "$result = (void *)$1;"
@ -157,11 +157,12 @@
* Rvalue reference conversion typemaps. * 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) { if (!$1) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null"); SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null");
return $null; return $null;
} %} }
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE && "$result = (void *)$1;" %typemap(out) SWIGTYPE && "$result = (void *)$1;"
%typemap(directorin) SWIGTYPE && %typemap(directorin) SWIGTYPE &&
@ -182,7 +183,7 @@
%typemap(din, %typemap(din,
nativepointer="cast(void*)$dinput" nativepointer="cast(void*)$dinput"
) SWIGTYPE && "$dclassname.swigGetCPtr($dinput)" ) SWIGTYPE && "$dclassname.swigRelease($dinput)"
%typemap(dout, excode=SWIGEXCODE, %typemap(dout, excode=SWIGEXCODE,
nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}") SWIGTYPE && { nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}") SWIGTYPE && {
$dclassname ret = new $dclassname($imcall, $owner);$excode $dclassname ret = new $dclassname($imcall, $owner);$excode

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 {};
}

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 {};
}

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

@ -388,8 +388,9 @@
%typemap(gotype) SWIGTYPE && %typemap(gotype) SWIGTYPE &&
%{$gotypename%} %{$gotypename%}
%typemap(in) SWIGTYPE && %typemap(in, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter)
%{ $1 = *($&1_ltype)&$input; %} %{ $1 = *($&1_ltype)&$input;
rvrdeleter.reset($1); %}
%typemap(out) SWIGTYPE && %typemap(out) SWIGTYPE &&
%{ *($&1_ltype)&$result = $1; %} %{ *($&1_ltype)&$result = $1; %}
@ -625,7 +626,7 @@
%typemap(goout) SWIGTYPE "" %typemap(goout) SWIGTYPE ""
%typemap(directorin) SWIGTYPE %typemap(directorin) SWIGTYPE
%{ $input = new $1_ltype((const $1_ltype &)$1); %} %{ $input = new $1_ltype(SWIG_STD_MOVE($1)); %}
%typemap(godirectorin) SWIGTYPE "" %typemap(godirectorin) SWIGTYPE ""

View File

@ -52,6 +52,9 @@ class string;
%typemap(godirectorin,fragment="CopyString") string %typemap(godirectorin,fragment="CopyString") string
%{ $result = swigCopyString($input) %} %{ $result = swigCopyString($input) %}
%typemap(throws) string
%{ _swig_gopanic($1.c_str()); %}
%typemap(in) const string & %typemap(in) const string &
%{ %{
$*1_ltype $1_str($input.p, $input.n); $*1_ltype $1_str($input.p, $input.n);
@ -88,22 +91,30 @@ class string;
%typemap(godirectorin,fragment="CopyString") const string & %typemap(godirectorin,fragment="CopyString") const string &
%{ $result = swigCopyString($input) %} %{ $result = swigCopyString($input) %}
%typemap(throws) const string &
%{ _swig_gopanic($1.c_str()); %}
%typemap(gotype) string * "*string" %typemap(gotype) string * "*string"
%typemap(in) string * (string temp) %typemap(in) string * (string temp)
%{ %{
if ($input) {
temp.assign($input->p, $input->n); temp.assign($input->p, $input->n);
$1 = &temp; $1 = &temp;
} else
$1 = 0;
%} %}
%typemap(godirectorout) string * %typemap(godirectorout) string *
%{ %{
{ if $input != nil {
p := Swig_malloc(len(*$input)) p := Swig_malloc(len(*$input))
s := (*[1<<30]byte)(unsafe.Pointer(p))[:len(*$input)] s := (*[1<<30]byte)(unsafe.Pointer(p))[:len(*$input)]
copy(s, *$input) copy(s, *$input)
$result = (*string)(unsafe.Pointer(&s)) $result = (*string)(unsafe.Pointer(&s))
} else {
$result = nil
} }
%} %}
@ -125,17 +136,27 @@ class string;
%typemap(directorin,fragment="AllocateString") string * (_gostring_ temp) %typemap(directorin,fragment="AllocateString") string * (_gostring_ temp)
%{ %{
if ($1) {
temp = Swig_AllocateString($1->data(), $1->length()); temp = Swig_AllocateString($1->data(), $1->length());
$input = &temp; $input = &temp;
} else
$input = 0;
%} %}
%typemap(godirectorin,fragment="CopyString") string * %typemap(godirectorin,fragment="CopyString") string *
%{ *$result = swigCopyString(*$input); %} %{ *$result = swigCopyString(*$input); %}
%typemap(argout,fragment="AllocateString") string * %typemap(argout,fragment="AllocateString") string *
%{ *$input = Swig_AllocateString($1->data(), $1->length()); %} %{
if ($1)
*$input = Swig_AllocateString($1->data(), $1->length());
%}
%typemap(goargout,fragment="CopyString") string * %typemap(goargout,fragment="CopyString") string *
%{ *$input = swigCopyString(*$1) %} %{
if $input != nil {
*$1 = swigCopyString(*$input)
}
%}
} }

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 * 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 <libguile.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -112,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_is_null(x) && SCM_INSTANCEP(x) && scm_is_true(scm_slot_exists_p(x, swig_symbol)) \
? scm_slot_ref(x, swig_symbol) : (x) ) ? scm_slot_ref(x, swig_symbol) : (x) )
SWIGINTERN void SWIG_Guile_MarkPointerNoncollectable(SCM s);
SWIGINTERN SCM SWIGINTERN SCM
SWIG_Guile_NewPointerObj(void *ptr, swig_type_info *type, int owner) SWIG_Guile_NewPointerObj(void *ptr, swig_type_info *type, int owner)
{ {
@ -125,7 +133,7 @@ SWIG_Guile_NewPointerObj(void *ptr, swig_type_info *type, int owner)
else else
SCM_NEWSMOB2(smob, swig_tag, ptr, (void *) type); 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; return smob;
} else { } else {
/* the scm_make() C function only handles the creation of gf, /* the scm_make() C function only handles the creation of gf,
@ -145,7 +153,7 @@ SWIGINTERN unsigned long
SWIG_Guile_PointerAddress(SCM object) SWIG_Guile_PointerAddress(SCM object)
{ {
SCM smob = SWIG_Guile_GetSmob(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) else if (SCM_SMOB_PREDICATE(swig_tag, smob)
|| SCM_SMOB_PREDICATE(swig_collectable_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)
|| SCM_SMOB_PREDICATE(swig_destroyed_tag, smob)) { || SCM_SMOB_PREDICATE(swig_destroyed_tag, smob)) {
@ -158,7 +166,7 @@ SWIGINTERN swig_type_info *
SWIG_Guile_PointerType(SCM object) SWIG_Guile_PointerType(SCM object)
{ {
SCM smob = SWIG_Guile_GetSmob(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) else if (SCM_SMOB_PREDICATE(swig_tag, smob)
|| SCM_SMOB_PREDICATE(swig_collectable_tag, smob) || SCM_SMOB_PREDICATE(swig_collectable_tag, smob)
|| SCM_SMOB_PREDICATE(swig_destroyed_tag, smob)) { || SCM_SMOB_PREDICATE(swig_destroyed_tag, smob)) {
@ -185,8 +193,9 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
swig_cast_info *cast; swig_cast_info *cast;
swig_type_info *from; swig_type_info *from;
SCM smob = SWIG_Guile_GetSmob(s); SCM smob = SWIG_Guile_GetSmob(s);
int ret = SWIG_ERROR;
if (SCM_NULLP(smob)) { if (scm_is_null(smob)) {
*result = NULL; *result = NULL;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
#if SCM_MAJOR_VERSION >= 2 #if SCM_MAJOR_VERSION >= 2
@ -197,22 +206,36 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags)
} else if (SWIG_Guile_IsValidSmob(smob)) { } else if (SWIG_Guile_IsValidSmob(smob)) {
from = (swig_type_info *) SCM_CELL_WORD_2(smob); from = (swig_type_info *) SCM_CELL_WORD_2(smob);
if (!from) return SWIG_ERROR; 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) { if (type) {
cast = SWIG_TypeCheckStruct(from, type); cast = SWIG_TypeCheckStruct(from, type);
if (cast) { if (cast) {
int newmemory = 0; int newmemory = 0;
*result = SWIG_TypeCast(cast, (void *) SCM_CELL_WORD_1(smob), &newmemory); *result = SWIG_TypeCast(cast, (void *) SCM_CELL_WORD_1(smob), &newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */ assert(!newmemory); /* newmemory handling not yet implemented */
return SWIG_OK; ret = SWIG_OK;
} else { } else {
return SWIG_ERROR; return SWIG_ERROR;
} }
} else { } else {
*result = (void *) SCM_CELL_WORD_1(smob); *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 * SWIGINTERNINLINE void *
@ -252,7 +275,7 @@ SWIGINTERN void
SWIG_Guile_MarkPointerNoncollectable(SCM s) SWIG_Guile_MarkPointerNoncollectable(SCM s)
{ {
SCM smob = SWIG_Guile_GetSmob(s); SCM smob = SWIG_Guile_GetSmob(s);
if (!SCM_NULLP(smob)) { if (!scm_is_null(smob)) {
if (SWIG_Guile_IsValidSmob(smob)) { if (SWIG_Guile_IsValidSmob(smob)) {
SCM_SET_CELL_TYPE(smob, swig_tag); SCM_SET_CELL_TYPE(smob, swig_tag);
} }
@ -265,7 +288,7 @@ SWIGINTERN void
SWIG_Guile_MarkPointerDestroyed(SCM s) SWIG_Guile_MarkPointerDestroyed(SCM s)
{ {
SCM smob = SWIG_Guile_GetSmob(s); SCM smob = SWIG_Guile_GetSmob(s);
if (!SCM_NULLP(smob)) { if (!scm_is_null(smob)) {
if (SWIG_Guile_IsValidSmob(smob)) { if (SWIG_Guile_IsValidSmob(smob)) {
SCM_SET_CELL_TYPE(smob, swig_destroyed_tag); SCM_SET_CELL_TYPE(smob, swig_destroyed_tag);
} }
@ -486,20 +509,20 @@ SWIG_Guile_GetArgs (SCM *dest, SCM rest,
int i; int i;
int num_args_passed = 0; int num_args_passed = 0;
for (i = 0; i<reqargs; i++) { 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")); scm_wrong_num_args(scm_from_utf8_string(procname ? (char *) procname : "unknown procedure"));
*dest++ = SCM_CAR(rest); *dest++ = SCM_CAR(rest);
rest = SCM_CDR(rest); rest = SCM_CDR(rest);
num_args_passed++; 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); *dest++ = SCM_CAR(rest);
rest = SCM_CDR(rest); rest = SCM_CDR(rest);
num_args_passed++; num_args_passed++;
} }
for (; i<optargs; i++) for (; i<optargs; i++)
*dest++ = SCM_UNDEFINED; *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")); scm_wrong_num_args(scm_from_utf8_string(procname ? (char *) procname : "unknown procedure"));
return num_args_passed; return num_args_passed;
} }

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

@ -83,4 +83,13 @@ namespace std {
$result = SWIG_str02scm($1.c_str()); $result = SWIG_str02scm($1.c_str());
} }
%typemap(throws) string {
scm_throw(scm_from_locale_symbol((char *) "swig-exception"),
scm_list_n(SWIG_str02scm($1.c_str()), SCM_UNDEFINED));
}
%typemap(throws) const string & {
scm_throw(scm_from_locale_symbol((char *) "swig-exception"),
scm_list_n(SWIG_str02scm($1.c_str()), SCM_UNDEFINED));
}
} }

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 {};
}

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 #ifdef SWIGGUILE_SCM
/* Hook the runtime module initialization
into the shared initialization function SWIG_Guile_Init. */
%runtime %{ %runtime %{
/* Hook the runtime module initialization /* Hook the runtime module initialization
into the shared initialization function SWIG_Guile_Init. */ into the shared initialization function SWIG_Guile_Init. */

View File

@ -4,17 +4,43 @@
* Guile-specific typemaps * 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 */ /* Pointers */
%typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] { %typemap(in) SWIGTYPE *, SWIGTYPE [] {
$1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, 0); $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 * { %typemap(in) void * {
$1 = ($1_ltype)SWIG_MustGetPtr($input, NULL, $argnum, 0); $1 = ($1_ltype)SWIG_MustGetPtr($input, NULL, $argnum, 0);
} }
%typemap(freearg) void * ""; %typemap(freearg) void * ""
%typemap(varin) SWIGTYPE * { %typemap(varin) SWIGTYPE * {
$1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0); $1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, 1, 0);
@ -117,6 +143,7 @@
%typemap(in) SWIGTYPE ($&1_ltype argp) { %typemap(in) SWIGTYPE ($&1_ltype argp) {
argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0); argp = ($&1_ltype)SWIG_MustGetPtr($input, $&1_descriptor, $argnum, 0);
if (!argp) { %argument_nullref("$1_type", $symname, $argnum); }
$1 = *argp; $1 = *argp;
} }
@ -130,7 +157,7 @@
#ifdef __cplusplus #ifdef __cplusplus
{ {
$&1_ltype resultptr; $&1_ltype resultptr;
resultptr = new $1_ltype((const $1_ltype &) $1); resultptr = new $1_ltype($1);
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1); $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1);
} }
#else #else
@ -145,8 +172,7 @@
%typemap(varout) SWIGTYPE %typemap(varout) SWIGTYPE
#ifdef __cplusplus #ifdef __cplusplus
{ {
$&1_ltype resultptr; $&1_ltype resultptr = ($&1_ltype)&$1;
resultptr = new $1_ltype((const $1_ltype&) $1);
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0); $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0);
} }
#else #else
@ -322,14 +348,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 /* SWIG_scm2str makes a malloc'ed copy of the string, so get rid of it after
the function call. */ 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 **INPUT, char **BOTH "if (must_free$argnum) SWIG_free(*$1);"
%typemap (freearg) char **OUTPUT "SWIG_free(*$1);" %typemap (freearg) char **OUTPUT "SWIG_free(*$1);"
/* But this shall not apply if we try to pass a single char by /* But this shall not apply if we try to pass a single char by
reference. */ 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. */ /* If we set a string variable, delete the old result first, unless const. */
@ -349,13 +375,13 @@ SIMPLE_MAP(unsigned long long, scm_to_ulong_long, scm_from_ulong_long, integer);
/* Void */ /* Void */
%typemap (out,doc="") void "gswig_result = SCM_UNSPECIFIED;"; %typemap (out,doc="") void "gswig_result = SCM_UNSPECIFIED;"
/* SCM is passed through */ /* SCM is passed through */
typedef unsigned long SCM; typedef unsigned long SCM;
%typemap (in) SCM "$1=$input;"; %typemap (in) SCM "$1=$input;"
%typemap (out) SCM "$result=$1;"; %typemap (out) SCM "$result=$1;"
%typecheck(SWIG_TYPECHECK_POINTER) SCM "$1=1;"; %typecheck(SWIG_TYPECHECK_POINTER) SCM "$1=1;";
/* ------------------------------------------------------------ /* ------------------------------------------------------------
@ -373,11 +399,6 @@ typedef unsigned long SCM;
* taken from typemaps/swigtype.swg * 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::*) { %typemap(in) SWIGTYPE (CLASS::*) {
int res = SWIG_ConvertMember($input, %as_voidptr(&$1), sizeof($1), $descriptor); int res = SWIG_ConvertMember($input, %as_voidptr(&$1), sizeof($1), $descriptor);
if (!SWIG_IsOK(res)) { if (!SWIG_IsOK(res)) {
@ -426,7 +447,7 @@ typedef unsigned long SCM;
%typecheck(SWIG_TYPECHECK_BOOL) %typecheck(SWIG_TYPECHECK_BOOL)
bool, bool&, const bool& bool, bool&, const bool&
{ {
$1 = SCM_BOOLP($input) ? 1 : 0; $1 = scm_is_bool($input) ? 1 : 0;
} }
%typecheck(SWIG_TYPECHECK_DOUBLE) %typecheck(SWIG_TYPECHECK_DOUBLE)

View File

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

View File

@ -29,11 +29,11 @@
} }
$1 = *argp; %} $1 = *argp; %}
%typemap(out) CONST TYPE %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 %typemap(directorin,descriptor="L$packagepath/$&javaclassname;") CONST TYPE
%{ $input = 0; %{ $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 %typemap(directorout) CONST TYPE
%{ if (!$input) { %{ if (!$input) {

View File

@ -51,6 +51,10 @@ SWIGINTERN int Swig::GetThreadName(char *name, size_t len) {
#endif #endif
#if defined(SWIG_JAVA_DETACH_ON_THREAD_END)
#include <pthread.h>
#endif
namespace Swig { namespace Swig {
/* Java object wrapper */ /* 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: private:
/* pointer to Java object */ /* pointer to Java object */
jobject jthis_; jobject jthis_;
@ -140,6 +157,10 @@ namespace Swig {
bool weak_global_; bool weak_global_;
}; };
#if defined(SWIG_JAVA_DETACH_ON_THREAD_END)
pthread_key_t JObjectWrapper::detach_key_;
#endif
/* Local JNI reference deleter */ /* Local JNI reference deleter */
class LocalRefGuard { class LocalRefGuard {
JNIEnv *jenv_; JNIEnv *jenv_;
@ -201,9 +222,19 @@ namespace Swig {
#else #else
director_->swig_jvm_->AttachCurrentThread(jenv, &args); director_->swig_jvm_->AttachCurrentThread(jenv, &args);
#endif #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() { ~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. // 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. // 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) if (env_status == JNI_EDETACHED)

View File

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

View File

@ -1,24 +1,38 @@
/* /* -----------------------------------------------------------------------------
The typemaps here allow handling functions returning std::auto_ptr<>, * std_auto_ptr.i
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 * SWIG library file for handling std::auto_ptr.
something else (e.g. use shared_ptr<> which SWIG supports fully). * 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) %define %auto_ptr(TYPE)
%typemap (jni) std::auto_ptr< TYPE > "jlong" %typemap (jni) std::auto_ptr< TYPE > "jlong"
%typemap (jtype) std::auto_ptr< TYPE > "long" %typemap (jtype) std::auto_ptr< TYPE > "long"
%typemap (jstype) std::auto_ptr< TYPE > "$typemap(jstype, TYPE)" %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 > %{ %typemap (out) std::auto_ptr< TYPE > %{
jlong lpp = 0; jlong lpp = 0;
*(TYPE **) &lpp = $1.release(); *(TYPE **) &lpp = $1.release();
$result = lpp; $result = lpp;
%} %}
%typemap(javaout) std::auto_ptr< TYPE > { %typemap(javaout) std::auto_ptr< TYPE > {
long cPtr = $jnicall; long cPtr = $jnicall;
return (cPtr == 0) ? null : new $typemap(jstype, TYPE)(cPtr, true); 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 >; %template() std::auto_ptr< TYPE >;
%enddef %enddef

View File

@ -96,6 +96,10 @@ class set {
public boolean hasNext() { public boolean hasNext() {
return curr.isNot(end); return curr.isNot(end);
} }
public void remove() {
throw new java.lang.UnsupportedOperationException();
}
}.init(); }.init();
} }

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

@ -92,6 +92,10 @@ class unordered_set {
public boolean hasNext() { public boolean hasNext() {
return curr.isNot(end); return curr.isNot(end);
} }
public void remove() {
throw new java.lang.UnsupportedOperationException();
}
}.init(); }.init();
} }

View File

@ -88,7 +88,10 @@ class wstring;
//%typemap(typecheck) wstring = wchar_t *; //%typemap(typecheck) wstring = wchar_t *;
%typemap(throws) wstring %typemap(throws) wstring
%{ std::string message($1.begin(), $1.end()); %{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()); SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
return $null; %} return $null; %}
@ -166,7 +169,10 @@ class wstring;
//%typemap(typecheck) const wstring & = wchar_t *; //%typemap(typecheck) const wstring & = wchar_t *;
%typemap(throws) const wstring & %typemap(throws) const wstring &
%{ std::string message($1.begin(), $1.end()); %{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()); SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
return $null; %} return $null; %}

View File

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

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

@ -1,6 +1,6 @@
%fragment ("js_check_arg_count", "templates") %{ %fragment ("js_check_arg_count", "templates") %{
if (argc != $jsargcount) { if (argc != $jsargcount) {
SE_REPORT_ERROR("$jswrapper: wrong number of arguments: %d, was expecting %d", (int)argc, $jsargcount); SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, $jsargcount);
return false; return false;
}%} }%}
@ -14,7 +14,6 @@
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
%fragment ("js_ctor", "templates") %fragment ("js_ctor", "templates")
%{ %{
// js_ctor
static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming) static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
{ {
CC_UNUSED bool ok = true; CC_UNUSED bool ok = true;
@ -39,14 +38,9 @@ SE_BIND_CTOR($jswrapper, __jsb_$jsmangledname_class, js_delete_$jsdtor)%}
%{ %{
static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming) static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
{ {
// js_ctor_dispatcher
size_t argc = s.args().size(); size_t argc = s.args().size();
bool ret = false; bool ret = false;
// switch all cases by means of series of if-returns.
$jsdispatchcases $jsdispatchcases
// default:
SE_REPORT_ERROR("Illegal arguments for construction of $jsname"); SE_REPORT_ERROR("Illegal arguments for construction of $jsname");
return false; return false;
} }
@ -64,7 +58,6 @@ SE_BIND_CTOR($jswrapper, __jsb_$jsmangledname_class, js_delete_$jsdtor)%}
%{ %{
static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming) static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
{ {
// js_overloaded_ctor
const auto& args = s.args(); const auto& args = s.args();
CC_UNUSED bool ok = true; CC_UNUSED bool ok = true;
$jslocals $jslocals
@ -84,7 +77,6 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
%fragment ("js_ctor_dispatch_case", "templates") %fragment ("js_ctor_dispatch_case", "templates")
%{ %{
// js_ctor_dispatch_case
if(argc == $jsargcount) { if(argc == $jsargcount) {
ret = $jswrapper(s); ret = $jswrapper(s);
if (ret) { return ret; } /* reset exception and return */ if (ret) { return ret; } /* reset exception and return */
@ -99,7 +91,6 @@ static bool $jswrapper(se::State& s) // NOLINT(readability-identifier-naming)
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
%fragment ("js_dtor", "templates") %fragment ("js_dtor", "templates")
%{ %{
// js_dtor
static bool $jswrapper(se::State& s) { static bool $jswrapper(se::State& s) {
return true; return true;
} }
@ -114,7 +105,7 @@ SE_BIND_FINALIZE_FUNC($jswrapper) %}
%fragment ("js_dtoroverride", "templates") %fragment ("js_dtoroverride", "templates")
%{ %{
static bool $jswrapper(se::State& s) static bool $jswrapper(se::State& s)
{// js_dtoroverride {
return true; return true;
} }
SE_BIND_FINALIZE_FUNC($jswrapper) %} SE_BIND_FINALIZE_FUNC($jswrapper) %}
@ -169,7 +160,6 @@ SE_BIND_PROP_SET($jswrapper) %}
%{ %{
static bool $jswrapper(se::State& s) static bool $jswrapper(se::State& s)
{ {
// js_function
$js_func_begin $js_func_begin
CC_UNUSED bool ok = true; CC_UNUSED bool ok = true;
const auto& args = s.args(); const auto& args = s.args();
@ -196,7 +186,6 @@ SE_BIND_FUNC($jswrapper) %}
%{ %{
static bool $jswrapper(se::State& s) static bool $jswrapper(se::State& s)
{ {
// js_function_dispatcher
CC_UNUSED bool ok = true; CC_UNUSED bool ok = true;
const auto& args = s.args(); const auto& args = s.args();
size_t argc = args.size(); size_t argc = args.size();
@ -216,7 +205,7 @@ SE_BIND_FUNC($jswrapper) %}
%fragment ("js_overloaded_function", "templates") %fragment ("js_overloaded_function", "templates")
%{ %{
static bool $jswrapper(se::State& s) static bool $jswrapper(se::State& s)
{// js_overloaded_function {
$js_func_begin $js_func_begin
CC_UNUSED bool ok = true; CC_UNUSED bool ok = true;
const auto& args = s.args(); const auto& args = s.args();
@ -233,7 +222,7 @@ static bool $jswrapper(se::State& s)
* - $jscode: code part of wrapper * - $jscode: code part of wrapper
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
%fragment ("js_function_dispatch_case", "templates") %fragment ("js_function_dispatch_case", "templates")
%{// js_function_dispatch_case %{
if (argc == $jsargcount) { if (argc == $jsargcount) {
ok = $jswrapper(s); ok = $jswrapper(s);
if (ok) { return true; } if (ok) { return true; }

View File

@ -38,36 +38,32 @@
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* standard typemaps * standard typemaps
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
/* NEW LANGUAGE NOTE:
the 'checkfn' param is something that I added for typemap(in)
it is an optional fn call to check the type of the lua object
the fn call must be of the form
int checkfn(lua_State *L, int index);
and return 1/0 depending upon if this is the correct type
For the typemap(out), an additional SWIG_arg parameter must be incremented
to reflect the number of values returned (normally SWIG_arg++; will do)
*/
// number // number
%typemap(in) char, int, short, long, signed char, float, double, int8_t, int16_t, int32_t, int64_t, size_t, ssize_t
%typemap(in) int, short, long, signed char, float, double %{
%{// %typemap(in) int, short, long, signed char, float, double ok &= sevalue_to_native($input, &$1, s.thisObject());
ok &= sevalue_to_native($input, &$1, nullptr); SE_PRECONDITION2(ok, false, "Error processing arguments"); %}
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); %}
// additional check for unsigned numbers, to not permit negative input // additional check for unsigned numbers, to not permit negative input
%typemap(in) unsigned int, unsigned short, unsigned long, unsigned char %typemap(in) unsigned char, unsigned int, unsigned short, unsigned long, unsigned char, uint8_t, uint16_t, uint32_t, uint64_t, size_t, ssize_t
%{// %typemap(in) unsigned int, unsigned short, unsigned long, unsigned char %{
ok &= sevalue_to_native($input, &$1, nullptr); ok &= sevalue_to_native($input, &$1, s.thisObject());
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); SE_PRECONDITION2(ok, false, "Error processing arguments");
%} %}
%typemap(out) int,short,long, %typemap(out) char, int,short,long,
unsigned int,unsigned short,unsigned long, unsigned char, unsigned int,unsigned short,unsigned long,
signed char,unsigned char, signed char,unsigned char,
float,double float,double,
int8_t, int16_t, int32_t, int64_t,
uint8_t, uint16_t, uint32_t, uint64_t,
size_t, ssize_t
%{ %{
// out 1 ok &= nativevalue_to_se($1, s.rval(), s.thisObject()); %}
ok &= nativevalue_to_se($1, s.rval(), s.thisObject() /*ctx*/); %}
%apply long {long long, signed long long, unsigned long long};
// size_t (which is just a unsigned long)
%apply unsigned long { size_t };
// we must also provide typemaps for primitives by const reference: // we must also provide typemaps for primitives by const reference:
// given a function: // given a function:
@ -75,27 +71,17 @@
// SWIG assumes that this code will need a pointer to int to be passed in // SWIG assumes that this code will need a pointer to int to be passed in
// (this might be ok for objects by const ref, but not for numeric primitives) // (this might be ok for objects by const ref, but not for numeric primitives)
// therefore we add a set of typemaps to fix this (for both in & out) // therefore we add a set of typemaps to fix this (for both in & out)
%typemap(in,checkfn="lua_isnumber") const int& ($*1_ltype temp) %typemap(in) const int& ($*1_ltype temp), const unsigned int& ($*1_ltype temp)
%{ %{
//temp=($*1_ltype)lua_tonumber(L,$input); $1=&temp; ok &= sevalue_to_native($input, &temp, s.thisObject());
ok &= sevalue_to_native($input, &temp, nullptr /*ctx*/); SE_PRECONDITION2(ok, false, "Error processing arguments");
SE_PRECONDITION2(ok, false, "$symname, Error processing arguments");
$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");
// temp=($*1_ltype)lua_tonumber(L,$input); $1=&temp;
ok &= sevalue_to_native($input, &temp, nullptr /*ctx*/);
SE_PRECONDITION2(ok, false, "$symname, Error processing arguments");
$1 = &temp; $1 = &temp;
%} %}
%typemap(out) const int&, const unsigned int& %typemap(out) const int&, const unsigned int&
%{ // out 2 %{
ok &= nativevalue_to_se(*$1, s.rval(), s.thisObject() /*ctx*/); ok &= nativevalue_to_se(*$1, s.rval(), s.thisObject());
SE_PRECONDITION2(ok, false, "$symname, Error processing arguments"); SE_PRECONDITION2(ok, false, "Error processing arguments");
%} %}
// for the other numbers we can just use an apply statement to cover them // for the other numbers we can just use an apply statement to cover them
@ -105,192 +91,101 @@
%apply const unsigned int & {const unsigned short&,const unsigned long&, %apply const unsigned int & {const unsigned short&,const unsigned long&,
const unsigned char&}; const unsigned char&};
/* enums have to be handled slightly differently %apply const long& {const long long&, const signed long long&, const unsigned long long&};
VC++ .net will not allow a cast from lua_Number(double) to enum directly. %apply const unsigned long & { const size_t & };
*/
%typemap(in) enum SWIGTYPE (int32_t temp)
%{ // %typemap(in) enum SWIGTYPE (int32_t temp)
ok &= sevalue_to_native($input, &temp);
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor");
$1 = ($ltype)temp;%}
%typemap(out) enum SWIGTYPE (int32_t temp)
%{ // out 4
s.rval().setInt32(static_cast<int32_t>($1));%}
// and const refs
%typemap(in) const enum SWIGTYPE &($basetype temp)
%{ // %typemap(in) const enum SWIGTYPE &
temp=($basetype)(int)lua_tonumber(L,$input); $1=&temp;%}
%typemap(in) const enum SWIGTYPE &&($basetype temp)
%{ // %typemap(in) const enum SWIGTYPE &&
temp=($basetype)(int)lua_tonumber(L,$input); $1=&temp;%}
%typemap(out) const enum SWIGTYPE &
%{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%}
%typemap(out) const enum SWIGTYPE &&
%{ lua_pushnumber(L, (lua_Number) *$1); SWIG_arg++;%}
%typemap(in) bool %typemap(in) bool
%{ // %typemap(in) bool %{
ok &= sevalue_to_native($input, &$1); ok &= sevalue_to_native($input, &$1);
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); %} SE_PRECONDITION2(ok, false, "Error processing arguments"); %}
%typemap(out) bool %typemap(out) bool
%{// out 5 %{
ok &= nativevalue_to_se($1, s.rval(), s.thisObject() /*ctx*/);%} ok &= nativevalue_to_se($1, s.rval(), s.thisObject());%}
// for const bool&, SWIG treats this as a const bool* so we must dereference it %typemap(out) bool &
%typemap(in,checkfn="lua_isboolean") const bool& (bool temp) %{
%{temp=(lua_toboolean(L, $input)!=0); ok &= nativevalue_to_se(*$1, s.rval(), s.thisObject());%}
$1=&temp;%}
%typemap(out) const bool& %typemap(in) const char * (ccstd::string temp)
%{ lua_pushboolean(L,(int)((*$1)!=0)); SWIG_arg++;%}
// strings (char * and char[])
%typemap(in) const char * (ccstd::string temp), char * (ccstd::string temp)
%{ %{
ok &= sevalue_to_native($input, &temp); ok &= sevalue_to_native($input, &temp);
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); SE_PRECONDITION2(ok, false, "Error processing arguments");
$1 = ($ltype) temp.c_str(); %} $1 = ($ltype) temp.c_str(); %}
%typemap(in) const char[ANY], char[ANY]
%{$1 = ($ltype)lua_tostring(L, $input);%}
%typemap(out) const char *, char * %typemap(out) const char *, char *
%{ // out 6 %{
ok &= nativevalue_to_se($1, s.rval(), nullptr /*ctx*/); ok &= nativevalue_to_se($1, s.rval(), nullptr /*ctx*/);
SE_PRECONDITION2(ok, false, "$symname, Error processing arguments"); SE_PRECONDITION2(ok, false, "Error processing arguments");
SE_HOLD_RETURN_VALUE($1, s.thisObject(), s.rval());
%} %}
%typemap(out) const char[ANY], char[ANY] %apply const char* {char*, const char[ANY], char[ANY]}
%{ lua_pushstring(L,(const char *)$1); SWIG_arg++;%}
// char's
// currently treating chars as small strings, not as numbers
// (however signed & unsigned char's are numbers...)
%typemap(in) char
%{$1 = (lua_tostring(L, $input))[0];%}
%typemap(out) char
%{ lua_pushlstring(L, &$1, 1); SWIG_arg++;%}
// by const ref
%typemap(in) const char& (char temp)
%{temp = (lua_tostring(L, $input))[0]; $1=&temp;%}
%typemap(out) const char&
%{ lua_pushlstring(L, $1, 1); SWIG_arg++;%}
// pointers and references // pointers and references
// under SWIG rules, it is ok, to have a pass in a lua nil, // under SWIG rules, it is ok, to have a pass in a javascript null,
// it should be converted to a SWIG NULL. // it should be converted to a SWIG NULL.
// This will only be allowed for pointers & arrays, not refs or by value // This will only be allowed for pointers & arrays, not refs or by value
// the checkfn lua_isuserdata will only work for userdata
// the checkfn SWIG_isptrtype will work for both userdata and nil
%typemap(in) SWIGTYPE* %typemap(in) SWIGTYPE*
%{ // %typemap(in) SWIGTYPE* %{
ok &= sevalue_to_native($input, &$1, s.thisObject()); ok &= sevalue_to_native($input, &$1, s.thisObject());
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); %} SE_PRECONDITION2(ok, false, "Error processing arguments"); %}
%typemap(in) SWIGTYPE[] %typemap(in) SWIGTYPE[]
%{ // %typemap(in) SWIGTYPE[] %{
ok &= sevalue_to_native($input, &$1, s.thisObject()); ok &= sevalue_to_native($input, &$1, s.thisObject());
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); %} SE_PRECONDITION2(ok, false, "Error processing arguments"); %}
%typemap(in) SWIGTYPE& ($*ltype temp) %typemap(in) SWIGTYPE& ($*ltype temp)
%{// %typemap(in) SWIGTYPE& %{
ok &= sevalue_to_native($input, &temp, s.thisObject()); ok &= sevalue_to_native($input, &temp, s.thisObject());
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); SE_PRECONDITION2(ok, false, "Error processing arguments");
$1 = &temp; $1 = &temp;
%} %}
%typemap(in) SWIGTYPE&& ($*ltype temp) %typemap(in) SWIGTYPE&& ($*ltype temp)
%{// %typemap(in) SWIGTYPE&& %{
ok &= sevalue_to_native($input, &temp, s.thisObject()); ok &= sevalue_to_native($input, &temp, s.thisObject());
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); SE_PRECONDITION2(ok, false, "Error processing arguments");
$1 = &temp; $1 = &temp;
%} %}
// out is simple // out is simple
%typemap(out) SWIGTYPE& %typemap(out) SWIGTYPE&
%{ // %typemap(out) SWIGTYPE& %{
ok &= nativevalue_to_se(*$1, s.rval(), s.thisObject() /*ctx*/); ok &= nativevalue_to_se(*$1, s.rval(), s.thisObject());
SE_PRECONDITION2(ok, false, "$symname, Error processing arguments"); SE_PRECONDITION2(ok, false, "Error processing arguments");
SE_HOLD_RETURN_VALUE(*$1, s.thisObject(), s.rval()); %} SE_HOLD_RETURN_VALUE(*$1, s.thisObject(), s.rval()); %}
%typemap(out) SWIGTYPE* %typemap(out) SWIGTYPE*
%{ // %typemap(out) SWIGTYPE* %{
ok &= nativevalue_to_se($1, s.rval(), s.thisObject() /*ctx*/); ok &= nativevalue_to_se($1, s.rval(), s.thisObject());
SE_PRECONDITION2(ok, false, "$symname, Error processing arguments"); SE_PRECONDITION2(ok, false, "Error processing arguments");
SE_HOLD_RETURN_VALUE($1, s.thisObject(), s.rval()); %} SE_HOLD_RETURN_VALUE($1, s.thisObject(), s.rval()); %}
%typemap(out) SWIGTYPE&& %typemap(out) SWIGTYPE&&
%{ // %typemap(out) SWIGTYPE&& %{
ok &= nativevalue_to_se($1, s.rval(), s.thisObject() /*ctx*/); ok &= nativevalue_to_se($1, s.rval(), s.thisObject());
SE_PRECONDITION2(ok, false, "$symname, Error processing arguments"); SE_PRECONDITION2(ok, false, "Error processing arguments");
SE_HOLD_RETURN_VALUE($1, s.thisObject(), s.rval()); %} SE_HOLD_RETURN_VALUE($1, s.thisObject(), s.rval()); %}
// dynamic casts
// this uses the SWIG_TypeDynamicCast() which relies on RTTI to find out what the pointer really is
// the we return it as the correct type
%typemap(out) SWIGTYPE *DYNAMIC,
SWIGTYPE &DYNAMIC
{
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1);
SWIG_NewPointerObj222(L,(void*)$1,ty,$owner); SWIG_arg++;
}
// passing objects by value // passing objects by value
// SWIG_ConvertPtr wants an object pointer (the $&ltype argp) // SWIG_ConvertPtr wants an object pointer (the $&ltype argp)
// then dereferences it to get the object // then dereferences it to get the object
%typemap(in) SWIGTYPE //($&ltype argp) %typemap(in) SWIGTYPE //($&ltype argp)
%{ %{
// %typemap(in) SWIGTYPE value in
ok &= sevalue_to_native($input, &$1, s.thisObject()); ok &= sevalue_to_native($input, &$1, s.thisObject());
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); SE_PRECONDITION2(ok, false, "Error processing arguments");
%} %}
// Also needed for object ptrs by const ref
// eg A* const& ref_pointer(A* const& a);
// found in mixed_types.i
%typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE *const&($*ltype temp)
%{temp=($*ltype)SWIG_MustGetPtr111(L,$input,$*descriptor,0,$argnum,"$symname");
$1=($1_ltype)&temp;%}
%typemap(out) SWIGTYPE *const&
%{ // %typemap(out) SWIGTYPE *const&
SWIG_NewPointerObj333(L,*$1,$*descriptor,$owner); SWIG_arg++; %}
// DISOWN-ing typemaps
// if you have an object pointer which must be disowned, use this typemap
// eg. for void destroy_foo(Foo* toDie);
// use %apply SWIGTYPE* DISOWN {Foo* toDie};
// you could just use %delobject, but this is more flexible
%typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE* DISOWN,SWIGTYPE DISOWN[]
%{ // %typemap(in,checkfn="SWIG_isptrtype") SWIGTYPE* DISOWN,SWIGTYPE DISOWN[]
if (!SWIG_IsOK(SWIG_ConvertPtrIn222(L,$input,(void**)&$1,$descriptor,SWIG_POINTER_DISOWN))){
SWIG_fail_ptr("$symname",$argnum,$descriptor);
}
%}
// Primitive types--return by value // Primitive types--return by value
// must make a new object, copy the data & return the new object // must make a new object, copy the data & return the new object
// Note: the brackets are {...} and not %{..%}, because we want them to be included in the wrapper // Note: the brackets are {...} and not %{..%}, because we want them to be included in the wrapper
// this is because typemap(out) does not support local variables, like in typemap(in) does // this is because typemap(out) does not support local variables, like in typemap(in) does
// and we need the $&1_ltype resultptr; to be declared // and we need the $&1_ltype resultptr; to be declared
%typemap(out) SWIGTYPE %typemap(out) SWIGTYPE
%{ // %typemap(out) SWIGTYPE %{
ok &= nativevalue_to_se($1, s.rval(), s.thisObject() /*ctx*/); ok &= nativevalue_to_se($1, s.rval(), s.thisObject() /*ctx*/);
SE_PRECONDITION2(ok, false, "$symname, Error processing arguments"); SE_PRECONDITION2(ok, false, "Error processing arguments");
SE_HOLD_RETURN_VALUE($1, s.thisObject(), s.rval()); SE_HOLD_RETURN_VALUE($1, s.thisObject(), s.rval());
%} %}
@ -299,17 +194,14 @@ $1=($1_ltype)&temp;%}
// so the standard wrapping cannot be done // so the standard wrapping cannot be done
// nor can you cast a member function pointer to a void* (obviously) // nor can you cast a member function pointer to a void* (obviously)
// therefore a special wrapping functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written // therefore a special wrapping functions SWIG_ConvertMember() & SWIG_NewMemberObj() were written
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE (CLASS::*) %typemap(in) SWIGTYPE (CLASS::*)
%{ %{
// %typemap(in,checkfn="lua_isuserdata") SWIGTYPE (CLASS::*) static_assert(false, "Binding member function pointer is not supported!");
if (!SWIG_IsOK(SWIG_ConvertMember(L,$input,(void*)(&$1),sizeof($1),$descriptor)))
SWIG_fail_ptr("$symname",$argnum,$descriptor);
%} %}
%typemap(out) SWIGTYPE (CLASS::*) %typemap(out) SWIGTYPE (CLASS::*)
%{ %{
// %typemap(out) SWIGTYPE (CLASS::*) static_assert(false, "Returning member function pointer is not supported!");
SWIG_NewMemberObj(L,(void*)(&$1),sizeof($1),$descriptor); SWIG_arg++;
%} %}
@ -320,20 +212,9 @@ $1=($1_ltype)&temp;%}
A function void fn(void*) should take any kind of pointer as a parameter (just like C/C++ does) A function void fn(void*) should take any kind of pointer as a parameter (just like C/C++ does)
but if it's 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* %typemap(in) void*
%{ ok &= sevalue_to_native($input, &$1); %{ ok &= sevalue_to_native($input, &$1);
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor");%} SE_PRECONDITION2(ok, false, "Error processing arguments");%}
/* long long is another special case:
as lua only supports one numeric type (lua_Number), we will just
cast it to that & accept the loss of precision.
An alternative solution would be a long long struct or class
with the relevant operators.
*/
%apply long {long long, signed long long, unsigned long long};
%apply const long& {const long long&, const signed long long&, const unsigned long long&};
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* typecheck rules * typecheck rules
@ -343,100 +224,10 @@ These define the detection routines which will spot what
parameters match which function 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 it's integral
%typecheck(SWIG_TYPECHECK_INTEGER)
int, short, long,
unsigned int, unsigned short, unsigned long,
signed char, unsigned char,
long long, unsigned long long, signed long long,
const int &, const short &, const long &,
const unsigned int &, const unsigned short &, const unsigned long &,
const signed char&, const unsigned char&,
const long long &, const unsigned long long &,
enum SWIGTYPE, const enum SWIGTYPE&, const enum SWIGTYPE &&,
float, double, const float &, const double&
{
$1 = lua_isnumber(L,$input);
}
// %typecheck(SWIG_TYPECHECK_BOOL)
// bool, const bool &
// {
// $1 = lua_isboolean(L,$input);
// }
// special check for a char (string of length 1)
// %typecheck(SWIG_TYPECHECK_CHAR,fragment="SWIG_lua_isnilstring") char, const char& {
// $1 = SWIG_lua_isnilstring(L,$input) && (lua_rawlen(L,$input)==1);
// }
// %typecheck(SWIG_TYPECHECK_STRING,fragment="SWIG_lua_isnilstring") char *, char[] {
// $1 = SWIG_lua_isnilstring(L,$input);
// }
%typemap(in) SWIGTYPE *self %typemap(in) SWIGTYPE *self
%{ $1 = SE_THIS_OBJECT<$*ltype>(s); %{ $1 = SE_THIS_OBJECT<$*ltype>(s);
SE_PRECONDITION2($1, false, "%s: Invalid Native Object", __FUNCTION__); %} if (nullptr == $1) return true;%}
// %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE [] {
// void *ptr;
// if (SWIG_isptrtype(L,$input)==0 || SWIG_ConvertPtr61(L,$input, (void **) &ptr, $1_descriptor, 0)) {
// $1 = 0;
// } else {
// $1 = 1;
// }
// }
// %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE & {
// void *ptr;
// if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr62(L,$input, (void **) &ptr, $1_descriptor, SWIG_POINTER_NO_NULL)) {
// $1 = 0;
// } else {
// $1 = 1;
// }
// }
// %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE && {
// void *ptr;
// if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr63(L,$input, (void **) &ptr, $1_descriptor, SWIG_POINTER_NO_NULL)) {
// $1 = 0;
// } else {
// $1 = 1;
// }
// }
// %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
// void *ptr;
// if (lua_isuserdata(L,$input)==0 || SWIG_ConvertPtr64(L,$input, (void **) &ptr, $&1_descriptor, SWIG_POINTER_NO_NULL)) {
// $1 = 0;
// } else {
// $1 = 1;
// }
// }
// %typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
// void *ptr;
// if (SWIG_isptrtype(L,$input)==0 || SWIG_ConvertPtr65(L,$input, (void **) &ptr, 0, 0)) {
// $1 = 0;
// } else {
// $1 = 1;
// }
// }
// // Also needed for object pointers by const ref
// // eg const A* ref_pointer(A* const& a);
// // found in mixed_types.i
// %typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *const&
// {
// void *ptr;
// if (SWIG_isptrtype(L,$input)==0 || SWIG_ConvertPtr66(L,$input, (void **) &ptr, $*descriptor, 0)) {
// $1 = 0;
// } else {
// $1 = 1;
// }
// }
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Others * Others
@ -451,16 +242,14 @@ parameters match which function
%apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) } %apply SWIGTYPE (CLASS::*) { SWIGTYPE (CLASS::*const) }
%apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) } %apply SWIGTYPE & { SWIGTYPE (CLASS::*const&) }
// size_t (which is just a unsigned long)
%apply unsigned long { size_t };
%apply const unsigned long & { const size_t & };
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* Specials * Specials
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
// swig::LANGUAGE_OBJ was added to allow containers of native objects // swig::LANGUAGE_OBJ was added to allow containers of native objects
// however it's rather difficult to do this in lua, as you cannot hold pointers // however it's rather difficult to do this in javascript, as you cannot hold pointers
// to native objects (they are held in the interpreter) // to native objects (they are held in the interpreter)
// therefore for now: just ignoring this feature // therefore for now: just ignoring this feature
#ifdef __cplusplus #ifdef __cplusplus
@ -475,40 +264,16 @@ parameters match which function
#endif // __cplusplus #endif // __cplusplus
// %typemap(memberin) float [ANY] {
// int i;
// for (i = 0; i < $1_dim0; i++) {
// $1[i] = $input[i];
// }
// }
// %typemap(out) float [ANY] {
// int i;
// $result = PyList_New($1_dim0);
// for (i = 0; i < $1_dim0; i++) {
// PyObject *o = PyFloat_FromDouble((double) $1[i]);
// PyList_SetItem($result, i, o);
// }
// }
// %typemap(check) double %{
// if ($1 < 0) {
// croak("hahaha Expecting a positive number");
// }
// %}
// Cocos custom type // Cocos custom type
%typemap(in) cc::Mat4* (cc::Mat4 temp) %{ %typemap(in) cc::Mat4* (cc::Mat4 temp) %{
// %typemap(in) cc::Mat4* (cc::Mat4 temp) %{
ok &= sevalue_to_native($input, &temp); ok &= sevalue_to_native($input, &temp);
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); SE_PRECONDITION2(ok, false, "Error processing arguments");
$1 = ($ltype) &temp; $1 = ($ltype) &temp;
%} %}
%typemap(out) cc::Float32Array %{ %typemap(out) cc::Float32Array %{
// %typemap(out) cc::Float32Array
ok &= nativevalue_to_se($1, s.rval(), s.thisObject() /*ctx*/); ok &= nativevalue_to_se($1, s.rval(), s.thisObject() /*ctx*/);
SE_PRECONDITION2(ok, false, "$symname, Error processing arguments"); SE_PRECONDITION2(ok, false, "Error processing arguments");
SE_HOLD_RETURN_VALUE($1, s.thisObject(), s.rval()); SE_HOLD_RETURN_VALUE($1, s.thisObject(), s.rval());
%} %}

View File

@ -32,71 +32,71 @@ assert(s==s2)
namespace std { namespace std {
%naturalvar string; // %naturalvar string;
%typemap(in) string // %typemap(in) string
%{// string // %{// string
ok &= sevalue_to_native($input, &$1); // ok &= sevalue_to_native($input, &$1);
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); %} // SE_PRECONDITION2(ok, false, "Error processing arguments"); %}
%typemap(out) string // %typemap(out) string
%{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_arg++;%} // %{ lua_pushlstring(L,$1.data(),$1.size()); SWIG_arg++;%}
%typemap(in) string *self // %typemap(in) string *self
%{ $1 = SE_THIS_OBJECT<$*ltype>(s); // %{ $1 = SE_THIS_OBJECT<$*ltype>(s);
SE_PRECONDITION2($1, false, "%s: Invalid Native Object", __FUNCTION__); %} // SE_PRECONDITION2($1, false, "Invalid Native Object"); %}
%typemap(in,checkfn="lua_isstring") string* // %typemap(in,checkfn="lua_isstring") string*
%{// string* // %{// string*
std::string // std::string
ok &= sevalue_to_native($input, &$1); // ok &= sevalue_to_native($input, &$1);
SE_PRECONDITION2(ok, false, "$symname,$argnum,$descriptor"); // SE_PRECONDITION2(ok, false, "Error processing arguments");
$1.assign(lua_tostringxxx(L,$input),lua_rawlen(L,$input));%} // $1.assign(lua_tostringxxx(L,$input),lua_rawlen(L,$input));%}
%typemap(out) string* // %typemap(out) string*
%{// out string* // %{// out string*
lua_pushlstringxxx(L,$1.data(),$1.size()); SWIG_arg++;%} // lua_pushlstringxxx(L,$1.data(),$1.size()); SWIG_arg++;%}
%typemap(in,checkfn="lua_isstring") const string& ($*1_ltype temp) // %typemap(in,checkfn="lua_isstring") const string& ($*1_ltype temp)
%{ // const std::string& // %{ // const std::string&
temp.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); $1=&temp;%} // temp.assign(lua_tostring(L,$input),lua_rawlen(L,$input)); $1=&temp;%}
%typemap(out) const string& // %typemap(out) const string&
%{ // out const string& // %{ // out const string&
lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%} // lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}
// %typecheck(SWIG_TYPECHECK_STRING) string, const string& { // // %typecheck(SWIG_TYPECHECK_STRING) string, const string& {
// $1 = lua_isstring(L,$input); // // $1 = lua_isstring(L,$input);
// } // // }
/* // /*
std::string& can be wrapped, but you must inform SWIG if it is in or out // std::string& can be wrapped, but you must inform SWIG if it is in or out
eg: // eg:
void fn(std::string& str); // void fn(std::string& str);
Is this an in/out/inout value? // Is this an in/out/inout value?
Therefore you need the usual // Therefore you need the usual
%apply (std::string& INOUT) {std::string& str}; // %apply (std::string& INOUT) {std::string& str};
or // or
%apply std::string& INOUT {std::string& str}; // %apply std::string& INOUT {std::string& str};
typemaps to tell SWIG what to do. // typemaps to tell SWIG what to do.
*/ // */
%typemap(in) string &INPUT=const string &; // %typemap(in) string &INPUT=const string &;
%typemap(in, numinputs=0) string &OUTPUT ($*1_ltype temp) // %typemap(in, numinputs=0) string &OUTPUT ($*1_ltype temp)
%{ $1 = &temp; %} // %{ $1 = &temp; %}
%typemap(argout) string &OUTPUT // %typemap(argout) string &OUTPUT
%{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%} // %{ lua_pushlstring(L,$1->data(),$1->size()); SWIG_arg++;%}
%typemap(in) string &INOUT =const string &; // %typemap(in) string &INOUT =const string &;
%typemap(in) string *INOUT %{ // %typemap(in) string *INOUT %{
// inout ... string* // // inout ... string*
%}; // %};
%typemap(argout) string &INOUT = string &OUTPUT; // %typemap(argout) string &INOUT = string &OUTPUT;
/* /*
A really cut down version of the string class A really cut down version of the string class

View File

@ -7,23 +7,27 @@
#define SWIG_exception(code, msg) do { SWIG_JSC_exception(context, exception, code, msg); SWIG_fail; } while (0) #define SWIG_exception(code, msg) do { SWIG_JSC_exception(context, exception, code, msg); SWIG_fail; } while (0)
#define SWIG_fail goto fail #define SWIG_fail goto fail
SWIGRUNTIME void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* type) { SWIGRUNTIME void SWIG_Javascript_Raise_ValueRef(JSContextRef context, JSValueRef *exception, JSValueRef valRef) {
JSStringRef message = JSStringCreateWithUTF8CString(type);
JSValueRef error_arguments[1]; JSValueRef error_arguments[1];
JSObjectRef exception_object; JSObjectRef exception_object;
JSValueRef exception_value;
exception_value = JSValueMakeString(context, message);
/* Converting the result to an object will let JavascriptCore add /* Converting the result to an object will let JavascriptCore add
"sourceURL" (file) and "line" (number) and "message" to the exception, "sourceURL" (file) and "line" (number) and "message" to the exception,
instead of just returning a raw string. This is extremely important for debugging your errors. instead of just returning a raw string. This is extremely important for debugging your errors.
Using JSObjectMakeError is better than JSValueToObject because the latter only populates Using JSObjectMakeError is better than JSValueToObject because the latter only populates
"sourceURL" and "line", but not "message" or any others I don't know about. "sourceURL" and "line", but not "message" or any others I don't know about.
*/ */
error_arguments[0] = exception_value; error_arguments[0] = valRef;
exception_object = JSObjectMakeError(context, 1, error_arguments, NULL); exception_object = JSObjectMakeError(context, 1, error_arguments, NULL);
/* Return the exception_object */ /* Return the exception_object */
*exception = exception_object; *exception = exception_object;
}
SWIGRUNTIME void SWIG_Javascript_Raise(JSContextRef context, JSValueRef *exception, const char* msg) {
JSStringRef message = JSStringCreateWithUTF8CString(msg);
JSValueRef exception_value = JSValueMakeString(context, message);
SWIG_Javascript_Raise_ValueRef(context, exception, exception_value);
JSStringRelease(message); JSStringRelease(message);
} }
@ -135,9 +139,16 @@ SWIGRUNTIME int SWIG_JSC_ConvertInstancePtr(JSContextRef context, JSObjectRef ob
} }
} }
if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !cdata->swigCMemOwn) {
return SWIG_ERROR_RELEASE_NOT_OWNED;
} else {
if (flags & SWIG_POINTER_DISOWN) { if (flags & SWIG_POINTER_DISOWN) {
cdata->swigCMemOwn = false; cdata->swigCMemOwn = false;
} }
if (flags & SWIG_POINTER_CLEAR) {
cdata->swigCObject = 0;
}
}
return SWIG_OK; 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, %define %_typemap2_string(StringCode, CharCode,
WarningLeakMsg,
Char, CharName, Char, CharName,
SWIG_AsCharPtrAndSize, SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize, SWIG_FromCharPtrAndSize,
@ -166,6 +167,7 @@ SWIG_AsVal_dec(Char)(SWIG_Object obj, Char *val)
%_typemap_string(StringCode, %_typemap_string(StringCode,
Char, Char,
WarningLeakMsg,
SWIG_AsCharPtrAndSize, SWIG_AsCharPtrAndSize,
SWIG_FromCharPtrAndSize, SWIG_FromCharPtrAndSize,
SWIG_CharPtrLen, SWIG_CharPtrLen,

View File

@ -41,7 +41,7 @@
#define SWIG_SetConstant(name, obj) #define SWIG_SetConstant(name, obj)
/* raise */ /* raise */
#define SWIG_Raise(obj, type, desc) SWIG_Javascript_Raise(context, exception, type) #define SWIG_Raise(obj, type, desc) SWIG_Javascript_Raise_ValueRef(context, exception, obj)
%insert("runtime") %{ %insert("runtime") %{
#define SWIG_JSC_FROM_DECL_ARGS(arg1) (JSContextRef context, arg1) #define SWIG_JSC_FROM_DECL_ARGS(arg1) (JSContextRef context, arg1)

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

@ -81,7 +81,7 @@ int SWIG_AsVal_dec(long)(SWIGV8_VALUE obj, long* val)
SWIGINTERNINLINE SWIGINTERNINLINE
SWIGV8_VALUE SWIG_From_dec(unsigned long)(unsigned long value) SWIGV8_VALUE SWIG_From_dec(unsigned long)(unsigned long value)
{ {
return SWIGV8_INTEGER_NEW_UNS(value); return value <= UINT32_MAX ? (SWIGV8_VALUE)SWIGV8_INTEGER_NEW_UNS(value) : (SWIGV8_VALUE)SWIGV8_NUMBER_NEW(static_cast<double>(value));
} }
} }
@ -149,7 +149,7 @@ int SWIG_AsVal_dec(long long)(SWIGV8_VALUE obj, long long* val)
SWIGINTERNINLINE SWIGINTERNINLINE
SWIGV8_VALUE SWIG_From_dec(unsigned long long)(unsigned long long value) SWIGV8_VALUE SWIG_From_dec(unsigned long long)(unsigned long long value)
{ {
return SWIGV8_INTEGER_NEW_UNS(value); return value <= UINT32_MAX ? (SWIGV8_VALUE)SWIGV8_INTEGER_NEW_UNS(value) : (SWIGV8_VALUE)SWIGV8_NUMBER_NEW(static_cast<double>(value));
} }
%#endif %#endif
} }

View File

@ -96,6 +96,11 @@ SWIGINTERN void SWIG_V8_Raise(const char *msg) {
SWIGV8_THROW_EXCEPTION(v8::Exception::Error(SWIGV8_STRING_NEW(msg))); SWIGV8_THROW_EXCEPTION(v8::Exception::Error(SWIGV8_STRING_NEW(msg)));
} }
SWIGINTERN void SWIG_V8_Raise(SWIGV8_VALUE obj, const char *msg) {
SWIGV8_THROW_EXCEPTION(v8::Exception::Error(SWIGV8_TO_STRING(obj)));
}
/* /*
Note: There are two contexts for handling errors. Note: There are two contexts for handling errors.
A static V8ErrorHandler is used in not overloaded methods. A static V8ErrorHandler is used in not overloaded methods.
@ -194,9 +199,16 @@ SWIGRUNTIME int SWIG_V8_ConvertInstancePtr(SWIGV8_OBJECT objRef, void **ptr, swi
*ptr = cdata->swigCObject; *ptr = cdata->swigCObject;
} }
if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !cdata->swigCMemOwn) {
return SWIG_ERROR_RELEASE_NOT_OWNED;
} else {
if (flags & SWIG_POINTER_DISOWN) { if (flags & SWIG_POINTER_DISOWN) {
cdata->swigCMemOwn = false; cdata->swigCMemOwn = false;
} }
if (flags & SWIG_POINTER_CLEAR) {
cdata->swigCObject = 0;
}
}
return SWIG_OK; return SWIG_OK;
} }

View File

@ -37,7 +37,7 @@
#define SWIG_SetConstant(name, obj) #define SWIG_SetConstant(name, obj)
/* raise */ /* raise */
#define SWIG_Raise(obj, type, desc) SWIG_V8_Raise(type) #define SWIG_Raise(obj, type, desc) SWIG_V8_Raise(obj, type)
/* Include the unified typemap library */ /* Include the unified typemap library */
%include <typemaps/swigtypemaps.swg> %include <typemaps/swigtypemaps.swg>

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

@ -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

@ -213,7 +213,7 @@ SWIG_fail;%}
// %apply SWIGTYPE EXCEPTION_BY_VAL {FooBar}; // %apply SWIGTYPE EXCEPTION_BY_VAL {FooBar};
// %apply SWIGTYPE& EXCEPTION_BY_VAL {FooBar&}; // note: need & twice // %apply SWIGTYPE& EXCEPTION_BY_VAL {FooBar&}; // note: need & twice
%typemap(throws) SWIGTYPE EXCEPTION_BY_VAL %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;%} SWIG_fail;%}
// similar for object reference // similar for object reference

View File

@ -1757,6 +1757,7 @@ SWIGRUNTIME void SWIG_Lua_NewPointerObj(lua_State *L,void *ptr,swig_type_info *t
(if possible) */ (if possible) */
SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type_info *type,int flags) 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_lua_userdata *usr;
swig_cast_info *cast; swig_cast_info *cast;
/* special case: lua nil => NULL pointer */ /* special case: lua nil => NULL pointer */
@ -1773,6 +1774,10 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type
usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */ usr=(swig_lua_userdata*)lua_touserdata(L,index); /* get data */
if (usr) 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 */ if (flags & SWIG_POINTER_DISOWN) /* must disown the object */
{ {
usr->own = 0; usr->own = 0;
@ -1780,18 +1785,25 @@ SWIGRUNTIME int SWIG_Lua_ConvertPtr(lua_State *L,int index,void **ptr,swig_type
if (!type) /* special cast void*, no casting fn */ if (!type) /* special cast void*, no casting fn */
{ {
*ptr=usr->ptr; *ptr=usr->ptr;
return SWIG_OK; /* ok */ ret = SWIG_OK;
} }
cast=SWIG_TypeCheckStruct(usr->type,type); /* performs normal type checking */ else
{
cast=SWIG_TypeCheck(usr->type->name,type); /* performs normal type checking */
if (cast) if (cast)
{ {
int newmemory = 0; int newmemory = 0;
*ptr=SWIG_TypeCast(cast,usr->ptr,&newmemory); *ptr=SWIG_TypeCast(cast,usr->ptr,&newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */ assert(!newmemory); /* newmemory handling not yet implemented */
return SWIG_OK; /* ok */ ret = SWIG_OK;
} }
} }
return SWIG_ERROR; /* error */ if ((ret == SWIG_OK) && (flags & SWIG_POINTER_CLEAR))
{
usr->ptr = 0;
}
}
return ret;
} }
SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State *L,int index,swig_type_info *type,int flags, SWIGRUNTIME void* SWIG_Lua_MustGetPtr(lua_State *L,int index,swig_type_info *type,int flags,

View File

@ -151,11 +151,17 @@ SWIGINTERN int SWIG_lua_isnilstring(lua_State *L, int idx) {
} }
%} %}
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE&& %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(SWIG_ConvertPtr(L,$input,(void**)&$1,$descriptor,$disown))){ 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); SWIG_fail_ptr("$symname", $argnum, $descriptor);
} }
}
$1 = ($1_ltype)argp;
rvrdeleter.reset($1);
%} %}
// out is simple // out is simple
@ -217,7 +223,7 @@ $1=($1_ltype)&temp;%}
#ifdef __cplusplus #ifdef __cplusplus
%typemap(out) SWIGTYPE %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++; SWIG_NewPointerObj(L,(void *) resultptr,$&1_descriptor,1); SWIG_arg++;
} }
#else #else
@ -248,7 +254,7 @@ $1=($1_ltype)&temp;%}
// void (must be empty without the SWIG_arg++) // void (must be empty without the SWIG_arg++)
%typemap(out) void ""; %typemap(out) void ""
/* void* is a special case /* void* is a special case
A function void fn(void*) should take any kind of pointer as a parameter (just like C/C++ does) A function void fn(void*) should take any kind of pointer as a parameter (just like C/C++ does)

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 {};
}

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 {};
}

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

@ -125,6 +125,7 @@ struct swig_mz_proxy {
Scheme_Type mztype; Scheme_Type mztype;
swig_type_info *type; swig_type_info *type;
void *object; void *object;
int own;
}; };
static Scheme_Type swig_type; static Scheme_Type swig_type;
@ -135,7 +136,7 @@ mz_free_swig(void *p, void *data) {
if (SCHEME_NULLP((Scheme_Object*)p) || SCHEME_TYPE((Scheme_Object*)p) != swig_type) if (SCHEME_NULLP((Scheme_Object*)p) || SCHEME_TYPE((Scheme_Object*)p) != swig_type)
return; return;
if (proxy->type) { if (proxy->type) {
if (proxy->type->clientdata) { if (proxy->type->clientdata && proxy->own) {
((Scheme_Prim *)proxy->type->clientdata)(1, (Scheme_Object **)&proxy); ((Scheme_Prim *)proxy->type->clientdata)(1, (Scheme_Object **)&proxy);
} }
} }
@ -143,42 +144,61 @@ mz_free_swig(void *p, void *data) {
static Scheme_Object * static Scheme_Object *
SWIG_MzScheme_NewPointerObj(void *ptr, swig_type_info *type, int owner) { SWIG_MzScheme_NewPointerObj(void *ptr, swig_type_info *type, int owner) {
if (ptr) {
struct swig_mz_proxy *new_proxy; struct swig_mz_proxy *new_proxy;
new_proxy = (struct swig_mz_proxy *) scheme_malloc(sizeof(struct swig_mz_proxy)); new_proxy = (struct swig_mz_proxy *) scheme_malloc(sizeof(struct swig_mz_proxy));
new_proxy->mztype = swig_type; new_proxy->mztype = swig_type;
new_proxy->type = type; new_proxy->type = type;
new_proxy->object = ptr; new_proxy->object = ptr;
if (owner) { new_proxy->own = owner & SWIG_POINTER_OWN;
if (new_proxy->own) {
scheme_add_finalizer(new_proxy, mz_free_swig, NULL); scheme_add_finalizer(new_proxy, mz_free_swig, NULL);
} }
return (Scheme_Object *) new_proxy; return (Scheme_Object *) new_proxy;
} else {
return scheme_make_null();
}
} }
static int static int
SWIG_MzScheme_ConvertPtr(Scheme_Object *s, void **result, swig_type_info *type, int flags) { SWIG_MzScheme_ConvertPtr(Scheme_Object *s, void **result, swig_type_info *type, int flags) {
swig_cast_info *cast; swig_cast_info *cast;
int ret = SWIG_ERROR;
if (SCHEME_NULLP(s)) { if (SCHEME_NULLP(s)) {
*result = NULL; *result = NULL;
return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK; return (flags & SWIG_POINTER_NO_NULL) ? SWIG_NullReferenceError : SWIG_OK;
} else if (SCHEME_TYPE(s) == swig_type) { } else if (SCHEME_TYPE(s) == swig_type) {
struct swig_mz_proxy *proxy = (struct swig_mz_proxy *) s; 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) { if (type) {
cast = SWIG_TypeCheckStruct(proxy->type, type); cast = SWIG_TypeCheckStruct(proxy->type, type);
if (cast) { if (cast) {
int newmemory = 0; int newmemory = 0;
*result = SWIG_TypeCast(cast, proxy->object, &newmemory); *result = SWIG_TypeCast(cast, proxy->object, &newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */ assert(!newmemory); /* newmemory handling not yet implemented */
return 0; ret = SWIG_OK;
} else { } else {
return 1; return SWIG_ERROR;
} }
} else { } else {
*result = proxy->object; *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 * 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

@ -52,6 +52,13 @@ namespace std {
$result = scheme_make_string($1->c_str()); $result = scheme_make_string($1->c_str());
} }
%typemap(throws) string {
scheme_signal_error("%s: %s", FUNC_NAME, $1.c_str());
}
%typemap(throws) const string & {
scheme_signal_error("%s: %s", FUNC_NAME, $1.c_str());
}
} }

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 {};
}

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 * 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 /* The MzScheme module handles all types uniformly via typemaps. Here
are the definitions. */ are the definitions. */
@ -66,9 +72,23 @@
#ifdef __cplusplus #ifdef __cplusplus
%typemap(in) SWIGTYPE &, SWIGTYPE && { %typemap(in) SWIGTYPE & {
$1 = ($ltype) SWIG_MustGetPtr($input, $descriptor, $argnum, 0); $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 && { %typemap(out) SWIGTYPE &, SWIGTYPE && {
@ -105,8 +125,8 @@
$1 = ($1_type) SWIG_convert_int($input); $1 = ($1_type) SWIG_convert_int($input);
} }
%typemap(out) 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);"; %typemap(varout) enum SWIGTYPE "$result = scheme_make_integer_value($1);"
/* Pass-by-value */ /* Pass-by-value */
@ -127,7 +147,7 @@
#ifdef __cplusplus #ifdef __cplusplus
{ {
$&1_ltype resultptr; $&1_ltype resultptr;
resultptr = new $1_ltype(($1_ltype &) $1); resultptr = new $1_ltype($1);
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1); $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 1);
} }
#else #else
@ -143,7 +163,7 @@
#ifdef __cplusplus #ifdef __cplusplus
{ {
$&1_ltype resultptr; $&1_ltype resultptr;
resultptr = new $1_ltype(($1_ltype &) $1); resultptr = new $1_ltype($1);
$result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0); $result = SWIG_NewPointerObj (resultptr, $&1_descriptor, 0);
} }
#else #else
@ -270,14 +290,18 @@ REF_MAP(float, SCHEME_REALP, scheme_real_to_double,
REF_MAP(double, SCHEME_REALP, scheme_real_to_double, REF_MAP(double, SCHEME_REALP, scheme_real_to_double,
scheme_make_double, real); scheme_make_double, real);
%typemap(throws) char * {
scheme_signal_error("%s: %s", FUNC_NAME, $1);
}
/* Void */ /* Void */
%typemap(out) void "$result = scheme_void;"; %typemap(out) void "$result = scheme_void;"
/* Pass through Scheme_Object * */ /* Pass through Scheme_Object * */
%typemap (in) Scheme_Object * "$1=$input;"; %typemap (in) Scheme_Object * "$1=$input;"
%typemap (out) Scheme_Object * "$result=$1;"; %typemap (out) Scheme_Object * "$result=$1;"
%typecheck(SWIG_TYPECHECK_POINTER) Scheme_Object * "$1=1;"; %typecheck(SWIG_TYPECHECK_POINTER) Scheme_Object * "$1=1;";
@ -291,7 +315,6 @@ REF_MAP(double, SCHEME_REALP, scheme_real_to_double,
// $2 = ($2_ltype) temp; // $2 = ($2_ltype) temp;
//} //}
/* ------------------------------------------------------------ /* ------------------------------------------------------------
* Typechecking rules * Typechecking rules
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */

View File

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

View File

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

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);
}

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 { %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)); %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 { %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)); %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) %{ %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); $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) { %typemap(directorout,noblock=1) CONST TYPE (void *swig_argp, int swig_res = 0) {

View File

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

View File

@ -232,7 +232,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
const swig_type_info *construct_type; // type of special type object const swig_type_info *construct_type; // type of special type object
std::vector < type_ptr_pair > types; // our c++ base classes 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::pair < const swig_octave_member *, octave_value > member_value_pair;
typedef std::map < std::string, member_value_pair > member_map; typedef std::map < std::string, member_value_pair > member_map;
@ -412,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, octave_swig_type(void *_ptr = 0, const swig_type_info *_type = 0, int _own = 0,
bool _always_static = false) 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) { always_static(_always_static) {
if (_type || _ptr) if (_type || _ptr)
types.push_back(std::make_pair(_type, _ptr)); types.push_back(std::make_pair(_type, _ptr));
@ -426,7 +426,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
} }
~octave_swig_type() { ~octave_swig_type() {
if (own) { if (thisown) {
++count; ++count;
for (unsigned int j = 0; j < types.size(); ++j) { for (unsigned int j = 0; j < types.size(); ++j) {
if (!types[j].first || !types[j].first->clientdata) if (!types[j].first || !types[j].first->clientdata)
@ -559,7 +559,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
} }
void merge(octave_swig_type &rhs) { void merge(octave_swig_type &rhs) {
rhs.own = 0; rhs.thisown = 0;
for (unsigned int j = 0; j < rhs.types.size(); ++j) { for (unsigned int j = 0; j < rhs.types.size(); ++j) {
assert(!rhs.types[j].second.destroyed); assert(!rhs.types[j].second.destroyed);
#ifdef SWIG_DIRECTORS #ifdef SWIG_DIRECTORS
@ -582,21 +582,40 @@ 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_begin() { return members.begin(); }
swig_member_const_iterator swig_members_end() { return members.end(); } 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; int res = SWIG_ERROR;
if (_own) int clear_pointer = 0;
*_own = own;
if (flags &SWIG_POINTER_DISOWN) if (own)
own = 0; *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 (!type && types.size()) {
if(vptr) if (vptr) {
*vptr = types[0].second.ptr; *vptr = types[0].second.ptr;
if (clear_pointer)
types[0].second.ptr = 0;
}
return SWIG_OK; return SWIG_OK;
} }
for (unsigned int j = 0; j < types.size(); ++j) for (unsigned int j = 0; j < types.size(); ++j)
if (type == types[j].first) { if (type == types[j].first) {
if(vptr) if (vptr) {
*vptr = types[j].second.ptr; *vptr = types[j].second.ptr;
if (clear_pointer)
types[j].second.ptr = 0;
}
return SWIG_OK; return SWIG_OK;
} }
for (unsigned int j = 0; j < types.size(); ++j) { for (unsigned int j = 0; j < types.size(); ++j) {
@ -607,10 +626,12 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
int newmemory = 0; int newmemory = 0;
*vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory); *vptr = SWIG_TypeCast(tc, types[j].second.ptr, &newmemory);
if (newmemory == 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 */ assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
if (_own) if (own)
*_own = *_own | SWIG_CAST_NEW_MEMORY; *own = *own | SWIG_CAST_NEW_MEMORY;
} }
if (clear_pointer)
types[j].second.ptr = 0;
} }
res = SWIG_OK; res = SWIG_OK;
break; break;
@ -619,7 +640,7 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
} }
bool is_owned() const { bool is_owned() const {
return own; return thisown;
} }
#ifdef SWIG_DIRECTORS #ifdef SWIG_DIRECTORS
@ -1526,6 +1547,7 @@ 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) { SWIGRUNTIME octave_value SWIG_Octave_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
int own = (flags &SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; int own = (flags &SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
if (ptr) {
#ifdef SWIG_DIRECTORS #ifdef SWIG_DIRECTORS
Swig::Director *d = Swig::get_rtdir(ptr); Swig::Director *d = Swig::get_rtdir(ptr);
if (d && Swig::swig_director_get_self(d)) if (d && Swig::swig_director_get_self(d))
@ -1533,6 +1555,8 @@ SWIGRUNTIME octave_value SWIG_Octave_NewPointerObj(void *ptr, swig_type_info *ty
#endif #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) { SWIGRUNTIME int SWIG_Octave_ConvertPtrAndOwn(octave_value ov, void **ptr, swig_type_info *type, int flags, int *own) {
if ( if (

View File

@ -32,8 +32,15 @@
#define SWIG_SetConstant(name, obj) SWIG_Octave_SetConstant(module_ns,name,obj) #define SWIG_SetConstant(name, obj) SWIG_Octave_SetConstant(module_ns,name,obj)
// raise // raise
#define SWIG_Octave_Raise(OBJ, TYPE, DESC) error("C++ side threw an exception of type " TYPE) %runtime %{
#define SWIG_Raise(obj, type, desc) SWIG_Octave_Raise(obj, type, desc) SWIGINTERN void SWIG_Octave_Raise(const octave_value &obj, const char *type) {
if (obj.is_string())
error("%s", obj.string_value().c_str());
else
error("C++ side threw an exception of type %s", type);
}
%}
#define SWIG_Raise(obj, type, desc) SWIG_Octave_Raise(obj, type)
// Include the unified typemap library // Include the unified typemap library
%include <typemaps/swigtypemaps.swg> %include <typemaps/swigtypemaps.swg>

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

@ -0,0 +1,32 @@
/* ------------------------------------------------------------
* SWIG library containing argc and argv multi-argument typemaps
* ------------------------------------------------------------ */
%typemap(in) (int ARGC, char **ARGV) {
int i;
I32 len;
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV) {
SWIG_croak("in method '$symname', Expecting reference to argv array");
goto fail;
}
len = av_len(av) + 1;
$1 = ($1_ltype) len;
$2 = (char **) malloc((len+1)*sizeof(char *));
for (i = 0; i < len; i++) {
SV **tv = av_fetch(av, i, 0);
$2[i] = SvPV_nolen(*tv);
}
$2[i] = NULL;
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
AV *av = (AV *)SvRV($input);
$1 = SvTYPE(av) == SVt_PVAV;
}
%typemap(freearg) (int ARGC, char **ARGV) {
if ($2 != NULL) {
free((void *)$2);
}
}

View File

@ -4,10 +4,21 @@
#include <stdlib.h> #include <stdlib.h>
extern "C" { extern "C" {
#endif #endif
#if __GNUC__ >= 10
#if defined(__cplusplus)
#pragma GCC diagnostic ignored "-Wvolatile"
#endif
#endif
#include "EXTERN.h" #include "EXTERN.h"
#include "perl.h" #include "perl.h"
#include "XSUB.h" #include "XSUB.h"
#if __GNUC__ >= 10
#pragma GCC diagnostic pop
#endif
/* PERL_REVISION was added in Perl 5.6. */ /* PERL_REVISION was added in Perl 5.6. */
#if !defined PERL_REVISION || (PERL_REVISION-0 == 5 && PERL_VERSION-0 < 8) #if !defined PERL_REVISION || (PERL_REVISION-0 == 5 && PERL_VERSION-0 < 8)
# error SWIG requires Perl >= 5.8.0 # error SWIG requires Perl >= 5.8.0

View File

@ -210,6 +210,7 @@ SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_
swig_cast_info *tc; swig_cast_info *tc;
void *voidptr = (void *)0; void *voidptr = (void *)0;
SV *tsv = 0; SV *tsv = 0;
int check_owned_pointer_release = (flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE;
if (own) if (own)
*own = 0; *own = 0;
@ -286,13 +287,14 @@ SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_
/* /*
* DISOWN implementation: we need a perl guru to check this one. * DISOWN implementation: we need a perl guru to check this one.
*/ */
if (tsv && (flags & SWIG_POINTER_DISOWN)) { if (tsv && ((flags & SWIG_POINTER_DISOWN) || check_owned_pointer_release)) {
/* /*
* almost copy paste code from below SWIG_POINTER_OWN setting * almost copy paste code from below SWIG_POINTER_OWN setting
*/ */
SV *obj = sv; SV *obj = sv;
HV *stash = SvSTASH(SvRV(obj)); HV *stash = SvSTASH(SvRV(obj));
GV *gv = *(GV**)hv_fetch(stash, "OWNER", 5, TRUE); GV *gv = *(GV**)hv_fetch(stash, "OWNER", 5, TRUE);
int owned = 0;
if (isGV(gv)) { if (isGV(gv)) {
HV *hv = GvHVn(gv); HV *hv = GvHVn(gv);
/* /*
@ -300,10 +302,21 @@ SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_
* Hence, to remove ownership, we delete the entry. * Hence, to remove ownership, we delete the entry.
*/ */
if (hv_exists_ent(hv, obj, 0)) { if (hv_exists_ent(hv, obj, 0)) {
owned = 1;
if (flags & SWIG_POINTER_DISOWN) {
hv_delete_ent(hv, obj, 0, 0); hv_delete_ent(hv, obj, 0, 0);
} }
} }
} }
if (check_owned_pointer_release && !owned) {
return SWIG_ERROR_RELEASE_NOT_OWNED;
}
}
if (tsv && (flags & SWIG_POINTER_CLEAR)) {
SvIV_set(tsv, 0);
}
return SWIG_OK; return SWIG_OK;
} }

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

@ -0,0 +1,40 @@
/* ------------------------------------------------------------
* SWIG library containing argc and argv multi-argument typemaps
* ------------------------------------------------------------ */
%typemap(in) (int ARGC, char **ARGV) {
int len, i;
zval *val;
zend_array *ar;
if (Z_TYPE($input) != IS_ARRAY) {
SWIG_PHP_Error(E_ERROR, "Type error in '$symname'. Expected array");
goto fail;
}
ar = Z_ARR($input);
len = zend_array_count(ar);
$1 = ($1_ltype) len;
$2 = (char **) malloc((len+1)*sizeof(char *));
i = 0;
ZEND_HASH_FOREACH_VAL(ar, val) {
if (Z_TYPE(*val) != IS_STRING) {
SWIG_PHP_Error(E_ERROR, "Array must use strings only, in '$symname'.");
goto fail;
}
if (i == len) {
SWIG_PHP_Error(E_ERROR, "Array is bigger than zend report in '$symname'.");
goto fail;
}
$2[i++] = Z_STRVAL(*val);
} ZEND_HASH_FOREACH_END();
$2[i] = NULL;
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING_ARRAY) (int ARGC, char **ARGV) {
$1 = Z_TYPE($input) == IS_ARRAY;
}
%typemap(freearg) (int ARGC, char **ARGV) {
if ($2 != NULL) {
free((void *)$2);
}
}

View File

@ -12,11 +12,11 @@
unsigned char, unsigned char,
signed char, signed char,
enum SWIGTYPE %{ enum SWIGTYPE %{
zend_declare_class_constant_long(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, ($1_type)$value); zend_declare_class_constant_long(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, ($1_type)($value));
%} %}
%typemap(classconsttab) bool %{ %typemap(classconsttab) bool %{
zend_declare_class_constant_bool(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, ($1_type)$value); zend_declare_class_constant_bool(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, ($1_type)($value));
%} %}
%typemap(classconsttab) float, %typemap(classconsttab) float,
@ -48,13 +48,13 @@
{ {
zval z; zval z;
ZVAL_UNDEF(&z); ZVAL_UNDEF(&z);
SWIG_SetPointerZval(&z, (void*)$value, $1_descriptor, 0); SWIG_SetPointerZval(&z, (void*)($value), $1_descriptor, 0);
zval_copy_ctor(&z); zval_copy_ctor(&z);
zend_declare_class_constant(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, &z); zend_declare_class_constant(SWIG_Php_ce_$class, "$const_name", sizeof("$const_name") - 1, &z);
} }
%} %}
%typemap(classconsttab) SWIGTYPE (CLASS::*) ""; %typemap(classconsttab) SWIGTYPE (CLASS::*) ""
%typemap(consttab) int, %typemap(consttab) int,
unsigned int, unsigned int,
@ -65,10 +65,10 @@
unsigned char, unsigned char,
signed char, signed char,
enum SWIGTYPE enum SWIGTYPE
"SWIG_LONG_CONSTANT($symname, ($1_type)$value);"; "SWIG_LONG_CONSTANT($symname, ($1_type)($value));";
%typemap(consttab) bool %typemap(consttab) bool
"SWIG_BOOL_CONSTANT($symname, ($1_type)$value);"; "SWIG_BOOL_CONSTANT($symname, ($1_type)($value));";
%typemap(consttab) float, %typemap(consttab) float,
double double
@ -92,7 +92,7 @@
SWIGTYPE [] { SWIGTYPE [] {
zend_constant c; zend_constant c;
ZVAL_UNDEF(&c.value); ZVAL_UNDEF(&c.value);
SWIG_SetPointerZval(&c.value, (void*)$value, $1_descriptor, 0); SWIG_SetPointerZval(&c.value, (void*)($value), $1_descriptor, 0);
zval_copy_ctor(&c.value); zval_copy_ctor(&c.value);
c.name = zend_string_init("$symname", sizeof("$symname") - 1, 0); c.name = zend_string_init("$symname", sizeof("$symname") - 1, 0);
SWIG_ZEND_CONSTANT_SET_FLAGS(&c, CONST_CS, module_number); SWIG_ZEND_CONSTANT_SET_FLAGS(&c, CONST_CS, module_number);
@ -100,4 +100,4 @@
} }
/* Handled as a global variable. */ /* Handled as a global variable. */
%typemap(consttab) SWIGTYPE (CLASS::*) ""; %typemap(consttab) SWIGTYPE (CLASS::*) ""

View File

@ -125,14 +125,31 @@
swig_acquire_ownership_obj((void*)$result, own); swig_acquire_ownership_obj((void*)$result, own);
%} %}
%typemap(in, phptype="SWIGTYPE") SWIGTYPE &, %typemap(in, phptype="SWIGTYPE") SWIGTYPE &
SWIGTYPE &&
%{ %{
if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) { if (SWIG_ConvertPtr(&$input, (void **) &$1, $1_descriptor, 0) < 0 || $1 == NULL) {
zend_type_error("Expected $1_descriptor for argument $argnum of $symname"); zend_type_error("Expected $1_descriptor for argument $argnum of $symname");
return; 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), %typemap(directorout) SWIGTYPE & ($1_ltype tmp),
SWIGTYPE && ($1_ltype tmp) SWIGTYPE && ($1_ltype tmp)
@ -240,9 +257,7 @@
if ((long long)LONG_MIN <= $1 && $1 <= (long long)LONG_MAX) { if ((long long)LONG_MIN <= $1 && $1 <= (long long)LONG_MAX) {
RETVAL_LONG((long)($1)); RETVAL_LONG((long)($1));
} else { } else {
char temp[256]; RETVAL_NEW_STR(zend_strpprintf(0, "%lld", (long long)$1));
sprintf(temp, "%lld", (long long)$1);
RETVAL_STRING(temp);
} }
%} %}
%typemap(out, phptype="int|string") unsigned long long %typemap(out, phptype="int|string") unsigned long long
@ -250,9 +265,7 @@
if ($1 <= (unsigned long long)LONG_MAX) { if ($1 <= (unsigned long long)LONG_MAX) {
RETVAL_LONG((long)($1)); RETVAL_LONG((long)($1));
} else { } else {
char temp[256]; RETVAL_NEW_STR(zend_strpprintf(0, "%llu", (unsigned long long)$1));
sprintf(temp, "%llu", (unsigned long long)$1);
RETVAL_STRING(temp);
} }
%} %}
@ -286,9 +299,7 @@
if ((long long)LONG_MIN <= *$1 && *$1 <= (long long)LONG_MAX) { if ((long long)LONG_MIN <= *$1 && *$1 <= (long long)LONG_MAX) {
RETVAL_LONG((long)(*$1)); RETVAL_LONG((long)(*$1));
} else { } else {
char temp[256]; RETVAL_NEW_STR(zend_strpprintf(0, "%lld", (long long)(*$1)));
sprintf(temp, "%lld", (long long)(*$1));
RETVAL_STRING(temp);
} }
%} %}
%typemap(out, phptype="int|string") const unsigned long long & %typemap(out, phptype="int|string") const unsigned long long &
@ -296,9 +307,7 @@
if (*$1 <= (unsigned long long)LONG_MAX) { if (*$1 <= (unsigned long long)LONG_MAX) {
RETVAL_LONG((long)(*$1)); RETVAL_LONG((long)(*$1));
} else { } else {
char temp[256]; RETVAL_NEW_STR(zend_strpprintf(0, "%llu", (unsigned long long)(*$1)));
sprintf(temp, "%llu", (unsigned long long)(*$1));
RETVAL_STRING(temp);
} }
%} %}
@ -451,7 +460,7 @@
%typemap(out, phptype="SWIGTYPE") SWIGTYPE %typemap(out, phptype="SWIGTYPE") SWIGTYPE
{ {
#ifdef __cplusplus #ifdef __cplusplus
$&1_ltype resultobj = new $1_ltype((const $1_ltype &) $1); $&1_ltype resultobj = new $1_ltype($1);
#else #else
$&1_ltype resultobj = ($&1_ltype) malloc(sizeof($1_type)); $&1_ltype resultobj = ($&1_ltype) malloc(sizeof($1_type));
memcpy(resultobj, &$1, sizeof($1_type)); memcpy(resultobj, &$1, sizeof($1_type));
@ -462,10 +471,10 @@
%typemap(directorin) SWIGTYPE %typemap(directorin) SWIGTYPE
%{ %{
ZVAL_UNDEF($input); ZVAL_UNDEF($input);
SWIG_SetPointerZval($input, SWIG_as_voidptr(new $1_ltype((const $1_ltype &)$1)), $&1_descriptor, 1); SWIG_SetPointerZval($input, (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] %typemap(out, phptype="string") char [ANY]
{ {

View File

@ -9,4 +9,8 @@
SWIG_php_minit { SWIG_php_minit {
zend_class_entry SWIGUNUSED internal_ce; zend_class_entry SWIGUNUSED internal_ce;
SWIG_InitializeModule((void*)&module_number); SWIG_InitializeModule((void*)&module_number);
#if PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION == 0
/* This hack is needed to avoid segfaults. */
EG(class_table) = CG(class_table);
#endif
%} %}

View File

@ -10,8 +10,6 @@
extern "C" { extern "C" {
#endif #endif
#include "php.h"
#if PHP_MAJOR_VERSION < 7 #if PHP_MAJOR_VERSION < 7
# error These bindings need PHP 7 or later - to generate PHP5 bindings use: SWIG < 4.0.0 and swig -php5 # error These bindings need PHP 7 or later - to generate PHP5 bindings use: SWIG < 4.0.0 and swig -php5
#endif #endif
@ -195,7 +193,7 @@ SWIG_ConvertPtrAndOwn(zval *z, void **ptr, swig_type_info *ty, int flags, swig_o
/* They don't care about the target type, so just pass on the pointer! */ /* They don't care about the target type, so just pass on the pointer! */
*ptr = value->ptr; *ptr = value->ptr;
} else { } else {
swig_cast_info *tc = SWIG_TypeCheckStruct(value->type, ty); swig_cast_info *tc = SWIG_TypeCheck(value->type->name, ty);
if (tc) { if (tc) {
int newmemory = 0; int newmemory = 0;
*ptr = SWIG_TypeCast(tc, value->ptr, &newmemory); *ptr = SWIG_TypeCast(tc, value->ptr, &newmemory);
@ -208,10 +206,20 @@ SWIG_ConvertPtrAndOwn(zval *z, void **ptr, swig_type_info *ty, int flags, swig_o
*ptr = NULL; *ptr = NULL;
} }
} }
if (*ptr == NULL) return SWIG_ERROR;
if (((flags & SWIG_POINTER_RELEASE) == SWIG_POINTER_RELEASE) && !value->newobject) {
return SWIG_ERROR_RELEASE_NOT_OWNED;
} else {
if (*ptr == NULL)
return SWIG_ERROR; /* should be SWIG_NullReferenceError?? */
if (flags & SWIG_POINTER_DISOWN) { if (flags & SWIG_POINTER_DISOWN) {
value->newobject = 0; value->newobject = 0;
} }
if (flags & SWIG_POINTER_CLEAR) {
value->ptr = 0;
}
}
return SWIG_OK; return SWIG_OK;
} }
case IS_NULL: case IS_NULL:

View File

@ -0,0 +1,41 @@
/* -----------------------------------------------------------------------------
* 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) {
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 $descriptor(TYPE *) for argument $argnum of $symname");
return;
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::auto_ptr< TYPE > %{
SWIG_SetPointerZval($result, (void *)$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

@ -86,5 +86,5 @@ namespace std {
/* SWIG will apply the non-const typemap above to const string& without /* SWIG will apply the non-const typemap above to const string& without
* this more specific typemap. */ * this more specific typemap. */
%typemap(argout) const string & ""; %typemap(argout) const string & ""
} }

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(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) {
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 $descriptor(TYPE *) for argument $argnum of $symname");
return;
}
}
$1.reset((TYPE *)argp);
}
%typemap (out) std::unique_ptr< TYPE > %{
SWIG_SetPointerZval($result, (void *)$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 {};
}

View File

@ -0,0 +1,24 @@
/* -----------------------------------------------------------------------------
* 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) {
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;
}
SwigValueWrapper< $1_ltype >::reset($1, ($&1_type)argp);
}

View File

@ -31,8 +31,8 @@
temp = (Z_TYPE($input) == IS_TRUE); temp = (Z_TYPE($input) == IS_TRUE);
$1 = &temp; $1 = &temp;
%} %}
%typemap(argout) TYPE *INPUT, TYPE &INPUT ""; %typemap(argout) TYPE *INPUT, TYPE &INPUT ""
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;"; %typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;"
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT %typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT
{ {
zval o; zval o;
@ -57,8 +57,8 @@
temp = (TYPE) zval_get_double(&$input); temp = (TYPE) zval_get_double(&$input);
$1 = &temp; $1 = &temp;
%} %}
%typemap(argout) TYPE *INPUT, TYPE &INPUT ""; %typemap(argout) TYPE *INPUT, TYPE &INPUT ""
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;"; %typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;"
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT %typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT
{ {
zval o; zval o;
@ -82,8 +82,8 @@
temp = (TYPE) zval_get_long(&$input); temp = (TYPE) zval_get_long(&$input);
$1 = &temp; $1 = &temp;
%} %}
%typemap(argout) TYPE *INPUT, TYPE &INPUT ""; %typemap(argout) TYPE *INPUT, TYPE &INPUT ""
%typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;"; %typemap(in,numinputs=0) TYPE *OUTPUT(TYPE temp), TYPE &OUTPUT(TYPE temp) "$1 = &temp;"
%typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT %typemap(argout,fragment="t_output_helper") TYPE *OUTPUT, TYPE &OUTPUT
{ {
zval o; zval o;
@ -122,9 +122,7 @@ INT_TYPEMAP(long long);
if ((long long)LONG_MIN <= temp$argnum && temp$argnum <= (long long)LONG_MAX) { if ((long long)LONG_MIN <= temp$argnum && temp$argnum <= (long long)LONG_MAX) {
ZVAL_LONG(&o, (long)temp$argnum); ZVAL_LONG(&o, (long)temp$argnum);
} else { } else {
char temp[256]; ZVAL_NEW_STR(&o, zend_strpprintf(0, "%lld", (long long)temp$argnum));
sprintf(temp, "%lld", (long long)temp$argnum);
ZVAL_STRING(&o, temp);
} }
t_output_helper($result, &o); t_output_helper($result, &o);
} }
@ -138,9 +136,7 @@ INT_TYPEMAP(long long);
if ((long long)LONG_MIN <= lvalue$argnum && lvalue$argnum <= (long long)LONG_MAX) { if ((long long)LONG_MIN <= lvalue$argnum && lvalue$argnum <= (long long)LONG_MAX) {
ZVAL_LONG(&$arg, (long)temp$argnum); ZVAL_LONG(&$arg, (long)temp$argnum);
} else { } else {
char temp[256]; ZVAL_NEW_STR(&$arg, zend_strpprintf(0, "%lld", (long long)lvalue$argnum));
sprintf(temp, "%lld", (long long)lvalue$argnum);
ZVAL_STRING(&$arg, temp);
} }
%} %}
%typemap(argout) long long &OUTPUT %typemap(argout) long long &OUTPUT
@ -148,9 +144,7 @@ INT_TYPEMAP(long long);
if ((long long)LONG_MIN <= *arg$argnum && *arg$argnum <= (long long)LONG_MAX) { if ((long long)LONG_MIN <= *arg$argnum && *arg$argnum <= (long long)LONG_MAX) {
ZVAL_LONG($result, (long)(*arg$argnum)); ZVAL_LONG($result, (long)(*arg$argnum));
} else { } else {
char temp[256]; ZVAL_NEW_STR($result, zend_strpprintf(0, "%lld", (long long)(*arg$argnum)));
sprintf(temp, "%lld", (long long)(*arg$argnum));
ZVAL_STRING($result, temp);
} }
%} %}
@ -161,9 +155,7 @@ INT_TYPEMAP(unsigned long long);
if (temp$argnum <= (unsigned long long)LONG_MAX) { if (temp$argnum <= (unsigned long long)LONG_MAX) {
ZVAL_LONG(&o, temp$argnum); ZVAL_LONG(&o, temp$argnum);
} else { } else {
char temp[256]; ZVAL_NEW_STR(&o, zend_strpprintf(0, "%llu", (unsigned long long)temp$argnum));
sprintf(temp, "%llu", (unsigned long long)temp$argnum);
ZVAL_STRING(&o, temp);
} }
t_output_helper($result, &o); t_output_helper($result, &o);
} }
@ -177,9 +169,7 @@ INT_TYPEMAP(unsigned long long);
if (lvalue$argnum <= (unsigned long long)LONG_MAX) { if (lvalue$argnum <= (unsigned long long)LONG_MAX) {
ZVAL_LONG($arg, (long)(lvalue$argnum)); ZVAL_LONG($arg, (long)(lvalue$argnum));
} else { } else {
char temp[256]; ZVAL_NEW_STR((*$arg), zend_strpprintf(0, "%llu", (unsigned long long)lvalue$argnum));
sprintf(temp, "%llu", (unsigned long long)lvalue$argnum);
ZVAL_STRING((*$arg), temp);
} }
%} %}
%typemap(argout) unsigned long long &OUTPUT %typemap(argout) unsigned long long &OUTPUT
@ -187,9 +177,7 @@ INT_TYPEMAP(unsigned long long);
if (*arg$argnum <= (unsigned long long)LONG_MAX) { if (*arg$argnum <= (unsigned long long)LONG_MAX) {
ZVAL_LONG($result, (long)(*arg$argnum)); ZVAL_LONG($result, (long)(*arg$argnum));
} else { } else {
char temp[256]; ZVAL_NEW_STR($result, zend_strpprintf(0, "%llu", (unsigned long long)(*arg$argnum)));
sprintf(temp, "%llu", (unsigned long long)(*arg$argnum));
ZVAL_STRING($result, temp);
} }
%} %}

View File

@ -81,7 +81,7 @@
%{ %{
$*1_ltype swig_val; $*1_ltype swig_val;
CONVERT_IN(swig_val, $*1_ltype, *$input); CONVERT_IN(swig_val, $*1_ltype, *$input);
$1_ltype temp = new $*1_ltype(($*1_ltype)swig_val); $1_ltype temp = new $*1_ltype(swig_val);
swig_acquire_ownership(temp); swig_acquire_ownership(temp);
$result = temp; $result = temp;
%} %}

View File

@ -4,7 +4,7 @@
%echo "pointer.i is deprecated. Use cpointer.i instead." %echo "pointer.i is deprecated. Use cpointer.i instead."
%echo "See http://www.swig.org/Doc3.0/Library.html" %echo "See https://www.swig.org/Doc3.0/Library.html"

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