aboutsummaryrefslogtreecommitdiff
path: root/Lib/d
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/d')
-rw-r--r--Lib/d/argcargv.i26
-rw-r--r--Lib/d/boost_shared_ptr.i6
-rw-r--r--Lib/d/carrays.i76
-rw-r--r--Lib/d/cpointer.i8
-rw-r--r--Lib/d/dclassgen.swg32
-rw-r--r--Lib/d/dexception.swg2
-rw-r--r--Lib/d/dhead.swg125
-rw-r--r--Lib/d/dkw.swg4
-rw-r--r--Lib/d/doperators.swg127
-rw-r--r--Lib/d/dprimitives.swg13
-rw-r--r--Lib/d/dstrings.swg7
-rw-r--r--Lib/d/dswigtype.swg93
-rw-r--r--Lib/d/std_auto_ptr.i42
-rw-r--r--Lib/d/std_map.i4
-rw-r--r--Lib/d/std_string.i7
-rw-r--r--Lib/d/std_unique_ptr.i42
-rw-r--r--Lib/d/std_vector.i164
-rw-r--r--Lib/d/swigmove.i16
-rw-r--r--Lib/d/wrapperloader.swg13
19 files changed, 313 insertions, 494 deletions
diff --git a/Lib/d/argcargv.i b/Lib/d/argcargv.i
new file mode 100644
index 000000000..92544f9b6
--- /dev/null
+++ b/Lib/d/argcargv.i
@@ -0,0 +1,26 @@
+/* -------------------------------------------------------------
+ * SWIG library containing argc and argv multi-argument typemaps
+ * ------------------------------------------------------------- */
+
+%typemap(ctype) (int ARGC, char **ARGV) "SWIG_c_dstring_array"
+%typemap(imtype) (int ARGC, char **ARGV) "string[]"
+%typemap(dtype) (int ARGC, char **ARGV) "string[]"
+
+%typemap(in, canthrow=1) (int ARGC, char **ARGV) {
+ $1_ltype i, len;
+ len = $input.len;
+ $2 = ($2_ltype) malloc((len+1)*sizeof($*2_ltype));
+ if ($2 == SWIG_NULLPTR) {
+ SWIG_DSetPendingException(SWIG_DException, "memory allocation failed");
+ return $null;
+ }
+ $1 = len;
+ for (i = 0; i < len; i++) {
+ $2[i] = $input.array[i].str;
+ }
+ $2[i] = SWIG_NULLPTR;
+}
+
+%typemap(freearg) (int ARGC, char **ARGV) {
+ free((void *)$2);
+}
diff --git a/Lib/d/boost_shared_ptr.i b/Lib/d/boost_shared_ptr.i
index 4a220a589..6d85c5aef 100644
--- a/Lib/d/boost_shared_ptr.i
+++ b/Lib/d/boost_shared_ptr.i
@@ -23,10 +23,10 @@
}
$1 = *argp; %}
%typemap(out) CONST TYPE
-%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
+%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype($1)); %}
%typemap(directorin) CONST TYPE
-%{ $input = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype((const $1_ltype &)$1)); %}
+%{ $input = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > (new $1_ltype(SWIG_STD_MOVE($1))); %}
%typemap(directorout) CONST TYPE
%{ if (!$input) {
@@ -116,7 +116,7 @@
%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * ($*1_ltype tempnull)
%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
%typemap(out, fragment="SWIG_null_deleter") SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *
-%{ $result = ($1 && *$1) ? new $*1_ltype(*($1_ltype)$1) : 0;
+%{ $result = ($1 && *$1) ? new $*1_ltype(*$1) : 0;
if ($owner) delete $1; %}
%typemap(directorin) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *
diff --git a/Lib/d/carrays.i b/Lib/d/carrays.i
index f2803ea46..0bd99a7c9 100644
--- a/Lib/d/carrays.i
+++ b/Lib/d/carrays.i
@@ -10,16 +10,16 @@
* Generates functions for creating and accessing elements of a C array
* (as pointers). Creates the following functions:
*
- * TYPE *new_NAME(int nelements)
+ * TYPE *new_NAME(size_t nelements)
* void delete_NAME(TYPE *);
- * TYPE NAME_getitem(TYPE *, int index);
- * void NAME_setitem(TYPE *, int index, TYPE value);
+ * TYPE NAME_getitem(TYPE *, size_t index);
+ * void NAME_setitem(TYPE *, size_t index, TYPE value);
*
* ----------------------------------------------------------------------------- */
%define %array_functions(TYPE,NAME)
%{
-static TYPE *new_##NAME(int nelements) { %}
+static TYPE *new_##NAME(size_t nelements) { %}
#ifdef __cplusplus
%{ return new TYPE[nelements](); %}
#else
@@ -35,18 +35,18 @@ static void delete_##NAME(TYPE *ary) { %}
#endif
%{}
-static TYPE NAME##_getitem(TYPE *ary, int index) {
+static TYPE NAME##_getitem(TYPE *ary, size_t index) {
return ary[index];
}
-static void NAME##_setitem(TYPE *ary, int index, TYPE value) {
+static void NAME##_setitem(TYPE *ary, size_t index, TYPE value) {
ary[index] = value;
}
%}
-TYPE *new_##NAME(int nelements);
+TYPE *new_##NAME(size_t nelements);
void delete_##NAME(TYPE *ary);
-TYPE NAME##_getitem(TYPE *ary, int index);
-void NAME##_setitem(TYPE *ary, int index, TYPE value);
+TYPE NAME##_getitem(TYPE *ary, size_t index);
+void NAME##_setitem(TYPE *ary, size_t index, TYPE value);
%enddef
@@ -58,13 +58,13 @@ void NAME##_setitem(TYPE *ary, int index, TYPE value);
* interface:
*
* struct NAME {
- * NAME(int nelements);
+ * NAME(size_t nelements);
* ~NAME();
- * TYPE getitem(int index);
- * void setitem(int index, TYPE value);
+ * TYPE getitem(size_t index);
+ * void setitem(size_t index, TYPE value);
* TYPE * ptr();
* static NAME *frompointer(TYPE *t);
- * }
+ * }
*
* ----------------------------------------------------------------------------- */
@@ -76,34 +76,36 @@ typedef TYPE NAME;
typedef struct {} NAME;
%extend NAME {
+
#ifdef __cplusplus
- NAME(int nelements) {
- return new TYPE[nelements]();
- }
- ~NAME() {
- delete [] self;
- }
+NAME(size_t nelements) {
+ return new TYPE[nelements]();
+}
+~NAME() {
+ delete [] self;
+}
#else
- NAME(int nelements) {
- return (TYPE *) calloc(nelements,sizeof(TYPE));
- }
- ~NAME() {
- free(self);
- }
+NAME(size_t nelements) {
+ return (TYPE *) calloc(nelements,sizeof(TYPE));
+}
+~NAME() {
+ free(self);
+}
#endif
- TYPE getitem(int index) {
- return self[index];
- }
- void setitem(int index, TYPE value) {
- self[index] = value;
- }
- TYPE * ptr() {
- return self;
- }
- static NAME *frompointer(TYPE *t) {
- return (NAME *) t;
- }
+TYPE getitem(size_t index) {
+ return self[index];
+}
+void setitem(size_t index, TYPE value) {
+ self[index] = value;
+}
+TYPE * ptr() {
+ return self;
+}
+static NAME *frompointer(TYPE *t) {
+ return (NAME *) t;
+}
+
};
%types(NAME = TYPE);
diff --git a/Lib/d/cpointer.i b/Lib/d/cpointer.i
index 75e610f67..da3084b7a 100644
--- a/Lib/d/cpointer.i
+++ b/Lib/d/cpointer.i
@@ -54,14 +54,14 @@ NAME() {
return new TYPE();
}
~NAME() {
- if (self) delete self;
+ delete self;
}
#else
NAME() {
return (TYPE *) calloc(1,sizeof(TYPE));
}
~NAME() {
- if (self) free(self);
+ free(self);
}
#endif
}
@@ -133,9 +133,9 @@ static TYPE *copy_##NAME(TYPE value) { %}
static void delete_##NAME(TYPE *self) { %}
#ifdef __cplusplus
-%{ if (self) delete self; %}
+%{ delete self; %}
#else
-%{ if (self) free(self); %}
+%{ free(self); %}
#endif
%{}
diff --git a/Lib/d/dclassgen.swg b/Lib/d/dclassgen.swg
index 84fa03a0b..e4ff8d5f5 100644
--- a/Lib/d/dclassgen.swg
+++ b/Lib/d/dclassgen.swg
@@ -76,6 +76,19 @@ public static void* swigGetCPtr(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr;
}
+public static void* swigRelease(typeof(this) obj) {
+ if (obj !is null) {
+ if (!obj.swigCMemOwn)
+ throw new Exception("Cannot release ownership as memory is not owned");
+ void* ptr = obj.swigCPtr;
+ obj.swigCMemOwn = false;
+ obj.dispose();
+ return ptr;
+ } else {
+ return null;
+ }
+}
+
mixin $imdmodule.SwigOperatorDefinitions;
%}
@@ -92,6 +105,19 @@ public static void* swigGetCPtr(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr;
}
+public static void* swigRelease(typeof(this) obj) {
+ if (obj !is null) {
+ if (!obj.swigCMemOwn)
+ throw new Exception("Cannot release ownership as memory is not owned");
+ void* ptr = obj.swigCPtr;
+ obj.swigCMemOwn = false;
+ obj.dispose();
+ return ptr;
+ } else {
+ return null;
+ }
+}
+
mixin $imdmodule.SwigOperatorDefinitions;
%}
@@ -100,7 +126,7 @@ mixin $imdmodule.SwigOperatorDefinitions;
* Type wrapper classes.
*/
-%typemap(dbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{
+%typemap(dbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE &&, SWIGTYPE [] %{
private void* swigCPtr;
public this(void* cObject, bool futureUse) {
@@ -115,6 +141,10 @@ public static void* swigGetCPtr(typeof(this) obj) {
return (obj is null) ? null : obj.swigCPtr;
}
+public static void* swigRelease(typeof(this) obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+
mixin $imdmodule.SwigOperatorDefinitions;
%}
diff --git a/Lib/d/dexception.swg b/Lib/d/dexception.swg
index 1aadbaada..74e0422b1 100644
--- a/Lib/d/dexception.swg
+++ b/Lib/d/dexception.swg
@@ -15,7 +15,7 @@
unsigned long,
unsigned short
%{ char error_msg[256];
- sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
+ SWIG_snprintf(error_msg, sizeof(error_msg), "C++ $1_type exception thrown, value: %d", $1);
SWIG_DSetPendingException(SWIG_DException, error_msg);
return $null; %}
diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg
index 50e9c2e87..40393c988 100644
--- a/Lib/d/dhead.swg
+++ b/Lib/d/dhead.swg
@@ -1,9 +1,6 @@
/* -----------------------------------------------------------------------------
* dhead.swg
*
- * Support code for exceptions if the SWIG_D_NO_EXCEPTION_HELPER is not defined
- * Support code for strings if the SWIG_D_NO_STRING_HELPER is not defined
- *
* Support code for function pointers. ----------------------------------------------------------------------------- */
%insert(runtime) %{
@@ -12,7 +9,7 @@
#include <stdio.h>
/* Contract support. */
-#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } else
+#define SWIG_contract_assert(nullreturn, expr, msg) do { if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } } while (0)
%}
@@ -20,7 +17,6 @@
* Exception support code.
*/
-#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
%insert(runtime) %{
// Support for throwing D exceptions from C/C++.
typedef enum {
@@ -71,87 +67,6 @@ SWIGEXPORT void SWIGRegisterExceptionCallbacks_$module(
}
%}
-#if (SWIG_D_VERSION == 1)
-%pragma(d) imdmoduleimports=%{
-// Exception throwing support currently requires Tango, but there is no reason
-// why it could not support Phobos.
-static import tango.core.Exception;
-static import tango.core.Thread;
-static import tango.stdc.stringz;
-%}
-
-%pragma(d) imdmodulecode=%{
-private class SwigExceptionHelper {
- static this() {
- swigRegisterExceptionCallbacks$module(
- &setException,
- &setIllegalArgumentException,
- &setIllegalElementException,
- &setIOException,
- &setNoSuchElementException);
- }
-
- static void setException(char* message) {
- auto exception = new object.Exception(tango.stdc.stringz.fromStringz(message).dup);
- SwigPendingException.set(exception);
- }
-
- static void setIllegalArgumentException(char* message) {
- auto exception = new tango.core.Exception.IllegalArgumentException(tango.stdc.stringz.fromStringz(message).dup);
- SwigPendingException.set(exception);
- }
-
- static void setIllegalElementException(char* message) {
- auto exception = new tango.core.Exception.IllegalElementException(tango.stdc.stringz.fromStringz(message).dup);
- SwigPendingException.set(exception);
- }
-
- static void setIOException(char* message) {
- auto exception = new tango.core.Exception.IOException(tango.stdc.stringz.fromStringz(message).dup);
- SwigPendingException.set(exception);
- }
-
- static void setNoSuchElementException(char* message) {
- auto exception = new tango.core.Exception.NoSuchElementException(tango.stdc.stringz.fromStringz(message).dup);
- SwigPendingException.set(exception);
- }
-}
-
-package class SwigPendingException {
-public:
- static this() {
- m_sPendingException = new ThreadLocalData(null);
- }
-
- static bool isPending() {
- return m_sPendingException.val !is null;
- }
-
- static void set(object.Exception e) {
- auto pending = m_sPendingException.val;
- if (pending !is null) {
- e.next = pending;
- throw new object.Exception("FATAL: An earlier pending exception from C/C++ " ~
- "code was missed and thus not thrown (" ~ pending.classinfo.name ~ ": " ~
- pending.msg ~ ")!", e);
- }
- m_sPendingException.val = e;
- }
-
- static object.Exception retrieve() {
- auto e = m_sPendingException.val;
- m_sPendingException.val = null;
- return e;
- }
-
-private:
- // The reference to the pending exception (if any) is stored thread-local.
- alias tango.core.Thread.ThreadLocal!(object.Exception) ThreadLocalData;
- static ThreadLocalData m_sPendingException;
-}
-alias void function(char* message) SwigExceptionCallback;
-%}
-#else
%pragma(d) imdmoduleimports=%{
static import std.conv;
%}
@@ -175,7 +90,7 @@ private class SwigExceptionHelper {
}
}
-package struct SwigPendingException {
+public class SwigPendingException {
public:
static this() {
m_sPendingException = null;
@@ -208,16 +123,13 @@ private:
}
alias void function(const char* message) SwigExceptionCallback;
%}
-#endif
// Callback registering function in wrapperloader.swg.
-#endif // SWIG_D_NO_EXCEPTION_HELPER
/*
* String support code.
*/
-#if !defined(SWIG_D_NO_STRING_HELPER)
%insert(runtime) %{
// Callback for returning strings to D without leaking memory.
typedef char * (* SWIG_DStringHelperCallback)(const char *);
@@ -231,23 +143,6 @@ SWIGEXPORT void SWIGRegisterStringCallback_$module(SWIG_DStringHelperCallback ca
}
%}
-#if (SWIG_D_VERSION == 1)
-%pragma(d) imdmoduleimports = "static import tango.stdc.stringz;";
-
-%pragma(d) imdmodulecode = %{
-private class SwigStringHelper {
- static this() {
- swigRegisterStringCallback$module(&createString);
- }
-
- static char* createString(char* cString) {
- // We are effectively dup'ing the string here.
- return tango.stdc.stringz.toStringz(tango.stdc.stringz.fromStringz(cString));
- }
-}
-alias char* function(char* cString) SwigStringCallback;
-%}
-#else
%pragma(d) imdmoduleimports = %{
static import std.conv;
static import std.string;
@@ -261,31 +156,18 @@ private class SwigStringHelper {
static const(char)* createString(const(char*) cString) {
// We are effectively dup'ing the string here.
- // TODO: Is this also correct for D2/Phobos?
+ // TODO: Is this correct for D2/Phobos?
return std.string.toStringz(std.conv.to!string(cString));
}
}
alias const(char)* function(const(char*) cString) SwigStringCallback;
%}
-#endif
// Callback registering function in wrapperloader.swg.
-#endif // SWIG_D_NO_STRING_HELPER
/*
* Function pointer support code.
*/
-#if (SWIG_D_VERSION == 1)
-%pragma(d) imdmodulecode = %{
-template SwigExternC(T) {
- static if (is(typeof(*(T.init)) R == return)) {
- static if (is(typeof(*(T.init)) P == function)) {
- alias extern(C) R function(P) SwigExternC;
- }
- }
-}
-%}
-#else
%pragma(d) imdmodulecode = %{
template SwigExternC(T) if (is(typeof(*(T.init)) P == function)) {
static if (is(typeof(*(T.init)) R == return)) {
@@ -295,4 +177,3 @@ template SwigExternC(T) if (is(typeof(*(T.init)) P == function)) {
}
}
%}
-#endif
diff --git a/Lib/d/dkw.swg b/Lib/d/dkw.swg
index 581093f96..b96d1fa6b 100644
--- a/Lib/d/dkw.swg
+++ b/Lib/d/dkw.swg
@@ -2,7 +2,7 @@
#define D_DKW_SWG_
/* Warnings for D keywords */
-#define DKEYWORD(x) %keywordwarn("'" `x` "' is a D keyword, renaming to '_" `x` "'",rename="_%s") `x`
+#define DKEYWORD(x) %keywordwarn("'" `x` "' is a D keyword",rename="_%s") `x`
// Source: http://www.digitalmars.com/d/{1.0,2.0}/lex.html and
DKEYWORD(Error);
@@ -120,7 +120,7 @@ DKEYWORD(with);
DKEYWORD(wstring);
// Not really a keyword, but dispose() methods are generated in proxy classes
-// and it's a special method name for D1/Tango.
+// and it was a special method name for D1/Tango.
DKEYWORD(dispose);
#undef DKEYWORD
diff --git a/Lib/d/doperators.swg b/Lib/d/doperators.swg
index 0cb63533c..f651c3928 100644
--- a/Lib/d/doperators.swg
+++ b/Lib/d/doperators.swg
@@ -4,129 +4,6 @@
* Mapping of C++ operator overloading methods to D.
* ----------------------------------------------------------------------------- */
-#if (SWIG_D_VERSION == 1)
-
-%pragma(d) imdmodulecode=%{
-template SwigOperatorDefinitions() {
- public override int opEquals(Object o) {
- if (auto rhs = cast(typeof(this))o) {
- if (swigCPtr == rhs.swigCPtr) return 1;
- static if (is(typeof(swigOpEquals(rhs)))) {
- return swigOpEquals(rhs) ? 1 : 0;
- } else {
- return 0;
- }
- }
- return super.opEquals(o);
- }
-%}
-// opEquals is emitted in pure C mode as well to define two proxy classes
-// pointing to the same struct as equal.
-
-#ifdef __cplusplus
-%rename(opPos) *::operator+();
-%rename(opPos) *::operator+() const;
-%rename(opNeg) *::operator-();
-%rename(opNeg) *::operator-() const;
-%rename(opCom) *::operator~();
-%rename(opCom) *::operator~() const;
-
-%rename(opAdd) *::operator+;
-%rename(opAddAssign) *::operator+=;
-%rename(opSub) *::operator-;
-%rename(opSubAssign) *::operator-=;
-%rename(opMul) *::operator*;
-%rename(opMulAssign) *::operator*=;
-%rename(opDiv) *::operator/;
-%rename(opDivAssign) *::operator/=;
-%rename(opMod) *::operator%;
-%rename(opModAssign) *::operator%=;
-%rename(opAnd) *::operator&;
-%rename(opAndAssign) *::operator&=;
-%rename(opOr) *::operator|;
-%rename(opOrAssign) *::operator|=;
-%rename(opXor) *::operator^;
-%rename(opXorAssign) *::operator^=;
-%rename(opShl) *::operator<<;
-%rename(opShlAssign) *::operator<<=;
-%rename(opShr) *::operator>>;
-%rename(opShrAssign) *::operator>>=;
-
-%rename(opIndex) *::operator[](unsigned) const;
-// opIndexAssign is not currently generated, it needs more extensive support
-// mechanisms.
-
-%rename(opCall) *::operator();
-
-// !a is not overrideable in D1.
-%ignoreoperator(LNOT) operator!;
-
-// opCmp is used in D.
-%rename(swigOpEquals) *::operator==;
-%rename(swigOpLt) *::operator<;
-%rename(swigOpLtEquals) *::operator<=;
-%rename(swigOpGt) *::operator>;
-%rename(swigOpGtEquals) *::operator>=;
-
-// a != b is rewritten as !a.opEquals(b) in D.
-%ignoreoperator(NOTEQUAL) operator!=;
-
-// The logic operators are not overrideable in D.
-%ignoreoperator(LAND) operator&&;
-%ignoreoperator(LOR) operator||;
-
-// ++/--a is rewritten as a +/-= 1 in D1,so ignore the prefix operators.
-%ignoreoperator(PLUSPLUS) *::operator++();
-%ignoreoperator(MINUSMINUS) *::operator--();
-%rename(swigOpInc) *::operator++(int);
-%rename(swigOpDec) *::operator--(int);
-
-// The C++ assignment operator does not translate well to D where the proxy
-// classes have reference semantics.
-%ignoreoperator(EQ) operator=;
-
-%pragma(d) imdmodulecode=%{
- public override int opCmp(Object o) {
- static if (is(typeof(swigOpLt(typeof(this).init) &&
- swigOpEquals(typeof(this).init)))) {
- if (auto rhs = cast(typeof(this))o) {
- if (swigOpLt(rhs)) {
- return -1;
- } else if (swigOpEquals(rhs)) {
- return 0;
- } else {
- return 1;
- }
- }
- }
- return super.opCmp(o);
- }
-
- public typeof(this) opPostInc(T = int)(T unused = 0) {
- static assert(
- is(typeof(swigOpInc(int.init))),
- "opPostInc called on " ~ typeof(this).stringof ~ ", but no postfix " ~
- "increment operator exists in the corresponding C++ class."
- );
- return swigOpInc(int.init);
- }
-
- public typeof(this) opPostDec(T = int)(T unused = 0) {
- static assert(
- is(typeof(swigOpDec(int.init))),
- "opPostInc called on " ~ typeof(this).stringof ~ ", but no postfix " ~
- "decrement operator exists in the corresponding C++ class."
- );
- return swigOpDec(int.init);
- }
-%}
-#endif
-
-%pragma(d) imdmodulecode=%{
-}
-%}
-
-#else
%pragma(d) imdmodulecode=%{
mixin template SwigOperatorDefinitions() {
public override bool opEquals(Object o) {
@@ -198,7 +75,7 @@ mixin template SwigOperatorDefinitions() {
// a != b is rewritten as !a.opEquals(b) in D.
%ignoreoperator(NOTEQUAL) operator!=;
-// The logic operators are not overrideable in D.
+// The logic operators are not overridable in D.
%ignoreoperator(LAND) operator&&;
%ignoreoperator(LOR) operator||;
@@ -255,5 +132,3 @@ mixin template SwigOperatorDefinitions() {
%pragma(d) imdmodulecode=%{
}
%}
-
-#endif
diff --git a/Lib/d/dprimitives.swg b/Lib/d/dprimitives.swg
index eaee816d3..843350fed 100644
--- a/Lib/d/dprimitives.swg
+++ b/Lib/d/dprimitives.swg
@@ -5,17 +5,10 @@
* ----------------------------------------------------------------------------- */
// C long/ulong width depends on the target arch, use stdlib aliases for them.
-#if (SWIG_D_VERSION == 1)
-%pragma(d) imdmoduleimports = "static import tango.stdc.config;"
-%pragma(d) globalproxyimports = "static import tango.stdc.config;"
-#define SWIG_LONG_DTYPE tango.stdc.config.c_long
-#define SWIG_ULONG_DTYPE tango.stdc.config.c_ulong
-#else
%pragma(d) imdmoduleimports = "static import core.stdc.config;"
%pragma(d) globalproxyimports = "static import core.stdc.config;"
#define SWIG_LONG_DTYPE core.stdc.config.c_long
#define SWIG_ULONG_DTYPE core.stdc.config.c_ulong
-#endif
/*
* The SWIG_D_PRIMITIVE macro is used to define the typemaps for the primitive
@@ -150,6 +143,12 @@ SWIG_D_PRIMITIVE(double, double)
const unsigned long &
""
+// Default assumes size_t is 32-bit for overloading
+%typecheck(SWIG_TYPECHECK_UINT32)
+ size_t,
+ const size_t &
+ ""
+
%typecheck(SWIG_TYPECHECK_INT64)
long long,
const long long &
diff --git a/Lib/d/dstrings.swg b/Lib/d/dstrings.swg
index 02895c153..0b875b58b 100644
--- a/Lib/d/dstrings.swg
+++ b/Lib/d/dstrings.swg
@@ -64,17 +64,10 @@
// We need to have the \0-terminated string conversion functions available in
// the D proxy modules.
-#if (SWIG_D_VERSION == 1)
-// Could be easily extended to support Phobos as well.
-SWIGD_STRING_TYPEMAPS(char*, char[], tango.stdc.stringz.fromStringz, tango.stdc.stringz.toStringz)
-
-%pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
-#else
SWIGD_STRING_TYPEMAPS(const(char)*, string, std.conv.to!string, std.string.toStringz)
%pragma(d) globalproxyimports = %{
static import std.conv;
static import std.string;
%}
-#endif
#undef SWIGD_STRING_TYPEMAPS
diff --git a/Lib/d/dswigtype.swg b/Lib/d/dswigtype.swg
index f0d604b6f..81a7d833d 100644
--- a/Lib/d/dswigtype.swg
+++ b/Lib/d/dswigtype.swg
@@ -20,6 +20,10 @@
%typemap(imtype) SWIGTYPE & "void*"
%typemap(dtype, nativepointer="$dtype") SWIGTYPE & "$dclassname"
+%typemap(ctype) SWIGTYPE && "void *"
+%typemap(imtype) SWIGTYPE && "void*"
+%typemap(dtype, nativepointer="$dtype") SWIGTYPE && "$dclassname"
+
%typemap(ctype) SWIGTYPE *const& "void *"
%typemap(imtype) SWIGTYPE *const& "void*"
%typemap(dtype) SWIGTYPE *const& "$*dclassname"
@@ -28,6 +32,7 @@
SWIGTYPE,
SWIGTYPE *,
SWIGTYPE &,
+ SWIGTYPE &&,
SWIGTYPE [],
SWIGTYPE *const&
""
@@ -47,7 +52,7 @@
%typemap(out) SWIGTYPE
#ifdef __cplusplus
-%{ $result = new $1_ltype((const $1_ltype &)$1); %}
+%{ $result = new $1_ltype($1); %}
#else
{
$&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
@@ -57,7 +62,7 @@
#endif
%typemap(directorin) SWIGTYPE
- "$input = (void *)new $1_ltype((const $1_ltype &)$1);"
+ "$input = (void *)new $1_ltype(SWIG_STD_MOVE($1));"
%typemap(directorout) SWIGTYPE
%{ if (!$input) {
SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type");
@@ -117,7 +122,7 @@
%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
if (!$1) {
- SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null");
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null");
return $null;
} %}
%typemap(out) SWIGTYPE & "$result = (void *)$1;"
@@ -149,6 +154,44 @@
/*
+ * Rvalue reference conversion typemaps.
+ */
+
+%typemap(in, canthrow=1, fragment="<memory>") SWIGTYPE && (std::unique_ptr<$*1_ltype> rvrdeleter) %{ $1 = ($1_ltype)$input;
+ if (!$1) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type is null");
+ return $null;
+ }
+ rvrdeleter.reset($1); %}
+%typemap(out) SWIGTYPE && "$result = (void *)$1;"
+
+%typemap(directorin) SWIGTYPE &&
+ "$input = ($1_ltype) &$1;"
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE &&
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type");
+ return $null;
+ }
+ $result = ($1_ltype)$input; %}
+
+%typemap(ddirectorin,
+ nativepointer="cast($dtype)$winput"
+) SWIGTYPE && "new $dclassname($winput, false)"
+%typemap(ddirectorout,
+ nativepointer="cast(void*)$dcall"
+) SWIGTYPE && "$dclassname.swigGetCPtr($dcall)"
+
+%typemap(din,
+ nativepointer="cast(void*)$dinput"
+) SWIGTYPE && "$dclassname.swigRelease($dinput)"
+%typemap(dout, excode=SWIGEXCODE,
+ nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}") SWIGTYPE && {
+ $dclassname ret = new $dclassname($imcall, $owner);$excode
+ return ret;
+}
+
+
+/*
* Array conversion typemaps.
*/
@@ -164,6 +207,7 @@
// Treat references to arrays like references to a single element.
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
+%apply SWIGTYPE && { SWIGTYPE ((&&)[ANY]) }
/*
@@ -195,3 +239,46 @@
nativepointer="cast(void*)$dcall"
) SWIGTYPE *const& "$*dclassname.swigGetCPtr($dcall)"
+/*
+ * D String & D array represent in C
+ */
+
+%insert(runtime) %{
+#include <stddef.h>
+typedef struct { size_t len; char *str;} SWIG_c_dstring;
+typedef struct { size_t len; SWIG_c_dstring *array; } SWIG_c_dstring_array;
+%}
+
+/*
+ * String & length
+ */
+%typemap(imtype) (const char *STRING, size_t LENGTH) "string"
+%typemap(dtype) (const char *STRING, size_t LENGTH) "string"
+%typemap(ctype,default="={0,0}") (const char *STRING, size_t LENGTH) "SWIG_c_dstring"
+%typemap(din, nativepointer="std.conv.to!string($dinput)") (const char *STRING, size_t LENGTH) "$dinput"
+%typemap(freearg) (const char *STRING, size_t LENGTH) ""
+%typemap(in, canthrow=1) (const char *STRING, size_t LENGTH) %{
+ $1 = ($1_ltype)$input.str;
+ $2 = ($2_ltype)$input.len;
+%}
+%typemap(argout) (const char *STRING, size_t LENGTH) {
+ $input.str = (char *)$1;
+ $input.len = (size_t)$2;
+}
+%typemap(directorin) (const char *STRING, size_t LENGTH) {
+ $input.str = (char *)$1;
+ $input.len = (size_t)$2;
+}
+%typemap(ddirectorin) (const char *STRING, size_t LENGTH) "std.conv.to!string($winput)"
+%apply (const char *STRING, size_t LENGTH) { (char *STRING, size_t LENGTH) }
+/* Enable write-back for non-const version */
+%typemap(argout) (char *STRING, size_t LENGTH) {
+ $input.str = (char *)$1;
+ $input.len = (size_t)$2;
+}
+%typemap(directorargout) (char *STRING, size_t LENGTH)
+{
+ $1 = ($1_ltype)$input.str;
+ $2 = ($2_ltype)$input.len;
+}
+%apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) }
diff --git a/Lib/d/std_auto_ptr.i b/Lib/d/std_auto_ptr.i
new file mode 100644
index 000000000..500b6115a
--- /dev/null
+++ b/Lib/d/std_auto_ptr.i
@@ -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 {};
+}
diff --git a/Lib/d/std_map.i b/Lib/d/std_map.i
index c5e03d06d..a374f55aa 100644
--- a/Lib/d/std_map.i
+++ b/Lib/d/std_map.i
@@ -44,7 +44,11 @@ namespace std {
throw std::out_of_range("key not found");
}
void set(const K& key, const T& x) {
+%#ifdef __cpp_lib_map_try_emplace
+ (*self).insert_or_assign(key, x);
+%#else
(*self)[key] = x;
+%#endif
}
void del(const K& key) throw (std::out_of_range) {
std::map< K, T, C >::iterator i = self->find(key);
diff --git a/Lib/d/std_string.i b/Lib/d/std_string.i
index 8d75d23e4..fbee0578c 100644
--- a/Lib/d/std_string.i
+++ b/Lib/d/std_string.i
@@ -79,19 +79,12 @@ class string;
// We need to have the \0-terminated string conversion functions available in
// the D proxy modules.
-#if (SWIG_D_VERSION == 1)
-// Could be easily extended to support Phobos as well.
-SWIGD_STD_STRING_TYPEMAPS(char*, char[], tango.stdc.stringz.fromStringz, tango.stdc.stringz.toStringz)
-
-%pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
-#else
SWIGD_STD_STRING_TYPEMAPS(const(char)*, string, std.conv.to!string, std.string.toStringz)
%pragma(d) globalproxyimports = %{
static import std.conv;
static import std.string;
%}
-#endif
#undef SWIGD_STD_STRING_TYPEMAPS
diff --git a/Lib/d/std_unique_ptr.i b/Lib/d/std_unique_ptr.i
new file mode 100644
index 000000000..9317a7e0e
--- /dev/null
+++ b/Lib/d/std_unique_ptr.i
@@ -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 {};
+}
diff --git a/Lib/d/std_vector.i b/Lib/d/std_vector.i
index fb8f7d2e0..8c67402e5 100644
--- a/Lib/d/std_vector.i
+++ b/Lib/d/std_vector.i
@@ -22,169 +22,6 @@
// MACRO for use within the std::vector class body
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CONST_REFERENCE, CTYPE...)
-#if (SWIG_D_VERSION == 1)
-%typemap(dimports) std::vector< CTYPE > "static import tango.core.Exception;"
-%proxycode %{
-public this($typemap(dtype, CTYPE)[] values) {
- this();
- append(values);
-}
-
-alias push_back add;
-alias push_back push;
-alias push_back opCatAssign;
-alias size length;
-alias opSlice slice;
-
-public $typemap(dtype, CTYPE) opIndexAssign($typemap(dtype, CTYPE) value, size_t index) {
- if (index >= size()) {
- throw new tango.core.Exception.NoSuchElementException("Tried to assign to element out of vector bounds.");
- }
- setElement(index, value);
- return value;
-}
-
-public $typemap(dtype, CTYPE) opIndex(size_t index) {
- if (index >= size()) {
- throw new tango.core.Exception.NoSuchElementException("Tried to read from element out of vector bounds.");
- }
- return getElement(index);
-}
-
-public void append($typemap(dtype, CTYPE)[] value...) {
- foreach (v; value) {
- add(v);
- }
-}
-
-public $typemap(dtype, CTYPE)[] opSlice() {
- $typemap(dtype, CTYPE)[] array = new $typemap(dtype, CTYPE)[size()];
- foreach (i, ref value; array) {
- value = getElement(i);
- }
- return array;
-}
-
-public int opApply(int delegate(ref $typemap(dtype, CTYPE) value) dg) {
- int result;
-
- size_t currentSize = size();
- for (size_t i = 0; i < currentSize; ++i) {
- auto value = getElement(i);
- result = dg(value);
- setElement(i, value);
- }
- return result;
-}
-
-public int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) {
- int result;
-
- size_t currentSize = size();
- for (size_t i = 0; i < currentSize; ++i) {
- auto value = getElement(i);
-
- // Workaround for http://d.puremagic.com/issues/show_bug.cgi?id=2443.
- auto index = i;
-
- result = dg(index, value);
- setElement(i, value);
- }
- return result;
-}
-
-public void capacity(size_t value) {
- if (value < size()) {
- throw new tango.core.Exception.IllegalArgumentException("Tried to make the capacity of a vector smaller than its size.");
- }
-
- reserve(value);
-}
-%}
-
- public:
- typedef size_t size_type;
- typedef ptrdiff_t difference_type;
- typedef CTYPE value_type;
- typedef value_type* pointer;
- typedef const value_type* const_pointer;
- typedef value_type& reference;
- typedef CONST_REFERENCE const_reference;
-
- void clear();
- void push_back(CTYPE const& x);
- size_type size() const;
- size_type capacity() const;
- void reserve(size_type n) throw (std::length_error);
-
- vector();
- vector(const vector &other);
-
- %extend {
- vector(size_type capacity) throw (std::length_error) {
- std::vector< CTYPE >* pv = 0;
- pv = new std::vector< CTYPE >();
-
- // Might throw std::length_error.
- pv->reserve(capacity);
-
- return pv;
- }
-
- size_type unused() const {
- return $self->capacity() - $self->size();
- }
-
- const_reference remove() throw (std::out_of_range) {
- if ($self->empty()) {
- throw std::out_of_range("Tried to remove last element from empty vector.");
- }
-
- std::vector< CTYPE >::const_reference value = $self->back();
- $self->pop_back();
- return value;
- }
-
- const_reference remove(size_type index) throw (std::out_of_range) {
- if (index >= $self->size()) {
- throw std::out_of_range("Tried to remove element with invalid index.");
- }
-
- std::vector< CTYPE >::iterator it = $self->begin() + index;
- std::vector< CTYPE >::const_reference value = *it;
- $self->erase(it);
- return value;
- }
- }
-
- // Wrappers for setting/getting items with the possibly thrown exception
- // specified (important for SWIG wrapper generation).
- %extend {
- const_reference getElement(size_type index) throw (std::out_of_range) {
- if ((index < 0) || ($self->size() <= index)) {
- throw std::out_of_range("Tried to get value of element with invalid index.");
- }
- return (*$self)[index];
- }
- }
-
- // Use CTYPE const& instead of const_reference to work around SWIG code
- // generation issue when using const pointers as vector elements (like
- // std::vector< const int* >).
- %extend {
- void setElement(size_type index, CTYPE const& val) throw (std::out_of_range) {
- if ((index < 0) || ($self->size() <= index)) {
- throw std::out_of_range("Tried to set value of element with invalid index.");
- }
- (*$self)[index] = val;
- }
- }
-
-%dmethodmodifiers std::vector::getElement "private"
-%dmethodmodifiers std::vector::setElement "private"
-%dmethodmodifiers std::vector::reserve "private"
-
-#else
%typemap(dimports) std::vector< CTYPE > %{
static import std.algorithm;
@@ -541,7 +378,6 @@ int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg)
%dmethodmodifiers std::vector::getElement "private"
%dmethodmodifiers std::vector::setElement "private"
-#endif
%enddef
// Extra methods added to the collection class if operator== is defined for the class being wrapped
diff --git a/Lib/d/swigmove.i b/Lib/d/swigmove.i
new file mode 100644
index 000000000..e2eb83406
--- /dev/null
+++ b/Lib/d/swigmove.i
@@ -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)"
diff --git a/Lib/d/wrapperloader.swg b/Lib/d/wrapperloader.swg
index b3c1d0dcf..f0f1d1b46 100644
--- a/Lib/d/wrapperloader.swg
+++ b/Lib/d/wrapperloader.swg
@@ -40,9 +40,10 @@ private {
} else {
version(D_Version2) {
static import std.conv;
+ } else {
+ static import std.c.string;
}
static import std.string;
- static import std.c.string;
}
version(D_Version2) {
@@ -112,7 +113,7 @@ private {
version(Tango) {
import tango.sys.Common;
} else version(linux) {
- import std.c.linux.linux;
+ import core.sys.posix.dlfcn;
} else {
extern(C) {
const RTLD_NOW = 2;
@@ -281,27 +282,19 @@ static this() {
"))library.loadSymbol(`" ~ symbol ~ "`);";
}
- //#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
mixin(bindCode("swigRegisterExceptionCallbacks$module", "SWIGRegisterExceptionCallbacks_$module"));
- //#endif // SWIG_D_NO_EXCEPTION_HELPER
- //#if !defined(SWIG_D_NO_STRING_HELPER)
mixin(bindCode("swigRegisterStringCallback$module", "SWIGRegisterStringCallback_$module"));
- //#endif // SWIG_D_NO_STRING_HELPER
$wrapperloaderbindcode
}
-//#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
extern(C) void function(
SwigExceptionCallback exceptionCallback,
SwigExceptionCallback illegalArgumentCallback,
SwigExceptionCallback illegalElementCallback,
SwigExceptionCallback ioCallback,
SwigExceptionCallback noSuchElementCallback) swigRegisterExceptionCallbacks$module;
-//#endif // SWIG_D_NO_EXCEPTION_HELPER
-//#if !defined(SWIG_D_NO_STRING_HELPER)
extern(C) void function(SwigStringCallback callback) swigRegisterStringCallback$module;
-//#endif // SWIG_D_NO_STRING_HELPER
%}
%pragma(d) wrapperloaderbindcommand = %{