Enhance SWIGTYPE "out" typemaps to use std::move when copying
objects, thereby making use of move semantics when wrapping a function returning
by value if the returned type supports move semantics.
Wrapping functions that return move only types 'by value' now work out the box
without having to provide custom typemaps.
The implementation removed all casts in the "out" typemaps to allow the compiler to
appropriately choose calling a move constructor, where possible, otherwise a copy
constructor. The implementation alsoand required modifying SwigValueWrapper to
change a cast operator from:
SwigValueWrapper::operator T&() const;
to
#if __cplusplus >=201103L
SwigValueWrapper::operator T&&() const;
#else
SwigValueWrapper::operator T&() const;
#endif
This is not backwards compatible for C++11 and later when using the valuewrapper feature
if a cast is explicitly being made in user supplied "out" typemaps. Suggested change
in custom "out" typemaps for C++11 and later code:
1. Try remove the cast altogether to let the compiler use an appropriate implicit cast.
2. Change the cast, for example, from static_cast<X &> to static_cast<X &&>, using the
__cplusplus macro if all versions of C++ need to be supported.
Issue #999
Closes #1044
More about the commit:
Added some missing "varout" typemaps for Ocaml which was falling back to
use "out" typemaps as they were missing.
Ruby std::set fix for SwigValueWrapper C++11 changes.
286 lines
9.4 KiB
Text
286 lines
9.4 KiB
Text
/* 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_ltype($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
|
|
%}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* 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>
|
|
%}
|