From 98441fc6ad6d6097c98baf28b54c7059045806b6 Mon Sep 17 00:00:00 2001
From: Joseph Wang
Date: Sun, 17 Oct 2010 07:33:58 +0000
Subject: [PATCH 001/317] [R] Fix failure in overloaded functions which was
breaking QuantLib-SWIG
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12282 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 4 ++++
Source/Modules/r.cxx | 14 +++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/CHANGES.current b/CHANGES.current
index a5f149421..65489354c 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (in progress)
===========================
+2010-10-17: drjoe
+ [R] Fix failure in overloaded functions which was breaking
+ QuantLib-SWIG
+
2010-10-14: olly
[PHP] Allow compilation on non-conforming Microsoft C++ compilers
which don't accept: return function_returning_void();
diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx
index 749797c78..61cbcdd79 100644
--- a/Source/Modules/r.cxx
+++ b/Source/Modules/r.cxx
@@ -1603,6 +1603,16 @@ void R::dispatchFunction(Node *n) {
j == 0 ? "" : " && ",
j+1);
}
+ else if (DohStrcmp(tm,"integer")==0) {
+ Printf(f->code, "%s(is.integer(argv[[%d]]) || is.numeric(argv[[%d]]))",
+ j == 0 ? "" : " && ",
+ j+1, j+1);
+ }
+ else if (DohStrcmp(tm,"character")==0) {
+ Printf(f->code, "%sis.character(argv[[%d]])",
+ j == 0 ? "" : " && ",
+ j+1);
+ }
else {
Printf(f->code, "%sextends(argtypes[%d], '%s')",
j == 0 ? "" : " && ",
@@ -1617,7 +1627,9 @@ void R::dispatchFunction(Node *n) {
}
}
if (cur_args != -1) {
- Printv(f->code, "}", NIL);
+ Printf(f->code, "} else {\n"
+ "stop(\"cannot find overloaded function for %s\");\n"
+ "}", sfname);
}
Printv(f->code, ";\nf(...)", NIL);
Printv(f->code, ";\n}", NIL);
From f77ccd81d5c0b09ba0d99833e60945edf381f2f5 Mon Sep 17 00:00:00 2001
From: Joseph Wang
Date: Sun, 17 Oct 2010 09:35:34 +0000
Subject: [PATCH 002/317] [R] Improve error message for missing argtypes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12283 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/Modules/r.cxx | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Source/Modules/r.cxx b/Source/Modules/r.cxx
index 61cbcdd79..8eb784c68 100644
--- a/Source/Modules/r.cxx
+++ b/Source/Modules/r.cxx
@@ -1628,7 +1628,8 @@ void R::dispatchFunction(Node *n) {
}
if (cur_args != -1) {
Printf(f->code, "} else {\n"
- "stop(\"cannot find overloaded function for %s\");\n"
+ "stop(\"cannot find overloaded function for %s with argtypes (\","
+ "toString(argtypes),\")\");\n"
"}", sfname);
}
Printv(f->code, ";\nf(...)", NIL);
From 383230d734280c8cbd8ca159d30fe5677134883d Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Mon, 18 Oct 2010 18:59:57 +0000
Subject: [PATCH 003/317] minor clarification about %{ %} blocks
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12284 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Doc/Manual/Introduction.html | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/Doc/Manual/Introduction.html b/Doc/Manual/Introduction.html
index 3bac9484e..24579d946 100644
--- a/Doc/Manual/Introduction.html
+++ b/Doc/Manual/Introduction.html
@@ -195,9 +195,9 @@ extern int my_mod(int n, int m);
The interface file contains ANSI C function prototypes and variable
declarations. The %module directive defines the name of the
-module that will be created by SWIG. The %{,%} block
-provides a location for inserting additional code such as C header
-files or additional C declarations.
+module that will be created by SWIG. The %{ %} block
+provides a location for inserting additional code, such as C header
+files or additional C declarations, into the generated C wrapper code.
2.3.2 The swig command
From 28e277f8c59322fd1041bb3cc68c5ed779bff407 Mon Sep 17 00:00:00 2001
From: Olly Betts
Date: Tue, 19 Oct 2010 06:31:31 +0000
Subject: [PATCH 004/317] Fix typo "the the" -> "the"
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12285 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/octave/octcontainer.swg | 3 +--
Lib/python/pycontainer.swg | 3 +--
Lib/ruby/rubycontainer.swg | 3 +--
Source/Swig/cwrap.c | 2 +-
Source/Swig/stype.c | 2 +-
5 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/Lib/octave/octcontainer.swg b/Lib/octave/octcontainer.swg
index 6613fcfff..4f14ccef1 100644
--- a/Lib/octave/octcontainer.swg
+++ b/Lib/octave/octcontainer.swg
@@ -4,8 +4,7 @@
* Octave cell <-> C++ container wrapper
*
* This wrapper, and its iterator, allows a general use (and reuse) of
- * the the mapping between C++ and Octave, thanks to the C++
- * templates.
+ * the mapping between C++ and Octave, thanks to the C++ templates.
*
* Of course, it needs the C++ compiler to support templates, but
* since we will use this wrapper with the STL containers, that should
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index efca86cf1..40506e15b 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -4,8 +4,7 @@
* Python sequence <-> C++ container wrapper
*
* This wrapper, and its iterator, allows a general use (and reuse) of
- * the the mapping between C++ and Python, thanks to the C++
- * templates.
+ * the mapping between C++ and Python, thanks to the C++ templates.
*
* Of course, it needs the C++ compiler to support templates, but
* since we will use this wrapper with the STL containers, that should
diff --git a/Lib/ruby/rubycontainer.swg b/Lib/ruby/rubycontainer.swg
index fa4b619f9..f643e84b3 100644
--- a/Lib/ruby/rubycontainer.swg
+++ b/Lib/ruby/rubycontainer.swg
@@ -4,8 +4,7 @@
* Ruby sequence <-> C++ container wrapper
*
* This wrapper, and its iterator, allows a general use (and reuse) of
- * the the mapping between C++ and Ruby, thanks to the C++
- * templates.
+ * the mapping between C++ and Ruby, thanks to the C++ templates.
*
* Of course, it needs the C++ compiler to support templates, but
* since we will use this wrapper with the STL containers, that should
diff --git a/Source/Swig/cwrap.c b/Source/Swig/cwrap.c
index 799d434a6..28401f89f 100644
--- a/Source/Swig/cwrap.c
+++ b/Source/Swig/cwrap.c
@@ -216,7 +216,7 @@ int Swig_cargs(Wrapper *w, ParmList *p) {
SwigType_del_reference(tvalue);
tycode = SwigType_type(tvalue);
if (tycode != T_USER) {
- /* plain primitive type, we copy the the def value */
+ /* plain primitive type, we copy the def value */
String *lstr = SwigType_lstr(tvalue, defname);
defvalue = NewStringf("%s = %s", lstr, qvalue);
Delete(lstr);
diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c
index a13f87cfc..742b6232a 100644
--- a/Source/Swig/stype.c
+++ b/Source/Swig/stype.c
@@ -366,7 +366,7 @@ SwigType *SwigType_default_create(SwigType *ty) {
* SwigType_default_create() before calling this function.
*
* Example deductions (matching the examples described in SwigType_default_create),
- * where the the most specialized matches are highest in the list:
+ * where the most specialized matches are highest in the list:
*
* a(ANY).a(ANY).SWIGTYPE
* a(ANY).a().SWIGTYPE
From 43794d90cdcaa6a4c477ef331c37e3076951c800 Mon Sep 17 00:00:00 2001
From: Sylvestre Ledru
Date: Fri, 29 Oct 2010 10:22:03 +0000
Subject: [PATCH 005/317] Revert of commit 12269 see:
http://sourceforge.net/mailarchive/forum.php?thread_name=4CC08FAA.5050009%40fultondesigns.co.uk&forum_name=swig-devel
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12286 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 4 ----
configure.in | 14 --------------
2 files changed, 18 deletions(-)
diff --git a/CHANGES.current b/CHANGES.current
index 65489354c..ebfb2cb81 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -18,7 +18,3 @@ Version 2.0.2 (in progress)
Fix unary scope operator (::) (global scope) regression introduced in 2.0.0, reported by
Ben Walker. The mangled symbol names were incorrect, sometimes resulting in types being
incorrectly treated as opaque types.
-
-2010-10-14: Sylvestre Ledru
- Fails the configure if cannot find a yacc implementation
- (like bison)
diff --git a/configure.in b/configure.in
index 7f584e5d6..36337b41d 100644
--- a/configure.in
+++ b/configure.in
@@ -122,20 +122,6 @@ echo "Note : None of the following packages are required for users to compile an
echo ""
AC_PROG_YACC
-echo "YACC $YACC"
-if test -z "$YACC"; then
- AC_MSG_ERROR([No implementation of Yacc (bison, yacc) detected.])
-fi
-# Actually, AC_PROG_YACC is lying. It sometimes put yacc into $YACC even it
-# hasn't been able to find it.
-# AC_CHECK_PROG(YACC_PRESENT, $YACC, AC_MSG_ERROR([No implementation of Yacc (bison, yacc) detected. Please install it (package bison)]) )
-
-AC_CHECK_PROG(yacc_present, $YACC, "yes","no")
-if test "x$yacc_present" != "xyes"; then
- AC_MSG_ERROR([No implementation of Yacc (bison, yacc) detected. Please install it (package bison)])
-fi
-
-
AC_PROG_RANLIB
AC_CHECK_PROGS(AR, ar aal, ar)
AC_SUBST(AR)
From 77b87aa9196c226b8625218b8608b5696b335d06 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 11 Nov 2010 19:30:44 +0000
Subject: [PATCH 006/317] typo fix in help message
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12288 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/Modules/python.cxx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 80f2e68df..6d5f500a4 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -130,7 +130,7 @@ static const char *usage2 = (char *) "\
-nofastproxy - Use traditional proxy mechanism for member methods (default) \n\
-nofastquery - Use traditional query mechanism for types (default) \n\
-noh - Don't generate the output header file\n\
- -nomodern - Don't use modern python features which are not back compatible \n\
+ -nomodern - Don't use modern python features which are not backwards compatible \n\
-nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n";
static const char *usage3 = (char *) "\
-noolddefs - Don't emit the old method definitions even when using fastproxy (default) \n\
From 580f2549582602399553fded9e12bca6f9746143 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor
Date: Fri, 12 Nov 2010 16:43:03 +0000
Subject: [PATCH 007/317] Update for recent runtime name changes (a better
mechanism is clearly needed here).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12290 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/go/cdata.i | 4 ++--
Lib/go/goruntime.swg | 12 ++++++------
Source/Modules/go.cxx | 6 +++---
3 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/Lib/go/cdata.i b/Lib/go/cdata.i
index decf297c1..6cfdffea1 100644
--- a/Lib/go/cdata.i
+++ b/Lib/go/cdata.i
@@ -59,8 +59,8 @@ void _swig_gc_makegobyteslice(void *a, int32 n) {
cgocallback(·_swig_internal_makegobyteslice, a, n);
}
void ·_swig_allocategobyteslice(byte *data, int32 len, swigcdata ret) {
- ret.data = mal(len);
- mcpy(ret.data, data, len);
+ ret.data = runtime·mal(len);
+ runtime·mcpy(ret.data, data, len);
ret.len = len;
FLUSH(&ret);
}
diff --git a/Lib/go/goruntime.swg b/Lib/go/goruntime.swg
index 057f81d01..6cde68f55 100644
--- a/Lib/go/goruntime.swg
+++ b/Lib/go/goruntime.swg
@@ -109,23 +109,23 @@ static void _swig_gopanic(const char *p) {
extern void ·_swig_internal_allocate(void);
#pragma dynexport _swig_gc_allocate _swig_gc_allocate
void _swig_gc_allocate(void *a, int32 n) {
- cgocallback(·_swig_internal_allocate, a, n);
+ runtime·cgocallback(·_swig_internal_allocate, a, n);
}
void ·_swig_allocatememory(int32 len, byte *ret) {
- ret = mal(len);
+ ret = runtime·mal(len);
FLUSH(&ret);
}
extern void ·_swig_internal_makegostring(void);
#pragma dynexport _swig_gc_makegostring _swig_gc_makegostring
void _swig_gc_makegostring(void *a, int32 n) {
- cgocallback(·_swig_internal_makegostring, a, n);
+ runtime·cgocallback(·_swig_internal_makegostring, a, n);
}
void ·_swig_allocatestring(byte *p, int32 l, String ret) {
- ret.str = mal(l+1);
- mcpy(ret.str, p, l);
+ ret.str = runtime·mal(l+1);
+ runtime·mcpy(ret.str, p, l);
ret.len = l;
FLUSH(&ret);
}
@@ -133,7 +133,7 @@ void ·_swig_allocatestring(byte *p, int32 l, String ret) {
extern void ·_swig_internal_gopanic(void);
#pragma dynexport _swig_gc_gopanic _swig_gc_gopanic
void _swig_gc_gopanic(void *a, int32 n) {
- cgocallback(·_swig_internal_gopanic, a, n);
+ runtime·cgocallback(·_swig_internal_gopanic, a, n);
}
%}
diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx
index 4b1d05b92..d3de53f8f 100644
--- a/Source/Modules/go.cxx
+++ b/Source/Modules/go.cxx
@@ -1068,7 +1068,7 @@ private:
Delete(parm_size);
Printv(f->code, "{\n", NULL);
- Printv(f->code, "\tcgocall(", wname, ", &p);\n", NULL);
+ Printv(f->code, "\truntime\xc2\xb7" "cgocall(", wname, ", &p);\n", NULL);
Printv(f->code, "}\n", NULL);
Printv(f->code, "\n", NULL);
@@ -2749,7 +2749,7 @@ private:
Printv(f_gc_wrappers, "void\n", NULL);
Printv(f_gc_wrappers, wname, "(void *a, int32 n)\n", NULL);
Printv(f_gc_wrappers, "{\n", NULL);
- Printv(f_gc_wrappers, "\tcgocallback(\xc2\xb7", go_name, ", a, n);\n", NULL);
+ Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", go_name, ", a, n);\n", NULL);
Printv(f_gc_wrappers, "}\n\n", NULL);
} else {
Printv(f_c_directors, " ", wname, "(go_val);\n", NULL);
@@ -3475,7 +3475,7 @@ private:
Printv(f_gc_wrappers, "void\n", NULL);
Printv(f_gc_wrappers, callback_wname, "(void *a, int32 n)\n", NULL);
Printv(f_gc_wrappers, "{\n", NULL);
- Printv(f_gc_wrappers, "\tcgocallback(\xc2\xb7", callback_name, ", a, n);\n", NULL);
+ Printv(f_gc_wrappers, "\truntime\xc2\xb7" "cgocallback(\xc2\xb7", callback_name, ", a, n);\n", NULL);
Printv(f_gc_wrappers, "}\n\n", NULL);
} else {
if (SwigType_type(result) != T_VOID) {
From e30befd13806fb89c1591c56a7a66a5c24d1a14e Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin
Date: Tue, 16 Nov 2010 14:08:50 +0000
Subject: [PATCH 008/317] Correct explanation of how to match on class name in
%rename.
Replace incorrect documentation of $parentNode from %rename discussion: it
advised using match$parentNode but this doesn't work because the parent node
is not yet set when %rename is parsed.
Document the "fullname" attribute of %rename which can be used to restrict the
match to the given full name of a declaration only.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12291 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Doc/Manual/SWIG.html | 24 ++++++++----------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html
index e51e55986..b8e3e2260 100644
--- a/Doc/Manual/SWIG.html
+++ b/Doc/Manual/SWIG.html
@@ -2002,22 +2002,6 @@ documentation is not exhaustive, see "%rename predicates" section of
swig.swg for the full list of supported match expressions.
-
-Another important feature of match is that it can be applied not
-only to the declaration itself but also to its enclosing declaration. So
-match$parentNode$name="SomeClass" would be true only for members of
-the C++ class with the specified name. This can, of course, be combined with
-more complicated matches making it possible to write
-
-
-
-%rename("%(lowercase)s", match$parentNode$name="SomeClass", %$isenum) "";
-
-
-
-to rename all enums nested in the given class to lower case.
-
-
In addition to literally matching some string with match you can
also use regexmatch or notregexmatch to match a string
@@ -2039,6 +2023,14 @@ declaration name directly can be preferable and can also be done using
%rename("$ignore", regextarget=1) "Old$";
+Notice that the check is done only against the name of the declaration
+itself, if you need to match the full name of a C++ declaration you
+must use fullname attribute:
+
+
+%rename("$ignore", regextarget=1, fullname=1) "NameSpace::ClassName::.*Old$";
+
+
As for notregexmatch , it restricts the match only to the strings not
From 953c4abacaad7c8cab4eb5c5f87e5164c7e414c8 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin
Date: Tue, 16 Nov 2010 14:09:09 +0000
Subject: [PATCH 009/317] Use rename list and not hash for renames with
regextarget attribute.
Renames which are regular expressions can't be put in the regex hash as they
don't literally match the real declarations names. Instead, put them in the
rename list against which we will match the declarations names later.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12292 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/Swig/naming.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c
index 5bf42f7cc..70744586c 100644
--- a/Source/Swig/naming.c
+++ b/Source/Swig/naming.c
@@ -1110,7 +1110,7 @@ void Swig_name_nameobj_add(Hash *name_hash, List *name_list, String *prefix, Str
}
if (!nname || !Len(nname) || Getattr(nameobj, "fullname") || /* any of these options trigger a 'list' nameobj */
- Getattr(nameobj, "sourcefmt") || Getattr(nameobj, "matchlist")) {
+ Getattr(nameobj, "sourcefmt") || Getattr(nameobj, "matchlist") || Getattr(nameobj, "regextarget")) {
if (decl)
Setattr(nameobj, "decl", decl);
if (nname && Len(nname))
From f6cab0170abdb69b1ac562b223d101bf55e5700f Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin
Date: Tue, 16 Nov 2010 14:09:39 +0000
Subject: [PATCH 010/317] Ignore non-matching regex renames when searching
renames list.
Skip over %renames with non-matching %(regex)s expansion when looking for the
one to apply to the given name. This allows to have multiple anonymous renames
using regex as now the first _matching_ one will be used instead of always
using the first one and ignoring all the rest of them.
Extend unit tests to verify that applying two anonymous %renames does work as
expected.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12293 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 10 ++++++++++
.../test-suite/csharp/rename_pcre_encoder_runme.cs | 12 ++++++++++++
.../test-suite/java/rename_pcre_encoder_runme.java | 14 ++++++++++++++
.../test-suite/python/rename_pcre_encoder_runme.py | 3 +++
Examples/test-suite/rename_pcre_encoder.i | 9 +++++++--
Source/Swig/naming.c | 8 +++++++-
6 files changed, 53 insertions(+), 3 deletions(-)
create mode 100644 Examples/test-suite/csharp/rename_pcre_encoder_runme.cs
create mode 100644 Examples/test-suite/java/rename_pcre_encoder_runme.java
diff --git a/CHANGES.current b/CHANGES.current
index ebfb2cb81..f18011e1a 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,16 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (in progress)
===========================
+2010-11-12: vadz
+ Fix handling of multiple regex-using %renames attached to the same
+ declaration. For example, now
+
+ %rename("%(regex/^Set(.*)/put\\1/)s") "";
+ %rename("%(regex/^Get(.*)/get\\1/)s") "";
+
+ works as expected whereas before only the last anonymous rename was
+ taken into account.
+
2010-10-17: drjoe
[R] Fix failure in overloaded functions which was breaking
QuantLib-SWIG
diff --git a/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs b/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs
new file mode 100644
index 000000000..f6289e7e2
--- /dev/null
+++ b/Examples/test-suite/csharp/rename_pcre_encoder_runme.cs
@@ -0,0 +1,12 @@
+using System;
+using rename_pcre_encoderNamespace;
+
+public class runme {
+ static void Main() {
+ SomeWidget w = new SomeWidget();
+ w.putBorderWidth(17);
+ if ( w.getBorderWidth() != 17 )
+ throw new Exception(String.Format("Border with should be 17, not {0}",
+ w.getBorderWidth()));
+ }
+}
diff --git a/Examples/test-suite/java/rename_pcre_encoder_runme.java b/Examples/test-suite/java/rename_pcre_encoder_runme.java
new file mode 100644
index 000000000..cb843338b
--- /dev/null
+++ b/Examples/test-suite/java/rename_pcre_encoder_runme.java
@@ -0,0 +1,14 @@
+import rename_pcre_encoder.*;
+
+public class rename_pcre_encoder_runme {
+ static { System.loadLibrary("rename_pcre_encoder"); }
+
+ public static void main(String argv[])
+ {
+ SomeWidget w = new SomeWidget();
+ w.putBorderWidth(17);
+ if ( w.getBorderWidth() != 17 )
+ throw new RuntimeException(String.format("Border with should be 17, not %d",
+ w.getBorderWidth()));
+ }
+}
diff --git a/Examples/test-suite/python/rename_pcre_encoder_runme.py b/Examples/test-suite/python/rename_pcre_encoder_runme.py
index ed7ca48b1..1186703a0 100644
--- a/Examples/test-suite/python/rename_pcre_encoder_runme.py
+++ b/Examples/test-suite/python/rename_pcre_encoder_runme.py
@@ -2,6 +2,9 @@ from rename_pcre_encoder import *
s = SomeWidget()
s.putBorderWidth(3)
+if s.getBorderWidth() != 3:
+ raise RuntimeError("Border should be 3, not %d" % (s.getBorderWidth(),))
+
s.putSize(4, 5)
a = AnotherWidget()
a.DoSomething()
diff --git a/Examples/test-suite/rename_pcre_encoder.i b/Examples/test-suite/rename_pcre_encoder.i
index c90af164d..66f30c7bc 100644
--- a/Examples/test-suite/rename_pcre_encoder.i
+++ b/Examples/test-suite/rename_pcre_encoder.i
@@ -3,14 +3,19 @@
// strip the wx prefix from all identifiers except those starting with wxEVT
%rename("%(regex:/wx(?!EVT)(.*)/\\1/)s") "";
-// Replace "Set" prefix with "put" in all functions
+// Replace "Set" and "Get" prefixes with "put" and "get" respectively.
%rename("%(regex:/^Set(.*)/put\\1/)s", %$isfunction) "";
+%rename("%(regex:/^Get(.*)/get\\1/)s", %$isfunction) "";
%inline %{
struct wxSomeWidget {
- void SetBorderWidth(int) {}
+ void SetBorderWidth(int width) { m_width = width; }
+ int GetBorderWidth() const { return m_width; }
+
void SetSize(int, int) {}
+
+ int m_width;
};
struct wxAnotherWidget {
diff --git a/Source/Swig/naming.c b/Source/Swig/naming.c
index 70744586c..6beecc130 100644
--- a/Source/Swig/naming.c
+++ b/Source/Swig/naming.c
@@ -1302,7 +1302,13 @@ Hash *Swig_name_nameobj_lget(List *namelist, Node *n, String *prefix, String *na
: Swig_name_match_value(tname, sname);
Delete(sname);
} else {
- match = 1;
+ /* Applying the renaming rule may fail if it contains a %(regex)s expression that doesn't match the given name. */
+ String *sname = NewStringf(Getattr(rn, "name"), name);
+ if (sname) {
+ if (Len(sname))
+ match = 1;
+ Delete(sname);
+ }
}
}
if (match) {
From ee1c2f3ef086080a54cf5aec99f8b46e3f4d910d Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 18 Nov 2010 00:15:13 +0000
Subject: [PATCH 011/317] Renamed 'immutable' test-case to 'immutable_values'.
This is a part of the pending merge of the D module, where 'immutable' is a keyword (and thus not a valid module name).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12294 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/test-suite/common.mk | 2 +-
Examples/test-suite/{immutable.i => immutable_values.i} | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
rename Examples/test-suite/{immutable.i => immutable_values.i} (90%)
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 026612db5..05d2f80c8 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -466,7 +466,7 @@ C_TEST_CASES += \
extern_declaration \
funcptr \
function_typedef \
- immutable \
+ immutable_values \
inctest \
integers \
keyword_rename \
diff --git a/Examples/test-suite/immutable.i b/Examples/test-suite/immutable_values.i
similarity index 90%
rename from Examples/test-suite/immutable.i
rename to Examples/test-suite/immutable_values.i
index ff5081e9c..1c1978661 100644
--- a/Examples/test-suite/immutable.i
+++ b/Examples/test-suite/immutable_values.i
@@ -1,6 +1,6 @@
// test to make sure setters are not generated for constants
-%module immutable
+%module immutable_values
%immutable;
From 0fb77ce2068128e02217cdddd6a388e6c6d30d9f Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 18 Nov 2010 00:15:41 +0000
Subject: [PATCH 012/317] Renamed 'template' test-case to 'template_basic'.
This is a part of the pending merge of the D module, where 'template' is a keyword (and thus not a valid module name).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12295 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/test-suite/common.mk | 2 +-
Examples/test-suite/{template.i => template_basic.i} | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
rename Examples/test-suite/{template.i => template_basic.i} (89%)
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 05d2f80c8..f0fe4af1c 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -318,11 +318,11 @@ CPP_TEST_CASES += \
struct_initialization_cpp \
struct_value \
symbol_clash \
- template \
template_arg_replace \
template_arg_scope \
template_arg_typename \
template_array_numeric \
+ template_basic \
template_base_template \
template_classes \
template_const_ref \
diff --git a/Examples/test-suite/template.i b/Examples/test-suite/template_basic.i
similarity index 89%
rename from Examples/test-suite/template.i
rename to Examples/test-suite/template_basic.i
index d2c7a91ed..570392bf6 100644
--- a/Examples/test-suite/template.i
+++ b/Examples/test-suite/template_basic.i
@@ -1,5 +1,5 @@
-/* File : example.i */
-%module "template"
+/* File: template_basic.i */
+%module "template_basic"
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector; /* Ruby, wrong class name */
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) vector; /* Ruby, wrong class name */
@@ -31,7 +31,7 @@ template class vector {
void set(int index, T &val) {
v[index] = val;
}
- // This really doesn't do anything except test const handling
+ // This really doesn't do anything except test const handling
void testconst(const T x) { }
};
From 4d09774cefd745dc6a0e38db0a3ab320d79c992c Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 18 Nov 2010 00:16:02 +0000
Subject: [PATCH 013/317] Minor rename in the 'smart_pointer_templatemethods'
test-case to avoid special casing for D.
This is a part of the pending merge of the D module, where 'Object' is a keyword.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12296 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/test-suite/smart_pointer_templatemethods.i | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/Examples/test-suite/smart_pointer_templatemethods.i b/Examples/test-suite/smart_pointer_templatemethods.i
index 7baa6386a..f79bbcc9d 100644
--- a/Examples/test-suite/smart_pointer_templatemethods.i
+++ b/Examples/test-suite/smart_pointer_templatemethods.i
@@ -1,4 +1,3 @@
-
%module smart_pointer_templatemethods
%inline %{
@@ -29,21 +28,21 @@ public:
void DisposeObjekt (void) {}
};
-class Object
+class Objct
{
public:
- Object () {}
- virtual ~Object () {}
+ Objct () {}
+ virtual ~Objct () {}
template Ptr QueryInterface (InterfaceId iid) const { return Ptr(); }
- void DisposeObject (void) {}
+ void DisposeObjct (void) {}
};
#ifdef SWIG
-%template(PtrObject) Ptr;
+%template(PtrObjct) Ptr;
%template(PtrInt) Ptr;
%template(ObjektInt) Objekt;
%template(PtrObjektInt) Ptr >;
-%template(QueryInterfaceObject) Object::QueryInterface;
+%template(QueryInterfaceObjct) Objct::QueryInterface;
#endif
}; // namespace
From 2070812f09468e17b6a1e027dcaa6b5ae3774570 Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 18 Nov 2010 00:16:23 +0000
Subject: [PATCH 014/317] Minor rename in the 'operbool' test-case to avoid
special casing for D.
This is a part of the pending merge of the D module, where a method having the same name as the module would lead to ambiguities.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12297 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/test-suite/operbool.i | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Examples/test-suite/operbool.i b/Examples/test-suite/operbool.i
index 793c0174e..ee8c889e9 100644
--- a/Examples/test-suite/operbool.i
+++ b/Examples/test-suite/operbool.i
@@ -1,6 +1,6 @@
%module operbool
-%rename(operbool) operator bool();
+%rename(operator_bool) operator bool();
%inline %{
class Test {
From a355d2d46af56c655816c37f24bb59fa6bade43f Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 18 Nov 2010 00:17:37 +0000
Subject: [PATCH 015/317] Added special cases to the test-suite as required for
D.
This is a part of the pending merge of the D module.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12298 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/test-suite/abstract_virtual.i | 6 ++--
Examples/test-suite/contract.i | 7 ++++-
Examples/test-suite/default_constructor.i | 6 ++--
Examples/test-suite/dynamic_cast.i | 13 +++++++--
Examples/test-suite/enums.i | 5 ++++
Examples/test-suite/evil_diamond.i | 3 +-
Examples/test-suite/evil_diamond_ns.i | 3 +-
Examples/test-suite/evil_diamond_prop.i | 1 +
Examples/test-suite/import_nomodule.i | 8 ++---
Examples/test-suite/inherit_target_language.i | 8 ++++-
Examples/test-suite/li_boost_shared_ptr.i | 2 +-
.../test-suite/li_boost_shared_ptr_bits.i | 2 +-
Examples/test-suite/li_std_combinations.i | 2 +-
Examples/test-suite/minherit2.i | 29 +++++++++++++++++--
Examples/test-suite/multiple_inheritance.i | 6 ++--
Examples/test-suite/namespace_class.i | 4 +++
Examples/test-suite/preproc_line_file.i | 4 +--
Examples/test-suite/pure_virtual.i | 5 ++--
Examples/test-suite/samename.i | 2 +-
Examples/test-suite/special_variable_macros.i | 14 +++++++++
Examples/test-suite/static_const_member.i | 3 ++
Examples/test-suite/template_enum.i | 4 +++
.../test-suite/template_inherit_abstract.i | 5 ++--
Examples/test-suite/typemap_namespace.i | 9 +++++-
Examples/test-suite/typemap_out_optimal.i | 6 +++-
Examples/test-suite/typemap_subst.i | 4 +--
Examples/test-suite/using_composition.i | 9 ++++--
Examples/test-suite/using_extend.i | 3 +-
Examples/test-suite/using_namespace.i | 3 +-
29 files changed, 137 insertions(+), 39 deletions(-)
diff --git a/Examples/test-suite/abstract_virtual.i b/Examples/test-suite/abstract_virtual.i
index 2e4d105b1..d8372c936 100644
--- a/Examples/test-suite/abstract_virtual.i
+++ b/Examples/test-suite/abstract_virtual.i
@@ -2,10 +2,12 @@
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) D; /* C#, Java, PHP multiple inheritance */
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) D; /* C#, D, Java, PHP multiple inheritance */
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, Java, PHP multiple inheritance */
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, D, Java, PHP multiple inheritance */
%inline %{
#if defined(_MSC_VER)
diff --git a/Examples/test-suite/contract.i b/Examples/test-suite/contract.i
index b979ef19e..0ad7e8e7c 100644
--- a/Examples/test-suite/contract.i
+++ b/Examples/test-suite/contract.i
@@ -3,12 +3,17 @@
%warnfilter(SWIGWARN_RUBY_MULTIPLE_INHERITANCE,
SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) C; /* Ruby, C#, Java, PHP multiple inheritance */
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) C; /* Ruby, C#, D, Java, PHP multiple inheritance */
#ifdef SWIGCSHARP
%ignore B::bar; // otherwise get a warning: `C.bar' no suitable methods found to override
#endif
+#ifdef SWIGD
+%ignore B::bar; // Prevents getting an error that C.bar does not override any function because multiple inheritance is not supported.
+#endif
+
%contract test_preassert(int a, int b) {
require:
a > 0;
diff --git a/Examples/test-suite/default_constructor.i b/Examples/test-suite/default_constructor.i
index ff22c7834..091adff20 100644
--- a/Examples/test-suite/default_constructor.i
+++ b/Examples/test-suite/default_constructor.i
@@ -5,11 +5,13 @@
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) EB; /* C#, Java, PHP multiple inheritance */
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) EB; /* C#, D, Java, PHP multiple inheritance */
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) AD; /* C#, Java, PHP multiple inheritance */
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) AD; /* C#, D, Java, PHP multiple inheritance */
%warnfilter(SWIGWARN_LANG_FRIEND_IGNORE) F; /* friend function */
diff --git a/Examples/test-suite/dynamic_cast.i b/Examples/test-suite/dynamic_cast.i
index ccbaa5b47..17850985a 100644
--- a/Examples/test-suite/dynamic_cast.i
+++ b/Examples/test-suite/dynamic_cast.i
@@ -1,7 +1,7 @@
/* File : example.i */
%module dynamic_cast
-#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO)
+#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD)
%apply SWIGTYPE *DYNAMIC { Foo * };
#endif
@@ -17,7 +17,7 @@ public:
};
%}
-#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGO) || defined(SWIGD)
%typemap(out) Foo *blah {
Bar *downcast = dynamic_cast($1);
*(Bar **)&$result = downcast;
@@ -37,6 +37,13 @@ public:
}
#endif
+#if defined(SWIGD)
+%typemap(dout, excode=SWIGEXCODE) Foo * {
+ Bar ret = new Bar($wcall, $owner);$excode
+ return ret;
+}
+#endif
+
#if defined(SWIGGO)
%insert(go_runtime) %{
func FooToBar(f Foo) Bar {
@@ -62,7 +69,7 @@ char *do_test(Bar *b) {
}
%}
-#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO)
+#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD)
// A general purpose function for dynamic casting of a Foo *
%{
static swig_type_info *
diff --git a/Examples/test-suite/enums.i b/Examples/test-suite/enums.i
index 5632b5e97..14c6efbba 100644
--- a/Examples/test-suite/enums.i
+++ b/Examples/test-suite/enums.i
@@ -58,6 +58,11 @@ typedef struct _Foo {
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) _iFoo;
+#ifdef SWIGD
+/* Work around missing support for proper char quoting due to parser shortcomings. */
+%dconstvalue("'a'") _iFoo::Char;
+#endif
+
#ifndef __cplusplus
%inline %{
typedef struct _iFoo
diff --git a/Examples/test-suite/evil_diamond.i b/Examples/test-suite/evil_diamond.i
index 7b2e9152f..a8d48b30b 100644
--- a/Examples/test-suite/evil_diamond.i
+++ b/Examples/test-suite/evil_diamond.i
@@ -6,7 +6,8 @@
%warnfilter(SWIGWARN_RUBY_WRONG_NAME,
SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) spam; // Ruby, wrong class name - C# & Java, PHP multiple inheritance
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) spam; // Ruby, wrong class name - C#, D & Java, PHP multiple inheritance
%inline %{
diff --git a/Examples/test-suite/evil_diamond_ns.i b/Examples/test-suite/evil_diamond_ns.i
index 515044007..0227b31ee 100644
--- a/Examples/test-suite/evil_diamond_ns.i
+++ b/Examples/test-suite/evil_diamond_ns.i
@@ -6,7 +6,8 @@
%warnfilter(SWIGWARN_RUBY_WRONG_NAME,
SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) Blah::spam; // Ruby, wrong class name - C# & Java, PHP multiple inheritance
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) Blah::spam; // Ruby, wrong class name - C#, D & Java, PHP multiple inheritance
%inline %{
namespace Blah {
diff --git a/Examples/test-suite/evil_diamond_prop.i b/Examples/test-suite/evil_diamond_prop.i
index 804ea66b4..2dac6eab7 100644
--- a/Examples/test-suite/evil_diamond_prop.i
+++ b/Examples/test-suite/evil_diamond_prop.i
@@ -6,6 +6,7 @@
%warnfilter(SWIGWARN_RUBY_WRONG_NAME,
SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE) spam; // Ruby, wrong class name - C# & Java, PHP multiple inheritance
%inline %{
diff --git a/Examples/test-suite/import_nomodule.i b/Examples/test-suite/import_nomodule.i
index a1ba9ad7a..4fd5cbf65 100644
--- a/Examples/test-suite/import_nomodule.i
+++ b/Examples/test-suite/import_nomodule.i
@@ -8,16 +8,16 @@
%import "import_nomodule.h"
-#if !defined(SWIGJAVA) && !defined(SWIGRUBY) && !defined(SWIGCSHARP)
+#if !defined(SWIGJAVA) && !defined(SWIGRUBY) && !defined(SWIGCSHARP) && !defined(SWIGD)
/**
* The proxy class does not have Bar derived from Foo, yet an instance of Bar
* can successfully be passed to a proxy function taking a Foo pointer (for some
* language modules).
*
- * This violation of the type system is not possible in Java and C# due to static
- * type checking. It's also not (currently) possible in Ruby, but this may be
- * fixable (needs more investigation).
+ * This violation of the type system is not possible in Java, C# and D due to
+ * static type checking. It's also not (currently) possible in Ruby, but this may
+ * be fixable (needs more investigation).
*/
%newobject create_Foo;
diff --git a/Examples/test-suite/inherit_target_language.i b/Examples/test-suite/inherit_target_language.i
index 20fb93fda..88801f3f6 100644
--- a/Examples/test-suite/inherit_target_language.i
+++ b/Examples/test-suite/inherit_target_language.i
@@ -1,4 +1,4 @@
-// Test using a target language specified base class, primarily for Java/C# and possibly other single inheritance languages
+// Test using a target language specified base class, primarily for Java/C#/D and possibly other single inheritance languages
// Note the multiple inheritance warnings don't appear because of the two techniques used in here: typemaps and %ignore
@@ -6,6 +6,8 @@
#if defined(SWIGJAVA)
# define csbase javabase
+#elif defined(SWIGD)
+# define csbase dbase
#endif
%pragma(csharp) moduleimports=%{
@@ -20,6 +22,10 @@ class TargetLanguageBase { public void targetLanguageBaseMethod() {} };
class TargetLanguageBase2 { public void targetLanguageBase2Method() {} };
%}
+%pragma(d) globalproxyimports=%{
+private class TargetLanguageBase { public void targetLanguageBaseMethod() {} };
+private class TargetLanguageBase2 { public void targetLanguageBase2Method() {} };
+%}
%typemap(csbase) SWIGTYPE "TargetLanguageBase"
diff --git a/Examples/test-suite/li_boost_shared_ptr.i b/Examples/test-suite/li_boost_shared_ptr.i
index f92df23a9..fc51e7b5a 100644
--- a/Examples/test-suite/li_boost_shared_ptr.i
+++ b/Examples/test-suite/li_boost_shared_ptr.i
@@ -34,7 +34,7 @@
# define SWIG_SHARED_PTR_NAMESPACE SwigBoost
#endif
-#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif
diff --git a/Examples/test-suite/li_boost_shared_ptr_bits.i b/Examples/test-suite/li_boost_shared_ptr_bits.i
index 610edb4b4..2232b6cf6 100644
--- a/Examples/test-suite/li_boost_shared_ptr_bits.i
+++ b/Examples/test-suite/li_boost_shared_ptr_bits.i
@@ -1,6 +1,6 @@
%module li_boost_shared_ptr_bits
-#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGPYTHON) || defined(SWIGD)
#define SHARED_PTR_WRAPPERS_IMPLEMENTED
#endif
diff --git a/Examples/test-suite/li_std_combinations.i b/Examples/test-suite/li_std_combinations.i
index 9acc8f23d..57f945bcd 100644
--- a/Examples/test-suite/li_std_combinations.i
+++ b/Examples/test-suite/li_std_combinations.i
@@ -14,7 +14,7 @@
%template(VectorVectorString) std::vector< std::vector >;
%template(PairIntPairIntString) std::pair< int, std::pair >;
-#if defined(SWIGCSHARP)
+#if defined(SWIGCSHARP) || defined(SWIGD)
// Checks macro containing a type with a comma
SWIG_STD_VECTOR_ENHANCED(std::pair< double, std::string >)
#endif
diff --git a/Examples/test-suite/minherit2.i b/Examples/test-suite/minherit2.i
index 1bca4fc48..7d470d30e 100644
--- a/Examples/test-suite/minherit2.i
+++ b/Examples/test-suite/minherit2.i
@@ -1,16 +1,18 @@
%module minherit2
-// A multiple inheritance example, mainly for Java and C#.
-// The example shows how it is possible to turn C++ abstract base classes into Java/C# interface.
+// A multiple inheritance example, mainly for Java, C# and D.
+// The example shows how it is possible to turn C++ abstract base classes into
+// Java/C#/D interfaces.
// In the future, all this trouble might be more automated.
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
SWIGWARN_RUBY_MULTIPLE_INHERITANCE,
SWIGWARN_PHP_MULTIPLE_INHERITANCE) RemoteMpe;
-#if defined(SWIGJAVA) || defined(SWIGCSHARP)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
#if defined(SWIGCSHARP)
#define javaclassmodifiers csclassmodifiers
@@ -22,6 +24,21 @@
#define javabase csbase
#endif
+#if defined(SWIGD)
+#define javaclassmodifiers dclassmodifiers
+#define javabody dbody
+#define javafinalize ddestructor
+#define javadestruct ddispose
+#define javaout dout
+#define javainterfaces dinterfaces
+#define javabase dbase
+
+%typemap(dimports) RemoteMpe %{
+$importtype(IRemoteSyncIO)
+$importtype(IRemoteAsyncIO)
+%}
+#endif
+
// Modify multiple inherited base classes into inheriting interfaces
%typemap(javainterfaces) RemoteMpe "IRemoteSyncIO, IRemoteAsyncIO";
%typemap(javabase, replace="1") RemoteMpe "";
@@ -51,6 +68,12 @@
// Features are inherited by derived classes, so override this
%csmethodmodifiers RemoteMpe::syncmethod "public"
%csmethodmodifiers RemoteMpe::asyncmethod "public"
+#elif defined(SWIGD)
+%dmethodmodifiers IRemoteSyncIO::syncmethod "";
+%dmethodmodifiers IRemoteAsyncIO::asyncmethod "";
+// Features are inherited by derived classes, so override this
+%dmethodmodifiers RemoteMpe::syncmethod "public"
+%dmethodmodifiers RemoteMpe::asyncmethod "public"
#endif
#endif
diff --git a/Examples/test-suite/multiple_inheritance.i b/Examples/test-suite/multiple_inheritance.i
index 1fc68eef9..044345020 100644
--- a/Examples/test-suite/multiple_inheritance.i
+++ b/Examples/test-suite/multiple_inheritance.i
@@ -5,11 +5,13 @@ It tests basic multiple inheritance */
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; /* C#, Java, PHP multiple inheritance */
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; /* C#, D, Java, PHP multiple inheritance */
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBarSpam; /* C#, Java, PHP multiple inheritance */
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBarSpam; /* C#, D, Java, PHP multiple inheritance */
%inline %{
diff --git a/Examples/test-suite/namespace_class.i b/Examples/test-suite/namespace_class.i
index 7dc9139cd..aea5362d1 100644
--- a/Examples/test-suite/namespace_class.i
+++ b/Examples/test-suite/namespace_class.i
@@ -2,6 +2,10 @@
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Ala::Ola;
+#ifdef SWIGD
+%warnfilter(SWIGWARN_IGNORE_OPERATOR_LT);
+#endif
+
%inline %{
template void foobar(T t) {}
namespace test {
diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i
index 353aa999f..91ff2133e 100644
--- a/Examples/test-suite/preproc_line_file.i
+++ b/Examples/test-suite/preproc_line_file.i
@@ -33,12 +33,12 @@ const int NUMBER_UNIQUE(thing) = -2; /* resolves to thing28 */
%javaconst(1);
#elif defined(SWIGCSHARP)
%csconst(1);
+#elif defined(SWIGD)
+%dnativeconst;
#else
%ignore LINE_NUMBER;
%ignore LINE_NUM;
/* spare space */
-
-
#endif
%{
diff --git a/Examples/test-suite/pure_virtual.i b/Examples/test-suite/pure_virtual.i
index 5bda283cf..9e345e2a4 100644
--- a/Examples/test-suite/pure_virtual.i
+++ b/Examples/test-suite/pure_virtual.i
@@ -9,7 +9,8 @@
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, Java, PHP multiple inheritance */
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) E; /* C#, D, Java, PHP multiple inheritance */
%nodefaultctor C;
%nodefaultdtor C;
@@ -65,7 +66,7 @@ public:
%}
/* Fill in method from AA. This class should be constructable */
-#ifdef SWIGCSHARP
+#if defined(SWIGCSHARP) || defined(SWIGD)
%ignore F::method2(); // Work around for lack of multiple inheritance support - base AA is ignored.
#endif
diff --git a/Examples/test-suite/samename.i b/Examples/test-suite/samename.i
index 819cb4abd..cc03995bc 100644
--- a/Examples/test-suite/samename.i
+++ b/Examples/test-suite/samename.i
@@ -1,6 +1,6 @@
%module samename
-#if !(defined(SWIGCSHARP) || defined(SWIGJAVA))
+#if !(defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGD))
class samename {
public:
void do_something() {
diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i
index c168b4747..45eab0507 100644
--- a/Examples/test-suite/special_variable_macros.i
+++ b/Examples/test-suite/special_variable_macros.i
@@ -165,6 +165,20 @@ namespace Space {
return new $typemap(jstype, Space::RenameMe)( new $typemap(jstype, Name)(s) );
}
%}
+#elif defined(SWIGD)
+#if (SWIG_D_VERSION == 1)
+%typemap(dcode) Space::RenameMe %{
+ public static NewName factory(char[] s) {
+ return new $typemap(dptype, Space::RenameMe)( new $typemap(dptype, Name)(s) );
+ }
+%}
+#else
+%typemap(dcode) Space::RenameMe %{
+ public static NewName factory(string s) {
+ return new $typemap(dptype, Space::RenameMe)( new $typemap(dptype, Name)(s) );
+ }
+%}
+#endif
#endif
%rename(NewName) Space::RenameMe;
diff --git a/Examples/test-suite/static_const_member.i b/Examples/test-suite/static_const_member.i
index 3db60b4c2..945e28490 100644
--- a/Examples/test-suite/static_const_member.i
+++ b/Examples/test-suite/static_const_member.i
@@ -11,6 +11,9 @@
#elif SWIGCSHARP
%csconst(1) EN;
%csconst(1) CHARTEST;
+#elif SWIGD
+%dnativeconst EN;
+%dnativeconst CHARTEST;
#endif
%inline %{
diff --git a/Examples/test-suite/template_enum.i b/Examples/test-suite/template_enum.i
index 0d6fbf5b9..f36d5dc40 100644
--- a/Examples/test-suite/template_enum.i
+++ b/Examples/test-suite/template_enum.i
@@ -13,6 +13,10 @@ public:
%template(foo_i) foo;
%template(foo_d) foo;
+#ifdef SWIGD
+// Workaround for the D module which uses the literal value in the generated wrapper code.
+%dconstvalue("3") Manta::ColorSpace::NumComponents;
+#endif
%inline {
diff --git a/Examples/test-suite/template_inherit_abstract.i b/Examples/test-suite/template_inherit_abstract.i
index 2f83433a5..87c921eab 100644
--- a/Examples/test-suite/template_inherit_abstract.i
+++ b/Examples/test-suite/template_inherit_abstract.i
@@ -4,7 +4,8 @@
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) oss::Module; /* C#, Java, PHP multiple inheritance */
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) oss::Module; /* C#, D, Java, PHP multiple inheritance */
%inline %{
@@ -56,7 +57,7 @@ namespace oss
%inline %{
namespace oss
{
-#if defined(SWIG) && defined(SWIGCSHARP)
+#if defined(SWIG) && (defined(SWIGCSHARP) || defined(SWIGD))
%ignore HModule::get(); // Work around for lack of multiple inheritance support - base ModuleBase is ignored.
#endif
struct test : HModule
diff --git a/Examples/test-suite/typemap_namespace.i b/Examples/test-suite/typemap_namespace.i
index 6614e0372..5a198b554 100644
--- a/Examples/test-suite/typemap_namespace.i
+++ b/Examples/test-suite/typemap_namespace.i
@@ -28,9 +28,16 @@ namespace Foo {
#endif
#ifdef SWIGGO
%typemap(gotype) Str1 * = char *;
+#endif
+#ifdef SWIGD
+ %typemap(cwtype) Str1 * = char *;
+ %typemap(dwtype) Str1 * = char *;
+ %typemap(dptype) Str1 * = char *;
+ %typemap(din) Str1 * = char *;
+ %typemap(dout) Str1 * = char *;
#endif
%typemap(in) Str1 * = char *;
-#if !(defined(SWIGCSHARP) || defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGMZSCHEME) || defined(SWIGOCAML) || defined(SWIGGO))
+#if !(defined(SWIGCSHARP) || defined(SWIGLUA) || defined(SWIGPHP) || defined(SWIGMZSCHEME) || defined(SWIGOCAML) || defined(SWIGGO) || defined(SWIGD))
%typemap(freearg) Str1 * = char *;
#endif
%typemap(typecheck) Str1 * = char *;
diff --git a/Examples/test-suite/typemap_out_optimal.i b/Examples/test-suite/typemap_out_optimal.i
index 23cd2ad3f..d707ed2d5 100644
--- a/Examples/test-suite/typemap_out_optimal.i
+++ b/Examples/test-suite/typemap_out_optimal.i
@@ -2,7 +2,7 @@
%module typemap_out_optimal
// Just the following languages tested
-#if defined (SWIGCSHARP)
+#if defined (SWIGCSHARP) || defined (SWIGD)
%typemap(out, optimal="1") SWIGTYPE %{
$result = new $1_ltype((const $1_ltype &)$1);
%}
@@ -18,6 +18,10 @@
%ignore XX::operator=;
+#ifdef SWIGD
+%rename(trace) XX::debug;
+#endif
+
%inline %{
#include
using namespace std;
diff --git a/Examples/test-suite/typemap_subst.i b/Examples/test-suite/typemap_subst.i
index 1b1f8a3f4..91ac62020 100644
--- a/Examples/test-suite/typemap_subst.i
+++ b/Examples/test-suite/typemap_subst.i
@@ -61,8 +61,8 @@
$1 = ($ltype) temp;
}
-/* Java, C# and Go modules don't use SWIG's runtime type system */
-#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO)
+/* Java, C#, Go and D modules don't use SWIG's runtime type system */
+#if !defined(SWIGJAVA) && !defined(SWIGCSHARP) && !defined(SWIGGO) && !defined(SWIGD)
%inline %{
void foo(const struct xyzzy **TEST) {}
%}
diff --git a/Examples/test-suite/using_composition.i b/Examples/test-suite/using_composition.i
index bd0f712b5..052412b5f 100644
--- a/Examples/test-suite/using_composition.i
+++ b/Examples/test-suite/using_composition.i
@@ -2,13 +2,16 @@
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, Java, PHP multiple inheritance
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, D, Java, PHP multiple inheritance
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar2; // C#, Java, PHP multiple inheritance
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar2; // C#, D, Java, PHP multiple inheritance
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar3; // C#, Java, PHP multiple inheritance
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar3; // C#, D, Java, PHP multiple inheritance
#ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) blah;
#endif
diff --git a/Examples/test-suite/using_extend.i b/Examples/test-suite/using_extend.i
index e14cc28e8..c52f65c23 100644
--- a/Examples/test-suite/using_extend.i
+++ b/Examples/test-suite/using_extend.i
@@ -2,7 +2,8 @@
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, Java, PHP multiple inheritance
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) FooBar; // C#, D, Java, PHP multiple inheritance
#ifdef SWIGLUA // lua only has one numeric type, so some overloads shadow each other creating warnings
%warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) blah;
#endif
diff --git a/Examples/test-suite/using_namespace.i b/Examples/test-suite/using_namespace.i
index ce02e9a87..1119b46f7 100644
--- a/Examples/test-suite/using_namespace.i
+++ b/Examples/test-suite/using_namespace.i
@@ -5,7 +5,8 @@
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
- SWIGWARN_PHP_MULTIPLE_INHERITANCE) Hi; // C#, Java, PHP multiple inheritance
+ SWIGWARN_D_MULTIPLE_INHERITANCE,
+ SWIGWARN_PHP_MULTIPLE_INHERITANCE) Hi; // C#, D, Java, PHP multiple inheritance
%inline %{
namespace hello
From 03aefbc6e95d094a6de231e1f5264c0946e209a3 Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 18 Nov 2010 00:24:02 +0000
Subject: [PATCH 016/317] Added support for the D programming languge.
It is still a bit rough around some edges, particularly with regard to multi-threading and operator overloading, and there are some documentation bits missing, but it should be fine for basic use.
The test-suite should build and run fine with the current versions of DMD, LDC and Tango (at least) on Linux x86_64 and Mac OS X 10.6.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12299 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Doc/Manual/D.html | 401 ++
Doc/Manual/Sections.html | 1 +
Doc/Manual/chapters | 1 +
Examples/Makefile.in | 89 +-
Examples/d/callback/Makefile | 28 +
Examples/d/callback/d1/runme.d | 36 +
Examples/d/callback/d2/runme.d | 36 +
Examples/d/callback/example.cxx | 4 +
Examples/d/callback/example.h | 24 +
Examples/d/callback/example.i | 13 +
Examples/d/check.list | 9 +
Examples/d/class/Makefile | 28 +
Examples/d/class/d1/runme.d | 58 +
Examples/d/class/d2/runme.d | 58 +
Examples/d/class/example.cxx | 28 +
Examples/d/class/example.h | 34 +
Examples/d/class/example.i | 10 +
Examples/d/constants/Makefile | 28 +
Examples/d/constants/d1/runme.d | 28 +
Examples/d/constants/d2/runme.d | 28 +
Examples/d/constants/example.d | 23 +
Examples/d/constants/example.i | 32 +
Examples/d/enum/Makefile | 28 +
Examples/d/enum/d1/runme.d | 28 +
Examples/d/enum/d2/runme.d | 28 +
Examples/d/enum/example.cxx | 37 +
Examples/d/enum/example.h | 13 +
Examples/d/enum/example.i | 11 +
Examples/d/extend/Makefile | 28 +
Examples/d/extend/d1/runme.d | 75 +
Examples/d/extend/d2/runme.d | 75 +
Examples/d/extend/example.cxx | 4 +
Examples/d/extend/example.h | 56 +
Examples/d/extend/example.i | 14 +
Examples/d/funcptr/Makefile | 28 +
Examples/d/funcptr/d1/runme.d | 34 +
Examples/d/funcptr/d2/runme.d | 34 +
Examples/d/funcptr/example.c | 19 +
Examples/d/funcptr/example.h | 9 +
Examples/d/funcptr/example.i | 16 +
Examples/d/simple/Makefile | 28 +
Examples/d/simple/d1/runme.d | 27 +
Examples/d/simple/d2/runme.d | 27 +
Examples/d/simple/example.c | 18 +
Examples/d/simple/example.i | 7 +
Examples/d/variables/Makefile | 28 +
Examples/d/variables/d1/runme.d | 71 +
Examples/d/variables/d2/runme.d | 71 +
Examples/d/variables/example.c | 91 +
Examples/d/variables/example.h | 6 +
Examples/d/variables/example.i | 49 +
Examples/test-suite/d/Makefile.in | 80 +
Examples/test-suite/d/README | 7 +
Examples/test-suite/d/aggregate_runme.1.d | 25 +
Examples/test-suite/d/aggregate_runme.2.d | 25 +
Examples/test-suite/d/allprotected_runme.1.d | 65 +
Examples/test-suite/d/allprotected_runme.2.d | 65 +
Examples/test-suite/d/apply_strings_runme.1.d | 12 +
Examples/test-suite/d/apply_strings_runme.2.d | 12 +
Examples/test-suite/d/bools_runme.1.d | 20 +
Examples/test-suite/d/bools_runme.2.d | 20 +
Examples/test-suite/d/catches_runme.1.d | 33 +
Examples/test-suite/d/catches_runme.2.d | 33 +
Examples/test-suite/d/char_strings_runme.1.d | 151 +
Examples/test-suite/d/char_strings_runme.2.d | 123 +
Examples/test-suite/d/constover_runme.1.d | 31 +
Examples/test-suite/d/constover_runme.2.d | 16 +
.../test-suite/d/d_nativepointers_runme.1.d | 23 +
.../test-suite/d/d_nativepointers_runme.2.d | 23 +
Examples/test-suite/d/default_args_runme.1.d | 127 +
Examples/test-suite/d/default_args_runme.2.d | 84 +
.../d/default_constructor_runme.1.d | 30 +
.../d/default_constructor_runme.2.d | 25 +
.../test-suite/d/director_basic_runme.1.d | 59 +
.../test-suite/d/director_basic_runme.2.d | 46 +
.../test-suite/d/director_classes_runme.1.d | 168 +
.../test-suite/d/director_classes_runme.2.d | 169 +
.../test-suite/d/director_classic_runme.1.d | 207 +
.../test-suite/d/director_classic_runme.2.d | 202 +
.../test-suite/d/director_ignore_runme.1.d | 39 +
.../test-suite/d/director_ignore_runme.2.d | 38 +
.../d/director_primitives_runme.1.d | 122 +
.../d/director_primitives_runme.2.d | 123 +
.../test-suite/d/director_protected_runme.1.d | 50 +
.../test-suite/d/director_protected_runme.2.d | 36 +
.../test-suite/d/director_string_runme.1.d | 46 +
.../test-suite/d/director_string_runme.2.d | 42 +
Examples/test-suite/d/enum_thorough_runme.1.d | 424 ++
Examples/test-suite/d/enum_thorough_runme.2.d | 425 ++
.../d/inherit_target_language_runme.1.d | 29 +
.../d/inherit_target_language_runme.2.d | 29 +
Examples/test-suite/d/li_attribute_runme.1.d | 75 +
Examples/test-suite/d/li_attribute_runme.2.d | 58 +
.../d/li_boost_shared_ptr_bits_runme.1.d | 21 +
.../d/li_boost_shared_ptr_bits_runme.2.d | 19 +
.../d/li_boost_shared_ptr_runme.1.d | 604 +++
.../d/li_boost_shared_ptr_runme.2.d | 602 +++
Examples/test-suite/d/li_std_except_runme.1.d | 40 +
Examples/test-suite/d/li_std_except_runme.2.d | 34 +
Examples/test-suite/d/li_std_string_runme.1.d | 97 +
Examples/test-suite/d/li_std_string_runme.2.d | 86 +
Examples/test-suite/d/li_std_vector_runme.1.d | 219 +
Examples/test-suite/d/li_std_vector_runme.2.d | 207 +
Examples/test-suite/d/li_typemaps_runme.1.d | 94 +
Examples/test-suite/d/li_typemaps_runme.2.d | 91 +
Examples/test-suite/d/long_long_runme.1.d | 35 +
Examples/test-suite/d/long_long_runme.2.d | 32 +
.../test-suite/d/member_pointer_runme.1.d | 43 +
.../test-suite/d/member_pointer_runme.2.d | 42 +
.../d/overload_complicated_runme.1.d | 50 +
.../d/overload_complicated_runme.2.d | 34 +
.../test-suite/d/overload_template_runme.1.d | 146 +
.../test-suite/d/overload_template_runme.2.d | 80 +
.../test-suite/d/pointer_reference_runme.1.d | 13 +
.../test-suite/d/pointer_reference_runme.2.d | 14 +
.../d/preproc_constants_c_runme.1.d | 63 +
.../d/preproc_constants_c_runme.2.d | 63 +
.../test-suite/d/preproc_constants_runme.1.d | 62 +
.../test-suite/d/preproc_constants_runme.2.d | 62 +
Examples/test-suite/d/sizet_runme.1.d | 15 +
Examples/test-suite/d/sizet_runme.2.d | 14 +
Examples/test-suite/d/sneaky1_runme.1.d | 21 +
Examples/test-suite/d/sneaky1_runme.2.d | 11 +
.../d/special_variable_macros_runme.1.d | 39 +
.../d/special_variable_macros_runme.2.d | 21 +
Examples/test-suite/d/threads_runme.1.d | 70 +
Examples/test-suite/d/threads_runme.2.d | 55 +
.../test-suite/d/throw_exception_runme.1.d | 30 +
.../test-suite/d/throw_exception_runme.2.d | 30 +
.../test-suite/d/typemap_namespace_runme.1.d | 13 +
.../test-suite/d/typemap_namespace_runme.2.d | 9 +
.../d/typemap_out_optimal_runme.1.d | 9 +
.../d/typemap_out_optimal_runme.2.d | 9 +
Examples/test-suite/d/varargs_runme.1.d | 20 +
Examples/test-suite/d/varargs_runme.2.d | 13 +
Examples/test-suite/d/virtual_poly_runme.1.d | 27 +
Examples/test-suite/d/virtual_poly_runme.2.d | 22 +
Examples/test-suite/d_nativepointers.i | 18 +
Lib/allkw.swg | 1 +
Lib/d/boost_shared_ptr.i | 201 +
Lib/d/carrays.i | 111 +
Lib/d/cpointer.i | 171 +
Lib/d/d.swg | 46 +
Lib/d/dclassgen.swg | 172 +
Lib/d/ddirectives.swg | 11 +
Lib/d/denums.swg | 60 +
Lib/d/dexception.swg | 30 +
Lib/d/dhead.swg | 310 ++
Lib/d/director.swg | 46 +
Lib/d/dkw.swg | 126 +
Lib/d/dmemberfunctionpointers.swg | 92 +
Lib/d/doperators.swg | 77 +
Lib/d/dprimitives.swg | 158 +
Lib/d/dstrings.swg | 80 +
Lib/d/dswigtype.swg | 177 +
Lib/d/dvoid.swg | 18 +
Lib/d/std_common.i | 5 +
Lib/d/std_deque.i | 1 +
Lib/d/std_except.i | 30 +
Lib/d/std_map.i | 59 +
Lib/d/std_pair.i | 34 +
Lib/d/std_shared_ptr.i | 2 +
Lib/d/std_string.i | 98 +
Lib/d/std_vector.i | 591 +++
Lib/d/stl.i | 12 +
Lib/d/typemaps.i | 298 ++
Lib/d/wrapperloader.swg | 303 ++
Lib/exception.i | 36 +-
Lib/std_except.i | 2 +-
Lib/swig.swg | 4 +-
Makefile.in | 17 +-
Source/Include/swigwarn.h | 21 +-
Source/Makefile.am | 1 +
Source/Modules/d.cxx | 4359 +++++++++++++++++
Source/Modules/swigmain.cxx | 2 +
configure.in | 43 +
176 files changed, 16449 insertions(+), 29 deletions(-)
create mode 100644 Doc/Manual/D.html
create mode 100644 Examples/d/callback/Makefile
create mode 100644 Examples/d/callback/d1/runme.d
create mode 100644 Examples/d/callback/d2/runme.d
create mode 100644 Examples/d/callback/example.cxx
create mode 100644 Examples/d/callback/example.h
create mode 100644 Examples/d/callback/example.i
create mode 100644 Examples/d/check.list
create mode 100644 Examples/d/class/Makefile
create mode 100644 Examples/d/class/d1/runme.d
create mode 100644 Examples/d/class/d2/runme.d
create mode 100644 Examples/d/class/example.cxx
create mode 100644 Examples/d/class/example.h
create mode 100644 Examples/d/class/example.i
create mode 100644 Examples/d/constants/Makefile
create mode 100644 Examples/d/constants/d1/runme.d
create mode 100644 Examples/d/constants/d2/runme.d
create mode 100644 Examples/d/constants/example.d
create mode 100644 Examples/d/constants/example.i
create mode 100644 Examples/d/enum/Makefile
create mode 100644 Examples/d/enum/d1/runme.d
create mode 100644 Examples/d/enum/d2/runme.d
create mode 100644 Examples/d/enum/example.cxx
create mode 100644 Examples/d/enum/example.h
create mode 100644 Examples/d/enum/example.i
create mode 100644 Examples/d/extend/Makefile
create mode 100644 Examples/d/extend/d1/runme.d
create mode 100644 Examples/d/extend/d2/runme.d
create mode 100644 Examples/d/extend/example.cxx
create mode 100644 Examples/d/extend/example.h
create mode 100644 Examples/d/extend/example.i
create mode 100644 Examples/d/funcptr/Makefile
create mode 100644 Examples/d/funcptr/d1/runme.d
create mode 100644 Examples/d/funcptr/d2/runme.d
create mode 100644 Examples/d/funcptr/example.c
create mode 100644 Examples/d/funcptr/example.h
create mode 100644 Examples/d/funcptr/example.i
create mode 100644 Examples/d/simple/Makefile
create mode 100644 Examples/d/simple/d1/runme.d
create mode 100644 Examples/d/simple/d2/runme.d
create mode 100644 Examples/d/simple/example.c
create mode 100644 Examples/d/simple/example.i
create mode 100644 Examples/d/variables/Makefile
create mode 100644 Examples/d/variables/d1/runme.d
create mode 100644 Examples/d/variables/d2/runme.d
create mode 100644 Examples/d/variables/example.c
create mode 100644 Examples/d/variables/example.h
create mode 100644 Examples/d/variables/example.i
create mode 100644 Examples/test-suite/d/Makefile.in
create mode 100644 Examples/test-suite/d/README
create mode 100644 Examples/test-suite/d/aggregate_runme.1.d
create mode 100644 Examples/test-suite/d/aggregate_runme.2.d
create mode 100644 Examples/test-suite/d/allprotected_runme.1.d
create mode 100644 Examples/test-suite/d/allprotected_runme.2.d
create mode 100644 Examples/test-suite/d/apply_strings_runme.1.d
create mode 100644 Examples/test-suite/d/apply_strings_runme.2.d
create mode 100644 Examples/test-suite/d/bools_runme.1.d
create mode 100644 Examples/test-suite/d/bools_runme.2.d
create mode 100644 Examples/test-suite/d/catches_runme.1.d
create mode 100644 Examples/test-suite/d/catches_runme.2.d
create mode 100644 Examples/test-suite/d/char_strings_runme.1.d
create mode 100644 Examples/test-suite/d/char_strings_runme.2.d
create mode 100644 Examples/test-suite/d/constover_runme.1.d
create mode 100644 Examples/test-suite/d/constover_runme.2.d
create mode 100644 Examples/test-suite/d/d_nativepointers_runme.1.d
create mode 100644 Examples/test-suite/d/d_nativepointers_runme.2.d
create mode 100644 Examples/test-suite/d/default_args_runme.1.d
create mode 100644 Examples/test-suite/d/default_args_runme.2.d
create mode 100644 Examples/test-suite/d/default_constructor_runme.1.d
create mode 100644 Examples/test-suite/d/default_constructor_runme.2.d
create mode 100644 Examples/test-suite/d/director_basic_runme.1.d
create mode 100644 Examples/test-suite/d/director_basic_runme.2.d
create mode 100644 Examples/test-suite/d/director_classes_runme.1.d
create mode 100644 Examples/test-suite/d/director_classes_runme.2.d
create mode 100644 Examples/test-suite/d/director_classic_runme.1.d
create mode 100644 Examples/test-suite/d/director_classic_runme.2.d
create mode 100644 Examples/test-suite/d/director_ignore_runme.1.d
create mode 100644 Examples/test-suite/d/director_ignore_runme.2.d
create mode 100644 Examples/test-suite/d/director_primitives_runme.1.d
create mode 100644 Examples/test-suite/d/director_primitives_runme.2.d
create mode 100644 Examples/test-suite/d/director_protected_runme.1.d
create mode 100644 Examples/test-suite/d/director_protected_runme.2.d
create mode 100644 Examples/test-suite/d/director_string_runme.1.d
create mode 100644 Examples/test-suite/d/director_string_runme.2.d
create mode 100644 Examples/test-suite/d/enum_thorough_runme.1.d
create mode 100644 Examples/test-suite/d/enum_thorough_runme.2.d
create mode 100644 Examples/test-suite/d/inherit_target_language_runme.1.d
create mode 100644 Examples/test-suite/d/inherit_target_language_runme.2.d
create mode 100644 Examples/test-suite/d/li_attribute_runme.1.d
create mode 100644 Examples/test-suite/d/li_attribute_runme.2.d
create mode 100644 Examples/test-suite/d/li_boost_shared_ptr_bits_runme.1.d
create mode 100644 Examples/test-suite/d/li_boost_shared_ptr_bits_runme.2.d
create mode 100644 Examples/test-suite/d/li_boost_shared_ptr_runme.1.d
create mode 100644 Examples/test-suite/d/li_boost_shared_ptr_runme.2.d
create mode 100644 Examples/test-suite/d/li_std_except_runme.1.d
create mode 100644 Examples/test-suite/d/li_std_except_runme.2.d
create mode 100644 Examples/test-suite/d/li_std_string_runme.1.d
create mode 100644 Examples/test-suite/d/li_std_string_runme.2.d
create mode 100644 Examples/test-suite/d/li_std_vector_runme.1.d
create mode 100644 Examples/test-suite/d/li_std_vector_runme.2.d
create mode 100644 Examples/test-suite/d/li_typemaps_runme.1.d
create mode 100644 Examples/test-suite/d/li_typemaps_runme.2.d
create mode 100644 Examples/test-suite/d/long_long_runme.1.d
create mode 100644 Examples/test-suite/d/long_long_runme.2.d
create mode 100644 Examples/test-suite/d/member_pointer_runme.1.d
create mode 100644 Examples/test-suite/d/member_pointer_runme.2.d
create mode 100644 Examples/test-suite/d/overload_complicated_runme.1.d
create mode 100644 Examples/test-suite/d/overload_complicated_runme.2.d
create mode 100644 Examples/test-suite/d/overload_template_runme.1.d
create mode 100644 Examples/test-suite/d/overload_template_runme.2.d
create mode 100644 Examples/test-suite/d/pointer_reference_runme.1.d
create mode 100644 Examples/test-suite/d/pointer_reference_runme.2.d
create mode 100644 Examples/test-suite/d/preproc_constants_c_runme.1.d
create mode 100644 Examples/test-suite/d/preproc_constants_c_runme.2.d
create mode 100644 Examples/test-suite/d/preproc_constants_runme.1.d
create mode 100644 Examples/test-suite/d/preproc_constants_runme.2.d
create mode 100644 Examples/test-suite/d/sizet_runme.1.d
create mode 100644 Examples/test-suite/d/sizet_runme.2.d
create mode 100644 Examples/test-suite/d/sneaky1_runme.1.d
create mode 100644 Examples/test-suite/d/sneaky1_runme.2.d
create mode 100644 Examples/test-suite/d/special_variable_macros_runme.1.d
create mode 100644 Examples/test-suite/d/special_variable_macros_runme.2.d
create mode 100644 Examples/test-suite/d/threads_runme.1.d
create mode 100644 Examples/test-suite/d/threads_runme.2.d
create mode 100644 Examples/test-suite/d/throw_exception_runme.1.d
create mode 100644 Examples/test-suite/d/throw_exception_runme.2.d
create mode 100644 Examples/test-suite/d/typemap_namespace_runme.1.d
create mode 100644 Examples/test-suite/d/typemap_namespace_runme.2.d
create mode 100644 Examples/test-suite/d/typemap_out_optimal_runme.1.d
create mode 100644 Examples/test-suite/d/typemap_out_optimal_runme.2.d
create mode 100644 Examples/test-suite/d/varargs_runme.1.d
create mode 100644 Examples/test-suite/d/varargs_runme.2.d
create mode 100644 Examples/test-suite/d/virtual_poly_runme.1.d
create mode 100644 Examples/test-suite/d/virtual_poly_runme.2.d
create mode 100644 Examples/test-suite/d_nativepointers.i
create mode 100644 Lib/d/boost_shared_ptr.i
create mode 100644 Lib/d/carrays.i
create mode 100644 Lib/d/cpointer.i
create mode 100644 Lib/d/d.swg
create mode 100644 Lib/d/dclassgen.swg
create mode 100644 Lib/d/ddirectives.swg
create mode 100644 Lib/d/denums.swg
create mode 100644 Lib/d/dexception.swg
create mode 100644 Lib/d/dhead.swg
create mode 100644 Lib/d/director.swg
create mode 100644 Lib/d/dkw.swg
create mode 100644 Lib/d/dmemberfunctionpointers.swg
create mode 100644 Lib/d/doperators.swg
create mode 100644 Lib/d/dprimitives.swg
create mode 100644 Lib/d/dstrings.swg
create mode 100644 Lib/d/dswigtype.swg
create mode 100644 Lib/d/dvoid.swg
create mode 100644 Lib/d/std_common.i
create mode 100644 Lib/d/std_deque.i
create mode 100644 Lib/d/std_except.i
create mode 100644 Lib/d/std_map.i
create mode 100644 Lib/d/std_pair.i
create mode 100644 Lib/d/std_shared_ptr.i
create mode 100644 Lib/d/std_string.i
create mode 100644 Lib/d/std_vector.i
create mode 100644 Lib/d/stl.i
create mode 100644 Lib/d/typemaps.i
create mode 100644 Lib/d/wrapperloader.swg
create mode 100644 Source/Modules/d.cxx
diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html
new file mode 100644
index 000000000..2b563788f
--- /dev/null
+++ b/Doc/Manual/D.html
@@ -0,0 +1,401 @@
+
+
+
+SWIG and D
+
+
+
+
+ 20 SWIG and D
+
+
+
+
+
+
+ 20.1 Introduction
+
+
+From the D Programming Language web site: »D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. […] The D language is statically typed and compiles directly to machine code.« As such, it is not very surprising that D is able to directly interface with C libraries . Why would a SWIG module for D be needed then in the first place?
+
+Well, besides the obvious downside that the C header files have to be manually converted to D modules for this to work, there is one major inconvenience with this approach: D code usually is on a higher abstraction level than C, and many of the features that make D interesting are simply not available when dealing with C libraries, requiring you e.g. to manually convert strings between pointers to \0 -terminated char arrays and D char arrays, making the algorithms from the D2 standard library unusable with C arrays and data structures, and so on.
+
+While these issues can be worked around relatively easy by hand-coding a thin wrapper layer around the C library in question, there is another issue where writing wrapper code per hand is not feasible: C++ libraries. D did not support interfacing to C++ in version 1 at all, and even if extern(C++) has been added to D2, the support is still very limited, and a custom wrapper layer is still required in many cases.
+
+To help addressing these issues, the SWIG C# module has been forked to support D. Is has evolved quite a lot since then, but there are still many similarities, so if you do not find what you are looking for on this page, it might be worth having a look at the chapter on C# (and also on Java , since the C# module was in turn forked from it).
+
+
+ 20.2 Command line invocation
+
+
+To activate the D module, pass the -d option to SWIG at the command line. The same standard command line switches as with any other language module are available, plus the following D specific ones:
+
+
+ -splitproxy
+
+ By default, SWIG generates two D modules: the proxy module, named like the source module (either specified via the %module directive or via the module command line switch), which contains all the proxy classes, functions, enums, etc., and the wrap module (named like the proxy module, but suffixed with _wrap ), which contains all the extern(C) function declarations and other private parts only used internally by the proxy module.
+ If the split proxy mode is enabled by passing this switch at the command line, all proxy classes and enums are emitted to their own D module instead. The main proxy module only contains free functions and constants in this case.
+
+
+ -package <pkg>
+
+ By default, the proxy D modules and the wrap D module are written to the root package. Using this option, you can specify another target package instead.
+
+
+ -wrapperlibrary <wl>
+
+ The code SWIG generates to dynamically load the C/C++ wrapper layer looks for a library called $module_wrap , just like the wrap D module is. With this switch, you can override the name of the file the wrapper code loads at runtime (the lib prefix and the suffix for shared libraries are appended automatically, depending on the OS).
+ This might especially be useful if you want to invoke SWIG several times on separate modules, but compile the resulting code into a single shared library.
+
+
+
+
+ 20.3 Typemaps
+
+
+ 20.3.1 C# <-> D name comparison
+
+
+
+ ctype <-> cwtype
+ imtype <-> dwtype
+ cstype <-> dptype
+ csin <-> din
+ csout <-> dout
+ csdirectorin <-> ddirectorin
+ csdirectorout <-> ddirectorout
+ csinterfaces <-> dinterfaces
+ csinterfaces_derived <-> dinterfaces_derived
+ csbase <-> dbase
+ csclassmodifiers <-> dclassmodifiers
+ cscode <-> dcode
+ csimports <-> dimports
+ csbody <-> dbody
+ csfinalize <-> ddestructor
+ csdestruct <-> ddispose
+ csdestruct_derived <-> ddispose_derived
+
+
+
+ 20.3.2 cwtype, dwtype, dptype
+
+
+Mapping of types between the C/C++ library, the C/C++ library wrapper exposing the C functions, the D wrapper module importing these functions and the D proxy code.
+
+The cwtype typemap is used to determine the types to use in the C wrapper functions. The types from the dwtype typemap are used in the extern(C) declarations of these functions in the D wrap module. The dptype typemap contains the D types used in the D proxy module/class.
+
+
+ 20.3.3 in, out, directorin, directorout
+
+
+Used for converting between the types for C/C++ and D when generating the code for the wrapper functions (on the C++ side).
+
+The code from the in typemap is used to convert arguments to the C wrapper function to the type used in the wrapped code (cwtype ->original C++ type), the out typemap is utilized to convert values from the wrapped code to wrapper function return types (original C++ type->cwtype ).
+
+The directorin typemap is used to convert parameters to the type used in the D director callback function, its return value is processed by directorout (see below).
+
+
+ 20.3.4 din, dout, ddirectorin, ddirectorout
+
+
+Typemaps for code generation in D proxy and type wrapper classes.
+
+The din typemap is used for converting function parameter types from the type used in the proxy module or class to the type used in the D wrap module (the $dinput macro is replaced).
+
+The dout typemap is used for converting function return values from the return type used in the wrap D module to the type returned by the proxy function. The $excode special variable in dout typemaps is replaced by the excode typemap attribute code if the method can throw any exceptions from unmanaged code, otherwise by nothing (the $wcall and $owner macros are replaced).
+
+The code from the ddirectorin and ddirectorout typemaps is used for conversion in director callback functions. Arguments are converted to the type used in the proxy class method they are calling by using the code from ddirectorin , the proxy class method return value is converted to the type the C++ code expects via the ddirectorout typemap (the $dpcall and $winput macros are replaced).
+
+The full chain of type conversions when a director callback is invoked looks like this:
+
+ type CPPClass::method(type a)
+ ↑ ↓
+ <directorout> <directorin>
+ ↑ ↓
+ cwtype methodCallback(cwtype a) C++
+ ::::::::::::::::::::::::::::::::::::::::::
+ dwtype methodCallback(dwtype a) D
+ ↑ ↓
+ <ddirectorout> <ddirectorin>
+ ↑ ↓
+ dptype DClass.method(dptype a)
+
+
+ 20.3.5 typecheck typemaps
+
+
+Because, unlike many scripting languages supported by SWIG, D does not need any dynamic dispatch helper to access an overloaded function, the purpose of these is merely to issue a warning for overloaded C++ functions that cannot be overloaded in D (as more than one C++ type maps to a single D type).
+
+
+ 20.3.6 Code injection typemaps
+
+
+These typemaps are used for generating the skeleton of proxy classes for C++ types.
+
+By overriding dbase , dinterfaces or dinterfaces_derived , the inheritance chain of the generated proxy class for a type can be modified. dclassmodifiers allows you to add any custom modifiers around the class keyword.
+
+Using dcode and dimports , you can specify additional D code which will be emitted into the class body respectively the imports section of the D module the class is written to.
+
+dconstructor , ddestructor , ddispose and ddispose_derived are used to generate the class constructor, destructor and dispose() method, respectively. The auxiliary code for handling the pointer to the C++ object is stored in dbody and dbody_derived . You can override them for specific types.
+
+
+ 20.3.7 Special variable macros
+
+
+The standard SWIG special variables are available for use within typemaps as described in the Typemaps documentation , for example $1 , $input , $result etc.
+
+When generating D wrappers, a few additional macros are available:
+
+ $dclassname (C#: $csclassname )
+
+ This special variable works similar to $n_type in that it returns the name of a type – it expands to the D proxy class name of the type being wrapped. If the type does not have an associated proxy class, it expands to the type wrapper class name, for example, SWIGTYPE_p_p_SomeCppClass is generated when wrapping SomeCppClass ** .
+ There are two other variants available, $&dclassname and $*dclassname . The former adds a level of indirection, while the latter removes one. For instance, when wrapping Foo ** , $*dclassname would be replaced by the proxy class name corresponding to Foo * .
+
+
+ $null
+ In code inserted into the generated C/C++ wrapper functions, this variable is replaced by either 0 or nothing at all, depending on whether the function has a return value or not. It can be used to bail out early e.g. in case of errors (return $null; ).
+
+ $dinput (C#: $csinput )
+
+ This variable is used in din typemaps and is replaced by the expression which is to be passed to C/C++.
+ For example, this input
+
+%typemap(din) SomeClass * "SomeClass.getCPointer($dinput)"
+
+%inline %{
+ class SomeClass {};
+ void foo(SomeClass *arg);
+%}
+ leads to the following D proxy code being generated:
+
+void foo(SomeClass arg) {
+ example_wrap.foo(SomeClass.getCPointer(arg));
+}
+
+ $wcall and $owner (C#: $imcall )
+
+ These variables are used in dout typemaps. $wcall contains the call to the wrapper layer which provides the value to be used, and $owner signals if the caller is responsible for managing the object lifetime (that is, if the called method is a constructor or has been marked via %newobject ).
+ Consider the following example:
+
+%typemap(dout) SomeClass * {
+ return new SomeClass($wcall, $owner);
+}
+
+%inline %{
+ class SomeClass;
+ SomeClass *foo();
+
+ %newobject bar();
+ SomeClass *bar();
+%}
+ The code generated for foo() and bar() looks like this:
+
+SomeClass foo() {
+ return new SomeClass(example_wrap.foo(), false);
+}
+
+SomeClass bar() {
+ return new SomeClass(example_wrap.bar(), true);
+}
+
+
+
+ $dpcall and $winput (C#: $cscall , $iminput )
+ These variables are used in the director-specific typemaps ddirectorin and ddirectorout . They are more or less the reverse of the $wcall and $dinput macros: $dpcall contains the invocation of the D proxy method of which the return value is to be passed back to C++, $winput contains the parameter value from C++.
+
+ $excode
+ This variable is used in dout and dconstructor typemaps and is filled with the contents of the excode typemap attribute if an exception could be thrown from the C++ side. See the C# documentation for details.
+
+ $dbaseclass
+ Currently for internal use only, it contains the D name of the C++ base class (if any) inside proxy classes.
+
+ $directorconnect
+
+ This macro is only valid inside the dconstructor typemap and contains the value of the dconstructor typemap attribute if the currently wrapped class has directors enabled.
+ This is how the default dconstructor typemap looks like (you usually do not want to specify a custom one):
+
+%typemap(dconstructor, excode=SWIGEXCODE,directorconnect="\n swigDirectorConnect();") SWIGTYPE {
+ this($wcall, true);$excode$directorconnect
+}
+
+
+
+ $importtype(SomeDType)
+
+ This macro is used in the dimports typemap if a dependency on another D type generated by SWIG is added by a custom typemap.
+ Consider the following code snippet:
+
+%typemap(dinterfaces) SomeClass "AnInterface, AnotherInterface";
+
+ This causes SWIG to add AnInterface and AnotherInterface to the base class list of SomeClass :
+
+class SomeClass : AnInterface, AnotherInterface {
+ …
+}
+
+ For this to work, AnInterface and AnotherInterface have to be in scope. If SWIG is not in split proxy mode, this is already the case, but it it is, they have to be added to the import list via the dimports typemap. Additionally, the import statement depends on the package SWIG is configured to emit the modules to.
+ The $importtype macro helps you to elegantly solve this problem:
+
+%typemap(dimports) RemoteMpe %{
+$importtype(AnInterface)
+$importtype(AnotherInterface)
+%}
+
+ If SWIG is in split proxy mode, it expands to an import statement for the specified type, to nothing if not.
+
+
+ $module
+ Expands to the name of the main proxy D module.
+
+ $wrapdmodule
+ Contains the fully qualified name of the wrap D module.
+
+
+
+ 20.4 %feature s
+
+
+The D module defines a number of directives which modify the SWIG features set globally or for a specific declaration:
+
+
+
+ %dnativeconst and %dconstvalue(value)
+
+ Out of the box, SWIG generates accessor methods for C #defines and C++ constants. The %dnativeconst directive enables wrapping these constants as D manifest constants (const in D1, enum in D2).
+ For this to work, the C/C++ code for the constant value must directly compile as D code, though. If this is not the case, you can manually override the expression written to the D wrapper using the %dconstvalue directive, passing the new value as parameter.
+ For enum s, again %dconstvalue can be used to override the value of an enum item if the initializer should not compile in D.
+
+
+ %dmethodmodifiers
+
+ This directive can be used to override the modifiers for a proxy function. For instance, you could make a public C++ member function private in D like this:
+
+%dmethodmodifiers A::foo "private";
+
+%inline %{
+struct A {
+ void foo();
+};
+%}
+
+
+
+
+
+ 20.5 Pragmas
+
+
+There are a few SWIG pragmas specific to the D module, which you can use to influence the D code SWIG generates:
+
+
+ %pragma(d) wrapdmodulecode
+ The passed text (D code) is copied verbatim to the wrap D module. For example, it can be (and is, internally) used to emit additional private helper code for the use by proxy typemaps.
+
+ %pragma(d) wrapdmoduleimports
+ Additional code to be emitted to the imports section of the wrap D module (the $importtype macro can be used here). You probably want to use this in conjunction with the wrapdmodulecode pragma.
+
+ %pragma(d) proxydmodulecode
+ Just like proxydmodulecode , the argument is copied to the proxy D module (if SWIG is in split proxy mode , it is emitted to the main proxy D module only).
+
+ %pragma(d) globalproxyimports
+
+ The D module currently does not support specifying dependencies on external modules (e.g. from the standard library) for the D typemaps. To add the import statements to the proxy modules (resp. to all proxy modules if in split proxy mode), you can use the globalproxyimports directive.
+ For example:
+
+%typemap(din) char[] "($dinput ? tango.stdc.stringz.toStringz($dinput) : null)"
+%pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
+
+
+
+ %pragma(d) wrapperloadercode
+
+ The D code for loading the wrapper library (it is copied to the wrap D module). The $wrapperloaderbindcode variable is replaced by the list of commands for binding the functions from the wrapper library to the symbols in the wrap D module.
+ Each time this pragma is specified, the previous value is overwritten.
+
+
+ %pragma(d) wrapperloaderbindcommand
+
+ The D command to use for binding the wrapper functions from the C/C++ library to the symbols in the wrap D module. The $function variable contains the name of the D function in the wrap module, the $symbol variable is replaced by the name of the symbol in the library.
+ Each time this pragma is specified, the previous value is overwritten.
+
+
+
+
+ 20.6 D Exceptions
+
+
+Out of the box, C++ exceptions are fundamentally incompatible to their equivalent in the D world and cannot simply be propagated to a calling D method. There is, however, an easy way to solve this problem: Just catch the exception in the C/C++ wrapper layer, pass the contents to D, and make the wrapper code rethrow the exception in the D world.
+
+The implementation details of this are a bit crude, but the SWIG D module automatically takes care of this, as long as it is able to detect that an exception could potentially be thrown (e.g. because the C++ method has a throw(…) exception specification).
+
+As this feature is implemented in exactly the same way it is for C#, please see the C# documentation for a more detailed explanation.
+
+
+ 20.7 D Directors
+
+
+When the directors feature is activated, SWIG generates extra code on both the C++ and the D side to enable cross-language polymorphism. Essentially, this means that if you subclass a proxy class in D, C++ code can access any overridden virtual methods just as if you created a derived class in C++.
+
+There is no D specific documentation yet, but the way the feature is implemented is very similar to how it is done in Java and C# .
+
+
+
+ 20.8 Other features
+
+
+The nspace feature of SWIG is not yet supported for D – all class modules are written to the same package, regardless of which C++ namespace they are in.
+
+Support of pointers to primitive types.
+
+
+ 20.9 D Typemap examples
+
+
+There are no D-specific typemap examples yet. However, with the above name comparison table , you should be able to get an idea what can be done by looking at the corresponding C# section .
+
+
+
+ 20.10 Work in progress and planned features
+
+
+There are a couple of features which are not implemented yet, but would be very useful and might be added in the near future:
+
+
+ Static linking: Currently, the C wrapper code is compiled into a dynamic library, out of which the symbol addresses are looked up at runtime by the D part. If statically linking the different languages into one binary was supported, a tool-chain capable of performing IPO at link time could inline the wrapping code, effectively reducing the overhead for simple calls to zero.
+ C array handling: Many data structures in some C/C++ libraries contain array containing of a pointer to the first element and the element count. Currently, one must manually writing wrapper code to be able to access these from D. It should be possible to add a set of SWIG macros to semi-automatically generate conversion code.
+ Operator overloading: Currently, operator overloading is supported only to a very limited extent – many C++ operators are just ignored with a warning. The problem here is that the way D handles operator overloading differs quite a lot from the way C++ does it, both syntactically and semantically, and even more so since the advent of template-based operator overloading in D2.
+
+
+Some generated code might also be a bit rough around the edges, particularly in the following areas:
+
+
+ Memory management: Although the currently generated wrapper code works fine with regard to the GC for the test-suite, there might be issues coming up in real-world multi-threaded usage.
+ D2 support : Originally, the module has been developed for the use with D1, D2/Phobos support has been added in later. The basic features should work equally well for both, but there could be issues concerning const-correctness etc.
+
+
+
+
+
+
diff --git a/Doc/Manual/Sections.html b/Doc/Manual/Sections.html
index 855244790..a44571992 100644
--- a/Doc/Manual/Sections.html
+++ b/Doc/Manual/Sections.html
@@ -52,6 +52,7 @@ Last update : SWIG-2.0.2 (in progress)
R support
Ruby support
Tcl support
+D support
Developer Documentation
diff --git a/Doc/Manual/chapters b/Doc/Manual/chapters
index e918e234a..924c8cfde 100644
--- a/Doc/Manual/chapters
+++ b/Doc/Manual/chapters
@@ -17,6 +17,7 @@ CCache.html
Allegrocl.html
CSharp.html
Chicken.html
+D.html
Go.html
Guile.html
Java.html
diff --git a/Examples/Makefile.in b/Examples/Makefile.in
index 582c75f29..5d5590311 100644
--- a/Examples/Makefile.in
+++ b/Examples/Makefile.in
@@ -69,7 +69,7 @@ IOBJS = $(IWRAP:.i=.@OBJEXT@)
CPP_DLLIBS = #-L/usr/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.7.2 \
-L/usr/local/lib -lg++ -lstdc++ -lgcc
-# Solaris workshop 5.0
+# Solaris workshop 5.0
# CPP_DLLIBS = -L/opt/SUNWspro/lib -lCrun
# Symbols used for using shared libraries
@@ -159,7 +159,7 @@ tcl_cpp: $(SRCS)
# -----------------------------------------------------------------
tcl_clean:
- rm -f *_wrap* *~ .~* mytclsh@EXEEXT@
+ rm -f *_wrap* *~ .~* mytclsh@EXEEXT@
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@
@@ -296,9 +296,9 @@ python_static_cpp: $(SRCS)
$(CXX) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES) \
$(PYTHON_INCLUDE) $(LIBS) -L$(PYTHON_LIB) $(PYTHON_LIBOPTS) -o $(TARGET)
-# -----------------------------------------------------------------
+# -----------------------------------------------------------------
# Running a Python example
-# -----------------------------------------------------------------
+# -----------------------------------------------------------------
ifeq (,$(PY3))
PYSCRIPT = runme.py
@@ -313,7 +313,7 @@ python_run: $(PYSCRIPT)
runme3.py: runme.py
cp $< $@
- $(PY2TO3) -w $@ >/dev/null 2>&1
+ $(PY2TO3) -w $@ >/dev/null 2>&1
# -----------------------------------------------------------------
# Cleaning the python examples
@@ -332,7 +332,7 @@ python_clean:
# Make sure these locate your Octave installation
OCTAVE_INCLUDE= $(DEFS) @OCTAVEEXT@
-OCTAVE_LIB =
+OCTAVE_LIB =
# Extra Octave specific dynamic linking options
OCTAVE_DLNK = @OCTAVEDYNAMICLINKING@
@@ -548,14 +548,14 @@ mzscheme: $(SRCS)
mzscheme_cpp: $(SRCS)
$(SWIG) -mzscheme -c++ $(SWIGOPT) $(INTERFACEPATH)
$(COMPILETOOL) $(MZC) `echo $(INCLUDES) | sed 's/-I/++ccf -I/g'` --cc $(ICXXSRCS) $(SRCS) $(CXXSRCS)
- $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS)
+ $(CXXSHARED) $(CFLAGS) -o $(LIBPREFIX)$(TARGET)$(MZSCHEME_SO) $(OBJS) $(IOBJS) $(MZDYNOBJ) $(CPP_DLLIBS)
# -----------------------------------------------------------------
# Cleaning the mzscheme examples
# -----------------------------------------------------------------
mzscheme_clean:
- rm -f *_wrap* *~ .~*
+ rm -f *_wrap* *~ .~*
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@
@@ -643,7 +643,7 @@ ocaml_static_cpp: $(SRCS)
$(INTERFACE:%.i=%.cmo) \
$(PROGFILE:%.ml=%.cmo) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \
- -cclib "$(LIBS)" -cc '$(CXX)'
+ -cclib "$(LIBS)" -cc '$(CXX)'
ocaml_static_cpp_toplevel: $(SRCS)
$(OCAMLCORE)
@@ -661,7 +661,7 @@ ocaml_static_cpp_toplevel: $(SRCS)
-g -ccopt -g -cclib -g -custom -o $(TARGET)_top \
$(INTERFACE:%.i=%.cmo) \
$(INTERFACE:%.i=%_wrap.@OBJEXT@) $(OBJS) \
- -cclib "$(LIBS)" -cc '$(CXX)'
+ -cclib "$(LIBS)" -cc '$(CXX)'
ocaml_dynamic_cpp: $(SRCS)
$(OCAMLCORE)
@@ -844,7 +844,7 @@ pike_cpp_static: $(SRCS)
# -----------------------------------------------------------------
pike_clean:
- rm -f *_wrap* *~ .~* mypike@EXEEXT@
+ rm -f *_wrap* *~ .~* mypike@EXEEXT@
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *@SO@
@@ -861,7 +861,7 @@ CHICKEN_CFLAGS = @CHICKENOPTS@
CHICKENOPTS = -quiet
CHICKEN_MAIN =
-# SWIG produces $(ISRCS) (the C wrapper file)
+# SWIG produces $(ISRCS) (the C wrapper file)
# and $(CHICKEN_GENERATED_SCHEME) (the Scheme wrapper file):
CHICKEN_GENERATED_SCHEME = $(INTERFACE:.i=.scm)
CHICKEN_COMPILED_SCHEME = $(INTERFACE:.i=_chicken.c)
@@ -1053,12 +1053,12 @@ lua_clean:
allegrocl: $(SRCS)
$(SWIG) -allegrocl -cwrap $(SWIGOPT) $(INTERFACEPATH)
- $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
+ $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
$(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
allegrocl_cpp: $(SRCS)
$(SWIG) -c++ -allegrocl $(SWIGOPT) $(INTERFACEPATH)
- $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
+ $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
allegrocl_clean:
@@ -1087,12 +1087,12 @@ clisp_clean:
cffi: $(SRCS)
$(SWIG) -cffi $(SWIGOPT) $(INTERFACEPATH)
-# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
+# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
# $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
cffi_cpp: $(SRCS)
$(SWIG) -c++ -cffi $(SWIGOPT) $(INTERFACEPATH)
- $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
+ $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
$(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
cffi_clean:
@@ -1106,12 +1106,12 @@ cffi_clean:
uffi: $(SRCS)
$(SWIG) -uffi $(SWIGOPT) $(INTERFACEPATH)
-# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
+# $(CC) -c $(CCSHARED) $(CFLAGS) $(ISRCS) $(INCLUDES) $(SRCS)
# $(LDSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
uffi_cpp: $(SRCS)
$(SWIG) -c++ -uffi $(SWIGOPT) $(INTERFACEPATH)
-# $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
+# $(CXX) -c $(CCSHARED) $(CFLAGS) $(ICXXSRCS) $(SRCS) $(CXXSRCS) $(INCLUDES)
# $(CXXSHARED) $(CFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(SO)
uffi_clean:
@@ -1212,3 +1212,56 @@ go_clean:
rm -f *_wrap* *_gc* .~* runme
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *.[568] *.a *@SO@
+
+##################################################################
+##### D ######
+##################################################################
+
+DLIBPREFIX = @DLIBPREFIX@
+
+ifeq (2,$(D_VERSION))
+ SWIGD = $(SWIG) -d -d2
+ DCOMPILER = @D2COMPILER@
+else
+ SWIGD = $(SWIG) -d
+ DCOMPILER = @D1COMPILER@
+endif
+
+ifeq (dmd,$(DCOMPILER))
+ # DMD is 32bit only by now
+ CFLAGS += -m32
+endif
+
+# ----------------------------------------------------------------
+# Build a dynamically loadable D wrapper for a C module
+# ----------------------------------------------------------------
+
+d: $(SRCS)
+ $(SWIGD) $(SWIGOPT) $(INTERFACEPATH)
+ $(CC) -c $(CCSHARED) $(CFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES)
+ $(LDSHARED) $(CFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
+
+# ----------------------------------------------------------------
+# Build a dynamically loadable D wrapper for a C++ module
+# ----------------------------------------------------------------
+
+d_cpp: $(SRCS)
+ $(SWIGD) -c++ $(SWIGOPT) $(INTERFACEPATH)
+ $(CXX) -c $(CCSHARED) $(CFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES)
+ $(CXXSHARED) $(CFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
+
+# ----------------------------------------------------------------
+# Compile D files
+# ----------------------------------------------------------------
+
+d_compile: $(SRCS)
+ $(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS)
+
+# -----------------------------------------------------------------
+# Clean the D examples
+# -----------------------------------------------------------------
+
+d_clean:
+ rm -f *_wrap* *~ .~* runme runme.exe `find . -name \*.d | grep -v runme.d`
+ rm -f core @EXTRA_CLEAN@
+ rm -f *.@OBJEXT@ *@SO@
diff --git a/Examples/d/callback/Makefile b/Examples/d/callback/Makefile
new file mode 100644
index 000000000..bc16dd0fc
--- /dev/null
+++ b/Examples/d/callback/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/callback/d1/runme.d b/Examples/d/callback/d1/runme.d
new file mode 100644
index 000000000..e34e09603
--- /dev/null
+++ b/Examples/d/callback/d1/runme.d
@@ -0,0 +1,36 @@
+module runme;
+
+import tango.io.Stdout;
+import example;
+
+public class DCallback : Callback {
+ public override void run() {
+ Stdout( "DCallback.run()" ).newline;
+ }
+}
+
+void main() {
+ auto caller = new Caller();
+
+ Stdout( "Adding and calling a normal C++ callback" ).newline;
+ Stdout( "----------------------------------------" ).newline;
+ {
+ scope auto callback = new Callback();
+ caller.setCallback(callback);
+ caller.call();
+ caller.resetCallback();
+ }
+
+ Stdout.newline;
+ Stdout( "Adding and calling a D callback" ).newline;
+ Stdout( "-------------------------------" ).newline;
+ {
+ scope auto callback = new DCallback();
+ caller.setCallback(callback);
+ caller.call();
+ caller.resetCallback();
+ }
+
+ Stdout.newline;
+ Stdout( "D exit" ).newline;
+}
diff --git a/Examples/d/callback/d2/runme.d b/Examples/d/callback/d2/runme.d
new file mode 100644
index 000000000..88ffcdefd
--- /dev/null
+++ b/Examples/d/callback/d2/runme.d
@@ -0,0 +1,36 @@
+module runme;
+
+import std.stdio;
+import example;
+
+public class DCallback : Callback {
+ public override void run() {
+ writeln( "DCallback.run()" );
+ }
+}
+
+void main() {
+ auto caller = new Caller();
+
+ writeln( "Adding and calling a normal C++ callback" );
+ writeln( "----------------------------------------" );
+ {
+ scope auto callback = new Callback();
+ caller.setCallback(callback);
+ caller.call();
+ caller.resetCallback();
+ }
+
+ writeln();
+ writeln( "Adding and calling a D callback" );
+ writeln( "-------------------------------" );
+ {
+ scope auto callback = new DCallback();
+ caller.setCallback(callback);
+ caller.call();
+ caller.resetCallback();
+ }
+
+ writeln();
+ writeln( "D exit" );
+}
diff --git a/Examples/d/callback/example.cxx b/Examples/d/callback/example.cxx
new file mode 100644
index 000000000..450d75608
--- /dev/null
+++ b/Examples/d/callback/example.cxx
@@ -0,0 +1,4 @@
+/* File : example.cxx */
+
+#include "example.h"
+
diff --git a/Examples/d/callback/example.h b/Examples/d/callback/example.h
new file mode 100644
index 000000000..38d25a043
--- /dev/null
+++ b/Examples/d/callback/example.h
@@ -0,0 +1,24 @@
+/* File : example.h */
+
+#include
+#include
+
+class Callback {
+public:
+ virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
+ virtual void run() { std::cout << "Callback::run()" << std::endl; }
+};
+
+
+class Caller {
+private:
+ Callback *_callback;
+public:
+ Caller(): _callback(0) {}
+ ~Caller() { delCallback(); }
+ void delCallback() { delete _callback; _callback = 0; }
+ void setCallback(Callback *cb) { delCallback(); _callback = cb; }
+ void resetCallback() { _callback = 0; }
+ void call() { if (_callback) _callback->run(); }
+};
+
diff --git a/Examples/d/callback/example.i b/Examples/d/callback/example.i
new file mode 100644
index 000000000..90beda01a
--- /dev/null
+++ b/Examples/d/callback/example.i
@@ -0,0 +1,13 @@
+/* File : example.i */
+%module(directors="1") example
+%{
+#include "example.h"
+%}
+
+%include "std_string.i"
+
+/* turn on director wrapping Callback */
+%feature("director") Callback;
+
+%include "example.h"
+
diff --git a/Examples/d/check.list b/Examples/d/check.list
new file mode 100644
index 000000000..010e7bbfc
--- /dev/null
+++ b/Examples/d/check.list
@@ -0,0 +1,9 @@
+# See top-level Makefile.in.
+callback
+class
+constants
+enum
+extend
+funcptr
+simple
+variables
diff --git a/Examples/d/class/Makefile b/Examples/d/class/Makefile
new file mode 100644
index 000000000..bc16dd0fc
--- /dev/null
+++ b/Examples/d/class/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/class/d1/runme.d b/Examples/d/class/d1/runme.d
new file mode 100644
index 000000000..b0c4263a2
--- /dev/null
+++ b/Examples/d/class/d1/runme.d
@@ -0,0 +1,58 @@
+// This example illustrates how C++ classes can be used from D using SWIG.
+// The D class gets mapped onto the C++ class and behaves as if it is a D class.
+module runme;
+
+import tango.io.Stdout;
+import example;
+
+void main() {
+ // ----- Object creation -----
+
+ Stdout( "Creating some objects:" ).newline;
+
+ {
+ scope Square s = new Square(10);
+ scope Circle c = new Circle(10);
+
+ // ----- Access a static member -----
+ Stdout.format( "{} shapes were created.", Shape.nshapes ).newline;
+
+ // ----- Member data access -----
+
+ // Notice how we can do this using functions specific to
+ // the 'Circle' class.
+ c.x = 20;
+ c.y = 30;
+
+ // Now use the same functions in the base class
+ Shape shape = s;
+ shape.x = -10;
+ shape.y = 5;
+
+ Stdout( "\nHere is their current position:" ).newline;
+ Stdout.format( " Circle = ( {}, {} )", c.x, c.y ).newline;
+ Stdout.format( " Square = ( {}, {} )", s.x, s.y ).newline;
+
+ // ----- Call some methods -----
+
+ Stdout( "\nHere are some properties of the shapes:" ).newline;
+ Shape[] shapes = [ cast(Shape) c, cast(Shape) s ];
+ foreach ( currentShape; shapes )
+ {
+ Stdout.format( " {}", currentShape.classinfo.name ).newline;
+ Stdout.format( " area = {}", currentShape.area() ).newline;
+ Stdout.format( " perimeter = {}", currentShape.perimeter() ).newline;
+ }
+
+ // Notice how the area() and perimeter() functions really
+ // invoke the appropriate virtual method on each object.
+
+ // ----- Delete everything -----
+ Stdout( "\nGuess I'll clean up now:" ).newline;
+ // Note: when this using scope is exited the D destructors are called which
+ // in turn call the C++ destructors.
+ }
+
+ Stdout.format( "{} shapes remain", Shape.nshapes ).newline;
+ Stdout( "\nGoodbye!" ).newline;
+}
diff --git a/Examples/d/class/d2/runme.d b/Examples/d/class/d2/runme.d
new file mode 100644
index 000000000..2e86c5fc7
--- /dev/null
+++ b/Examples/d/class/d2/runme.d
@@ -0,0 +1,58 @@
+// This example illustrates how C++ classes can be used from D using SWIG.
+// The D class gets mapped onto the C++ class and behaves as if it is a D class.
+module runme;
+
+import std.stdio;
+import example;
+
+void main() {
+ // ----- Object creation -----
+
+ writeln( "Creating some objects:" );
+
+ {
+ scope Square s = new Square(10);
+ scope Circle c = new Circle(10);
+
+ // ----- Access a static member -----
+ writefln( "%s shapes were created.", Shape.nshapes );
+
+ // ----- Member data access -----
+
+ // Notice how we can do this using functions specific to
+ // the 'Circle' class.
+ c.x = 20;
+ c.y = 30;
+
+ // Now use the same functions in the base class
+ Shape shape = s;
+ shape.x = -10;
+ shape.y = 5;
+
+ writeln( "\nHere is their current position:" );
+ writefln( " Circle = ( %s, %s )", c.x, c.y );
+ writefln( " Square = ( %s, %s )", s.x, s.y );
+
+ // ----- Call some methods -----
+
+ writeln( "\nHere are some properties of the shapes:" );
+ Shape[] shapes = [ cast(Shape) c, cast(Shape) s ];
+ foreach ( currentShape; shapes )
+ {
+ writefln( " %s", currentShape.classinfo.name );
+ writefln( " area = %s", currentShape.area() );
+ writefln( " perimeter = %s", currentShape.perimeter() );
+ }
+
+ // Notice how the area() and perimeter() functions really
+ // invoke the appropriate virtual method on each object.
+
+ // ----- Delete everything -----
+ writeln( "\nGuess I'll clean up now:" );
+ // Note: when this using scope is exited the D destructors are called which
+ // in turn call the C++ destructors.
+ }
+
+ writefln( "%s shapes remain", Shape.nshapes );
+ writeln( "\nGoodbye!" );
+}
diff --git a/Examples/d/class/example.cxx b/Examples/d/class/example.cxx
new file mode 100644
index 000000000..1e8e203dd
--- /dev/null
+++ b/Examples/d/class/example.cxx
@@ -0,0 +1,28 @@
+/* File : example.c */
+
+#include "example.h"
+#define M_PI 3.14159265358979323846
+
+/* Move the shape to a new location */
+void Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+int Shape::nshapes = 0;
+
+double Circle::area(void) {
+ return M_PI*radius*radius;
+}
+
+double Circle::perimeter(void) {
+ return 2*M_PI*radius;
+}
+
+double Square::area(void) {
+ return width*width;
+}
+
+double Square::perimeter(void) {
+ return 4*width;
+}
diff --git a/Examples/d/class/example.h b/Examples/d/class/example.h
new file mode 100644
index 000000000..0d4527e92
--- /dev/null
+++ b/Examples/d/class/example.h
@@ -0,0 +1,34 @@
+/* File : example.h */
+
+class Shape {
+public:
+ Shape() {
+ nshapes++;
+ }
+ virtual ~Shape() {
+ nshapes--;
+ };
+ double x, y;
+ void move(double dx, double dy);
+ virtual double area(void) = 0;
+ virtual double perimeter(void) = 0;
+ static int nshapes;
+};
+
+class Circle : public Shape {
+private:
+ double radius;
+public:
+ Circle(double r) : radius(r) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
+
+class Square : public Shape {
+private:
+ double width;
+public:
+ Square(double w) : width(w) { };
+ virtual double area(void);
+ virtual double perimeter(void);
+};
diff --git a/Examples/d/class/example.i b/Examples/d/class/example.i
new file mode 100644
index 000000000..75700b305
--- /dev/null
+++ b/Examples/d/class/example.i
@@ -0,0 +1,10 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+%include "example.h"
+
diff --git a/Examples/d/constants/Makefile b/Examples/d/constants/Makefile
new file mode 100644
index 000000000..ce17134ec
--- /dev/null
+++ b/Examples/d/constants/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ example_wrap.c
+EXTRA_LDFLAGS = example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/constants/d1/runme.d b/Examples/d/constants/d1/runme.d
new file mode 100644
index 000000000..47362cbf3
--- /dev/null
+++ b/Examples/d/constants/d1/runme.d
@@ -0,0 +1,28 @@
+module runme;
+
+import tango.io.Stdout;
+static import example;
+
+void main() {
+ Stdout.formatln("ICONST = {} (should be 42)", example.ICONST);
+ Stdout.formatln("FCONST = {} (should be 2.18)", example.FCONST);
+ Stdout.formatln("CCONST = {} (should be 'x')", example.CCONST);
+ Stdout.formatln("CCONST2 = {} (this should be on a new line)", example.CCONST2);
+ Stdout.formatln("SCONST = {} (should be 'Hello World')", example.SCONST);
+ Stdout.formatln("SCONST2 = {} (should be '\"Hello World\"')", example.SCONST2);
+ Stdout.formatln("EXPR = {} (should be 48.55)", example.EXPR);
+ Stdout.formatln("iconst = {} (should be 37)", example.iconst);
+ Stdout.formatln("fconst = {} (should be 3.14)", example.fconst);
+
+ static if (is(typeof(example.EXTERN))) {
+ Stdout.formatln("EXTERN should not be defined, but is: {}.", example.EXTERN );
+ } else {
+ Stdout.formatln("EXTERN isn't defined (good)");
+ }
+
+ static if (is(typeof(example.FOO))) {
+ Stdout.formatln("FOO should not be defined, but is: {}.", example.FOO);
+ } else {
+ Stdout.formatln("FOO isn't defined (good)");
+ }
+}
diff --git a/Examples/d/constants/d2/runme.d b/Examples/d/constants/d2/runme.d
new file mode 100644
index 000000000..4be510d16
--- /dev/null
+++ b/Examples/d/constants/d2/runme.d
@@ -0,0 +1,28 @@
+module runme;
+
+import std.stdio;
+static import example;
+
+void main() {
+ writefln("ICONST = %s (should be 42)", example.ICONST);
+ writefln("FCONST = %s (should be 2.1828)", example.FCONST);
+ writefln("CCONST = %s (should be 'x')", example.CCONST);
+ writefln("CCONST2 = %s (this should be on a new line)", example.CCONST2);
+ writefln("SCONST = %s (should be 'Hello World')", example.SCONST);
+ writefln("SCONST2 = %s (should be '\"Hello World\"')", example.SCONST2);
+ writefln("EXPR = %s (should be 48.5484)", example.EXPR);
+ writefln("iconst = %s (should be 37)", example.iconst);
+ writefln("fconst = %s (should be 3.14)", example.fconst);
+
+ static if (is(typeof(example.EXTERN))) {
+ writefln("EXTERN should not be defined, but is: %s.", example.EXTERN );
+ } else {
+ writeln("EXTERN isn't defined (good)");
+ }
+
+ static if (is(typeof(example.FOO))) {
+ writefln("FOO should not be defined, but is: %s.", example.FOO);
+ } else {
+ writeln("FOO isn't defined (good)");
+ }
+}
diff --git a/Examples/d/constants/example.d b/Examples/d/constants/example.d
new file mode 100644
index 000000000..7448d0ad9
--- /dev/null
+++ b/Examples/d/constants/example.d
@@ -0,0 +1,23 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.41
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+module example;
+
+static import example_wrap;
+
+static import tango.stdc.stringz;
+
+public const int ICONST = 42;
+public const double FCONST = 2.1828;
+public const char CCONST = 'x';
+public const char CCONST2 = '\n';
+public const char[] SCONST = "Hello World";
+public const char[] SCONST2 = "\"Hello World\"";
+public const double EXPR = 42+3*(2.1828);
+public const int iconst = 37;
+public const double fconst = 3.14;
diff --git a/Examples/d/constants/example.i b/Examples/d/constants/example.i
new file mode 100644
index 000000000..5eb541919
--- /dev/null
+++ b/Examples/d/constants/example.i
@@ -0,0 +1,32 @@
+/* File : example.i */
+%module example
+
+/* Force the generated D code to use the C constant values rather than
+ retrieving them at runtime. You can also try disabling the feature and
+ compare the generated code. */
+%dnativeconst;
+
+
+/* A few preprocessor macros */
+
+#define ICONST 42
+#define FCONST 2.1828
+#define CCONST 'x'
+#define CCONST2 '\n'
+#define SCONST "Hello World"
+#define SCONST2 "\"Hello World\""
+
+/* This should work just fine */
+#define EXPR ICONST + 3*(FCONST)
+
+/* This shouldn't do anything */
+#define EXTERN extern
+
+/* Neither should this (BAR isn't defined) */
+#define FOO (ICONST + BAR)
+
+
+/* The following directives also produce constants */
+
+%constant int iconst = 37;
+%constant double fconst = 3.14;
diff --git a/Examples/d/enum/Makefile b/Examples/d/enum/Makefile
new file mode 100644
index 000000000..bc16dd0fc
--- /dev/null
+++ b/Examples/d/enum/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/enum/d1/runme.d b/Examples/d/enum/d1/runme.d
new file mode 100644
index 000000000..d986986d1
--- /dev/null
+++ b/Examples/d/enum/d1/runme.d
@@ -0,0 +1,28 @@
+module runme;
+
+import tango.io.Stdout;
+import example;
+
+void main() {
+ Stdout( "Printing out some enum values:" ).newline;
+ Stdout(" color:").newline;
+ Stdout.formatln(" {} = {}", color.RED, cast(int)color.RED);
+ Stdout.formatln(" {} = {}", color.BLUE, cast(int)color.BLUE);
+ Stdout.formatln(" {} = {}", color.GREEN, cast(int)color.GREEN);
+
+ Stdout("\n Foo.speed:").newline;
+ Stdout.formatln(" Foo.{} = {}", Foo.speed.IMPULSE, cast(int)Foo.speed.IMPULSE);
+ Stdout.formatln(" Foo.{} = {}", Foo.speed.WARP, cast(int)Foo.speed.WARP);
+ Stdout.formatln(" Foo.{} = {}", Foo.speed.LUDICROUS , cast(int)Foo.speed.LUDICROUS);
+
+ Stdout("\nTesting use of enums with functions:").newline;
+ example.enum_test(color.RED, Foo.speed.IMPULSE);
+ example.enum_test(color.BLUE, Foo.speed.WARP);
+ example.enum_test(color.GREEN, Foo.speed.LUDICROUS);
+
+ Stdout( "\nTesting use of enum with class method:" ).newline;
+ scope f = new Foo();
+ f.enum_test(Foo.speed.IMPULSE);
+ f.enum_test(Foo.speed.WARP);
+ f.enum_test(Foo.speed.LUDICROUS);
+}
diff --git a/Examples/d/enum/d2/runme.d b/Examples/d/enum/d2/runme.d
new file mode 100644
index 000000000..acaec8ae8
--- /dev/null
+++ b/Examples/d/enum/d2/runme.d
@@ -0,0 +1,28 @@
+module runme;
+
+import std.stdio;
+import example;
+
+void main() {
+ writeln( "Printing out some enum values:" );
+ writeln(" color:");
+ writefln(" %s = %s", color.RED, cast(int)color.RED);
+ writefln(" %s = %s", color.BLUE, cast(int)color.BLUE);
+ writefln(" %s = %s", color.GREEN, cast(int)color.GREEN);
+
+ writeln("\n Foo.speed:");
+ writefln(" Foo.%s = %s", Foo.speed.IMPULSE, cast(int)Foo.speed.IMPULSE);
+ writefln(" Foo.%s = %s", Foo.speed.WARP, cast(int)Foo.speed.WARP);
+ writefln(" Foo.%s = %s", Foo.speed.LUDICROUS , cast(int)Foo.speed.LUDICROUS);
+
+ writeln("\nTesting use of enums with functions:");
+ example.enum_test(color.RED, Foo.speed.IMPULSE);
+ example.enum_test(color.BLUE, Foo.speed.WARP);
+ example.enum_test(color.GREEN, Foo.speed.LUDICROUS);
+
+ writeln( "\nTesting use of enum with class method:" );
+ scope f = new Foo();
+ f.enum_test(Foo.speed.IMPULSE);
+ f.enum_test(Foo.speed.WARP);
+ f.enum_test(Foo.speed.LUDICROUS);
+}
diff --git a/Examples/d/enum/example.cxx b/Examples/d/enum/example.cxx
new file mode 100644
index 000000000..df7bb6328
--- /dev/null
+++ b/Examples/d/enum/example.cxx
@@ -0,0 +1,37 @@
+/* File : example.cxx */
+
+#include "example.h"
+#include
+
+void Foo::enum_test(speed s) {
+ if (s == IMPULSE) {
+ printf("IMPULSE speed\n");
+ } else if (s == WARP) {
+ printf("WARP speed\n");
+ } else if (s == LUDICROUS) {
+ printf("LUDICROUS speed\n");
+ } else {
+ printf("Unknown speed\n");
+ }
+}
+
+void enum_test(color c, Foo::speed s) {
+ if (c == RED) {
+ printf("color = RED, ");
+ } else if (c == BLUE) {
+ printf("color = BLUE, ");
+ } else if (c == GREEN) {
+ printf("color = GREEN, ");
+ } else {
+ printf("color = Unknown color!, ");
+ }
+ if (s == Foo::IMPULSE) {
+ printf("speed = IMPULSE speed\n");
+ } else if (s == Foo::WARP) {
+ printf("speed = WARP speed\n");
+ } else if (s == Foo::LUDICROUS) {
+ printf("speed = LUDICROUS speed\n");
+ } else {
+ printf("speed = Unknown speed!\n");
+ }
+}
diff --git a/Examples/d/enum/example.h b/Examples/d/enum/example.h
new file mode 100644
index 000000000..9119cd9fc
--- /dev/null
+++ b/Examples/d/enum/example.h
@@ -0,0 +1,13 @@
+/* File : example.h */
+
+enum color { RED, BLUE, GREEN };
+
+class Foo {
+ public:
+ Foo() { }
+ enum speed { IMPULSE=10, WARP=20, LUDICROUS=30 };
+ void enum_test(speed s);
+};
+
+void enum_test(color c, Foo::speed s);
+
diff --git a/Examples/d/enum/example.i b/Examples/d/enum/example.i
new file mode 100644
index 000000000..23ee8a822
--- /dev/null
+++ b/Examples/d/enum/example.i
@@ -0,0 +1,11 @@
+/* File : example.i */
+%module example
+
+%{
+#include "example.h"
+%}
+
+/* Let's just grab the original header file here */
+
+%include "example.h"
+
diff --git a/Examples/d/extend/Makefile b/Examples/d/extend/Makefile
new file mode 100644
index 000000000..bc16dd0fc
--- /dev/null
+++ b/Examples/d/extend/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.cxx example_wrap.cxx
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d_cpp; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/extend/d1/runme.d b/Examples/d/extend/d1/runme.d
new file mode 100644
index 000000000..96501d1a4
--- /dev/null
+++ b/Examples/d/extend/d1/runme.d
@@ -0,0 +1,75 @@
+/// This file illustrates the cross language polymorphism using directors.
+module runme;
+
+import example;
+import tango.io.Stdout;
+
+// CEO class, which overrides Employee.getPosition().
+class CEO : Manager {
+public:
+ this( char[] name ) {
+ super( name );
+ }
+
+ override char[] getPosition() {
+ return "CEO";
+ }
+
+ // Public method to stop the SWIG proxy base class from thinking it owns the underlying C++ memory.
+ void disownMemory() {
+ swigCMemOwn = false;
+ }
+}
+
+void main() {
+ // Create an instance of CEO, a class derived from the D proxy of the
+ // underlying C++ class. The calls to getName() and getPosition() are standard,
+ // the call to getTitle() uses the director wrappers to call CEO.getPosition().
+
+ auto e = new CEO( "Alice" );
+ Stdout.formatln( "{} is a {}.", e.getName(), e.getPosition() );
+ Stdout.formatln( "Just call her '{}'.", e.getTitle() );
+ Stdout( "----------------------" ).newline;
+
+ {
+ // Create a new EmployeeList instance. This class does not have a C++
+ // director wrapper, but can be used freely with other classes that do.
+ scope auto list = new EmployeeList();
+
+ // EmployeeList owns its items, so we must surrender ownership of objects we add.
+ e.disownMemory();
+ list.addEmployee(e);
+ Stdout( "----------------------" ).newline;
+
+ // Now we access the first four items in list (three are C++ objects that
+ // EmployeeList's constructor adds, the last is our CEO). The virtual
+ // methods of all these instances are treated the same. For items 0, 1, and
+ // 2, all methods resolve in C++. For item 3, our CEO, getTitle calls
+ // getPosition which resolves in D. The call to getPosition is
+ // slightly different, however, because of the overidden getPosition() call, since
+ // now the object reference has been "laundered" by passing through
+ // EmployeeList as an Employee*. Previously, D resolved the call
+ // immediately in CEO, but now D thinks the object is an instance of
+ // class Employee. So the call passes through the
+ // Employee proxy class and on to the C wrappers and C++ director,
+ // eventually ending up back at the D CEO implementation of getPosition().
+ // The call to getTitle() for item 3 runs the C++ Employee::getTitle()
+ // method, which in turn calls getPosition(). This virtual method call
+ // passes down through the C++ director class to the D implementation
+ // in CEO. All this routing takes place transparently.
+
+ Stdout( "(position, title) for items 0-3:" ).newline;
+ Stdout.formatln( " {}, '{}'", list.getItem(0).getPosition(), list.getItem(0).getTitle() );
+ Stdout.formatln( " {}, '{}'", list.getItem(1).getPosition(), list.getItem(1).getTitle() );
+ Stdout.formatln( " {}, '{}'", list.getItem(2).getPosition(), list.getItem(2).getTitle() );
+ Stdout.formatln( " {}, '{}'", list.getItem(3).getPosition(), list.getItem(3).getTitle() );
+ Stdout( "----------------------" ).newline;
+
+ // All Employees will be destroyed when the EmployeeList goes out of scope,
+ // including the CEO instance.
+ }
+ Stdout( "----------------------" ).newline;
+
+ // All done.
+ Stdout( "Exiting cleanly from D code." ).newline;
+}
diff --git a/Examples/d/extend/d2/runme.d b/Examples/d/extend/d2/runme.d
new file mode 100644
index 000000000..1ea6dfd21
--- /dev/null
+++ b/Examples/d/extend/d2/runme.d
@@ -0,0 +1,75 @@
+/// This file illustrates the cross language polymorphism using directors.
+module runme;
+
+import std.stdio;
+import example;
+
+// CEO class, which overrides Employee.getPosition().
+class CEO : Manager {
+public:
+ this( string name ) {
+ super( name );
+ }
+
+ override string getPosition() const {
+ return "CEO";
+ }
+
+ // Public method to stop the SWIG proxy base class from thinking it owns the underlying C++ memory.
+ void disownMemory() {
+ swigCMemOwn = false;
+ }
+}
+
+void main() {
+ // Create an instance of CEO, a class derived from the D proxy of the
+ // underlying C++ class. The calls to getName() and getPosition() are standard,
+ // the call to getTitle() uses the director wrappers to call CEO.getPosition().
+
+ auto e = new CEO( "Alice" );
+ writefln( "%s is a %s.", e.getName(), e.getPosition() );
+ writefln( "Just call her '%s'.", e.getTitle() );
+ writeln( "----------------------" );
+
+ {
+ // Create a new EmployeeList instance. This class does not have a C++
+ // director wrapper, but can be used freely with other classes that do.
+ scope auto list = new EmployeeList();
+
+ // EmployeeList owns its items, so we must surrender ownership of objects we add.
+ e.disownMemory();
+ list.addEmployee(e);
+ writeln( "----------------------" );
+
+ // Now we access the first four items in list (three are C++ objects that
+ // EmployeeList's constructor adds, the last is our CEO). The virtual
+ // methods of all these instances are treated the same. For items 0, 1, and
+ // 2, all methods resolve in C++. For item 3, our CEO, getTitle calls
+ // getPosition which resolves in D. The call to getPosition is
+ // slightly different, however, because of the overidden getPosition() call, since
+ // now the object reference has been "laundered" by passing through
+ // EmployeeList as an Employee*. Previously, D resolved the call
+ // immediately in CEO, but now D thinks the object is an instance of
+ // class Employee. So the call passes through the
+ // Employee proxy class and on to the C wrappers and C++ director,
+ // eventually ending up back at the D CEO implementation of getPosition().
+ // The call to getTitle() for item 3 runs the C++ Employee::getTitle()
+ // method, which in turn calls getPosition(). This virtual method call
+ // passes down through the C++ director class to the D implementation
+ // in CEO. All this routing takes place transparently.
+
+ writeln( "(position, title) for items 0-3:" );
+ writefln( " %s, '%s'", list.getItem(0).getPosition(), list.getItem(0).getTitle() );
+ writefln( " %s, '%s'", list.getItem(1).getPosition(), list.getItem(1).getTitle() );
+ writefln( " %s, '%s'", list.getItem(2).getPosition(), list.getItem(2).getTitle() );
+ writefln( " %s, '%s'", list.getItem(3).getPosition(), list.getItem(3).getTitle() );
+ writeln( "----------------------" );
+
+ // All Employees will be destroyed when the EmployeeList goes out of scope,
+ // including the CEO instance.
+ }
+ writeln( "----------------------" );
+
+ // All done.
+ writeln( "Exiting cleanly from D code." );
+}
diff --git a/Examples/d/extend/example.cxx b/Examples/d/extend/example.cxx
new file mode 100644
index 000000000..450d75608
--- /dev/null
+++ b/Examples/d/extend/example.cxx
@@ -0,0 +1,4 @@
+/* File : example.cxx */
+
+#include "example.h"
+
diff --git a/Examples/d/extend/example.h b/Examples/d/extend/example.h
new file mode 100644
index 000000000..7ad93fbc1
--- /dev/null
+++ b/Examples/d/extend/example.h
@@ -0,0 +1,56 @@
+/* File : example.h */
+
+#include
+#include
+#include
+#include
+#include
+
+class Employee {
+private:
+ std::string name;
+public:
+ Employee(const char* n): name(n) {}
+ virtual std::string getTitle() { return getPosition() + " " + getName(); }
+ virtual std::string getName() { return name; }
+ virtual std::string getPosition() const { return "Employee"; }
+ virtual ~Employee() { printf("~Employee() @ %p\n", this); }
+};
+
+
+class Manager: public Employee {
+public:
+ Manager(const char* n): Employee(n) {}
+ virtual std::string getPosition() const { return "Manager"; }
+};
+
+
+class EmployeeList {
+ std::vector list;
+public:
+ EmployeeList() {
+ list.push_back(new Employee("Bob"));
+ list.push_back(new Employee("Jane"));
+ list.push_back(new Manager("Ted"));
+ }
+ void addEmployee(Employee *p) {
+ list.push_back(p);
+ std::cout << "New employee added. Current employees are:" << std::endl;
+ std::vector::iterator i;
+ for (i=list.begin(); i!=list.end(); i++) {
+ std::cout << " " << (*i)->getTitle() << std::endl;
+ }
+ }
+ const Employee *getItem(int i) {
+ return list[i];
+ }
+ ~EmployeeList() {
+ std::vector::iterator i;
+ std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl;
+ for (i=list.begin(); i!=list.end(); i++) {
+ delete *i;
+ }
+ std::cout << "~EmployeeList empty." << std::endl;
+ }
+};
+
diff --git a/Examples/d/extend/example.i b/Examples/d/extend/example.i
new file mode 100644
index 000000000..0647e1319
--- /dev/null
+++ b/Examples/d/extend/example.i
@@ -0,0 +1,14 @@
+/* File : example.i */
+%module(directors="1") example
+%{
+#include "example.h"
+%}
+
+%include "std_string.i"
+
+/* turn on director wrapping for Manager */
+%feature("director") Employee;
+%feature("director") Manager;
+
+%include "example.h"
+
diff --git a/Examples/d/funcptr/Makefile b/Examples/d/funcptr/Makefile
new file mode 100644
index 000000000..616102926
--- /dev/null
+++ b/Examples/d/funcptr/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.c example_wrap.c
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/funcptr/d1/runme.d b/Examples/d/funcptr/d1/runme.d
new file mode 100644
index 000000000..2947602a5
--- /dev/null
+++ b/Examples/d/funcptr/d1/runme.d
@@ -0,0 +1,34 @@
+module runme;
+
+import tango.io.Stdout;
+static import example;
+
+extern(C) int add(int a, int b) {
+ return a + b;
+}
+
+extern(C) int sub(int a, int b) {
+ return a - b;
+}
+
+extern(C) int mul(int a, int b) {
+ return a * b;
+}
+
+void main() {
+ int a = 37;
+ int b = 42;
+
+ Stdout( "a = " )( a ).newline;
+ Stdout( "b = " )( b ).newline;
+
+ Stdout( "Trying some C callback functions:" ).newline;
+ Stdout( " ADD(a,b) = " )( example.do_op( a, b, example.ADD ) ).newline;
+ Stdout( " SUB(a,b) = " )( example.do_op( a, b, example.SUB ) ).newline;
+ Stdout( " MUL(a,b) = " )( example.do_op( a, b, example.MUL ) ).newline;
+
+ Stdout( "Now the same with callback functions defined in D:" ).newline;
+ Stdout( " add(a,b) = " )( example.do_op( a, b, &add ) ).newline;
+ Stdout( " sub(a,b) = " )( example.do_op( a, b, &sub ) ).newline;
+ Stdout( " mul(a,b) = " )( example.do_op( a, b, &mul ) ).newline;
+}
diff --git a/Examples/d/funcptr/d2/runme.d b/Examples/d/funcptr/d2/runme.d
new file mode 100644
index 000000000..929911d6c
--- /dev/null
+++ b/Examples/d/funcptr/d2/runme.d
@@ -0,0 +1,34 @@
+module runme;
+
+import std.stdio;
+static import example;
+
+extern(C) int add(int a, int b) {
+ return a + b;
+}
+
+extern(C) int sub(int a, int b) {
+ return a - b;
+}
+
+extern(C) int mul(int a, int b) {
+ return a * b;
+}
+
+void main() {
+ int a = 37;
+ int b = 42;
+
+ writefln( "a = %s", a );
+ writefln( "b = %s", b );
+
+ writeln( "Trying some C callback functions:" );
+ writefln( " ADD(a,b) = %s", example.do_op( a, b, example.ADD ) );
+ writefln( " SUB(a,b) = %s", example.do_op( a, b, example.SUB ) );
+ writefln( " MUL(a,b) = %s", example.do_op( a, b, example.MUL ) );
+
+ writeln( "Now the same with callback functions defined in D:" );
+ writefln( " add(a,b) = %s", example.do_op( a, b, &add ) );
+ writefln( " sub(a,b) = %s", example.do_op( a, b, &sub ) );
+ writefln( " mul(a,b) = %s", example.do_op( a, b, &mul ) );
+}
diff --git a/Examples/d/funcptr/example.c b/Examples/d/funcptr/example.c
new file mode 100644
index 000000000..5c4a3dabf
--- /dev/null
+++ b/Examples/d/funcptr/example.c
@@ -0,0 +1,19 @@
+/* File : example.c */
+
+int do_op(int a, int b, int (*op)(int,int)) {
+ return (*op)(a,b);
+}
+
+int add(int a, int b) {
+ return a+b;
+}
+
+int sub(int a, int b) {
+ return a-b;
+}
+
+int mul(int a, int b) {
+ return a*b;
+}
+
+int (*funcvar)(int,int) = add;
diff --git a/Examples/d/funcptr/example.h b/Examples/d/funcptr/example.h
new file mode 100644
index 000000000..9936e24fc
--- /dev/null
+++ b/Examples/d/funcptr/example.h
@@ -0,0 +1,9 @@
+/* file: example.h */
+
+extern int do_op(int,int, int (*op)(int,int));
+extern int add(int,int);
+extern int sub(int,int);
+extern int mul(int,int);
+
+extern int (*funcvar)(int,int);
+
diff --git a/Examples/d/funcptr/example.i b/Examples/d/funcptr/example.i
new file mode 100644
index 000000000..8b3bef678
--- /dev/null
+++ b/Examples/d/funcptr/example.i
@@ -0,0 +1,16 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+/* Wrap a function taking a pointer to a function */
+extern int do_op(int a, int b, int (*op)(int, int));
+
+/* Now install a bunch of "ops" as constants */
+%constant int (*ADD)(int,int) = add;
+%constant int (*SUB)(int,int) = sub;
+%constant int (*MUL)(int,int) = mul;
+
+extern int (*funcvar)(int,int);
+
diff --git a/Examples/d/simple/Makefile b/Examples/d/simple/Makefile
new file mode 100644
index 000000000..312e6a9e9
--- /dev/null
+++ b/Examples/d/simple/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.c example_wrap.c
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/simple/d1/runme.d b/Examples/d/simple/d1/runme.d
new file mode 100644
index 000000000..1293f1839
--- /dev/null
+++ b/Examples/d/simple/d1/runme.d
@@ -0,0 +1,27 @@
+module runme;
+
+import tango.io.Stdout;
+static import example;
+
+void main() {
+ /*
+ * Call our gcd() function.
+ */
+ int x = 42;
+ int y = 105;
+ int g = example.gcd( x, y );
+ Stdout.format( "The gcd of {} and {} is {}.", x, y, g ).newline;
+
+ /*
+ * Manipulate the Foo global variable.
+ */
+
+ // Output its current value
+ Stdout.format( "Foo = {}", example.Foo ).newline;
+
+ // Change its value
+ example.Foo = 3.1415926;
+
+ // See if the change took effect
+ Stdout.format( "Foo = {}", example.Foo ).newline;
+}
diff --git a/Examples/d/simple/d2/runme.d b/Examples/d/simple/d2/runme.d
new file mode 100644
index 000000000..7f278923b
--- /dev/null
+++ b/Examples/d/simple/d2/runme.d
@@ -0,0 +1,27 @@
+module runme;
+
+import std.stdio;
+static import example;
+
+void main() {
+ /*
+ * Call our gcd() function.
+ */
+ int x = 42;
+ int y = 105;
+ int g = example.gcd(x, y);
+ writefln("The gcd of %s and %s is %s.", x, y, g);
+
+ /*
+ * Manipulate the Foo global variable.
+ */
+
+ // Output its current value
+ writefln("Foo = %s", example.Foo);
+
+ // Change its value
+ example.Foo = 3.1415926;
+
+ // See if the change took effect
+ writefln("Foo = %s", example.Foo);
+}
diff --git a/Examples/d/simple/example.c b/Examples/d/simple/example.c
new file mode 100644
index 000000000..1c2af789c
--- /dev/null
+++ b/Examples/d/simple/example.c
@@ -0,0 +1,18 @@
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+
diff --git a/Examples/d/simple/example.i b/Examples/d/simple/example.i
new file mode 100644
index 000000000..24093b9bf
--- /dev/null
+++ b/Examples/d/simple/example.i
@@ -0,0 +1,7 @@
+/* File : example.i */
+%module example
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+%}
diff --git a/Examples/d/variables/Makefile b/Examples/d/variables/Makefile
new file mode 100644
index 000000000..312e6a9e9
--- /dev/null
+++ b/Examples/d/variables/Makefile
@@ -0,0 +1,28 @@
+ifeq (2,$(D_VERSION))
+ WORKING_DIR = d2/
+else
+ WORKING_DIR = d1/
+endif
+
+TOP = ../../..
+SWIG = $(TOP)/../preinst-swig
+EXTRA_CFLAGS = -I../ ../example.c example_wrap.c
+EXTRA_LDFLAGS = example.o example_wrap.o
+TARGET = example_wrap
+SWIGOPT =
+DSRCS = *.d
+DFLAGS = -ofrunme
+
+
+all:: d
+
+d::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile EXTRA_CFLAGS='$(EXTRA_CFLAGS)' EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' SWIG='$(SWIG)' SWIGOPT='$(SWIGOPT) -outcurrentdir ../example.i' TARGET='$(TARGET)' d; \
+ $(MAKE) -f $(TOP)/Makefile DSRCS='$(DSRCS)' DFLAGS='$(DFLAGS)' d_compile
+
+clean::
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_clean
+
+check: all
diff --git a/Examples/d/variables/d1/runme.d b/Examples/d/variables/d1/runme.d
new file mode 100644
index 000000000..35c896bdc
--- /dev/null
+++ b/Examples/d/variables/d1/runme.d
@@ -0,0 +1,71 @@
+// This example illustrates global variable access from C#.
+module runme;
+
+import tango.io.Stdout;
+static import example;
+
+void main() {
+ // Try to set the values of some global variables
+ example.ivar = 42;
+ example.svar = -31000;
+ example.lvar = 65537;
+ example.uivar = 123456;
+ example.usvar = 61000;
+ example.ulvar = 654321;
+ example.scvar = -13;
+ example.ucvar = 251;
+ example.cvar = 'S';
+ example.fvar = 3.14159f;
+ example.dvar = 2.1828;
+ example.strvar = "Hello World";
+ example.iptrvar = example.new_int(37);
+ example.ptptr = example.new_Point(37,42);
+ example.name = "Bill";
+
+ // Now print out the values of the variables
+ Stdout.formatln( "Variables (printed from D):" );
+ Stdout.formatln( "ivar = {}", example.ivar );
+ Stdout.formatln( "svar = {}", example.svar );
+ Stdout.formatln( "lvar = {}", example.lvar );
+ Stdout.formatln( "uivar = {}", example.uivar );
+ Stdout.formatln( "usvar = {}", example.usvar );
+ Stdout.formatln( "ulvar = {}", example.ulvar );
+ Stdout.formatln( "scvar = {}", example.scvar );
+ Stdout.formatln( "ucvar = {}", example.ucvar );
+ Stdout.formatln( "fvar = {}", example.fvar );
+ Stdout.formatln( "dvar = {}", example.dvar );
+ Stdout.formatln( "cvar = {}", example.cvar );
+ Stdout.formatln( "strvar = {}", example.strvar );
+ Stdout.formatln( "cstrvar = {}", example.cstrvar );
+ Stdout.formatln( "iptrvar = {}", example.iptrvar );
+ Stdout.formatln( "name = {}", example.name );
+ Stdout.formatln( "ptptr = {} {}", example.ptptr, example.Point_print(example.ptptr) );
+ Stdout.formatln( "pt = {} {}", example.pt, example.Point_print(example.pt) );
+ Stdout.formatln( "status = {}", example.status );
+
+ Stdout.formatln( "\nVariables (printed from the C library):" );
+ example.print_vars();
+
+ Stdout.formatln( "\nNow I'm going to try and modify some read only variables:" );
+ Stdout.formatln( "Checking that the read only variables are readonly..." );
+
+ Stdout( " 'path'..." );
+ static if ( is( typeof( example.path = "a" ) ) )
+ Stdout.formatln("Oh dear, this variable is not read only!");
+ else
+ Stdout.formatln("Good.");
+
+ Stdout( " 'status'..." );
+ static if ( is( typeof( example.status = 2 ) ) )
+ Stdout.formatln("Oh dear, this variable is not read only!");
+ else
+ Stdout.formatln("Good.");
+
+ Stdout.formatln( "\nI'm going to try and update a structure variable:" );
+
+ example.pt = example.ptptr;
+
+ Stdout( "The new value is " ).flush;
+ example.pt_print();
+ Stdout.formatln( "You should see the value {}", example.Point_print(example.ptptr) );
+}
diff --git a/Examples/d/variables/d2/runme.d b/Examples/d/variables/d2/runme.d
new file mode 100644
index 000000000..f80b81819
--- /dev/null
+++ b/Examples/d/variables/d2/runme.d
@@ -0,0 +1,71 @@
+// This example illustrates global variable access from C#.
+module runme;
+
+import std.stdio;
+static import example;
+
+void main() {
+ // Try to set the values of some global variables
+ example.ivar = 42;
+ example.svar = -31000;
+ example.lvar = 65537;
+ example.uivar = 123456;
+ example.usvar = 61000;
+ example.ulvar = 654321;
+ example.scvar = -13;
+ example.ucvar = 251;
+ example.cvar = 'S';
+ example.fvar = 3.14159f;
+ example.dvar = 2.1828;
+ example.strvar = "Hello World";
+ example.iptrvar = example.new_int(37);
+ example.ptptr = example.new_Point(37,42);
+ example.name = "Bill";
+
+ // Now print out the values of the variables
+ writefln( "Variables (printed from D):" );
+ writefln( "ivar = %s", example.ivar );
+ writefln( "svar = %s", example.svar );
+ writefln( "lvar = %s", example.lvar );
+ writefln( "uivar = %s", example.uivar );
+ writefln( "usvar = %s", example.usvar );
+ writefln( "ulvar = %s", example.ulvar );
+ writefln( "scvar = %s", example.scvar );
+ writefln( "ucvar = %s", example.ucvar );
+ writefln( "fvar = %s", example.fvar );
+ writefln( "dvar = %s", example.dvar );
+ writefln( "cvar = %s", example.cvar );
+ writefln( "strvar = %s", example.strvar );
+ writefln( "cstrvar = %s", example.cstrvar );
+ writefln( "iptrvar = %s", example.iptrvar );
+ writefln( "name = %s", example.name );
+ writefln( "ptptr = %s %s", example.ptptr, example.Point_print(example.ptptr) );
+ writefln( "pt = %s %s", example.pt, example.Point_print(example.pt) );
+ writefln( "status = %s", example.status );
+
+ writefln( "\nVariables (printed from the C library):" );
+ example.print_vars();
+
+ writefln( "\nNow I'm going to try and modify some read only variables:" );
+ writefln( "Checking that the read only variables are readonly..." );
+
+ writeln( " 'path'..." );
+ static if ( is( typeof( example.path = "a" ) ) )
+ writefln("Oh dear, this variable is not read only!");
+ else
+ writefln("Good.");
+
+ writeln( " 'status'..." );
+ static if ( is( typeof( example.status = 2 ) ) )
+ writefln("Oh dear, this variable is not read only!");
+ else
+ writefln("Good.");
+
+ writefln( "\nI'm going to try and update a structure variable:" );
+
+ example.pt = example.ptptr;
+
+ write( "The new value is " );
+ example.pt_print();
+ writefln( "You should see the value %s", example.Point_print(example.ptptr) );
+}
diff --git a/Examples/d/variables/example.c b/Examples/d/variables/example.c
new file mode 100644
index 000000000..1bf9c120f
--- /dev/null
+++ b/Examples/d/variables/example.c
@@ -0,0 +1,91 @@
+/* File : example.c */
+
+/* I'm a file containing some C global variables */
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+#include
+#include
+#include "example.h"
+
+int ivar = 0;
+short svar = 0;
+long lvar = 0;
+unsigned int uivar = 0;
+unsigned short usvar = 0;
+unsigned long ulvar = 0;
+signed char scvar = 0;
+unsigned char ucvar = 0;
+char cvar = 0;
+float fvar = 0;
+double dvar = 0;
+char *strvar = 0;
+const char cstrvar[] = "Goodbye";
+int *iptrvar = 0;
+char name[256] = "Dave";
+char path[256] = "/home/beazley";
+
+
+/* Global variables involving a structure */
+Point *ptptr = 0;
+Point pt = { 10, 20 };
+
+/* A variable that we will make read-only in the interface */
+int status = 1;
+
+/* A debugging function to print out their values */
+
+void print_vars() {
+ printf("ivar = %d\n", ivar);
+ printf("svar = %d\n", svar);
+ printf("lvar = %ld\n", lvar);
+ printf("uivar = %u\n", uivar);
+ printf("usvar = %u\n", usvar);
+ printf("ulvar = %lu\n", ulvar);
+ printf("scvar = %d\n", scvar);
+ printf("ucvar = %u\n", ucvar);
+ printf("fvar = %g\n", fvar);
+ printf("dvar = %g\n", dvar);
+ printf("cvar = %c\n", cvar);
+ printf("strvar = %s\n", strvar ? strvar : "(null)");
+ printf("cstrvar = %s\n", cstrvar ? cstrvar : "(null)");
+ printf("iptrvar = %p\n", iptrvar);
+ printf("name = %s\n", name);
+ printf("ptptr = %p (%d, %d)\n", ptptr, ptptr ? ptptr->x : 0, ptptr ? ptptr->y : 0);
+ printf("pt = (%d, %d)\n", pt.x, pt.y);
+ printf("status = %d\n", status);
+}
+
+/* A function to create an integer (to test iptrvar) */
+
+int *new_int(int value) {
+ int *ip = (int *) malloc(sizeof(int));
+ *ip = value;
+ return ip;
+}
+
+/* A function to create a point */
+
+Point *new_Point(int x, int y) {
+ Point *p = (Point *) malloc(sizeof(Point));
+ p->x = x;
+ p->y = y;
+ return p;
+}
+
+char * Point_print(Point *p) {
+ static char buffer[256];
+ if (p) {
+ sprintf(buffer,"(%d, %d)", p->x,p->y);
+ } else {
+ sprintf(buffer,"null");
+ }
+ return buffer;
+}
+
+void pt_print() {
+ printf("(%d, %d)\n", pt.x, pt.y);
+}
diff --git a/Examples/d/variables/example.h b/Examples/d/variables/example.h
new file mode 100644
index 000000000..0f7e89594
--- /dev/null
+++ b/Examples/d/variables/example.h
@@ -0,0 +1,6 @@
+/* File: example.h */
+
+typedef struct {
+ int x,y;
+} Point;
+
diff --git a/Examples/d/variables/example.i b/Examples/d/variables/example.i
new file mode 100644
index 000000000..591b871ed
--- /dev/null
+++ b/Examples/d/variables/example.i
@@ -0,0 +1,49 @@
+/* File : example.i */
+%module example
+%{
+#include "example.h"
+%}
+
+/* Some global variable declarations */
+%inline %{
+extern int ivar;
+extern short svar;
+extern long lvar;
+extern unsigned int uivar;
+extern unsigned short usvar;
+extern unsigned long ulvar;
+extern signed char scvar;
+extern unsigned char ucvar;
+extern char cvar;
+extern float fvar;
+extern double dvar;
+extern char *strvar;
+extern const char cstrvar[];
+extern int *iptrvar;
+extern char name[256];
+
+extern Point *ptptr;
+extern Point pt;
+%}
+
+
+/* Some read-only variables */
+
+%immutable;
+
+%inline %{
+extern int status;
+extern char path[256];
+%}
+
+%mutable;
+
+/* Some helper functions to make it easier to test */
+%inline %{
+extern void print_vars();
+extern int *new_int(int value);
+extern Point *new_Point(int x, int y);
+extern char *Point_print(Point *p);
+extern void pt_print();
+%}
+
diff --git a/Examples/test-suite/d/Makefile.in b/Examples/test-suite/d/Makefile.in
new file mode 100644
index 000000000..2e9eb827f
--- /dev/null
+++ b/Examples/test-suite/d/Makefile.in
@@ -0,0 +1,80 @@
+#######################################################################
+# Makefile for D test-suite
+#######################################################################
+
+LANGUAGE = d
+srcdir = @srcdir@
+top_srcdir = ../@top_srcdir@
+top_builddir = ../@top_builddir@
+
+ifeq (2,$(D_VERSION))
+ VERSIONSUFFIX = .2
+else
+ VERSIONSUFFIX = .1
+endif
+
+TESTSUFFIX = _runme$(VERSIONSUFFIX).d
+
+CPP_TEST_CASES = \
+ d_nativepointers \
+ exception_partial_info
+
+include $(srcdir)/../common.mk
+
+# Override some variables from common.mk:
+
+TARGETSUFFIX = _wrap
+
+SWIGOPT+=-splitproxy -package $*
+
+# Rules for the different types of tests
+%.cpptest:
+ $(setup)
+ +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_cpp))
+ +$(run_testcase)
+
+%.ctest:
+ $(setup)
+ +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_c))
+ +$(run_testcase)
+
+%.multicpptest:
+ $(setup)
+ +(cd $*$(VERSIONSUFFIX) && $(swig_and_compile_multi_cpp))
+ +$(run_testcase)
+
+# Makes a directory for the testcase if it does not exist
+setup = \
+ if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \
+ echo "$(ACTION)ing testcase $* (with run test) under $(LANGUAGE)" ; \
+ else \
+ echo "$(ACTION)ing testcase $* under $(LANGUAGE)" ; \
+ fi; \
+ if [ ! -d $*$(VERSIONSUFFIX) ]; then \
+ mkdir $*$(VERSIONSUFFIX); \
+ fi; \
+ if [ ! -d $*$(VERSIONSUFFIX)/$* ]; then \
+ mkdir $*$(VERSIONSUFFIX)/$*; \
+ fi
+
+# Compiles D files then runs the testcase. A testcase is only run if
+# a file is found which has _runme.d appended after the testcase name.
+run_testcase = \
+ if [ -f $(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) ]; then \
+ cd $*$(VERSIONSUFFIX) && \
+ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
+ DFLAGS='-of$*_runme' \
+ DSRCS='../$(srcdir)/$(TESTPREFIX)$*$(TESTSUFFIX) $*/*.d' d_compile && \
+ env LD_LIBRARY_PATH=".:$$LD_LIBRARY_PATH" $(RUNTOOL) ./$*_runme; \
+ else \
+ cd $*$(VERSIONSUFFIX) && \
+ $(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile \
+ DFLAGS='-c' \
+ DSRCS='$*/*.d' d_compile && cd .. ; \
+ fi
+
+# Clean: remove testcase directories
+%.clean:
+ @if [ -d $* ]; then \
+ rm -rf $*; \
+ fi
diff --git a/Examples/test-suite/d/README b/Examples/test-suite/d/README
new file mode 100644
index 000000000..bb5372882
--- /dev/null
+++ b/Examples/test-suite/d/README
@@ -0,0 +1,7 @@
+D language module testsuite
+---------------------------
+
+Please see ../README for the common readme file.
+
+By default the D1 version is built, set D_VERSION=2 (in the environment or at
+the make command line) to run it for D2 instead.
diff --git a/Examples/test-suite/d/aggregate_runme.1.d b/Examples/test-suite/d/aggregate_runme.1.d
new file mode 100644
index 000000000..a00d34c25
--- /dev/null
+++ b/Examples/test-suite/d/aggregate_runme.1.d
@@ -0,0 +1,25 @@
+module aggregate_runme;
+
+import aggregate.aggregate;
+
+void main() {
+ // Confirm that move() returns correct results under normal use.
+ int result = move(UP);
+ if (result != UP) throw new Exception("UP failed");
+
+ result = move(DOWN);
+ if (result != DOWN) throw new Exception("DOWN failed");
+
+ result = move(LEFT);
+ if (result != LEFT) throw new Exception("LEFT failed");
+
+ result = move(RIGHT);
+ if (result != RIGHT) throw new Exception("RIGHT failed");
+
+ // Confirm that move() raises an exception when the contract is violated.
+ try {
+ move(0);
+ throw new Exception("0 test failed");
+ }
+ catch (Exception e) {}
+}
diff --git a/Examples/test-suite/d/aggregate_runme.2.d b/Examples/test-suite/d/aggregate_runme.2.d
new file mode 100644
index 000000000..a00d34c25
--- /dev/null
+++ b/Examples/test-suite/d/aggregate_runme.2.d
@@ -0,0 +1,25 @@
+module aggregate_runme;
+
+import aggregate.aggregate;
+
+void main() {
+ // Confirm that move() returns correct results under normal use.
+ int result = move(UP);
+ if (result != UP) throw new Exception("UP failed");
+
+ result = move(DOWN);
+ if (result != DOWN) throw new Exception("DOWN failed");
+
+ result = move(LEFT);
+ if (result != LEFT) throw new Exception("LEFT failed");
+
+ result = move(RIGHT);
+ if (result != RIGHT) throw new Exception("RIGHT failed");
+
+ // Confirm that move() raises an exception when the contract is violated.
+ try {
+ move(0);
+ throw new Exception("0 test failed");
+ }
+ catch (Exception e) {}
+}
diff --git a/Examples/test-suite/d/allprotected_runme.1.d b/Examples/test-suite/d/allprotected_runme.1.d
new file mode 100644
index 000000000..82a180e66
--- /dev/null
+++ b/Examples/test-suite/d/allprotected_runme.1.d
@@ -0,0 +1,65 @@
+module allprotected_runme;
+
+import allprotected.Klass;
+import allprotected.ProtectedBase;
+
+void main() {
+ auto mpb = new MyProtectedBase("MyProtectedBase");
+ mpb.accessProtected();
+}
+
+class MyProtectedBase : ProtectedBase {
+public:
+ this(char[] name) {
+ super(name);
+ }
+
+ void accessProtected() {
+ char[] s = virtualMethod();
+ if (s != "ProtectedBase")
+ throw new Exception("Failed");
+
+ Klass k = instanceMethod(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = instanceOverloaded(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = instanceOverloaded(new Klass("xyz"), "abc");
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ k = staticMethod(new Klass("abc"));
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ k = staticOverloaded(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = staticOverloaded(new Klass("xyz"), "abc");
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ instanceMemberVariable = 30;
+ int i = instanceMemberVariable;
+ if (i != 30)
+ throw new Exception("Failed");
+
+ staticMemberVariable = 40;
+ i = staticMemberVariable;
+ if (i != 40)
+ throw new Exception("Failed");
+
+ i = staticConstMemberVariable;
+ if (i != 20)
+ throw new Exception("Failed");
+
+ anEnum = ProtectedBase.AnEnum.EnumVal1;
+ ProtectedBase.AnEnum ae = anEnum;
+ if (ae != ProtectedBase.AnEnum.EnumVal1)
+ throw new Exception("Failed");
+ }
+}
diff --git a/Examples/test-suite/d/allprotected_runme.2.d b/Examples/test-suite/d/allprotected_runme.2.d
new file mode 100644
index 000000000..799230291
--- /dev/null
+++ b/Examples/test-suite/d/allprotected_runme.2.d
@@ -0,0 +1,65 @@
+module allprotected_runme;
+
+import allprotected.Klass;
+import allprotected.ProtectedBase;
+
+void main() {
+ auto mpb = new MyProtectedBase("MyProtectedBase");
+ mpb.accessProtected();
+}
+
+class MyProtectedBase : ProtectedBase {
+public:
+ this(string name) {
+ super(name);
+ }
+
+ void accessProtected() {
+ string s = virtualMethod();
+ if (s != "ProtectedBase")
+ throw new Exception("Failed");
+
+ Klass k = instanceMethod(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = instanceOverloaded(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = instanceOverloaded(new Klass("xyz"), "abc");
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ k = staticMethod(new Klass("abc"));
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ k = staticOverloaded(new Klass("xyz"));
+ if (k.getName() != "xyz")
+ throw new Exception("Failed");
+
+ k = staticOverloaded(new Klass("xyz"), "abc");
+ if (k.getName() != "abc")
+ throw new Exception("Failed");
+
+ instanceMemberVariable = 30;
+ int i = instanceMemberVariable;
+ if (i != 30)
+ throw new Exception("Failed");
+
+ staticMemberVariable = 40;
+ i = staticMemberVariable;
+ if (i != 40)
+ throw new Exception("Failed");
+
+ i = staticConstMemberVariable;
+ if (i != 20)
+ throw new Exception("Failed");
+
+ anEnum = ProtectedBase.AnEnum.EnumVal1;
+ ProtectedBase.AnEnum ae = anEnum;
+ if (ae != ProtectedBase.AnEnum.EnumVal1)
+ throw new Exception("Failed");
+ }
+}
diff --git a/Examples/test-suite/d/apply_strings_runme.1.d b/Examples/test-suite/d/apply_strings_runme.1.d
new file mode 100644
index 000000000..960caa4ca
--- /dev/null
+++ b/Examples/test-suite/d/apply_strings_runme.1.d
@@ -0,0 +1,12 @@
+module apply_strings_runme;
+
+import apply_strings.apply_strings;
+
+const char[] TEST_MESSAGE = "A message from target language to the C++ world and back again.";
+
+void main() {
+ if (UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed");
+ if (SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed");
+ auto pChar = CharFunction(null);
+ if (pChar !is null) throw new Exception("CharFunction failed");
+}
diff --git a/Examples/test-suite/d/apply_strings_runme.2.d b/Examples/test-suite/d/apply_strings_runme.2.d
new file mode 100644
index 000000000..86183f8a3
--- /dev/null
+++ b/Examples/test-suite/d/apply_strings_runme.2.d
@@ -0,0 +1,12 @@
+module apply_strings_runme;
+
+import apply_strings.apply_strings;
+
+enum string TEST_MESSAGE = "A message from target language to the C++ world and back again.";
+
+void main() {
+ if (UCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("UCharFunction failed");
+ if (SCharFunction(TEST_MESSAGE) != TEST_MESSAGE) throw new Exception("SCharFunction failed");
+ auto pChar = CharFunction(null);
+ if (pChar !is null) throw new Exception("CharFunction failed");
+}
diff --git a/Examples/test-suite/d/bools_runme.1.d b/Examples/test-suite/d/bools_runme.1.d
new file mode 100644
index 000000000..f501b0762
--- /dev/null
+++ b/Examples/test-suite/d/bools_runme.1.d
@@ -0,0 +1,20 @@
+/// This is the bool runtime testcase. It checks that the C++ bool type works.
+module bools_runme;
+
+import bools.bools;
+
+void main() {
+ bool t = true;
+ bool f = false;
+
+ check_bo(f);
+ check_bo(t);
+}
+
+void check_bo(bool input) {
+ for (int i = 0; i < 1000; ++i) {
+ if (bo(input) != input) {
+ throw new Exception("Runtime test check_bo failed.");
+ }
+ }
+}
diff --git a/Examples/test-suite/d/bools_runme.2.d b/Examples/test-suite/d/bools_runme.2.d
new file mode 100644
index 000000000..f501b0762
--- /dev/null
+++ b/Examples/test-suite/d/bools_runme.2.d
@@ -0,0 +1,20 @@
+/// This is the bool runtime testcase. It checks that the C++ bool type works.
+module bools_runme;
+
+import bools.bools;
+
+void main() {
+ bool t = true;
+ bool f = false;
+
+ check_bo(f);
+ check_bo(t);
+}
+
+void check_bo(bool input) {
+ for (int i = 0; i < 1000; ++i) {
+ if (bo(input) != input) {
+ throw new Exception("Runtime test check_bo failed.");
+ }
+ }
+}
diff --git a/Examples/test-suite/d/catches_runme.1.d b/Examples/test-suite/d/catches_runme.1.d
new file mode 100644
index 000000000..55b18132d
--- /dev/null
+++ b/Examples/test-suite/d/catches_runme.1.d
@@ -0,0 +1,33 @@
+module catches_runme;
+
+import catches.catches;
+
+void main() {
+ test({ test_catches(1); }, "C++ int exception thrown, value: 1");
+ test({ test_catches(2); }, "two");
+ test({ test_catches(3); }, "C++ ThreeException const & exception thrown");
+
+ test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1");
+ test({ test_exception_specification(2); }, "unknown exception");
+ test({ test_exception_specification(3); }, "unknown exception");
+
+ test({ test_catches_all(1); }, "unknown exception");
+}
+
+void test(void delegate() command, char[] expectedMessage) {
+ bool didntThrow;
+ try {
+ command();
+ didntThrow = true;
+ } catch (Exception e) {
+ if (e.msg != expectedMessage) {
+ throw new Exception("Failed to propagate C++ exception. Expected '" ~
+ expectedMessage ~ "', but received '" ~ e.msg ~ "'.");
+ }
+ }
+
+ if (didntThrow) {
+ throw new Exception("Failed to propagate C++ exception. Expected '" ~
+ expectedMessage ~ "', but no exception was thrown.");
+ }
+}
diff --git a/Examples/test-suite/d/catches_runme.2.d b/Examples/test-suite/d/catches_runme.2.d
new file mode 100644
index 000000000..508558485
--- /dev/null
+++ b/Examples/test-suite/d/catches_runme.2.d
@@ -0,0 +1,33 @@
+module catches_runme;
+
+import catches.catches;
+
+void main() {
+ test({ test_catches(1); }, "C++ int exception thrown, value: 1");
+ test({ test_catches(2); }, "two");
+ test({ test_catches(3); }, "C++ ThreeException const & exception thrown");
+
+ test({ test_exception_specification(1); }, "C++ int exception thrown, value: 1");
+ test({ test_exception_specification(2); }, "unknown exception");
+ test({ test_exception_specification(3); }, "unknown exception");
+
+ test({ test_catches_all(1); }, "unknown exception");
+}
+
+void test(void delegate() command, string expectedMessage) {
+ bool didntThrow;
+ try {
+ command();
+ didntThrow = true;
+ } catch (Exception e) {
+ if (e.msg != expectedMessage) {
+ throw new Exception("Failed to propagate C++ exception. Expected '" ~
+ expectedMessage ~ "', but received '" ~ e.msg ~ "'.");
+ }
+ }
+
+ if (didntThrow) {
+ throw new Exception("Failed to propagate C++ exception. Expected '" ~
+ expectedMessage ~ "', but no exception was thrown.");
+ }
+}
diff --git a/Examples/test-suite/d/char_strings_runme.1.d b/Examples/test-suite/d/char_strings_runme.1.d
new file mode 100644
index 000000000..cde6fe0f7
--- /dev/null
+++ b/Examples/test-suite/d/char_strings_runme.1.d
@@ -0,0 +1,151 @@
+module char_strings_runme;
+
+import tango.text.convert.Integer;
+import char_strings.char_strings;
+
+const char[] CPLUSPLUS_MSG = "A message from the deep dark world of C++, where anything is possible.";
+const char[] OTHERLAND_MSG = "Little message from the safe world.";
+
+void main() {
+ const uint count = 10000;
+ uint i = 0;
+
+ // get functions
+ for (i=0; i STARTED <---").newline;
+
+ debug_shared=TRACE;
+
+ // Change loop count to run for a long time to monitor memory
+ const int LOOP_COUNT = 1; // 50000;
+ for (int i = 0; i < LOOP_COUNT; ++i) {
+ runTest();
+ GC.collect();
+ }
+
+ if (TRACE)
+ Stdout("---> NEARLY FINISHED <---").newline;
+
+ // Try to get the GC to collect everything not referenced anymore.
+ int countdown = 100;
+ while (--countdown) {
+ GC.collect();
+ if (Klass.getTotal_count() == 1)
+ break;
+ Thread.sleep(0.01);
+ }
+
+ // A single remaining instance expected: the global variable (GlobalValue).
+ if (Klass.getTotal_count() != 1)
+ throw new Exception("Klass.total_count=" ~ toString(Klass.getTotal_count()));
+
+ // A single remaining instance expected: the global variable (GlobalSmartValue).
+ int wrapper_count = shared_ptr_wrapper_count();
+ if (wrapper_count != NOT_COUNTING)
+ if (wrapper_count != 1)
+ throw new Exception("shared_ptr wrapper count=" ~ toString(wrapper_count));
+
+ if (TRACE)
+ Stdout("---> FINISHED <---").newline;
+}
+
+void runTest() {
+ // simple shared_ptr usage - created in C++
+ {
+ auto k = new Klass("me oh my");
+ char[] val = k.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(1, k);
+ }
+
+ // simple shared_ptr usage - not created in C++
+ {
+ auto k = factorycreate();
+ char[] val = k.getValue();
+ verifyValue("factorycreate", val);
+ verifyCount(1, k);
+ }
+
+ // pass by shared_ptr
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointertest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerpointertest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerreftest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr pointer reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerpointerreftest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointerpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by value
+ {
+ auto k = new Klass("me oh my");
+ auto kret = valuetest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my valuetest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = pointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my pointertest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = reftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my reftest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = pointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my pointerreftest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // null tests
+ {
+ Klass k = null;
+
+ // TODO: add in const versions too
+ if (smartpointertest(k) !is null)
+ throw new Exception("return was not null");
+
+ if (smartpointerpointertest(k) !is null)
+ throw new Exception("return was not null");
+
+ if (smartpointerreftest(k) !is null)
+ throw new Exception("return was not null");
+
+ if (smartpointerpointerreftest(k) !is null)
+ throw new Exception("return was not null");
+
+ if (nullsmartpointerpointertest(null) != "null pointer")
+ throw new Exception("not null smartpointer pointer");
+
+ try { valuetest(k); throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {}
+
+ if (pointertest(k) !is null)
+ throw new Exception("return was not null");
+
+ try { reftest(k); throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {}
+ }
+
+ // $owner
+ {
+ auto k = pointerownertest();
+ char[] val = k.getValue();
+ verifyValue("pointerownertest", val);
+ verifyCount(1, k);
+ }
+ {
+ auto k = smartpointerpointerownertest();
+ char[] val = k.getValue();
+ verifyValue("smartpointerpointerownertest", val);
+ verifyCount(1, k);
+ }
+
+ ////////////////////////////////// Derived classes ////////////////////////////////////////
+ // derived pass by shared_ptr
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrtest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrtest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr pointer
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrpointertest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrreftest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr pointer ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by pointer
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedpointertest-Derived", val);
+ verifyCount(2, k); // includes an extra reference for the upcast in the proxy class
+ verifyCount(2, kret);
+ }
+ // derived pass by ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my derivedreftest-Derived", val);
+ verifyCount(2, k); // includes an extra reference for the upcast in the proxy class
+ verifyCount(2, kret);
+ }
+
+ ////////////////////////////////// Derived and base class mixed ////////////////////////////////////////
+ // pass by shared_ptr (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointertest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr pointer (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerpointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerpointertest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr reference (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerreftest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr pointer reference (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerpointerreftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my smartpointerpointerreftest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by value (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = valuetest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my valuetest", val); // note slicing
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = pointertest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my pointertest-Derived", val);
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // pass by ref (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = reftest(k);
+ char[] val = kret.getValue();
+ verifyValue("me oh my reftest-Derived", val);
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // 3rd derived class
+ {
+ auto k = new Klass3rdDerived("me oh my");
+ char[] val = k.getValue();
+ verifyValue("me oh my-3rdDerived", val);
+ verifyCount(3, k); // 3 classes in inheritance chain == 3 swigCPtr values
+ val = test3rdupcast(k);
+ verifyValue("me oh my-3rdDerived", val);
+ verifyCount(3, k);
+ }
+
+ ////////////////////////////////// Member variables ////////////////////////////////////////
+ // smart pointer by value
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member value");
+ m.SmartMemberValue = k;
+ char[] val = k.getValue();
+ verifyValue("smart member value", val);
+ verifyCount(2, k);
+
+ auto kmember = m.SmartMemberValue;
+ val = kmember.getValue();
+ verifyValue("smart member value", val);
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+
+ delete m;
+
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+ }
+ // smart pointer by pointer
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member pointer");
+ m.SmartMemberPointer = k;
+ char[] val = k.getValue();
+ verifyValue("smart member pointer", val);
+ verifyCount(1, k);
+
+ auto kmember = m.SmartMemberPointer;
+ val = kmember.getValue();
+ verifyValue("smart member pointer", val);
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+
+ delete m;
+
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+ }
+ // smart pointer by reference
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member reference");
+ m.SmartMemberReference = k;
+ char[] val = k.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(2, k);
+
+ auto kmember = m.SmartMemberReference;
+ val = kmember.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+
+ // The C++ reference refers to SmartMemberValue...
+ auto kmemberVal = m.SmartMemberValue;
+ val = kmember.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(4, kmemberVal);
+ verifyCount(4, kmember);
+ verifyCount(4, k);
+
+ delete m;
+
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+ }
+ // plain by value
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member value");
+ m.MemberValue = k;
+ char[] val = k.getValue();
+ verifyValue("plain member value", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberValue;
+ val = kmember.getValue();
+ verifyValue("plain member value", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+ // plain by pointer
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member pointer");
+ m.MemberPointer = k;
+ char[] val = k.getValue();
+ verifyValue("plain member pointer", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberPointer;
+ val = kmember.getValue();
+ verifyValue("plain member pointer", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+ // plain by reference
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member reference");
+ m.MemberReference = k;
+ char[] val = k.getValue();
+ verifyValue("plain member reference", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberReference;
+ val = kmember.getValue();
+ verifyValue("plain member reference", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+
+ // null member variables
+ {
+ auto m = new MemberVariables();
+
+ // shared_ptr by value
+ auto k = m.SmartMemberValue;
+ if (k !is null)
+ throw new Exception("expected null");
+ m.SmartMemberValue = null;
+ k = m.SmartMemberValue;
+ if (k !is null)
+ throw new Exception("expected null");
+ verifyCount(0, k);
+
+ // plain by value
+ try { m.MemberValue = null; throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {}
+ }
+
+ ////////////////////////////////// Global variables ////////////////////////////////////////
+ // smart pointer
+ {
+ auto kglobal = GlobalSmartValue;
+ if (kglobal !is null)
+ throw new Exception("expected null");
+
+ auto k = new Klass("smart global value");
+ GlobalSmartValue = k;
+ verifyCount(2, k);
+
+ kglobal = GlobalSmartValue;
+ char[] val = kglobal.getValue();
+ verifyValue("smart global value", val);
+ verifyCount(3, kglobal);
+ verifyCount(3, k);
+ verifyValue("smart global value", GlobalSmartValue.getValue());
+ GlobalSmartValue = null;
+ }
+ // plain value
+ {
+ Klass kglobal;
+
+ auto k = new Klass("global value");
+ GlobalValue = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalValue;
+ char[] val = kglobal.getValue();
+ verifyValue("global value", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+ verifyValue("global value", GlobalValue.getValue());
+
+ try { GlobalValue = null; throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {}
+ }
+ // plain pointer
+ {
+ auto kglobal = GlobalPointer;
+ if (kglobal !is null)
+ throw new Exception("expected null");
+
+ auto k = new Klass("global pointer");
+ GlobalPointer = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalPointer;
+ char[] val = kglobal.getValue();
+ verifyValue("global pointer", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+ GlobalPointer = null;
+ }
+ // plain reference
+ {
+ Klass kglobal;
+
+ auto k = new Klass("global reference");
+ GlobalReference = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalReference;
+ char[] val = kglobal.getValue();
+ verifyValue("global reference", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+
+ try { GlobalReference = null; throw new Exception("Failed to catch null pointer"); } catch (IllegalArgumentException) {}
+ }
+
+ ////////////////////////////////// Templates ////////////////////////////////////////
+ {
+ PairIntDouble pid = new PairIntDouble(10, 20.2);
+ if (pid.baseVal1 != 20 || pid.baseVal2 != 40.4)
+ throw new Exception("Base values wrong");
+ if (pid.val1 != 10 || pid.val2 != 20.2)
+ throw new Exception("Derived Values wrong");
+ }
+}
+
+private void verifyValue(char[] expected, char[] got) {
+ if (expected != got)
+ throw new Exception("verify value failed. Expected: " ~ expected ~ " Got: " ~ got);
+}
+
+private void verifyCount(int expected, Klass k) {
+ // We deliberately call the use_count(Klass) overload also for objects which
+ // are instances of a subclass of Klass (due to static dispatch); things still
+ // have to work.
+ int got = use_count(k);
+ if (expected != got)
+ throw new Exception("verify use_count failed. Expected: " ~ toString(expected) ~ " Got: " ~ toString(got));
+}
diff --git a/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d b/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d
new file mode 100644
index 000000000..773ae74d5
--- /dev/null
+++ b/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d
@@ -0,0 +1,602 @@
+module li_boost_shared_ptr_runme;
+
+import core.memory;
+import core.thread;
+import std.conv;
+import std.exception;
+import std.stdio;
+import li_boost_shared_ptr.li_boost_shared_ptr;
+import li_boost_shared_ptr.Klass;
+import li_boost_shared_ptr.KlassDerived;
+import li_boost_shared_ptr.Klass3rdDerived;
+import li_boost_shared_ptr.MemberVariables;
+import li_boost_shared_ptr.PairIntDouble;
+
+// Debugging flag
+enum TRACE = false;
+
+void main() {
+ if (TRACE)
+ writeln("---> STARTED <---");
+
+ debug_shared = TRACE;
+
+ // Change loop count to run for a long time to monitor memory
+ enum LOOP_COUNT = 1; // 50000;
+ for (int i = 0; i < LOOP_COUNT; ++i) {
+ runTest();
+ GC.collect();
+ }
+
+ if (TRACE)
+ writeln("---> NEARLY FINISHED <---");
+
+ // Try to get the GC to collect everything not referenced anymore.
+ int countdown = 100;
+ while (--countdown) {
+ GC.collect();
+ if (Klass.getTotal_count() == 1)
+ break;
+ Thread.sleep(100);
+ }
+
+ // A single remaining instance expected: the global variable (GlobalValue).
+ if (Klass.getTotal_count() != 1)
+ throw new Exception("Klass.total_count=" ~ to!string(Klass.getTotal_count()));
+
+ // A single remaining instance expected: the global variable (GlobalSmartValue).
+ int wrapper_count = shared_ptr_wrapper_count();
+ if (wrapper_count != NOT_COUNTING)
+ if (wrapper_count != 1)
+ throw new Exception("shared_ptr wrapper count=" ~ to!string(wrapper_count));
+
+ if (TRACE)
+ writeln("---> FINISHED <---");
+}
+
+void runTest() {
+ // simple shared_ptr usage - created in C++
+ {
+ auto k = new Klass("me oh my");
+ string val = k.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(1, k);
+ }
+
+ // simple shared_ptr usage - not created in C++
+ {
+ auto k = factorycreate();
+ string val = k.getValue();
+ verifyValue("factorycreate", val);
+ verifyCount(1, k);
+ }
+
+ // pass by shared_ptr
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointertest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerpointertest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerreftest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by shared_ptr pointer reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = smartpointerpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerpointerreftest", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointerpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // const pass by shared_ptr reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = constsmartpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my", val);
+ verifyCount(2, k);
+ verifyCount(2, kret);
+ }
+
+ // pass by value
+ {
+ auto k = new Klass("me oh my");
+ auto kret = valuetest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my valuetest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer
+ {
+ auto k = new Klass("me oh my");
+ auto kret = pointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my pointertest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = reftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my reftest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer reference
+ {
+ auto k = new Klass("me oh my");
+ auto kret = pointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my pointerreftest", val);
+ verifyCount(1, k);
+ verifyCount(1, kret);
+ }
+
+ // null tests
+ {
+ Klass k = null;
+
+ // TODO: add in const versions too
+ enforce(smartpointertest(k) is null, "return was not null");
+ enforce(smartpointerpointertest(k) is null, "return was not null");
+ enforce(smartpointerreftest(k) is null, "return was not null");
+ enforce(smartpointerpointerreftest(k) is null, "return was not null");
+ enforce(nullsmartpointerpointertest(null) == "null pointer",
+ "not null smartpointer pointer");
+
+ enforceThrows( (){ valuetest(k); }, "Failed to catch null pointer");
+ enforce(pointertest(k) is null, "return was not null");
+ enforceThrows( (){ reftest(k); }, "Failed to catch null pointer");
+ }
+
+ // $owner
+ {
+ auto k = pointerownertest();
+ string val = k.getValue();
+ verifyValue("pointerownertest", val);
+ verifyCount(1, k);
+ }
+ {
+ auto k = smartpointerpointerownertest();
+ string val = k.getValue();
+ verifyValue("smartpointerpointerownertest", val);
+ verifyCount(1, k);
+ }
+
+ ////////////////////////////////// Derived classes ////////////////////////////////////////
+ // derived pass by shared_ptr
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrtest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrtest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr pointer
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrpointertest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrreftest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by shared_ptr pointer ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedsmartptrpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedsmartptrpointerreftest-Derived", val);
+ verifyCount(4, k); // includes two extra references for upcasts in the proxy classes
+ verifyCount(4, kret);
+ }
+ // derived pass by pointer
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedpointertest-Derived", val);
+ verifyCount(2, k); // includes an extra reference for the upcast in the proxy class
+ verifyCount(2, kret);
+ }
+ // derived pass by ref
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = derivedreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my derivedreftest-Derived", val);
+ verifyCount(2, k); // includes an extra reference for the upcast in the proxy class
+ verifyCount(2, kret);
+ }
+
+ ////////////////////////////////// Derived and base class mixed ////////////////////////////////////////
+ // pass by shared_ptr (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointertest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr pointer (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerpointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerpointertest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr reference (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerreftest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by shared_ptr pointer reference (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = smartpointerpointerreftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my smartpointerpointerreftest-Derived", val);
+ verifyCount(3, k); // an extra reference for the upcast in the proxy class
+ verifyCount(3, kret);
+ }
+
+ // pass by value (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = valuetest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my valuetest", val); // note slicing
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // pass by pointer (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = pointertest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my pointertest-Derived", val);
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // pass by ref (mixed)
+ {
+ auto k = new KlassDerived("me oh my");
+ auto kret = reftest(k);
+ string val = kret.getValue();
+ verifyValue("me oh my reftest-Derived", val);
+ verifyCount(2, k); // an extra reference for the upcast in the proxy class
+ verifyCount(1, kret);
+ }
+
+ // 3rd derived class
+ {
+ auto k = new Klass3rdDerived("me oh my");
+ string val = k.getValue();
+ verifyValue("me oh my-3rdDerived", val);
+ verifyCount(3, k); // 3 classes in inheritance chain == 3 swigCPtr values
+ val = test3rdupcast(k);
+ verifyValue("me oh my-3rdDerived", val);
+ verifyCount(3, k);
+ }
+
+ ////////////////////////////////// Member variables ////////////////////////////////////////
+ // smart pointer by value
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member value");
+ m.SmartMemberValue = k;
+ string val = k.getValue();
+ verifyValue("smart member value", val);
+ verifyCount(2, k);
+
+ auto kmember = m.SmartMemberValue;
+ val = kmember.getValue();
+ verifyValue("smart member value", val);
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+
+ delete m;
+
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+ }
+ // smart pointer by pointer
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member pointer");
+ m.SmartMemberPointer = k;
+ string val = k.getValue();
+ verifyValue("smart member pointer", val);
+ verifyCount(1, k);
+
+ auto kmember = m.SmartMemberPointer;
+ val = kmember.getValue();
+ verifyValue("smart member pointer", val);
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+
+ delete m;
+
+ verifyCount(2, kmember);
+ verifyCount(2, k);
+ }
+ // smart pointer by reference
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("smart member reference");
+ m.SmartMemberReference = k;
+ string val = k.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(2, k);
+
+ auto kmember = m.SmartMemberReference;
+ val = kmember.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+
+ // The C++ reference refers to SmartMemberValue...
+ auto kmemberVal = m.SmartMemberValue;
+ val = kmember.getValue();
+ verifyValue("smart member reference", val);
+ verifyCount(4, kmemberVal);
+ verifyCount(4, kmember);
+ verifyCount(4, k);
+
+ delete m;
+
+ verifyCount(3, kmember);
+ verifyCount(3, k);
+ }
+ // plain by value
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member value");
+ m.MemberValue = k;
+ string val = k.getValue();
+ verifyValue("plain member value", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberValue;
+ val = kmember.getValue();
+ verifyValue("plain member value", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+ // plain by pointer
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member pointer");
+ m.MemberPointer = k;
+ string val = k.getValue();
+ verifyValue("plain member pointer", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberPointer;
+ val = kmember.getValue();
+ verifyValue("plain member pointer", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+ // plain by reference
+ {
+ auto m = new MemberVariables();
+ auto k = new Klass("plain member reference");
+ m.MemberReference = k;
+ string val = k.getValue();
+ verifyValue("plain member reference", val);
+ verifyCount(1, k);
+
+ auto kmember = m.MemberReference;
+ val = kmember.getValue();
+ verifyValue("plain member reference", val);
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+
+ delete m;
+
+ verifyCount(1, kmember);
+ verifyCount(1, k);
+ }
+
+ // null member variables
+ {
+ auto m = new MemberVariables();
+
+ // shared_ptr by value
+ auto k = m.SmartMemberValue;
+ if (k !is null)
+ throw new Exception("expected null");
+ m.SmartMemberValue = null;
+ k = m.SmartMemberValue;
+ if (k !is null)
+ throw new Exception("expected null");
+ verifyCount(0, k);
+
+ // plain by value
+ enforceThrows( (){ m.MemberValue = null; }, "Failed to catch null pointer");
+ }
+
+ ////////////////////////////////// Global variables ////////////////////////////////////////
+ // smart pointer
+ {
+ auto kglobal = GlobalSmartValue;
+ enforce(kglobal is null, "expected null");
+
+ auto k = new Klass("smart global value");
+ GlobalSmartValue = k;
+ verifyCount(2, k);
+
+ kglobal = GlobalSmartValue;
+ string val = kglobal.getValue();
+ verifyValue("smart global value", val);
+ verifyCount(3, kglobal);
+ verifyCount(3, k);
+ verifyValue("smart global value", GlobalSmartValue.getValue());
+ GlobalSmartValue = null;
+ }
+ // plain value
+ {
+ Klass kglobal;
+
+ auto k = new Klass("global value");
+ GlobalValue = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalValue;
+ string val = kglobal.getValue();
+ verifyValue("global value", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+ verifyValue("global value", GlobalValue.getValue());
+
+ enforceThrows((){ GlobalValue = null; }, "Failed to catch null pointer");
+ }
+ // plain pointer
+ {
+ auto kglobal = GlobalPointer;
+ enforce(kglobal is null, "expected null");
+
+ auto k = new Klass("global pointer");
+ GlobalPointer = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalPointer;
+ string val = kglobal.getValue();
+ verifyValue("global pointer", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+ GlobalPointer = null;
+ }
+ // plain reference
+ {
+ Klass kglobal;
+
+ auto k = new Klass("global reference");
+ GlobalReference = k;
+ verifyCount(1, k);
+
+ kglobal = GlobalReference;
+ string val = kglobal.getValue();
+ verifyValue("global reference", val);
+ verifyCount(1, kglobal);
+ verifyCount(1, k);
+
+ enforceThrows((){ GlobalReference = null; }, "Failed to catch null pointer");
+ }
+
+ ////////////////////////////////// Templates ////////////////////////////////////////
+ {
+ auto pid = new PairIntDouble(10, 20.2);
+ enforce(pid.baseVal1 == 20 && pid.baseVal2== 40.4, "Base values wrong");
+ enforce(pid.val1 == 10 && pid.val2 == 20.2, "Derived Values wrong");
+ }
+}
+
+private void verifyValue(string expected, string got) {
+ if (expected != got)
+ throw new Exception("verify value failed. Expected: " ~ expected ~ " Got: " ~ got);
+}
+
+private void verifyCount(int expected, Klass k) {
+ // We deliberately call the use_count(Klass) overload also for objects which
+ // are instances of a subclass of Klass (due to static dispatch); things still
+ // have to work.
+ int got = use_count(k);
+ if (expected != got)
+ throw new Exception("verify use_count failed. Expected: " ~ to!string(expected) ~ " Got: " ~ to!string(got));
+}
+
+private void enforceThrows(void delegate() dg, string errorMessage) {
+ bool hasThrown;
+ try {
+ dg();
+ } catch (Exception) {
+ hasThrown = true;
+ } finally {
+ if (!hasThrown) {
+ throw new Exception(errorMessage);
+ }
+ }
+}
diff --git a/Examples/test-suite/d/li_std_except_runme.1.d b/Examples/test-suite/d/li_std_except_runme.1.d
new file mode 100644
index 000000000..39f3bb202
--- /dev/null
+++ b/Examples/test-suite/d/li_std_except_runme.1.d
@@ -0,0 +1,40 @@
+module li_std_except_runme;
+
+import tango.core.Exception;
+import tango.io.Console;
+import li_std_except.Test;
+
+void main() {
+ with (new Test()) {
+ mixin(test("Exception", "throw_bad_exception"));
+ mixin(test("Exception", "throw_domain_error"));
+ mixin(test("Exception", "throw_exception"));
+ mixin(test("IllegalArgumentException", "throw_invalid_argument"));
+ mixin(test("NoSuchElementException", "throw_length_error"));
+ mixin(test("Exception", "throw_logic_error"));
+ mixin(test("NoSuchElementException", "throw_out_of_range"));
+ mixin(test("Exception", "throw_overflow_error"));
+ mixin(test("Exception", "throw_range_error"));
+ mixin(test("Exception", "throw_runtime_error"));
+ mixin(test("Exception", "throw_underflow_error"));
+ }
+}
+
+char[] test(char[] e, char[] f) {
+ return "if (!works!(" ~ e ~ ")(&" ~ f ~ ")) {\n" ~
+ "throw new Exception(\"" ~ f ~ " failed\");\n" ~
+ "}";
+}
+
+bool works(alias E, F)(F f) {
+ try {
+ try {
+ f();
+ } catch(E) {
+ return true;
+ }
+ } catch(Exception e) {
+ Cerr( "Received wrong exception: " ~ e.classinfo.name ).newline;
+ }
+ return false;
+}
diff --git a/Examples/test-suite/d/li_std_except_runme.2.d b/Examples/test-suite/d/li_std_except_runme.2.d
new file mode 100644
index 000000000..f2b4b672c
--- /dev/null
+++ b/Examples/test-suite/d/li_std_except_runme.2.d
@@ -0,0 +1,34 @@
+module li_std_except_runme;
+
+import std.exception;
+import std.stdio;
+import li_std_except.Test;
+
+void main() {
+ with (new Test()) {
+ enforce(works!(Exception)(&throw_bad_exception));
+ enforce(works!(Exception)(&throw_domain_error));
+ enforce(works!(Exception)(&throw_exception));
+ enforce(works!(Exception)(&throw_invalid_argument));
+ enforce(works!(Exception)(&throw_length_error));
+ enforce(works!(Exception)(&throw_logic_error));
+ enforce(works!(Exception)(&throw_out_of_range));
+ enforce(works!(Exception)(&throw_overflow_error));
+ enforce(works!(Exception)(&throw_range_error));
+ enforce(works!(Exception)(&throw_runtime_error));
+ enforce(works!(Exception)(&throw_underflow_error));
+ }
+}
+
+bool works(alias E, F)(F f) {
+ try {
+ try {
+ f();
+ } catch(E) {
+ return true;
+ }
+ } catch(Exception e) {
+ writefln( "Received wrong exception: %s", e.classinfo.name );
+ }
+ return false;
+}
diff --git a/Examples/test-suite/d/li_std_string_runme.1.d b/Examples/test-suite/d/li_std_string_runme.1.d
new file mode 100644
index 000000000..b5bbb51c0
--- /dev/null
+++ b/Examples/test-suite/d/li_std_string_runme.1.d
@@ -0,0 +1,97 @@
+module li_std_string_runme;
+
+import tango.core.Exception;
+import li_std_string.li_std_string;
+import li_std_string.Structure;
+import li_std_string.SWIGTYPE_p_std__string;
+
+
+void main() {
+ // Checking expected use of %typemap(in) std::string {}
+ test_value("Fee");
+
+ // Checking expected result of %typemap(out) std::string {}
+ if (test_value("Fi") != "Fi")
+ throw new Exception("Test 1 failed");
+
+ // Verify type-checking for %typemap(in) std::string {}
+ try {
+ test_value(null);
+ throw new Exception("Test 2 failed");
+ } catch (IllegalArgumentException) {
+ }
+
+ // Checking expected use of %typemap(in) const std::string & {}
+ test_const_reference("Fo");
+
+ // Checking expected result of %typemap(out) const std::string& {}
+ if (test_const_reference("Fum") != "Fum")
+ throw new Exception("Test 3 failed");
+
+ // Verify type-checking for %typemap(in) const std::string & {}
+ try {
+ test_const_reference(null);
+ throw new Exception("Test 4 failed");
+ } catch (IllegalArgumentException) {
+ }
+
+ // Input and output typemaps for pointers and non-const references to
+ // std::string are *not* supported; the following tests confirm
+ // that none of these cases are slipping through.
+
+ SWIGTYPE_p_std__string stringPtr = null;
+
+ stringPtr = test_pointer_out();
+ test_pointer(stringPtr);
+
+ stringPtr = test_const_pointer_out();
+ test_const_pointer(stringPtr);
+
+ stringPtr = test_reference_out();
+ test_reference(stringPtr);
+
+ // Check throw exception specification
+ try {
+ test_throw();
+ throw new Exception("test 5 failed!");
+ } catch (Exception e) {
+ if (e.msg != "test_throw message")
+ throw new Exception("Test 5 string check: " ~ e.msg);
+ }
+ try {
+ test_const_reference_throw();
+ throw new Exception("test 6 failed!");
+ } catch (Exception e) {
+ if (e.msg != "test_const_reference_throw message")
+ throw new Exception("Test 6 string check: " ~ e.msg);
+ }
+
+ // Global variables.
+ const char[] s = "initial string";
+ if (GlobalString2 != "global string 2")
+ throw new Exception("GlobalString2 test 1");
+ GlobalString2 = s;
+ if (GlobalString2 != s)
+ throw new Exception("GlobalString2 test 2");
+ if (ConstGlobalString != "const global string")
+ throw new Exception("ConstGlobalString test");
+
+ // Member variables.
+ auto myStructure = new Structure();
+ if (myStructure.MemberString2 != "member string 2")
+ throw new Exception("MemberString2 test 1");
+ myStructure.MemberString2 = s;
+ if (myStructure.MemberString2 != s)
+ throw new Exception("MemberString2 test 2");
+ if (myStructure.ConstMemberString != "const member string")
+ throw new Exception("ConstMemberString test");
+
+ // Static member variables.
+ if (Structure.StaticMemberString2 != "static member string 2")
+ throw new Exception("StaticMemberString2 test 1");
+ Structure.StaticMemberString2 = s;
+ if (Structure.StaticMemberString2 != s)
+ throw new Exception("StaticMemberString2 test 2");
+ if (Structure.ConstStaticMemberString != "const static member string")
+ throw new Exception("ConstStaticMemberString test");
+}
diff --git a/Examples/test-suite/d/li_std_string_runme.2.d b/Examples/test-suite/d/li_std_string_runme.2.d
new file mode 100644
index 000000000..395c2f7ff
--- /dev/null
+++ b/Examples/test-suite/d/li_std_string_runme.2.d
@@ -0,0 +1,86 @@
+module li_std_string_runme;
+
+import std.exception;
+import li_std_string.li_std_string;
+import li_std_string.Structure;
+import li_std_string.SWIGTYPE_p_std__string;
+
+void main() {
+ // Checking expected use of %typemap(in) std::string {}
+ test_value("Fee");
+
+ // Checking expected result of %typemap(out) std::string {}
+ enforce(test_value("Fi") == "Fi", "Test 1 failed");
+
+ // Verify type-checking for %typemap(in) std::string {}
+ enforceThrows( (){ test_value(null); }, "Test 2 failed.");
+
+ // Checking expected use of %typemap(in) const std::string & {}
+ test_const_reference("Fo");
+
+ // Checking expected result of %typemap(out) const std::string& {}
+ enforce(test_const_reference("Fum") == "Fum", "Test 3 failed");
+
+ // Verify type-checking for %typemap(in) const std::string & {}
+ enforceThrows( (){ test_const_reference(null); }, "Test 4 failed.");
+
+ // Input and output typemaps for pointers and non-const references to
+ // std::string are *not* supported; the following tests confirm
+ // that none of these cases are slipping through.
+
+ SWIGTYPE_p_std__string stringPtr = null;
+
+ stringPtr = test_pointer_out();
+ test_pointer(stringPtr);
+
+ stringPtr = test_const_pointer_out();
+ test_const_pointer(stringPtr);
+
+ stringPtr = test_reference_out();
+ test_reference(stringPtr);
+
+ // Check throw exception specification
+ try {
+ test_throw();
+ throw new Exception("test 5 failed!");
+ } catch (Exception e) {
+ enforce(e.msg == "test_throw message", "Test 5 string check: " ~ e.msg);
+ }
+ try {
+ test_const_reference_throw();
+ throw new Exception("test 6 failed!");
+ } catch (Exception e) {
+ enforce(e.msg == "test_const_reference_throw message", "Test 6 string check: " ~ e.msg);
+ }
+
+ // Global variables.
+ const string s = "initial string";
+ enforce(GlobalString2 == "global string 2", "GlobalString2 test 1");
+ GlobalString2 = s;
+ enforce(GlobalString2 == s, "GlobalString2 test 2");
+ enforce(ConstGlobalString == "const global string", "ConstGlobalString test");
+
+ // Member variables.
+ auto myStructure = new Structure();
+ enforce(myStructure.MemberString2 == "member string 2", "MemberString2 test 1");
+ myStructure.MemberString2 = s;
+ enforce(myStructure.MemberString2 == s, "MemberString2 test 2");
+ enforce(myStructure.ConstMemberString == "const member string", "ConstMemberString test");
+
+ // Static member variables.
+ enforce(Structure.StaticMemberString2 == "static member string 2", "StaticMemberString2 test 1");
+ Structure.StaticMemberString2 = s;
+ enforce(Structure.StaticMemberString2 == s, "StaticMemberString2 test 2");
+ enforce(Structure.ConstStaticMemberString == "const static member string", "ConstStaticMemberString test");
+}
+
+private void enforceThrows(void delegate() dg, string errorMessage) {
+ bool hasThrown;
+ try {
+ dg();
+ } catch (Exception) {
+ hasThrown = true;
+ } finally {
+ enforce(hasThrown, errorMessage);
+ }
+}
diff --git a/Examples/test-suite/d/li_std_vector_runme.1.d b/Examples/test-suite/d/li_std_vector_runme.1.d
new file mode 100644
index 000000000..895fb450f
--- /dev/null
+++ b/Examples/test-suite/d/li_std_vector_runme.1.d
@@ -0,0 +1,219 @@
+module li_std_vector_runme;
+
+import tango.core.Exception;
+import tango.io.Stdout;
+import Integer = tango.text.convert.Integer;
+import li_std_vector.li_std_vector;
+import li_std_vector.DoubleVector;
+import li_std_vector.IntVector;
+import li_std_vector.IntPtrVector;
+import li_std_vector.IntConstPtrVector;
+import li_std_vector.RealVector;
+import li_std_vector.Struct;
+import li_std_vector.StructVector;
+import li_std_vector.StructPtrVector;
+import li_std_vector.StructConstPtrVector;
+
+const size_t SIZE = 20;
+
+void main() {
+ // Basic functionality tests.
+ {
+ auto vector = new IntVector();
+ for (size_t i = 0; i < SIZE; ++i) {
+ vector ~= i * 10;
+ }
+
+ if (vector.length != SIZE) {
+ throw new Exception("length test failed.");
+ }
+
+ vector[0] = 200;
+ if (vector[0] != 200) {
+ throw new Exception("indexing test failed");
+ }
+ vector[0] = 0 * 10;
+
+ try {
+ vector[vector.length] = 777;
+ throw new Exception("out of range test failed");
+ } catch (NoSuchElementException) {
+ }
+
+ foreach (i, value; vector) {
+ if (value != (i * 10)) {
+ throw new Exception("foreach test failed, i: " ~ Integer.toString(i));
+ }
+ }
+
+ vector.clear();
+ if (vector.size != 0) {
+ throw new Exception("clear test failed");
+ }
+ }
+
+ // Slice tests.
+ {
+ auto dVector = new DoubleVector();
+ for (size_t i = 0; i < SIZE; ++i) {
+ dVector ~= i * 10.1f;
+ }
+
+ double[] dArray = dVector[];
+ foreach (i, value; dArray) {
+ if (dVector[i] != value) {
+ throw new Exception("slice test 1 failed, i: " ~ Integer.toString(i));
+ }
+ }
+
+
+ auto sVector = new StructVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ sVector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] array = sVector[];
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(array[i]);
+ void* vPtr = Struct.swigGetCPtr(sVector[i]);
+ if (aPtr != vPtr) {
+ throw new Exception("slice test 2 failed, i: " ~
+ Integer.toString(i));
+ }
+ }
+ }
+
+ // remove() tests.
+ {
+ auto iVector = new IntVector();
+ for (int i = 0; i < SIZE; i++) {
+ iVector ~= i;
+ }
+
+ iVector.remove(iVector.length - 1);
+ iVector.remove(SIZE / 2);
+ iVector.remove(0);
+
+ try {
+ iVector.remove(iVector.size);
+ throw new Exception("remove test failed");
+ } catch (NoSuchElementException) {
+ }
+ }
+
+ // Capacity tests.
+ {
+ auto dv = new DoubleVector(10);
+ if ((dv.capacity != 10) || (dv.length != 0)) {
+ throw new Exception("constructor setting capacity test failed");
+ }
+
+ // TODO: Is this really required (and spec'ed) behavior?
+ dv.capacity = 20;
+ if (dv.capacity != 20) {
+ throw new Exception("capacity test 1 failed");
+ }
+
+ dv ~= 1.11;
+ try {
+ dv.capacity = dv.length - 1;
+ throw new Exception("capacity test 2 failed");
+ } catch (IllegalArgumentException) {
+ }
+ }
+
+ // Test the methods being wrapped.
+ {
+ auto iv = new IntVector();
+ for (int i=0; i<4; i++) {
+ iv ~= i;
+ }
+
+ double x = average(iv);
+ x += average(new IntVector([1, 2, 3, 4]));
+ RealVector rv = half(new RealVector([10.0f, 10.5f, 11.0f, 11.5f]));
+
+ auto dv = new DoubleVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ dv ~= i / 2.0;
+ }
+ halve_in_place(dv);
+
+ RealVector v0 = vecreal(new RealVector());
+ float flo = 123.456f;
+ v0 ~= flo;
+ flo = v0[0];
+
+ IntVector v1 = vecintptr(new IntVector());
+ IntPtrVector v2 = vecintptr(new IntPtrVector());
+ IntConstPtrVector v3 = vecintconstptr(new IntConstPtrVector());
+
+ v1 ~= 123;
+ v2.clear();
+ v3.clear();
+
+ StructVector v4 = vecstruct(new StructVector());
+ StructPtrVector v5 = vecstructptr(new StructPtrVector());
+ StructConstPtrVector v6 = vecstructconstptr(new StructConstPtrVector());
+
+ v4 ~= new Struct(123);
+ v5 ~= new Struct(123);
+ v6 ~= new Struct(123);
+ }
+
+ // Test vectors of pointers.
+ {
+ auto vector = new StructPtrVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ vector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] array = vector[];
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(array[i]);
+ void* vPtr = Struct.swigGetCPtr(vector[i]);
+ if (aPtr != vPtr) {
+ throw new Exception("StructPtrVector test 1 failed, i: " ~
+ Integer.toString(i));
+ }
+ }
+ }
+
+ // Test vectors of const pointers.
+ {
+ auto vector = new StructConstPtrVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ vector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] array = vector[];
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(array[i]);
+ void* vPtr = Struct.swigGetCPtr(vector[i]);
+ if (aPtr != vPtr) {
+ throw new Exception("StructConstPtrVector test 1 failed, i: " ~
+ Integer.toString(i));
+ }
+ }
+ }
+
+ // Test vectors destroyed via dispose().
+ {
+ {
+ scope vector = new StructVector();
+ vector ~= new Struct(0.0);
+ vector ~= new Struct(11.1);
+ }
+ {
+ scope vector = new DoubleVector();
+ vector ~= 0.0;
+ vector ~= 11.1;
+ }
+ }
+}
diff --git a/Examples/test-suite/d/li_std_vector_runme.2.d b/Examples/test-suite/d/li_std_vector_runme.2.d
new file mode 100644
index 000000000..7860ad6fc
--- /dev/null
+++ b/Examples/test-suite/d/li_std_vector_runme.2.d
@@ -0,0 +1,207 @@
+module li_std_vector_runme;
+
+import std.algorithm;
+import std.array;
+import std.conv;
+import std.exception;
+import std.stdio;
+import li_std_vector.li_std_vector;
+import li_std_vector.DoubleVector;
+import li_std_vector.IntVector;
+import li_std_vector.IntPtrVector;
+import li_std_vector.IntConstPtrVector;
+import li_std_vector.RealVector;
+import li_std_vector.Struct;
+import li_std_vector.StructVector;
+import li_std_vector.StructPtrVector;
+import li_std_vector.StructConstPtrVector;
+
+const size_t SIZE = 20;
+
+void main() {
+ // Basic functionality tests.
+ {
+ auto vector = new IntVector();
+ for (size_t i = 0; i < SIZE; ++i) {
+ vector ~= i * 10;
+ }
+
+ enforce(vector.length == SIZE, "length test failed.");
+
+ vector[0] = 200;
+ enforce(vector[0] == 200, "indexing test failed");
+ vector[0] = 0 * 10;
+
+ enforceThrows((){ vector[vector.length] = 777; }, "out of range test failed" );
+
+ foreach (i, value; vector) {
+ enforce(value == (i * 10), "foreach test failed, i: " ~ to!string(i));
+ }
+
+ enforce(canFind!`a == 0 * 10`(vector[]), "canFind test 1 failed");
+ enforce(canFind!`a == 10 * 10`(vector[]), "canFind test 2 failed");
+ enforce(canFind!`a == 19 * 10`(vector[]), "canFind test 3 failed");
+ enforce(!canFind!`a == 20 * 10`(vector[]), "canFind test 4 failed");
+
+ foreach (i, _; vector) {
+ enforce(indexOf(vector[], i * 10) == i, "indexOf test failed, i: " ~ to!string(i));
+ }
+
+ enforce(indexOf(vector[], 42) == -1, "non-existant item indexOf test failed");
+
+ vector.clear();
+ enforce(vector.length == 0, "clear test failed");
+ }
+
+ // To array conversion tests.
+ {
+ auto dVector = new DoubleVector();
+ for (size_t i = 0; i < SIZE; ++i) {
+ dVector ~= i * 10.1f;
+ }
+
+ double[] dArray = array(dVector[]);
+ foreach (i, value; dArray) {
+ enforce(dVector[i] == value, "slice test 1 failed, i: " ~ to!string(i));
+ }
+
+
+ auto sVector = new StructVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ sVector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] sArray = array(sVector[]);
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(sArray[i]);
+ void* vPtr = Struct.swigGetCPtr(sVector[i]);
+ enforce(aPtr == vPtr, "slice test 2 failed, i: " ~ to!string(i));
+ }
+ }
+
+ // remove() tests.
+ {
+ auto iVector = new IntVector();
+ for (int i = 0; i < SIZE; i++) {
+ iVector ~= i;
+ }
+
+ iVector.remove(iVector.length - 1);
+ iVector.remove(SIZE / 2);
+ iVector.remove(0);
+
+ enforceThrows((){ iVector.remove(iVector.length); }, "remove test failed");
+ }
+
+ // Capacity tests.
+ {
+ auto dv = new DoubleVector(10);
+ enforce(dv.capacity == 10, "constructor setting capacity test failed (1)");
+ enforce(dv.length == 0, "constructor setting capacity test failed (1)");
+
+ dv.reserve(20);
+ enforce(dv.capacity == 20, "capacity test failed");
+ }
+
+ // Test the methods being wrapped.
+ {
+ auto iv = new IntVector();
+ for (int i=0; i<4; i++) {
+ iv ~= i;
+ }
+
+ double x = average(iv);
+ x += average(new IntVector([1, 2, 3, 4]));
+ RealVector rv = half(new RealVector([10.0f, 10.5f, 11.0f, 11.5f]));
+
+ auto dv = new DoubleVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ dv ~= i / 2.0;
+ }
+ halve_in_place(dv);
+
+ RealVector v0 = vecreal(new RealVector());
+ float flo = 123.456f;
+ v0 ~= flo;
+ flo = v0[0];
+
+ IntVector v1 = vecintptr(new IntVector());
+ IntPtrVector v2 = vecintptr(new IntPtrVector());
+ IntConstPtrVector v3 = vecintconstptr(new IntConstPtrVector());
+
+ v1 ~= 123;
+ v2.clear();
+ v3.clear();
+
+ StructVector v4 = vecstruct(new StructVector());
+ StructPtrVector v5 = vecstructptr(new StructPtrVector());
+ StructConstPtrVector v6 = vecstructconstptr(new StructConstPtrVector());
+
+ v4 ~= new Struct(123);
+ v5 ~= new Struct(123);
+ v6 ~= new Struct(123);
+ }
+
+ // Test vectors of pointers.
+ {
+ auto vector = new StructPtrVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ vector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] array = array(vector[]);
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(array[i]);
+ void* vPtr = Struct.swigGetCPtr(vector[i]);
+ enforce(aPtr == vPtr, "StructConstPtrVector test 1 failed, i: " ~ to!string(i));
+ }
+ }
+
+ // Test vectors of const pointers.
+ {
+ auto vector = new StructConstPtrVector();
+ for (size_t i = 0; i < SIZE; i++) {
+ vector ~= new Struct(i / 10.0);
+ }
+
+ Struct[] array = array(vector[]);
+
+ for (size_t i = 0; i < SIZE; i++) {
+ // Make sure that a shallow copy has been made.
+ void* aPtr = Struct.swigGetCPtr(array[i]);
+ void* vPtr = Struct.swigGetCPtr(vector[i]);
+ enforce(aPtr == vPtr, "StructConstPtrVector test 1 failed, i: " ~ to!string(i));
+ }
+ }
+
+ // Test vectors destroyed via scope.
+ {
+ {
+ scope vector = new StructVector();
+ vector ~= new Struct(0.0);
+ vector ~= new Struct(11.1);
+ }
+ {
+ scope vector = new DoubleVector();
+ vector ~= 0.0;
+ vector ~= 11.1;
+ }
+ }
+}
+
+private void enforceThrows(void delegate() dg, string errorMessage) {
+ bool hasThrown;
+ try {
+ dg();
+ } catch (Exception) {
+ hasThrown = true;
+ } finally {
+ if (!hasThrown) {
+ throw new Exception(errorMessage);
+ }
+ }
+}
diff --git a/Examples/test-suite/d/li_typemaps_runme.1.d b/Examples/test-suite/d/li_typemaps_runme.1.d
new file mode 100644
index 000000000..e37b12bc2
--- /dev/null
+++ b/Examples/test-suite/d/li_typemaps_runme.1.d
@@ -0,0 +1,94 @@
+/// Tests correct handling of a few INPUT/OUTPUT/INOUT-typemapped functions.
+module li_typemaps_runme;
+
+import li_typemaps.li_typemaps;
+
+void main() {
+ // Check double INPUT typemaps
+ if (in_double(22.22) != 22.22) raiseError("in_double");
+ if (inr_double(22.22) != 22.22) raiseError("inr_double");
+
+ // Check double OUTPUT typemaps
+ {
+ double var = 44.44;
+ out_double(22.22, var);
+ if (var != 22.22) raiseError("out_double");
+ }
+ {
+ double var = 44.44;
+ outr_double(22.22, var);
+ if (var != 22.22) raiseError("outr_double");
+ }
+
+ // Check double INOUT typemaps
+ {
+ double var = 44.44;
+ inout_double(var);
+ if (var != 44.44) raiseError("inout_double");
+ }
+ {
+ double var = 44.44;
+ inoutr_double(var);
+ if (var != 44.44) raiseError("inoutr_double");
+ }
+
+ // Check unsigned long long INPUT typemaps
+ if (in_ulonglong(20) != 20) raiseError("in_ulonglong");
+ if (inr_ulonglong(20) != 20) raiseError("inr_ulonglong");
+
+ // Check unsigned long long OUTPUT typemaps
+ {
+ ulong var = 40;
+ out_ulonglong(20, var);
+ if (var != 20) raiseError("out_ulonglong");
+ }
+ {
+ ulong var = 40;
+ outr_ulonglong(20, var);
+ if (var != 20) raiseError("outr_ulonglong");
+ }
+
+ // Check unsigned long long INOUT typemaps
+ {
+ ulong var = 40;
+ inout_ulonglong(var);
+ if (var != 40) raiseError("inout_ulonglong");
+ }
+ {
+ ulong var = 40;
+ inoutr_ulonglong(var);
+ if (var != 40) raiseError("inoutr_ulonglong");
+ }
+
+ // Check unsigned bool INPUT typemaps
+ if (in_bool(false) != false) raiseError("in_bool");
+ if (inr_bool(false) != false) raiseError("inr_bool");
+
+ // Check unsigned bool OUTPUT typemaps
+ {
+ bool var = false;
+ out_bool(true, var);
+ if (var != true) raiseError("out_bool");
+ }
+ {
+ bool var = false;
+ outr_bool(true, var);
+ if (var != true) raiseError("outr_bool");
+ }
+
+ // Check unsigned bool INOUT typemaps
+ {
+ bool var = false;
+ inout_bool(var);
+ if (var != false) raiseError("inout_bool");
+ }
+ {
+ bool var = false;
+ inoutr_bool(var);
+ if (var != false) raiseError("inoutr_bool");
+ }
+}
+
+void raiseError(char[] funcName) {
+ throw new Exception("Test FAILED for function " ~ funcName);
+}
diff --git a/Examples/test-suite/d/li_typemaps_runme.2.d b/Examples/test-suite/d/li_typemaps_runme.2.d
new file mode 100644
index 000000000..de515b0ff
--- /dev/null
+++ b/Examples/test-suite/d/li_typemaps_runme.2.d
@@ -0,0 +1,91 @@
+/// Tests correct handling of a few INPUT/OUTPUT/INOUT-typemapped functions.
+module li_typemaps_runme;
+
+import std.exception;
+import li_typemaps.li_typemaps;
+
+void main() {
+ // Check double INPUT typemaps
+ enforce(in_double(22.22) == 22.22, "in_double");
+ enforce(inr_double(22.22) == 22.22, "inr_double");
+
+ // Check double OUTPUT typemaps
+ {
+ double var = 44.44;
+ out_double(22.22, var);
+ enforce(var == 22.22, "out_double");
+ }
+ {
+ double var = 44.44;
+ outr_double(22.22, var);
+ enforce(var == 22.22, "outr_double");
+ }
+
+ // Check double INOUT typemaps
+ {
+ double var = 44.44;
+ inout_double(var);
+ enforce(var == 44.44, "inout_double");
+ }
+ {
+ double var = 44.44;
+ inoutr_double(var);
+ enforce(var == 44.44, "inoutr_double");
+ }
+
+ // Check unsigned long long INPUT typemaps
+ enforce(in_ulonglong(20) == 20, "in_ulonglong");
+ enforce(inr_ulonglong(20) == 20, "inr_ulonglong");
+
+ // Check unsigned long long OUTPUT typemaps
+ {
+ ulong var = 40;
+ out_ulonglong(20, var);
+ enforce(var == 20, "out_ulonglong");
+ }
+ {
+ ulong var = 40;
+ outr_ulonglong(20, var);
+ enforce(var == 20, "outr_ulonglong");
+ }
+
+ // Check unsigned long long INOUT typemaps
+ {
+ ulong var = 40;
+ inout_ulonglong(var);
+ enforce(var == 40, "inout_ulonglong");
+ }
+ {
+ ulong var = 40;
+ inoutr_ulonglong(var);
+ enforce(var == 40, "inoutr_ulonglong");
+ }
+
+ // Check unsigned bool INPUT typemaps
+ enforce(in_bool(false) == false, "in_bool");
+ enforce(inr_bool(false) == false, "inr_bool");
+
+ // Check unsigned bool OUTPUT typemaps
+ {
+ bool var = false;
+ out_bool(true, var);
+ enforce(var == true, "out_bool");
+ }
+ {
+ bool var = false;
+ outr_bool(true, var);
+ enforce(var == true, "outr_bool");
+ }
+
+ // Check unsigned bool INOUT typemaps
+ {
+ bool var = false;
+ inout_bool(var);
+ enforce(var == false, "inout_bool");
+ }
+ {
+ bool var = false;
+ inoutr_bool(var);
+ enforce(var == false, "inoutr_bool");
+ }
+}
diff --git a/Examples/test-suite/d/long_long_runme.1.d b/Examples/test-suite/d/long_long_runme.1.d
new file mode 100644
index 000000000..a6d5448bc
--- /dev/null
+++ b/Examples/test-suite/d/long_long_runme.1.d
@@ -0,0 +1,35 @@
+// Checks if the long long and unsigned long long types work.
+module long_long_runme;
+
+import Integer = tango.text.convert.Integer;
+import long_long.long_long;
+
+void main() {
+ check_ll(0L);
+ check_ll(0x7FFFFFFFFFFFFFFFL);
+ check_ll(-10L);
+
+ check_ull(0u);
+ check_ull(127u);
+ check_ull(128u);
+ check_ull(9223372036854775807u); //0x7FFFFFFFFFFFFFFFL
+ check_ull(18446744073709551615u); //0xFFFFFFFFFFFFFFFFL
+}
+
+void check_ll(long value) {
+ ll = value;
+ long value_check = ll;
+ if (value != value_check) {
+ throw new Exception("Runtime test using long long failed: expected: " ~
+ Integer.toString(value) ~ ", got: " ~ Integer.toString(value_check));
+ }
+}
+
+void check_ull(ulong value) {
+ ull = value;
+ ulong value_check = ull;
+ if (value != value_check) {
+ throw new Exception( "Runtime test using unsigned long long failed: expected: " ~
+ Integer.toString(value) ~ ", ll_check=" ~ Integer.toString(value_check));
+ }
+}
diff --git a/Examples/test-suite/d/long_long_runme.2.d b/Examples/test-suite/d/long_long_runme.2.d
new file mode 100644
index 000000000..a082171b4
--- /dev/null
+++ b/Examples/test-suite/d/long_long_runme.2.d
@@ -0,0 +1,32 @@
+// Checks if the long long and unsigned long long types work.
+module long_long_runme;
+
+import std.conv;
+import std.exception;
+import long_long.long_long;
+
+void main() {
+ check_ll(0L);
+ check_ll(0x7FFFFFFFFFFFFFFFL);
+ check_ll(-10L);
+
+ check_ull(0u);
+ check_ull(127u);
+ check_ull(128u);
+ check_ull(9223372036854775807u); //0x7FFFFFFFFFFFFFFFL
+ check_ull(18446744073709551615u); //0xFFFFFFFFFFFFFFFFL
+}
+
+void check_ll(long value) {
+ ll = value;
+ long value_check = ll;
+ enforce(value == value_check, "Runtime test using long long failed: expected: " ~
+ to!string(value) ~ ", got: " ~ to!string(value_check));
+}
+
+void check_ull(ulong value) {
+ ull = value;
+ ulong value_check = ull;
+ enforce(value == value_check, "Runtime test using unsigned long long failed: expected: " ~
+ to!string(value) ~ ", ll_check=" ~ to!string(value_check));
+}
diff --git a/Examples/test-suite/d/member_pointer_runme.1.d b/Examples/test-suite/d/member_pointer_runme.1.d
new file mode 100644
index 000000000..c1f8d33b8
--- /dev/null
+++ b/Examples/test-suite/d/member_pointer_runme.1.d
@@ -0,0 +1,43 @@
+module member_pointer_runme;
+
+import Float = tango.text.convert.Float;
+import member_pointer.member_pointer;
+import member_pointer.Square;
+import member_pointer.SWIGTYPE_m_Shape__f_void__double;
+
+void main() {
+ auto s = new Square(10);
+
+ // Do some calculations
+ auto area_pt = areapt();
+ auto perim_pt = perimeterpt();
+ check("Square area ", 100.0, do_op(s, area_pt));
+ check("Square perim", 40.0, do_op(s, perim_pt));
+
+ SWIGTYPE_m_Shape__f_void__double memberPtr = null;
+ memberPtr = areavar;
+ memberPtr = perimetervar;
+
+ // Try the variables
+ check("Square area ", 100.0, do_op(s, areavar));
+ check("Square perim", 40.0, do_op(s, perimetervar));
+
+ // Modify one of the variables
+ areavar = perim_pt;
+ check("Square perimeter", 40.0, do_op(s,areavar));
+
+ // Try the constants
+ memberPtr = AREAPT;
+ memberPtr = PERIMPT;
+ memberPtr = NULLPT;
+
+ check("Square area", 100.0, do_op(s, AREAPT));
+ check("Square perim", 40.0, do_op(s, PERIMPT));
+}
+
+void check(char[] what, double expected, double actual) {
+ if (expected != actual) {
+ throw new Exception("Failed: " ~ what ~ ": expected "
+ ~ Float.toString(expected) ~ ", but got " ~ Float.toString(actual));
+ }
+}
diff --git a/Examples/test-suite/d/member_pointer_runme.2.d b/Examples/test-suite/d/member_pointer_runme.2.d
new file mode 100644
index 000000000..a5c293cd0
--- /dev/null
+++ b/Examples/test-suite/d/member_pointer_runme.2.d
@@ -0,0 +1,42 @@
+module member_pointer_runme;
+
+import std.conv;
+import std.exception;
+import member_pointer.member_pointer;
+import member_pointer.Square;
+import member_pointer.SWIGTYPE_m_Shape__f_void__double;
+
+void main() {
+ auto s = new Square(10);
+
+ // Do some calculations
+ auto area_pt = areapt();
+ auto perim_pt = perimeterpt();
+ check("Square area", 100.0, do_op(s, area_pt));
+ check("Square perim", 40.0, do_op(s, perim_pt));
+
+ SWIGTYPE_m_Shape__f_void__double memberPtr = null;
+ memberPtr = areavar;
+ memberPtr = perimetervar;
+
+ // Try the variables
+ check("Square area", 100.0, do_op(s, areavar));
+ check("Square perim", 40.0, do_op(s, perimetervar));
+
+ // Modify one of the variables
+ areavar = perim_pt;
+ check("Square perimeter", 40.0, do_op(s,areavar));
+
+ // Try the constants
+ memberPtr = AREAPT;
+ memberPtr = PERIMPT;
+ memberPtr = NULLPT;
+
+ check("Square area", 100.0, do_op(s, AREAPT));
+ check("Square perim", 40.0, do_op(s, PERIMPT));
+}
+
+void check(string what, double expected, double actual) {
+ enforce(expected == actual, "Failed: " ~ what ~ ": expected " ~
+ to!string(expected) ~ ", but got " ~ to!string(actual));
+}
diff --git a/Examples/test-suite/d/overload_complicated_runme.1.d b/Examples/test-suite/d/overload_complicated_runme.1.d
new file mode 100644
index 000000000..03d1bf1e6
--- /dev/null
+++ b/Examples/test-suite/d/overload_complicated_runme.1.d
@@ -0,0 +1,50 @@
+module overload_complicated_runme;
+
+import overload_complicated;
+
+void main() {
+ SWIGTYPE_p_int pInt = null;
+
+ // Check the correct constructors are available
+ Pop p = new Pop(pInt);
+
+ p = new Pop(pInt, false);
+
+ // Check overloaded in const only and pointers/references which target languages cannot disambiguate
+ if (p.hip(false) != 701)
+ throw new Exception("Test 1 failed");
+
+ if (p.hip(pInt) != 702)
+ throw new Exception("Test 2 failed");
+
+ // Reverse the order for the above
+ if (p.hop(pInt) != 805)
+ throw new Exception("Test 3 failed");
+
+ if (p.hop(false) != 801)
+ throw new Exception("Test 4 failed");
+
+ // Few more variations and order shuffled
+ if (p.pop(false) != 901)
+ throw new Exception("Test 5 failed");
+
+ if (p.pop(pInt) != 902)
+ throw new Exception("Test 6 failed");
+
+ if (p.pop() != 905)
+ throw new Exception("Test 7 failed");
+
+ // Overload on const only
+ if (p.bop(pInt) != 1001)
+ throw new Exception("Test 8 failed");
+
+ if (p.bip(pInt) != 2001)
+ throw new Exception("Test 9 failed");
+
+ // Globals
+ if (muzak(false) != 3001)
+ throw new Exception("Test 10 failed");
+
+ if (muzak(pInt) != 3002)
+ throw new Exception("Test 11 failed");
+}
diff --git a/Examples/test-suite/d/overload_complicated_runme.2.d b/Examples/test-suite/d/overload_complicated_runme.2.d
new file mode 100644
index 000000000..9d03ec5e6
--- /dev/null
+++ b/Examples/test-suite/d/overload_complicated_runme.2.d
@@ -0,0 +1,34 @@
+module overload_complicated_runme;
+
+import std.exception;
+import overload_complicated.overload_complicated;
+import overload_complicated.Pop;
+
+void main() {
+ int* pInt = new int;
+
+ // Check the correct constructors are available
+ auto p = new Pop(pInt);
+ p = new Pop(pInt, false);
+
+ // Check overloaded in const only and pointers/references which target languages cannot disambiguate
+ enforce(p.hip(false) == 701, "Test 1 failed");
+ enforce(p.hip(pInt) == 702, "Test 2 failed");
+
+ // Reverse the order for the above
+ enforce(p.hop(pInt) == 805, "Test 3 failed");
+ enforce(p.hop(false) == 801, "Test 4 failed");
+
+ // Few more variations and order shuffled
+ enforce(p.pop(false) == 901, "Test 5 failed");
+ enforce(p.pop(pInt) == 902, "Test 6 failed");
+ enforce(p.pop() == 905, "Test 7 failed");
+
+ // Overload on const only
+ enforce(p.bop(pInt) == 1001, "Test 8 failed");
+ enforce(p.bip(pInt) == 2001, "Test 9 failed");
+
+ // Globals
+ enforce(muzak(false) == 3001, "Test 10 failed");
+ enforce(muzak(pInt) == 3002, "Test 11 failed");
+}
diff --git a/Examples/test-suite/d/overload_template_runme.1.d b/Examples/test-suite/d/overload_template_runme.1.d
new file mode 100644
index 000000000..a1fe8012f
--- /dev/null
+++ b/Examples/test-suite/d/overload_template_runme.1.d
@@ -0,0 +1,146 @@
+module overload_template_runme;
+
+import overload_template.overload_template;
+import overload_template.Klass;
+
+void main() {
+ int f = foo();
+
+ f += maximum(3,4);
+ double b = maximum(3.4,5.2);
+ b++; // warning suppression
+
+ // mix 1
+ if (mix1("hi") != 101)
+ throw new Exception ("mix1(const char*)");
+
+ if (mix1(1.0, 1.0) != 102)
+ throw new Exception ("mix1(double, const double &)");
+
+ if (mix1(1.0) != 103)
+ throw new Exception ("mix1(double)");
+
+ // mix 2
+ if (mix2("hi") != 101)
+ throw new Exception ("mix2(const char*)");
+
+ if (mix2(1.0, 1.0) != 102)
+ throw new Exception ("mix2(double, const double &)");
+
+ if (mix2(1.0) != 103)
+ throw new Exception ("mix2(double)");
+
+ // mix 3
+ if (mix3("hi") != 101)
+ throw new Exception ("mix3(const char*)");
+
+ if (mix3(1.0, 1.0) != 102)
+ throw new Exception ("mix3(double, const double &)");
+
+ if (mix3(1.0) != 103)
+ throw new Exception ("mix3(double)");
+
+ // Combination 1
+ if (overtparams1(100) != 10)
+ throw new Exception ("overtparams1(int)");
+
+ if (overtparams1(100.0, 100) != 20)
+ throw new Exception ("overtparams1(double, int)");
+
+ // Combination 2
+ if (overtparams2(100.0, 100) != 40)
+ throw new Exception ("overtparams2(double, int)");
+
+ // Combination 3
+ if (overloaded() != 60)
+ throw new Exception ("overloaded()");
+
+ if (overloaded(100.0, 100) != 70)
+ throw new Exception ("overloaded(double, int)");
+
+ // Combination 4
+ if (overloadedagain("hello") != 80)
+ throw new Exception ("overloadedagain(const char *)");
+
+ if (overloadedagain() != 90)
+ throw new Exception ("overloadedagain(double)");
+
+ // specializations
+ if (specialization(10) != 202)
+ throw new Exception ("specialization(int)");
+
+ if (specialization(10.0) != 203)
+ throw new Exception ("specialization(double)");
+
+ if (specialization(10, 10) != 204)
+ throw new Exception ("specialization(int, int)");
+
+ if (specialization(10.0, 10.0) != 205)
+ throw new Exception ("specialization(double, double)");
+
+ if (specialization("hi", "hi") != 201)
+ throw new Exception ("specialization(const char *, const char *)");
+
+ // simple specialization
+ xyz();
+ xyz_int();
+ xyz_double();
+
+ // a bit of everything
+ if (overload("hi") != 0)
+ throw new Exception ("overload()");
+
+ if (overload(1) != 10)
+ throw new Exception ("overload(int t)");
+
+ if (overload(1, 1) != 20)
+ throw new Exception ("overload(int t, const int &)");
+
+ if (overload(1, "hello") != 30)
+ throw new Exception ("overload(int t, const char *)");
+
+ auto k = new Klass();
+ if (overload(k) != 10)
+ throw new Exception ("overload(Klass t)");
+
+ if (overload(k, k) != 20)
+ throw new Exception ("overload(Klass t, const Klass &)");
+
+ if (overload(k, "hello") != 30)
+ throw new Exception ("overload(Klass t, const char *)");
+
+ if (overload(10.0, "hi") != 40)
+ throw new Exception ("overload(double t, const char *)");
+
+ if (overload() != 50)
+ throw new Exception ("overload(const char *)");
+
+
+ // everything put in a namespace
+ if (nsoverload("hi") != 1000)
+ throw new Exception ("nsoverload()");
+
+ if (nsoverload(1) != 1010)
+ throw new Exception ("nsoverload(int t)");
+
+ if (nsoverload(1, 1) != 1020)
+ throw new Exception ("nsoverload(int t, const int &)");
+
+ if (nsoverload(1, "hello") != 1030)
+ throw new Exception ("nsoverload(int t, const char *)");
+
+ if (nsoverload(k) != 1010)
+ throw new Exception ("nsoverload(Klass t)");
+
+ if (nsoverload(k, k) != 1020)
+ throw new Exception ("nsoverload(Klass t, const Klass &)");
+
+ if (nsoverload(k, "hello") != 1030)
+ throw new Exception ("nsoverload(Klass t, const char *)");
+
+ if (nsoverload(10.0, "hi") != 1040)
+ throw new Exception ("nsoverload(double t, const char *)");
+
+ if (nsoverload() != 1050)
+ throw new Exception ("nsoverload(const char *)");
+}
diff --git a/Examples/test-suite/d/overload_template_runme.2.d b/Examples/test-suite/d/overload_template_runme.2.d
new file mode 100644
index 000000000..9fe6eb2cf
--- /dev/null
+++ b/Examples/test-suite/d/overload_template_runme.2.d
@@ -0,0 +1,80 @@
+module overload_template_runme;
+
+import std.exception;
+import overload_template.overload_template;
+import overload_template.Klass;
+
+void main() {
+ int f = foo();
+
+ f += maximum(3,4);
+ double b = maximum(3.4,5.2);
+ b++; // warning suppression
+
+ // mix 1
+ enforce(mix1("hi") == 101, "mix1(const char*)");
+ enforce(mix1(1.0, 1.0) == 102, "mix1(double, const double &)");
+ enforce(mix1(1.0) == 103, "mix1(double)");
+
+ // mix 2
+ enforce(mix2("hi") == 101, "mix2(const char*)");
+ enforce(mix2(1.0, 1.0) == 102, "mix2(double, const double &)");
+ enforce(mix2(1.0) == 103, "mix2(double)");
+
+ // mix 3
+ enforce(mix3("hi") == 101, "mix3(const char*)");
+ enforce(mix3(1.0, 1.0) == 102, "mix3(double, const double &)");
+ enforce(mix3(1.0) == 103, "mix3(double)");
+
+ // Combination 1
+ enforce(overtparams1(100) == 10, "overtparams1(int)");
+ enforce(overtparams1(100.0, 100) == 20, "overtparams1(double, int)");
+
+ // Combination 2
+ enforce(overtparams2(100.0, 100) == 40, "overtparams2(double, int)");
+
+ // Combination 3
+ enforce(overloaded() == 60, "overloaded()");
+ enforce(overloaded(100.0, 100) == 70, "overloaded(double, int)");
+
+ // Combination 4
+ enforce(overloadedagain("hello") == 80, "overloadedagain(const char *)");
+ enforce(overloadedagain() == 90, "overloadedagain(double)");
+
+ // specializations
+ enforce(specialization(10) == 202, "specialization(int)");
+ enforce(specialization(10.0) == 203, "specialization(double)");
+ enforce(specialization(10, 10) == 204, "specialization(int, int)");
+ enforce(specialization(10.0, 10.0) == 205, "specialization(double, double)");
+ enforce(specialization("hi", "hi") == 201, "specialization(const char *, const char *)");
+
+ // simple specialization
+ xyz();
+ xyz_int();
+ xyz_double();
+
+ // a bit of everything
+ enforce(overload("hi") == 0, "overload()");
+ enforce(overload(1) == 10, "overload(int t)");
+ enforce(overload(1, 1) == 20, "overload(int t, const int &)");
+ enforce(overload(1, "hello") == 30, "overload(int t, const char *)");
+
+ auto k = new Klass();
+ enforce(overload(k) == 10, "overload(Klass t)");
+ enforce(overload(k, k) == 20, "overload(Klass t, const Klass &)");
+ enforce(overload(k, "hello") == 30, "overload(Klass t, const char *)");
+ enforce(overload(10.0, "hi") == 40, "overload(double t, const char *)");
+ enforce(overload() == 50, "overload(const char *)");
+
+
+ // everything put in a namespace
+ enforce(nsoverload("hi") == 1000, "nsoverload()");
+ enforce(nsoverload(1) == 1010, "nsoverload(int t)");
+ enforce(nsoverload(1, 1) == 1020, "nsoverload(int t, const int &)");
+ enforce(nsoverload(1, "hello") == 1030, "nsoverload(int t, const char *)");
+ enforce(nsoverload(k) == 1010, "nsoverload(Klass t)");
+ enforce(nsoverload(k, k) == 1020, "nsoverload(Klass t, const Klass &)");
+ enforce(nsoverload(k, "hello") == 1030, "nsoverload(Klass t, const char *)");
+ enforce(nsoverload(10.0, "hi") == 1040, "nsoverload(double t, const char *)");
+ enforce(nsoverload() == 1050, "nsoverload(const char *)");
+}
diff --git a/Examples/test-suite/d/pointer_reference_runme.1.d b/Examples/test-suite/d/pointer_reference_runme.1.d
new file mode 100644
index 000000000..c593b939c
--- /dev/null
+++ b/Examples/test-suite/d/pointer_reference_runme.1.d
@@ -0,0 +1,13 @@
+module pointer_reference_runme;
+
+import pointer_reference.pointer_reference;
+import pointer_reference.Struct;
+
+void main() {
+ Struct s = get();
+ if (s.value != 10) throw new Exception("get test failed");
+
+ Struct ss = new Struct(20);
+ set(ss);
+ if (Struct.instance.value != 20) throw new Exception("set test failed");
+}
diff --git a/Examples/test-suite/d/pointer_reference_runme.2.d b/Examples/test-suite/d/pointer_reference_runme.2.d
new file mode 100644
index 000000000..8f287dfbd
--- /dev/null
+++ b/Examples/test-suite/d/pointer_reference_runme.2.d
@@ -0,0 +1,14 @@
+module pointer_reference_runme;
+
+import std.exception;
+import pointer_reference.pointer_reference;
+import pointer_reference.Struct;
+
+void main() {
+ Struct s = get();
+ enforce(s.value == 10, "get test failed");
+
+ auto ss = new Struct(20);
+ set(ss);
+ enforce(Struct.instance.value == 20, "set test failed");
+}
diff --git a/Examples/test-suite/d/preproc_constants_c_runme.1.d b/Examples/test-suite/d/preproc_constants_c_runme.1.d
new file mode 100644
index 000000000..f25bbfdee
--- /dev/null
+++ b/Examples/test-suite/d/preproc_constants_c_runme.1.d
@@ -0,0 +1,63 @@
+module preproc_constants_c_runme;
+
+import preproc_constants_c.preproc_constants_c;
+
+// Same as preproc_constants.i testcase, but bool types are int instead.
+void main() {
+ static assert(is(int == typeof(CONST_INT1())));
+ static assert(is(int == typeof(CONST_INT2())));
+ static assert(is(uint == typeof(CONST_UINT1())));
+ static assert(is(uint == typeof(CONST_UINT2())));
+ static assert(is(uint == typeof(CONST_UINT3())));
+ static assert(is(uint == typeof(CONST_UINT4())));
+ static assert(is(int == typeof(CONST_LONG1())));
+ static assert(is(int == typeof(CONST_LONG2())));
+ static assert(is(int == typeof(CONST_LONG3())));
+ static assert(is(int == typeof(CONST_LONG4())));
+ static assert(is(long == typeof(CONST_LLONG1())));
+ static assert(is(long == typeof(CONST_LLONG2())));
+ static assert(is(long == typeof(CONST_LLONG3())));
+ static assert(is(long == typeof(CONST_LLONG4())));
+ static assert(is(ulong == typeof(CONST_ULLONG1())));
+ static assert(is(ulong == typeof(CONST_ULLONG2())));
+ static assert(is(ulong == typeof(CONST_ULLONG3())));
+ static assert(is(ulong == typeof(CONST_ULLONG4())));
+ static assert(is(double == typeof(CONST_DOUBLE1())));
+ static assert(is(double == typeof(CONST_DOUBLE2())));
+ static assert(is(double == typeof(CONST_DOUBLE3())));
+ static assert(is(double == typeof(CONST_DOUBLE4())));
+ static assert(is(double == typeof(CONST_DOUBLE5())));
+ static assert(is(double == typeof(CONST_DOUBLE6())));
+ static assert(is(int == typeof(CONST_BOOL1())));
+ static assert(is(int == typeof(CONST_BOOL2())));
+ static assert(is(char == typeof(CONST_CHAR())));
+ static assert(is(char[] == typeof(CONST_STRING1())));
+ static assert(is(char[] == typeof(CONST_STRING2())));
+
+ static assert(is(int == typeof(INT_AND_BOOL())));
+// static assert(is(int == typeof(INT_AND_CHAR())));
+ static assert(is(int == typeof(INT_AND_INT())));
+ static assert(is(uint == typeof(INT_AND_UINT())));
+ static assert(is(int == typeof(INT_AND_LONG())));
+ static assert(is(uint == typeof(INT_AND_ULONG())));
+ static assert(is(long == typeof(INT_AND_LLONG())));
+ static assert(is(ulong == typeof(INT_AND_ULLONG())));
+ static assert(is(int == typeof(BOOL_AND_BOOL())));
+
+ static assert(is(int == typeof(EXPR_MULTIPLY())));
+ static assert(is(int == typeof(EXPR_DIVIDE())));
+ static assert(is(int == typeof(EXPR_PLUS())));
+ static assert(is(int == typeof(EXPR_MINUS())));
+ static assert(is(int == typeof(EXPR_LSHIFT())));
+ static assert(is(int == typeof(EXPR_RSHIFT())));
+ static assert(is(int == typeof(EXPR_LTE())));
+ static assert(is(int == typeof(EXPR_GTE())));
+ static assert(is(int == typeof(EXPR_INEQUALITY())));
+ static assert(is(int == typeof(EXPR_EQUALITY())));
+ static assert(is(int == typeof(EXPR_AND())));
+ static assert(is(int == typeof(EXPR_XOR())));
+ static assert(is(int == typeof(EXPR_OR())));
+ static assert(is(int == typeof(EXPR_LAND())));
+ static assert(is(int == typeof(EXPR_LOR())));
+ static assert(is(double == typeof(EXPR_CONDITIONAL())));
+}
diff --git a/Examples/test-suite/d/preproc_constants_c_runme.2.d b/Examples/test-suite/d/preproc_constants_c_runme.2.d
new file mode 100644
index 000000000..07d6ac53d
--- /dev/null
+++ b/Examples/test-suite/d/preproc_constants_c_runme.2.d
@@ -0,0 +1,63 @@
+module preproc_constants_c_runme;
+
+import preproc_constants_c.preproc_constants_c;
+
+// Same as preproc_constants.i testcase, but bool types are int instead.
+void main() {
+ static assert(is(int == typeof(CONST_INT1())));
+ static assert(is(int == typeof(CONST_INT2())));
+ static assert(is(uint == typeof(CONST_UINT1())));
+ static assert(is(uint == typeof(CONST_UINT2())));
+ static assert(is(uint == typeof(CONST_UINT3())));
+ static assert(is(uint == typeof(CONST_UINT4())));
+ static assert(is(int == typeof(CONST_LONG1())));
+ static assert(is(int == typeof(CONST_LONG2())));
+ static assert(is(int == typeof(CONST_LONG3())));
+ static assert(is(int == typeof(CONST_LONG4())));
+ static assert(is(long == typeof(CONST_LLONG1())));
+ static assert(is(long == typeof(CONST_LLONG2())));
+ static assert(is(long == typeof(CONST_LLONG3())));
+ static assert(is(long == typeof(CONST_LLONG4())));
+ static assert(is(ulong == typeof(CONST_ULLONG1())));
+ static assert(is(ulong == typeof(CONST_ULLONG2())));
+ static assert(is(ulong == typeof(CONST_ULLONG3())));
+ static assert(is(ulong == typeof(CONST_ULLONG4())));
+ static assert(is(double == typeof(CONST_DOUBLE1())));
+ static assert(is(double == typeof(CONST_DOUBLE2())));
+ static assert(is(double == typeof(CONST_DOUBLE3())));
+ static assert(is(double == typeof(CONST_DOUBLE4())));
+ static assert(is(double == typeof(CONST_DOUBLE5())));
+ static assert(is(double == typeof(CONST_DOUBLE6())));
+ static assert(is(int == typeof(CONST_BOOL1())));
+ static assert(is(int == typeof(CONST_BOOL2())));
+ static assert(is(char == typeof(CONST_CHAR())));
+ static assert(is(string == typeof(CONST_STRING1())));
+ static assert(is(string == typeof(CONST_STRING2())));
+
+ static assert(is(int == typeof(INT_AND_BOOL())));
+// static assert(is(int == typeof(INT_AND_CHAR())));
+ static assert(is(int == typeof(INT_AND_INT())));
+ static assert(is(uint == typeof(INT_AND_UINT())));
+ static assert(is(int == typeof(INT_AND_LONG())));
+ static assert(is(uint == typeof(INT_AND_ULONG())));
+ static assert(is(long == typeof(INT_AND_LLONG())));
+ static assert(is(ulong == typeof(INT_AND_ULLONG())));
+ static assert(is(int == typeof(BOOL_AND_BOOL())));
+
+ static assert(is(int == typeof(EXPR_MULTIPLY())));
+ static assert(is(int == typeof(EXPR_DIVIDE())));
+ static assert(is(int == typeof(EXPR_PLUS())));
+ static assert(is(int == typeof(EXPR_MINUS())));
+ static assert(is(int == typeof(EXPR_LSHIFT())));
+ static assert(is(int == typeof(EXPR_RSHIFT())));
+ static assert(is(int == typeof(EXPR_LTE())));
+ static assert(is(int == typeof(EXPR_GTE())));
+ static assert(is(int == typeof(EXPR_INEQUALITY())));
+ static assert(is(int == typeof(EXPR_EQUALITY())));
+ static assert(is(int == typeof(EXPR_AND())));
+ static assert(is(int == typeof(EXPR_XOR())));
+ static assert(is(int == typeof(EXPR_OR())));
+ static assert(is(int == typeof(EXPR_LAND())));
+ static assert(is(int == typeof(EXPR_LOR())));
+ static assert(is(double == typeof(EXPR_CONDITIONAL())));
+}
diff --git a/Examples/test-suite/d/preproc_constants_runme.1.d b/Examples/test-suite/d/preproc_constants_runme.1.d
new file mode 100644
index 000000000..a2aaa8fcd
--- /dev/null
+++ b/Examples/test-suite/d/preproc_constants_runme.1.d
@@ -0,0 +1,62 @@
+module preproc_constants_runme;
+
+import preproc_constants.preproc_constants;
+
+void main() {
+ static assert(is(int == typeof(CONST_INT1())));
+ static assert(is(int == typeof(CONST_INT2())));
+ static assert(is(uint == typeof(CONST_UINT1())));
+ static assert(is(uint == typeof(CONST_UINT2())));
+ static assert(is(uint == typeof(CONST_UINT3())));
+ static assert(is(uint == typeof(CONST_UINT4())));
+ static assert(is(int == typeof(CONST_LONG1())));
+ static assert(is(int == typeof(CONST_LONG2())));
+ static assert(is(int == typeof(CONST_LONG3())));
+ static assert(is(int == typeof(CONST_LONG4())));
+ static assert(is(long == typeof(CONST_LLONG1())));
+ static assert(is(long == typeof(CONST_LLONG2())));
+ static assert(is(long == typeof(CONST_LLONG3())));
+ static assert(is(long == typeof(CONST_LLONG4())));
+ static assert(is(ulong == typeof(CONST_ULLONG1())));
+ static assert(is(ulong == typeof(CONST_ULLONG2())));
+ static assert(is(ulong == typeof(CONST_ULLONG3())));
+ static assert(is(ulong == typeof(CONST_ULLONG4())));
+ static assert(is(double == typeof(CONST_DOUBLE1())));
+ static assert(is(double == typeof(CONST_DOUBLE2())));
+ static assert(is(double == typeof(CONST_DOUBLE3())));
+ static assert(is(double == typeof(CONST_DOUBLE4())));
+ static assert(is(double == typeof(CONST_DOUBLE5())));
+ static assert(is(double == typeof(CONST_DOUBLE6())));
+ static assert(is(bool == typeof(CONST_BOOL1())));
+ static assert(is(bool == typeof(CONST_BOOL2())));
+ static assert(is(char == typeof(CONST_CHAR())));
+ static assert(is(char[] == typeof(CONST_STRING1())));
+ static assert(is(char[] == typeof(CONST_STRING2())));
+
+ static assert(is(int == typeof(INT_AND_BOOL())));
+// static assert(is(int == typeof(INT_AND_CHAR())));
+ static assert(is(int == typeof(INT_AND_INT())));
+ static assert(is(uint == typeof(INT_AND_UINT())));
+ static assert(is(int == typeof(INT_AND_LONG())));
+ static assert(is(uint == typeof(INT_AND_ULONG())));
+ static assert(is(long == typeof(INT_AND_LLONG())));
+ static assert(is(ulong == typeof(INT_AND_ULLONG())));
+ static assert(is(int == typeof(BOOL_AND_BOOL())));
+
+ static assert(is(int == typeof(EXPR_MULTIPLY())));
+ static assert(is(int == typeof(EXPR_DIVIDE())));
+ static assert(is(int == typeof(EXPR_PLUS())));
+ static assert(is(int == typeof(EXPR_MINUS())));
+ static assert(is(int == typeof(EXPR_LSHIFT())));
+ static assert(is(int == typeof(EXPR_RSHIFT())));
+ static assert(is(bool == typeof(EXPR_LTE())));
+ static assert(is(bool == typeof(EXPR_GTE())));
+ static assert(is(bool == typeof(EXPR_INEQUALITY())));
+ static assert(is(bool == typeof(EXPR_EQUALITY())));
+ static assert(is(int == typeof(EXPR_AND())));
+ static assert(is(int == typeof(EXPR_XOR())));
+ static assert(is(int == typeof(EXPR_OR())));
+ static assert(is(bool == typeof(EXPR_LAND())));
+ static assert(is(bool == typeof(EXPR_LOR())));
+ static assert(is(double == typeof(EXPR_CONDITIONAL())));
+}
diff --git a/Examples/test-suite/d/preproc_constants_runme.2.d b/Examples/test-suite/d/preproc_constants_runme.2.d
new file mode 100644
index 000000000..e2eab2c46
--- /dev/null
+++ b/Examples/test-suite/d/preproc_constants_runme.2.d
@@ -0,0 +1,62 @@
+module preproc_constants_runme;
+
+import preproc_constants.preproc_constants;
+
+void main() {
+ static assert(is(int == typeof(CONST_INT1())));
+ static assert(is(int == typeof(CONST_INT2())));
+ static assert(is(uint == typeof(CONST_UINT1())));
+ static assert(is(uint == typeof(CONST_UINT2())));
+ static assert(is(uint == typeof(CONST_UINT3())));
+ static assert(is(uint == typeof(CONST_UINT4())));
+ static assert(is(int == typeof(CONST_LONG1())));
+ static assert(is(int == typeof(CONST_LONG2())));
+ static assert(is(int == typeof(CONST_LONG3())));
+ static assert(is(int == typeof(CONST_LONG4())));
+ static assert(is(long == typeof(CONST_LLONG1())));
+ static assert(is(long == typeof(CONST_LLONG2())));
+ static assert(is(long == typeof(CONST_LLONG3())));
+ static assert(is(long == typeof(CONST_LLONG4())));
+ static assert(is(ulong == typeof(CONST_ULLONG1())));
+ static assert(is(ulong == typeof(CONST_ULLONG2())));
+ static assert(is(ulong == typeof(CONST_ULLONG3())));
+ static assert(is(ulong == typeof(CONST_ULLONG4())));
+ static assert(is(double == typeof(CONST_DOUBLE1())));
+ static assert(is(double == typeof(CONST_DOUBLE2())));
+ static assert(is(double == typeof(CONST_DOUBLE3())));
+ static assert(is(double == typeof(CONST_DOUBLE4())));
+ static assert(is(double == typeof(CONST_DOUBLE5())));
+ static assert(is(double == typeof(CONST_DOUBLE6())));
+ static assert(is(bool == typeof(CONST_BOOL1())));
+ static assert(is(bool == typeof(CONST_BOOL2())));
+ static assert(is(char == typeof(CONST_CHAR())));
+ static assert(is(string == typeof(CONST_STRING1())));
+ static assert(is(string == typeof(CONST_STRING2())));
+
+ static assert(is(int == typeof(INT_AND_BOOL())));
+// static assert(is(int == typeof(INT_AND_CHAR())));
+ static assert(is(int == typeof(INT_AND_INT())));
+ static assert(is(uint == typeof(INT_AND_UINT())));
+ static assert(is(int == typeof(INT_AND_LONG())));
+ static assert(is(uint == typeof(INT_AND_ULONG())));
+ static assert(is(long == typeof(INT_AND_LLONG())));
+ static assert(is(ulong == typeof(INT_AND_ULLONG())));
+ static assert(is(int == typeof(BOOL_AND_BOOL())));
+
+ static assert(is(int == typeof(EXPR_MULTIPLY())));
+ static assert(is(int == typeof(EXPR_DIVIDE())));
+ static assert(is(int == typeof(EXPR_PLUS())));
+ static assert(is(int == typeof(EXPR_MINUS())));
+ static assert(is(int == typeof(EXPR_LSHIFT())));
+ static assert(is(int == typeof(EXPR_RSHIFT())));
+ static assert(is(bool == typeof(EXPR_LTE())));
+ static assert(is(bool == typeof(EXPR_GTE())));
+ static assert(is(bool == typeof(EXPR_INEQUALITY())));
+ static assert(is(bool == typeof(EXPR_EQUALITY())));
+ static assert(is(int == typeof(EXPR_AND())));
+ static assert(is(int == typeof(EXPR_XOR())));
+ static assert(is(int == typeof(EXPR_OR())));
+ static assert(is(bool == typeof(EXPR_LAND())));
+ static assert(is(bool == typeof(EXPR_LOR())));
+ static assert(is(double == typeof(EXPR_CONDITIONAL())));
+}
diff --git a/Examples/test-suite/d/sizet_runme.1.d b/Examples/test-suite/d/sizet_runme.1.d
new file mode 100644
index 000000000..ae42e20e5
--- /dev/null
+++ b/Examples/test-suite/d/sizet_runme.1.d
@@ -0,0 +1,15 @@
+module sizet_runme;
+
+import sizet.sizet;
+
+void main() {
+ size_t s = 2000;
+ s = test1(s+1);
+ s = test2(s+1);
+ s = test3(s+1);
+ s = test4(s+1);
+
+ if (s != 2004) {
+ throw new Exception("failed");
+ }
+}
diff --git a/Examples/test-suite/d/sizet_runme.2.d b/Examples/test-suite/d/sizet_runme.2.d
new file mode 100644
index 000000000..63eb03b21
--- /dev/null
+++ b/Examples/test-suite/d/sizet_runme.2.d
@@ -0,0 +1,14 @@
+module sizet_runme;
+
+import std.exception;
+import sizet.sizet;
+
+void main() {
+ size_t s = 2000;
+ s = test1(s+1);
+ s = test2(s+1);
+ s = test3(s+1);
+ s = test4(s+1);
+
+ enforce(s == 2004, "failed");
+}
diff --git a/Examples/test-suite/d/sneaky1_runme.1.d b/Examples/test-suite/d/sneaky1_runme.1.d
new file mode 100644
index 000000000..b293b4972
--- /dev/null
+++ b/Examples/test-suite/d/sneaky1_runme.1.d
@@ -0,0 +1,21 @@
+module sneaky1_runme;
+
+import sneaky1.sneaky1;
+
+void main() {
+ if (add(30, 2) != 32) {
+ throw new Exception("add test failed");
+ }
+
+ if (subtract(20, 2) != 18) {
+ throw new Exception("subtract test failed");
+ }
+
+ if (mul(20, 2) != 40) {
+ throw new Exception("mul test failed");
+ }
+
+ if (divide(20, 2) != 10) {
+ throw new Exception("div test failed");
+ }
+}
diff --git a/Examples/test-suite/d/sneaky1_runme.2.d b/Examples/test-suite/d/sneaky1_runme.2.d
new file mode 100644
index 000000000..84e51e74d
--- /dev/null
+++ b/Examples/test-suite/d/sneaky1_runme.2.d
@@ -0,0 +1,11 @@
+module sneaky1_runme;
+
+import std.exception;
+import sneaky1.sneaky1;
+
+void main() {
+ enforce(add(30, 2) == 32, "add test failed");
+ enforce(subtract(20, 2) == 18, "subtract test failed");
+ enforce(mul(20, 2) == 40, "mul test failed");
+ enforce(divide(20, 2) == 10, "div test failed");
+}
diff --git a/Examples/test-suite/d/special_variable_macros_runme.1.d b/Examples/test-suite/d/special_variable_macros_runme.1.d
new file mode 100644
index 000000000..12491eef5
--- /dev/null
+++ b/Examples/test-suite/d/special_variable_macros_runme.1.d
@@ -0,0 +1,39 @@
+module special_variable_macros_runme;
+
+import special_variable_macros.special_variable_macros;
+import special_variable_macros.Name;
+import special_variable_macros.NewName;
+import special_variable_macros.PairIntBool;
+
+void main() {
+ auto name = new Name();
+
+ if (testFred(name) != "none") {
+ throw new Exception("test failed");
+ }
+
+ if (testJack(name) != "$specialname") {
+ throw new Exception("test failed");
+ }
+
+ if (testJill(name) != "jilly") {
+ throw new Exception("test failed");
+ }
+
+ if (testMary(name) != "SWIGTYPE_p_NameWrap") {
+ throw new Exception("test failed");
+ }
+
+ if (testJim(name) != "multiname num") {
+ throw new Exception("test failed");
+ }
+
+ if (testJohn(new PairIntBool(10, false)) != 123) {
+ throw new Exception("test failed");
+ }
+
+ auto newName = NewName.factory("factoryname");
+ if (newName.getStoredName().getName() != "factoryname") {
+ throw new Exception("test failed");
+ }
+}
diff --git a/Examples/test-suite/d/special_variable_macros_runme.2.d b/Examples/test-suite/d/special_variable_macros_runme.2.d
new file mode 100644
index 000000000..128e5870f
--- /dev/null
+++ b/Examples/test-suite/d/special_variable_macros_runme.2.d
@@ -0,0 +1,21 @@
+module special_variable_macros_runme;
+
+import std.exception;
+import special_variable_macros.special_variable_macros;
+import special_variable_macros.Name;
+import special_variable_macros.NewName;
+import special_variable_macros.PairIntBool;
+
+void main() {
+ auto name = new Name();
+ enforce(testFred(name) == "none");
+ enforce(testJack(name) == "$specialname");
+ enforce(testJill(name) == "jilly");
+ enforce(testMary(name) == "SWIGTYPE_p_NameWrap");
+ enforce(testJim(name) == "multiname num");
+
+ enforce(testJohn(new PairIntBool(10, false)) == 123);
+
+ auto newName = NewName.factory("factoryname");
+ enforce(newName.getStoredName().getName() == "factoryname");
+}
diff --git a/Examples/test-suite/d/threads_runme.1.d b/Examples/test-suite/d/threads_runme.1.d
new file mode 100644
index 000000000..206875824
--- /dev/null
+++ b/Examples/test-suite/d/threads_runme.1.d
@@ -0,0 +1,70 @@
+module threads_runme;
+
+import tango.core.Thread;
+import tango.io.Console;
+import Integer = tango.text.convert.Integer;
+import threads.Kerfuffle;
+
+// Spawn 8 threads.
+const uint NUM_THREADS = 8;
+
+// Run test for a few seconds on a 1GHz machine.
+const uint WORKER_LOOP_PASSES = 30000;
+
+void main() {
+ auto kerf = new Kerfuffle();
+ TestThread[] threads;
+
+ // Invoke the threads.
+ for (uint i = 0; i < NUM_THREADS; i++) {
+ auto thread = new TestThread(kerf);
+ threads ~= thread;
+ thread.name = Integer.toString(i);
+ thread.start();
+ }
+
+ // Wait for the threads to finish.
+ foreach(thread; threads) {
+ thread.join();
+ }
+
+ // Check if any thread has failed.
+ foreach(thread; threads) {
+ if (thread.failed) throw new Exception("Test failed.");
+ }
+}
+
+class TestThread : Thread {
+public:
+ this(Kerfuffle kerf) {
+ super(&run);
+ m_kerf = kerf;
+ }
+
+ void run() {
+ failed = false;
+ try {
+ for (uint i = 0; i < WORKER_LOOP_PASSES; i++) {
+ char[] given = "This is the test char[] that should come back. A number: " ~ Integer.toString(i);
+ char[] received = m_kerf.StdString(given);
+ if (received != given) {
+ throw new Exception("StdString char[] does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'.");
+ }
+ }
+ for (uint i = 0; i < WORKER_LOOP_PASSES; i++) {
+ char[] given = "This is the test char[] that should come back. A number: " ~ Integer.toString(i);
+ char[] received = m_kerf.CharString(given);
+ if (received != given) {
+ throw new Exception("StdString char[] does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'.");
+ }
+ }
+ } catch (Exception e) {
+ Cerr("Test failed (thread " ~ name() ~ "): " ~ e.msg).newline;
+ failed = true;
+ }
+ }
+
+ bool failed;
+private:
+ Kerfuffle m_kerf;
+}
diff --git a/Examples/test-suite/d/threads_runme.2.d b/Examples/test-suite/d/threads_runme.2.d
new file mode 100644
index 000000000..3ac27a5a8
--- /dev/null
+++ b/Examples/test-suite/d/threads_runme.2.d
@@ -0,0 +1,55 @@
+module threads_runme;
+
+import core.thread;
+import std.conv;
+import std.exception;
+import std.range;
+import std.stdio;
+import threads.Kerfuffle;
+
+// Spawn 8 threads.
+enum THREADS = iota(0, 9);
+
+// Run test for a few seconds on a 1GHz machine.
+enum WORK_RANGE = iota(0, 30000);
+
+void main() {
+ auto kerf = new Kerfuffle();
+ TestThread[] threads;
+
+ // Invoke the threads.
+ foreach (i; THREADS) {
+ auto thread = new TestThread(kerf);
+ threads ~= thread;
+ thread.name = to!string(i);
+ thread.start();
+ }
+
+ // Wait for the threads to finish.
+ foreach (i, thread; threads) {
+ thread.join(true);
+ }
+}
+
+class TestThread : Thread {
+ this(Kerfuffle kerf) {
+ super(&run);
+ m_kerf = kerf;
+ }
+
+ void run() {
+ foreach (i; WORK_RANGE) {
+ string given = "This is the test string that should come back. A number: " ~ to!string(i);
+ string received = m_kerf.StdString(given);
+ enforce(received == given, "StdString string does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'.");
+ }
+ foreach (i; WORK_RANGE) {
+ string given = "This is the test string that should come back. A number: " ~ to!string(i);
+ string received = m_kerf.CharString(given);
+ enforce(received == given, "CharString string does not match. Received: '" ~ received ~ "'. Expected: '" ~ given ~ "'.");
+ }
+ }
+
+private:
+ Kerfuffle m_kerf;
+}
diff --git a/Examples/test-suite/d/throw_exception_runme.1.d b/Examples/test-suite/d/throw_exception_runme.1.d
new file mode 100644
index 000000000..f2397a202
--- /dev/null
+++ b/Examples/test-suite/d/throw_exception_runme.1.d
@@ -0,0 +1,30 @@
+module throw_exception_runme;
+
+import throw_exception.Foo;
+
+void main() {
+ test!("test_int");
+ test!("test_msg");
+ test!("test_cls");
+ test!("test_cls_ptr");
+ test!("test_cls_ref");
+ test!("test_cls_td");
+ test!("test_cls_ptr_td");
+ test!("test_cls_ref_td");
+ test!("test_array");
+ test!("test_enum");
+}
+
+void test(char[] methodName)() {
+ auto foo = new Foo();
+
+ bool didntThrow;
+ try {
+ mixin("foo." ~ methodName ~ "();");
+ didntThrow = true;
+ } catch (Exception) {}
+
+ if (didntThrow) {
+ throw new Exception(methodName ~ " failed");
+ }
+}
diff --git a/Examples/test-suite/d/throw_exception_runme.2.d b/Examples/test-suite/d/throw_exception_runme.2.d
new file mode 100644
index 000000000..6fc82a93d
--- /dev/null
+++ b/Examples/test-suite/d/throw_exception_runme.2.d
@@ -0,0 +1,30 @@
+module throw_exception_runme;
+
+import throw_exception.Foo;
+
+void main() {
+ test!("test_int");
+ test!("test_msg");
+ test!("test_cls");
+ test!("test_cls_ptr");
+ test!("test_cls_ref");
+ test!("test_cls_td");
+ test!("test_cls_ptr_td");
+ test!("test_cls_ref_td");
+ test!("test_array");
+ test!("test_enum");
+}
+
+void test(string methodName)() {
+ auto foo = new Foo();
+
+ bool didntThrow;
+ try {
+ mixin("foo." ~ methodName ~ "();");
+ didntThrow = true;
+ } catch (Exception) {}
+
+ if (didntThrow) {
+ throw new Exception(methodName ~ " failed");
+ }
+}
diff --git a/Examples/test-suite/d/typemap_namespace_runme.1.d b/Examples/test-suite/d/typemap_namespace_runme.1.d
new file mode 100644
index 000000000..3a5ca1a9f
--- /dev/null
+++ b/Examples/test-suite/d/typemap_namespace_runme.1.d
@@ -0,0 +1,13 @@
+module typemap_namespace_runme;
+
+import typemap_namespace.typemap_namespace;
+
+void main() {
+ if (test1("hello") != "hello") {
+ throw new Exception("test1 failed");
+ }
+
+ if (test2("hello") != "hello") {
+ throw new Exception("test2 failed");
+ }
+}
diff --git a/Examples/test-suite/d/typemap_namespace_runme.2.d b/Examples/test-suite/d/typemap_namespace_runme.2.d
new file mode 100644
index 000000000..2281e403b
--- /dev/null
+++ b/Examples/test-suite/d/typemap_namespace_runme.2.d
@@ -0,0 +1,9 @@
+module typemap_namespace_runme;
+
+import std.exception;
+import typemap_namespace.typemap_namespace;
+
+void main() {
+ enforce(test1("hello") == "hello", "test1 failed");
+ enforce(test2("hello") == "hello", "test2 failed");
+}
diff --git a/Examples/test-suite/d/typemap_out_optimal_runme.1.d b/Examples/test-suite/d/typemap_out_optimal_runme.1.d
new file mode 100644
index 000000000..16aab3cff
--- /dev/null
+++ b/Examples/test-suite/d/typemap_out_optimal_runme.1.d
@@ -0,0 +1,9 @@
+module typemap_out_optimal_runme;
+
+import typemap_out_optimal.XX;
+
+void main() {
+ XX x;
+ XX.trace = false;
+ x = XX.create();
+}
diff --git a/Examples/test-suite/d/typemap_out_optimal_runme.2.d b/Examples/test-suite/d/typemap_out_optimal_runme.2.d
new file mode 100644
index 000000000..16aab3cff
--- /dev/null
+++ b/Examples/test-suite/d/typemap_out_optimal_runme.2.d
@@ -0,0 +1,9 @@
+module typemap_out_optimal_runme;
+
+import typemap_out_optimal.XX;
+
+void main() {
+ XX x;
+ XX.trace = false;
+ x = XX.create();
+}
diff --git a/Examples/test-suite/d/varargs_runme.1.d b/Examples/test-suite/d/varargs_runme.1.d
new file mode 100644
index 000000000..53f76d075
--- /dev/null
+++ b/Examples/test-suite/d/varargs_runme.1.d
@@ -0,0 +1,20 @@
+module varargs_runme;
+
+import varargs.varargs;
+import varargs.Foo;
+
+void main() {
+ if (test("Hello") != "Hello") {
+ throw new Exception("Test 1 failed");
+ }
+
+ auto f = new Foo("Greetings");
+
+ if (f.str != "Greetings") {
+ throw new Exception("Test 2 failed");
+ }
+
+ if (f.test("Hello") != "Hello") {
+ throw new Exception("Test 3 failed");
+ }
+}
diff --git a/Examples/test-suite/d/varargs_runme.2.d b/Examples/test-suite/d/varargs_runme.2.d
new file mode 100644
index 000000000..b2b5ceddc
--- /dev/null
+++ b/Examples/test-suite/d/varargs_runme.2.d
@@ -0,0 +1,13 @@
+module varargs_runme;
+
+import std.exception;
+import varargs.varargs;
+import varargs.Foo;
+
+void main() {
+ enforce(test("Hello") == "Hello", "Test 1 failed");
+
+ auto f = new Foo("Greetings");
+ enforce(f.str == "Greetings", "Test 2 failed");
+ enforce(f.test("Hello") == "Hello", "Test 3 failed");
+}
diff --git a/Examples/test-suite/d/virtual_poly_runme.1.d b/Examples/test-suite/d/virtual_poly_runme.1.d
new file mode 100644
index 000000000..fb2e7814d
--- /dev/null
+++ b/Examples/test-suite/d/virtual_poly_runme.1.d
@@ -0,0 +1,27 @@
+module virtual_poly_runme;
+
+import virtual_poly.NDouble;
+import virtual_poly.NInt;
+import virtual_poly.NNumber;
+
+void main() {
+ // D supports covariant (polymorphic) return types, so this should work like
+ // in C++.
+ auto d = new NDouble(3.5);
+ NDouble dc = d.copy();
+ if (d.get() != dc.get()) {
+ throw new Exception("Test 1 failed.");
+ }
+
+ auto i = new NInt(2);
+ NInt ic = i.copy();
+ if (i.get() != ic.get()) {
+ throw new Exception("Test 2 failed.");
+ }
+
+ NNumber n = d;
+ auto nd = cast(NDouble) n.copy();
+ if (nd.get() != d.get()) {
+ throw new Exception("Test 3 failed.");
+ }
+}
diff --git a/Examples/test-suite/d/virtual_poly_runme.2.d b/Examples/test-suite/d/virtual_poly_runme.2.d
new file mode 100644
index 000000000..f749ee236
--- /dev/null
+++ b/Examples/test-suite/d/virtual_poly_runme.2.d
@@ -0,0 +1,22 @@
+module virtual_poly_runme;
+
+import std.exception;
+import virtual_poly.NDouble;
+import virtual_poly.NInt;
+import virtual_poly.NNumber;
+
+void main() {
+ // D supports covariant (polymorphic) return types, so this should work like
+ // in C++.
+ auto d = new NDouble(3.5);
+ NDouble dc = d.copy();
+ enforce(d.get() == dc.get(), "Test 1 failed.");
+
+ auto i = new NInt(2);
+ NInt ic = i.copy();
+ enforce(i.get() == ic.get(), "Test 2 failed.");
+
+ NNumber n = d;
+ auto nd = cast(NDouble) n.copy();
+ enforce(nd.get() == d.get(), "Test 3 failed.");
+}
diff --git a/Examples/test-suite/d_nativepointers.i b/Examples/test-suite/d_nativepointers.i
new file mode 100644
index 000000000..b681844f5
--- /dev/null
+++ b/Examples/test-suite/d_nativepointers.i
@@ -0,0 +1,18 @@
+%module d_nativepointers;
+
+%inline %{
+ class SomeClass {
+ };
+ class OpaqueClass;
+ typedef void (*FuncA)(int **x, char ***y);
+ typedef void (*FuncB)(int **x, SomeClass *y);
+
+ int *a( int *value ){ return value; }
+ float **b( float **value ){ return value; }
+ char ***c( char ***value ){ return value; }
+ SomeClass *d( SomeClass *value ){ return value; }
+ SomeClass **e( SomeClass **value ){ return value; }
+ OpaqueClass *f( OpaqueClass *value ){ return value; }
+ FuncA g( FuncA value ){ return value; }
+ FuncB* h( FuncB* value ){ return value; }
+%}
diff --git a/Lib/allkw.swg b/Lib/allkw.swg
index fb76ff287..2e0dad6cf 100644
--- a/Lib/allkw.swg
+++ b/Lib/allkw.swg
@@ -18,6 +18,7 @@
%include
%include
+%include
%include
%include
%include
diff --git a/Lib/d/boost_shared_ptr.i b/Lib/d/boost_shared_ptr.i
new file mode 100644
index 000000000..97feee5cb
--- /dev/null
+++ b/Lib/d/boost_shared_ptr.i
@@ -0,0 +1,201 @@
+%include
+
+%define SWIG_SHARED_PTR_TYPEMAPS(CONST, TYPE...)
+
+%naturalvar TYPE;
+%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
+
+// destructor mods
+%feature("unref") TYPE
+//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ((*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\"))) << \"]\" << endl << flush; }\n"
+ "(void)arg1; delete smartarg1;"
+
+
+// plain value
+%typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0) %{
+ argp = ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0;
+ if (!argp) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type");
+ return $null;
+ }
+ $1 = *argp; %}
+%typemap(out) CONST TYPE
+%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(new $1_ltype(($1_ltype &)$1)); %}
+
+// plain pointer
+%typemap(in, canthrow=1) CONST TYPE * (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
+ smartarg = (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input;
+ $1 = (TYPE *)(smartarg ? smartarg->get() : 0); %}
+%typemap(out, fragment="SWIG_null_deleter") CONST TYPE * %{
+ $result = $1 ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner) : 0;
+%}
+
+// plain reference
+%typemap(in, canthrow=1) CONST TYPE & %{
+ $1 = ($1_ltype)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
+ if (!$1) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type reference is null");
+ return $null;
+ } %}
+%typemap(out, fragment="SWIG_null_deleter") CONST TYPE &
+%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >($1 SWIG_NO_NULL_DELETER_$owner); %}
+
+// plain pointer by reference
+%typemap(in) TYPE *CONST& ($*1_ltype temp = 0)
+%{ temp = (TYPE *)(((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input) ? ((SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *)$input)->get() : 0);
+ $1 = &temp; %}
+%typemap(out, fragment="SWIG_null_deleter") TYPE *CONST&
+%{ $result = new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(*$1 SWIG_NO_NULL_DELETER_$owner); %}
+
+// shared_ptr by value
+%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
+%{ if ($input) $1 = *($&1_ltype)$input; %}
+%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >
+%{ $result = $1 ? new $1_ltype($1) : 0; %}
+
+// shared_ptr by reference
+%typemap(in, canthrow=1) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & ($*1_ltype tempnull)
+%{ $1 = $input ? ($1_ltype)$input : &tempnull; %}
+%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &
+%{ $result = *$1 ? new $*1_ltype(*$1) : 0; %}
+
+// shared_ptr by pointer
+%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;
+ if ($owner) delete $1; %}
+
+// shared_ptr by pointer reference
+%typemap(in) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& (SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > tempnull, $*1_ltype temp = 0)
+%{ temp = $input ? *($1_ltype)&$input : &tempnull;
+ $1 = &temp; %}
+%typemap(out) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *&
+%{ *($1_ltype)&$result = (*$1 && **$1) ? new SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >(**$1) : 0; %}
+
+// various missing typemaps - If ever used (unlikely) ensure compilation error rather than runtime bug
+%typemap(in) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
+#error "typemaps for $1_type not available"
+%}
+%typemap(out) CONST TYPE[], CONST TYPE[ANY], CONST TYPE (CLASS::*) %{
+#error "typemaps for $1_type not available"
+%}
+
+
+%typemap (cwtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "void *"
+%typemap (dwtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "void*"
+%typemap (dptype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(dptype, TYPE)"
+
+%typemap(din) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(dptype, TYPE).swigGetCPtr($dinput)"
+
+%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+
+
+%typemap(dout, excode=SWIGEXCODE) CONST TYPE {
+ auto ret = new $typemap(dptype, TYPE)($wcall, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) CONST TYPE & {
+ auto ret = new $typemap(dptype, TYPE)($wcall, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) CONST TYPE * {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+%typemap(dout, excode=SWIGEXCODE) TYPE *CONST& {
+ void* cPtr = $wcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ return ret;
+}
+
+// For shared pointers, both the derived and the base class have to »own« their
+// pointer; otherwise the reference count is not decreased properly on destruction.
+%typemap(dbody) SWIGTYPE %{
+private void* swigCPtr;
+private bool swigCMemOwn;
+
+public this(void* cObject, bool ownCObject) {
+ swigCPtr = cObject;
+ swigCMemOwn = ownCObject;
+}
+
+public static void* swigGetCPtr($dclassname obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+%}
+
+%typemap(dbody_derived) SWIGTYPE %{
+private void* swigCPtr;
+private bool swigCMemOwn;
+
+public this(void* cObject, bool ownCObject) {
+ super($wrapdmodule.$dclassnameSmartPtrUpcast(cObject), ownCObject);
+ swigCPtr = cObject;
+ swigCMemOwn = ownCObject;
+}
+
+public static void* swigGetCPtr($dclassname obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+%}
+
+%typemap(ddispose, methodname="dispose", methodmodifiers="public") TYPE {
+ synchronized(this) {
+ if (swigCPtr !is null) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ $wcall;
+ }
+ swigCPtr = null;
+ }
+ }
+}
+
+%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public") TYPE {
+ synchronized(this) {
+ if (swigCPtr !is null) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ $wcall;
+ }
+ swigCPtr = null;
+ super.dispose();
+ }
+ }
+}
+
+%template() SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
+%enddef
diff --git a/Lib/d/carrays.i b/Lib/d/carrays.i
new file mode 100644
index 000000000..9893d09e5
--- /dev/null
+++ b/Lib/d/carrays.i
@@ -0,0 +1,111 @@
+/* -----------------------------------------------------------------------------
+ * carrays.i
+ *
+ * D-specific version of ../carrays.i.
+ * ----------------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * %array_functions(TYPE,NAME)
+ *
+ * Generates functions for creating and accessing elements of a C array
+ * (as pointers). Creates the following functions:
+ *
+ * TYPE *new_NAME(int nelements)
+ * void delete_NAME(TYPE *);
+ * TYPE NAME_getitem(TYPE *, int index);
+ * void NAME_setitem(TYPE *, int index, TYPE value);
+ *
+ * ----------------------------------------------------------------------------- */
+
+%define %array_functions(TYPE,NAME)
+%{
+static TYPE *new_##NAME(int nelements) { %}
+#ifdef __cplusplus
+%{ return new TYPE[nelements]; %}
+#else
+%{ return (TYPE *) calloc(nelements,sizeof(TYPE)); %}
+#endif
+%{}
+
+static void delete_##NAME(TYPE *ary) { %}
+#ifdef __cplusplus
+%{ delete [] ary; %}
+#else
+%{ free(ary); %}
+#endif
+%{}
+
+static TYPE NAME##_getitem(TYPE *ary, int index) {
+ return ary[index];
+}
+static void NAME##_setitem(TYPE *ary, int index, TYPE value) {
+ ary[index] = value;
+}
+%}
+
+TYPE *new_##NAME(int nelements);
+void delete_##NAME(TYPE *ary);
+TYPE NAME##_getitem(TYPE *ary, int index);
+void NAME##_setitem(TYPE *ary, int index, TYPE value);
+
+%enddef
+
+
+/* -----------------------------------------------------------------------------
+ * %array_class(TYPE,NAME)
+ *
+ * Generates a class wrapper around a C array. The class has the following
+ * interface:
+ *
+ * struct NAME {
+ * NAME(int nelements);
+ * ~NAME();
+ * TYPE getitem(int index);
+ * void setitem(int index, TYPE value);
+ * TYPE * ptr();
+ * static NAME *frompointer(TYPE *t);
+ * }
+ *
+ * ----------------------------------------------------------------------------- */
+
+%define %array_class(TYPE,NAME)
+%{
+typedef TYPE NAME;
+%}
+
+typedef struct NAME {} NAME;
+
+%extend NAME {
+#ifdef __cplusplus
+ NAME(int nelements) {
+ return new TYPE[nelements];
+ }
+ ~NAME() {
+ delete [] self;
+ }
+#else
+ NAME(int 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;
+ }
+};
+
+%types(NAME = TYPE);
+
+%enddef
diff --git a/Lib/d/cpointer.i b/Lib/d/cpointer.i
new file mode 100644
index 000000000..75e610f67
--- /dev/null
+++ b/Lib/d/cpointer.i
@@ -0,0 +1,171 @@
+/* -----------------------------------------------------------------------------
+ * cpointer.i
+ *
+ * D-specific version of ../cpointer.i.
+ * ----------------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ * %pointer_class(type,name)
+ *
+ * Places a simple proxy around a simple type like 'int', 'float', or whatever.
+ * The proxy provides this interface:
+ *
+ * class type {
+ * public:
+ * type();
+ * ~type();
+ * type value();
+ * void assign(type value);
+ * };
+ *
+ * Example:
+ *
+ * %pointer_class(int, intp);
+ *
+ * int add(int *x, int *y) { return *x + *y; }
+ *
+ * In python (with proxies)
+ *
+ * >>> a = intp()
+ * >>> a.assign(10)
+ * >>> a.value()
+ * 10
+ * >>> b = intp()
+ * >>> b.assign(20)
+ * >>> print add(a,b)
+ * 30
+ *
+ * As a general rule, this macro should not be used on class/structures that
+ * are already defined in the interface.
+ * ----------------------------------------------------------------------------- */
+
+
+%define %pointer_class(TYPE, NAME)
+%{
+typedef TYPE NAME;
+%}
+
+typedef struct {
+} NAME;
+
+%extend NAME {
+#ifdef __cplusplus
+NAME() {
+ return new TYPE();
+}
+~NAME() {
+ if (self) delete self;
+}
+#else
+NAME() {
+ return (TYPE *) calloc(1,sizeof(TYPE));
+}
+~NAME() {
+ if (self) free(self);
+}
+#endif
+}
+
+%extend NAME {
+
+void assign(TYPE value) {
+ *self = value;
+}
+TYPE value() {
+ return *self;
+}
+TYPE * ptr() {
+ return self;
+}
+static NAME * frompointer(TYPE *t) {
+ return (NAME *) t;
+}
+
+}
+
+%types(NAME = TYPE);
+
+%enddef
+
+/* -----------------------------------------------------------------------------
+ * %pointer_functions(type,name)
+ *
+ * Create functions for allocating/deallocating pointers. This can be used
+ * if you don't want to create a proxy class or if the pointer is complex.
+ *
+ * %pointer_functions(int, intp)
+ *
+ * int add(int *x, int *y) { return *x + *y; }
+ *
+ * In python (with proxies)
+ *
+ * >>> a = copy_intp(10)
+ * >>> intp_value(a)
+ * 10
+ * >>> b = new_intp()
+ * >>> intp_assign(b,20)
+ * >>> print add(a,b)
+ * 30
+ * >>> delete_intp(a)
+ * >>> delete_intp(b)
+ *
+ * ----------------------------------------------------------------------------- */
+
+%define %pointer_functions(TYPE,NAME)
+%{
+static TYPE *new_##NAME() { %}
+#ifdef __cplusplus
+%{ return new TYPE(); %}
+#else
+%{ return (TYPE *) calloc(1,sizeof(TYPE)); %}
+#endif
+%{}
+
+static TYPE *copy_##NAME(TYPE value) { %}
+#ifdef __cplusplus
+%{ return new TYPE(value); %}
+#else
+%{ TYPE *self = (TYPE *) calloc(1,sizeof(TYPE));
+ *self = value;
+ return self; %}
+#endif
+%{}
+
+static void delete_##NAME(TYPE *self) { %}
+#ifdef __cplusplus
+%{ if (self) delete self; %}
+#else
+%{ if (self) free(self); %}
+#endif
+%{}
+
+static void NAME ##_assign(TYPE *self, TYPE value) {
+ *self = value;
+}
+
+static TYPE NAME ##_value(TYPE *self) {
+ return *self;
+}
+%}
+
+TYPE *new_##NAME();
+TYPE *copy_##NAME(TYPE value);
+void delete_##NAME(TYPE *self);
+void NAME##_assign(TYPE *self, TYPE value);
+TYPE NAME##_value(TYPE *self);
+
+%enddef
+
+/* -----------------------------------------------------------------------------
+ * %pointer_cast(type1,type2,name)
+ *
+ * Generates a pointer casting function.
+ * ----------------------------------------------------------------------------- */
+
+%define %pointer_cast(TYPE1,TYPE2,NAME)
+%inline %{
+TYPE2 NAME(TYPE1 x) {
+ return (TYPE2) x;
+}
+%}
+%enddef
diff --git a/Lib/d/d.swg b/Lib/d/d.swg
new file mode 100644
index 000000000..f5bb4596c
--- /dev/null
+++ b/Lib/d/d.swg
@@ -0,0 +1,46 @@
+/* -----------------------------------------------------------------------------
+ * d.swg
+ *
+ * Main library file for the D language module. See the D chapter in the SWIG
+ * manual for explanation on the typemaps, pragmas, etc. used.
+ * ----------------------------------------------------------------------------- */
+
+// Typemaps for exception handling.
+%include
+
+// Typemaps for primitive types.
+%include
+
+// Typemaps for non-primitive types (C/C++ classes and structs).
+%include
+
+// Typemaps for enumeration types.
+%include
+
+// Typemaps for member function pointers.
+%include
+
+// Typemaps for wrapping pointers to/arrays of C chars as D strings.
+%include
+
+// Typemaps for handling void function return types and empty parameter lists.
+%include
+
+// Typemaps containing D code used when generating D proxy classes.
+%include
+
+// Mapping of C++ operator overloading methods to D.
+%include
+
+// Helper code string and exception handling.
+%include
+
+// Wrapper loader code for dynamically linking the C wrapper library from the D
+// wrapper module.
+%include
+
+// List of all reserved D keywords.
+%include
+
+// D-specific directives.
+%include
diff --git a/Lib/d/dclassgen.swg b/Lib/d/dclassgen.swg
new file mode 100644
index 000000000..bc73d7b6a
--- /dev/null
+++ b/Lib/d/dclassgen.swg
@@ -0,0 +1,172 @@
+/* -----------------------------------------------------------------------------
+ * dclassgen.swg
+ *
+ * Typemaps containing D code used when generating D proxy classes.
+ * ----------------------------------------------------------------------------- */
+
+%typemap(dbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(dclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "class"
+%typemap(dcode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(dimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(dinterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(dinterfaces_derived) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+
+// See .
+%typemap(dclassmodifiers) enum SWIGTYPE "enum"
+%typemap(dcode) enum SWIGTYPE ""
+
+
+/*
+ * Proxy classes.
+ */
+
+%typemap(dconstructor, excode=SWIGEXCODE,directorconnect="\n swigDirectorConnect();") SWIGTYPE {
+ this($wcall, true);$excode$directorconnect
+}
+
+%typemap(ddestructor) SWIGTYPE %{
+~this() {
+ dispose();
+}
+%}
+
+// We do not use »override« attribute for generated dispose() methods to stay
+// somewhat compatible to Phobos and older Tango versions where Object.dispose()
+// does not exist.
+%typemap(ddispose, methodname="dispose", methodmodifiers="public") SWIGTYPE {
+ synchronized(this) {
+ if (swigCPtr !is null) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ $wcall;
+ }
+ swigCPtr = null;
+ }
+ }
+}
+
+%typemap(ddispose_derived, methodname="dispose", methodmodifiers="public") SWIGTYPE {
+ synchronized(this) {
+ if (swigCPtr !is null) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ $wcall;
+ }
+ swigCPtr = null;
+ super.dispose();
+ }
+ }
+}
+
+%define SWIGD_CLASS_BODIES(OP_EQUALS_RETURN)
+// Unfortunately, the »package« visibility attribute does not work in D when the
+// module in question is in the root package (happens if no -package is specified
+// at the SWIG command line), so we are stuck with public visibility for
+// swigGetCPtr().
+%typemap(dbody) SWIGTYPE %{
+private void* swigCPtr;
+protected bool swigCMemOwn;
+
+public this(void* cObject, bool ownCObject) {
+ swigCPtr = cObject;
+ swigCMemOwn = ownCObject;
+}
+
+public override OP_EQUALS_RETURN opEquals(Object rhs) {
+ if (auto other = cast($dclassname)rhs) {
+ return (swigCPtr == other.swigCPtr);
+ }
+ return super.opEquals(rhs);
+}
+
+public static void* swigGetCPtr($dclassname obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+%}
+
+%typemap(dbody_derived) SWIGTYPE %{
+private void* swigCPtr;
+
+public this(void* cObject, bool ownCObject) {
+ super($wrapdmodule.$dclassnameUpcast(cObject), ownCObject);
+ swigCPtr = cObject;
+}
+
+public override OP_EQUALS_RETURN opEquals(Object rhs) {
+ if (auto other = cast($dclassname)rhs) {
+ return (swigCPtr == other.swigCPtr);
+ }
+ return super.opEquals(rhs);
+}
+
+public static void* swigGetCPtr($dclassname obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+%}
+
+
+/*
+ * Type wrapper classes.
+ */
+
+%typemap(dbody) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] %{
+private void* swigCPtr;
+
+public this(void* cObject, bool futureUse) {
+ swigCPtr = cObject;
+}
+
+protected this() {
+ swigCPtr = null;
+}
+
+public override OP_EQUALS_RETURN opEquals(Object rhs) {
+ if (auto other = cast($dclassname)rhs) {
+ return (swigCPtr == other.swigCPtr);
+ }
+ return super.opEquals(rhs);
+}
+
+public static void* swigGetCPtr($dclassname obj) {
+ return (obj is null) ? null : obj.swigCPtr;
+}
+%}
+
+
+/*
+ * Member function pointer wrapper classes (see ).
+ */
+
+%typemap(dbody) SWIGTYPE (CLASS::*) %{
+private char* m_swigCMemberPtr;
+
+public this(char* cMemberPtr, bool futureUse) {
+ m_swigCMemberPtr = cMemberPtr;
+}
+
+protected this() {
+ m_swigCMemberPtr = null;
+}
+
+public override OP_EQUALS_RETURN opEquals(Object rhs) {
+ if (auto other = cast($dclassname)rhs) {
+ return (m_swigCMemberPtr == other.m_swigCMemberPtr);
+ }
+ return super.opEquals(rhs);
+}
+
+
+package static char* swigGetCMemberPtr($dclassname obj) {
+ return (obj is null) ? null : obj.m_swigCMemberPtr;
+}
+%}
+%enddef
+
+
+#if SWIG_D_VERSION == 1
+ SWIGD_CLASS_BODIES(int)
+#else
+ SWIGD_CLASS_BODIES(bool)
+#endif
+
+#undef SWIGD_CLASS_BODIES
diff --git a/Lib/d/ddirectives.swg b/Lib/d/ddirectives.swg
new file mode 100644
index 000000000..2b6ad77e2
--- /dev/null
+++ b/Lib/d/ddirectives.swg
@@ -0,0 +1,11 @@
+/* -----------------------------------------------------------------------------
+ * ddirectives.swg
+ *
+ * D-specifiv directives.
+ * ----------------------------------------------------------------------------- */
+
+#define %dnativeconst %feature("d:nativeconst")
+#define %dconstvalue(value) %feature("d:constvalue",value)
+#define %dmethodmodifiers %feature("d:methodmodifiers")
+#define %dstripprefix %feature("d:stripprefix")
+#define %dnothrowexception %feature("except")
diff --git a/Lib/d/denums.swg b/Lib/d/denums.swg
new file mode 100644
index 000000000..2632679ba
--- /dev/null
+++ b/Lib/d/denums.swg
@@ -0,0 +1,60 @@
+/* -----------------------------------------------------------------------------
+ * denums.swg
+ *
+ * Typemaps for enumerations.
+ * ----------------------------------------------------------------------------- */
+
+
+/*
+ * Typemaps for enumeration types.
+ */
+
+%typemap(cwtype) enum SWIGTYPE "int"
+%typemap(dwtype) enum SWIGTYPE "int"
+%typemap(dptype, cprimitive="1") enum SWIGTYPE "$dclassname"
+
+%typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE ""
+
+%typemap(in) enum SWIGTYPE %{ $1 = ($1_ltype)$input; %}
+%typemap(out) enum SWIGTYPE %{ $result = $1; %}
+
+%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
+%typemap(directorin) enum SWIGTYPE "$input = $1;"
+%typemap(ddirectorin) enum SWIGTYPE "cast($dclassname)$winput"
+%typemap(ddirectorout) enum SWIGTYPE "cast(int)$dpcall"
+
+%typemap(din) enum SWIGTYPE "cast(int)$dinput"
+%typemap(dout, excode=SWIGEXCODE) enum SWIGTYPE {
+ $dclassname ret = cast($dclassname)$wcall;$excode
+ return ret;
+}
+
+
+/*
+ * Typemaps for (const) references to enumeration types.
+ */
+
+%typemap(cwtype) const enum SWIGTYPE & "int"
+%typemap(dwtype) const enum SWIGTYPE & "int"
+%typemap(dptype) const enum SWIGTYPE & "$*dclassname"
+
+%typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""
+
+%typemap(in) const enum SWIGTYPE & ($*1_ltype temp)
+%{ temp = ($*1_ltype)$input;
+ $1 = &temp; %}
+%typemap(out) const enum SWIGTYPE & %{ $result = *$1; %}
+
+%typemap(directorin) const enum SWIGTYPE & "$input = $1_name;"
+%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const enum SWIGTYPE &
+%{ static $*1_ltype temp = ($*1_ltype)$input;
+ $result = &temp; %}
+
+%typemap(ddirectorin) const enum SWIGTYPE & "cast($*dclassname)$winput"
+%typemap(ddirectorout) const enum SWIGTYPE & "cast(int)$dpcall"
+
+%typemap(din) const enum SWIGTYPE & "cast(int)$dinput"
+%typemap(dout, excode=SWIGEXCODE) const enum SWIGTYPE & {
+ $*dclassname ret = cast($*dclassname)$wcall;$excode
+ return ret;
+}
diff --git a/Lib/d/dexception.swg b/Lib/d/dexception.swg
new file mode 100644
index 000000000..f45cf7bfb
--- /dev/null
+++ b/Lib/d/dexception.swg
@@ -0,0 +1,30 @@
+/* -----------------------------------------------------------------------------
+ * dexception.swg
+ *
+ * Typemaps used for propagating C++ exceptions to D.
+ * ----------------------------------------------------------------------------- */
+
+// Code which is inserted into the dout typemaps and class constructors via
+// excode if exceptions can be thrown.
+%define SWIGEXCODE "\n if ($wrapdmodule.SwigPendingException.isPending) throw $wrapdmodule.SwigPendingException.retrieve();" %enddef
+
+%typemap(throws, canthrow=1) int,
+ long,
+ short,
+ unsigned int,
+ unsigned long,
+ unsigned short
+%{ char error_msg[256];
+ sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
+ SWIG_DSetPendingException(SWIG_DException, error_msg);
+ return $null; %}
+
+%typemap(throws, canthrow=1) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY],
+ enum SWIGTYPE, const enum SWIGTYPE &
+%{ (void)$1;
+ SWIG_DSetPendingException(SWIG_DException, "C++ $1_type exception thrown");
+ return $null; %}
+
+%typemap(throws, canthrow=1) char *
+%{ SWIG_DSetPendingException(SWIG_DException, $1);
+ return $null; %}
diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg
new file mode 100644
index 000000000..e05bc7728
--- /dev/null
+++ b/Lib/d/dhead.swg
@@ -0,0 +1,310 @@
+/* -----------------------------------------------------------------------------
+ * 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
+ * ----------------------------------------------------------------------------- */
+
+%insert(runtime) %{
+#include
+#include
+#include
+%}
+
+
+#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
+%insert(runtime) %{
+// Support for throwing D exceptions from C/C++.
+typedef enum {
+ SWIG_DException = 0,
+ SWIG_DIllegalArgumentException,
+ SWIG_DIllegalElementException,
+ SWIG_DIOException,
+ SWIG_DNoSuchElementException,
+} SWIG_DExceptionCodes;
+
+typedef void (SWIGSTDCALL* SWIG_DExceptionCallback_t)(const char *);
+
+typedef struct {
+ SWIG_DExceptionCodes code;
+ SWIG_DExceptionCallback_t callback;
+} SWIG_DException_t;
+
+static SWIG_DException_t SWIG_d_exceptions[] = {
+ { SWIG_DException, NULL },
+ { SWIG_DIllegalArgumentException, NULL },
+ { SWIG_DIllegalElementException, NULL },
+ { SWIG_DIOException, NULL },
+ { SWIG_DNoSuchElementException, NULL }
+};
+
+static void SWIGUNUSED SWIG_DSetPendingException(SWIG_DExceptionCodes code, const char *msg) {
+ if ((size_t)code < sizeof(SWIG_d_exceptions)/sizeof(SWIG_DException_t)) {
+ SWIG_d_exceptions[code].callback(msg);
+ } else {
+ SWIG_d_exceptions[SWIG_DException].callback(msg);
+ }
+}
+
+#ifdef __cplusplus
+extern "C"
+#endif
+SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module(
+ SWIG_DExceptionCallback_t exceptionCallback,
+ SWIG_DExceptionCallback_t illegalArgumentCallback,
+ SWIG_DExceptionCallback_t illegalElementCallback,
+ SWIG_DExceptionCallback_t ioCallback,
+ SWIG_DExceptionCallback_t noSuchElementCallback) {
+ SWIG_d_exceptions[SWIG_DException].callback = exceptionCallback;
+ SWIG_d_exceptions[SWIG_DIllegalArgumentException].callback = illegalArgumentCallback;
+ SWIG_d_exceptions[SWIG_DIllegalElementException].callback = illegalElementCallback;
+ SWIG_d_exceptions[SWIG_DIOException].callback = ioCallback;
+ SWIG_d_exceptions[SWIG_DNoSuchElementException].callback = noSuchElementCallback;
+}
+%}
+
+#if (SWIG_D_VERSION == 1)
+%pragma(d) wrapdmoduleimports=%{
+// 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) wrapdmodulecode=%{
+private class SwigExceptionHelper {
+ static this() {
+ swigRegisterExceptionCallbacks(
+ &setException,
+ &setIllegalArgumentException,
+ &setIllegalElementException,
+ &setIOException,
+ &setNoSuchElementException);
+ }
+
+ static void setException(char* message) {
+ auto exception = new Exception(tango.stdc.stringz.fromStringz(message).dup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+
+ static void setIllegalArgumentException(char* message) {
+ auto exception = new tango.core.Exception.IllegalArgumentException(tango.stdc.stringz.fromStringz(message).dup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+
+ static void setIllegalElementException(char* message) {
+ auto exception = new tango.core.Exception.IllegalElementException(tango.stdc.stringz.fromStringz(message).dup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+
+ static void setIOException(char* message) {
+ auto exception = new tango.core.Exception.IOException(tango.stdc.stringz.fromStringz(message).dup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+
+ static void setNoSuchElementException(char* message) {
+ auto exception = new tango.core.Exception.NoSuchElementException(tango.stdc.stringz.fromStringz(message).dup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+}
+
+package class SwigPendingException {
+public:
+ static this() {
+ m_sPendingCount = 0;
+ m_sPendingException = new ThreadLocalData(null);
+ }
+
+ static bool isPending() {
+ bool pending = false;
+ if (m_sPendingCount > 0) {
+ if (m_sPendingException.val !is null) {
+ pending = true;
+ }
+ }
+ return pending;
+ }
+
+ static void set(Exception e) {
+ if (m_sPendingException.val !is null) {
+ throw new Exception("FATAL: An earlier pending exception from C/C++ code " ~
+ "was missed and thus not thrown (" ~ m_sPendingException.val.classinfo.name ~
+ ": " ~ m_sPendingException.val.msg ~ ")!", e);
+ }
+
+ m_sPendingException.val = e;
+ synchronized {
+ ++m_sPendingCount;
+ }
+ }
+
+ static Exception retrieve() {
+ Exception e = null;
+ if (m_sPendingCount > 0) {
+ if (m_sPendingException.val !is null) {
+ e = m_sPendingException.val;
+ m_sPendingException.val = null;
+ synchronized {
+ --m_sPendingCount;
+ }
+ }
+ }
+ return e;
+ }
+
+private:
+ // The pending exception counter is stored thread-global.
+ static int m_sPendingCount;
+
+ // The reference to the pending exception (if any) is stored thread-local.
+ alias tango.core.Thread.ThreadLocal!(Exception) ThreadLocalData;
+ static ThreadLocalData m_sPendingException;
+}
+alias void function(char* message) SwigExceptionCallback;
+%}
+#else
+%pragma(d) wrapdmoduleimports=%{
+static import std.conv;
+%}
+
+%pragma(d) wrapdmodulecode=%{
+private class SwigExceptionHelper {
+ static this() {
+ // The D1/Tango version maps C++ exceptions to multiple exception types.
+ swigRegisterExceptionCallbacks(
+ &setException,
+ &setException,
+ &setException,
+ &setException,
+ &setException
+ );
+ }
+
+ static void setException(char* message) {
+ auto exception = new Exception(std.conv.to!string(message).idup);
+ exception.next = SwigPendingException.retrieve();
+ SwigPendingException.set(exception);
+ }
+}
+
+package struct SwigPendingException {
+public:
+ static this() {
+ m_sPendingCount = 0;
+ m_sPendingException = null;
+ }
+
+ static bool isPending() {
+ bool pending = false;
+ if (m_sPendingCount > 0) {
+ if (m_sPendingException !is null) {
+ pending = true;
+ }
+ }
+ return pending;
+ }
+
+ static void set(Exception e) {
+ if (m_sPendingException !is null) {
+ throw new Exception("FATAL: An earlier pending exception from C/C++ code " ~
+ "was missed and thus not thrown (" ~ m_sPendingException.classinfo.name ~
+ ": " ~ m_sPendingException.msg ~ ")!", e);
+ }
+
+ m_sPendingException = e;
+ synchronized {
+ ++m_sPendingCount;
+ }
+ }
+
+ static Exception retrieve() {
+ Exception e = null;
+ if (m_sPendingCount > 0) {
+ if (m_sPendingException !is null) {
+ e = m_sPendingException;
+ m_sPendingException = null;
+ synchronized {
+ --m_sPendingCount;
+ }
+ }
+ }
+ return e;
+ }
+
+private:
+ // The pending exception counter is stored thread-global.
+ static shared int m_sPendingCount;
+
+ // The reference to the pending exception (if any) is stored thread-local.
+ static Exception m_sPendingException;
+}
+alias void function(const char* message) SwigExceptionCallback;
+%}
+#endif
+// Callback registering function in wrapperloader.swg.
+#endif // SWIG_D_NO_EXCEPTION_HELPER
+
+#if !defined(SWIG_D_NO_STRING_HELPER)
+%insert(runtime) %{
+// Callback for returning strings to D without leaking memory.
+typedef char * (SWIGSTDCALL* SWIG_DStringHelperCallback)(const char *);
+static SWIG_DStringHelperCallback SWIG_d_string_callback = NULL;
+
+#ifdef __cplusplus
+extern "C"
+#endif
+SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_$module(SWIG_DStringHelperCallback callback) {
+ SWIG_d_string_callback = callback;
+}
+%}
+
+#if (SWIG_D_VERSION == 1)
+%pragma(d) wrapdmoduleimports = "static import tango.stdc.stringz;";
+
+%pragma(d) wrapdmodulecode = %{
+private class SwigStringHelper {
+ static this() {
+ swigRegisterStringCallback(&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) wrapdmoduleimports = %{
+static import std.conv;
+static import std.string;
+%}
+
+%pragma(d) wrapdmodulecode = %{
+private class SwigStringHelper {
+ static this() {
+ swigRegisterStringCallback(&createString);
+ }
+
+ static const(char)* createString(const(char*) cString) {
+ // We are effectively dup'ing the string here.
+ // TODO: Is this also 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
+
+%insert(runtime) %{
+/* Contract support. */
+#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_DSetPendingException(SWIG_DException, msg); return nullreturn; } else
+%}
diff --git a/Lib/d/director.swg b/Lib/d/director.swg
new file mode 100644
index 000000000..9692e03c1
--- /dev/null
+++ b/Lib/d/director.swg
@@ -0,0 +1,46 @@
+/* -----------------------------------------------------------------------------
+ * director.swg
+ *
+ * This file contains support for director classes so that D proxy
+ * methods can be called from C++.
+ * ----------------------------------------------------------------------------- */
+
+#ifdef __cplusplus
+
+#if defined(DEBUG_DIRECTOR_OWNED)
+#include
+#endif
+#include
+
+namespace Swig {
+ // Director base class – not used in D directors.
+ class Director {
+ };
+
+ // Base class for director exceptions.
+ class DirectorException {
+ protected:
+ std::string swig_msg;
+
+ public:
+ DirectorException(const char* msg) : swig_msg(msg) {
+ }
+ DirectorException(const std::string &msg) : swig_msg(msg) {
+ }
+ const std::string& what() const {
+ return swig_msg;
+ }
+ virtual ~DirectorException() {
+ }
+ };
+
+ // Exception which is thrown when attempting to call a pure virtual method
+ // from D code thorugh the director layer.
+ class DirectorPureVirtualException : public Swig::DirectorException {
+ public:
+ DirectorPureVirtualException(const char* msg) : DirectorException(std::string("Attempted to invoke pure virtual method ") + msg) {
+ }
+ };
+}
+
+#endif /* __cplusplus */
diff --git a/Lib/d/dkw.swg b/Lib/d/dkw.swg
new file mode 100644
index 000000000..5091f02cc
--- /dev/null
+++ b/Lib/d/dkw.swg
@@ -0,0 +1,126 @@
+#ifndef D_DKW_SWG_
+#define D_DKW_SWG_
+
+/* Warnings for D keywords */
+#define DKEYWORD(x) %keywordwarn("'" `x` "' is a D keyword, renaming to '_" `x` "'",rename="_%s") `x`
+
+// Source: http://www.digitalmars.com/d/{1.0,2.0}/lex.html and
+DKEYWORD(Object);
+DKEYWORD(__FILE__);
+DKEYWORD(__LINE__);
+DKEYWORD(__gshared);
+DKEYWORD(__thread);
+DKEYWORD(__traits);
+DKEYWORD(abstract);
+DKEYWORD(alias);
+DKEYWORD(align);
+DKEYWORD(asm);
+DKEYWORD(assert);
+DKEYWORD(auto);
+DKEYWORD(body);
+DKEYWORD(bool);
+DKEYWORD(break);
+DKEYWORD(byte);
+DKEYWORD(case);
+DKEYWORD(cast);
+DKEYWORD(catch);
+DKEYWORD(cdouble);
+DKEYWORD(cent);
+DKEYWORD(cfloat);
+DKEYWORD(char);
+DKEYWORD(class);
+DKEYWORD(const);
+DKEYWORD(continue);
+DKEYWORD(creal);
+DKEYWORD(dchar);
+DKEYWORD(debug);
+DKEYWORD(default);
+DKEYWORD(delegate);
+DKEYWORD(delete);
+DKEYWORD(deprecated);
+DKEYWORD(do);
+DKEYWORD(double);
+DKEYWORD(dstring);
+DKEYWORD(else);
+DKEYWORD(enum);
+DKEYWORD(export);
+DKEYWORD(extern);
+DKEYWORD(false);
+DKEYWORD(final);
+DKEYWORD(finally);
+DKEYWORD(float);
+DKEYWORD(for);
+DKEYWORD(foreach);
+DKEYWORD(foreach_reverse);
+DKEYWORD(function);
+DKEYWORD(goto);
+DKEYWORD(idouble);
+DKEYWORD(if);
+DKEYWORD(ifloat);
+DKEYWORD(immutable);
+DKEYWORD(import);
+DKEYWORD(in);
+DKEYWORD(inout);
+DKEYWORD(int);
+DKEYWORD(interface);
+DKEYWORD(invariant);
+DKEYWORD(ireal);
+DKEYWORD(is);
+DKEYWORD(lazy);
+DKEYWORD(long);
+DKEYWORD(macro);
+DKEYWORD(mixin);
+DKEYWORD(module);
+DKEYWORD(new);
+DKEYWORD(nothrow);
+DKEYWORD(null);
+DKEYWORD(out);
+DKEYWORD(override);
+DKEYWORD(package);
+DKEYWORD(pragma);
+DKEYWORD(private);
+DKEYWORD(protected);
+DKEYWORD(public);
+DKEYWORD(pure);
+DKEYWORD(real);
+DKEYWORD(ref);
+DKEYWORD(return);
+DKEYWORD(scope);
+DKEYWORD(shared);
+DKEYWORD(short);
+DKEYWORD(static);
+DKEYWORD(string);
+DKEYWORD(struct);
+DKEYWORD(super);
+DKEYWORD(switch);
+DKEYWORD(synchronized);
+DKEYWORD(template);
+DKEYWORD(this);
+DKEYWORD(throw);
+DKEYWORD(true);
+DKEYWORD(try);
+DKEYWORD(typedef);
+DKEYWORD(typeid);
+DKEYWORD(typeof);
+DKEYWORD(ubyte);
+DKEYWORD(ucent);
+DKEYWORD(uint);
+DKEYWORD(ulong);
+DKEYWORD(union);
+DKEYWORD(unittest);
+DKEYWORD(ushort);
+DKEYWORD(version);
+DKEYWORD(void);
+DKEYWORD(volatile);
+DKEYWORD(wchar);
+DKEYWORD(while);
+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.
+DKEYWORD(dispose);
+
+#undef DKEYWORD
+
+#endif //D_DKW_SWG_
diff --git a/Lib/d/dmemberfunctionpointers.swg b/Lib/d/dmemberfunctionpointers.swg
new file mode 100644
index 000000000..2774858f4
--- /dev/null
+++ b/Lib/d/dmemberfunctionpointers.swg
@@ -0,0 +1,92 @@
+/* -----------------------------------------------------------------------------
+ * dmemberfunctionpointers.swg
+ *
+ * Typemaps for member function pointers.
+ * ----------------------------------------------------------------------------- */
+
+
+%typemap(cwtype) SWIGTYPE (CLASS::*) "char *"
+%typemap(dwtype) SWIGTYPE (CLASS::*) "char*"
+%typemap(dptype) SWIGTYPE (CLASS::*) "$dclassname"
+
+%typecheck(SWIG_TYPECHECK_POINTER)
+ SWIGTYPE (CLASS::*)
+ ""
+
+
+/*
+ * Conversion generation typemaps.
+ */
+
+%typemap(in, fragment="SWIG_UnPackData") SWIGTYPE (CLASS::*) %{
+ SWIG_UnpackData($input, (void *)&$1, sizeof($1));
+%}
+%typemap(out, fragment="SWIG_PackData") SWIGTYPE (CLASS::*) %{
+ char buf[128];
+ char *data = SWIG_PackData(buf, (void *)&$1, sizeof($1));
+ *data = '\0';
+ $result = SWIG_d_string_callback(buf);
+%}
+
+%typemap(directorin) SWIGTYPE (CLASS::*) "$input = (void *) $1;"
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE (CLASS::*)
+ "$result = ($1_ltype)$input;"
+
+%typemap(ddirectorin) SWIGTYPE (CLASS::*)
+ "($winput is null) ? null : new $dclassname($winput, false)"
+%typemap(ddirectorout) SWIGTYPE (CLASS::*) "$dclassname.swigGetCPtr($dpcall)"
+
+%typemap(din) SWIGTYPE (CLASS::*) "$dclassname.swigGetCMemberPtr($dinput)"
+%typemap(dout, excode=SWIGEXCODE) SWIGTYPE (CLASS::*) {
+ char* cMemberPtr = $wcall;
+ $dclassname ret = (cMemberPtr is null) ? null : new $dclassname(cMemberPtr, $owner);$excode
+ return ret;
+}
+
+
+/*
+ * Helper functions to pack/unpack arbitrary binary data (member function
+ * pointers in this case) into a string.
+ */
+
+%fragment("SWIG_PackData", "header") {
+/* Pack binary data into a string */
+SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) {
+ static const char hex[17] = "0123456789abcdef";
+ register const unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register unsigned char uu = *u;
+ *(c++) = hex[(uu & 0xf0) >> 4];
+ *(c++) = hex[uu & 0xf];
+ }
+ return c;
+}
+}
+
+%fragment("SWIG_UnPackData", "header") {
+/* Unpack binary data from a string */
+SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
+ register unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register char d = *(c++);
+ register unsigned char uu;
+ if ((d >= '0') && (d <= '9'))
+ uu = ((d - '0') << 4);
+ else if ((d >= 'a') && (d <= 'f'))
+ uu = ((d - ('a'-10)) << 4);
+ else
+ return (char *) 0;
+ d = *(c++);
+ if ((d >= '0') && (d <= '9'))
+ uu |= (d - '0');
+ else if ((d >= 'a') && (d <= 'f'))
+ uu |= (d - ('a'-10));
+ else
+ return (char *) 0;
+ *u = uu;
+ }
+ return c;
+}
+}
diff --git a/Lib/d/doperators.swg b/Lib/d/doperators.swg
new file mode 100644
index 000000000..b3d8d7257
--- /dev/null
+++ b/Lib/d/doperators.swg
@@ -0,0 +1,77 @@
+/* -----------------------------------------------------------------------------
+ * doperators.swg
+ *
+ * Mapping of C++ operator overloading methods to D.
+ * ----------------------------------------------------------------------------- */
+
+#ifdef __cplusplus
+
+#if (SWIG_D_VERSION == 1)
+
+%rename(opAdd) *::operator+;
+%rename(opPos) *::operator+();
+%rename(opAddAssign) *::operator+=;
+%rename(opSub) *::operator-;
+%rename(opNeg) *::operator-();
+%rename(opSubAssign) *::operator-=;
+%rename(opMul) *::operator*;
+%rename(opMulAssign) *::operator*=;
+%rename(opDiv) *::operator/;
+%rename(opDivAssign) *::operator/=;
+%rename(opMod) *::operator%;
+%rename(opModAssign) *::operator%=;
+
+%rename(opCom) *::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;
+%rename(opIndexAssign) *::operator[](unsigned);
+%rename(opCall) *::operator();
+
+// !a is not overrideable in D1.
+%ignoreoperator(LNOT) operator!;
+
+// a != b is rewritten as !a.opEquals(b) in D.
+// For now, just ignore both of them, since there would be quite a bit of magic
+// needed to correctly generate a wrapper method for non-primitives types (there is
+// only one opEquals overload with an Object parameter in D).
+%ignoreoperator(EQ) operator==;
+%ignoreoperator(NOTEQUAL) operator!=;
+
+// opCmp is used in D.
+%ignoreoperator(LT) operator<;
+%ignoreoperator(LTEQUAL) operator<=;
+%ignoreoperator(GT) operator>;
+%ignoreoperator(GTEQUAL) operator>=;
+
+// The logic operators are not overrideable in D.
+%ignoreoperator(LAND) operator&&;
+%ignoreoperator(LOR) operator||;
+
+// ++/--a is rewritten as a +/-= 1 in D.
+%ignoreoperator(PLUSPLUS) operator++();
+%ignoreoperator(MINUSMINUS) operator--();
+%ignoreoperator(PLUSPLUS) operator++(int);
+%ignoreoperator(MINUSMINUS) operator--(int);
+
+// The C++ assignment operator does not translate well to D where custom types
+// have reference semantics.
+%ignoreoperator(EQ) operator=;
+
+#else
+
+// Operator overloading works completely different in D2, proper support will
+// probably need fairly extensive code generation support.
+
+#endif
+
+#endif
diff --git a/Lib/d/dprimitives.swg b/Lib/d/dprimitives.swg
new file mode 100644
index 000000000..94999af2c
--- /dev/null
+++ b/Lib/d/dprimitives.swg
@@ -0,0 +1,158 @@
+/* -----------------------------------------------------------------------------
+ * dprimitves.swg
+ *
+ * Typemaps for primitive types.
+ * ----------------------------------------------------------------------------- */
+
+/*
+ * The SWIG_D_PRIMITIVE macro is used to define the typemaps for the primitive
+ * types, because are more or less the same for all of them. The few special
+ * cases are handeled below.
+ */
+%define SWIG_D_PRIMITIVE(TYPE, DTYPE)
+%typemap(cwtype) TYPE, const TYPE & "TYPE"
+%typemap(dwtype) TYPE, const TYPE & "DTYPE"
+%typemap(dptype, cprimitive="1") TYPE, const TYPE & "DTYPE"
+
+%typemap(in) TYPE "$1 = ($1_ltype)$input;"
+%typemap(out) TYPE "$result = $1;"
+%typemap(directorin) TYPE "$input = $1;"
+%typemap(directorout) TYPE "$result = ($1_ltype)$input;"
+%typemap(ddirectorin) TYPE "$winput"
+%typemap(ddirectorout) TYPE "$dpcall"
+
+%typemap(in) const TYPE & ($*1_ltype temp)
+%{ temp = ($*1_ltype)$input;
+ $1 = &temp; %}
+%typemap(out) const TYPE & "$result = *$1;"
+%typemap(directorin) const TYPE & "$input = $1_name;"
+%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const TYPE &
+%{ static $*1_ltype temp;
+ temp = ($*1_ltype)$input;
+ $result = &temp; %}
+%typemap(ddirectorin) const TYPE & "$winput"
+%typemap(ddirectorout) const TYPE & "$dpcall"
+
+%typemap(din) TYPE, const TYPE & "$dinput"
+%typemap(dout, excode=SWIGEXCODE) TYPE, const TYPE & {
+ auto ret = $wcall;$excode
+ return ret;
+}
+%enddef
+
+
+SWIG_D_PRIMITIVE(bool, bool)
+SWIG_D_PRIMITIVE(char, char)
+SWIG_D_PRIMITIVE(signed char, byte)
+SWIG_D_PRIMITIVE(unsigned char, ubyte)
+SWIG_D_PRIMITIVE(short, short)
+SWIG_D_PRIMITIVE(unsigned short, ushort)
+SWIG_D_PRIMITIVE(int, int)
+SWIG_D_PRIMITIVE(unsigned int, uint)
+SWIG_D_PRIMITIVE(long, int)
+SWIG_D_PRIMITIVE(unsigned long, uint)
+SWIG_D_PRIMITIVE(size_t, size_t)
+SWIG_D_PRIMITIVE(long long, long)
+SWIG_D_PRIMITIVE(unsigned long long, ulong)
+SWIG_D_PRIMITIVE(float, float)
+SWIG_D_PRIMITIVE(double, double)
+
+
+// The C++ boolean type needs some special casing since it is not part of the
+// C standard and is thus represented as unsigned int in the C wrapper layer.
+%typemap(cwtype) bool, const bool & "unsigned int"
+%typemap(dwtype) bool, const bool & "uint"
+
+%typemap(in) bool "$1 = $input ? true : false;"
+%typemap(in) const bool & ($*1_ltype temp)
+%{ temp = $input ? true : false;
+ $1 = &temp; %}
+
+%typemap(directorout) bool
+ "$result = $input ? true : false;"
+%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const bool &
+%{ static $*1_ltype temp;
+ temp = $input ? true : false;
+ $result = &temp; %}
+
+%typemap(ddirectorin) bool "($winput ? true : false)"
+
+%typemap(dout, excode=SWIGEXCODE) bool, const bool & {
+ bool ret = $wcall ? true : false;$excode
+ return ret;
+}
+
+
+// Judging from the history of the C# module, the explicit casts are needed for
+// certain versions of VC++.
+%typemap(out) unsigned long "$result = (unsigned long)$1;"
+%typemap(out) const unsigned long & "$result = (unsigned long)*$1;"
+
+
+/*
+ * Typecheck typemaps.
+ */
+
+%typecheck(SWIG_TYPECHECK_BOOL)
+ bool,
+ const bool &
+ ""
+
+%typecheck(SWIG_TYPECHECK_CHAR)
+ char,
+ const char &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT8)
+ signed char,
+ const signed char &
+ ""
+
+%typecheck(SWIG_TYPECHECK_UINT8)
+ unsigned char,
+ const unsigned char &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT16)
+ short,
+ const short &
+ ""
+
+%typecheck(SWIG_TYPECHECK_UINT16)
+ unsigned short,
+ const unsigned short &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT32)
+ int,
+ long,
+ const int &,
+ const long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_UINT32)
+ unsigned int,
+ unsigned long,
+ const unsigned int &,
+ const unsigned long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT64)
+ long long,
+ const long long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_UINT64)
+ unsigned long long,
+ const unsigned long long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_FLOAT)
+ float,
+ const float &
+ ""
+
+%typecheck(SWIG_TYPECHECK_DOUBLE)
+ double,
+ const double &
+ ""
diff --git a/Lib/d/dstrings.swg b/Lib/d/dstrings.swg
new file mode 100644
index 000000000..a145c8d75
--- /dev/null
+++ b/Lib/d/dstrings.swg
@@ -0,0 +1,80 @@
+/* -----------------------------------------------------------------------------
+ * dstrings.swg
+ *
+ * Typemaps for wrapping pointers to/arrays of C chars as D strings.
+ * ----------------------------------------------------------------------------- */
+
+%define SWIGD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
+%typemap(cwtype) char *, char *&, char[ANY], char[] "char *"
+%typemap(dwtype) char *, char *&, char[ANY], char[] #DW_STRING_TYPE
+%typemap(dptype) char *, char *&, char[ANY], char[] #DP_STRING_TYPE
+
+
+/*
+ * char* typemaps.
+ */
+
+%typemap(in) char * %{ $1 = ($1_ltype)$input; %}
+%typemap(out) char * %{ $result = SWIG_d_string_callback((const char *)$1); %}
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * %{ $result = ($1_ltype)$input; %}
+%typemap(directorin) char * %{ $input = SWIG_d_string_callback((const char *)$1); %}
+%typemap(ddirectorin) char * "FROM_STRINGZ($winput)"
+%typemap(ddirectorout) char * "TO_STRINGZ($dpcall)"
+
+
+/*
+ * char*& typemaps.
+ */
+
+%typemap(in) char *& ($*1_ltype temp = 0) %{
+ temp = ($*1_ltype)$input;
+ $1 = &temp;
+%}
+%typemap(out) char *& %{ if ($1) $result = SWIG_d_string_callback((const char *)*$1); %}
+
+
+/*
+ * char array typemaps.
+ */
+
+%typemap(in) char[ANY], char[] %{ $1 = ($1_ltype)$input; %}
+%typemap(out) char[ANY], char[] %{ $result = SWIG_d_string_callback((const char *)$1); %}
+
+%typemap(directorout) char[ANY], char[] %{ $result = ($1_ltype)$input; %}
+%typemap(directorin) char[ANY], char[] %{ $input = SWIG_d_string_callback((const char *)$1); %}
+
+%typemap(ddirectorin) char[ANY], char[] "$winput"
+%typemap(ddirectorout) char[ANY], char[] "$dpcall"
+
+
+%typemap(din) char *, char *&, char[ANY], char[] "($dinput ? TO_STRINGZ($dinput) : null)"
+%typemap(dout, excode=SWIGEXCODE) char *, char *&, char[ANY], char[] {
+ DP_STRING_TYPE ret = FROM_STRINGZ ## ($wcall);$excode
+ return ret;
+}
+
+%typecheck(SWIG_TYPECHECK_STRING)
+ char *,
+ char *&,
+ char[ANY],
+ char[]
+ ""
+%enddef
+
+
+// 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
new file mode 100644
index 000000000..ed2fb531d
--- /dev/null
+++ b/Lib/d/dswigtype.swg
@@ -0,0 +1,177 @@
+/* -----------------------------------------------------------------------------
+ * dswigtype.swg
+ *
+ * Typemaps for non-primitive types (C/C++ classes and structs).
+ * ----------------------------------------------------------------------------- */
+
+%typemap(cwtype) SWIGTYPE "void *"
+%typemap(dwtype) SWIGTYPE "void*"
+%typemap(dptype) SWIGTYPE "$&dclassname"
+
+%typemap(cwtype) SWIGTYPE [] "void *"
+%typemap(dwtype) SWIGTYPE [] "void*"
+%typemap(dptype) SWIGTYPE [] "$dclassname"
+
+%typemap(cwtype) SWIGTYPE * "void *"
+%typemap(dwtype) SWIGTYPE * "void*"
+%typemap(dptype, nativepointer="$dptype") SWIGTYPE * "$dclassname"
+
+%typemap(cwtype) SWIGTYPE & "void *"
+%typemap(dwtype) SWIGTYPE & "void*"
+%typemap(dptype) SWIGTYPE & "$dclassname"
+
+%typemap(cwtype) SWIGTYPE *const& "void *"
+%typemap(dwtype) SWIGTYPE *const& "void*"
+%typemap(dptype) SWIGTYPE *const& "$*dclassname"
+
+%typecheck(SWIG_TYPECHECK_POINTER)
+ SWIGTYPE,
+ SWIGTYPE *,
+ SWIGTYPE &,
+ SWIGTYPE [],
+ SWIGTYPE *const&
+ ""
+
+
+/*
+ * By-value conversion typemaps (parameter is converted to a pointer).
+ */
+
+%typemap(in, canthrow=1) SWIGTYPE ($&1_type argp)
+%{ argp = ($&1_ltype)$input;
+ if (!argp) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Attempt to dereference null $1_type");
+ return $null;
+ }
+ $1 = *argp; %}
+
+%typemap(out) SWIGTYPE
+#ifdef __cplusplus
+%{ $result = new $1_ltype((const $1_ltype &)$1); %}
+#else
+{
+ $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
+ memmove($1ptr, &$1, sizeof($1_type));
+ $result = $1ptr;
+}
+#endif
+
+%typemap(directorin) SWIGTYPE
+ "$input = (void *)&$1;"
+%typemap(directorout) SWIGTYPE
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "Unexpected null return for type $1_type");
+ return $null;
+ }
+ $result = *($&1_ltype)$input; %}
+
+%typemap(ddirectorin) SWIGTYPE "new $&dclassname($winput, false)"
+%typemap(ddirectorout) SWIGTYPE "$&dclassname.swigGetCPtr($dpcall)"
+
+%typemap(din) SWIGTYPE "$&dclassname.swigGetCPtr($dinput)"
+%typemap(dout, excode=SWIGEXCODE) SWIGTYPE {
+ $&dclassname ret = new $&dclassname($wcall, true);$excode
+ return ret;
+}
+
+
+/*
+ * Pointer conversion typemaps.
+ */
+
+%typemap(in) SWIGTYPE * "$1 = ($1_ltype)$input;"
+%typemap(out) SWIGTYPE * "$result = (void *)$1;"
+
+%typemap(directorin) SWIGTYPE *
+ "$input = (void *) $1;"
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *
+ "$result = ($1_ltype)$input;"
+
+%typemap(ddirectorin,
+ nativepointer="cast($dptype)$winput"
+) SWIGTYPE * "($winput is null) ? null : new $dclassname($winput, false)"
+
+%typemap(ddirectorout,
+ nativepointer="cast(void*)$dpcall"
+) SWIGTYPE * "$dclassname.swigGetCPtr($dpcall)"
+
+%typemap(din,
+ nativepointer="cast(void*)$dinput"
+) SWIGTYPE * "$dclassname.swigGetCPtr($dinput)"
+
+%typemap(dout, excode=SWIGEXCODE,
+ nativepointer="{\n auto ret = cast($dptype)$wcall;$excode\n return ret;\n}"
+) SWIGTYPE * {
+ void* cPtr = $wcall;
+ $dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode
+ return ret;
+}
+
+// Use the same typemaps for const pointers.
+%apply SWIGTYPE * { SWIGTYPE *const }
+
+
+/*
+ * Reference conversion typemaps.
+ */
+
+%typemap(in, canthrow=1) SWIGTYPE & %{ $1 = ($1_ltype)$input;
+ if (!$1) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "$1_type type is null");
+ return $null;
+ } %}
+%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) SWIGTYPE & "new $dclassname($winput, false)"
+%typemap(ddirectorout) SWIGTYPE & "$dclassname.swigGetCPtr($dpcall)"
+
+%typemap(din) SWIGTYPE & "$dclassname.swigGetCPtr($dinput)"
+%typemap(dout, excode=SWIGEXCODE) SWIGTYPE & {
+ $dclassname ret = new $dclassname($wcall, $owner);$excode
+ return ret;
+}
+
+
+/*
+ * Array conversion typemaps.
+ */
+
+%typemap(in) SWIGTYPE [] %{ $1 = ($1_ltype)$input; %}
+%typemap(out) SWIGTYPE [] %{ $result = $1; %}
+
+%typemap(din) SWIGTYPE [] "$dclassname.swigGetCPtr($dinput)"
+%typemap(dout, excode=SWIGEXCODE) SWIGTYPE [] {
+ void* cPtr = $wcall;
+ $dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode
+ return ret;
+}
+
+// Treat references to arrays like like references to a single element.
+%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
+
+
+/*
+ * Pointer reference conversion typemaps.
+ */
+
+%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
+%{ temp = ($*1_ltype)$input;
+ $1 = ($1_ltype)&temp; %}
+%typemap(out) SWIGTYPE *const&
+%{ $result = (void *)*$1; %}
+
+%typemap(din) SWIGTYPE *const& "$*dclassname.swigGetCPtr($dinput)"
+%typemap(dout, excode=SWIGEXCODE) SWIGTYPE *const& {
+ void* cPtr = $wcall;
+ $*dclassname ret = (cPtr is null) ? null : new $*dclassname(cPtr, $owner);$excode
+ return ret;
+}
diff --git a/Lib/d/dvoid.swg b/Lib/d/dvoid.swg
new file mode 100644
index 000000000..a08da5e32
--- /dev/null
+++ b/Lib/d/dvoid.swg
@@ -0,0 +1,18 @@
+/* -----------------------------------------------------------------------------
+ * dvoid.swg
+ *
+ * Typemaps for handling void function return types and empty parameter lists.
+ * ----------------------------------------------------------------------------- */
+
+%typemap(cwtype) void "void"
+%typemap(dwtype) void "void"
+%typemap(dptype, cprimitive="1") void "void"
+
+%typemap(out, null="") void ""
+%typemap(ddirectorin) void "$winput"
+%typemap(ddirectorout) void "$dpcall"
+%typemap(directorin) void ""
+
+%typemap(dout, excode=SWIGEXCODE) void {
+ $wcall;$excode
+}
diff --git a/Lib/d/std_common.i b/Lib/d/std_common.i
new file mode 100644
index 000000000..cee11e8ca
--- /dev/null
+++ b/Lib/d/std_common.i
@@ -0,0 +1,5 @@
+%include
+
+%apply size_t { std::size_t };
+%apply const size_t& { const std::size_t& };
+
diff --git a/Lib/d/std_deque.i b/Lib/d/std_deque.i
new file mode 100644
index 000000000..cb98f6c2f
--- /dev/null
+++ b/Lib/d/std_deque.i
@@ -0,0 +1 @@
+%include
diff --git a/Lib/d/std_except.i b/Lib/d/std_except.i
new file mode 100644
index 000000000..2b557e5fc
--- /dev/null
+++ b/Lib/d/std_except.i
@@ -0,0 +1,30 @@
+/* -----------------------------------------------------------------------------
+ * std_except.i
+ *
+ * Typemaps used by the STL wrappers that throw exceptions. These typemaps are
+ * used when methods are declared with an STL exception specification, such as
+ * size_t at() const throw (std::out_of_range);
+ * ----------------------------------------------------------------------------- */
+
+%{
+#include
+%}
+
+namespace std
+{
+ %ignore exception;
+ struct exception {};
+}
+
+%typemap(throws, canthrow=1) std::bad_exception "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::domain_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::exception "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::invalid_argument "SWIG_DSetPendingException(SWIG_DIllegalArgumentException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::length_error "SWIG_DSetPendingException(SWIG_DNoSuchElementException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::logic_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::out_of_range "SWIG_DSetPendingException(SWIG_DNoSuchElementException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::overflow_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::range_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::runtime_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+%typemap(throws, canthrow=1) std::underflow_error "SWIG_DSetPendingException(SWIG_DException, $1.what());\n return $null;"
+
diff --git a/Lib/d/std_map.i b/Lib/d/std_map.i
new file mode 100644
index 000000000..0e8574b8a
--- /dev/null
+++ b/Lib/d/std_map.i
@@ -0,0 +1,59 @@
+/* -----------------------------------------------------------------------------
+ * std_map.i
+ *
+ * SWIG typemaps for std::map
+ * ----------------------------------------------------------------------------- */
+
+%include
+
+// ------------------------------------------------------------------------
+// std::map
+// ------------------------------------------------------------------------
+
+%{
+#include
+#include
+#include
+%}
+
+// exported class
+
+namespace std {
+ template class map {
+ // add typemaps here
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef K key_type;
+ typedef T mapped_type;
+ map();
+ map(const map &);
+
+ unsigned int size() const;
+ bool empty() const;
+ void clear();
+ %extend {
+ const T& get(const K& key) throw (std::out_of_range) {
+ std::map::iterator i = self->find(key);
+ if (i != self->end())
+ return i->second;
+ else
+ throw std::out_of_range("key not found");
+ }
+ void set(const K& key, const T& x) {
+ (*self)[key] = x;
+ }
+ void del(const K& key) throw (std::out_of_range) {
+ std::map::iterator i = self->find(key);
+ if (i != self->end())
+ self->erase(i);
+ else
+ throw std::out_of_range("key not found");
+ }
+ bool has_key(const K& key) {
+ std::map::iterator i = self->find(key);
+ return i != self->end();
+ }
+ }
+ };
+}
diff --git a/Lib/d/std_pair.i b/Lib/d/std_pair.i
new file mode 100644
index 000000000..0712ad762
--- /dev/null
+++ b/Lib/d/std_pair.i
@@ -0,0 +1,34 @@
+/* -----------------------------------------------------------------------------
+ * std_pair.i
+ *
+ * SWIG typemaps for std::pair
+ * ----------------------------------------------------------------------------- */
+
+%include
+%include
+
+// ------------------------------------------------------------------------
+// std::pair
+// ------------------------------------------------------------------------
+
+%{
+#include
+%}
+
+namespace std {
+
+ template struct pair {
+
+ pair();
+ pair(T t, U u);
+ pair(const pair& p);
+
+ template pair(const pair &p);
+
+ T first;
+ U second;
+ };
+
+ // add specializations here
+
+}
diff --git a/Lib/d/std_shared_ptr.i b/Lib/d/std_shared_ptr.i
new file mode 100644
index 000000000..df873679c
--- /dev/null
+++ b/Lib/d/std_shared_ptr.i
@@ -0,0 +1,2 @@
+#define SWIG_SHARED_PTR_NAMESPACE std
+%include
diff --git a/Lib/d/std_string.i b/Lib/d/std_string.i
new file mode 100644
index 000000000..4938cfdf7
--- /dev/null
+++ b/Lib/d/std_string.i
@@ -0,0 +1,98 @@
+/* -----------------------------------------------------------------------------
+ * std_string.i
+ *
+ * Typemaps for std::string and const std::string&
+ * These are mapped to a D char[] and are passed around by value.
+ *
+ * To use non-const std::string references, use the following %apply. Note
+ * that they are passed by value.
+ * %apply const std::string & {std::string &};
+ * ----------------------------------------------------------------------------- */
+
+%{
+#include
+%}
+
+namespace std {
+
+%naturalvar string;
+
+class string;
+
+%define SWIGD_STD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
+// string
+%typemap(cwtype) string, const string & "char *"
+%typemap(dwtype) string, const string & #DW_STRING_TYPE
+%typemap(dptype) string, const string & #DP_STRING_TYPE
+
+%typemap(in, canthrow=1) string, const string &
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
+ return $null;
+ }
+ $1.assign($input); %}
+%typemap(in, canthrow=1) const string &
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
+ return $null;
+ }
+ std::string $1_str($input);
+ $1 = &$1_str; %}
+
+%typemap(out) string %{ $result = SWIG_d_string_callback($1.c_str()); %}
+%typemap(out) const string & %{ $result = SWIG_d_string_callback($1->c_str()); %}
+
+%typemap(din) string, const string & "($dinput ? TO_STRINGZ($dinput) : null)"
+%typemap(dout, excode=SWIGEXCODE) string, const string & {
+ DP_STRING_TYPE ret = FROM_STRINGZ($wcall);$excode
+ return ret;
+}
+
+%typemap(directorin) string, const string & %{ $input = SWIG_d_string_callback($1.c_str()); %}
+
+%typemap(directorout, canthrow=1) string
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
+ return $null;
+ }
+ $result.assign($input); %}
+
+%typemap(directorout, canthrow=1, warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const string &
+%{ if (!$input) {
+ SWIG_DSetPendingException(SWIG_DIllegalArgumentException, "null string");
+ return $null;
+ }
+ /* possible thread/reentrant code problem */
+ static std::string $1_str;
+ $1_str = $input;
+ $result = &$1_str; %}
+
+%typemap(ddirectorin) string, const string & "FROM_STRINGZ($winput)"
+%typemap(ddirectorout) string, const string & "TO_STRINGZ($dpcall)"
+
+%typemap(throws, canthrow=1) string, const string &
+%{ SWIG_DSetPendingException(SWIG_DException, $1.c_str());
+ return $null; %}
+
+%typemap(typecheck) string, const string & = char *;
+%enddef
+
+// 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
+
+} // namespace std
diff --git a/Lib/d/std_vector.i b/Lib/d/std_vector.i
new file mode 100644
index 000000000..cdaf1e30b
--- /dev/null
+++ b/Lib/d/std_vector.i
@@ -0,0 +1,591 @@
+/* -----------------------------------------------------------------------------
+ * std_vector.i
+ *
+ * SWIG typemaps for std::vector, D implementation.
+ *
+ * The D wrapper is made to loosely resemble a tango.util.container.more.Vector
+ * and to provide built-in array-like access.
+ *
+ * If T does define an operator==, then use the SWIG_STD_VECTOR_ENHANCED
+ * macro to obtain enhanced functionality (none yet), for example:
+ *
+ * SWIG_STD_VECTOR_ENHANCED(SomeNamespace::Klass)
+ * %template(VectKlass) std::vector;
+ *
+ * Warning: heavy macro usage in this file. Use swig -E to get a sane view on
+ * the real file contents!
+ * ----------------------------------------------------------------------------- */
+
+// Warning: Use the typemaps here in the expectation that the macros they are in will change name.
+
+%include
+
+// MACRO for use within the std::vector class body
+%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CONST_REFERENCE, CWTYPE...)
+#if (SWIG_D_VERSION == 1)
+%typemap(dimports) std::vector< CWTYPE > "static import tango.core.Exception;"
+%typemap(dcode) std::vector< CWTYPE > %{
+public this($typemap(dptype, CWTYPE)[] values) {
+ this();
+ append(values);
+}
+
+alias push_back add;
+alias push_back push;
+alias push_back opCatAssign;
+alias size length;
+alias opSlice slice;
+
+public $typemap(dptype, CWTYPE) opIndexAssign($typemap(dptype, CWTYPE) 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(dptype, CWTYPE) 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(dptype, CWTYPE)[] value...) {
+ foreach (v; value) {
+ add(v);
+ }
+}
+
+public $typemap(dptype, CWTYPE)[] opSlice() {
+ $typemap(dptype, CWTYPE)[] array = new $typemap(dptype, CWTYPE)[size()];
+ foreach (i, ref value; array) {
+ value = getElement(i);
+ }
+ return array;
+}
+
+public int opApply(int delegate(ref $typemap(dptype, CWTYPE) 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(dptype, CWTYPE) 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 CWTYPE value_type;
+ typedef CONST_REFERENCE const_reference;
+ void clear();
+ void push_back(CWTYPE 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< CWTYPE >* pv = 0;
+ pv = new std::vector< CWTYPE >();
+
+ // 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< CWTYPE >::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< CWTYPE >::iterator it = $self->begin() + index;
+ std::vector< CWTYPE >::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 CWTYPE 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, CWTYPE 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< CWTYPE > %{
+static import std.algorithm;
+static import std.exception;
+static import std.range;
+static import std.traits;
+%}
+%typemap(dcode) std::vector< CWTYPE > %{
+alias size_t KeyType;
+alias $typemap(dptype, CWTYPE) ValueType;
+
+this(ValueType[] values...) {
+ this();
+ reserve(values.length);
+ foreach (e; values) {
+ this ~= e;
+ }
+}
+
+struct Range {
+ private $typemap(dptype, std::vector< CWTYPE >) _outer;
+ private size_t _a, _b;
+
+ this($typemap(dptype, std::vector< CWTYPE >) data, size_t a, size_t b) {
+ _outer = data;
+ _a = a;
+ _b = b;
+ }
+
+ @property bool empty() const {
+ assert((cast($typemap(dptype, std::vector< CWTYPE >))_outer).length >= _b);
+ return _a >= _b;
+ }
+
+ @property Range save() {
+ return this;
+ }
+
+ @property ValueType front() {
+ std.exception.enforce(!empty);
+ return _outer[_a];
+ }
+
+ @property void front(ValueType value) {
+ std.exception.enforce(!empty);
+ _outer[_a] = std.algorithm.move(value);
+ }
+
+ void popFront() {
+ std.exception.enforce(!empty);
+ ++_a;
+ }
+
+ void opIndexAssign(ValueType value, size_t i) {
+ i += _a;
+ std.exception.enforce(i < _b && _b <= _outer.length);
+ _outer[i] = value;
+ }
+
+ void opIndexOpAssign(string op)(ValueType value, size_t i) {
+ std.exception.enforce(_outer && _a + i < _b && _b <= _outer.length);
+ auto element = _outer[i];
+ mixin("element "~op~"= value;");
+ _outer[i] = element;
+ }
+}
+
+// TODO: dup?
+
+Range opSlice() {
+ return Range(this, 0, length);
+}
+
+Range opSlice(size_t a, size_t b) {
+ std.exception.enforce(a <= b && b <= length);
+ return Range(this, a, b);
+}
+
+size_t opDollar() const {
+ return length;
+}
+
+@property ValueType front() {
+ std.exception.enforce(!empty);
+ return getElement(0);
+}
+
+@property void front(ValueType value) {
+ std.exception.enforce(!empty);
+ setElement(0, value);
+}
+
+@property ValueType back() {
+ std.exception.enforce(!empty);
+ return getElement(length - 1);
+}
+
+@property void back(ValueType value) {
+ std.exception.enforce(!empty);
+ setElement(length - 1, value);
+}
+
+ValueType opIndex(size_t i) {
+ return getElement(i);
+}
+
+void opIndexAssign(ValueType value, size_t i) {
+ setElement(i, value);
+}
+
+void opIndexOpAssign(string op)(ValueType value, size_t i) {
+ auto element = this[i];
+ mixin("element "~op~"= value;");
+ this[i] = element;
+}
+
+ValueType[] opBinary(string op, Stuff)(Stuff stuff) if (op == "~") {
+ ValueType[] result;
+ result ~= this[];
+ assert(result.length == length);
+ result ~= stuff[];
+ return result;
+}
+
+void opOpAssign(string op, Stuff)(Stuff stuff) if (op == "~") {
+ static if (is(typeof(insertBack(stuff)))) {
+ insertBack(stuff);
+ } else if (is(typeof(insertBack(stuff[])))) {
+ insertBack(stuff[]);
+ } else {
+ static assert(false, "Cannot append " ~ Stuff.stringof ~ " to " ~ typeof(this).stringof);
+ }
+}
+
+alias size length;
+
+alias remove removeAny;
+alias removeAny stableRemoveAny;
+
+size_t insertBack(Stuff)(Stuff stuff)
+if (std.traits.isImplicitlyConvertible!(Stuff, ValueType)){
+ push_back(stuff);
+ return 1;
+}
+size_t insertBack(Stuff)(Stuff stuff)
+if (std.range.isInputRange!Stuff &&
+ std.traits.isImplicitlyConvertible!(std.range.ElementType!Stuff, ValueType)) {
+ size_t itemCount;
+ foreach(item; stuff) {
+ insertBack(item);
+ ++itemCount;
+ }
+ return itemCount;
+}
+alias insertBack insert;
+
+alias pop_back removeBack;
+alias pop_back stableRemoveBack;
+
+size_t insertBefore(Stuff)(Range r, Stuff stuff)
+if (std.traits.isImplicitlyConvertible!(Stuff, ValueType)) {
+ std.exception.enforce(r._outer.swigCPtr == swigCPtr && r._a < length);
+ insertAt(r._a, stuff);
+ return 1;
+}
+
+size_t insertBefore(Stuff)(Range r, Stuff stuff)
+if (std.range.isInputRange!Stuff && std.traits.isImplicitlyConvertible!(ElementType!Stuff, ValueType)) {
+ std.exception.enforce(r._outer.swigCPtr == swigCPtr && r._a <= length);
+
+ size_t insertCount;
+ foreach(i, item; stuff) {
+ insertAt(r._a + i, item);
+ ++insertCount;
+ }
+
+ return insertCount;
+}
+
+size_t insertAfter(Stuff)(Range r, Stuff stuff) {
+ // TODO: optimize
+ immutable offset = r._a + r.length;
+ std.exception.enforce(offset <= length);
+ auto result = insertBack(stuff);
+ std.algorithm.bringToFront(this[offset .. length - result],
+ this[length - result .. length]);
+ return result;
+}
+
+size_t replace(Stuff)(Range r, Stuff stuff)
+if (std.range.isInputRange!Stuff &&
+ std.traits.isImplicitlyConvertible!(ElementType!Stuff, ValueType)) {
+ immutable offset = r._a;
+ std.exception.enforce(offset <= length);
+ size_t result;
+ for (; !stuff.empty; stuff.popFront()) {
+ if (r.empty) {
+ // append the rest
+ return result + insertBack(stuff);
+ }
+ r.front = stuff.front;
+ r.popFront();
+ ++result;
+ }
+ // Remove remaining stuff in r
+ remove(r);
+ return result;
+}
+
+size_t replace(Stuff)(Range r, Stuff stuff)
+if (std.traits.isImplicitlyConvertible!(Stuff, ValueType))
+{
+ if (r.empty)
+ {
+ insertBefore(r, stuff);
+ }
+ else
+ {
+ r.front = stuff;
+ r.popFront();
+ remove(r);
+ }
+ return 1;
+}
+
+Range linearRemove(Range r) {
+ std.exception.enforce(r._a <= r._b && r._b <= length);
+ immutable tailLength = length - r._b;
+ linearRemove(r._a, r._b);
+ return this[length - tailLength .. length];
+}
+alias remove stableLinearRemove;
+
+int opApply(int delegate(ref $typemap(dptype, CWTYPE) 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;
+}
+
+int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) 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:
+ typedef size_t size_type;
+ typedef CWTYPE value_type;
+ typedef CONST_REFERENCE const_reference;
+ bool empty() const;
+ void clear();
+ void push_back(CWTYPE const& x);
+ void pop_back();
+ 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< CWTYPE >* pv = 0;
+ pv = new std::vector< CWTYPE >();
+
+ // Might throw std::length_error.
+ pv->reserve(capacity);
+
+ return pv;
+ }
+
+ 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< CWTYPE >::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< CWTYPE >::iterator it = $self->begin() + index;
+ std::vector< CWTYPE >::const_reference value = *it;
+ $self->erase(it);
+ return value;
+ }
+
+ void removeBack(size_type how_many) throw (std::out_of_range) {
+ std::vector< CWTYPE >::iterator end = $self->end();
+ std::vector< CWTYPE >::iterator start = end - how_many;
+ $self->erase(start, end);
+ }
+
+ void linearRemove(size_type start_index, size_type end_index) throw (std::out_of_range) {
+ std::vector< CWTYPE >::iterator start = $self->begin() + start_index;
+ std::vector< CWTYPE >::iterator end = $self->begin() + end_index;
+ $self->erase(start, end);
+ }
+
+ void insertAt(size_type index, CWTYPE const& x) throw (std::out_of_range) {
+ std::vector< CWTYPE >::iterator it = $self->begin() + index;
+ $self->insert(it, x);
+ }
+ }
+
+ // 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 CWTYPE 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, CWTYPE 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"
+#endif
+%enddef
+
+// Extra methods added to the collection class if operator== is defined for the class being wrapped
+// The class will then implement IList<>, which adds extra functionality
+%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CWTYPE...)
+ %extend {
+ }
+%enddef
+
+// For vararg handling in macros, from swigmacros.swg
+#define %arg(X...) X
+
+// Macros for std::vector class specializations/enhancements
+%define SWIG_STD_VECTOR_ENHANCED(CWTYPE...)
+namespace std {
+ template<> class vector {
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(%arg(CWTYPE const&), %arg(CWTYPE))
+ SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CWTYPE)
+ };
+}
+%enddef
+
+%{
+#include
+#include
+%}
+
+namespace std {
+ // primary (unspecialized) class template for std::vector
+ // does not require operator== to be defined
+ template class vector {
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(T const&, T)
+ };
+ // specializations for pointers
+ template class vector {
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(T *const&, T *)
+ SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T *)
+ };
+ // bool is a bit different in the C++ standard - const_reference in particular
+ template<> class vector {
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(bool, bool)
+ SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(bool)
+ };
+}
+
+// template specializations for std::vector
+// these provide extra collections methods as operator== is defined
+SWIG_STD_VECTOR_ENHANCED(char)
+SWIG_STD_VECTOR_ENHANCED(signed char)
+SWIG_STD_VECTOR_ENHANCED(unsigned char)
+SWIG_STD_VECTOR_ENHANCED(short)
+SWIG_STD_VECTOR_ENHANCED(unsigned short)
+SWIG_STD_VECTOR_ENHANCED(int)
+SWIG_STD_VECTOR_ENHANCED(unsigned int)
+SWIG_STD_VECTOR_ENHANCED(long)
+SWIG_STD_VECTOR_ENHANCED(unsigned long)
+SWIG_STD_VECTOR_ENHANCED(long long)
+SWIG_STD_VECTOR_ENHANCED(unsigned long long)
+SWIG_STD_VECTOR_ENHANCED(float)
+SWIG_STD_VECTOR_ENHANCED(double)
+SWIG_STD_VECTOR_ENHANCED(std::string) // also requires a %include
diff --git a/Lib/d/stl.i b/Lib/d/stl.i
new file mode 100644
index 000000000..9d2e91eee
--- /dev/null
+++ b/Lib/d/stl.i
@@ -0,0 +1,12 @@
+/* -----------------------------------------------------------------------------
+ * stl.i
+ *
+ * Initial STL definition. extended as needed in each language
+ * ----------------------------------------------------------------------------- */
+
+%include
+%include
+%include
+%include
+%include
+
diff --git a/Lib/d/typemaps.i b/Lib/d/typemaps.i
new file mode 100644
index 000000000..cd5636562
--- /dev/null
+++ b/Lib/d/typemaps.i
@@ -0,0 +1,298 @@
+/* -----------------------------------------------------------------------------
+ * typemaps.i
+ *
+ * Pointer and reference handling typemap library
+ *
+ * These mappings provide support for input/output arguments and common
+ * uses for C/C++ pointers and C++ references.
+ * ----------------------------------------------------------------------------- */
+
+/*
+INPUT typemaps
+--------------
+
+These typemaps are used for pointer/reference parameters that are input only
+and are mapped to a D input parameter.
+
+The following typemaps can be applied to turn a pointer or reference into a simple
+input value. That is, instead of passing a pointer or reference to an object,
+you would use a real value instead.
+
+ bool *INPUT, bool &INPUT
+ signed char *INPUT, signed char &INPUT
+ unsigned char *INPUT, unsigned char &INPUT
+ short *INPUT, short &INPUT
+ unsigned short *INPUT, unsigned short &INPUT
+ int *INPUT, int &INPUT
+ unsigned int *INPUT, unsigned int &INPUT
+ long *INPUT, long &INPUT
+ unsigned long *INPUT, unsigned long &INPUT
+ long long *INPUT, long long &INPUT
+ unsigned long long *INPUT, unsigned long long &INPUT
+ float *INPUT, float &INPUT
+ double *INPUT, double &INPUT
+
+To use these, suppose you had a C function like this :
+
+ double fadd(double *a, double *b) {
+ return *a+*b;
+ }
+
+You could wrap it with SWIG as follows :
+
+ %include
+ double fadd(double *INPUT, double *INPUT);
+
+or you can use the %apply directive :
+
+ %include
+ %apply double *INPUT { double *a, double *b };
+ double fadd(double *a, double *b);
+
+In D you could then use it like this:
+ double answer = fadd(10.0, 20.0);
+*/
+
+%define INPUT_TYPEMAP(TYPE, CWTYPE, DTYPE)
+%typemap(cwtype) TYPE *INPUT, TYPE &INPUT "CWTYPE"
+%typemap(dwtype) TYPE *INPUT, TYPE &INPUT "DTYPE"
+%typemap(dptype) TYPE *INPUT, TYPE &INPUT "DTYPE"
+%typemap(din) TYPE *INPUT, TYPE &INPUT "$dinput"
+%typemap(ddirectorin) TYPE *INPUT, TYPE &INPUT "$winput"
+%typemap(ddirectorout) TYPE *INPUT, TYPE &INPUT "$dpcall"
+
+%typemap(in) TYPE *INPUT, TYPE &INPUT
+%{ $1 = ($1_ltype)&$input; %}
+
+%typemap(directorout) TYPE *INPUT, TYPE &INPUT
+%{ $result = ($1_ltype)&$input; %}
+
+%typemap(directorin) TYPE &INPUT
+%{ $input = (CWTYPE *)$1; %}
+
+%typemap(directorin) TYPE *INPUT
+%{ $input = (CWTYPE *)$1; %}
+
+%typemap(typecheck) TYPE *INPUT = TYPE;
+%typemap(typecheck) TYPE &INPUT = TYPE;
+%enddef
+
+INPUT_TYPEMAP(bool, unsigned int, bool)
+//INPUT_TYPEMAP(char, char, char) // Why was this commented out?
+INPUT_TYPEMAP(signed char, signed char, byte)
+INPUT_TYPEMAP(unsigned char, unsigned char, ubyte)
+INPUT_TYPEMAP(short, short, short)
+INPUT_TYPEMAP(unsigned short, unsigned short, ushort)
+INPUT_TYPEMAP(int, int, int)
+INPUT_TYPEMAP(unsigned int, unsigned int, uint)
+INPUT_TYPEMAP(long, long, int)
+INPUT_TYPEMAP(unsigned long, unsigned long, uint)
+INPUT_TYPEMAP(long long, long long, long)
+INPUT_TYPEMAP(unsigned long long, unsigned long long, ulong)
+INPUT_TYPEMAP(float, float, float)
+INPUT_TYPEMAP(double, double, double)
+
+INPUT_TYPEMAP(enum SWIGTYPE, unsigned int, int)
+%typemap(dptype) enum SWIGTYPE *INPUT, enum SWIGTYPE &INPUT "$*dclassname"
+
+#undef INPUT_TYPEMAP
+
+
+/*
+OUTPUT typemaps
+---------------
+
+These typemaps are used for pointer/reference parameters that are output only and
+are mapped to a D output parameter.
+
+The following typemaps can be applied to turn a pointer or reference into an
+"output" value. When calling a function, no input value would be given for
+a parameter, but an output value would be returned. In D, the 'out' keyword is
+used when passing the parameter to a function that takes an output parameter.
+
+ bool *OUTPUT, bool &OUTPUT
+ signed char *OUTPUT, signed char &OUTPUT
+ unsigned char *OUTPUT, unsigned char &OUTPUT
+ short *OUTPUT, short &OUTPUT
+ unsigned short *OUTPUT, unsigned short &OUTPUT
+ int *OUTPUT, int &OUTPUT
+ unsigned int *OUTPUT, unsigned int &OUTPUT
+ long *OUTPUT, long &OUTPUT
+ unsigned long *OUTPUT, unsigned long &OUTPUT
+ long long *OUTPUT, long long &OUTPUT
+ unsigned long long *OUTPUT, unsigned long long &OUTPUT
+ float *OUTPUT, float &OUTPUT
+ double *OUTPUT, double &OUTPUT
+
+For example, suppose you were trying to wrap the modf() function in the
+C math library which splits x into integral and fractional parts (and
+returns the integer part in one of its parameters):
+
+ double modf(double x, double *ip);
+
+You could wrap it with SWIG as follows :
+
+ %include
+ double modf(double x, double *OUTPUT);
+
+or you can use the %apply directive :
+
+ %include
+ %apply double *OUTPUT { double *ip };
+ double modf(double x, double *ip);
+
+The D output of the function would be the function return value and the
+value returned in the second output parameter. In D you would use it like this:
+
+ double dptr;
+ double fraction = modf(5, dptr);
+*/
+
+%define OUTPUT_TYPEMAP(TYPE, CWTYPE, DTYPE, TYPECHECKPRECEDENCE)
+%typemap(cwtype) TYPE *OUTPUT, TYPE &OUTPUT "CWTYPE *"
+%typemap(dwtype) TYPE *OUTPUT, TYPE &OUTPUT "out DTYPE"
+%typemap(dptype) TYPE *OUTPUT, TYPE &OUTPUT "out DTYPE"
+%typemap(din) TYPE *OUTPUT, TYPE &OUTPUT "$dinput"
+%typemap(ddirectorin) TYPE *OUTPUT, TYPE &OUTPUT "$winput"
+%typemap(ddirectorout) TYPE *OUTPUT, TYPE &OUTPUT "$dpcall"
+
+
+%typemap(in) TYPE *OUTPUT, TYPE &OUTPUT
+%{ $1 = ($1_ltype)$input; %}
+
+%typemap(directorout,warning="Need to provide TYPE *OUTPUT directorout typemap") TYPE *OUTPUT, TYPE &OUTPUT {
+}
+
+%typemap(directorin) TYPE &OUTPUT
+%{ $input = &$1; %}
+
+%typemap(directorin,warning="Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown") TYPE *OUTPUT
+{
+}
+
+
+%typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *OUTPUT, TYPE &OUTPUT ""
+%enddef
+
+OUTPUT_TYPEMAP(bool, unsigned int, bool, BOOL_PTR)
+//OUTPUT_TYPEMAP(char, char, char, CHAR_PTR) // Why was this commented out?
+OUTPUT_TYPEMAP(signed char, signed char, ubyte, INT8_PTR)
+OUTPUT_TYPEMAP(unsigned char, unsigned char, byte, UINT8_PTR)
+OUTPUT_TYPEMAP(short, short, short, INT16_PTR)
+OUTPUT_TYPEMAP(unsigned short, unsigned short, ushort, UINT16_PTR)
+OUTPUT_TYPEMAP(int, int, int, INT32_PTR)
+OUTPUT_TYPEMAP(unsigned int, unsigned int, uint, UINT32_PTR)
+OUTPUT_TYPEMAP(long, long, int, INT32_PTR)
+OUTPUT_TYPEMAP(unsigned long, unsigned long, uint, UINT32_PTR)
+OUTPUT_TYPEMAP(long long, long long, long, INT64_PTR)
+OUTPUT_TYPEMAP(unsigned long long, unsigned long long, ulong, UINT64_PTR)
+OUTPUT_TYPEMAP(float, float, float, FLOAT_PTR)
+OUTPUT_TYPEMAP(double, double, double, DOUBLE_PTR)
+
+OUTPUT_TYPEMAP(enum SWIGTYPE, unsigned int, int, INT32_PTR)
+%typemap(dptype) enum SWIGTYPE *OUTPUT, enum SWIGTYPE &OUTPUT "out $*dclassname"
+
+#undef OUTPUT_TYPEMAP
+
+%typemap(in) bool *OUTPUT, bool &OUTPUT
+%{ *$input = 0;
+ $1 = ($1_ltype)$input; %}
+
+
+/*
+INOUT typemaps
+--------------
+
+These typemaps are for pointer/reference parameters that are both input and
+output and are mapped to a D reference parameter.
+
+The following typemaps can be applied to turn a pointer or reference into a
+reference parameters, that is the parameter is both an input and an output.
+In D, the 'ref' keyword is used for reference parameters.
+
+ bool *INOUT, bool &INOUT
+ signed char *INOUT, signed char &INOUT
+ unsigned char *INOUT, unsigned char &INOUT
+ short *INOUT, short &INOUT
+ unsigned short *INOUT, unsigned short &INOUT
+ int *INOUT, int &INOUT
+ unsigned int *INOUT, unsigned int &INOUT
+ long *INOUT, long &INOUT
+ unsigned long *INOUT, unsigned long &INOUT
+ long long *INOUT, long long &INOUT
+ unsigned long long *INOUT, unsigned long long &INOUT
+ float *INOUT, float &INOUT
+ double *INOUT, double &INOUT
+
+For example, suppose you were trying to wrap the following function :
+
+ void neg(double *x) {
+ *x = -(*x);
+ }
+
+You could wrap it with SWIG as follows :
+
+ %include
+ void neg(double *INOUT);
+
+or you can use the %apply directive :
+
+ %include
+ %apply double *INOUT { double *x };
+ void neg(double *x);
+
+The D output of the function would be the new value returned by the
+reference parameter. In D you would use it like this:
+
+
+ double x = 5.0;
+ neg(x);
+
+The implementation of the OUTPUT and INOUT typemaps is different to the scripting
+languages in that the scripting languages will return the output value as part
+of the function return value.
+*/
+
+%define INOUT_TYPEMAP(TYPE, CWTYPE, DTYPE, TYPECHECKPRECEDENCE)
+%typemap(cwtype) TYPE *INOUT, TYPE &INOUT "CWTYPE *"
+%typemap(dwtype) TYPE *INOUT, TYPE &INOUT "ref DTYPE"
+%typemap(dptype) TYPE *INOUT, TYPE &INOUT "ref DTYPE"
+%typemap(din) TYPE *INOUT, TYPE &INOUT "$dinput"
+%typemap(ddirectorin) TYPE *INOUT, TYPE &INOUT "$winput"
+%typemap(ddirectorout) TYPE *INOUT, TYPE &INOUT "$dpcall"
+
+%typemap(in) TYPE *INOUT, TYPE &INOUT
+%{ $1 = ($1_ltype)$input; %}
+
+%typemap(directorout,warning="Need to provide TYPE *INOUT directorout typemap") TYPE *INOUT, TYPE &INOUT {
+}
+
+%typemap(directorin) TYPE &INOUT
+%{ $input = &$1; %}
+
+%typemap(directorin,warning="Need to provide TYPE *INOUT directorin typemap, TYPE array length is unknown") TYPE *INOUT, TYPE &INOUT
+{
+}
+
+%typecheck(SWIG_TYPECHECK_##TYPECHECKPRECEDENCE) TYPE *INOUT, TYPE &INOUT ""
+%enddef
+
+INOUT_TYPEMAP(bool, unsigned int, bool, BOOL_PTR)
+//INOUT_TYPEMAP(char, char, char, CHAR_PTR)
+INOUT_TYPEMAP(signed char, signed char, ubyte, INT8_PTR)
+INOUT_TYPEMAP(unsigned char, unsigned char, byte, UINT8_PTR)
+INOUT_TYPEMAP(short, short, short, INT16_PTR)
+INOUT_TYPEMAP(unsigned short, unsigned short, ushort, UINT16_PTR)
+INOUT_TYPEMAP(int, int, int, INT32_PTR)
+INOUT_TYPEMAP(unsigned int, unsigned int, uint, UINT32_PTR)
+INOUT_TYPEMAP(long, long, int, INT32_PTR)
+INOUT_TYPEMAP(unsigned long, unsigned long, uint, UINT32_PTR)
+INOUT_TYPEMAP(long long, long long, long, INT64_PTR)
+INOUT_TYPEMAP(unsigned long long, unsigned long long, ulong, UINT64_PTR)
+INOUT_TYPEMAP(float, float, float, FLOAT_PTR)
+INOUT_TYPEMAP(double, double, double, DOUBLE_PTR)
+
+INOUT_TYPEMAP(enum SWIGTYPE, unsigned int, int, INT32_PTR)
+%typemap(dptype) enum SWIGTYPE *INOUT, enum SWIGTYPE &INOUT "ref $*dclassname"
+
+#undef INOUT_TYPEMAP
diff --git a/Lib/d/wrapperloader.swg b/Lib/d/wrapperloader.swg
new file mode 100644
index 000000000..9336843af
--- /dev/null
+++ b/Lib/d/wrapperloader.swg
@@ -0,0 +1,303 @@
+/* -----------------------------------------------------------------------------
+ * wrapperloader.swg
+ *
+ * Support code for dynamically linking the C wrapper library from the D
+ * wrapper module.
+ *
+ * The loading code was adapted from the Derelict project and is used with
+ * permission from Michael Parker, the original author.
+ * ----------------------------------------------------------------------------- */
+
+%pragma(d) wrapperloadercode = %{
+private {
+ version(linux) {
+ version = Nix;
+ } else version(darwin) {
+ version = Nix;
+ } else version(OSX) {
+ version = Nix;
+ } else version(FreeBSD) {
+ version = Nix;
+ version = freebsd;
+ } else version(freebsd) {
+ version = Nix;
+ } else version(Unix) {
+ version = Nix;
+ } else version(Posix) {
+ version = Nix;
+ }
+
+ version(Tango) {
+ static import tango.stdc.string;
+ static import tango.stdc.stringz;
+
+ version (PhobosCompatibility) {
+ } else {
+ alias char[] string;
+ alias wchar[] wstring;
+ alias dchar[] dstring;
+ }
+ } else {
+ version(D_Version2) {
+ static import std.conv;
+ }
+ static import std.string;
+ static import std.c.string;
+ }
+
+ version(D_Version2) {
+ mixin("alias const(char)* CCPTR;");
+ } else {
+ alias char* CCPTR;
+ }
+
+ CCPTR swigToCString(string str) {
+ version(Tango) {
+ return tango.stdc.stringz.toStringz(str);
+ } else {
+ return std.string.toStringz(str);
+ }
+ }
+
+ string swigToDString(CCPTR cstr) {
+ version(Tango) {
+ return tango.stdc.stringz.fromStringz(cstr);
+ } else {
+ version(D_Version2) {
+ mixin("return std.conv.to!string(cstr);");
+ } else {
+ return std.c.string.toString(cstr);
+ }
+ }
+ }
+}
+
+class SwigSwigSharedLibLoadException : Exception {
+ this(in string[] libNames, in string[] reasons) {
+ string msg = "Failed to load one or more shared libraries:";
+ foreach(i, n; libNames) {
+ msg ~= "\n\t" ~ n ~ " - ";
+ if(i < reasons.length)
+ msg ~= reasons[i];
+ else
+ msg ~= "Unknown";
+ }
+ super(msg);
+ }
+}
+
+class SwigSymbolLoadException : Exception {
+ this(string SwigSharedLibName, string symbolName) {
+ super("Failed to load symbol " ~ symbolName ~ " from shared library " ~ SwigSharedLibName);
+ _symbolName = symbolName;
+ }
+
+ string symbolName() {
+ return _symbolName;
+ }
+
+private:
+ string _symbolName;
+}
+
+private {
+ version(Nix) {
+ version(freebsd) {
+ // the dl* functions are in libc on FreeBSD
+ }
+ else {
+ pragma(lib, "dl");
+ }
+
+ version(Tango) {
+ import tango.sys.Common;
+ } else version(linux) {
+ import std.c.linux.linux;
+ } else {
+ extern(C) {
+ const RTLD_NOW = 2;
+
+ void *dlopen(CCPTR file, int mode);
+ int dlclose(void* handle);
+ void *dlsym(void* handle, CCPTR name);
+ CCPTR dlerror();
+ }
+ }
+
+ alias void* SwigSharedLibHandle;
+
+ SwigSharedLibHandle swigLoadSharedLib(string libName) {
+ return dlopen(swigToCString(libName), RTLD_NOW);
+ }
+
+ void swigUnloadSharedLib(SwigSharedLibHandle hlib) {
+ dlclose(hlib);
+ }
+
+ void* swigGetSymbol(SwigSharedLibHandle hlib, string symbolName) {
+ return dlsym(hlib, swigToCString(symbolName));
+ }
+
+ string swigGetErrorStr() {
+ CCPTR err = dlerror();
+ if (err is null) {
+ return "Unknown Error";
+ }
+ return swigToDString(err);
+ }
+ } else version(Windows) {
+ alias uint DWORD;
+ alias CCPTR LPCSTR;
+ alias void* HMODULE;
+ alias void* HLOCAL;
+ alias int function() FARPROC;
+ struct VA_LIST {}
+
+ extern (Windows) {
+ HMODULE LoadLibraryA(LPCSTR);
+ FARPROC GetProcAddress(HMODULE, LPCSTR);
+ void FreeLibrary(HMODULE);
+ DWORD GetLastError();
+ DWORD FormatMessageA(DWORD, in void*, DWORD, DWORD, LPCSTR, DWORD, VA_LIST*);
+ HLOCAL LocalFree(HLOCAL);
+ }
+
+ enum {
+ LANG_NEUTRAL = 0,
+ SUBLANG_DEFAULT = 1,
+ FORMAT_MESSAGE_ALLOCATE_BUFFER = 256,
+ FORMAT_MESSAGE_IGNORE_INSERTS = 512,
+ FORMAT_MESSAGE_FROM_SYSTEM = 4096
+ }
+
+ alias HMODULE SwigSharedLibHandle;
+
+ SwigSharedLibHandle swigLoadSharedLib(string libName) {
+ return LoadLibraryA(swigToCString(libName));
+ }
+
+ void swigUnloadSharedLib(SwigSharedLibHandle hlib) {
+ FreeLibrary(hlib);
+ }
+
+ void* swigGetSymbol(SwigSharedLibHandle hlib, string symbolName) {
+ return GetProcAddress(hlib, swigToCString(symbolName));
+ }
+
+ string swigGetErrorStr() {
+ DWORD errcode = GetLastError();
+
+ LPCSTR msgBuf;
+ DWORD i = FormatMessageA(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ null,
+ errcode,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ cast(LPCSTR)&msgBuf,
+ 0,
+ null);
+
+ string text = swigToDString(msgBuf);
+ LocalFree(cast(HLOCAL)msgBuf);
+
+ if (i >= 2) {
+ i -= 2;
+ }
+ return text[0 .. i];
+ }
+ } else {
+ static assert(0, "Operating system not supported by the wrapper loading code.");
+ }
+
+ final class SwigSharedLib {
+ void load(string[] names) {
+ if (_hlib !is null) return;
+
+ string[] failedLibs;
+ string[] reasons;
+
+ foreach(n; names) {
+ _hlib = swigLoadSharedLib(n);
+ if (_hlib is null) {
+ failedLibs ~= n;
+ reasons ~= swigGetErrorStr();
+ continue;
+ }
+ _name = n;
+ break;
+ }
+
+ if (_hlib is null) {
+ throw new SwigSwigSharedLibLoadException(failedLibs, reasons);
+ }
+ }
+
+ void* loadSymbol(string symbolName, bool doThrow = true) {
+ void* sym = swigGetSymbol(_hlib, symbolName);
+ if(doThrow && (sym is null)) {
+ throw new SwigSymbolLoadException(_name, symbolName);
+ }
+ return sym;
+ }
+
+ void unload() {
+ if(_hlib !is null) {
+ swigUnloadSharedLib(_hlib);
+ _hlib = null;
+ }
+ }
+
+ private:
+ string _name;
+ SwigSharedLibHandle _hlib;
+ }
+}
+
+static this() {
+ string[] possibleFileNames;
+ version (Posix) {
+ version (OSX) {
+ possibleFileNames ~= ["lib$wraplibrary.dylib", "lib$wraplibrary.bundle"];
+ }
+ possibleFileNames ~= ["lib$wraplibrary.so"];
+ } else version (Windows) {
+ possibleFileNames ~= ["$wraplibrary.dll", "lib$wraplibrary.so"];
+ } else {
+ static assert(false, "Operating system not supported by the wrapper loading code.");
+ }
+
+ auto library = new SwigSharedLib;
+ library.load(possibleFileNames);
+
+ string bindCode(string functionPointer, string symbol) {
+ return functionPointer ~ " = cast(typeof(" ~ functionPointer ~
+ "))library.loadSymbol(`" ~ symbol ~ "`);";
+ }
+
+ //#if !defined(SWIG_D_NO_EXCEPTION_HELPER)
+ mixin(bindCode("swigRegisterExceptionCallbacks", "SWIGRegisterExceptionCallbacks_$module"));
+ //#endif // SWIG_D_NO_EXCEPTION_HELPER
+ //#if !defined(SWIG_D_NO_STRING_HELPER)
+ mixin(bindCode("swigRegisterStringCallback", "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;
+//#endif // SWIG_D_NO_EXCEPTION_HELPER
+
+//#if !defined(SWIG_D_NO_STRING_HELPER)
+extern(C) void function(SwigStringCallback callback) swigRegisterStringCallback;
+//#endif // SWIG_D_NO_STRING_HELPER
+%}
+
+%pragma(d) wrapperloaderbindcommand = %{
+ mixin(bindCode("$function", "$symbol"));%}
diff --git a/Lib/exception.i b/Lib/exception.i
index 2bc86b458..8d8df33dd 100644
--- a/Lib/exception.i
+++ b/Lib/exception.i
@@ -209,6 +209,40 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
#endif // SWIGLUA
+#ifdef SWIGD
+%{
+SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
+ SWIG_DExceptionCodes exception_code;
+ switch(code) {
+ case SWIG_IndexError:
+ exception_code = SWIG_DNoSuchElementException;
+ break;
+ case SWIG_IOError:
+ exception_code = SWIG_DIOException;
+ break;
+ case SWIG_ValueError:
+ exception_code = SWIG_DIllegalArgumentException;
+ break;
+ case SWIG_DivisionByZero:
+ case SWIG_MemoryError:
+ case SWIG_OverflowError:
+ case SWIG_RuntimeError:
+ case SWIG_TypeError:
+ case SWIG_SyntaxError:
+ case SWIG_SystemError:
+ case SWIG_UnknownError:
+ default:
+ exception_code = SWIG_DException;
+ break;
+ }
+ SWIG_DSetPendingException(exception_code, msg);
+}
+%}
+
+#define SWIG_exception(code, msg)\
+{ SWIG_DThrowException(code, msg); return $null; }
+#endif // SWIGD
+
#ifdef __cplusplus
/*
You can use the SWIG_CATCH_STDEXCEPT macro with the %exception
@@ -259,7 +293,7 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
/* rethrow the unknown exception */
-#ifdef SWIGCSHARP
+#if defined(SWIGCSHARP) || defined(SWIGD)
%typemap(throws,noblock=1, canthrow=1) (...) {
SWIG_exception(SWIG_RuntimeError,"unknown exception");
}
diff --git a/Lib/std_except.i b/Lib/std_except.i
index 769a68995..a4a7a85ac 100644
--- a/Lib/std_except.i
+++ b/Lib/std_except.i
@@ -19,7 +19,7 @@
* a new std_except.i file in the target library directory.
* ----------------------------------------------------------------------------- */
-#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGUILE) || defined(SWIGUTL)
+#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGGUILE) || defined(SWIGUTL) || defined(SWIGD)
#error "This version of std_except.i should not be used"
#endif
diff --git a/Lib/swig.swg b/Lib/swig.swg
index 4ec3d35e6..e7c01823e 100644
--- a/Lib/swig.swg
+++ b/Lib/swig.swg
@@ -77,7 +77,7 @@
#define %clearoldnodefault %feature("oldnodefault","")
/* the %exception directive */
-#ifdef SWIGCSHARP
+#if defined(SWIGCSHARP) || defined(SWIGD)
#define %exception %feature("except", canthrow=1)
#else
#define %exception %feature("except")
@@ -95,7 +95,7 @@
to set/get variable methods. You don't need to use the
%allowexception directive when using %exceptionvar.
*/
-#ifdef SWIGCSHARP
+#if defined(SWIGCSHARP) || defined(SWIGD)
#define %exceptionvar %feature("exceptvar", canthrow=1)
#else
#define %exceptionvar %feature("exceptvar")
diff --git a/Makefile.in b/Makefile.in
index e1f06d0c5..a12366e12 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -76,6 +76,7 @@ skip-cffi = test -n "@SKIP_CFFI@"
skip-uffi = test -n "@SKIP_UFFI@"
skip-r = test -n "@SKIP_R@"
skip-go = test -n "@SKIP_GO@"
+skip-d = test -n "@SKIP_D@"
# Additional dependencies for some tests
skip-gcj = test -n "@SKIP_GCJ@"
@@ -112,6 +113,7 @@ check-aliveness:
@$(skip-lua) || ./$(TARGET) -lua -help
@$(skip-r) || ./$(TARGET) -r -help
@$(skip-go) || ./$(TARGET) -go -help
+ @$(skip-d) || ./$(TARGET) -d -help
check-ccache:
test -z "$(ENABLE_CCACHE)" || (cd $(CCACHE) && $(MAKE) check)
@@ -138,7 +140,8 @@ check-examples: \
check-uffi-examples \
check-cffi-examples \
check-r-examples \
- check-go-examples
+ check-go-examples \
+ check-d-examples
tcl_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/tcl/check.list)
perl5_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/perl5/check.list)
@@ -161,6 +164,7 @@ uffi_examples :=
cffi_examples :=
r_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/r/check.list)
go_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/go/check.list)
+d_examples :=$(shell sed '/^\#/d' $(srcdir)/Examples/d/check.list)
# all examples
check-%-examples :
@@ -213,7 +217,8 @@ check-test-suite: \
check-cffi-test-suite \
check-chicken-test-suite \
check-r-test-suite \
- check-go-test-suite
+ check-go-test-suite \
+ check-d-test-suite
check-%-test-suite:
@if test -z "$(skip-$*)"; then \
@@ -265,7 +270,8 @@ all-test-suite: \
all-cffi-test-suite \
all-chicken-test-suite \
all-r-test-suite \
- all-go-test-suite
+ all-go-test-suite \
+ all-d-test-suite
all-%-test-suite:
@$(MAKE) -k -s check-$*-test-suite ACTION=all
@@ -293,7 +299,8 @@ broken-test-suite: \
broken-cffi-test-suite \
broken-chicken-test-suite \
broken-r-test-suite \
- broken-go-test-suite
+ broken-go-test-suite \
+ broken-d-test-suite
broken-%-test-suite:
@$(MAKE) -k -s check-$*-test-suite ACTION=broken
@@ -410,7 +417,7 @@ install-main:
@$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(BIN_DIR)/`echo $(TARGET_NOEXE) | sed '$(transform)'`@EXEEXT@
lib-languages = gcj typemaps tcl perl5 python guile java mzscheme ruby php ocaml octave \
- pike chicken csharp modula3 allegrocl clisp lua cffi uffi r go
+ pike chicken csharp modula3 allegrocl clisp lua cffi uffi r go d
lib-modules = std
diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h
index 5db30e6e9..d7d11b368 100644
--- a/Source/Include/swigwarn.h
+++ b/Source/Include/swigwarn.h
@@ -1,5 +1,5 @@
-/* -----------------------------------------------------------------------------
- * This file is part of SWIG, which is licensed as a whole under version 3
+/* -----------------------------------------------------------------------------
+ * This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
* terms also apply to certain portions of SWIG. The full details of the SWIG
* license and copyrights can be found in the LICENSE and COPYRIGHT files
@@ -201,6 +201,23 @@
/* Feel free to claim any number in this space that's not currently being used. Just make sure you
add an entry here */
+#define WARN_D_TYPEMAP_CWTYPE_UNDEF 700
+#define WARN_D_TYPEMAP_DWTYPE_UNDEF 701
+#define WARN_D_TYPEMAP_DPTYPE_UNDEF 702
+#define WARN_D_MULTIPLE_INHERITANCE 703
+#define WARN_D_TYPEMAP_CLASSMOD_UNDEF 704
+#define WARN_D_TYPEMAP_DBODY_UNDEF 705
+#define WARN_D_TYPEMAP_DOUT_UNDEF 706
+#define WARN_D_TYPEMAP_DIN_UNDEF 707
+#define WARN_D_TYPEMAP_DDIRECTORIN_UNDEF 708
+#define WARN_D_TYPEMAP_DCONSTRUCTOR_UNDEF 709
+#define WARN_D_EXCODE_MISSING 710
+#define WARN_D_CANTHROW_MISSING 711
+#define WARN_D_NO_DIRECTORCONNECT_ATTR 712
+#define WARN_D_NAME_COLLISION 713
+
+/* please leave 700-719 free for D */
+
#define WARN_RUBY_WRONG_NAME 801
#define WARN_RUBY_MULTIPLE_INHERITANCE 802
diff --git a/Source/Makefile.am b/Source/Makefile.am
index ddf8018ec..984b9c268 100644
--- a/Source/Makefile.am
+++ b/Source/Makefile.am
@@ -42,6 +42,7 @@ eswig_SOURCES = CParse/cscanner.c \
Modules/clisp.cxx \
Modules/contract.cxx \
Modules/csharp.cxx \
+ Modules/d.cxx \
Modules/directors.cxx \
Modules/emit.cxx \
Modules/go.cxx \
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
new file mode 100644
index 000000000..e3e1d9759
--- /dev/null
+++ b/Source/Modules/d.cxx
@@ -0,0 +1,4359 @@
+/* -----------------------------------------------------------------------------
+ * This file is part of SWIG, which is licensed as a whole under version 3
+ * (or any later version) of the GNU General Public License. Some additional
+ * terms also apply to certain portions of SWIG. The full details of the SWIG
+ * license and copyrights can be found in the LICENSE and COPYRIGHT files
+ * included with the SWIG source code as distributed by the SWIG developers
+ * and at http://www.swig.org/legal.html.
+ *
+ * d.cxx
+ *
+ * D language module for SWIG.
+ * ----------------------------------------------------------------------------- */
+
+char cvsroot_d_cxx[] = "$Id$";
+
+#include "swigmod.h"
+#include "cparse.h"
+#include
+
+// Hash type used for storing information about director callbacks for a class.
+typedef DOH UpcallData;
+
+class D : public Language {
+ static const char *usage;
+ const String *empty_string;
+ const String *public_string;
+ const String *protected_string;
+ const String *static_string;
+
+ /*
+ * Files and file sections containing C/C++ code.
+ */
+ File *f_begin;
+ File *f_runtime;
+ File *f_runtime_h;
+ File *f_header;
+ File *f_wrappers;
+ File *f_init;
+ File *f_directors;
+ File *f_directors_h;
+ List *filenames_list;
+
+ /*
+ * Command line-set modes of operation.
+ */
+ // Whether a single proxy D module is generated or classes and enums are
+ // written to their own files.
+ bool split_proxy_dmodule;
+
+ // The major D version targeted (currently 1 or 2).
+ unsigned short d_version;
+
+ /*
+ * State variables which indicate what is being wrapped at the moment.
+ * This is probably not the most elegant way of handling state, but it has
+ * proven to work in the C# and Java modules.
+ */
+ // Indicates if wrapping a native function.
+ bool native_function_flag;
+
+ // Indicates if wrapping a static functions or member variables
+ bool static_flag;
+
+ // Indicates if wrapping a nonstatic member variable
+ bool variable_wrapper_flag;
+
+ // Indicates if wrapping a member variable/enum/const.
+ bool wrapping_member_flag;
+
+ // Indicates if wrapping a global variable.
+ bool global_variable_flag;
+
+ // Name of a variable being wrapped.
+ String *variable_name;
+
+ /*
+ * Variables temporarily holding the generated C++ code.
+ */
+ // C++ code for the generated wrapper functions for casts up the C++
+ // for inheritance hierarchies.
+ String *upcasts_code;
+
+ // Function pointer typedefs for handling director callbacks on the C++ side.
+ String *director_callback_typedefs;
+
+ // Variables for storing the function pointers to the director callbacks on
+ // the C++ side.
+ String *director_callback_pointers;
+
+ /*
+ * Names of generated D entities.
+ */
+ // The name of the D module containing the interface to the C wrapper.
+ String *wrap_dmodule_name;
+
+ // The fully qualified name of the wrap D module (package name included).
+ String *wrap_dmodule_fq_name;
+
+ // The name of the proxy module which exposes the (SWIG) module contents as a
+ // D module.
+ String *proxy_dmodule_name;
+
+ // The fully qualified name of the proxy D module.
+ String *proxy_dmodule_fq_name;
+
+ // Optional: Package the D modules are placed in (set via the -package
+ // command line option).
+ String *package;
+
+ // The directory the generated D module files are written to. Is constructed
+ // from the package path if a target package is set, points to the general
+ // output directory otherwise.
+ String *dmodule_directory;
+
+ // The name of the library which contains the C wrapper (used when generating
+ // the dynamic library loader). Can be overridden via the -wrapperlibrary
+ // command line flag.
+ String *wrap_library_name;
+
+ /*
+ * Variables temporarily holding the generated D code.
+ */
+ // Import statements written to the wrap D module header set via
+ // %pragma(d) wrapdmoduleimports.
+ String *wrap_dmodule_imports;
+
+ // The code for the wrap D module body.
+ String *wrap_dmodule_code;
+
+ // Import statements for all proxy modules (the main proxy module and, if in
+ // split proxy module mode, the proxy class modules) from
+ // %pragma(d) globalproxyimports.
+ String *global_proxy_imports;
+
+ // Imports written to the proxy D module header from global_proxy_imports
+ // and, if in split proxy module mode, from D::requireDType().
+ String *proxy_dmodule_imports;
+
+ // The D code for proxy functions/classes which is written to the proxy D
+ // module. If not in split proxy mode, this contains the whole proxy code.
+ String *proxy_dmodule_code;
+
+ // The D code generated for the currently wrapped enum.
+ String *proxy_enum_code;
+
+ /*
+ * D data for the current proxy class.
+ */
+ // The name of the current proxy class.
+ String *proxy_class_name;
+
+ // The import directives for the current proxy class. They are written to the
+ // same D module the proxy class is written to.
+ String *proxy_class_imports;
+
+ // Code for enumerations nested in the current proxy class. Is emitted earlier
+ // than the rest of the body to work around forward referencing-issues.
+ String *proxy_class_enums_code;
+
+ // The generated D code making up the body of the current proxy class.
+ String *proxy_class_body_code;
+
+ // D code which is emitted right after the proxy class.
+ String *proxy_class_epilogue_code;
+
+ // The full code for the current proxy class, including the epilogue.
+ String* proxy_class_code;
+
+ // Contains a D call to the function wrapping C++ the destructor of the
+ // current class (if there is a public C++ destructor).
+ String *destructor_call;
+
+ // D code for the director callbacks generated for the current class.
+ String *director_dcallbacks_code;
+
+ /*
+ * Code for dynamically loading the wrapper library on the D side.
+ */
+ // D code which is inserted into the wrapper module if dynamic linking is used.
+ String *wrapper_loader_code;
+
+ // The D code to bind a function pointer to a library symbol.
+ String *wrapper_loader_bind_command;
+
+ // The cumulated binding commands binding all wrapper functions to the C/C++
+ // library symbols.
+ String *wrapper_loader_bind_code;
+
+ /*
+ * Director data.
+ */
+ List *dmethods_seq;
+ Hash *dmethods_table;
+ int n_dmethods;
+ int first_class_dmethod;
+ int curr_class_dmethod;
+
+ /*
+ * SWIG types data.
+ */
+ // Collects information about encountered types SWIG does not know about (e.g.
+ // incomplete types). This is used later to generate type wrapper proxy
+ // classes for the unknown types.
+ Hash *unknown_types;
+
+
+public:
+ /* ---------------------------------------------------------------------------
+ * D::D()
+ * --------------------------------------------------------------------------- */
+ D():empty_string(NewString("")),
+ public_string(NewString("public")),
+ protected_string(NewString("protected")),
+ f_begin(NULL),
+ f_runtime(NULL),
+ f_runtime_h(NULL),
+ f_header(NULL),
+ f_wrappers(NULL),
+ f_init(NULL),
+ f_directors(NULL),
+ f_directors_h(NULL),
+ filenames_list(NULL),
+ split_proxy_dmodule(false),
+ d_version(1),
+ native_function_flag(false),
+ static_flag(false),
+ variable_wrapper_flag(false),
+ wrapping_member_flag(false),
+ global_variable_flag(false),
+ variable_name(NULL),
+ upcasts_code(NULL),
+ director_callback_typedefs(NULL),
+ director_callback_pointers(NULL),
+ wrap_dmodule_name(NULL),
+ wrap_dmodule_fq_name(NULL),
+ proxy_dmodule_name(NULL),
+ proxy_dmodule_fq_name(NULL),
+ package(NULL),
+ dmodule_directory(NULL),
+ wrap_library_name(NULL),
+ wrap_dmodule_imports(NULL),
+ wrap_dmodule_code(NULL),
+ global_proxy_imports(NULL),
+ proxy_dmodule_imports(NULL),
+ proxy_dmodule_code(NULL),
+ proxy_enum_code(NULL),
+ proxy_class_name(NULL),
+ proxy_class_imports(NULL),
+ proxy_class_enums_code(NULL),
+ proxy_class_body_code(NULL),
+ proxy_class_epilogue_code(NULL),
+ proxy_class_code(NULL),
+ destructor_call(NULL),
+ director_dcallbacks_code(NULL),
+ wrapper_loader_code(NULL),
+ wrapper_loader_bind_command(NULL),
+ wrapper_loader_bind_code(NULL),
+ dmethods_seq(NULL),
+ dmethods_table(NULL),
+ n_dmethods(0),
+ unknown_types(NULL) {
+
+ // For now, multiple inheritance with directors is not possible. It should be
+ // easy to implement though.
+ director_multiple_inheritance = 0;
+ director_language = 1;
+
+ // Not used:
+ Delete(none_comparison);
+ none_comparison = NewString("");
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::main()
+ * --------------------------------------------------------------------------- */
+ virtual void main(int argc, char *argv[]) {
+ SWIG_library_directory("d");
+
+ // Look for certain command line options
+ for (int i = 1; i < argc; i++) {
+ if (argv[i]) {
+ if ((strcmp(argv[i], "-d2") == 0)) {
+ Swig_mark_arg(i);
+ d_version = 2;
+ } else if (strcmp(argv[i], "-wrapperlibrary") == 0) {
+ if (argv[i + 1]) {
+ wrap_library_name = NewString("");
+ Printf(wrap_library_name, argv[i + 1]);
+ Swig_mark_arg(i);
+ Swig_mark_arg(i + 1);
+ i++;
+ } else {
+ Swig_arg_error();
+ }
+ } else if (strcmp(argv[i], "-package") == 0) {
+ if (argv[i + 1]) {
+ package = NewString("");
+ Printf(package, argv[i + 1]);
+ Swig_mark_arg(i);
+ Swig_mark_arg(i + 1);
+ i++;
+ } else {
+ Swig_arg_error();
+ }
+ } else if ((strcmp(argv[i], "-splitproxy") == 0)) {
+ Swig_mark_arg(i);
+ split_proxy_dmodule = true;
+ } else if (strcmp(argv[i], "-help") == 0) {
+ Printf(stdout, "%s\n", usage);
+ }
+ }
+ }
+
+ // Add a symbol to the parser for conditional compilation
+ Preprocessor_define("SWIGD 1", 0);
+
+ // Also make the target D version available as preprocessor symbol for
+ // use in our library files.
+ String *version_define = NewStringf("SWIG_D_VERSION %u", d_version);
+ Preprocessor_define(version_define, 0);
+ Delete(version_define);
+
+ // Add typemap definitions
+ SWIG_typemap_lang("d");
+ SWIG_config_file("d.swg");
+
+ allow_overloading();
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::top()
+ * --------------------------------------------------------------------------- */
+ virtual int top(Node *n) {
+ // Get any options set in the module directive
+ Node *optionsnode = Getattr(Getattr(n, "module"), "options");
+
+ if (optionsnode) {
+ if (Getattr(optionsnode, "wrapdmodulename")) {
+ wrap_dmodule_name = Copy(Getattr(optionsnode, "wrapdmodulename"));
+ }
+
+ if (Getattr(optionsnode, "directors")) {
+ // Check if directors are enabled for this module. Note: This is a
+ // "master switch", if it is not set, not director code will be emitted
+ // at all. %feature("director") statements are also required to enable
+ // directors for individual classes or methods.
+ //
+ // Use the »directors« attributte of the %module directive to enable
+ // director generation (e.g. »%module(directors="1") modulename«).
+ allow_directors();
+ }
+
+ if (Getattr(optionsnode, "dirprot")) {
+ allow_dirprot();
+ }
+
+ allow_allprotected(GetFlag(optionsnode, "allprotected"));
+ }
+
+ /* Initialize all of the output files */
+ String *outfile = Getattr(n, "outfile");
+ String *outfile_h = Getattr(n, "outfile_h");
+
+ if (!outfile) {
+ Printf(stderr, "Unable to determine outfile\n");
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ f_begin = NewFile(outfile, "w", SWIG_output_files());
+ if (!f_begin) {
+ FileErrorDisplay(outfile);
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ if (directorsEnabled()) {
+ if (!outfile_h) {
+ Printf(stderr, "Unable to determine outfile_h\n");
+ SWIG_exit(EXIT_FAILURE);
+ }
+ f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files());
+ if (!f_runtime_h) {
+ FileErrorDisplay(outfile_h);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ }
+
+ f_runtime = NewString("");
+ f_init = NewString("");
+ f_header = NewString("");
+ f_wrappers = NewString("");
+ f_directors_h = NewString("");
+ f_directors = NewString("");
+
+ /* Register file targets with the SWIG file handler */
+ Swig_register_filebyname("header", f_header);
+ Swig_register_filebyname("wrapper", f_wrappers);
+ Swig_register_filebyname("begin", f_begin);
+ Swig_register_filebyname("runtime", f_runtime);
+ Swig_register_filebyname("init", f_init);
+ Swig_register_filebyname("director", f_directors);
+ Swig_register_filebyname("director_h", f_directors_h);
+
+ unknown_types = NewHash();
+ filenames_list = NewList();
+
+ // Make the package name and the resulting module output path.
+ if (package) {
+ // Append a dot so we can prepend the package variable directly to the
+ // module names in the rest of the code.
+ Printv(package, ".", NIL);
+ } else {
+ // Write the generated D modules to the »root« package by default.
+ package = NewString("");
+ }
+
+ dmodule_directory = Copy(SWIG_output_directory());
+ if (Len(package) > 0) {
+ String *package_directory = Copy(package);
+ Replaceall(package_directory, ".", SWIG_FILE_DELIMITER);
+ Printv(dmodule_directory, package_directory, NIL);
+ Delete(package_directory);
+ }
+
+ // Make the wrap and proxy D module names.
+ // The wrap module name can be set in the module directive.
+ if (!wrap_dmodule_name) {
+ wrap_dmodule_name = NewStringf("%s_wrap", Getattr(n, "name"));
+ }
+ wrap_dmodule_fq_name = NewStringf("%s%s", package, wrap_dmodule_name);
+ proxy_dmodule_name = Copy(Getattr(n, "name"));
+ proxy_dmodule_fq_name = NewStringf("%s%s", package, proxy_dmodule_name);
+
+ wrap_dmodule_code = NewString("");
+ proxy_class_imports = NewString("");
+ proxy_class_enums_code = NewString("");
+ proxy_class_body_code = NewString("");
+ proxy_class_epilogue_code = NewString("");
+ proxy_class_code = NewString("");
+ destructor_call = NewString("");
+ proxy_dmodule_code = NewString("");
+ proxy_dmodule_imports = NewString("");
+ wrap_dmodule_imports = NewString("");
+ upcasts_code = NewString("");
+ global_proxy_imports = NewString("");
+ wrapper_loader_code = NewString("");
+ wrapper_loader_bind_command = NewString("");
+ wrapper_loader_bind_code = NewString("");
+ dmethods_seq = NewList();
+ dmethods_table = NewHash();
+ n_dmethods = 0;
+
+ // By default, expect the dynamically loaded wrapper library to be named
+ // like the wrapper D module (i.e. [lib]_wrap[.so/.dll] unless the
+ // user overrides it).
+ if (!wrap_library_name)
+ wrap_library_name = Copy(wrap_dmodule_name);
+
+ Swig_banner(f_begin);
+
+ Printf(f_runtime, "\n");
+ Printf(f_runtime, "#define SWIGD\n");
+
+ if (directorsEnabled()) {
+ Printf(f_runtime, "#define SWIG_DIRECTORS\n");
+
+ /* Emit initial director header and director code: */
+ Swig_banner(f_directors_h);
+ Printf(f_directors_h, "\n");
+ Printf(f_directors_h, "#ifndef SWIG_%s_WRAP_H_\n", proxy_dmodule_name);
+ Printf(f_directors_h, "#define SWIG_%s_WRAP_H_\n\n", proxy_dmodule_name);
+
+ Printf(f_directors, "\n\n");
+ Printf(f_directors, "/* ---------------------------------------------------\n");
+ Printf(f_directors, " * C++ director class methods\n");
+ Printf(f_directors, " * --------------------------------------------------- */\n\n");
+ if (outfile_h)
+ Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
+ }
+
+ Printf(f_runtime, "\n");
+
+ Swig_name_register("wrapper", "D_%f");
+
+ Printf(f_wrappers, "\n#ifdef __cplusplus\n");
+ Printf(f_wrappers, "extern \"C\" {\n");
+ Printf(f_wrappers, "#endif\n\n");
+
+ // Emit all the wrapper code.
+ Language::top(n);
+
+ if (directorsEnabled()) {
+ // Insert director runtime into the f_runtime file (before %header section).
+ Swig_insert_file("director.swg", f_runtime);
+ }
+
+ // Generate the wrap D module.
+ // TODO: Add support for »static« linking.
+ {
+ String *filen = NewStringf("%s%s.d", dmodule_directory, wrap_dmodule_name);
+ File *wrap_d_file = NewFile(filen, "w", SWIG_output_files());
+ if (!wrap_d_file) {
+ FileErrorDisplay(filen);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Append(filenames_list, Copy(filen));
+ Delete(filen);
+ filen = NULL;
+
+ // Start writing out the intermediary class file.
+ emitBanner(wrap_d_file);
+
+ Printf(wrap_d_file, "module %s;\n", wrap_dmodule_fq_name);
+
+ Printv(wrap_d_file, wrap_dmodule_imports, "\n", NIL);
+
+ Replaceall(wrapper_loader_code, "$wraplibrary", wrap_library_name);
+ Replaceall(wrapper_loader_code, "$wrapperloaderbindcode", wrapper_loader_bind_code);
+ Replaceall(wrapper_loader_code, "$module", proxy_dmodule_name);
+ Printf(wrap_d_file, "%s\n", wrapper_loader_code);
+
+ // Add the wrapper function declarations.
+ replaceModuleVariables(wrap_dmodule_code);
+ Printv(wrap_d_file, wrap_dmodule_code, NIL);
+
+ Close(wrap_d_file);
+ }
+
+ // Generate the D proxy module for the wrapped module.
+ {
+ String *filen = NewStringf("%s%s.d", dmodule_directory, proxy_dmodule_name);
+ File *proxy_d_file = NewFile(filen, "w", SWIG_output_files());
+ if (!proxy_d_file) {
+ FileErrorDisplay(filen);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Append(filenames_list, Copy(filen));
+ Delete(filen);
+ filen = NULL;
+
+ emitBanner(proxy_d_file);
+
+ Printf(proxy_d_file, "module %s;\n", proxy_dmodule_fq_name);
+ Printf(proxy_d_file, "\nstatic import %s;\n", wrap_dmodule_fq_name);
+ Printv(proxy_d_file, global_proxy_imports, NIL);
+ Printv(proxy_d_file, proxy_dmodule_imports, NIL);
+ Printv(proxy_d_file, "\n", NIL);
+
+ // Write a D type wrapper class for each SWIG type to the proxy module code.
+ for (Iterator swig_type = First(unknown_types); swig_type.key; swig_type = Next(swig_type)) {
+ writeTypeWrapperClass(swig_type.key, swig_type.item);
+ }
+
+ // Add the proxy functions (and classes, if they are not written to a
+ // seperate file).
+ replaceModuleVariables(proxy_dmodule_code);
+ Printv(proxy_d_file, proxy_dmodule_code, NIL);
+
+ Close(proxy_d_file);
+ }
+
+ if (upcasts_code)
+ Printv(f_wrappers, upcasts_code, NIL);
+
+ Printf(f_wrappers, "#ifdef __cplusplus\n");
+ Printf(f_wrappers, "}\n");
+ Printf(f_wrappers, "#endif\n");
+
+ // Check for overwriting file problems on filesystems that are case insensitive
+ Iterator it1;
+ Iterator it2;
+ for (it1 = First(filenames_list); it1.item; it1 = Next(it1)) {
+ String *item1_lower = Swig_string_lower(it1.item);
+ for (it2 = Next(it1); it2.item; it2 = Next(it2)) {
+ String *item2_lower = Swig_string_lower(it2.item);
+ if (it1.item && it2.item) {
+ if (Strcmp(item1_lower, item2_lower) == 0) {
+ Swig_warning(WARN_LANG_PORTABILITY_FILENAME, input_file, line_number,
+ "Portability warning: File %s will be overwritten by %s on case insensitive filesystems such as "
+ "Windows' FAT32 and NTFS unless the class/module name is renamed\n", it1.item, it2.item);
+ }
+ }
+ Delete(item2_lower);
+ }
+ Delete(item1_lower);
+ }
+
+ Delete(unknown_types);
+ unknown_types = NULL;
+ Delete(filenames_list);
+ filenames_list = NULL;
+ Delete(wrap_dmodule_name);
+ wrap_dmodule_name = NULL;
+ Delete(wrap_dmodule_fq_name);
+ wrap_dmodule_fq_name = NULL;
+ Delete(wrap_dmodule_code);
+ wrap_dmodule_code = NULL;
+ Delete(proxy_class_imports);
+ proxy_class_imports = NULL;
+ Delete(proxy_class_enums_code);
+ proxy_class_enums_code = NULL;
+ Delete(proxy_class_body_code);
+ proxy_class_body_code = NULL;
+ Delete(proxy_class_epilogue_code);
+ proxy_class_epilogue_code = NULL;
+ Delete(proxy_class_code);
+ proxy_class_code = NULL;
+ Delete(destructor_call);
+ destructor_call = NULL;
+ Delete(proxy_dmodule_name);
+ proxy_dmodule_name = NULL;
+ Delete(proxy_dmodule_fq_name);
+ proxy_dmodule_fq_name = NULL;
+ Delete(proxy_dmodule_code);
+ proxy_dmodule_code = NULL;
+ Delete(proxy_dmodule_imports);
+ proxy_dmodule_imports = NULL;
+ Delete(wrap_dmodule_imports);
+ wrap_dmodule_imports = NULL;
+ Delete(upcasts_code);
+ upcasts_code = NULL;
+ Delete(global_proxy_imports);
+ global_proxy_imports = NULL;
+ Delete(wrapper_loader_code);
+ wrapper_loader_code = NULL;
+ Delete(wrapper_loader_bind_code);
+ wrapper_loader_bind_code = NULL;
+ Delete(wrapper_loader_bind_command);
+ wrapper_loader_bind_command = NULL;
+ Delete(dmethods_seq);
+ dmethods_seq = NULL;
+ Delete(dmethods_table);
+ dmethods_table = NULL;
+ Delete(package);
+ package = NULL;
+ Delete(dmodule_directory);
+ dmodule_directory = NULL;
+ n_dmethods = 0;
+
+ // Merge all the generated C/C++ code and close the output files.
+ Dump(f_runtime, f_begin);
+ Dump(f_header, f_begin);
+
+ if (directorsEnabled()) {
+ Dump(f_directors, f_begin);
+ Dump(f_directors_h, f_runtime_h);
+
+ Printf(f_runtime_h, "\n");
+ Printf(f_runtime_h, "#endif\n");
+
+ Close(f_runtime_h);
+ Delete(f_runtime_h);
+ f_runtime_h = NULL;
+ Delete(f_directors);
+ f_directors = NULL;
+ Delete(f_directors_h);
+ f_directors_h = NULL;
+ }
+
+ Dump(f_wrappers, f_begin);
+ Wrapper_pretty_print(f_init, f_begin);
+ Delete(f_header);
+ Delete(f_wrappers);
+ Delete(f_init);
+ Close(f_begin);
+ Delete(f_runtime);
+ Delete(f_begin);
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::insertDirective()
+ * --------------------------------------------------------------------------- */
+ virtual int insertDirective(Node *n) {
+ String *code = Getattr(n, "code");
+ replaceModuleVariables(code);
+ return Language::insertDirective(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::pragmaDirective()
+ *
+ * Valid Pragmas:
+ * wrapdmodulecode - text (D code) is copied verbatim to the wrap module
+ * wrapdmoduleimports - import statements for the wrap module
+ *
+ * proxydmodulecode - text (D code) is copied verbatim to the proxy module
+ * (the main proxy module if in split proxy mode).
+ * globalproxyimports - import statements inserted into _all_ proxy modules.
+ *
+ * wrapperloadercode - D code for loading the wrapper library (is copied to
+ * the wrap D module).
+ * wrapperloaderbindcommand - D code for binding a symbol from the wrapper
+ * library to the declaration in the wrap D module.
+ * --------------------------------------------------------------------------- */
+ virtual int pragmaDirective(Node *n) {
+ if (!ImportMode) {
+ String *lang = Getattr(n, "lang");
+ String *code = Getattr(n, "name");
+ String *value = Getattr(n, "value");
+
+ if (Strcmp(lang, "d") == 0) {
+ String *strvalue = NewString(value);
+ Replaceall(strvalue, "\\\"", "\"");
+
+ if (Strcmp(code, "wrapdmodulecode") == 0) {
+ Printf(wrap_dmodule_code, "%s\n", strvalue);
+ } else if (Strcmp(code, "wrapdmoduleimports") == 0) {
+ replaceImportTypeMacros(strvalue);
+ Chop(strvalue);
+ Printf(wrap_dmodule_imports, "%s\n", strvalue);
+ } else if (Strcmp(code, "proxydmodulecode") == 0) {
+ Printf(proxy_dmodule_code, "%s\n", strvalue);
+ } else if (Strcmp(code, "globalproxyimports") == 0) {
+ replaceImportTypeMacros(strvalue);
+ Chop(strvalue);
+ Printf(global_proxy_imports, "%s\n", strvalue);
+ } else if (Strcmp(code, "wrapperloadercode") == 0) {
+ Delete(wrapper_loader_code);
+ wrapper_loader_code = Copy(strvalue);
+ } else if (Strcmp(code, "wrapperloaderbindcommand") == 0) {
+ Delete(wrapper_loader_bind_command);
+ wrapper_loader_bind_command = Copy(strvalue);
+ } else {
+ Swig_error(input_file, line_number, "Unrecognized pragma.\n");
+ }
+ Delete(strvalue);
+ }
+ }
+ return Language::pragmaDirective(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::enumDeclaration()
+ *
+ * Wraps C/C++ enums as D enums.
+ * --------------------------------------------------------------------------- */
+ virtual int enumDeclaration(Node *n) {
+ if (ImportMode)
+ return SWIG_OK;
+
+ if (getCurrentClass() && (cplus_mode != PUBLIC))
+ return SWIG_NOWRAP;
+
+ proxy_enum_code = NewString("");
+ String *symname = Getattr(n, "sym:name");
+ String *typemap_lookup_type = Getattr(n, "name");
+
+ // Emit the enum declaration.
+ if (typemap_lookup_type) {
+ const String *enummodifiers = lookupCodeTypemap(n, "dclassmodifiers", typemap_lookup_type, WARN_D_TYPEMAP_CLASSMOD_UNDEF);
+ Printv(proxy_enum_code, "\n", enummodifiers, " ", symname, " {\n", NIL);
+ } else {
+ // Handle anonymous enums.
+ Printv(proxy_enum_code, "\nenum {\n", NIL);
+ }
+
+ // Emit each enum item.
+ Language::enumDeclaration(n);
+
+ if (!GetFlag(n, "nonempty")) {
+ // Do not wrap empty enums; the resulting D code would be illegal.
+ Delete(proxy_enum_code);
+ return SWIG_NOWRAP;
+ }
+
+ // Finish the enum.
+ if (typemap_lookup_type) {
+ Printv(proxy_enum_code,
+ lookupCodeTypemap(n, "dcode", typemap_lookup_type, WARN_NONE), // Extra D code
+ "\n}\n", NIL);
+ } else {
+ // Handle anonymous enums.
+ Printv(proxy_enum_code, "\n}\n", NIL);
+ }
+
+ Replaceall(proxy_enum_code, "$dclassname", symname);
+
+ const String* imports =
+ lookupCodeTypemap(n, "dimports", typemap_lookup_type, WARN_NONE);
+ String* imports_trimmed;
+ if (Len(imports) > 0) {
+ imports_trimmed = Copy(imports);
+ Chop(imports_trimmed);
+ replaceImportTypeMacros(imports_trimmed);
+ Printv(imports_trimmed, "\n", NIL);
+ } else {
+ imports_trimmed = NewString("");
+ }
+
+ if (is_wrapping_class()) {
+ // Enums defined within the C++ class are written into the proxy
+ // class.
+ Printv(proxy_class_imports, imports_trimmed, NIL);
+ Printv(proxy_class_enums_code, proxy_enum_code, NIL);
+ } else {
+ // Write non-anonymous enums to their own file if in split proxy module
+ // mode.
+ if (split_proxy_dmodule && typemap_lookup_type) {
+ assertClassNameValidity(proxy_class_name);
+
+ String *filename = NewStringf("%s%s.d", dmodule_directory, symname);
+ File *class_file = NewFile(filename, "w", SWIG_output_files());
+ if (!class_file) {
+ FileErrorDisplay(filename);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Append(filenames_list, Copy(filename));
+ Delete(filename);
+
+ emitBanner(class_file);
+ Printf(class_file, "module %s%s;\n", package, symname);
+ Printv(class_file, imports_trimmed, NIL);
+
+ Printv(class_file, proxy_enum_code, NIL);
+
+ Close(class_file);
+ Delete(class_file);
+ } else {
+ Printv(proxy_dmodule_imports, imports, NIL);
+ Printv(proxy_dmodule_code, proxy_enum_code, NIL);
+ }
+ }
+
+ Delete(imports_trimmed);
+
+ Delete(proxy_enum_code);
+ proxy_enum_code = NULL;
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::enumvalueDeclaration()
+ * --------------------------------------------------------------------------- */
+ virtual int enumvalueDeclaration(Node *n) {
+ if (getCurrentClass() && (cplus_mode != PUBLIC))
+ return SWIG_NOWRAP;
+
+ Swig_require("enumvalueDeclaration", n, "*name", "?value", NIL);
+ String *value = Getattr(n, "value");
+ String *name = Getattr(n, "name");
+ Node *parent = parentNode(n);
+ String *tmpValue;
+
+ // Strange hack from parent method.
+ // RESEARCH: What is this doing?
+ if (value)
+ tmpValue = NewString(value);
+ else
+ tmpValue = NewString(name);
+ // Note that this is used in enumValue() amongst other places
+ Setattr(n, "value", tmpValue);
+
+ String *proxy_name = Getattr(n, "sym:name");
+
+ // Emit the enum item.
+ {
+ if (!GetFlag(n, "firstenumitem"))
+ Printf(proxy_enum_code, ",\n");
+
+ Printf(proxy_enum_code, " %s", proxy_name);
+
+ // Check for the %dconstvalue feature
+ String *value = Getattr(n, "feature:d:constvalue");
+
+ // Note that in D, enum values must be compile-time constants. Thus,
+ // %dnativeconst(0) (getting the enum values at runtime) is not supported.
+ value = value ? value : Getattr(n, "enumvalue");
+ if (value) {
+ Printf(proxy_enum_code, " = %s", value);
+ }
+
+ // Keep track that the currently processed enum has at least one value.
+ SetFlag(parent, "nonempty");
+ }
+
+ Delete(tmpValue);
+ Swig_restore(n);
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::memberfunctionHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int memberfunctionHandler(Node *n) {
+ Language::memberfunctionHandler(n);
+
+ String *overloaded_name = getOverloadedName(n);
+ String *intermediary_function_name =
+ Swig_name_member(NSPACE_TODO,proxy_class_name, overloaded_name);
+ Setattr(n, "imfuncname", intermediary_function_name);
+
+ String *proxy_func_name = Getattr(n, "sym:name");
+ Setattr(n, "proxyfuncname", proxy_func_name);
+ if (split_proxy_dmodule &&
+ Len(Getattr(n, "parms")) == 0 &&
+ Strncmp(proxy_func_name, package, Len(proxy_func_name)) == 0) {
+ // If we are in split proxy mode and the function is named like the
+ // target package, the D compiler is unable to resolve the ambiguity
+ // between the package name and an argument-less function call.
+ Swig_warning(WARN_D_NAME_COLLISION, input_file, line_number,
+ "%s::%s might collide with the package name, consider using %%rename to resolve the ambiguity.\n",
+ proxy_class_name, proxy_func_name);
+ }
+
+ writeProxyClassFunction(n);
+
+ Delete(overloaded_name);
+
+ // For each function, look if we have to alias in the parent class function
+ // for the overload resolution process to work as expected from C++
+ // (http://www.digitalmars.com/d/2.0/function.html#function-inheritance).
+ // For multiple overloads, only emit the alias directive once (for the
+ // last method, »sym:nextSibling« is null then).
+ // Smart pointer classes do not mirror the inheritance hierarchy of the
+ // underlying types, so aliasing the base class methods in is not required
+ // for them.
+ // DMD BUG: We have to emit the alias after the last function becasue
+ // taking a delegate in the overload checking code fails otherwise
+ // (http://d.puremagic.com/issues/show_bug.cgi?id=4860).
+ if (!Getattr(n, "sym:nextSibling") && !is_smart_pointer() &&
+ !areAllOverloadsOverridden(n)) {
+ String *name = Getattr(n, "sym:name");
+ Printf(proxy_class_body_code, "\nalias $dbaseclass.%s %s;\n", name, name);
+ }
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::staticmemberfunctionHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int staticmemberfunctionHandler(Node *n) {
+ static_flag = true;
+
+ Language::staticmemberfunctionHandler(n);
+
+ String *overloaded_name = getOverloadedName(n);
+ String *intermediary_function_name =
+ Swig_name_member(NSPACE_TODO,proxy_class_name, overloaded_name);
+ Setattr(n, "proxyfuncname", Getattr(n, "sym:name"));
+ Setattr(n, "imfuncname", intermediary_function_name);
+ writeProxyClassFunction(n);
+ Delete(overloaded_name);
+
+ static_flag = false;
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::globalvariableHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int globalvariableHandler(Node *n) {
+ variable_name = Getattr(n, "sym:name");
+ global_variable_flag = true;
+ int ret = Language::globalvariableHandler(n);
+ global_variable_flag = false;
+
+ return ret;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::membervariableHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int membervariableHandler(Node *n) {
+ variable_name = Getattr(n, "sym:name");
+ wrapping_member_flag = true;
+ variable_wrapper_flag = true;
+ Language::membervariableHandler(n);
+ wrapping_member_flag = false;
+ variable_wrapper_flag = false;
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::staticmembervariableHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int staticmembervariableHandler(Node *n) {
+ if (GetFlag(n, "feature:d:nativeconst") != 1) {
+ Delattr(n, "value");
+ }
+
+ variable_name = Getattr(n, "sym:name");
+ wrapping_member_flag = true;
+ static_flag = true;
+ Language::staticmembervariableHandler(n);
+ wrapping_member_flag = false;
+ static_flag = false;
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::memberconstantHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int memberconstantHandler(Node *n) {
+ variable_name = Getattr(n, "sym:name");
+ wrapping_member_flag = true;
+ Language::memberconstantHandler(n);
+ wrapping_member_flag = false;
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::constructorHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int constructorHandler(Node *n) {
+ Language::constructorHandler(n);
+
+ // Wrappers not wanted for some methods where the parameters cannot be overloaded in D.
+ if (Getattr(n, "overload:ignore")) {
+ return SWIG_OK;
+ }
+
+ ParmList *l = Getattr(n, "parms");
+ String *tm;
+ String *proxy_constructor_code = NewString("");
+
+ // Holds code for the constructor helper method generated only when the din
+ // typemap has code in the pre or post attributes.
+ String *helper_code = NewString("");
+ String *helper_args = NewString("");
+ String *pre_code = NewString("");
+ String *post_code = NewString("");
+ String *terminator_code = NewString("");
+ NewString("");
+
+ String *overloaded_name = getOverloadedName(n);
+ String *mangled_overname = Swig_name_construct(NSPACE_TODO,overloaded_name);
+ String *imcall = NewString("");
+
+ const String *methodmods = Getattr(n, "feature:d:methodmodifiers");
+ methodmods = methodmods ? methodmods : (is_public(n) ? public_string : protected_string);
+
+ // Typemaps were attached earlier to the node, get the return type of the
+ // call to the C++ constructor wrapper.
+ const String *wrapper_return_type = lookupDTypemap(n, "dwtype", true);
+
+ String *dwtypeout = Getattr(n, "tmap:dwtype:out");
+ if (dwtypeout) {
+ // The type in the dwtype typemap's out attribute overrides the type in
+ // the typemap itself.
+ wrapper_return_type = dwtypeout;
+ }
+
+ Printf(proxy_constructor_code, "\n%s this(", methodmods);
+ Printf(helper_code, "static private %s SwigConstruct%s(",
+ wrapper_return_type, proxy_class_name);
+
+ Printv(imcall, wrap_dmodule_fq_name, ".", mangled_overname, "(", NIL);
+
+ /* Attach the non-standard typemaps to the parameter list */
+ Swig_typemap_attach_parms("in", l, NULL);
+ Swig_typemap_attach_parms("dptype", l, NULL);
+ Swig_typemap_attach_parms("din", l, NULL);
+
+ emit_mark_varargs(l);
+
+ int gencomma = 0;
+
+ /* Output each parameter */
+ Parm *p = l;
+ for (unsigned int i = 0; p; i++) {
+ if (checkAttribute(p, "varargs:ignore", "1")) {
+ // Skip ignored varargs.
+ p = nextSibling(p);
+ continue;
+ }
+
+ if (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ // Skip ignored parameters.
+ p = Getattr(p, "tmap:in:next");
+ continue;
+ }
+
+ SwigType *pt = Getattr(p, "type");
+ String *param_type = NewString("");
+
+ // Get the D parameter type.
+ if ((tm = lookupDTypemap(p, "dptype", true))) {
+ const String *inattributes = Getattr(p, "tmap:dptype:inattributes");
+ Printf(param_type, "%s%s", inattributes ? inattributes : empty_string, tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ if (gencomma)
+ Printf(imcall, ", ");
+
+ String *arg = makeParameterName(n, p, i, false);
+ String *parmtype = 0;
+
+ // Get the D code to convert the parameter value to the type used in the
+ // wrapper D module.
+ if ((tm = lookupDTypemap(p, "din"))) {
+ Replaceall(tm, "$dinput", arg);
+ String *pre = Getattr(p, "tmap:din:pre");
+ if (pre) {
+ replaceClassname(pre, pt);
+ Replaceall(pre, "$dinput", arg);
+ if (Len(pre_code) > 0)
+ Printf(pre_code, "\n");
+ Printv(pre_code, pre, NIL);
+ }
+ String *post = Getattr(p, "tmap:din:post");
+ if (post) {
+ replaceClassname(post, pt);
+ Replaceall(post, "$dinput", arg);
+ if (Len(post_code) > 0)
+ Printf(post_code, "\n");
+ Printv(post_code, post, NIL);
+ }
+ String *terminator = Getattr(p, "tmap:din:terminator");
+ if (terminator) {
+ replaceClassname(terminator, pt);
+ Replaceall(terminator, "$dinput", arg);
+ if (Len(terminator_code) > 0)
+ Insert(terminator_code, 0, "\n");
+ Insert(terminator_code, 0, terminator);
+ }
+ parmtype = Getattr(p, "tmap:din:parmtype");
+ if (parmtype)
+ Replaceall(parmtype, "$dinput", arg);
+ Printv(imcall, tm, NIL);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DIN_UNDEF, input_file, line_number,
+ "No din typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ /* Add parameter to proxy function */
+ if (gencomma) {
+ Printf(proxy_constructor_code, ", ");
+ Printf(helper_code, ", ");
+ Printf(helper_args, ", ");
+ }
+ Printf(proxy_constructor_code, "%s %s", param_type, arg);
+ Printf(helper_code, "%s %s", param_type, arg);
+ Printf(helper_args, "%s", parmtype ? parmtype : arg);
+ ++gencomma;
+
+ Delete(parmtype);
+ Delete(arg);
+ Delete(param_type);
+ p = Getattr(p, "tmap:in:next");
+ }
+
+ Printf(imcall, ")");
+
+ Printf(proxy_constructor_code, ")");
+ Printf(helper_code, ")");
+
+ // Insert the dconstructor typemap (replacing $directorconnect as needed).
+ Hash *attributes = NewHash();
+ String *construct_tm = Copy(lookupCodeTypemap(n, "dconstructor",
+ Getattr(n, "name"), WARN_D_TYPEMAP_DCONSTRUCTOR_UNDEF, attributes));
+ if (construct_tm) {
+ const bool use_director = (parentNode(n) && Swig_directorclass(n));
+ if (!use_director) {
+ Replaceall(construct_tm, "$directorconnect", "");
+ } else {
+ String *connect_attr = Getattr(attributes, "tmap:dconstructor:directorconnect");
+
+ if (connect_attr) {
+ Replaceall(construct_tm, "$directorconnect", connect_attr);
+ } else {
+ Swig_warning(WARN_D_NO_DIRECTORCONNECT_ATTR, input_file, line_number,
+ "\"directorconnect\" attribute missing in %s \"dconstructor\" typemap.\n",
+ Getattr(n, "name"));
+ Replaceall(construct_tm, "$directorconnect", "");
+ }
+ }
+
+ Printv(proxy_constructor_code, " ", construct_tm, NIL);
+ }
+
+ replaceExcode(n, proxy_constructor_code, "dconstructor", attributes);
+
+ bool is_pre_code = Len(pre_code) > 0;
+ bool is_post_code = Len(post_code) > 0;
+ bool is_terminator_code = Len(terminator_code) > 0;
+ if (is_pre_code || is_post_code || is_terminator_code) {
+ Printf(helper_code, " {\n");
+ if (is_pre_code) {
+ Printv(helper_code, pre_code, "\n", NIL);
+ }
+ if (is_post_code) {
+ Printf(helper_code, " try {\n");
+ Printv(helper_code, " return ", imcall, ";\n", NIL);
+ Printv(helper_code, " } finally {\n", post_code, "\n }", NIL);
+ } else {
+ Printv(helper_code, " return ", imcall, ";", NIL);
+ }
+ if (is_terminator_code) {
+ Printv(helper_code, "\n", terminator_code, NIL);
+ }
+ Printf(helper_code, "\n}\n");
+ String *helper_name = NewStringf("%s.SwigConstruct%s(%s)",
+ proxy_class_name, proxy_class_name, helper_args);
+ Replaceall(proxy_constructor_code, "$wcall", helper_name);
+ Delete(helper_name);
+ } else {
+ Replaceall(proxy_constructor_code, "$wcall", imcall);
+ }
+
+ Printv(proxy_class_body_code, proxy_constructor_code, "\n", NIL);
+
+ Delete(helper_args);
+ Delete(pre_code);
+ Delete(post_code);
+ Delete(terminator_code);
+ Delete(construct_tm);
+ Delete(attributes);
+ Delete(overloaded_name);
+ Delete(imcall);
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::destructorHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int destructorHandler(Node *n) {
+ Language::destructorHandler(n);
+ String *symname = Getattr(n, "sym:name");
+ Printv(destructor_call, wrap_dmodule_fq_name, ".", Swig_name_destroy(NSPACE_TODO,symname), "(cast(void*)swigCPtr)", NIL);
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classHandler()
+ * --------------------------------------------------------------------------- */
+ virtual int classHandler(Node *n) {
+ File *class_file = NULL;
+
+ proxy_class_name = Copy(Getattr(n, "sym:name"));
+
+ if (!addSymbol(proxy_class_name, n)) {
+ return SWIG_ERROR;
+ }
+
+ assertClassNameValidity(proxy_class_name);
+
+ if (split_proxy_dmodule) {
+ String *filename = NewStringf("%s%s.d", dmodule_directory, proxy_class_name);
+ class_file = NewFile(filename, "w", SWIG_output_files());
+ if (!class_file) {
+ FileErrorDisplay(filename);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Append(filenames_list, Copy(filename));
+ Delete(filename);
+
+ emitBanner(class_file);
+ Printf(class_file, "module %s%s;\n", package, proxy_class_name);
+ Printf(class_file, "\nstatic import %s;\n", wrap_dmodule_fq_name);
+ }
+
+ Clear(proxy_class_imports);
+ Clear(proxy_class_enums_code);
+ Clear(proxy_class_body_code);
+ Clear(proxy_class_epilogue_code);
+ Clear(proxy_class_code);
+ Clear(destructor_call);
+
+
+ Language::classHandler(n);
+
+
+ writeProxyClassAndUpcasts(n);
+ writeDirectorConnectWrapper(n);
+
+ Replaceall(proxy_class_code, "$dclassname", proxy_class_name);
+
+ if (split_proxy_dmodule) {
+ Printv(class_file, global_proxy_imports, NIL);
+ Printv(class_file, proxy_class_imports, NIL);
+
+ replaceModuleVariables(proxy_class_code);
+ Printv(class_file, proxy_class_code, NIL);
+
+ Close(class_file);
+ Delete(class_file);
+ } else {
+ Printv(proxy_dmodule_imports, proxy_class_imports, NIL);
+ Printv(proxy_dmodule_code, proxy_class_code, NIL);
+ }
+
+ Delete(proxy_class_name);
+ proxy_class_name = NULL;
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::constantWrapper()
+ *
+ * Used for wrapping constants declared by #define or %constant and also for
+ * (primitive) static member constants initialised inline.
+ *
+ * If the %dnativeconst feature is used, the C/C++ constant value is used to
+ * initialize a D »const«. If not, a »getter« method is generated which
+ * retrieves the value via a call to the C wrapper. However, if there is a
+ * %dconstvalue specified, it overrides all other settings.
+ * --------------------------------------------------------------------------- */
+ virtual int constantWrapper(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ if (!addSymbol(symname, n))
+ return SWIG_ERROR;
+
+ // The %dnativeconst feature determines if a D const or a getter function is
+ // created.
+ if (GetFlag(n, "feature:d:nativeconst") != 1) {
+ // Default constant handling will work with any type of C constant. It
+ // generates a getter function (which is the same as a read only property
+ // in D) which retrieves the value via by calling the C wrapper.
+ // Note that this is only called for global constants, static member
+ // constants are already handeled in staticmemberfunctionHandler().
+
+ Swig_save("constantWrapper", n, "value", NIL);
+
+ // Add the stripped quotes back in.
+ String *old_value = Getattr(n, "value");
+ SwigType *t = Getattr(n, "type");
+ if (SwigType_type(t) == T_STRING) {
+ Setattr(n, "value", NewStringf("\"%s\"", old_value));
+ Delete(old_value);
+ } else if (SwigType_type(t) == T_CHAR) {
+ Setattr(n, "value", NewStringf("\'%s\'", old_value));
+ Delete(old_value);
+ }
+
+ int result = globalvariableHandler(n);
+
+ Swig_restore(n);
+ return result;
+ }
+
+ String *constants_code = NewString("");
+ SwigType *t = Getattr(n, "type");
+ ParmList *l = Getattr(n, "parms");
+
+ // Attach the non-standard typemaps to the parameter list.
+ Swig_typemap_attach_parms("dptype", l, NULL);
+
+ // Get D return type.
+ String *return_type = NewString("");
+ String *tm;
+ if ((tm = lookupDTypemap(n, "dptype"))) {
+ String *dptypeout = Getattr(n, "tmap:dptype:out");
+ if (dptypeout) {
+ // The type in the out attribute of the typemap overrides the type
+ // in the dptype typemap.
+ tm = dptypeout;
+ replaceClassname(tm, t);
+ }
+ Printf(return_type, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ const String *itemname = wrapping_member_flag ? variable_name : symname;
+
+ String *attributes = Getattr(n, "feature:d:methodmodifiers");
+ if (attributes) {
+ attributes = Copy(attributes);
+ } else {
+ attributes = Copy(is_public(n) ? public_string : protected_string);
+ }
+
+ if (d_version == 1) {
+ if (static_flag) {
+ Printv(attributes, " static", NIL);
+ }
+ Printf(constants_code, "\n%s const %s %s = ", attributes, return_type, itemname);
+ } else {
+ Printf(constants_code, "\n%s enum %s %s = ", attributes, return_type, itemname);
+ }
+ Delete(attributes);
+
+ // Retrive the override value set via %dconstvalue, if any.
+ String *override_value = Getattr(n, "feature:d:constvalue");
+ if (override_value) {
+ Printf(constants_code, "%s;\n", override_value);
+ } else {
+ // Just take the value from the C definition and hope it compiles in D.
+ String* value = Getattr(n, "wrappedasconstant") ?
+ Getattr(n, "staticmembervariableHandler:value") : Getattr(n, "value");
+
+ // Add the stripped quotes back in.
+ if (SwigType_type(t) == T_STRING) {
+ Printf(constants_code, "\"%s\";\n", value);
+ } else if (SwigType_type(t) == T_CHAR) {
+ Printf(constants_code, "\'%s\';\n", value);
+ } else {
+ Printf(constants_code, "%s;\n", value);
+ }
+ }
+
+ // Emit the generated code to appropriate place.
+ if (wrapping_member_flag) {
+ Printv(proxy_class_body_code, constants_code, NIL);
+ } else {
+ Printv(proxy_dmodule_code, constants_code, NIL);
+ }
+
+ // Cleanup.
+ Delete(return_type);
+ Delete(constants_code);
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::functionWrapper()
+ *
+ * Generates the C wrapper code for a function and the corresponding
+ * declaration in the wrap D module.
+ * --------------------------------------------------------------------------- */
+ virtual int functionWrapper(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ SwigType *t = Getattr(n, "type");
+ ParmList *l = Getattr(n, "parms");
+ String *tm;
+ Parm *p;
+ int i;
+ String *c_return_type = NewString("");
+ String *im_return_type = NewString("");
+ String *cleanup = NewString("");
+ String *outarg = NewString("");
+ String *body = NewString("");
+ int num_arguments = 0;
+ int num_required = 0;
+ bool is_void_return;
+ String *overloaded_name = getOverloadedName(n);
+
+ if (!Getattr(n, "sym:overloaded")) {
+ if (!addSymbol(Getattr(n, "sym:name"), n))
+ return SWIG_ERROR;
+ }
+
+ // A new wrapper function object
+ Wrapper *f = NewWrapper();
+
+ // Make a wrapper name for this function
+ String *wname = Swig_name_wrapper(overloaded_name);
+
+ /* Attach the non-standard typemaps to the parameter list. */
+ Swig_typemap_attach_parms("cwtype", l, f);
+ Swig_typemap_attach_parms("dwtype", l, f);
+
+ /* Get return types */
+ if ((tm = lookupDTypemap(n, "cwtype"))) {
+ String *cwtypeout = Getattr(n, "tmap:cwtype:out");
+ if (cwtypeout) {
+ // The type in the cwtype typemap's out attribute overrides the type in
+ // the typemap itself.
+ tm = cwtypeout;
+ }
+ Printf(c_return_type, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number,
+ "No cwtype typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ if ((tm = lookupDTypemap(n, "dwtype"))) {
+ String *dwtypeout = Getattr(n, "tmap:dwtype:out");
+ if (dwtypeout) {
+ // The type in the dwtype typemap's out attribute overrides the type in
+ // the typemap itself.
+ tm = dwtypeout;
+ }
+ Printf(im_return_type, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number, "No dwtype typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ is_void_return = (Cmp(c_return_type, "void") == 0);
+ if (!is_void_return)
+ Wrapper_add_localv(f, "jresult", c_return_type, "jresult", NIL);
+
+ Printv(f->def, " SWIGEXPORT ", c_return_type, " SWIGSTDCALL ", wname, "(", NIL);
+
+ // Emit all of the local variables for holding arguments.
+ emit_parameter_variables(l, f);
+
+ /* Attach the standard typemaps */
+ emit_attach_parmmaps(l, f);
+
+ // Parameter overloading
+ Setattr(n, "wrap:parms", l);
+ Setattr(n, "wrap:name", wname);
+
+ // Wrappers not wanted for some methods where the parameters cannot be overloaded in D
+ if (Getattr(n, "sym:overloaded")) {
+ // Emit warnings for the few cases that can't be overloaded in D and give up on generating wrapper
+ Swig_overload_check(n);
+ if (Getattr(n, "overload:ignore"))
+ return SWIG_OK;
+ }
+
+ // Collect the parameter list for the wrap D module declaration of the
+ // generated wrapper function.
+ String *wrap_dmodule_parameters = NewString("(");
+
+ /* Get number of required and total arguments */
+ num_arguments = emit_num_arguments(l);
+ num_required = emit_num_required(l);
+ int gencomma = 0;
+
+ // Now walk the function parameter list and generate code to get arguments
+ for (i = 0, p = l; i < num_arguments; i++) {
+
+ while (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ p = Getattr(p, "tmap:in:next");
+ }
+
+ SwigType *pt = Getattr(p, "type");
+ String *ln = Getattr(p, "lname");
+ String *im_param_type = NewString("");
+ String *c_param_type = NewString("");
+ String *arg = NewString("");
+
+ Printf(arg, "j%s", ln);
+
+ /* Get the cwtype types of the parameter */
+ if ((tm = lookupDTypemap(p, "cwtype", true))) {
+ Printv(c_param_type, tm, NIL);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number, "No cwtype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ /* Get the intermediary class parameter types of the parameter */
+ if ((tm = lookupDTypemap(p, "dwtype", true))) {
+ const String *inattributes = Getattr(p, "tmap:dwtype:inattributes");
+ Printf(im_param_type, "%s%s", inattributes ? inattributes : empty_string, tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number, "No dwtype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ /* Add parameter to intermediary class method */
+ if (gencomma)
+ Printf(wrap_dmodule_parameters, ", ");
+ Printf(wrap_dmodule_parameters, "%s %s", im_param_type, arg);
+
+ // Add parameter to C function
+ Printv(f->def, gencomma ? ", " : "", c_param_type, " ", arg, NIL);
+
+ gencomma = 1;
+
+ // Get typemap for this argument
+ if ((tm = Getattr(p, "tmap:in"))) {
+ canThrow(n, "in", p);
+ Replaceall(tm, "$input", arg);
+ Setattr(p, "emit:input", arg);
+ Printf(f->code, "%s\n", tm);
+ p = Getattr(p, "tmap:in:next");
+ } else {
+ Swig_warning(WARN_TYPEMAP_IN_UNDEF, input_file, line_number, "Unable to use type %s as a function argument.\n", SwigType_str(pt, 0));
+ p = nextSibling(p);
+ }
+ Delete(im_param_type);
+ Delete(c_param_type);
+ Delete(arg);
+ }
+
+ /* Insert constraint checking code */
+ for (p = l; p;) {
+ if ((tm = Getattr(p, "tmap:check"))) {
+ canThrow(n, "check", p);
+ Replaceall(tm, "$input", Getattr(p, "emit:input"));
+ Printv(f->code, tm, "\n", NIL);
+ p = Getattr(p, "tmap:check:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+
+ /* Insert cleanup code */
+ for (p = l; p;) {
+ if ((tm = Getattr(p, "tmap:freearg"))) {
+ canThrow(n, "freearg", p);
+ Replaceall(tm, "$input", Getattr(p, "emit:input"));
+ Printv(cleanup, tm, "\n", NIL);
+ p = Getattr(p, "tmap:freearg:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+
+ /* Insert argument output code */
+ for (p = l; p;) {
+ if ((tm = Getattr(p, "tmap:argout"))) {
+ canThrow(n, "argout", p);
+ Replaceall(tm, "$result", "jresult");
+ Replaceall(tm, "$input", Getattr(p, "emit:input"));
+ Printv(outarg, tm, "\n", NIL);
+ p = Getattr(p, "tmap:argout:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+
+ // Look for usage of throws typemap and the canthrow flag
+ ParmList *throw_parm_list = NULL;
+ if ((throw_parm_list = Getattr(n, "catchlist"))) {
+ Swig_typemap_attach_parms("throws", throw_parm_list, f);
+ for (p = throw_parm_list; p; p = nextSibling(p)) {
+ if ((tm = Getattr(p, "tmap:throws"))) {
+ canThrow(n, "throws", p);
+ }
+ }
+ }
+
+ String *null_attribute = 0;
+ // Now write code to make the function call
+ if (!native_function_flag) {
+ if (Cmp(nodeType(n), "constant") == 0) {
+ // Wrapping a constant hack
+ Swig_save("functionWrapper", n, "wrap:action", NIL);
+
+ // below based on Swig_VargetToFunction()
+ SwigType *ty = Swig_wrapped_var_type(Getattr(n, "type"), use_naturalvar_mode(n));
+ Setattr(n, "wrap:action", NewStringf("result = (%s) %s;", SwigType_lstr(ty, 0), Getattr(n, "value")));
+ }
+
+ Swig_director_emit_dynamic_cast(n, f);
+ String *actioncode = emit_action(n);
+
+ if (Cmp(nodeType(n), "constant") == 0)
+ Swig_restore(n);
+
+ /* Return value if necessary */
+ if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) {
+ canThrow(n, "out", n);
+ Replaceall(tm, "$result", "jresult");
+
+ if (GetFlag(n, "feature:new"))
+ Replaceall(tm, "$owner", "1");
+ else
+ Replaceall(tm, "$owner", "0");
+
+ Printf(f->code, "%s", tm);
+ null_attribute = Getattr(n, "tmap:out:null");
+ if (Len(tm))
+ Printf(f->code, "\n");
+ } else {
+ Swig_warning(WARN_TYPEMAP_OUT_UNDEF, input_file, line_number, "Unable to use return type %s in function %s.\n", SwigType_str(t, 0), Getattr(n, "name"));
+ }
+ emit_return_variable(n, t, f);
+ }
+
+ /* Output argument output code */
+ Printv(f->code, outarg, NIL);
+
+ /* Output cleanup code */
+ Printv(f->code, cleanup, NIL);
+
+ /* Look to see if there is any newfree cleanup code */
+ if (GetFlag(n, "feature:new")) {
+ if ((tm = Swig_typemap_lookup("newfree", n, "result", 0))) {
+ canThrow(n, "newfree", n);
+ Printf(f->code, "%s\n", tm);
+ }
+ }
+
+ /* See if there is any return cleanup code */
+ if (!native_function_flag) {
+ if ((tm = Swig_typemap_lookup("ret", n, "result", 0))) {
+ canThrow(n, "ret", n);
+ Printf(f->code, "%s\n", tm);
+ }
+ }
+
+ // Complete D wrapper parameter list and emit the declaration/binding code.
+ Printv(wrap_dmodule_parameters, ")", NIL);
+ writeWrapDModuleFunction(overloaded_name, im_return_type,
+ wrap_dmodule_parameters, wname);
+ Delete(wrap_dmodule_parameters);
+
+ // Finish C function header.
+ Printf(f->def, ") {");
+
+ if (!is_void_return)
+ Printv(f->code, " return jresult;\n", NIL);
+ Printf(f->code, "}\n");
+
+ /* Substitute the cleanup code */
+ Replaceall(f->code, "$cleanup", cleanup);
+
+ /* Substitute the function name */
+ Replaceall(f->code, "$symname", symname);
+
+ /* Contract macro modification */
+ if (Replaceall(f->code, "SWIG_contract_assert(", "SWIG_contract_assert($null, ") > 0) {
+ Setattr(n, "d:canthrow", "1");
+ }
+
+ if (!null_attribute)
+ Replaceall(f->code, "$null", "0");
+ else
+ Replaceall(f->code, "$null", null_attribute);
+
+ /* Dump the function out */
+ if (!native_function_flag) {
+ Wrapper_print(f, f_wrappers);
+
+ // Handle %exception which sets the canthrow attribute.
+ if (Getattr(n, "feature:except:canthrow")) {
+ Setattr(n, "d:canthrow", "1");
+ }
+
+ // A very simple check (it is not foolproof) to assist typemap writers
+ // with setting the correct features when the want to throw D exceptions
+ // from C++ code. It checks for the common methods which set
+ // a pending D exception and issues a warning if one of them has been found
+ // in the typemap, but the »canthrow« attribute/feature is not set.
+ if (!Getattr(n, "d:canthrow")) {
+ if (Strstr(f->code, "SWIG_exception")) {
+ Swig_warning(WARN_D_CANTHROW_MISSING, input_file, line_number,
+ "C code contains a call to SWIG_exception and D code does not handle pending exceptions via the canthrow attribute.\n");
+ } else if (Strstr(f->code, "SWIG_DSetPendingException")) {
+ Swig_warning(WARN_D_CANTHROW_MISSING, input_file, line_number,
+ "C code contains a call to a SWIG_DSetPendingException method and D code does not handle pending exceptions via the canthrow attribute.\n");
+ }
+ }
+ }
+
+ // If we are not processing an enum or constant, and we were not generating
+ // a wrapper function which will be accessed via a proxy class, write a
+ // function to the proxy D module.
+ if (!is_wrapping_class()) {
+ writeProxyDModuleFunction(n);
+ }
+
+ // If we are processing a public member variable, write the property-style
+ // member function to the proxy class.
+ if (wrapping_member_flag) {
+ Setattr(n, "proxyfuncname", variable_name);
+ Setattr(n, "imfuncname", symname);
+
+ writeProxyClassFunction(n);
+ }
+
+ Delete(c_return_type);
+ Delete(im_return_type);
+ Delete(cleanup);
+ Delete(outarg);
+ Delete(body);
+ Delete(overloaded_name);
+ DelWrapper(f);
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::nativeWrapper()
+ * --------------------------------------------------------------------------- */
+ virtual int nativeWrapper(Node *n) {
+ String *wrapname = Getattr(n, "wrap:name");
+
+ if (!addSymbol(wrapname, n))
+ return SWIG_ERROR;
+
+ if (Getattr(n, "type")) {
+ Swig_save("nativeWrapper", n, "name", NIL);
+ Setattr(n, "name", wrapname);
+ native_function_flag = true;
+ functionWrapper(n);
+ Swig_restore(n);
+ native_function_flag = false;
+ } else {
+ Swig_error(input_file, line_number, "No return type for %%native method %s.\n", Getattr(n, "wrap:name"));
+ }
+
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirector()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirector(Node *n) {
+ proxy_class_name = NewString(Getattr(n, "sym:name"));
+
+ int success = Language::classDirector(n);
+
+ Delete(proxy_class_name);
+ proxy_class_name = NULL;
+
+ return success;
+ }
+
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorInit()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorInit(Node *n) {
+ Delete(director_ctor_code);
+ director_ctor_code = NewString("$director_new");
+
+ // Write C++ director class declaration, for example:
+ // class SwigDirector_myclass : public myclass, public Swig::Director {
+ String *classname = Swig_class_name(n);
+ String *directorname = NewStringf("SwigDirector_%s", classname);
+ String *declaration = Swig_class_declaration(n, directorname);
+ const String *base = Getattr(n, "classtype");
+
+ Printf(f_directors_h,
+ "%s : public %s, public Swig::Director {\n", declaration, base);
+ Printf(f_directors_h, "\npublic:\n");
+
+ Delete(declaration);
+ Delete(directorname);
+ Delete(classname);
+
+ // Stash for later.
+ Setattr(n, "director:ctor", NewString("Swig::Director()"));
+
+ // Keep track of the director methods for this class.
+ first_class_dmethod = curr_class_dmethod = n_dmethods;
+
+ director_callback_typedefs = NewString("");
+ director_callback_pointers = NewString("");
+ director_dcallbacks_code = NewString("");
+
+ return Language::classDirectorInit(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorMethod()
+ *
+ * Emit a virtual director method to pass a method call on to the
+ * underlying D object.
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorMethod(Node *n, Node *parent, String *super) {
+ String *empty_str = NewString("");
+ String *classname = Getattr(parent, "sym:name");
+ String *c_classname = Getattr(parent, "name");
+ String *name = Getattr(n, "name");
+ String *symname = Getattr(n, "sym:name");
+ SwigType *type = Getattr(n, "type");
+ SwigType *returntype = Getattr(n, "returntype");
+ String *overloaded_name = getOverloadedName(n);
+ String *storage = Getattr(n, "storage");
+ String *value = Getattr(n, "value");
+ String *decl = Getattr(n, "decl");
+ String *declaration = NewString("");
+ String *tm;
+ Parm *p;
+ int i;
+ Wrapper *w = NewWrapper();
+ ParmList *l = Getattr(n, "parms");
+ bool is_void = !(Cmp(returntype, "void"));
+ String *qualified_return = NewString("");
+ bool pure_virtual = (!(Cmp(storage, "virtual")) && !(Cmp(value, "0")));
+ int status = SWIG_OK;
+ bool output_director = true;
+ String *dirclassname = getDirectorClassName(parent);
+ String *qualified_name = NewStringf("%s::%s", dirclassname, name);
+ SwigType *c_ret_type = NULL;
+ String *dcallback_call_args = NewString("");
+ String *imclass_dmethod;
+ String *callback_typedef_parms = NewString("");
+ String *delegate_parms = NewString("");
+ String *proxy_method_param_list = NewString("");
+ String *proxy_callback_return_type = NewString("");
+ String *callback_def = NewString("");
+ String *callback_code = NewString("");
+ String *imcall_args = NewString("");
+ int gencomma = 0;
+ bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
+
+ // Kludge Alert: functionWrapper sets sym:overload properly, but it
+ // isn't at this point, so we have to manufacture it ourselves. At least
+ // we're consistent with the sym:overload name in functionWrapper. (?? when
+ // does the overloaded method name get set?)
+
+ imclass_dmethod = NewStringf("SwigDirector_%s", Swig_name_member(NSPACE_TODO,classname, overloaded_name));
+
+ if (returntype) {
+ qualified_return = SwigType_rcaststr(returntype, "c_result");
+
+ if (!is_void && !ignored_method) {
+ if (!SwigType_isclass(returntype)) {
+ if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
+ String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
+ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
+ Delete(construct_result);
+ } else {
+ String *base_typename = SwigType_base(returntype);
+ String *resolved_typename = SwigType_typedef_resolve_all(base_typename);
+ Symtab *symtab = Getattr(n, "sym:symtab");
+ Node *typenode = Swig_symbol_clookup(resolved_typename, symtab);
+
+ if (SwigType_ispointer(returntype) || (typenode && Getattr(typenode, "abstract"))) {
+ /* initialize pointers to something sane. Same for abstract
+ classes when a reference is returned. */
+ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= 0", NIL);
+ } else {
+ /* If returning a reference, initialize the pointer to a sane
+ default - if a D exception occurs, then the pointer returns
+ something other than a NULL-initialized reference. */
+ String *non_ref_type = Copy(returntype);
+
+ /* Remove reference and const qualifiers */
+ Replaceall(non_ref_type, "r.", "");
+ Replaceall(non_ref_type, "q(const).", "");
+ Wrapper_add_localv(w, "result_default", "static", SwigType_str(non_ref_type, "result_default"), "=", SwigType_str(non_ref_type, "()"), NIL);
+ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), "= &result_default", NIL);
+
+ Delete(non_ref_type);
+ }
+
+ Delete(base_typename);
+ Delete(resolved_typename);
+ }
+ } else {
+ SwigType *vt;
+
+ vt = cplus_value_type(returntype);
+ if (!vt) {
+ Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), NIL);
+ } else {
+ Wrapper_add_localv(w, "c_result", SwigType_lstr(vt, "c_result"), NIL);
+ Delete(vt);
+ }
+ }
+ }
+
+ /* Create the intermediate class wrapper */
+ Parm *tp = NewParm(returntype, empty_str, n);
+
+ tm = lookupDTypemap(tp, "dwtype");
+ if (tm) {
+ String *dwtypeout = Getattr(tp, "tmap:dwtype:out");
+ if (dwtypeout) {
+ // The type in the dwtype typemap's out attribute overrides the type
+ // in the typemap.
+ tm = dwtypeout;
+ }
+ Printf(callback_def, "\nprivate extern(C) %s swigDirectorCallback_%s_%s(void* dObject", tm, classname, overloaded_name);
+ Printv(proxy_callback_return_type, tm, NIL);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number,
+ "No dwtype typemap defined for %s\n", SwigType_str(returntype, 0));
+ }
+
+ Parm *retpm = NewParm(returntype, empty_str, n);
+
+ if ((c_ret_type = Swig_typemap_lookup("cwtype", retpm, "", 0))) {
+ if (!is_void && !ignored_method) {
+ String *jretval_decl = NewStringf("%s jresult", c_ret_type);
+ Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
+ Delete(jretval_decl);
+ }
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number,
+ "No cwtype typemap defined for %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ output_director = false;
+ }
+
+ Delete(retpm);
+ }
+
+ /* Go through argument list, attach lnames for arguments */
+ for (i = 0, p = l; p; p = nextSibling(p), ++i) {
+ String *arg = Getattr(p, "name");
+ String *lname = NewString("");
+
+ if (!arg && Cmp(Getattr(p, "type"), "void")) {
+ lname = NewStringf("arg%d", i);
+ Setattr(p, "name", lname);
+ } else
+ lname = arg;
+
+ Setattr(p, "lname", lname);
+ }
+
+ // Attach the standard typemaps.
+ Swig_typemap_attach_parms("out", l, 0);
+ Swig_typemap_attach_parms("cwtype", l, 0);
+ Swig_typemap_attach_parms("dwtype", l, 0);
+ Swig_typemap_attach_parms("dptype", l, 0);
+ Swig_typemap_attach_parms("directorin", l, 0);
+ Swig_typemap_attach_parms("ddirectorin", l, 0);
+
+ // Preamble code.
+ if (!ignored_method)
+ Printf(w->code, "if (!swig_callback_%s) {\n", overloaded_name);
+
+ if (!pure_virtual) {
+ String *super_call = Swig_method_call(super, l);
+ if (is_void) {
+ Printf(w->code, "%s;\n", super_call);
+ if (!ignored_method)
+ Printf(w->code, "return;\n");
+ } else {
+ Printf(w->code, "return %s;\n", super_call);
+ }
+ Delete(super_call);
+ } else {
+ Printf(w->code, " throw Swig::DirectorPureVirtualException(\"%s::%s\");\n", SwigType_namestr(c_classname), SwigType_namestr(name));
+ }
+
+ if (!ignored_method)
+ Printf(w->code, "} else {\n");
+
+ // Go through argument list.
+ for (p = l; p; /* empty */) {
+ /* Is this superfluous? */
+ while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
+ p = Getattr(p, "tmap:directorin:next");
+ }
+
+ SwigType *pt = Getattr(p, "type");
+ String *ln = Copy(Getattr(p, "name"));
+ String *c_param_type = NULL;
+ String *c_decl = NewString("");
+ String *arg = NewString("");
+
+ Printf(arg, "j%s", ln);
+
+ // Add each parameter to the D callback invocation arguments.
+ Printf(dcallback_call_args, ", %s", arg);
+
+ /* Get parameter's intermediary C type */
+ if ((c_param_type = lookupDTypemap(p, "cwtype", true))) {
+ String *cwtypeout = Getattr(p, "tmap:cwtype:out");
+ if (cwtypeout) {
+ // The type in the cwtype typemap's out attribute overrides the type
+ // in the typemap itself.
+ c_param_type = cwtypeout;
+ }
+
+ Parm *tp = NewParm(c_param_type, empty_str, n);
+ String *desc_tm = NULL;
+
+ /* Add to local variables */
+ Printf(c_decl, "%s %s", c_param_type, arg);
+ if (!ignored_method)
+ Wrapper_add_localv(w, arg, c_decl, (!(SwigType_ispointer(pt) || SwigType_isreference(pt)) ? "" : "= 0"), NIL);
+
+ /* Add input marshalling code */
+ if ((desc_tm = Swig_typemap_lookup("directorin", tp, "", 0))
+ && (tm = Getattr(p, "tmap:directorin"))) {
+
+ Replaceall(tm, "$input", arg);
+ Replaceall(tm, "$owner", "0");
+
+ if (Len(tm))
+ if (!ignored_method)
+ Printf(w->code, "%s\n", tm);
+
+ Delete(tm);
+
+ // Add parameter type to the C typedef for the D callback function.
+ Printf(callback_typedef_parms, ", %s", c_param_type);
+
+ /* Add parameter to the intermediate class code if generating the
+ * intermediate's upcall code */
+ if ((tm = lookupDTypemap(p, "dwtype", true))) {
+ String *dwtypeout = Getattr(p, "tmap:dwtype:out");
+ if (dwtypeout) {
+ // The type in the dwtype typemap's out attribute overrides the
+ // type in the typemap itself.
+ tm = dwtypeout;
+ }
+ const String *im_directorinattributes = Getattr(p, "tmap:dwtype:directorinattributes");
+
+ // TODO: Is this copy really needed?
+ String *din = Copy(lookupDTypemap(p, "ddirectorin", true));
+
+ if (din) {
+ Replaceall(din, "$winput", ln);
+
+ Printf(delegate_parms, ", ");
+ if (gencomma > 0) {
+ Printf(proxy_method_param_list, ", ");
+ Printf(imcall_args, ", ");
+ }
+ Printf(delegate_parms, "%s%s %s", im_directorinattributes ? im_directorinattributes : empty_string, tm, ln);
+
+ if (Cmp(din, ln)) {
+ Printv(imcall_args, din, NIL);
+ } else {
+ Printv(imcall_args, ln, NIL);
+ }
+
+ Delete(din);
+
+ // Get the parameter type in the proxy D class (used later when
+ // generating the overload checking code for the directorConnect
+ // function).
+ if ((tm = lookupDTypemap(p, "dptype", true))) {
+ Printf(proxy_method_param_list, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DDIRECTORIN_UNDEF, input_file, line_number,
+ "No ddirectorin typemap defined for %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ output_director = false;
+ }
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number,
+ "No dwtype typemap defined for %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ output_director = false;
+ }
+
+ p = Getattr(p, "tmap:directorin:next");
+
+ Delete(desc_tm);
+ } else {
+ if (!desc_tm) {
+ Swig_warning(WARN_D_TYPEMAP_DDIRECTORIN_UNDEF, input_file, line_number,
+ "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(c_param_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ p = nextSibling(p);
+ } else if (!tm) {
+ Swig_warning(WARN_D_TYPEMAP_DDIRECTORIN_UNDEF, input_file, line_number,
+ "No or improper directorin typemap defined for argument %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ p = nextSibling(p);
+ }
+
+ output_director = false;
+ }
+
+ Delete(tp);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number,
+ "No cwtype typemap defined for %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ output_director = false;
+ p = nextSibling(p);
+ }
+
+ gencomma++;
+ Delete(arg);
+ Delete(c_decl);
+ Delete(c_param_type);
+ }
+
+ /* header declaration, start wrapper definition */
+ String *target;
+ SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
+ target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
+ Printf(w->def, "%s", target);
+ Delete(qualified_name);
+ Delete(target);
+ target = Swig_method_decl(rtype, decl, name, l, 0, 1);
+ Printf(declaration, " virtual %s", target);
+ Delete(target);
+
+ // Add any exception specifications to the methods in the director class
+ ParmList *throw_parm_list = NULL;
+ if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
+ int gencomma = 0;
+
+ Append(w->def, " throw(");
+ Append(declaration, " throw(");
+
+ if (throw_parm_list)
+ Swig_typemap_attach_parms("throws", throw_parm_list, 0);
+ for (p = throw_parm_list; p; p = nextSibling(p)) {
+ if ((tm = Getattr(p, "tmap:throws"))) {
+ if (gencomma++) {
+ Append(w->def, ", ");
+ Append(declaration, ", ");
+ }
+ Printf(w->def, "%s", SwigType_str(Getattr(p, "type"), 0));
+ Printf(declaration, "%s", SwigType_str(Getattr(p, "type"), 0));
+ }
+ }
+
+ Append(w->def, ")");
+ Append(declaration, ")");
+ }
+
+ Append(w->def, " {");
+ Append(declaration, ";\n");
+
+ // Finish the callback function declaraction.
+ Printf(callback_def, "%s)", delegate_parms);
+ Printf(callback_def, " {\n");
+
+ /* Emit the intermediate class's upcall to the actual class */
+
+ String *upcall = NewStringf("(cast(%s)dObject).%s(%s)", classname, symname, imcall_args);
+
+ if (!is_void) {
+ Parm *tp = NewParm(returntype, empty_str, n);
+
+ // RESEARCH: What happens if there is no ddirectorout typemap?
+ if ((tm = lookupDTypemap(tp, "ddirectorout"))) {
+ Replaceall(tm, "$dpcall", upcall);
+
+ Printf(callback_code, " return %s;\n", tm);
+ }
+
+ Delete(tm);
+ Delete(tp);
+ } else {
+ Printf(callback_code, " %s;\n", upcall);
+ }
+
+ Printf(callback_code, "}\n");
+ Delete(upcall);
+
+ if (!ignored_method) {
+ if (!is_void)
+ Printf(w->code, "jresult = (%s) ", c_ret_type);
+
+ Printf(w->code, "swig_callback_%s(d_object%s);\n", overloaded_name, dcallback_call_args);
+
+ if (!is_void) {
+ String *jresult_str = NewString("jresult");
+ String *result_str = NewString("c_result");
+ Parm *tp = NewParm(returntype, result_str, n);
+
+ /* Copy jresult into c_result... */
+ // FIXME: lookupDTypemap?
+ if ((tm = Swig_typemap_lookup("directorout", tp, result_str, w))) {
+ Replaceall(tm, "$input", jresult_str);
+ Replaceall(tm, "$result", result_str);
+ Printf(w->code, "%s\n", tm);
+ } else {
+ Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
+ "Unable to use return type %s used in %s::%s (skipping director method)\n",
+ SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ output_director = false;
+ }
+
+ Delete(tp);
+ Delete(jresult_str);
+ Delete(result_str);
+ }
+
+ /* Terminate wrapper code */
+ Printf(w->code, "}\n");
+ if (!is_void)
+ Printf(w->code, "return %s;", qualified_return);
+ }
+
+ Printf(w->code, "}");
+
+ // We expose virtual protected methods via an extra public inline method which makes a straight call to the wrapped class' method
+ String *inline_extra_method = NewString("");
+ if (dirprot_mode() && !is_public(n) && !pure_virtual) {
+ Printv(inline_extra_method, declaration, NIL);
+ String *extra_method_name = NewStringf("%sSwigPublic", name);
+ Replaceall(inline_extra_method, name, extra_method_name);
+ Replaceall(inline_extra_method, ";\n", " {\n ");
+ if (!is_void)
+ Printf(inline_extra_method, "return ");
+ String *methodcall = Swig_method_call(super, l);
+ Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
+ Delete(methodcall);
+ Delete(extra_method_name);
+ }
+
+ /* emit code */
+ if (status == SWIG_OK && output_director) {
+ if (!is_void) {
+ Replaceall(w->code, "$null", qualified_return);
+ } else {
+ Replaceall(w->code, "$null", "");
+ }
+ if (!ignored_method)
+ Printv(director_dcallbacks_code, callback_def, callback_code, NIL);
+ if (!Getattr(n, "defaultargs")) {
+ Wrapper_print(w, f_directors);
+ Printv(f_directors_h, declaration, NIL);
+ Printv(f_directors_h, inline_extra_method, NIL);
+ }
+ }
+
+ if (!ignored_method) {
+ // Register the upcall method so that the callback registering code can
+ // be written later.
+
+ // We cannot directly use n here because its »type« attribute does not
+ // the full return type any longer after Language::functionHandler has
+ // returned.
+ Parm *tp = NewParm(returntype, empty_str, n);
+ String *dp_return_type = lookupDTypemap(tp, "dptype");
+ if (dp_return_type) {
+ String *dptypeout = Getattr(n, "tmap:dptype:out");
+ if (dptypeout) {
+ // The type in the dptype typemap's out attribute overrides the type
+ // in the typemap itself.
+ dp_return_type = dptypeout;
+ replaceClassname(dp_return_type, returntype);
+ }
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(type, 0));
+ dp_return_type = NewString("");
+ }
+
+ UpcallData *udata = addUpcallMethod(imclass_dmethod, symname, decl, overloaded_name, dp_return_type, proxy_method_param_list);
+ Delete(dp_return_type);
+
+ // Write the global callback function pointer on the C code.
+ String *methid = Getattr(udata, "class_methodidx");
+
+ Printf(director_callback_typedefs, " typedef %s (SWIGSTDCALL* SWIG_Callback%s_t)", c_ret_type, methid);
+ Printf(director_callback_typedefs, "(void *dobj%s);\n", callback_typedef_parms);
+ Printf(director_callback_pointers, " SWIG_Callback%s_t swig_callback_%s;\n", methid, overloaded_name);
+
+ // Write the type alias for the callback to the wrap D module.
+ String* proxy_callback_type = NewString("");
+ Printf(proxy_callback_type, "SwigDirector_%s_Callback%s", classname, methid);
+ Printf(wrap_dmodule_code, "alias extern(C) %s function(void*%s) %s;\n", proxy_callback_return_type, delegate_parms, proxy_callback_type);
+ Delete(proxy_callback_type);
+ }
+
+ Delete(qualified_return);
+ Delete(c_ret_type);
+ Delete(declaration);
+ Delete(callback_typedef_parms);
+ Delete(delegate_parms);
+ Delete(proxy_method_param_list);
+ Delete(callback_def);
+ Delete(callback_code);
+ DelWrapper(w);
+
+ return status;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorConstructor()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorConstructor(Node *n) {
+ Node *parent = parentNode(n);
+ String *decl = Getattr(n, "decl");;
+ String *supername = Swig_class_name(parent);
+ String *classname = getDirectorClassName(parent);
+ String *sub = NewString("");
+ Parm *p;
+ ParmList *superparms = Getattr(n, "parms");
+ ParmList *parms;
+ int argidx = 0;
+
+ /* Assign arguments to superclass's parameters, if not already done */
+ for (p = superparms; p; p = nextSibling(p)) {
+ String *pname = Getattr(p, "name");
+
+ if (!pname) {
+ pname = NewStringf("arg%d", argidx++);
+ Setattr(p, "name", pname);
+ }
+ }
+
+ // TODO: Is this copy needed?
+ parms = CopyParmList(superparms);
+
+ if (!Getattr(n, "defaultargs")) {
+ /* constructor */
+ {
+ String *basetype = Getattr(parent, "classtype");
+ String *target = Swig_method_decl(0, decl, classname, parms, 0, 0);
+ String *call = Swig_csuperclass_call(0, basetype, superparms);
+ String *classtype = SwigType_namestr(Getattr(n, "name"));
+
+ Printf(f_directors, "%s::%s : %s, %s {\n", classname, target, call, Getattr(parent, "director:ctor"));
+ Printf(f_directors, " swig_init_callbacks();\n");
+ Printf(f_directors, "}\n\n");
+
+ Delete(classtype);
+ Delete(target);
+ Delete(call);
+ }
+
+ /* constructor header */
+ {
+ String *target = Swig_method_decl(0, decl, classname, parms, 0, 1);
+ Printf(f_directors_h, " %s;\n", target);
+ Delete(target);
+ }
+ }
+
+ Delete(sub);
+ Delete(supername);
+ Delete(parms);
+ return Language::classDirectorConstructor(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorDefaultConstructor()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorDefaultConstructor(Node *n) {
+ String *classname = Swig_class_name(n);
+ String *classtype = SwigType_namestr(Getattr(n, "name"));
+ Wrapper *w = NewWrapper();
+
+ Printf(w->def, "SwigDirector_%s::SwigDirector_%s() : %s {", classname, classname, Getattr(n, "director:ctor"));
+ Printf(w->code, "}\n");
+ Wrapper_print(w, f_directors);
+
+ Printf(f_directors_h, " SwigDirector_%s();\n", classname);
+ DelWrapper(w);
+ Delete(classtype);
+ Delete(classname);
+ return Language::classDirectorDefaultConstructor(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorDestructor()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorDestructor(Node *n) {
+ Node *current_class = getCurrentClass();
+ String *classname = Swig_class_name(current_class);
+ Wrapper *w = NewWrapper();
+
+ if (Getattr(n, "throw")) {
+ Printf(f_directors_h, " virtual ~SwigDirector_%s() throw ();\n", classname);
+ Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() throw () {\n", classname, classname);
+ } else {
+ Printf(f_directors_h, " virtual ~SwigDirector_%s();\n", classname);
+ Printf(w->def, "SwigDirector_%s::~SwigDirector_%s() {\n", classname, classname);
+ }
+
+ Printv(w->code, "}\n", NIL);
+
+ Wrapper_print(w, f_directors);
+
+ DelWrapper(w);
+ Delete(classname);
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorEnd()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorEnd(Node *n) {
+ int i;
+ String *director_classname = getDirectorClassName(n);
+
+ Wrapper *w = NewWrapper();
+
+ if (Len(director_callback_typedefs) > 0) {
+ Printf(f_directors_h, "\n%s", director_callback_typedefs);
+ }
+
+ Printf(f_directors_h, " void swig_connect_director(void* dobj");
+
+ Printf(w->def, "void %s::swig_connect_director(void* dobj", director_classname);
+ Printf(w->code, "d_object = dobj;");
+
+ for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
+ UpcallData *udata = Getitem(dmethods_seq, i);
+ String *methid = Getattr(udata, "class_methodidx");
+ String *overname = Getattr(udata, "overname");
+
+ Printf(f_directors_h, ", SWIG_Callback%s_t callback%s", methid, overname);
+ Printf(w->def, ", SWIG_Callback%s_t callback_%s", methid, overname);
+ Printf(w->code, "swig_callback_%s = callback_%s;\n", overname, overname);
+ }
+
+ Printf(f_directors_h, ");\n");
+ Printf(w->def, ") {");
+
+ Printf(f_directors_h, "\nprivate:\n");
+ Printf(f_directors_h, " void swig_init_callbacks();\n");
+ Printf(f_directors_h, " void *d_object;\n");
+ if (Len(director_callback_typedefs) > 0) {
+ Printf(f_directors_h, "%s", director_callback_pointers);
+ }
+ Printf(f_directors_h, "};\n\n");
+ Printf(w->code, "}\n\n");
+
+ Printf(w->code, "void %s::swig_init_callbacks() {\n", director_classname);
+ for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
+ UpcallData *udata = Getitem(dmethods_seq, i);
+ String *overname = Getattr(udata, "overname");
+ Printf(w->code, "swig_callback_%s = 0;\n", overname);
+ }
+ Printf(w->code, "}");
+
+ Wrapper_print(w, f_directors);
+
+ DelWrapper(w);
+
+ return Language::classDirectorEnd(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::classDirectorDisown()
+ * --------------------------------------------------------------------------- */
+ virtual int classDirectorDisown(Node *n) {
+ (void) n;
+ return SWIG_OK;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceSpecialVariables()
+ * --------------------------------------------------------------------------- */
+ virtual void replaceSpecialVariables(String *method, String *tm, Parm *parm) {
+ (void)method;
+ SwigType *type = Getattr(parm, "type");
+
+ // Just assume that this goes to the proxy class, we cannot know.
+ replaceClassname(tm, type);
+ }
+
+protected:
+ /* ---------------------------------------------------------------------------
+ * D::extraDirectorProtectedCPPMethodsRequired()
+ * --------------------------------------------------------------------------- */
+ virtual bool extraDirectorProtectedCPPMethodsRequired() const {
+ return false;
+ }
+
+private:
+ /* ---------------------------------------------------------------------------
+ * D::writeWrapDModuleFunction()
+ *
+ * Writes a function declaration for the given (C) wrapper function to the
+ * wrap D module.
+ *
+ * d_name - The name the function in the D wrap module will get.
+ * wrapper_function_name - The name of the exported function in the C wrapper
+ * (usually d_name prefixed by »D_«).
+ * --------------------------------------------------------------------------- */
+ void writeWrapDModuleFunction(const_String_or_char_ptr d_name,
+ const_String_or_char_ptr return_type, const_String_or_char_ptr parameters,
+ const_String_or_char_ptr wrapper_function_name) {
+
+ // TODO: Add support for static linking here.
+ Printf(wrap_dmodule_code, "extern(C) %s function%s %s;\n", return_type,
+ parameters, d_name);
+ Printv(wrapper_loader_bind_code, wrapper_loader_bind_command, NIL);
+ Replaceall(wrapper_loader_bind_code, "$function", d_name);
+ Replaceall(wrapper_loader_bind_code, "$symbol", wrapper_function_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeProxyClassFunction()
+ *
+ * Creates a D proxy function for a C++ function in the wrapped class. Used
+ * for both static and non-static C++ class functions.
+ *
+ * The Node must contain two extra attributes.
+ * - "proxyfuncname": The name of the D proxy function.
+ * - "imfuncname": The corresponding function in the wrap D module.
+ * --------------------------------------------------------------------------- */
+ void writeProxyClassFunction(Node *n) {
+ SwigType *t = Getattr(n, "type");
+ ParmList *l = Getattr(n, "parms");
+ String *intermediary_function_name = Getattr(n, "imfuncname");
+ String *proxy_function_name = Getattr(n, "proxyfuncname");
+ String *tm;
+ Parm *p;
+ int i;
+ String *imcall = NewString("");
+ String *return_type = NewString("");
+ String *function_code = NewString("");
+ bool setter_flag = false;
+ String *pre_code = NewString("");
+ String *post_code = NewString("");
+ String *terminator_code = NewString("");
+
+ // Wrappers not wanted for some methods where the parameters cannot be
+ // overloaded in D.
+ if (Getattr(n, "overload:ignore"))
+ return;
+
+ // Don't generate proxy method for additional explicitcall method used in
+ // directors.
+ if (GetFlag(n, "explicitcall"))
+ return;
+
+ // RESEARCH: What is this good for?
+ if (l) {
+ if (SwigType_type(Getattr(l, "type")) == T_VOID) {
+ l = nextSibling(l);
+ }
+ }
+
+ /* Attach the non-standard typemaps to the parameter list */
+ Swig_typemap_attach_parms("in", l, NULL);
+ Swig_typemap_attach_parms("dptype", l, NULL);
+ Swig_typemap_attach_parms("din", l, NULL);
+
+ // Get return types.
+ if ((tm = lookupDTypemap(n, "dptype"))) {
+ String *dptypeout = Getattr(n, "tmap:dptype:out");
+ if (dptypeout) {
+ // The type in the dptype typemap's out attribute overrides the type in
+ // the typemap.
+ tm = dptypeout;
+ replaceClassname(tm, t);
+ }
+ Printf(return_type, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ if (wrapping_member_flag) {
+ // Check if this is a setter method for a public member.
+ setter_flag = (Cmp(Getattr(n, "sym:name"),
+ Swig_name_set(NSPACE_TODO,Swig_name_member(NSPACE_TODO,proxy_class_name, variable_name))) == 0);
+ }
+
+ // Write function modifiers.
+ {
+ String *modifiers;
+
+ const String *mods_override = Getattr(n, "feature:d:methodmodifiers");
+ if (mods_override) {
+ modifiers = Copy(mods_override);
+ } else {
+ modifiers = Copy(is_public(n) ? public_string : protected_string);
+
+ if (Getattr(n, "override")) {
+ Printf(modifiers, " override");
+ }
+ }
+
+ if (is_smart_pointer()) {
+ // Smart pointer classes do not mirror the inheritance hierarchy of the
+ // underlying pointer type, so no override required.
+ Replaceall(modifiers, "override", "");
+ }
+
+ Chop(modifiers);
+
+ if (static_flag) {
+ Printf(modifiers, " static");
+ }
+
+ Printf(function_code, "%s ", modifiers);
+ Delete(modifiers);
+ }
+
+ // Complete the function declaration up to the parameter list.
+ Printf(function_code, "%s %s(", return_type, proxy_function_name);
+
+ // Write the wrapper function call up to the parameter list.
+ Printv(imcall, wrap_dmodule_fq_name, ".$imfuncname(", NIL);
+ if (!static_flag) {
+ Printf(imcall, "cast(void*)swigCPtr");
+ }
+
+ // Write the parameter list for the proxy function declaration and the
+ // wrapper function call.
+ emit_mark_varargs(l);
+ int gencomma = !static_flag;
+ for (i = 0, p = l; p; i++) {
+ // Ignored varargs.
+ if (checkAttribute(p, "varargs:ignore", "1")) {
+ p = nextSibling(p);
+ continue;
+ }
+
+ // Ignored parameters.
+ if (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ p = Getattr(p, "tmap:in:next");
+ continue;
+ }
+
+ // Ignore the 'this' argument for variable wrappers.
+ if (!(variable_wrapper_flag && i == 0)) {
+ String *param_name = makeParameterName(n, p, i, setter_flag);
+ SwigType *pt = Getattr(p, "type");
+
+ // Write the wrapper function call argument.
+ {
+ if (gencomma) {
+ Printf(imcall, ", ");
+ }
+
+ if ((tm = lookupDTypemap(p, "din", true))) {
+ Replaceall(tm, "$dinput", param_name);
+ String *pre = Getattr(p, "tmap:din:pre");
+ if (pre) {
+ replaceClassname(pre, pt);
+ Replaceall(pre, "$dinput", param_name);
+ if (Len(pre_code) > 0)
+ Printf(pre_code, "\n");
+ Printv(pre_code, pre, NIL);
+ }
+ String *post = Getattr(p, "tmap:din:post");
+ if (post) {
+ replaceClassname(post, pt);
+ Replaceall(post, "$dinput", param_name);
+ if (Len(post_code) > 0)
+ Printf(post_code, "\n");
+ Printv(post_code, post, NIL);
+ }
+ String *terminator = Getattr(p, "tmap:din:terminator");
+ if (terminator) {
+ replaceClassname(terminator, pt);
+ Replaceall(terminator, "$dinput", param_name);
+ if (Len(terminator_code) > 0)
+ Insert(terminator_code, 0, "\n");
+ Insert(terminator_code, 0, terminator);
+ }
+ Printv(imcall, tm, NIL);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DIN_UNDEF, input_file, line_number,
+ "No din typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+ }
+
+ // Write the D proxy function parameter.
+ {
+ String *proxy_type = NewString("");
+
+ if ((tm = lookupDTypemap(p, "dptype"))) {
+ const String *inattributes = Getattr(p, "tmap:dptype:inattributes");
+ Printf(proxy_type, "%s%s", inattributes ? inattributes : empty_string, tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ if (gencomma >= 2)
+ Printf(function_code, ", ");
+ gencomma = 2;
+ Printf(function_code, "%s %s", proxy_type, param_name);
+
+ Delete(proxy_type);
+ }
+
+ Delete(param_name);
+ }
+ p = Getattr(p, "tmap:in:next");
+ }
+
+ Printf(imcall, ")");
+ Printf(function_code, ") ");
+
+ if (d_version > 1 && wrapping_member_flag) {
+ Printf(function_code, "@property ");
+ }
+
+ if (wrapMemberFunctionAsDConst(n)) {
+ Printf(function_code, "const ");
+ }
+
+ // Lookup the code used to convert the wrapper return value to the proxy
+ // function return type.
+ if ((tm = lookupDTypemap(n, "dout"))) {
+ replaceExcode(n, tm, "dout", n);
+ bool is_pre_code = Len(pre_code) > 0;
+ bool is_post_code = Len(post_code) > 0;
+ bool is_terminator_code = Len(terminator_code) > 0;
+ if (is_pre_code || is_post_code || is_terminator_code) {
+ if (is_post_code) {
+ Insert(tm, 0, "\n try ");
+ Printv(tm, " finally {\n", post_code, "\n }", NIL);
+ } else {
+ Insert(tm, 0, "\n ");
+ }
+ if (is_pre_code) {
+ Insert(tm, 0, pre_code);
+ Insert(tm, 0, "\n");
+ }
+ if (is_terminator_code) {
+ Printv(tm, "\n", terminator_code, NIL);
+ }
+ Insert(tm, 0, "{");
+ Printv(tm, "}", NIL);
+ }
+ if (GetFlag(n, "feature:new"))
+ Replaceall(tm, "$owner", "true");
+ else
+ Replaceall(tm, "$owner", "false");
+ replaceClassname(tm, t);
+
+ // For director methods: generate code to selectively make a normal
+ // polymorphic call or an explicit method call. Needed to prevent infinite
+ // recursion when calling director methods.
+ Node *explicit_n = Getattr(n, "explicitcallnode");
+ if (explicit_n) {
+ String *ex_overloaded_name = getOverloadedName(explicit_n);
+ String *ex_intermediary_function_name = Swig_name_member(NSPACE_TODO,proxy_class_name, ex_overloaded_name);
+
+ String *ex_imcall = Copy(imcall);
+ Replaceall(ex_imcall, "$imfuncname", ex_intermediary_function_name);
+ Replaceall(imcall, "$imfuncname", intermediary_function_name);
+
+ String *excode = NewString("");
+ if (!Cmp(return_type, "void"))
+ Printf(excode, "if (this.classinfo == %s.classinfo) %s; else %s", proxy_class_name, imcall, ex_imcall);
+ else
+ Printf(excode, "((this.classinfo == %s.classinfo) ? %s : %s)", proxy_class_name, imcall, ex_imcall);
+
+ Clear(imcall);
+ Printv(imcall, excode, NIL);
+ Delete(ex_overloaded_name);
+ Delete(excode);
+ } else {
+ Replaceall(imcall, "$imfuncname", intermediary_function_name);
+ }
+ Replaceall(tm, "$wcall", imcall);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,
+ "No dout typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ // The whole function body is now in stored tm (if there was a matching type
+ // map, of course), so simply append it to the code buffer. The braces are
+ // included in the typemap.
+ Printv(function_code, tm, NIL);
+
+ // Write function code buffer to the class code.
+ Printv(proxy_class_body_code, "\n", function_code, "\n", NIL);
+
+ Delete(pre_code);
+ Delete(post_code);
+ Delete(terminator_code);
+ Delete(function_code);
+ Delete(return_type);
+ Delete(imcall);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeProxyDModuleFunction()
+ * --------------------------------------------------------------------------- */
+ void writeProxyDModuleFunction(Node *n) {
+ SwigType *t = Getattr(n, "type");
+ ParmList *l = Getattr(n, "parms");
+ String *tm;
+ Parm *p;
+ int i;
+ String *imcall = NewString("");
+ String *return_type = NewString("");
+ String *function_code = NewString("");
+ int num_arguments = 0;
+ int num_required = 0;
+ String *overloaded_name = getOverloadedName(n);
+ String *func_name = NULL;
+ String *pre_code = NewString("");
+ String *post_code = NewString("");
+ String *terminator_code = NewString("");
+
+ // RESEARCH: What is this good for?
+ if (l) {
+ if (SwigType_type(Getattr(l, "type")) == T_VOID) {
+ l = nextSibling(l);
+ }
+ }
+
+ /* Attach the non-standard typemaps to the parameter list */
+ Swig_typemap_attach_parms("dptype", l, NULL);
+ Swig_typemap_attach_parms("din", l, NULL);
+
+ /* Get return types */
+ if ((tm = lookupDTypemap(n, "dptype"))) {
+ String *dptypeout = Getattr(n, "tmap:dptype:out");
+ if (dptypeout) {
+ // The type in the dptype typemap's out attribute overrides the type in
+ // the typemap.
+ tm = dptypeout;
+ replaceClassname(tm, t);
+ }
+ Printf(return_type, "%s", tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ /* Change function name for global variables */
+ if (global_variable_flag) {
+ // RESEARCH: Is the Copy() needed here?
+ func_name = Copy(variable_name);
+ } else {
+ func_name = Copy(Getattr(n, "sym:name"));
+ }
+
+ /* Start generating the function */
+ const String *outattributes = Getattr(n, "tmap:dptype:outattributes");
+ if (outattributes)
+ Printf(function_code, " %s\n", outattributes);
+
+ const String *methodmods = Getattr(n, "feature:d:methodmodifiers");
+ // TODO: Check if is_public(n) could possibly make any sense here
+ // (private global functions would be useless anyway?).
+ methodmods = methodmods ? methodmods : empty_string;
+
+ Printf(function_code, "\n%s%s %s(", methodmods, return_type, func_name);
+ Printv(imcall, wrap_dmodule_fq_name, ".", overloaded_name, "(", NIL);
+
+ /* Get number of required and total arguments */
+ num_arguments = emit_num_arguments(l);
+ num_required = emit_num_required(l);
+
+ int gencomma = 0;
+
+ /* Output each parameter */
+ for (i = 0, p = l; i < num_arguments; i++) {
+
+ /* Ignored parameters */
+ while (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ p = Getattr(p, "tmap:in:next");
+ }
+
+ SwigType *pt = Getattr(p, "type");
+ String *param_type = NewString("");
+
+ // Get the D parameter type.
+ if ((tm = lookupDTypemap(p, "dptype", true))) {
+ const String *inattributes = Getattr(p, "tmap:dptype:inattributes");
+ Printf(param_type, "%s%s", inattributes ? inattributes : empty_string, tm);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
+ "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ if (gencomma)
+ Printf(imcall, ", ");
+
+ const bool generating_setter = global_variable_flag || wrapping_member_flag;
+ String *arg = makeParameterName(n, p, i, generating_setter);
+
+ // Get the D code to convert the parameter value to the type used in the
+ // wrapper D module.
+ if ((tm = lookupDTypemap(p, "din", true))) {
+ Replaceall(tm, "$dinput", arg);
+ String *pre = Getattr(p, "tmap:din:pre");
+ if (pre) {
+ replaceClassname(pre, pt);
+ Replaceall(pre, "$dinput", arg);
+ if (Len(pre_code) > 0)
+ Printf(pre_code, "\n");
+ Printv(pre_code, pre, NIL);
+ }
+ String *post = Getattr(p, "tmap:din:post");
+ if (post) {
+ replaceClassname(post, pt);
+ Replaceall(post, "$dinput", arg);
+ if (Len(post_code) > 0)
+ Printf(post_code, "\n");
+ Printv(post_code, post, NIL);
+ }
+ String *terminator = Getattr(p, "tmap:din:terminator");
+ if (terminator) {
+ replaceClassname(terminator, pt);
+ Replaceall(terminator, "$dinput", arg);
+ if (Len(terminator_code) > 0)
+ Insert(terminator_code, 0, "\n");
+ Insert(terminator_code, 0, terminator);
+ }
+ Printv(imcall, tm, NIL);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DIN_UNDEF, input_file, line_number,
+ "No din typemap defined for %s\n", SwigType_str(pt, 0));
+ }
+
+ /* Add parameter to module class function */
+ if (gencomma >= 2)
+ Printf(function_code, ", ");
+ gencomma = 2;
+ Printf(function_code, "%s %s", param_type, arg);
+
+ p = Getattr(p, "tmap:in:next");
+ Delete(arg);
+ Delete(param_type);
+ }
+
+ Printf(imcall, ")");
+ Printf(function_code, ") ");
+
+ if (global_variable_flag && (d_version > 1)) {
+ Printf(function_code, "@property ");
+ }
+
+ // Lookup the code used to convert the wrapper return value to the proxy
+ // function return type.
+ if ((tm = lookupDTypemap(n, "dout"))) {
+ replaceExcode(n, tm, "dout", n);
+ bool is_pre_code = Len(pre_code) > 0;
+ bool is_post_code = Len(post_code) > 0;
+ bool is_terminator_code = Len(terminator_code) > 0;
+ if (is_pre_code || is_post_code || is_terminator_code) {
+ if (is_post_code) {
+ Insert(tm, 0, "\n try ");
+ Printv(tm, " finally {\n", post_code, "\n }", NIL);
+ } else {
+ Insert(tm, 0, "\n ");
+ }
+ if (is_pre_code) {
+ Insert(tm, 0, pre_code);
+ Insert(tm, 0, "\n");
+ }
+ if (is_terminator_code) {
+ Printv(tm, "\n", terminator_code, NIL);
+ }
+ Insert(tm, 0, " {");
+ Printf(tm, "\n}");
+ }
+ if (GetFlag(n, "feature:new"))
+ Replaceall(tm, "$owner", "true");
+ else
+ Replaceall(tm, "$owner", "false");
+ replaceClassname(tm, t);
+ Replaceall(tm, "$wcall", imcall);
+ } else {
+ Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,
+ "No dout typemap defined for %s\n", SwigType_str(t, 0));
+ }
+
+ // The whole function code is now stored in tm (if there was a matching
+ // type map, of course), so simply append it to the code buffer.
+ Printf(function_code, "%s\n", tm ? (const String *) tm : empty_string);
+ Printv(proxy_dmodule_code, function_code, NIL);
+
+ Delete(pre_code);
+ Delete(post_code);
+ Delete(terminator_code);
+ Delete(function_code);
+ Delete(return_type);
+ Delete(imcall);
+ Delete(func_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeProxyClassAndUpcasts()
+ * --------------------------------------------------------------------------- */
+ void writeProxyClassAndUpcasts(Node *n) {
+ SwigType *typemap_lookup_type = Getattr(n, "classtypeobj");
+
+ /*
+ * Handle inheriting from D and C++ classes.
+ */
+
+ String *c_classname = SwigType_namestr(Getattr(n, "name"));
+ String *c_baseclass = NULL;
+ String *baseclass = NULL;
+ String *c_baseclassname = NULL;
+
+ // Inheritance from pure D classes.
+ Node *attributes = NewHash();
+ const String *pure_baseclass =
+ lookupCodeTypemap(n, "dbase", typemap_lookup_type, WARN_NONE, attributes);
+ bool purebase_replace = GetFlag(attributes, "tmap:dbase:replace") ? true : false;
+ bool purebase_notderived = GetFlag(attributes, "tmap:dbase:notderived") ? true : false;
+ Delete(attributes);
+
+ // C++ inheritance.
+ if (!purebase_replace) {
+ List *baselist = Getattr(n, "bases");
+ if (baselist) {
+ Iterator base = First(baselist);
+ while (base.item && GetFlag(base.item, "feature:ignore")) {
+ base = Next(base);
+ }
+ if (base.item) {
+ c_baseclassname = Getattr(base.item, "name");
+ baseclass = Copy(getProxyName(c_baseclassname));
+ if (baseclass)
+ c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
+ base = Next(base);
+ /* Warn about multiple inheritance for additional base class(es) */
+ while (base.item) {
+ if (GetFlag(base.item, "feature:ignore")) {
+ base = Next(base);
+ continue;
+ }
+ String *proxyclassname = SwigType_str(Getattr(n, "classtypeobj"), 0);
+ String *baseclassname = SwigType_str(Getattr(base.item, "name"), 0);
+ Swig_warning(WARN_D_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
+ "Base %s of class %s ignored: multiple inheritance is not supported in D.\n", baseclassname, proxyclassname);
+ base = Next(base);
+ }
+ }
+ }
+ }
+
+ bool derived = baseclass && getProxyName(c_baseclassname);
+
+ if (derived && purebase_notderived) {
+ pure_baseclass = empty_string;
+ }
+ const String *wanted_base = baseclass ? baseclass : pure_baseclass;
+
+ if (purebase_replace) {
+ wanted_base = pure_baseclass;
+ derived = false;
+ Delete(baseclass);
+ baseclass = NULL;
+ if (purebase_notderived) {
+ Swig_error(Getfile(n), Getline(n),
+ "The dbase typemap for proxy %s must contain just one of the 'replace' or 'notderived' attributes.\n",
+ typemap_lookup_type);
+ }
+ } else if (baseclass && Len(pure_baseclass) > 0) {
+ Swig_warning(WARN_D_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
+ "Warning for %s proxy: Base class %s ignored. Multiple inheritance is not supported in D. "
+ "Perhaps you need one of the 'replace' or 'notderived' attributes in the dbase typemap?\n", typemap_lookup_type, pure_baseclass);
+ }
+
+ // Add code to do C++ casting to base class (only for classes in an inheritance hierarchy)
+ if (derived) {
+ writeClassUpcast(n, proxy_class_name, c_classname, c_baseclass);
+ }
+
+ /*
+ * Write needed imports.
+ */
+ // If this class is derived from a C++ class, we need to have the D class
+ // generated for it in scope.
+ if (derived) {
+ requireDType(baseclass);
+
+ if (split_proxy_dmodule) {
+ // Fully qualify the baseclass name.
+ String *module = NewStringf("%s%s.", package, baseclass);
+ Insert(baseclass, 0, module);
+ Delete(module);
+ }
+ }
+
+ // Write any custom import statements to the proxy module header.
+ const String *imports = lookupCodeTypemap(n, "dimports", typemap_lookup_type, WARN_NONE);
+ if (Len(imports) > 0) {
+ String* imports_trimmed = Copy(imports);
+ Chop(imports_trimmed);
+ replaceImportTypeMacros(imports_trimmed);
+ Printv(proxy_class_imports, imports_trimmed, "\n", NIL);
+ Delete(imports_trimmed);
+ }
+
+ /*
+ * Write the proxy class header.
+ */
+ // Class modifiers.
+ const String *modifiers =
+ lookupCodeTypemap(n, "dclassmodifiers", typemap_lookup_type, WARN_D_TYPEMAP_CLASSMOD_UNDEF);
+
+ // User-defined interfaces.
+ const String *interfaces =
+ lookupCodeTypemap(n, derived ? "dinterfaces_derived" : "dinterfaces", typemap_lookup_type, WARN_NONE);
+
+ Printv(proxy_class_code,
+ "\n",
+ modifiers,
+ " $dclassname",
+ (*Char(wanted_base) || *Char(interfaces)) ? " : " : "", wanted_base,
+ (*Char(wanted_base) && *Char(interfaces)) ? ", " : "", interfaces, " {",
+ NIL);
+
+ /*
+ * Write the proxy class body.
+ */
+ String* body = NewString("");
+
+ // Default class body.
+ const String *dbody;
+ if (derived) {
+ dbody = lookupCodeTypemap(n, "dbody_derived", typemap_lookup_type, WARN_D_TYPEMAP_DBODY_UNDEF);
+ } else {
+ dbody = lookupCodeTypemap(n, "dbody", typemap_lookup_type, WARN_D_TYPEMAP_DBODY_UNDEF);
+ }
+
+ Printv(body, dbody, NIL);
+
+ // Destructor and dispose().
+ // If the C++ destructor is accessible (public), it is wrapped by the
+ // dispose() method which is also called by the emitted D constructor. If it
+ // is not accessible, no D destructor is written and the generated dispose()
+ // method throws an exception.
+ // This enables C++ classes with protected or private destructors to be used
+ // in D as it would be used in C++ (GC finalization is a no-op then because
+ // of the empty D destructor) while preventing usage in »scope« variables.
+ // The method name for the dispose() method is specified in a typemap
+ // attribute called »methodname«.
+ const String *tm = NULL;
+
+ String *dispose_methodname;
+ String *dispose_methodmodifiers;
+ attributes = NewHash();
+ if (derived) {
+ tm = lookupCodeTypemap(n, "ddispose_derived", typemap_lookup_type, WARN_NONE, attributes);
+ dispose_methodname = Getattr(attributes, "tmap:ddispose_derived:methodname");
+ dispose_methodmodifiers = Getattr(attributes, "tmap:ddispose_derived:methodmodifiers");
+ } else {
+ tm = lookupCodeTypemap(n, "ddispose", typemap_lookup_type, WARN_NONE, attributes);
+ dispose_methodname = Getattr(attributes, "tmap:ddispose:methodname");
+ dispose_methodmodifiers = Getattr(attributes, "tmap:ddispose:methodmodifiers");
+ }
+
+ if (tm && *Char(tm)) {
+ if (!dispose_methodname) {
+ Swig_error(Getfile(n), Getline(n),
+ "No methodname attribute defined in the ddispose%s typemap for %s\n",
+ (derived ? "_derived" : ""), proxy_class_name);
+ }
+ if (!dispose_methodmodifiers) {
+ Swig_error(Getfile(n), Getline(n),
+ "No methodmodifiers attribute defined in ddispose%s typemap for %s.\n",
+ (derived ? "_derived" : ""), proxy_class_name);
+ }
+ }
+
+ if (tm) {
+ // Write the destructor if the C++ one is accessible.
+ if (*Char(destructor_call)) {
+ Printv(body,
+ lookupCodeTypemap(n, "ddestructor", typemap_lookup_type, WARN_NONE), NIL);
+ }
+
+ // Write the dispose() method.
+ String *dispose_code = NewString("");
+ Printv(dispose_code, tm, NIL);
+
+ if (*Char(destructor_call)) {
+ Replaceall(dispose_code, "$wcall", destructor_call);
+ } else {
+ Replaceall(dispose_code, "$wcall", "throw new Exception(\"C++ destructor does not have public access\")");
+ }
+
+ if (*Char(dispose_code)) {
+ Printv(body, "\n", dispose_methodmodifiers,
+ (derived ? " override" : ""), " void ", dispose_methodname, "() ",
+ dispose_code, "\n", NIL);
+ }
+ }
+
+ if (Swig_directorclass(n)) {
+ // If directors are enabled for the current class, generate the
+ // director connect helper function which is called from the constructor
+ // and write it to the class body.
+ writeDirectorConnectProxy();
+ }
+
+ // Write all constants and enumerations first to prevent forward reference
+ // errors.
+ Printv(body, proxy_class_enums_code, NIL);
+
+ // Write the code generated in other methods to the class body.
+ Printv(body, proxy_class_body_code, NIL);
+
+ // Append extra user D code to the class body.
+ Printv(body,
+ lookupCodeTypemap(n, "dcode", typemap_lookup_type, WARN_NONE), "\n", NIL);
+
+ // Write the class body and the curly bracket closing the class definition
+ // to the proxy module.
+ indentCode(body);
+ Replaceall(body, "$dbaseclass", baseclass);
+ Delete(baseclass);
+
+ Printv(proxy_class_code, body, "\n}\n", NIL);
+ Delete(body);
+
+ // Write the epilogue code if there is any.
+ Printv(proxy_class_code, proxy_class_epilogue_code, NIL);
+ }
+
+
+ /* ---------------------------------------------------------------------------
+ * D::writeClassUpcast()
+ * --------------------------------------------------------------------------- */
+ void writeClassUpcast(Node *n, const String* d_class_name,
+ String* c_class_name, String* c_base_name) {
+
+ String *smartptr = Getattr(n, "feature:smartptr");
+ String *upcast_name = NewString("");
+ Printv(upcast_name, d_class_name,
+ (smartptr != 0 ? "SmartPtrUpcast" : "Upcast"), NIL);
+
+ String *upcast_wrapper_name = Swig_name_wrapper(upcast_name);
+
+ writeWrapDModuleFunction(upcast_name, "void*", "(void* objectRef)",
+ upcast_wrapper_name);
+
+ if (smartptr) {
+ SwigType *spt = Swig_cparse_type(smartptr);
+ if (spt) {
+ SwigType *smart = SwigType_typedef_resolve_all(spt);
+ Delete(spt);
+ SwigType *bsmart = Copy(smart);
+ SwigType *rclassname = SwigType_typedef_resolve_all(c_class_name);
+ SwigType *rbaseclass = SwigType_typedef_resolve_all(c_base_name);
+ Replaceall(bsmart, rclassname, rbaseclass);
+ Delete(rclassname);
+ Delete(rbaseclass);
+ String *smartnamestr = SwigType_namestr(smart);
+ String *bsmartnamestr = SwigType_namestr(bsmart);
+ Printv(upcasts_code,
+ "SWIGEXPORT ", bsmartnamestr, " * SWIGSTDCALL ", upcast_wrapper_name,
+ "(", smartnamestr, " *objectRef) {\n",
+ " return objectRef ? new ", bsmartnamestr, "(*objectRef) : 0;\n"
+ "}\n",
+ "\n", NIL);
+ Delete(bsmartnamestr);
+ Delete(smartnamestr);
+ Delete(bsmart);
+ } else {
+ Swig_error(Getfile(n), Getline(n),
+ "Invalid type (%s) in 'smartptr' feature for class %s.\n",
+ smartptr, c_class_name);
+ }
+ } else {
+ Printv(upcasts_code,
+ "SWIGEXPORT ", c_base_name, " * SWIGSTDCALL ", upcast_wrapper_name,
+ "(", c_base_name, " *objectRef) {\n",
+ " return (", c_base_name, " *)objectRef;\n"
+ "}\n",
+ "\n", NIL);
+ }
+
+ Replaceall(upcasts_code, "$cclass", c_class_name);
+ Replaceall(upcasts_code, "$cbaseclass", c_base_name);
+
+ Delete(upcast_name);
+ Delete(upcast_wrapper_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeTypeWrapperClass()
+ * --------------------------------------------------------------------------- */
+ void writeTypeWrapperClass(String *classname, SwigType *type) {
+ Node *n = NewHash();
+ Setfile(n, input_file);
+ Setline(n, line_number);
+
+ assertClassNameValidity(classname);
+
+ String* imports_target;
+ String* code_target;
+ File *class_file = NULL;
+ if (split_proxy_dmodule) {
+ String *filename = NewStringf("%s%s.d", dmodule_directory, classname);
+ class_file = NewFile(filename, "w", SWIG_output_files());
+ if (!class_file) {
+ FileErrorDisplay(filename);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Append(filenames_list, Copy(filename));
+ Delete(filename);
+
+ emitBanner(class_file);
+ Printf(class_file, "module %s%s;\n", package, classname);
+ Printf(class_file, "\nstatic import %s;\n", wrap_dmodule_fq_name);
+
+ imports_target = NewString("");
+ code_target = NewString("");
+ } else {
+ imports_target = proxy_dmodule_imports;
+ code_target = proxy_dmodule_code;
+ }
+
+ // Import statements.
+ const String *imports = lookupCodeTypemap(n, "dimports", type, WARN_NONE);
+ if (Len(imports) > 0) {
+ String *imports_trimmed = Copy(imports);
+ Chop(imports_trimmed);
+ replaceImportTypeMacros(imports_trimmed);
+ Printv(imports_target, imports_trimmed, "\n", NIL);
+ Delete(imports_trimmed);
+ }
+
+ // Pure D baseclass and interfaces (no C++ inheritance possible.
+ const String *pure_baseclass = lookupCodeTypemap(n, "dbase", type, WARN_NONE);
+ const String *pure_interfaces = lookupCodeTypemap(n, "dinterfaces", type, WARN_NONE);
+
+ // Emit the class.
+ Printv(code_target,
+ "\n",
+ lookupCodeTypemap(n, "dclassmodifiers", type, WARN_D_TYPEMAP_CLASSMOD_UNDEF),
+ " $dclassname",
+ (*Char(pure_baseclass) || *Char(pure_interfaces)) ? " : " : "", pure_baseclass,
+ ((*Char(pure_baseclass)) && *Char(pure_interfaces)) ? ", " : "", pure_interfaces,
+ " {", NIL);
+
+ String* body = NewString("");
+ Printv(body, lookupCodeTypemap(n, "dbody", type, WARN_D_TYPEMAP_DBODY_UNDEF),
+ lookupCodeTypemap(n, "dcode", type, WARN_NONE), NIL);
+ indentCode(body);
+ Printv(code_target, body, "\n}\n", NIL);
+ Delete(body);
+
+ Replaceall(code_target, "$dclassname", classname);
+
+ if (split_proxy_dmodule) {
+ Printv(class_file, imports_target, NIL);
+ Delete(imports_target);
+
+ replaceModuleVariables(code_target);
+ Printv(class_file, code_target, NIL);
+ Delete(code_target);
+
+ Close(class_file);
+ Delete(class_file);
+ }
+
+ Delete(n);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeDirectorConnectProxy()
+ *
+ * Writes the helper method which registers the director callbacks by calling
+ * the director connect function from the D side to the proxy class.
+ * --------------------------------------------------------------------------- */
+ void writeDirectorConnectProxy() {
+ Printf(proxy_class_body_code, "\nprivate void swigDirectorConnect() {\n");
+
+ int i;
+ for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
+ UpcallData *udata = Getitem(dmethods_seq, i);
+ String *method = Getattr(udata, "method");
+ String *overloaded_name = Getattr(udata, "overname");
+ String *return_type = Getattr(udata, "return_type");
+ String *param_list = Getattr(udata, "param_list");
+ String *methid = Getattr(udata, "class_methodidx");
+ Printf(proxy_class_body_code, " %s.SwigDirector_%s_Callback%s callback%s;\n", wrap_dmodule_fq_name, proxy_class_name, methid, methid);
+ Printf(proxy_class_body_code, " if (swigIsMethodOverridden!(%s delegate(%s), %s function(%s), %s)()) {\n", return_type, param_list, return_type, param_list, method);
+ Printf(proxy_class_body_code, " callback%s = &swigDirectorCallback_%s_%s;\n", methid, proxy_class_name, overloaded_name);
+ Printf(proxy_class_body_code, " }\n\n");
+ }
+ Printf(proxy_class_body_code, " %s.%s_director_connect(cast(void*)swigCPtr, cast(void*)this", wrap_dmodule_fq_name, proxy_class_name);
+ for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
+ UpcallData *udata = Getitem(dmethods_seq, i);
+ String *methid = Getattr(udata, "class_methodidx");
+ Printf(proxy_class_body_code, ", callback%s", methid);
+ }
+ Printf(proxy_class_body_code, ");\n");
+ Printf(proxy_class_body_code, "}\n");
+
+ // Helper function to determine if a method has been overridden in a
+ // subclass of the wrapped class. If not, we just pass null to the
+ // director_connect_function since the method from the C++ class should
+ // be called as usual (see above).
+ // Only emit it if the proxy class has at least one method.
+ if (first_class_dmethod < curr_class_dmethod) {
+ Printf(proxy_class_body_code, "\n");
+ Printf(proxy_class_body_code, "private bool swigIsMethodOverridden(DelegateType, FunctionType, alias fn)() {\n");
+ Printf(proxy_class_body_code, " DelegateType dg = &fn;\n");
+ Printf(proxy_class_body_code, " return dg.funcptr != SwigNonVirtualAddressOf!(FunctionType, fn);\n");
+ Printf(proxy_class_body_code, "}\n");
+ Printf(proxy_class_body_code, "\n");
+ Printf(proxy_class_body_code, "private static Function SwigNonVirtualAddressOf(Function, alias fn)() {\n");
+ Printf(proxy_class_body_code, " return cast(Function) &fn;\n");
+ Printf(proxy_class_body_code, "}\n");
+ }
+
+ if (Len(director_dcallbacks_code) > 0) {
+ Printv(proxy_class_epilogue_code, director_dcallbacks_code, NIL);
+ }
+
+ Delete(director_callback_typedefs);
+ director_callback_typedefs = NULL;
+ Delete(director_callback_pointers);
+ director_callback_pointers = NULL;
+ Delete(director_dcallbacks_code);
+ director_dcallbacks_code = NULL;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::writeDirectorConnectWrapper()
+ *
+ * Writes the director connect function and the corresponding declaration to
+ * the C++ wrapper respectively the D wrapper.
+ * --------------------------------------------------------------------------- */
+ void writeDirectorConnectWrapper(Node *n) {
+ if (!Swig_directorclass(n))
+ return;
+
+ // Output the director connect method.
+ String *norm_name = SwigType_namestr(Getattr(n, "name"));
+ String *connect_name = NewStringf("%s_director_connect", proxy_class_name);
+ String *sym_name = Getattr(n, "sym:name");
+ Wrapper *code_wrap;
+
+ Printv(wrapper_loader_bind_code, wrapper_loader_bind_command, NIL);
+ Replaceall(wrapper_loader_bind_code, "$function", connect_name);
+ Replaceall(wrapper_loader_bind_code, "$symbol", Swig_name_wrapper(connect_name));
+
+ Printf(wrap_dmodule_code, "extern(C) void function(void* cObject, void* dObject");
+
+ code_wrap = NewWrapper();
+ Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL D_%s(void *objarg, void *dobj", connect_name);
+
+ Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name);
+ Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name);
+
+ Printf(code_wrap->code, " if (director) {\n");
+ Printf(code_wrap->code, " director->swig_connect_director(dobj");
+
+ for (int i = first_class_dmethod; i < curr_class_dmethod; ++i) {
+ UpcallData *udata = Getitem(dmethods_seq, i);
+ String *methid = Getattr(udata, "class_methodidx");
+
+ Printf(code_wrap->def, ", SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid);
+ Printf(code_wrap->code, ", callback%s", methid);
+ Printf(wrap_dmodule_code, ", SwigDirector_%s_Callback%s callback%s", sym_name, methid, methid);
+ }
+
+ Printf(code_wrap->def, ") {\n");
+ Printf(code_wrap->code, ");\n");
+ Printf(wrap_dmodule_code, ") %s;\n", connect_name);
+ Printf(code_wrap->code, " }\n");
+ Printf(code_wrap->code, "}\n");
+
+ Wrapper_print(code_wrap, f_wrappers);
+ DelWrapper(code_wrap);
+
+ Delete(connect_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::requireDType()
+ *
+ * Adds an import statement for the given module to the header of current
+ * module. This is only used for dependencies created in generated code, user-
+ * (read: typemap-) specified import statements are handeled seperately.
+ * --------------------------------------------------------------------------- */
+ void requireDType(const String *dmodule_name) {
+ String *import = createImportStatement(dmodule_name);
+ Append(import, "\n");
+ if (is_wrapping_class()) {
+ addImportStatement(proxy_class_imports, import);
+ } else {
+ addImportStatement(proxy_dmodule_imports, import);
+ }
+ Delete(import);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::addImportStatement()
+ *
+ * Adds the given import statement to the given list of import statements if
+ * there is no statement importing that module present yet.
+ * --------------------------------------------------------------------------- */
+ void addImportStatement(String *target, const String *import) const {
+ char *position = Strstr(target, import);
+ if (position) {
+ // If the import statement has been found in the target string, we have to
+ // check if the previous import was static, which would lead to problems
+ // if this import is not.
+ // Thus, we check if the seven characters in front of the occurence are
+ // »static «. If the import string passed is also static, the checks fail
+ // even if the found statement is also static because the last seven
+ // characters would be part of the previous import statement then.
+
+ if (position - Char(target) < 7) {
+ return;
+ }
+ if (strncmp(position - 7, "static ", 7)) {
+ return;
+ }
+ }
+
+ Printv(target, import, NIL);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::createImportStatement()
+ *
+ * Creates a string containing an import statement for the given module if it
+ * is needed in the currently generated proxy D module (i.e. if it is not the
+ * current module itself).
+ * --------------------------------------------------------------------------- */
+ String *createImportStatement(const String *dmodule_name,
+ bool static_import = true) const {
+
+ if (inProxyModule(dmodule_name)) {
+ return NewStringf("");
+ } else {
+ if (static_import) {
+ return NewStringf("static import %s%s;", package, dmodule_name);
+ } else {
+ return NewStringf("import %s%s;", package, dmodule_name);
+ }
+ }
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::inProxyModule()
+ *
+ * Determines if the specified proxy class is decleared in the currently
+ * processed proxy D module.
+ *
+ * This function is used to determine if fully qualified type names have to be
+ * used (package, module and type name). This is never the case if the split
+ * proxy mode is not used, all proxy types are written to the same module then.
+ * --------------------------------------------------------------------------- */
+ bool inProxyModule(const String *type_name) const {
+ if (!split_proxy_dmodule) {
+ // If we are not in split proxy module mode, proxy code is always written
+ // to the same module.
+ return true;
+ }
+
+ if (!Len(proxy_class_name)) {
+ return false;
+ }
+
+ return (Strcmp(proxy_class_name, type_name) == 0);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::addUpcallMethod()
+ *
+ * Adds new director upcall signature.
+ * --------------------------------------------------------------------------- */
+ UpcallData *addUpcallMethod(String *imclass_method, String *class_method,
+ String *decl, String *overloaded_name, String *return_type, String *param_list) {
+
+ UpcallData *udata;
+ String *imclass_methodidx;
+ String *class_methodidx;
+ Hash *new_udata;
+ String *key = NewStringf("%s|%s", imclass_method, decl);
+
+ ++curr_class_dmethod;
+
+ /* Do we know about this director class already? */
+ if ((udata = Getattr(dmethods_table, key))) {
+ Delete(key);
+ return Getattr(udata, "methodoff");
+ }
+
+ imclass_methodidx = NewStringf("%d", n_dmethods);
+ class_methodidx = NewStringf("%d", n_dmethods - first_class_dmethod);
+ n_dmethods++;
+
+ new_udata = NewHash();
+ Append(dmethods_seq, new_udata);
+ Setattr(dmethods_table, key, new_udata);
+
+ Setattr(new_udata, "method", Copy(class_method));
+ Setattr(new_udata, "class_methodidx", class_methodidx);
+ Setattr(new_udata, "decl", Copy(decl));
+ Setattr(new_udata, "overname", Copy(overloaded_name));
+ Setattr(new_udata, "return_type", Copy(return_type));
+ Setattr(new_udata, "param_list", Copy(param_list));
+
+ Delete(key);
+ return new_udata;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::assertClassNameValidity()
+ * --------------------------------------------------------------------------- */
+ void assertClassNameValidity(const String* class_name) const {
+ if (split_proxy_dmodule) {
+ if (Cmp(class_name, wrap_dmodule_name) == 0) {
+ Swig_error(input_file, line_number, "Class name cannot be equal to wrap D module name: %s\n",
+ class_name);
+ SWIG_exit(EXIT_FAILURE);
+ }
+
+ if (Cmp(class_name, proxy_dmodule_name) == 0) {
+ Swig_error(input_file, line_number, "Class name cannot be equal to proxy D module name: %s\n",
+ class_name);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ }
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::getPrimitiveDptype()
+ *
+ * Returns the D proxy type for the passed type if it is a primitive type in
+ * both C and D.
+ * --------------------------------------------------------------------------- */
+ String *getPrimitiveDptype(Node *node, SwigType *type) {
+ SwigType *stripped_type = SwigType_typedef_resolve_all(type);
+
+ // A reference can only be the »outermost element« of a typ.
+ bool mutable_ref = false;
+ if (SwigType_isreference(stripped_type)) {
+ SwigType_del_reference(stripped_type);
+
+ if (SwigType_isconst(stripped_type)) {
+ SwigType_del_qualifier(stripped_type);
+ } else {
+ mutable_ref = true;
+ }
+ }
+
+ // Strip all the pointers from the type.
+ int indirection_count = 0;
+ while (SwigType_ispointer(stripped_type)) {
+ ++indirection_count;
+ SwigType_del_pointer(stripped_type);
+ }
+
+ // Now that we got rid of the pointers, see if we are dealing with a
+ // primitive type.
+ String *dptype = 0;
+ if (SwigType_isfunction(stripped_type) && indirection_count > 0) {
+ // type was a function pointer, split it up.
+ SwigType_add_pointer(stripped_type);
+ --indirection_count;
+
+ SwigType *return_type = Copy(stripped_type);
+ SwigType *params_type = SwigType_functionpointer_decompose(return_type);
+ String *return_dtype = getPrimitiveDptype(node, return_type);
+ Delete(return_type);
+ if (!return_dtype) {
+ return 0;
+ }
+
+ List *parms = SwigType_parmlist(params_type);
+ List *param_dtypes = NewList();
+ for (Iterator it = First(parms); it.item; it = Next(it)) {
+ String *current_dtype = getPrimitiveDptype(node, it.item);
+ if (Cmp(current_dtype, "void") == 0) {
+ // void somefunc(void) is legal syntax in C, but not in D, so simply
+ // skip the void parameter.
+ Delete(current_dtype);
+ continue;
+ }
+ if (!current_dtype) {
+ Delete(return_dtype);
+ Delete(param_dtypes);
+ return 0;
+ }
+ Append(param_dtypes, current_dtype);
+ }
+
+ String *param_list = NewString("");
+ {
+ bool gen_comma = false;
+ for (Iterator it = First(param_dtypes); it.item; it = Next(it)) {
+ if (gen_comma) {
+ Append(param_list, ", ");
+ }
+ Append(param_list, it.item);
+ Delete(it.item);
+ gen_comma = true;
+ }
+ }
+
+ dptype = NewStringf("%s function(%s)", return_dtype, param_list);
+ Delete(param_list);
+ Delete(param_dtypes);
+ Delete(return_dtype);
+ } else {
+ Hash *attributes = NewHash();
+ const String *tm =
+ lookupCodeTypemap(node, "dptype", stripped_type, WARN_NONE, attributes);
+ if(!GetFlag(attributes, "tmap:dptype:cprimitive")) {
+ dptype = 0;
+ } else {
+ dptype = Copy(tm);
+
+ // We need to call replaceClassname here with the stripped type to avoid
+ // $dclassname in the enum typemaps being replaced later with the full
+ // type.
+ replaceClassname(dptype, stripped_type);
+ }
+ Delete(attributes);
+ }
+ Delete(stripped_type);
+
+ if (!dptype) {
+ // The type passed is no primitive type.
+ return 0;
+ }
+
+ // The type is ultimately a primitive type, now append the right number of
+ // indirection levels (pointers).
+ for (int i = 0; i < indirection_count; ++i) {
+ Append(dptype, "*");
+ }
+
+ // Add a level of indirection for a mutable reference since it is wrapped
+ // as a pointer.
+ if (mutable_ref) {
+ Append(dptype, "*");
+ }
+
+ return dptype;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::lookupCodeTypemap()
+ *
+ * Looks up a D code fragment for generating the wrapper class for the given
+ * type.
+ *
+ * n - for input only and must contain info for Getfile(n) and Getline(n) to work
+ * tmap_method - typemap method name
+ * type - typemap type to lookup
+ * warning - warning number to issue if no typemaps found
+ * typemap_attributes - the typemap attributes are attached to this node and will
+ * also be used for temporary storage if non null
+ * return is never NULL, unlike Swig_typemap_lookup()
+ * --------------------------------------------------------------------------- */
+ const String *lookupCodeTypemap(Node *n, const_String_or_char_ptr tmap_method,
+ SwigType *type, int warning, Node *typemap_attributes = 0) const {
+
+ Node *node = !typemap_attributes ? NewHash() : typemap_attributes;
+ Setattr(node, "type", type);
+ Setfile(node, Getfile(n));
+ Setline(node, Getline(n));
+ const String *tm = Swig_typemap_lookup(tmap_method, node, "", 0);
+ if (!tm) {
+ tm = empty_string;
+ if (warning != WARN_NONE) {
+ Swig_warning(warning, Getfile(n), Getline(n),
+ "No %s typemap defined for %s\n", tmap_method, SwigType_str(type, 0));
+ }
+ }
+ if (!typemap_attributes) {
+ Delete(node);
+ }
+
+ return tm;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::lookupDTypemap()
+ *
+ * Looks up a D typemap for the given node, replacing D-specific special
+ * variables as needed.
+ *
+ * The method parameter specifies the typemap method to use. If attached is
+ * true, the value is just fetched from the tmap: node attribute,
+ * Swig_typemap_lookup is used otherwise.
+ * --------------------------------------------------------------------------- */
+ String *lookupDTypemap(Node *n, const_String_or_char_ptr method, bool attached = false) {
+ String *result = 0;
+
+ if (attached) {
+ String *attr_name = NewStringf("tmap:%s", method);
+ result = Getattr(n, attr_name);
+ Delete(attr_name);
+ } else {
+ // FIXME: As a workaround for a bug so far only surfacing in the
+ // smart_pointer_const_overload test case, remove the nativepointer
+ // typemap attribute since it seems to be already there from a dout
+ // typemap of a different type in that test.
+ String *np_key = NewStringf("tmap:%s:nativepointer", method);
+ Delattr(n, np_key);
+ Delete(np_key);
+
+ result = Swig_typemap_lookup(method, n, "", 0);
+ }
+
+ if (!result) {
+ return 0;
+ }
+
+ // Check if the passed node actually has type information attached. This
+ // is not the case e.g. in constructorWrapper.
+ SwigType *type = Getattr(n, "type");
+ if (type) {
+ String *np_key = NewStringf("tmap:%s:nativepointer", method);
+ String *np_value = Getattr(n, np_key);
+ Delete(np_key);
+ String *dptype;
+ if (np_value && (dptype = getPrimitiveDptype(n, type))) {
+ // If the typemap in question has a »nativepointer« attribute and we
+ // are dealing with a primitive type, use it instead.
+ result = Copy(np_value);
+ Replaceall(result, "$dptype", dptype);
+ }
+
+ replaceClassname(result, type);
+ }
+
+ return result;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceClassname()
+ *
+ * Replaces the special variable $dclassname with the proxy class name for
+ * classes/structs/unions SWIG knows about. Also substitutes the enumeration
+ * name for non-anonymous enums. Otherwise, $classname is replaced with a
+ * $descriptor(type)-like name.
+ *
+ * $*dclassname and $&classname work like with descriptors (see manual section
+ * 10.4.3), they remove a prointer from respectively add a pointer to the type.
+ *
+ * Inputs:
+ * tm - String to perform the substitution at (will usually come from a
+ * typemap.
+ * pt - The type to substitute for the variables.
+ * Outputs:
+ * tm - String with the variables substituted.
+ * Return:
+ * substitution_performed - flag indicating if a substitution was performed
+ * --------------------------------------------------------------------------- */
+ bool replaceClassname(String *tm, SwigType *pt) {
+ bool substitution_performed = false;
+ SwigType *type = Copy(SwigType_typedef_resolve_all(pt));
+ SwigType *strippedtype = SwigType_strip_qualifiers(type);
+
+ if (Strstr(tm, "$dclassname")) {
+ SwigType *classnametype = Copy(strippedtype);
+ replaceClassnameVariable(tm, "$dclassname", classnametype);
+ substitution_performed = true;
+ Delete(classnametype);
+ }
+ if (Strstr(tm, "$*dclassname")) {
+ SwigType *classnametype = Copy(strippedtype);
+ Delete(SwigType_pop(classnametype));
+ replaceClassnameVariable(tm, "$*dclassname", classnametype);
+ substitution_performed = true;
+ Delete(classnametype);
+ }
+ if (Strstr(tm, "$&dclassname")) {
+ SwigType *classnametype = Copy(strippedtype);
+ SwigType_add_pointer(classnametype);
+ replaceClassnameVariable(tm, "$&dclassname", classnametype);
+ substitution_performed = true;
+ Delete(classnametype);
+ }
+
+ Delete(strippedtype);
+ Delete(type);
+
+ return substitution_performed;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceClassnameVariable()
+ *
+ * See D::replaceClassname().
+ * --------------------------------------------------------------------------- */
+ void replaceClassnameVariable(String *target, const char *variable, SwigType *type) {
+ // TODO: Fix const-correctness of methods called in here and make type const.
+
+ // We make use of the fact that this function is called at least once for
+ // every type encountered which is written to a seperate file, which allows
+ // us to handle imports here.
+ // When working in split proxy module mode, each generated proxy class/enum
+ // is written to a seperate module. This requires us to add a corresponding
+ // import when a type is used in another generated module. If we are not
+ // working in split proxy module mode, this is not relevant and the
+ // generated module name is discarded.
+ String *import_name;
+
+ String *qualified_type_name;
+ if (SwigType_isenum(type)) {
+ // RESEARCH: Make sure that we really cannot get here for anonymous enums.
+ Node *n = enumLookup(type);
+ const String *symname = Getattr(n, "sym:name");
+
+ // Add in class scope when referencing enum if not a global enum.
+ const String *parent_name = NULL;
+ String *scopename_prefix = Swig_scopename_prefix(Getattr(n, "name"));
+ if (scopename_prefix) {
+ parent_name = getProxyName(scopename_prefix);
+ Delete(scopename_prefix);
+ }
+
+ if (parent_name) {
+ qualified_type_name = createQualifiedName(parent_name);
+ Printv(qualified_type_name, ".", symname, NIL);
+
+ // An enum nested in a class is not written to a seperate module (this
+ // would not even be possible in D), so just import the parent.
+ import_name = Copy(parent_name);
+ } else {
+ qualified_type_name = createQualifiedName(symname);
+
+ // A non-nested enum is written to a seperate module, import it.
+ import_name = Copy(symname);
+ }
+ } else {
+ const String *class_name = getProxyName(type);
+ if (class_name) {
+ // This is something wrapped as a proxy class (getProxyName() works for
+ // pointers to classes too).
+ qualified_type_name = createQualifiedName(class_name);
+ import_name = Copy(class_name);
+ } else {
+ // SWIG does not know anything about the type (after resolving typedefs).
+ // Just mangle the type name string like $descriptor(type) would do.
+ String *descriptor = NewStringf("SWIGTYPE%s", SwigType_manglestr(type));
+ qualified_type_name = createQualifiedName(descriptor);
+ import_name = Copy(descriptor);
+
+ // Add to hash table so that a type wrapper class can be created later.
+ Setattr(unknown_types, descriptor, type);
+
+ Delete(descriptor);
+ }
+ }
+
+ Replaceall(target, variable, qualified_type_name);
+ Delete(qualified_type_name);
+
+ requireDType(import_name);
+ Delete(import_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::createQualifiedName()
+ * --------------------------------------------------------------------------- */
+ String *createQualifiedName(const String *class_name) const {
+ if (inProxyModule(class_name)) {
+ return Copy(class_name);
+ } else {
+ return NewStringf("%s%s.%s", package, class_name, class_name);
+ }
+}
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceModuleVariables()
+ *
+ * Replaces the $wrapdmodule and $module variables with their values in the
+ * target string.
+ * --------------------------------------------------------------------------- */
+ void replaceModuleVariables(String *target) const {
+ Replaceall(target, "$wrapdmodule", wrap_dmodule_fq_name);
+ Replaceall(target, "$module", proxy_dmodule_name);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceExcode()
+ *
+ * If a C++ method can throw a exception, additional code is added to the
+ * proxy method to check if an exception is pending so that it can be
+ * rethrown on the D side.
+ *
+ * This method replaces the $excode variable with the exception handling code
+ * in the excode typemap attribute if it »canthrow« an exception.
+ * --------------------------------------------------------------------------- */
+ void replaceExcode(Node *n, String *code, const String *typemap, Node *parameter) const {
+ String *excode_attribute = NewStringf("tmap:%s:excode", typemap);
+ String *excode = Getattr(parameter, excode_attribute);
+ if (Getattr(n, "d:canthrow")) {
+ int count = Replaceall(code, "$excode", excode);
+ if (count < 1 || !excode) {
+ Swig_warning(WARN_D_EXCODE_MISSING, input_file, line_number,
+ "D exception may not be thrown – no $excode or excode attribute in '%s' typemap.\n",
+ typemap);
+ }
+ } else {
+ Replaceall(code, "$excode", "");
+ }
+ Delete(excode_attribute);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::replaceImportTypeMacros()
+ *
+ * Replaces the $importtype(SomeDClass) macro with an import statement if it
+ * is required to get SomeDClass in scope for the currently generated proxy
+ * D module.
+ * --------------------------------------------------------------------------- */
+ void replaceImportTypeMacros(String *target) const {
+ // Code from replace_embedded_typemap.
+ char *start = 0;
+ while ((start = Strstr(target, "$importtype("))) {
+ char *end = 0;
+ char *param_start = 0;
+ char *param_end = 0;
+ int level = 0;
+ char *c = start;
+ while (*c) {
+ if (*c == '(') {
+ if (level == 0) {
+ param_start = c + 1;
+ }
+ level++;
+ }
+ if (*c == ')') {
+ level--;
+ if (level == 0) {
+ param_end = c;
+ end = c + 1;
+ break;
+ }
+ }
+ c++;
+ }
+
+ if (end) {
+ String *current_macro = NewStringWithSize(start, (end - start));
+ String *current_param = NewStringWithSize(param_start, (param_end - param_start));
+
+ String *import = createImportStatement(current_param, false);
+ Replace(target, current_macro, import, DOH_REPLACE_ANY);
+ Delete(import);
+
+ Delete(current_param);
+ Delete(current_macro);
+ } else {
+ String *current_macro = NewStringWithSize(start, (c - start));
+ Swig_error(Getfile(target), Getline(target), "Syntax error in: %s\n", current_macro);
+ Replace(target, current_macro, "", DOH_REPLACE_ANY);
+ Delete(current_macro);
+ }
+ }
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::getOverloadedName()
+ * --------------------------------------------------------------------------- */
+ String *getOverloadedName(Node *n) const {
+ // A void* parameter is used for all wrapped classes in the wrapper code.
+ // Thus, the wrapper function names for overloaded functions are postfixed
+ // with a counter string to make them unique.
+ String *overloaded_name = Copy(Getattr(n, "sym:name"));
+
+ if (Getattr(n, "sym:overloaded")) {
+ Append(overloaded_name, Getattr(n, "sym:overname"));
+ }
+
+ return overloaded_name;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::getProxyName()
+ *
+ * Returns the D class name if a type corresponds to something wrapped with a
+ * proxy class, NULL otherwise.
+ * --------------------------------------------------------------------------- */
+ const String *getProxyName(SwigType *t) {
+ Node *n = classLookup(t);
+ if (n) {
+ return Getattr(n, "sym:name");
+ } else {
+ return NULL;
+ }
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::directorClassName()
+ * --------------------------------------------------------------------------- */
+ String *getDirectorClassName(Node *n) const {
+ String *dirclassname;
+ const char *attrib = "director:classname";
+
+ if (!(dirclassname = Getattr(n, attrib))) {
+ String *classname = Getattr(n, "sym:name");
+
+ dirclassname = NewStringf("SwigDirector_%s", classname);
+ Setattr(n, attrib, dirclassname);
+ }
+
+ return dirclassname;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::makeParameterName()
+ *
+ * Inputs:
+ * n - Node
+ * p - parameter node
+ * arg_num - parameter argument number
+ * setter - set this flag when wrapping variables
+ * Return:
+ * arg - a unique parameter name
+ * --------------------------------------------------------------------------- */
+ String *makeParameterName(Node *n, Parm *p, int arg_num, bool setter) const {
+ String *arg = 0;
+ String *pn = Getattr(p, "name");
+
+ // Use C parameter name unless it is a duplicate or an empty parameter name
+ int count = 0;
+ ParmList *plist = Getattr(n, "parms");
+ while (plist) {
+ if ((Cmp(pn, Getattr(plist, "name")) == 0))
+ count++;
+ plist = nextSibling(plist);
+ }
+ String *wrn = pn ? Swig_name_warning(p, 0, pn, 0) : 0;
+ arg = (!pn || (count > 1) || wrn) ? NewStringf("arg%d", arg_num) : Copy(pn);
+
+ if (setter && Cmp(arg, "self") != 0) {
+ // In theory, we could use the normal parameter name for setter functions.
+ // Unfortunately, it is set to "Class::VariableName" for static public
+ // members by the parser, which is not legal D syntax. Thus, we just force
+ // it to "value".
+ Delete(arg);
+ arg = NewString("value");
+ }
+
+ if (split_proxy_dmodule && Strncmp(arg, package, Len(arg)) == 0) {
+ // If we are in split proxy mode and the argument is named like the target
+ // package, we append an underscore to its name to avoid clashes.
+ Append(arg, "_");
+ }
+
+ return arg;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::canThrow()
+ *
+ * Determines whether the code in the typemap can throw a D exception.
+ * If so, note it for later when excodeSubstitute() is called.
+ * --------------------------------------------------------------------------- */
+ void canThrow(Node *n, const String *typemap, Node *parameter) const {
+ String *canthrow_attribute = NewStringf("tmap:%s:canthrow", typemap);
+ String *canthrow = Getattr(parameter, canthrow_attribute);
+ if (canthrow)
+ Setattr(n, "d:canthrow", "1");
+ Delete(canthrow_attribute);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::wrapMemberFunctionAsDConst()
+ *
+ * Determines whether the member function represented by the passed node is
+ * wrapped as D »const« or not.
+ * --------------------------------------------------------------------------- */
+ bool wrapMemberFunctionAsDConst(Node *n) const {
+ if (d_version == 1) return false;
+ if (static_flag) return false; // Never emit »const« for static member functions.
+ return GetFlag(n, "memberget") || SwigType_isconst(Getattr(n, "decl"));
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::areAllOverloadsOverridden()
+ *
+ * Determines whether the class the passed function node belongs to overrides
+ * all the overlaods for the passed function node defined somewhere up the
+ * inheritance hierachy.
+ * --------------------------------------------------------------------------- */
+ bool areAllOverloadsOverridden(Node *n) const {
+ List *base_list = Getattr(parentNode(n), "bases");
+ if (!base_list) {
+ // If the class which contains n is not derived from any other class,
+ // there cannot be any not-overridden overloads.
+ return true;
+ }
+
+ // In case of multiple base classes, skip to the one which has not been
+ // ignored.
+ // RESEARCH: Also emit a warning in case of multiple inheritance here?
+ Iterator it = First(base_list);
+ while (it.item && GetFlag(it.item, "feature:ignore")) {
+ it = Next(it);
+ }
+ Node *base_class = it.item;
+
+ if (!base_class) {
+ // If all base classes have been ignored, there cannot be one either.
+ return true;
+ }
+
+ // We try to find at least a single overload which exists in the base class
+ // so we can progress up the inheritance hierachy even if there have been
+ // new overloads introduced after the topmost class.
+ Node *base_function = NULL;
+ for (Node *tmp = firstChild(base_class); tmp; tmp = nextSibling(tmp)) {
+ if (Strcmp(Getattr(tmp, "sym:name"), Getattr(n, "sym:name")) == 0) {
+ base_function = tmp;
+ break;
+ }
+ }
+
+ if (!base_function) {
+ // If there is no overload which also exists in the super class, there
+ // cannot be any base class overloads not overridden.
+ return true;
+ }
+
+ size_t base_overload_count = 0;
+ for (Node *tmp = firstSibling(base_function); tmp; tmp = Getattr(tmp, "sym:nextSibling")) {
+ if (is_protected(base_function) &&
+ !(Swig_director_mode() && Swig_director_protected_mode() && Swig_all_protected_mode())) {
+ // If the base class function is »protected« and were are not in
+ // director mode, it is not emitted to the base class and thus we do
+ // not count it. Otherwise, we would run into issues if the visiblity
+ // of some functions was changed from protected to public in a child
+ // class with the using directive.
+ continue;
+ }
+ ++base_overload_count;
+ }
+
+ return ((base_overload_count <= overridingOverloadCount(n)) &&
+ areAllOverloadsOverridden(base_function));
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::overridingOverloadCount()
+ *
+ * Given a member function node, this function counts how many of the
+ * overloads of the function (including itself) override a function in the
+ * base class.
+ * --------------------------------------------------------------------------- */
+ size_t overridingOverloadCount(Node *n) const {
+ size_t result = 0;
+
+ Node *tmp = firstSibling(n);
+ do {
+ // KLUDGE: We also have to count the function if the access attribute is
+ // not present, since this means that it has been promoted into another
+ // protection level in the base class with the C++ »using« directive, and
+ // is thus taken into account when counting the base class overloads, even
+ // if it is not marked as »override« by the SWIG parser.
+ if (Getattr(n, "override") || !Getattr(n, "access")) {
+ ++result;
+ }
+ } while((tmp = Getattr(tmp, "sym:nextSibling")));
+
+ return result;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::firstSibling()
+ *
+ * Returns the first sibling of the passed node.
+ * --------------------------------------------------------------------------- */
+ Node *firstSibling(Node *n) const {
+ Node *result = n;
+ while (Node *tmp = Getattr(result, "sym:previousSibling")) {
+ result = tmp;
+ }
+ return result;
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::indentCode()
+ *
+ * Helper function to indent a code (string) by one level.
+ * --------------------------------------------------------------------------- */
+ void indentCode(String* code) const {
+ Replaceall(code, "\n", "\n ");
+ Replaceall(code, " \n", "\n");
+ Chop(code);
+ }
+
+ /* ---------------------------------------------------------------------------
+ * D::emitBanner()
+ * --------------------------------------------------------------------------- */
+ void emitBanner(File *f) const {
+ Printf(f, "/* ----------------------------------------------------------------------------\n");
+ Swig_banner_target_lang(f, " *");
+ Printf(f, " * ----------------------------------------------------------------------------- */\n\n");
+ }
+};
+
+static Language *new_swig_d() {
+ return new D();
+}
+
+/* -----------------------------------------------------------------------------
+ * swig_d() - Instantiate module
+ * ----------------------------------------------------------------------------- */
+extern "C" Language *swig_d(void) {
+ return new_swig_d();
+}
+
+/* -----------------------------------------------------------------------------
+ * Usage information displayed at the command line.
+ * ----------------------------------------------------------------------------- */
+const char *D::usage = (char *) "\
+D Options (available with -d)\n\
+ -splitproxy - Write each D type to a dedicated file instead of\n\
+ generating a single proxy D module.\n\
+ -noproxy - Generate the low-level functional interface instead\n\
+ of proxy classes\n\
+ -package - Write generated D modules into package \n\
+ -wrapperlibrary - Sets the name of the wrapper library to \n\
+\n";
diff --git a/Source/Modules/swigmain.cxx b/Source/Modules/swigmain.cxx
index 86cccdf88..01ab1b79f 100644
--- a/Source/Modules/swigmain.cxx
+++ b/Source/Modules/swigmain.cxx
@@ -52,6 +52,7 @@ extern "C" {
Language *swig_uffi(void);
Language *swig_r(void);
Language *swig_go(void);
+ Language *swig_d(void);
}
struct swig_module {
@@ -70,6 +71,7 @@ static swig_module modules[] = {
{"-clisp", swig_clisp, "CLISP"},
{"-cffi", swig_cffi, "CFFI"},
{"-csharp", swig_csharp, "C#"},
+ {"-d", swig_d, "D"},
{"-go", swig_go, "Go"},
{"-guile", swig_guile, "Guile"},
{"-java", swig_java, "Java"},
diff --git a/configure.in b/configure.in
index 36337b41d..5383c40c7 100644
--- a/configure.in
+++ b/configure.in
@@ -2016,6 +2016,42 @@ fi
AC_SUBST(GOGCC)
AC_SUBST(GO)
+#----------------------------------------------------------------
+# Look for D
+#----------------------------------------------------------------
+
+AC_ARG_WITH(d, AS_HELP_STRING([--without-d], [Disable D]), [with_d="$withval"], [with_d=yes])
+AC_ARG_WITH(d1-compiler, [ --with-d1-compiler=path Set location of D1 compiler (DMD compatible)],[D1COMPILERBIN="$withval"], [D1COMPILERBIN=])
+AC_ARG_WITH(d2-compiler, [ --with-d2-compiler=path Set location of D2 compiler (DMD compatible)],[D2COMPILERBIN="$withval"], [D2COMPILERBIN=])
+
+# First, check for "--without-d" or "--with-d=no".
+if test x"${with_d}" = xno -o x"${with_alllang}" = xno ; then
+ AC_MSG_NOTICE([Disabling D])
+ D1COMPILER=
+ D2COMPILER=
+else
+ if test -z "$D1COMPILERBIN" ; then
+ AC_CHECK_PROGS(D1COMPILER, dmd ldmd gdmd)
+ else
+ D1COMPILER="$D1COMPILERBIN"
+ fi
+ if test -z "$D2COMPILERBIN" ; then
+ AC_CHECK_PROGS(D2COMPILER, dmd gdmd)
+ else
+ D2COMPILER="$D2COMPILERBIN"
+ fi
+fi
+
+# Do not prefix library file names with "lib" on Windows.
+case $host in
+*-*-cygwin* | *-*-mingw*) DLIBPREFIX="";;
+*)DLIBPREFIX="lib";;
+esac
+
+AC_SUBST(D1COMPILER)
+AC_SUBST(D2COMPILER)
+AC_SUBST(DLIBPREFIX)
+
#----------------------------------------------------------------
# Determine which languages to use for examples/test-suite
#----------------------------------------------------------------
@@ -2172,6 +2208,12 @@ if test -z "$GO" ; then
fi
AC_SUBST(SKIP_GO)
+SKIP_D=
+if test -z "$D1COMPILER" && test -z "$D2COMPILER" ; then
+ SKIP_D="1"
+fi
+AC_SUBST(SKIP_D)
+
#----------------------------------------------------------------
# Additional language dependencies
#----------------------------------------------------------------
@@ -2232,6 +2274,7 @@ AC_CONFIG_FILES([ \
Examples/xml/Makefile \
Examples/test-suite/chicken/Makefile \
Examples/test-suite/csharp/Makefile \
+ Examples/test-suite/d/Makefile \
Examples/test-suite/guile/Makefile \
Examples/test-suite/guilescm/Makefile \
Examples/test-suite/java/Makefile \
From d69d8ff641b28fdd7a6ddaeb724980060225fd3d Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 18 Nov 2010 10:16:05 +0000
Subject: [PATCH 017/317] [D] Renamed the "dnativeconst" feature to
"dmanifestconst".
This should make it clearer that it controls manifest constant generation, not handling of C++ const member functions.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12300 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Doc/Manual/D.html | 4 ++--
Examples/d/constants/example.i | 2 +-
Examples/test-suite/preproc_line_file.i | 2 +-
Examples/test-suite/static_const_member.i | 4 ++--
Lib/d/ddirectives.swg | 2 +-
Source/Modules/d.cxx | 12 ++++++------
6 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html
index 2b563788f..a232f236b 100644
--- a/Doc/Manual/D.html
+++ b/Doc/Manual/D.html
@@ -281,9 +281,9 @@ $importtype(AnotherInterface)
- %dnativeconst and %dconstvalue(value)
+ %dmanifestconst and %dconstvalue(value)
- Out of the box, SWIG generates accessor methods for C #defines and C++ constants. The %dnativeconst directive enables wrapping these constants as D manifest constants (const in D1, enum in D2).
+ Out of the box, SWIG generates accessor methods for C #defines and C++ constants. The %dmanifestconst directive enables wrapping these constants as D manifest constants (const in D1, enum in D2).
For this to work, the C/C++ code for the constant value must directly compile as D code, though. If this is not the case, you can manually override the expression written to the D wrapper using the %dconstvalue directive, passing the new value as parameter.
For enum s, again %dconstvalue can be used to override the value of an enum item if the initializer should not compile in D.
diff --git a/Examples/d/constants/example.i b/Examples/d/constants/example.i
index 5eb541919..edeb258cd 100644
--- a/Examples/d/constants/example.i
+++ b/Examples/d/constants/example.i
@@ -4,7 +4,7 @@
/* Force the generated D code to use the C constant values rather than
retrieving them at runtime. You can also try disabling the feature and
compare the generated code. */
-%dnativeconst;
+%dmanifestconst;
/* A few preprocessor macros */
diff --git a/Examples/test-suite/preproc_line_file.i b/Examples/test-suite/preproc_line_file.i
index 91ff2133e..b221b7728 100644
--- a/Examples/test-suite/preproc_line_file.i
+++ b/Examples/test-suite/preproc_line_file.i
@@ -34,7 +34,7 @@ const int NUMBER_UNIQUE(thing) = -2; /* resolves to thing28 */
#elif defined(SWIGCSHARP)
%csconst(1);
#elif defined(SWIGD)
-%dnativeconst;
+%dmanifestconst;
#else
%ignore LINE_NUMBER;
%ignore LINE_NUM;
diff --git a/Examples/test-suite/static_const_member.i b/Examples/test-suite/static_const_member.i
index 945e28490..a8d119b81 100644
--- a/Examples/test-suite/static_const_member.i
+++ b/Examples/test-suite/static_const_member.i
@@ -12,8 +12,8 @@
%csconst(1) EN;
%csconst(1) CHARTEST;
#elif SWIGD
-%dnativeconst EN;
-%dnativeconst CHARTEST;
+%dmanifestconst EN;
+%dmanifestconst CHARTEST;
#endif
%inline %{
diff --git a/Lib/d/ddirectives.swg b/Lib/d/ddirectives.swg
index 2b6ad77e2..f3052cb87 100644
--- a/Lib/d/ddirectives.swg
+++ b/Lib/d/ddirectives.swg
@@ -4,7 +4,7 @@
* D-specifiv directives.
* ----------------------------------------------------------------------------- */
-#define %dnativeconst %feature("d:nativeconst")
+#define %dmanifestconst %feature("d:manifestconst")
#define %dconstvalue(value) %feature("d:constvalue",value)
#define %dmethodmodifiers %feature("d:methodmodifiers")
#define %dstripprefix %feature("d:stripprefix")
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
index e3e1d9759..4f48275fc 100644
--- a/Source/Modules/d.cxx
+++ b/Source/Modules/d.cxx
@@ -864,7 +864,7 @@ public:
String *value = Getattr(n, "feature:d:constvalue");
// Note that in D, enum values must be compile-time constants. Thus,
- // %dnativeconst(0) (getting the enum values at runtime) is not supported.
+ // %dmanifestconst(0) (getting the enum values at runtime) is not supported.
value = value ? value : Getattr(n, "enumvalue");
if (value) {
Printf(proxy_enum_code, " = %s", value);
@@ -976,7 +976,7 @@ public:
* D::staticmembervariableHandler()
* --------------------------------------------------------------------------- */
virtual int staticmembervariableHandler(Node *n) {
- if (GetFlag(n, "feature:d:nativeconst") != 1) {
+ if (GetFlag(n, "feature:d:manifestconst") != 1) {
Delattr(n, "value");
}
@@ -1298,7 +1298,7 @@ public:
* Used for wrapping constants declared by #define or %constant and also for
* (primitive) static member constants initialised inline.
*
- * If the %dnativeconst feature is used, the C/C++ constant value is used to
+ * If the %dmanifestconst feature is used, the C/C++ constant value is used to
* initialize a D »const«. If not, a »getter« method is generated which
* retrieves the value via a call to the C wrapper. However, if there is a
* %dconstvalue specified, it overrides all other settings.
@@ -1308,9 +1308,9 @@ public:
if (!addSymbol(symname, n))
return SWIG_ERROR;
- // The %dnativeconst feature determines if a D const or a getter function is
- // created.
- if (GetFlag(n, "feature:d:nativeconst") != 1) {
+ // The %dmanifestconst feature determines if a D manifest constant
+ // (const/enum) or a getter function is created.
+ if (GetFlag(n, "feature:d:manifestconst") != 1) {
// Default constant handling will work with any type of C constant. It
// generates a getter function (which is the same as a read only property
// in D) which retrieves the value via by calling the C wrapper.
From 68678aefd58f3e28707855e851ef0d46af4baa9c Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 18 Nov 2010 10:16:15 +0000
Subject: [PATCH 018/317] Added note about the inclusion of D to the CHANGES
file.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12301 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 3 +++
1 file changed, 3 insertions(+)
diff --git a/CHANGES.current b/CHANGES.current
index f18011e1a..0b0bc59e7 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (in progress)
===========================
+2010-11-18: klickverbot
+ [D] Added the D language module.
+
2010-11-12: vadz
Fix handling of multiple regex-using %renames attached to the same
declaration. For example, now
From cd492d8300156be36276edef31d1594deeee0f6b Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Sun, 21 Nov 2010 23:43:19 +0000
Subject: [PATCH 019/317] [D] Added a missing part of the Windows wrapper
library loading code.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12302 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/d/wrapperloader.swg | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/Lib/d/wrapperloader.swg b/Lib/d/wrapperloader.swg
index 9336843af..428af7b60 100644
--- a/Lib/d/wrapperloader.swg
+++ b/Lib/d/wrapperloader.swg
@@ -146,6 +146,7 @@ private {
return swigToDString(err);
}
} else version(Windows) {
+ alias ushort WORD;
alias uint DWORD;
alias CCPTR LPCSTR;
alias void* HMODULE;
@@ -162,6 +163,10 @@ private {
HLOCAL LocalFree(HLOCAL);
}
+ DWORD MAKELANGID(WORD p, WORD s) {
+ return (((cast(WORD)s) << 10) | cast(WORD)p);
+ }
+
enum {
LANG_NEUTRAL = 0,
SUBLANG_DEFAULT = 1,
From e362f85431c5cfa321870ea14431c803e1a2da7b Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Mon, 22 Nov 2010 00:33:26 +0000
Subject: [PATCH 020/317] [D] Use __cdecl instead of __stdcall on Windows as
well to avoid special casing.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12303 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/d/dhead.swg | 8 ++++----
Source/Modules/d.cxx | 10 +++++-----
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg
index e05bc7728..e4dca36e8 100644
--- a/Lib/d/dhead.swg
+++ b/Lib/d/dhead.swg
@@ -23,7 +23,7 @@ typedef enum {
SWIG_DNoSuchElementException,
} SWIG_DExceptionCodes;
-typedef void (SWIGSTDCALL* SWIG_DExceptionCallback_t)(const char *);
+typedef void (* SWIG_DExceptionCallback_t)(const char *);
typedef struct {
SWIG_DExceptionCodes code;
@@ -49,7 +49,7 @@ static void SWIGUNUSED SWIG_DSetPendingException(SWIG_DExceptionCodes code, cons
#ifdef __cplusplus
extern "C"
#endif
-SWIGEXPORT void SWIGSTDCALL SWIGRegisterExceptionCallbacks_$module(
+SWIGEXPORT void SWIGRegisterExceptionCallbacks_$module(
SWIG_DExceptionCallback_t exceptionCallback,
SWIG_DExceptionCallback_t illegalArgumentCallback,
SWIG_DExceptionCallback_t illegalElementCallback,
@@ -253,13 +253,13 @@ alias void function(const char* message) SwigExceptionCallback;
#if !defined(SWIG_D_NO_STRING_HELPER)
%insert(runtime) %{
// Callback for returning strings to D without leaking memory.
-typedef char * (SWIGSTDCALL* SWIG_DStringHelperCallback)(const char *);
+typedef char * (* SWIG_DStringHelperCallback)(const char *);
static SWIG_DStringHelperCallback SWIG_d_string_callback = NULL;
#ifdef __cplusplus
extern "C"
#endif
-SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_$module(SWIG_DStringHelperCallback callback) {
+SWIGEXPORT void SWIGRegisterStringCallback_$module(SWIG_DStringHelperCallback callback) {
SWIG_d_string_callback = callback;
}
%}
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
index 4f48275fc..c4274bf63 100644
--- a/Source/Modules/d.cxx
+++ b/Source/Modules/d.cxx
@@ -1480,7 +1480,7 @@ public:
if (!is_void_return)
Wrapper_add_localv(f, "jresult", c_return_type, "jresult", NIL);
- Printv(f->def, " SWIGEXPORT ", c_return_type, " SWIGSTDCALL ", wname, "(", NIL);
+ Printv(f->def, " SWIGEXPORT ", c_return_type, " ", wname, "(", NIL);
// Emit all of the local variables for holding arguments.
emit_parameter_variables(l, f);
@@ -2308,7 +2308,7 @@ public:
// Write the global callback function pointer on the C code.
String *methid = Getattr(udata, "class_methodidx");
- Printf(director_callback_typedefs, " typedef %s (SWIGSTDCALL* SWIG_Callback%s_t)", c_ret_type, methid);
+ Printf(director_callback_typedefs, " typedef %s (* SWIG_Callback%s_t)", c_ret_type, methid);
Printf(director_callback_typedefs, "(void *dobj%s);\n", callback_typedef_parms);
Printf(director_callback_pointers, " SWIG_Callback%s_t swig_callback_%s;\n", methid, overloaded_name);
@@ -3287,7 +3287,7 @@ private:
String *smartnamestr = SwigType_namestr(smart);
String *bsmartnamestr = SwigType_namestr(bsmart);
Printv(upcasts_code,
- "SWIGEXPORT ", bsmartnamestr, " * SWIGSTDCALL ", upcast_wrapper_name,
+ "SWIGEXPORT ", bsmartnamestr, " * ", upcast_wrapper_name,
"(", smartnamestr, " *objectRef) {\n",
" return objectRef ? new ", bsmartnamestr, "(*objectRef) : 0;\n"
"}\n",
@@ -3302,7 +3302,7 @@ private:
}
} else {
Printv(upcasts_code,
- "SWIGEXPORT ", c_base_name, " * SWIGSTDCALL ", upcast_wrapper_name,
+ "SWIGEXPORT ", c_base_name, " * ", upcast_wrapper_name,
"(", c_base_name, " *objectRef) {\n",
" return (", c_base_name, " *)objectRef;\n"
"}\n",
@@ -3480,7 +3480,7 @@ private:
Printf(wrap_dmodule_code, "extern(C) void function(void* cObject, void* dObject");
code_wrap = NewWrapper();
- Printf(code_wrap->def, "SWIGEXPORT void SWIGSTDCALL D_%s(void *objarg, void *dobj", connect_name);
+ Printf(code_wrap->def, "SWIGEXPORT void D_%s(void *objarg, void *dobj", connect_name);
Printf(code_wrap->code, " %s *obj = (%s *)objarg;\n", norm_name, norm_name);
Printf(code_wrap->code, " SwigDirector_%s *director = dynamic_cast(obj);\n", sym_name, sym_name);
From e0c82f6f2b5d550d45449979980a024fc822a34d Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 25 Nov 2010 20:35:10 +0000
Subject: [PATCH 021/317] portability fix
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12308 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/Modules/d.cxx | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
index c4274bf63..ce33b5252 100644
--- a/Source/Modules/d.cxx
+++ b/Source/Modules/d.cxx
@@ -1015,6 +1015,7 @@ public:
ParmList *l = Getattr(n, "parms");
String *tm;
String *proxy_constructor_code = NewString("");
+ int i;
// Holds code for the constructor helper method generated only when the din
// typemap has code in the pre or post attributes.
@@ -1060,7 +1061,7 @@ public:
/* Output each parameter */
Parm *p = l;
- for (unsigned int i = 0; p; i++) {
+ for (i = 0; p; i++) {
if (checkAttribute(p, "varargs:ignore", "1")) {
// Skip ignored varargs.
p = nextSibling(p);
From 004643ff30118e7a61484f329bfeebebfb202053 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 25 Nov 2010 20:39:11 +0000
Subject: [PATCH 022/317] Fix mangling of PHP constructor wrapper when types
use global scope or typedefs
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12309 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/Modules/php.cxx | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
index 05f2082c2..b95eaa7cd 100644
--- a/Source/Modules/php.cxx
+++ b/Source/Modules/php.cxx
@@ -1601,10 +1601,9 @@ public:
Delete(args);
args = NewString("$res=null");
}
- SwigType *t = Getattr(current_class, "classtype");
- String *mangled_type = SwigType_manglestr(SwigType_ltype(t));
+ String *mangled_type = SwigType_manglestr(Getattr(n, "type"));
Printf(output, "\t%sfunction %s(%s) {\n", acc, methodname, args);
- Printf(output, "\t\tif (is_resource($%s) && get_resource_type($%s) === '_p%s') {\n", arg0, arg0, mangled_type);
+ Printf(output, "\t\tif (is_resource($%s) && get_resource_type($%s) === '%s') {\n", arg0, arg0, mangled_type);
Printf(output, "\t\t\t$this->%s=$%s;\n", SWIG_PTR, arg0);
Printf(output, "\t\t\treturn;\n");
Printf(output, "\t\t}\n");
From 75ad4f57b94728e6ecfb0ad29e985ea483672555 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Fri, 26 Nov 2010 20:28:39 +0000
Subject: [PATCH 023/317] Incorrect mangling leading to some cast errors in the
Go director destructors
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12315 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/Modules/go.cxx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx
index d3de53f8f..6e8d2c09a 100644
--- a/Source/Modules/go.cxx
+++ b/Source/Modules/go.cxx
@@ -2679,7 +2679,7 @@ private:
Setattr(n, "wrap:name", fnname);
- Swig_DestructorToFunction(n, getNSpace(), Getattr(parentNode(n), "classtype"), CPlusPlus, Extend);
+ Swig_DestructorToFunction(n, getNSpace(), getClassType(), CPlusPlus, Extend);
ParmList *parms = Getattr(n, "parms");
Setattr(n, "wrap:parms", parms);
From b89248404ddcfcfd3520780e6b1d50b4ac6843b6 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Fri, 26 Nov 2010 20:32:23 +0000
Subject: [PATCH 024/317] Remove generated files from svn for Go examples
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12316 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/go/callback/example.go | 188 ---------------
Examples/go/class/example.go | 284 ----------------------
Examples/go/constants/example.go | 44 ----
Examples/go/enum/example.go | 93 --------
Examples/go/extend/example.go | 397 -------------------------------
Examples/go/funcptr/example.go | 54 -----
Examples/go/multimap/example.go | 55 -----
Examples/go/pointer/example.go | 68 ------
Examples/go/reference/example.go | 126 ----------
Examples/go/simple/example.go | 48 ----
Examples/go/template/example.go | 150 ------------
Examples/go/variables/example.go | 198 ---------------
12 files changed, 1705 deletions(-)
delete mode 100644 Examples/go/callback/example.go
delete mode 100644 Examples/go/class/example.go
delete mode 100644 Examples/go/constants/example.go
delete mode 100644 Examples/go/enum/example.go
delete mode 100644 Examples/go/extend/example.go
delete mode 100644 Examples/go/funcptr/example.go
delete mode 100644 Examples/go/multimap/example.go
delete mode 100644 Examples/go/pointer/example.go
delete mode 100644 Examples/go/reference/example.go
delete mode 100644 Examples/go/simple/example.go
delete mode 100644 Examples/go/template/example.go
delete mode 100644 Examples/go/variables/example.go
diff --git a/Examples/go/callback/example.go b/Examples/go/callback/example.go
deleted file mode 100644
index 5c0cfb051..000000000
--- a/Examples/go/callback/example.go
+++ /dev/null
@@ -1,188 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-type _swig_DirectorCallback struct {
- SwigcptrCallback
- v interface{}
-}
-
-func (p *_swig_DirectorCallback) Swigcptr() uintptr {
- return p.SwigcptrCallback.Swigcptr()
-}
-
-func (p *_swig_DirectorCallback) SwigIsCallback() {
-}
-
-func (p *_swig_DirectorCallback) DirectorInterface() interface{} {
- return p.v
-}
-
-func _swig_NewDirectorCallbackCallback(*_swig_DirectorCallback) SwigcptrCallback
-
-func NewDirectorCallback(v interface{}) Callback {
- p := &_swig_DirectorCallback{0, v}
- p.SwigcptrCallback = _swig_NewDirectorCallbackCallback(p)
- return p
-}
-
-func _swig_wrap_DeleteDirectorCallback(uintptr)
-
-func DeleteDirectorCallback(arg1 Callback) {
- _swig_wrap_DeleteDirectorCallback(arg1.Swigcptr())
-}
-
-func Swiggo_DeleteDirector_Callback(p *_swig_DirectorCallback) {
- p.SwigcptrCallback = 0
-}
-
-type _swig_DirectorInterfaceCallbackRun interface {
- Run()
-}
-
-func _swig_wrap__swig_DirectorCallback_upcall_Run(SwigcptrCallback)
-func (swig_p *_swig_DirectorCallback) Run() {
- if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceCallbackRun); swig_ok {
- swig_g.Run()
- return
- }
- _swig_wrap__swig_DirectorCallback_upcall_Run(swig_p.SwigcptrCallback)
-}
-
-func DirectorCallbackRun(p Callback) {
- _swig_wrap__swig_DirectorCallback_upcall_Run(p.(*_swig_DirectorCallback).SwigcptrCallback)
-}
-
-func Swig_DirectorCallback_callback_run(p *_swig_DirectorCallback) {
- p.Run()
-}
-
-type SwigcptrCallback uintptr
-
-func (p SwigcptrCallback) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrCallback) SwigIsCallback() {
-}
-
-func (p SwigcptrCallback) DirectorInterface() interface{} {
- return nil
-}
-
-func _swig_wrap_delete_Callback(uintptr)
-
-func DeleteCallback(arg1 Callback) {
- _swig_wrap_delete_Callback(arg1.Swigcptr())
-}
-
-func _swig_wrap_Callback_run(SwigcptrCallback)
-
-func (arg1 SwigcptrCallback) Run() {
- _swig_wrap_Callback_run(arg1)
-}
-
-func _swig_wrap_new_Callback() SwigcptrCallback
-
-func NewCallback() Callback {
- return _swig_wrap_new_Callback()
-}
-
-type Callback interface {
- Swigcptr() uintptr
- SwigIsCallback()
- DirectorInterface() interface{}
- Run()
-}
-
-type SwigcptrCaller uintptr
-
-func (p SwigcptrCaller) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrCaller) SwigIsCaller() {
-}
-
-func _swig_wrap_new_Caller() SwigcptrCaller
-
-func NewCaller() Caller {
- return _swig_wrap_new_Caller()
-}
-
-func _swig_wrap_delete_Caller(uintptr)
-
-func DeleteCaller(arg1 Caller) {
- _swig_wrap_delete_Caller(arg1.Swigcptr())
-}
-
-func _swig_wrap_Caller_delCallback(SwigcptrCaller)
-
-func (arg1 SwigcptrCaller) DelCallback() {
- _swig_wrap_Caller_delCallback(arg1)
-}
-
-func _swig_wrap_Caller_setCallback(SwigcptrCaller, uintptr)
-
-func (arg1 SwigcptrCaller) SetCallback(arg2 Callback) {
- _swig_wrap_Caller_setCallback(arg1, arg2.Swigcptr())
-}
-
-func _swig_wrap_Caller_call(SwigcptrCaller)
-
-func (arg1 SwigcptrCaller) Call() {
- _swig_wrap_Caller_call(arg1)
-}
-
-type Caller interface {
- Swigcptr() uintptr
- SwigIsCaller()
- DelCallback()
- SetCallback(arg2 Callback)
- Call()
-}
-
-
-type SwigcptrSwigDirector_Callback uintptr
-type SwigDirector_Callback interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrSwigDirector_Callback) Swigcptr() uintptr {
- return uintptr(p)
-}
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
diff --git a/Examples/go/class/example.go b/Examples/go/class/example.go
deleted file mode 100644
index ec8113ad4..000000000
--- a/Examples/go/class/example.go
+++ /dev/null
@@ -1,284 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-type SwigcptrShape uintptr
-
-func (p SwigcptrShape) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrShape) SwigIsShape() {
-}
-
-func _swig_wrap_delete_Shape(uintptr)
-
-func DeleteShape(arg1 Shape) {
- _swig_wrap_delete_Shape(arg1.Swigcptr())
-}
-
-func _swig_wrap_Shape_x_set(SwigcptrShape, float64)
-
-func (arg1 SwigcptrShape) SetX(arg2 float64) {
- _swig_wrap_Shape_x_set(arg1, arg2)
-}
-
-func _swig_wrap_Shape_x_get(SwigcptrShape) float64
-
-func (arg1 SwigcptrShape) GetX() float64 {
- return _swig_wrap_Shape_x_get(arg1)
-}
-
-func _swig_wrap_Shape_y_set(SwigcptrShape, float64)
-
-func (arg1 SwigcptrShape) SetY(arg2 float64) {
- _swig_wrap_Shape_y_set(arg1, arg2)
-}
-
-func _swig_wrap_Shape_y_get(SwigcptrShape) float64
-
-func (arg1 SwigcptrShape) GetY() float64 {
- return _swig_wrap_Shape_y_get(arg1)
-}
-
-func _swig_wrap_Shape_move(SwigcptrShape, float64, float64)
-
-func (arg1 SwigcptrShape) Move(arg2 float64, arg3 float64) {
- _swig_wrap_Shape_move(arg1, arg2, arg3)
-}
-
-func _swig_wrap_Shape_area(SwigcptrShape) float64
-
-func (arg1 SwigcptrShape) Area() float64 {
- return _swig_wrap_Shape_area(arg1)
-}
-
-func _swig_wrap_Shape_perimeter(SwigcptrShape) float64
-
-func (arg1 SwigcptrShape) Perimeter() float64 {
- return _swig_wrap_Shape_perimeter(arg1)
-}
-
-func _swig_wrap_Shape_nshapes_set(int)
-
-func SetShapeNshapes(arg1 int) {
- _swig_wrap_Shape_nshapes_set(arg1)
-}
-
-func GetShapeNshapes() int
-type Shape interface {
- Swigcptr() uintptr
- SwigIsShape()
- SetX(arg2 float64)
- GetX() float64
- SetY(arg2 float64)
- GetY() float64
- Move(arg2 float64, arg3 float64)
- Area() float64
- Perimeter() float64
-}
-
-type SwigcptrCircle uintptr
-
-func (p SwigcptrCircle) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrCircle) SwigIsCircle() {
-}
-
-func _swig_wrap_new_Circle(float64) SwigcptrCircle
-
-func NewCircle(arg1 float64) Circle {
- return _swig_wrap_new_Circle(arg1)
-}
-
-func _swig_wrap_Circle_area(SwigcptrCircle) float64
-
-func (arg1 SwigcptrCircle) Area() float64 {
- return _swig_wrap_Circle_area(arg1)
-}
-
-func _swig_wrap_Circle_perimeter(SwigcptrCircle) float64
-
-func (arg1 SwigcptrCircle) Perimeter() float64 {
- return _swig_wrap_Circle_perimeter(arg1)
-}
-
-func _swig_wrap_delete_Circle(uintptr)
-
-func DeleteCircle(arg1 Circle) {
- _swig_wrap_delete_Circle(arg1.Swigcptr())
-}
-
-func _swig_wrap_SetCircle_X(SwigcptrCircle, float64)
-
-func (_swig_base SwigcptrCircle) SetX(arg1 float64) {
- _swig_wrap_SetCircle_X(_swig_base, arg1)
-}
-
-func _swig_wrap_GetCircle_X(SwigcptrCircle) float64
-
-func (_swig_base SwigcptrCircle) GetX() float64 {
- return _swig_wrap_GetCircle_X(_swig_base)
-}
-
-func _swig_wrap_SetCircle_Y(SwigcptrCircle, float64)
-
-func (_swig_base SwigcptrCircle) SetY(arg1 float64) {
- _swig_wrap_SetCircle_Y(_swig_base, arg1)
-}
-
-func _swig_wrap_GetCircle_Y(SwigcptrCircle) float64
-
-func (_swig_base SwigcptrCircle) GetY() float64 {
- return _swig_wrap_GetCircle_Y(_swig_base)
-}
-
-func _swig_wrap_Circle_move(SwigcptrCircle, float64, float64)
-
-func (_swig_base SwigcptrCircle) Move(arg1 float64, arg2 float64) {
- _swig_wrap_Circle_move(_swig_base, arg1, arg2)
-}
-
-func (p SwigcptrCircle) SwigIsShape() {
-}
-
-func (p SwigcptrCircle) SwigGetShape() Shape {
- return SwigcptrShape(p.Swigcptr())
-}
-
-type Circle interface {
- Swigcptr() uintptr
- SwigIsCircle()
- Area() float64
- Perimeter() float64
- SetX(arg1 float64)
- GetX() float64
- SetY(arg1 float64)
- GetY() float64
- Move(arg1 float64, arg2 float64)
- SwigIsShape()
- SwigGetShape() Shape
-}
-
-type SwigcptrSquare uintptr
-
-func (p SwigcptrSquare) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrSquare) SwigIsSquare() {
-}
-
-func _swig_wrap_new_Square(float64) SwigcptrSquare
-
-func NewSquare(arg1 float64) Square {
- return _swig_wrap_new_Square(arg1)
-}
-
-func _swig_wrap_Square_area(SwigcptrSquare) float64
-
-func (arg1 SwigcptrSquare) Area() float64 {
- return _swig_wrap_Square_area(arg1)
-}
-
-func _swig_wrap_Square_perimeter(SwigcptrSquare) float64
-
-func (arg1 SwigcptrSquare) Perimeter() float64 {
- return _swig_wrap_Square_perimeter(arg1)
-}
-
-func _swig_wrap_delete_Square(uintptr)
-
-func DeleteSquare(arg1 Square) {
- _swig_wrap_delete_Square(arg1.Swigcptr())
-}
-
-func _swig_wrap_SetSquare_X(SwigcptrSquare, float64)
-
-func (_swig_base SwigcptrSquare) SetX(arg1 float64) {
- _swig_wrap_SetSquare_X(_swig_base, arg1)
-}
-
-func _swig_wrap_GetSquare_X(SwigcptrSquare) float64
-
-func (_swig_base SwigcptrSquare) GetX() float64 {
- return _swig_wrap_GetSquare_X(_swig_base)
-}
-
-func _swig_wrap_SetSquare_Y(SwigcptrSquare, float64)
-
-func (_swig_base SwigcptrSquare) SetY(arg1 float64) {
- _swig_wrap_SetSquare_Y(_swig_base, arg1)
-}
-
-func _swig_wrap_GetSquare_Y(SwigcptrSquare) float64
-
-func (_swig_base SwigcptrSquare) GetY() float64 {
- return _swig_wrap_GetSquare_Y(_swig_base)
-}
-
-func _swig_wrap_Square_move(SwigcptrSquare, float64, float64)
-
-func (_swig_base SwigcptrSquare) Move(arg1 float64, arg2 float64) {
- _swig_wrap_Square_move(_swig_base, arg1, arg2)
-}
-
-func (p SwigcptrSquare) SwigIsShape() {
-}
-
-func (p SwigcptrSquare) SwigGetShape() Shape {
- return SwigcptrShape(p.Swigcptr())
-}
-
-type Square interface {
- Swigcptr() uintptr
- SwigIsSquare()
- Area() float64
- Perimeter() float64
- SetX(arg1 float64)
- GetX() float64
- SetY(arg1 float64)
- GetY() float64
- Move(arg1 float64, arg2 float64)
- SwigIsShape()
- SwigGetShape() Shape
-}
-
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
diff --git a/Examples/go/constants/example.go b/Examples/go/constants/example.go
deleted file mode 100644
index 0e5e66418..000000000
--- a/Examples/go/constants/example.go
+++ /dev/null
@@ -1,44 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-const ICONST int = 42
-const FCONST float64 = 2.1828
-const CCONST byte = 'x'
-func _swig_getCCONST2() byte
-var CCONST2 byte = _swig_getCCONST2()
-const SCONST string = "Hello World"
-func _swig_getSCONST2() string
-var SCONST2 string = _swig_getSCONST2()
-func _swig_getEXPR() float64
-var EXPR float64 = _swig_getEXPR()
-const Iconst int = 37
-const Fconst float64 = 3.14
-
diff --git a/Examples/go/enum/example.go b/Examples/go/enum/example.go
deleted file mode 100644
index 4653ab57a..000000000
--- a/Examples/go/enum/example.go
+++ /dev/null
@@ -1,93 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-type Color int
-func _swig_getRED() Color
-var RED Color = _swig_getRED()
-func _swig_getBLUE() Color
-var BLUE Color = _swig_getBLUE()
-func _swig_getGREEN() Color
-var GREEN Color = _swig_getGREEN()
-type SwigcptrFoo uintptr
-
-func (p SwigcptrFoo) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrFoo) SwigIsFoo() {
-}
-
-func _swig_wrap_new_Foo() SwigcptrFoo
-
-func NewFoo() Foo {
- return _swig_wrap_new_Foo()
-}
-
-type FooSpeed int
-func _swig_getFoo_IMPULSE_Foo() FooSpeed
-var FooIMPULSE FooSpeed = _swig_getFoo_IMPULSE_Foo()
-func _swig_getFoo_WARP_Foo() FooSpeed
-var FooWARP FooSpeed = _swig_getFoo_WARP_Foo()
-func _swig_getFoo_LUDICROUS_Foo() FooSpeed
-var FooLUDICROUS FooSpeed = _swig_getFoo_LUDICROUS_Foo()
-func _swig_wrap_Foo_enum_test(SwigcptrFoo, FooSpeed)
-
-func (arg1 SwigcptrFoo) Enum_test(arg2 FooSpeed) {
- _swig_wrap_Foo_enum_test(arg1, arg2)
-}
-
-func _swig_wrap_delete_Foo(uintptr)
-
-func DeleteFoo(arg1 Foo) {
- _swig_wrap_delete_Foo(arg1.Swigcptr())
-}
-
-type Foo interface {
- Swigcptr() uintptr
- SwigIsFoo()
- Enum_test(arg2 FooSpeed)
-}
-
-func _swig_wrap_enum_test(Color, FooSpeed)
-
-func Enum_test(arg1 Color, arg2 FooSpeed) {
- _swig_wrap_enum_test(arg1, arg2)
-}
-
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
diff --git a/Examples/go/extend/example.go b/Examples/go/extend/example.go
deleted file mode 100644
index 08f21e6ab..000000000
--- a/Examples/go/extend/example.go
+++ /dev/null
@@ -1,397 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-type _swig_DirectorEmployee struct {
- SwigcptrEmployee
- v interface{}
-}
-
-func (p *_swig_DirectorEmployee) Swigcptr() uintptr {
- return p.SwigcptrEmployee.Swigcptr()
-}
-
-func (p *_swig_DirectorEmployee) SwigIsEmployee() {
-}
-
-func (p *_swig_DirectorEmployee) DirectorInterface() interface{} {
- return p.v
-}
-
-func _swig_NewDirectorEmployeeEmployee(*_swig_DirectorEmployee, string) SwigcptrEmployee
-
-func NewDirectorEmployee(v interface{}, arg1 string) Employee {
- p := &_swig_DirectorEmployee{0, v}
- p.SwigcptrEmployee = _swig_NewDirectorEmployeeEmployee(p, arg1)
- return p
-}
-
-type _swig_DirectorInterfaceEmployeeGetTitle interface {
- GetTitle() string
-}
-
-func _swig_wrap__swig_DirectorEmployee_upcall_GetTitle(SwigcptrEmployee) string
-func (swig_p *_swig_DirectorEmployee) GetTitle() string {
- if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceEmployeeGetTitle); swig_ok {
- return swig_g.GetTitle()
- }
- return _swig_wrap__swig_DirectorEmployee_upcall_GetTitle(swig_p.SwigcptrEmployee)
-}
-
-func DirectorEmployeeGetTitle(p Employee) string {
- return _swig_wrap__swig_DirectorEmployee_upcall_GetTitle(p.(*_swig_DirectorEmployee).SwigcptrEmployee)
-}
-
-func Swig_DirectorEmployee_callback_getTitle(p *_swig_DirectorEmployee) (swig_result string) {
- return p.GetTitle()
-}
-
-type _swig_DirectorInterfaceEmployeeGetName interface {
- GetName() string
-}
-
-func _swig_wrap__swig_DirectorEmployee_upcall_GetName(SwigcptrEmployee) string
-func (swig_p *_swig_DirectorEmployee) GetName() string {
- if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceEmployeeGetName); swig_ok {
- return swig_g.GetName()
- }
- return _swig_wrap__swig_DirectorEmployee_upcall_GetName(swig_p.SwigcptrEmployee)
-}
-
-func DirectorEmployeeGetName(p Employee) string {
- return _swig_wrap__swig_DirectorEmployee_upcall_GetName(p.(*_swig_DirectorEmployee).SwigcptrEmployee)
-}
-
-func Swig_DirectorEmployee_callback_getName(p *_swig_DirectorEmployee) (swig_result string) {
- return p.GetName()
-}
-
-type _swig_DirectorInterfaceEmployeeGetPosition interface {
- GetPosition() string
-}
-
-func _swig_wrap__swig_DirectorEmployee_upcall_GetPosition(SwigcptrEmployee) string
-func (swig_p *_swig_DirectorEmployee) GetPosition() string {
- if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceEmployeeGetPosition); swig_ok {
- return swig_g.GetPosition()
- }
- return _swig_wrap__swig_DirectorEmployee_upcall_GetPosition(swig_p.SwigcptrEmployee)
-}
-
-func DirectorEmployeeGetPosition(p Employee) string {
- return _swig_wrap__swig_DirectorEmployee_upcall_GetPosition(p.(*_swig_DirectorEmployee).SwigcptrEmployee)
-}
-
-func Swig_DirectorEmployee_callback_getPosition(p *_swig_DirectorEmployee) (swig_result string) {
- return p.GetPosition()
-}
-
-func _swig_wrap_DeleteDirectorEmployee(uintptr)
-
-func DeleteDirectorEmployee(arg1 Employee) {
- _swig_wrap_DeleteDirectorEmployee(arg1.Swigcptr())
-}
-
-func Swiggo_DeleteDirector_Employee(p *_swig_DirectorEmployee) {
- p.SwigcptrEmployee = 0
-}
-
-type SwigcptrEmployee uintptr
-
-func (p SwigcptrEmployee) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrEmployee) SwigIsEmployee() {
-}
-
-func (p SwigcptrEmployee) DirectorInterface() interface{} {
- return nil
-}
-
-func _swig_wrap_new_Employee(string) SwigcptrEmployee
-
-func NewEmployee(arg1 string) Employee {
- return _swig_wrap_new_Employee(arg1)
-}
-
-func _swig_wrap_Employee_getTitle(SwigcptrEmployee) string
-
-func (arg1 SwigcptrEmployee) GetTitle() string {
- return _swig_wrap_Employee_getTitle(arg1)
-}
-
-func _swig_wrap_Employee_getName(SwigcptrEmployee) string
-
-func (arg1 SwigcptrEmployee) GetName() string {
- return _swig_wrap_Employee_getName(arg1)
-}
-
-func _swig_wrap_Employee_getPosition(SwigcptrEmployee) string
-
-func (arg1 SwigcptrEmployee) GetPosition() string {
- return _swig_wrap_Employee_getPosition(arg1)
-}
-
-func _swig_wrap_delete_Employee(uintptr)
-
-func DeleteEmployee(arg1 Employee) {
- _swig_wrap_delete_Employee(arg1.Swigcptr())
-}
-
-type Employee interface {
- Swigcptr() uintptr
- SwigIsEmployee()
- DirectorInterface() interface{}
- GetTitle() string
- GetName() string
- GetPosition() string
-}
-
-type _swig_DirectorManager struct {
- SwigcptrManager
- v interface{}
-}
-
-func (p *_swig_DirectorManager) Swigcptr() uintptr {
- return p.SwigcptrManager.Swigcptr()
-}
-
-func (p *_swig_DirectorManager) SwigIsManager() {
-}
-
-func (p *_swig_DirectorManager) DirectorInterface() interface{} {
- return p.v
-}
-
-func _swig_NewDirectorManagerManager(*_swig_DirectorManager, string) SwigcptrManager
-
-func NewDirectorManager(v interface{}, arg1 string) Manager {
- p := &_swig_DirectorManager{0, v}
- p.SwigcptrManager = _swig_NewDirectorManagerManager(p, arg1)
- return p
-}
-
-type _swig_DirectorInterfaceManagerGetTitle interface {
- GetTitle() string
-}
-
-func _swig_wrap__swig_DirectorManager_upcall_GetTitle(SwigcptrManager) string
-func (swig_p *_swig_DirectorManager) GetTitle() string {
- if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceManagerGetTitle); swig_ok {
- return swig_g.GetTitle()
- }
- return _swig_wrap__swig_DirectorManager_upcall_GetTitle(swig_p.SwigcptrManager)
-}
-
-func DirectorManagerGetTitle(p Manager) string {
- return _swig_wrap__swig_DirectorManager_upcall_GetTitle(p.(*_swig_DirectorManager).SwigcptrManager)
-}
-
-func Swig_DirectorManager_callback_getTitle(p *_swig_DirectorManager) (swig_result string) {
- return p.GetTitle()
-}
-
-type _swig_DirectorInterfaceManagerGetName interface {
- GetName() string
-}
-
-func _swig_wrap__swig_DirectorManager_upcall_GetName(SwigcptrManager) string
-func (swig_p *_swig_DirectorManager) GetName() string {
- if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceManagerGetName); swig_ok {
- return swig_g.GetName()
- }
- return _swig_wrap__swig_DirectorManager_upcall_GetName(swig_p.SwigcptrManager)
-}
-
-func DirectorManagerGetName(p Manager) string {
- return _swig_wrap__swig_DirectorManager_upcall_GetName(p.(*_swig_DirectorManager).SwigcptrManager)
-}
-
-func Swig_DirectorManager_callback_getName(p *_swig_DirectorManager) (swig_result string) {
- return p.GetName()
-}
-
-type _swig_DirectorInterfaceManagerGetPosition interface {
- GetPosition() string
-}
-
-func _swig_wrap__swig_DirectorManager_upcall_GetPosition(SwigcptrManager) string
-func (swig_p *_swig_DirectorManager) GetPosition() string {
- if swig_g, swig_ok := swig_p.v.(_swig_DirectorInterfaceManagerGetPosition); swig_ok {
- return swig_g.GetPosition()
- }
- return _swig_wrap__swig_DirectorManager_upcall_GetPosition(swig_p.SwigcptrManager)
-}
-
-func DirectorManagerGetPosition(p Manager) string {
- return _swig_wrap__swig_DirectorManager_upcall_GetPosition(p.(*_swig_DirectorManager).SwigcptrManager)
-}
-
-func Swig_DirectorManager_callback_getPosition(p *_swig_DirectorManager) (swig_result string) {
- return p.GetPosition()
-}
-
-func _swig_wrap_DeleteDirectorManager(uintptr)
-
-func DeleteDirectorManager(arg1 Manager) {
- _swig_wrap_DeleteDirectorManager(arg1.Swigcptr())
-}
-
-func Swiggo_DeleteDirector_Manager(p *_swig_DirectorManager) {
- p.SwigcptrManager = 0
-}
-
-type SwigcptrManager uintptr
-
-func (p SwigcptrManager) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrManager) SwigIsManager() {
-}
-
-func (p SwigcptrManager) DirectorInterface() interface{} {
- return nil
-}
-
-func _swig_wrap_new_Manager(string) SwigcptrManager
-
-func NewManager(arg1 string) Manager {
- return _swig_wrap_new_Manager(arg1)
-}
-
-func _swig_wrap_Manager_getPosition(SwigcptrManager) string
-
-func (arg1 SwigcptrManager) GetPosition() string {
- return _swig_wrap_Manager_getPosition(arg1)
-}
-
-func _swig_wrap_delete_Manager(uintptr)
-
-func DeleteManager(arg1 Manager) {
- _swig_wrap_delete_Manager(arg1.Swigcptr())
-}
-
-func _swig_wrap_Manager_getTitle(SwigcptrManager) string
-
-func (_swig_base SwigcptrManager) GetTitle() string {
- return _swig_wrap_Manager_getTitle(_swig_base)
-}
-
-func _swig_wrap_Manager_getName(SwigcptrManager) string
-
-func (_swig_base SwigcptrManager) GetName() string {
- return _swig_wrap_Manager_getName(_swig_base)
-}
-
-func (p SwigcptrManager) SwigIsEmployee() {
-}
-
-func (p SwigcptrManager) SwigGetEmployee() Employee {
- return SwigcptrEmployee(p.Swigcptr())
-}
-
-type Manager interface {
- Swigcptr() uintptr
- SwigIsManager()
- DirectorInterface() interface{}
- GetPosition() string
- GetTitle() string
- GetName() string
- SwigIsEmployee()
- SwigGetEmployee() Employee
-}
-
-type SwigcptrEmployeeList uintptr
-
-func (p SwigcptrEmployeeList) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrEmployeeList) SwigIsEmployeeList() {
-}
-
-func _swig_wrap_new_EmployeeList() SwigcptrEmployeeList
-
-func NewEmployeeList() EmployeeList {
- return _swig_wrap_new_EmployeeList()
-}
-
-func _swig_wrap_EmployeeList_addEmployee(SwigcptrEmployeeList, uintptr)
-
-func (arg1 SwigcptrEmployeeList) AddEmployee(arg2 Employee) {
- _swig_wrap_EmployeeList_addEmployee(arg1, arg2.Swigcptr())
-}
-
-func _swig_wrap_EmployeeList_get_item(SwigcptrEmployeeList, int) SwigcptrEmployee
-
-func (arg1 SwigcptrEmployeeList) Get_item(arg2 int) Employee {
- return _swig_wrap_EmployeeList_get_item(arg1, arg2)
-}
-
-func _swig_wrap_delete_EmployeeList(uintptr)
-
-func DeleteEmployeeList(arg1 EmployeeList) {
- _swig_wrap_delete_EmployeeList(arg1.Swigcptr())
-}
-
-type EmployeeList interface {
- Swigcptr() uintptr
- SwigIsEmployeeList()
- AddEmployee(arg2 Employee)
- Get_item(arg2 int) Employee
-}
-
-
-type SwigcptrSwigDirector_Manager uintptr
-type SwigDirector_Manager interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrSwigDirector_Manager) Swigcptr() uintptr {
- return uintptr(p)
-}
-
-type SwigcptrSwigDirector_Employee uintptr
-type SwigDirector_Employee interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrSwigDirector_Employee) Swigcptr() uintptr {
- return uintptr(p)
-}
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
diff --git a/Examples/go/funcptr/example.go b/Examples/go/funcptr/example.go
deleted file mode 100644
index b059bae8d..000000000
--- a/Examples/go/funcptr/example.go
+++ /dev/null
@@ -1,54 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-func Do_op(int, int, _swig_fnptr) int
-func _swig_getADD() _swig_fnptr
-var ADD _swig_fnptr = _swig_getADD()
-func _swig_getSUB() _swig_fnptr
-var SUB _swig_fnptr = _swig_getSUB()
-func _swig_getMUL() _swig_fnptr
-var MUL _swig_fnptr = _swig_getMUL()
-func _swig_wrap_funcvar_set(_swig_fnptr)
-
-func SetFuncvar(arg1 _swig_fnptr) {
- _swig_wrap_funcvar_set(arg1)
-}
-
-func GetFuncvar() _swig_fnptr
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
diff --git a/Examples/go/multimap/example.go b/Examples/go/multimap/example.go
deleted file mode 100644
index 59ed9eaad..000000000
--- a/Examples/go/multimap/example.go
+++ /dev/null
@@ -1,55 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-func Gcd(int, int) int
-func Gcdmain([]string) int
-func Count(string, byte) int
-func _swig_wrap_capitalize([]string)
-
-func Capitalize(arg1 []string) {
- _swig_wrap_capitalize(arg1)
-}
-
-func _swig_wrap_circle(float64, float64)
-
-func Circle(arg1 float64, arg2 float64) {
- _swig_wrap_circle(arg1, arg2)
-}
-
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
diff --git a/Examples/go/pointer/example.go b/Examples/go/pointer/example.go
deleted file mode 100644
index 567c41c32..000000000
--- a/Examples/go/pointer/example.go
+++ /dev/null
@@ -1,68 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-func _swig_wrap_add(*int, *int, *int)
-
-func Add(arg1 *int, arg2 *int, arg3 *int) {
- _swig_wrap_add(arg1, arg2, arg3)
-}
-
-func New_intp() *int
-func Copy_intp(int) *int
-func _swig_wrap_delete_intp(*int)
-
-func Delete_intp(arg1 *int) {
- _swig_wrap_delete_intp(arg1)
-}
-
-func _swig_wrap_intp_assign(*int, int)
-
-func Intp_assign(arg1 *int, arg2 int) {
- _swig_wrap_intp_assign(arg1, arg2)
-}
-
-func Intp_value(*int) int
-func _swig_wrap_sub(int, int, []int)
-
-func Sub(arg1 int, arg2 int, arg3 []int) {
- _swig_wrap_sub(arg1, arg2, arg3)
-}
-
-func Divide(int, int, []int) int
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
diff --git a/Examples/go/reference/example.go b/Examples/go/reference/example.go
deleted file mode 100644
index fb98f8a18..000000000
--- a/Examples/go/reference/example.go
+++ /dev/null
@@ -1,126 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-type SwigcptrVector uintptr
-
-func (p SwigcptrVector) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrVector) SwigIsVector() {
-}
-
-func _swig_wrap_new_Vector(float64, float64, float64) SwigcptrVector
-
-func NewVector(arg1 float64, arg2 float64, arg3 float64) Vector {
- return _swig_wrap_new_Vector(arg1, arg2, arg3)
-}
-
-func _swig_wrap_delete_Vector(uintptr)
-
-func DeleteVector(arg1 Vector) {
- _swig_wrap_delete_Vector(arg1.Swigcptr())
-}
-
-func _swig_wrap_Vector_print(SwigcptrVector) string
-
-func (arg1 SwigcptrVector) Print() string {
- return _swig_wrap_Vector_print(arg1)
-}
-
-type Vector interface {
- Swigcptr() uintptr
- SwigIsVector()
- Print() string
-}
-
-func _swig_wrap_addv(uintptr, uintptr) SwigcptrVector
-
-func Addv(arg1 Vector, arg2 Vector) Vector {
- return _swig_wrap_addv(arg1.Swigcptr(), arg2.Swigcptr())
-}
-
-type SwigcptrVectorArray uintptr
-
-func (p SwigcptrVectorArray) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrVectorArray) SwigIsVectorArray() {
-}
-
-func _swig_wrap_new_VectorArray(int) SwigcptrVectorArray
-
-func NewVectorArray(arg1 int) VectorArray {
- return _swig_wrap_new_VectorArray(arg1)
-}
-
-func _swig_wrap_delete_VectorArray(uintptr)
-
-func DeleteVectorArray(arg1 VectorArray) {
- _swig_wrap_delete_VectorArray(arg1.Swigcptr())
-}
-
-func _swig_wrap_VectorArray_size(SwigcptrVectorArray) int
-
-func (arg1 SwigcptrVectorArray) Size() int {
- return _swig_wrap_VectorArray_size(arg1)
-}
-
-func _swig_wrap_VectorArray_get(SwigcptrVectorArray, int) SwigcptrVector
-
-func (arg1 SwigcptrVectorArray) Get(arg2 int) Vector {
- return _swig_wrap_VectorArray_get(arg1, arg2)
-}
-
-func _swig_wrap_VectorArray_set(SwigcptrVectorArray, int, uintptr)
-
-func (arg1 SwigcptrVectorArray) Set(arg2 int, arg3 Vector) {
- _swig_wrap_VectorArray_set(arg1, arg2, arg3.Swigcptr())
-}
-
-type VectorArray interface {
- Swigcptr() uintptr
- SwigIsVectorArray()
- Size() int
- Get(arg2 int) Vector
- Set(arg2 int, arg3 Vector)
-}
-
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
diff --git a/Examples/go/simple/example.go b/Examples/go/simple/example.go
deleted file mode 100644
index df0e70564..000000000
--- a/Examples/go/simple/example.go
+++ /dev/null
@@ -1,48 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-func Gcd(int, int) int
-func _swig_wrap_Foo_set(float64)
-
-func SetFoo(arg1 float64) {
- _swig_wrap_Foo_set(arg1)
-}
-
-func GetFoo() float64
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
diff --git a/Examples/go/template/example.go b/Examples/go/template/example.go
deleted file mode 100644
index 671b5c2ba..000000000
--- a/Examples/go/template/example.go
+++ /dev/null
@@ -1,150 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-func Maxint(int, int) int
-func Maxdouble(float64, float64) float64
-type SwigcptrVecint uintptr
-
-func (p SwigcptrVecint) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrVecint) SwigIsVecint() {
-}
-
-func _swig_wrap_new_vecint(int) SwigcptrVecint
-
-func NewVecint(arg1 int) Vecint {
- return _swig_wrap_new_vecint(arg1)
-}
-
-func _swig_wrap_vecint_get(SwigcptrVecint, int) *int
-
-func (arg1 SwigcptrVecint) Get(arg2 int) *int {
- return _swig_wrap_vecint_get(arg1, arg2)
-}
-
-func _swig_wrap_vecint_set(SwigcptrVecint, int, *int)
-
-func (arg1 SwigcptrVecint) Set(arg2 int, arg3 *int) {
- _swig_wrap_vecint_set(arg1, arg2, arg3)
-}
-
-func _swig_wrap_vecint_getitem(SwigcptrVecint, int) int
-
-func (arg1 SwigcptrVecint) Getitem(arg2 int) int {
- return _swig_wrap_vecint_getitem(arg1, arg2)
-}
-
-func _swig_wrap_vecint_setitem(SwigcptrVecint, int, int)
-
-func (arg1 SwigcptrVecint) Setitem(arg2 int, arg3 int) {
- _swig_wrap_vecint_setitem(arg1, arg2, arg3)
-}
-
-func _swig_wrap_delete_vecint(uintptr)
-
-func DeleteVecint(arg1 Vecint) {
- _swig_wrap_delete_vecint(arg1.Swigcptr())
-}
-
-type Vecint interface {
- Swigcptr() uintptr
- SwigIsVecint()
- Get(arg2 int) *int
- Set(arg2 int, arg3 *int)
- Getitem(arg2 int) int
- Setitem(arg2 int, arg3 int)
-}
-
-type SwigcptrVecdouble uintptr
-
-func (p SwigcptrVecdouble) Swigcptr() uintptr {
- return (uintptr)(p)
-}
-
-func (p SwigcptrVecdouble) SwigIsVecdouble() {
-}
-
-func _swig_wrap_new_vecdouble(int) SwigcptrVecdouble
-
-func NewVecdouble(arg1 int) Vecdouble {
- return _swig_wrap_new_vecdouble(arg1)
-}
-
-func _swig_wrap_vecdouble_get(SwigcptrVecdouble, int) *float64
-
-func (arg1 SwigcptrVecdouble) Get(arg2 int) *float64 {
- return _swig_wrap_vecdouble_get(arg1, arg2)
-}
-
-func _swig_wrap_vecdouble_set(SwigcptrVecdouble, int, *float64)
-
-func (arg1 SwigcptrVecdouble) Set(arg2 int, arg3 *float64) {
- _swig_wrap_vecdouble_set(arg1, arg2, arg3)
-}
-
-func _swig_wrap_vecdouble_getitem(SwigcptrVecdouble, int) float64
-
-func (arg1 SwigcptrVecdouble) Getitem(arg2 int) float64 {
- return _swig_wrap_vecdouble_getitem(arg1, arg2)
-}
-
-func _swig_wrap_vecdouble_setitem(SwigcptrVecdouble, int, float64)
-
-func (arg1 SwigcptrVecdouble) Setitem(arg2 int, arg3 float64) {
- _swig_wrap_vecdouble_setitem(arg1, arg2, arg3)
-}
-
-func _swig_wrap_delete_vecdouble(uintptr)
-
-func DeleteVecdouble(arg1 Vecdouble) {
- _swig_wrap_delete_vecdouble(arg1.Swigcptr())
-}
-
-type Vecdouble interface {
- Swigcptr() uintptr
- SwigIsVecdouble()
- Get(arg2 int) *float64
- Set(arg2 int, arg3 *float64)
- Getitem(arg2 int) float64
- Setitem(arg2 int, arg3 float64)
-}
-
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
diff --git a/Examples/go/variables/example.go b/Examples/go/variables/example.go
deleted file mode 100644
index f4f299b73..000000000
--- a/Examples/go/variables/example.go
+++ /dev/null
@@ -1,198 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 2.0.1
- *
- * This file is not intended to be easily readable and contains a number of
- * coding conventions designed to improve portability and efficiency. Do not make
- * changes to this file unless you know what you are doing--modify the SWIG
- * interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package example
-
-
-type _swig_fnptr *byte
-type _swig_memberptr *byte
-
-
-func _swig_allocatememory(int) *byte
-func _swig_internal_allocate(len int) *byte {
- return _swig_allocatememory(len)
-}
-
-func _swig_allocatestring(*byte, int) string
-func _swig_internal_makegostring(p *byte, l int) string {
- return _swig_allocatestring(p, l)
-}
-
-func _swig_internal_gopanic(p *byte, l int) {
- panic(_swig_allocatestring(p, l))
-}
-
-func _swig_wrap_ivar_set(int)
-
-func SetIvar(arg1 int) {
- _swig_wrap_ivar_set(arg1)
-}
-
-func GetIvar() int
-func _swig_wrap_svar_set(int16)
-
-func SetSvar(arg1 int16) {
- _swig_wrap_svar_set(arg1)
-}
-
-func GetSvar() int16
-func _swig_wrap_lvar_set(int32)
-
-func SetLvar(arg1 int32) {
- _swig_wrap_lvar_set(arg1)
-}
-
-func GetLvar() int32
-func _swig_wrap_uivar_set(uint)
-
-func SetUivar(arg1 uint) {
- _swig_wrap_uivar_set(arg1)
-}
-
-func GetUivar() uint
-func _swig_wrap_usvar_set(uint16)
-
-func SetUsvar(arg1 uint16) {
- _swig_wrap_usvar_set(arg1)
-}
-
-func GetUsvar() uint16
-func _swig_wrap_ulvar_set(uint32)
-
-func SetUlvar(arg1 uint32) {
- _swig_wrap_ulvar_set(arg1)
-}
-
-func GetUlvar() uint32
-func _swig_wrap_scvar_set(int8)
-
-func SetScvar(arg1 int8) {
- _swig_wrap_scvar_set(arg1)
-}
-
-func GetScvar() int8
-func _swig_wrap_ucvar_set(byte)
-
-func SetUcvar(arg1 byte) {
- _swig_wrap_ucvar_set(arg1)
-}
-
-func GetUcvar() byte
-func _swig_wrap_cvar_set(byte)
-
-func SetCvar(arg1 byte) {
- _swig_wrap_cvar_set(arg1)
-}
-
-func GetCvar() byte
-func _swig_wrap_fvar_set(float32)
-
-func SetFvar(arg1 float32) {
- _swig_wrap_fvar_set(arg1)
-}
-
-func GetFvar() float32
-func _swig_wrap_dvar_set(float64)
-
-func SetDvar(arg1 float64) {
- _swig_wrap_dvar_set(arg1)
-}
-
-func GetDvar() float64
-func _swig_wrap_strvar_set(string)
-
-func SetStrvar(arg1 string) {
- _swig_wrap_strvar_set(arg1)
-}
-
-func GetStrvar() string
-func GetCstrvar() string
-func _swig_wrap_iptrvar_set(*int)
-
-func SetIptrvar(arg1 *int) {
- _swig_wrap_iptrvar_set(arg1)
-}
-
-func GetIptrvar() *int
-func _swig_wrap_name_set(string)
-
-func SetName(arg1 string) {
- _swig_wrap_name_set(arg1)
-}
-
-func GetName() string
-func _swig_wrap_ptptr_set(uintptr)
-
-func SetPtptr(arg1 Point) {
- _swig_wrap_ptptr_set(arg1.Swigcptr())
-}
-
-func _swig_wrap_ptptr_get() SwigcptrPoint
-
-func GetPtptr() Point {
- return _swig_wrap_ptptr_get()
-}
-
-func _swig_wrap_pt_set(uintptr)
-
-func SetPt(arg1 Point) {
- _swig_wrap_pt_set(arg1.Swigcptr())
-}
-
-func _swig_wrap_pt_get() SwigcptrPoint
-
-func GetPt() Point {
- return _swig_wrap_pt_get()
-}
-
-func GetStatus() int
-func GetPath() string
-func _swig_wrap_print_vars()
-
-func Print_vars() {
- _swig_wrap_print_vars()
-}
-
-func New_int(int) *int
-func _swig_wrap_new_Point(int, int) SwigcptrPoint
-
-func New_Point(arg1 int, arg2 int) Point {
- return _swig_wrap_new_Point(arg1, arg2)
-}
-
-func _swig_wrap_Point_print(uintptr) string
-
-func Point_print(arg1 Point) string {
- return _swig_wrap_Point_print(arg1.Swigcptr())
-}
-
-func _swig_wrap_pt_print()
-
-func Pt_print() {
- _swig_wrap_pt_print()
-}
-
-
-type SwigcptrPoint uintptr
-type Point interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrPoint) Swigcptr() uintptr {
- return uintptr(p)
-}
-
-type SwigcptrVoid uintptr
-type Void interface {
- Swigcptr() uintptr;
-}
-func (p SwigcptrVoid) Swigcptr() uintptr {
- return uintptr(p)
-}
-
From d7cc6904c5ea372380e5523cbd540e6f300e4d16 Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Fri, 26 Nov 2010 23:23:26 +0000
Subject: [PATCH 025/317] [D] Document "-d2" switch, native pointer support and
D_VERSION=2.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12317 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Doc/Manual/D.html | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html
index a232f236b..4b52f68d0 100644
--- a/Doc/Manual/D.html
+++ b/Doc/Manual/D.html
@@ -27,6 +27,10 @@
D Exceptions
D Directors
Other features
+
D Typemap examples
Work in progress and planned features
@@ -53,6 +57,11 @@
To activate the D module, pass the -d option to SWIG at the command line. The same standard command line switches as with any other language module are available, plus the following D specific ones:
+ -d2
+
+ By default, SWIG generates code for D1/Tango. Use the -d2 flag to target D2/Phobos instead.
+
+
-splitproxy
By default, SWIG generates two D modules: the proxy module, named like the source module (either specified via the %module directive or via the module command line switch), which contains all the proxy classes, functions, enums, etc., and the wrap module (named like the proxy module, but suffixed with _wrap ), which contains all the extern(C) function declarations and other private parts only used internally by the proxy module.
@@ -78,6 +87,8 @@
20.3.1 C# <-> D name comparison
+If you already know the SWIG C# module, you might find the following name comparison table useful:
+
ctype <-> cwtype
imtype <-> dwtype
@@ -367,7 +378,25 @@ struct A {
The nspace feature of SWIG is not yet supported for D – all class modules are written to the same package, regardless of which C++ namespace they are in.
-Support of pointers to primitive types.
+
+ 20.8.1 Native pointer support
+
+
+Contrary to many of the scripting languages supported by SWIG, D fully supports C-style pointers. The D module thus includes a custom mechanism to wrap C pointers directly as D pointers where applicable, that is, if the type that is pointed to is represented the same in C and D (on the bit-level), dubbed a »primtive type« below.
+
+Central to this custom pointer handling scheme are two typemap attributes: the cprimitive attribute on the dptype typemap and the nativepointer attribute on all the typemaps which influence the D side of the code (dptype , din , dout , …). When a D typemap is looked up, the following happens behind the scenes:
+
+First, the matching typemap is determined by the usual typemap lookup rules. Then, it is checked if the result has the nativepointer attribute set. If it is present, it means that its value should replace the typemap value if and only if the actual type the typemap is looked up for is a primitive type, a pointer to a primitive type (through an arbitrary level of indirections), or a function pointer with only primitive types in its signature.
+
+To determine if a type should be considered primitive, the cprimitive attribute on its dptype attribute is used. For example, the dptype typemap for float has cprimitive="1" , so the code from the nativepointer attribute is taken into account e.g. for float ** or the function pointer float (*)(float *) .
+
+
+ 20.8.2 Running the test-suite
+
+
+As with any other language, the SWIG test-suite can be built for D using the *-d-test-suite targets of the top-level Makefile. By default, D1 is targeted, to build it with D2, use the optional D_VERSION variable, e.g. make check-d-test-suite D_VERSION=2 .
+
+Note: If you want to use GDC on Linux or another platform which requires you to link libdl for dynamically loading the shared library, you might have to add -ldl manually to the d_compile target in Examples/Makefile , because GDC does not currently honor the pragma(lib,…) statement.
20.9 D Typemap examples
From a22df2eca9d1726fa7af02cebc459eb373ed7fc7 Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Sat, 27 Nov 2010 00:13:44 +0000
Subject: [PATCH 026/317] [D] Refer to the built-in Exception class using its
fully-qualified name.
A C++ class called "Exception" could shadow the built-in one before, leading to compilation errors in the exception handling code.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12318 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/test-suite/d/Makefile.in | 1 +
Examples/test-suite/d_exception_name.i | 15 +++++++++++++++
Lib/d/dhead.swg | 24 ++++++++++++------------
Source/Modules/d.cxx | 2 +-
4 files changed, 29 insertions(+), 13 deletions(-)
create mode 100644 Examples/test-suite/d_exception_name.i
diff --git a/Examples/test-suite/d/Makefile.in b/Examples/test-suite/d/Makefile.in
index 2e9eb827f..ec13fede3 100644
--- a/Examples/test-suite/d/Makefile.in
+++ b/Examples/test-suite/d/Makefile.in
@@ -16,6 +16,7 @@ endif
TESTSUFFIX = _runme$(VERSIONSUFFIX).d
CPP_TEST_CASES = \
+ d_exception_name \
d_nativepointers \
exception_partial_info
diff --git a/Examples/test-suite/d_exception_name.i b/Examples/test-suite/d_exception_name.i
new file mode 100644
index 000000000..23f338a73
--- /dev/null
+++ b/Examples/test-suite/d_exception_name.i
@@ -0,0 +1,15 @@
+// Tests if exception handling still works in the presence of a wrapped C++
+// class called »Exception«, which could shadow the built-in Exception class.
+%module d_exception_name
+
+%inline %{
+ class Exception {
+ Exception(int i) {}
+ };
+
+ class Foo {
+ ~Foo() {}
+ public:
+ void bar(Exception *e) {}
+ };
+%}
diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg
index e4dca36e8..cb2b41079 100644
--- a/Lib/d/dhead.swg
+++ b/Lib/d/dhead.swg
@@ -84,7 +84,7 @@ private class SwigExceptionHelper {
}
static void setException(char* message) {
- auto exception = new Exception(tango.stdc.stringz.fromStringz(message).dup);
+ auto exception = new object.Exception(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
@@ -131,9 +131,9 @@ public:
return pending;
}
- static void set(Exception e) {
+ static void set(object.Exception e) {
if (m_sPendingException.val !is null) {
- throw new Exception("FATAL: An earlier pending exception from C/C++ code " ~
+ throw new object.Exception("FATAL: An earlier pending exception from C/C++ code " ~
"was missed and thus not thrown (" ~ m_sPendingException.val.classinfo.name ~
": " ~ m_sPendingException.val.msg ~ ")!", e);
}
@@ -144,8 +144,8 @@ public:
}
}
- static Exception retrieve() {
- Exception e = null;
+ static object.Exception retrieve() {
+ object.Exception e = null;
if (m_sPendingCount > 0) {
if (m_sPendingException.val !is null) {
e = m_sPendingException.val;
@@ -163,7 +163,7 @@ private:
static int m_sPendingCount;
// The reference to the pending exception (if any) is stored thread-local.
- alias tango.core.Thread.ThreadLocal!(Exception) ThreadLocalData;
+ alias tango.core.Thread.ThreadLocal!(object.Exception) ThreadLocalData;
static ThreadLocalData m_sPendingException;
}
alias void function(char* message) SwigExceptionCallback;
@@ -187,7 +187,7 @@ private class SwigExceptionHelper {
}
static void setException(char* message) {
- auto exception = new Exception(std.conv.to!string(message).idup);
+ auto exception = new object.Exception(std.conv.to!string(message).idup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
@@ -210,9 +210,9 @@ public:
return pending;
}
- static void set(Exception e) {
+ static void set(object.Exception e) {
if (m_sPendingException !is null) {
- throw new Exception("FATAL: An earlier pending exception from C/C++ code " ~
+ throw new object.Exception("FATAL: An earlier pending exception from C/C++ code " ~
"was missed and thus not thrown (" ~ m_sPendingException.classinfo.name ~
": " ~ m_sPendingException.msg ~ ")!", e);
}
@@ -223,8 +223,8 @@ public:
}
}
- static Exception retrieve() {
- Exception e = null;
+ static object.Exception retrieve() {
+ object.Exception e = null;
if (m_sPendingCount > 0) {
if (m_sPendingException !is null) {
e = m_sPendingException;
@@ -242,7 +242,7 @@ private:
static shared int m_sPendingCount;
// The reference to the pending exception (if any) is stored thread-local.
- static Exception m_sPendingException;
+ static object.Exception m_sPendingException;
}
alias void function(const char* message) SwigExceptionCallback;
%}
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
index ce33b5252..c726ac022 100644
--- a/Source/Modules/d.cxx
+++ b/Source/Modules/d.cxx
@@ -3216,7 +3216,7 @@ private:
if (*Char(destructor_call)) {
Replaceall(dispose_code, "$wcall", destructor_call);
} else {
- Replaceall(dispose_code, "$wcall", "throw new Exception(\"C++ destructor does not have public access\")");
+ Replaceall(dispose_code, "$wcall", "throw new object.Exception(\"C++ destructor does not have public access\")");
}
if (*Char(dispose_code)) {
From 3477a9dff13227605d51433df50935b87f5f73af Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Sun, 28 Nov 2010 23:12:03 +0000
Subject: [PATCH 027/317] [D] Replaced the term "wrap D module" with
"intermediary D module" (including names derived from it).
This was suggested by wsfulton on the mailing list in order to bring the D module in line with the C# one, the naming scheme of which is intended to be language-independent.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12319 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Doc/Manual/D.html | 72 +--
Examples/test-suite/dynamic_cast.i | 2 +-
Examples/test-suite/special_variable_macros.i | 4 +-
Examples/test-suite/typemap_namespace.i | 6 +-
Lib/d/boost_shared_ptr.i | 44 +-
Lib/d/dclassgen.swg | 8 +-
Lib/d/denums.swg | 20 +-
Lib/d/dexception.swg | 2 +-
Lib/d/dhead.swg | 16 +-
Lib/d/dmemberfunctionpointers.swg | 10 +-
Lib/d/dprimitives.swg | 18 +-
Lib/d/dstrings.swg | 12 +-
Lib/d/dswigtype.swg | 52 +--
Lib/d/dvoid.swg | 10 +-
Lib/d/std_string.i | 10 +-
Lib/d/std_vector.i | 96 ++--
Lib/d/typemaps.i | 40 +-
Source/Include/swigwarn.h | 6 +-
Source/Modules/d.cxx | 419 +++++++++---------
19 files changed, 423 insertions(+), 424 deletions(-)
diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html
index 4b52f68d0..959a4f48f 100644
--- a/Doc/Manual/D.html
+++ b/Doc/Manual/D.html
@@ -15,7 +15,7 @@
Typemaps
C# <-> D name comparison
-cwtype, dwtype, dptype
+ctype, imtype, dtype
in, out, directorin, directorout
din, dout, ddirectorin, ddirectorout
typecheck typemaps
@@ -64,18 +64,18 @@
-splitproxy
- By default, SWIG generates two D modules: the proxy module, named like the source module (either specified via the %module directive or via the module command line switch), which contains all the proxy classes, functions, enums, etc., and the wrap module (named like the proxy module, but suffixed with _wrap ), which contains all the extern(C) function declarations and other private parts only used internally by the proxy module.
+ By default, SWIG generates two D modules: the proxy module, named like the source module (either specified via the %module directive or via the module command line switch), which contains all the proxy classes, functions, enums, etc., and the intermediary module (named like the proxy module, but suffixed with _im ), which contains all the extern(C) function declarations and other private parts only used internally by the proxy module.
If the split proxy mode is enabled by passing this switch at the command line, all proxy classes and enums are emitted to their own D module instead. The main proxy module only contains free functions and constants in this case.
-package <pkg>
- By default, the proxy D modules and the wrap D module are written to the root package. Using this option, you can specify another target package instead.
+ By default, the proxy D modules and the intermediary D module are written to the root package. Using this option, you can specify another target package instead.
-wrapperlibrary <wl>
- The code SWIG generates to dynamically load the C/C++ wrapper layer looks for a library called $module_wrap , just like the wrap D module is. With this switch, you can override the name of the file the wrapper code loads at runtime (the lib prefix and the suffix for shared libraries are appended automatically, depending on the OS).
+ The code SWIG generates to dynamically load the C/C++ wrapper layer looks for a library called $module_wrap by default. With this switch, you can override the name of the file the wrapper code loads at runtime (the lib prefix and the suffix for shared libraries are appended automatically, depending on the OS).
This might especially be useful if you want to invoke SWIG several times on separate modules, but compile the resulting code into a single shared library.
@@ -90,9 +90,9 @@
If you already know the SWIG C# module, you might find the following name comparison table useful:
- ctype <-> cwtype
- imtype <-> dwtype
- cstype <-> dptype
+ ctype <-> ctype
+ imtype <-> imtype
+ cstype <-> dtype
csin <-> din
csout <-> dout
csdirectorin <-> ddirectorin
@@ -110,12 +110,12 @@
- 20.3.2 cwtype, dwtype, dptype
+ 20.3.2 ctype, imtype, dtype
Mapping of types between the C/C++ library, the C/C++ library wrapper exposing the C functions, the D wrapper module importing these functions and the D proxy code.
-The cwtype typemap is used to determine the types to use in the C wrapper functions. The types from the dwtype typemap are used in the extern(C) declarations of these functions in the D wrap module. The dptype typemap contains the D types used in the D proxy module/class.
+The ctype typemap is used to determine the types to use in the C wrapper functions. The types from the imtype typemap are used in the extern(C) declarations of these functions in the intermediary D module. The dtype typemap contains the D types used in the D proxy module/class.
20.3.3 in, out, directorin, directorout
@@ -123,7 +123,7 @@
Used for converting between the types for C/C++ and D when generating the code for the wrapper functions (on the C++ side).
-The code from the in typemap is used to convert arguments to the C wrapper function to the type used in the wrapped code (cwtype ->original C++ type), the out typemap is utilized to convert values from the wrapped code to wrapper function return types (original C++ type->cwtype ).
+The code from the in typemap is used to convert arguments to the C wrapper function to the type used in the wrapped code (ctype ->original C++ type), the out typemap is utilized to convert values from the wrapped code to wrapper function return types (original C++ type->ctype ).
The directorin typemap is used to convert parameters to the type used in the D director callback function, its return value is processed by directorout (see below).
@@ -133,11 +133,11 @@
Typemaps for code generation in D proxy and type wrapper classes.
-The din typemap is used for converting function parameter types from the type used in the proxy module or class to the type used in the D wrap module (the $dinput macro is replaced).
+The din typemap is used for converting function parameter types from the type used in the proxy module or class to the type used in the intermediary D module (the $dinput macro is replaced).
-The dout typemap is used for converting function return values from the return type used in the wrap D module to the type returned by the proxy function. The $excode special variable in dout typemaps is replaced by the excode typemap attribute code if the method can throw any exceptions from unmanaged code, otherwise by nothing (the $wcall and $owner macros are replaced).
+The dout typemap is used for converting function return values from the return type used in the intermediary D module to the type returned by the proxy function. The $excode special variable in dout typemaps is replaced by the excode typemap attribute code if the method can throw any exceptions from unmanaged code, otherwise by nothing (the $imcall and $owner macros are replaced).
-The code from the ddirectorin and ddirectorout typemaps is used for conversion in director callback functions. Arguments are converted to the type used in the proxy class method they are calling by using the code from ddirectorin , the proxy class method return value is converted to the type the C++ code expects via the ddirectorout typemap (the $dpcall and $winput macros are replaced).
+The code from the ddirectorin and ddirectorout typemaps is used for conversion in director callback functions. Arguments are converted to the type used in the proxy class method they are calling by using the code from ddirectorin , the proxy class method return value is converted to the type the C++ code expects via the ddirectorout typemap (the $dcall and $winput macros are replaced).
The full chain of type conversions when a director callback is invoked looks like this:
@@ -145,13 +145,13 @@
↑ ↓
<directorout> <directorin>
↑ ↓
- cwtype methodCallback(cwtype a) C++
+ ctype methodCallback(ctype a) C++
::::::::::::::::::::::::::::::::::::::::::
- dwtype methodCallback(dwtype a) D
+ imtype methodCallback(imtype a) D
↑ ↓
<ddirectorout> <ddirectorin>
↑ ↓
- dptype DClass.method(dptype a)
+ dtype DClass.method(dtype a)
20.3.5 typecheck typemaps
@@ -202,16 +202,16 @@
leads to the following D proxy code being generated:
void foo(SomeClass arg) {
- example_wrap.foo(SomeClass.getCPointer(arg));
+ example_im.foo(SomeClass.getCPointer(arg));
}
- $wcall and $owner (C#: $imcall )
+ $imcall and $owner (C#: $imcall )
- These variables are used in dout typemaps. $wcall contains the call to the wrapper layer which provides the value to be used, and $owner signals if the caller is responsible for managing the object lifetime (that is, if the called method is a constructor or has been marked via %newobject ).
+ These variables are used in dout typemaps. $imcall contains the call to the intermediary module which provides the value to be used, and $owner signals if the caller is responsible for managing the object lifetime (that is, if the called method is a constructor or has been marked via %newobject ).
Consider the following example:
%typemap(dout) SomeClass * {
- return new SomeClass($wcall, $owner);
+ return new SomeClass($imcall, $owner);
}
%inline %{
@@ -224,17 +224,17 @@ void foo(SomeClass arg) {
The code generated for foo() and bar() looks like this:
SomeClass foo() {
- return new SomeClass(example_wrap.foo(), false);
+ return new SomeClass(example_im.foo(), false);
}
SomeClass bar() {
- return new SomeClass(example_wrap.bar(), true);
+ return new SomeClass(example_im.bar(), true);
}
- $dpcall and $winput (C#: $cscall , $iminput )
-
These variables are used in the director-specific typemaps ddirectorin and ddirectorout . They are more or less the reverse of the $wcall and $dinput macros: $dpcall contains the invocation of the D proxy method of which the return value is to be passed back to C++, $winput contains the parameter value from C++.
+
$dcall and $winput (C#: $cscall , $iminput )
+
These variables are used in the director-specific typemaps ddirectorin and ddirectorout . They are more or less the reverse of the $imcall and $dinput macros: $dcall contains the invocation of the D proxy method of which the return value is to be passed back to C++, $winput contains the parameter value from C++.
$excode
This variable is used in dout and dconstructor typemaps and is filled with the contents of the excode typemap attribute if an exception could be thrown from the C++ side. See the C# documentation for details.
@@ -248,7 +248,7 @@ SomeClass bar() {
This is how the default dconstructor typemap looks like (you usually do not want to specify a custom one):
%typemap(dconstructor, excode=SWIGEXCODE,directorconnect="\n swigDirectorConnect();") SWIGTYPE {
- this($wcall, true);$excode$directorconnect
+ this($imcall, true);$excode$directorconnect
}
@@ -280,8 +280,8 @@ $importtype(AnotherInterface)
$module
Expands to the name of the main proxy D module.
-
$wrapdmodule
-
Contains the fully qualified name of the wrap D module.
+
$imdmodule
+
Contains the fully qualified name of the intermediary D module.
@@ -295,7 +295,7 @@ $importtype(AnotherInterface)
%dmanifestconst and %dconstvalue(value)
Out of the box, SWIG generates accessor methods for C #defines and C++ constants. The %dmanifestconst directive enables wrapping these constants as D manifest constants (const in D1, enum in D2).
- For this to work, the C/C++ code for the constant value must directly compile as D code, though. If this is not the case, you can manually override the expression written to the D wrapper using the %dconstvalue directive, passing the new value as parameter.
+ For this to work, the C/C++ code for the constant value must directly compile as D code, though. If this is not the case, you can manually override the expression written to the D proxy module using the %dconstvalue directive, passing the new value as parameter.
For enum s, again %dconstvalue can be used to override the value of an enum item if the initializer should not compile in D.
@@ -321,11 +321,11 @@ struct A {
There are a few SWIG pragmas specific to the D module, which you can use to influence the D code SWIG generates:
- %pragma(d) wrapdmodulecode
- The passed text (D code) is copied verbatim to the wrap D module. For example, it can be (and is, internally) used to emit additional private helper code for the use by proxy typemaps.
+ %pragma(d) imdmodulecode
+ The passed text (D code) is copied verbatim to the intermediary D module. For example, it can be (and is, internally) used to emit additional private helper code for the use by proxy typemaps.
- %pragma(d) wrapdmoduleimports
- Additional code to be emitted to the imports section of the wrap D module (the $importtype macro can be used here). You probably want to use this in conjunction with the wrapdmodulecode pragma.
+ %pragma(d) imdmoduleimports
+ Additional code to be emitted to the imports section of the intermediary D module (the $importtype macro can be used here). You probably want to use this in conjunction with the imdmodulecode pragma.
%pragma(d) proxydmodulecode
Just like proxydmodulecode , the argument is copied to the proxy D module (if SWIG is in split proxy mode , it is emitted to the main proxy D module only).
@@ -342,13 +342,13 @@ struct A {
%pragma(d) wrapperloadercode
- The D code for loading the wrapper library (it is copied to the wrap D module). The $wrapperloaderbindcode variable is replaced by the list of commands for binding the functions from the wrapper library to the symbols in the wrap D module.
+ The D code for loading the wrapper library (it is copied to the intermediary D module). The $wrapperloaderbindcode variable is replaced by the list of commands for binding the functions from the wrapper library to the symbols in the intermediary D module.
Each time this pragma is specified, the previous value is overwritten.
%pragma(d) wrapperloaderbindcommand
- The D command to use for binding the wrapper functions from the C/C++ library to the symbols in the wrap D module. The $function variable contains the name of the D function in the wrap module, the $symbol variable is replaced by the name of the symbol in the library.
+ The D command to use for binding the wrapper functions from the C/C++ library to the symbols in the intermediary D module. The $function variable contains the name of the D function in the wrap module, the $symbol variable is replaced by the name of the symbol in the library.
Each time this pragma is specified, the previous value is overwritten.
@@ -384,11 +384,11 @@ struct A {
Contrary to many of the scripting languages supported by SWIG, D fully supports C-style pointers. The D module thus includes a custom mechanism to wrap C pointers directly as D pointers where applicable, that is, if the type that is pointed to is represented the same in C and D (on the bit-level), dubbed a »primtive type« below.
-
Central to this custom pointer handling scheme are two typemap attributes: the cprimitive attribute on the dptype typemap and the nativepointer attribute on all the typemaps which influence the D side of the code (dptype , din , dout , …). When a D typemap is looked up, the following happens behind the scenes:
+
Central to this custom pointer handling scheme are two typemap attributes: the cprimitive attribute on the dtype typemap and the nativepointer attribute on all the typemaps which influence the D side of the code (dtype , din , dout , …). When a D typemap is looked up, the following happens behind the scenes:
First, the matching typemap is determined by the usual typemap lookup rules. Then, it is checked if the result has the nativepointer attribute set. If it is present, it means that its value should replace the typemap value if and only if the actual type the typemap is looked up for is a primitive type, a pointer to a primitive type (through an arbitrary level of indirections), or a function pointer with only primitive types in its signature.
-
To determine if a type should be considered primitive, the cprimitive attribute on its dptype attribute is used. For example, the dptype typemap for float has cprimitive="1" , so the code from the nativepointer attribute is taken into account e.g. for float ** or the function pointer float (*)(float *) .
+
To determine if a type should be considered primitive, the cprimitive attribute on its dtype attribute is used. For example, the dtype typemap for float has cprimitive="1" , so the code from the nativepointer attribute is taken into account e.g. for float ** or the function pointer float (*)(float *) .
20.8.2 Running the test-suite
diff --git a/Examples/test-suite/dynamic_cast.i b/Examples/test-suite/dynamic_cast.i
index 17850985a..392b3bfd1 100644
--- a/Examples/test-suite/dynamic_cast.i
+++ b/Examples/test-suite/dynamic_cast.i
@@ -39,7 +39,7 @@ public:
#if defined(SWIGD)
%typemap(dout, excode=SWIGEXCODE) Foo * {
- Bar ret = new Bar($wcall, $owner);$excode
+ Bar ret = new Bar($imcall, $owner);$excode
return ret;
}
#endif
diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i
index 45eab0507..1ad673b41 100644
--- a/Examples/test-suite/special_variable_macros.i
+++ b/Examples/test-suite/special_variable_macros.i
@@ -169,13 +169,13 @@ namespace Space {
#if (SWIG_D_VERSION == 1)
%typemap(dcode) Space::RenameMe %{
public static NewName factory(char[] s) {
- return new $typemap(dptype, Space::RenameMe)( new $typemap(dptype, Name)(s) );
+ return new $typemap(dtype, Space::RenameMe)( new $typemap(dtype, Name)(s) );
}
%}
#else
%typemap(dcode) Space::RenameMe %{
public static NewName factory(string s) {
- return new $typemap(dptype, Space::RenameMe)( new $typemap(dptype, Name)(s) );
+ return new $typemap(dtype, Space::RenameMe)( new $typemap(dtype, Name)(s) );
}
%}
#endif
diff --git a/Examples/test-suite/typemap_namespace.i b/Examples/test-suite/typemap_namespace.i
index 5a198b554..1fd7ce718 100644
--- a/Examples/test-suite/typemap_namespace.i
+++ b/Examples/test-suite/typemap_namespace.i
@@ -30,9 +30,9 @@ namespace Foo {
%typemap(gotype) Str1 * = char *;
#endif
#ifdef SWIGD
- %typemap(cwtype) Str1 * = char *;
- %typemap(dwtype) Str1 * = char *;
- %typemap(dptype) Str1 * = char *;
+ %typemap(ctype) Str1 * = char *;
+ %typemap(imtype) Str1 * = char *;
+ %typemap(dtype) Str1 * = char *;
%typemap(din) Str1 * = char *;
%typemap(dout) Str1 * = char *;
#endif
diff --git a/Lib/d/boost_shared_ptr.i b/Lib/d/boost_shared_ptr.i
index 97feee5cb..37ce26d00 100644
--- a/Lib/d/boost_shared_ptr.i
+++ b/Lib/d/boost_shared_ptr.i
@@ -82,62 +82,62 @@
%}
-%typemap (cwtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+%typemap (ctype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "void *"
-%typemap (dwtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+%typemap (imtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "void*"
-%typemap (dptype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
+%typemap (dtype) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
- SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(dptype, TYPE)"
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(dtype, TYPE)"
%typemap(din) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > &,
SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *,
- SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(dptype, TYPE).swigGetCPtr($dinput)"
+ SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& "$typemap(dtype, TYPE).swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > {
- void* cPtr = $wcall;
- auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ void* cPtr = $imcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > & {
- void* cPtr = $wcall;
- auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ void* cPtr = $imcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > * {
- void* cPtr = $wcall;
- auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ void* cPtr = $imcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *& {
- void* cPtr = $wcall;
- auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ void* cPtr = $imcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) CONST TYPE {
- auto ret = new $typemap(dptype, TYPE)($wcall, true);$excode
+ auto ret = new $typemap(dtype, TYPE)($imcall, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) CONST TYPE & {
- auto ret = new $typemap(dptype, TYPE)($wcall, true);$excode
+ auto ret = new $typemap(dtype, TYPE)($imcall, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) CONST TYPE * {
- void* cPtr = $wcall;
- auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ void* cPtr = $imcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
%typemap(dout, excode=SWIGEXCODE) TYPE *CONST& {
- void* cPtr = $wcall;
- auto ret = (cPtr is null) ? null : new $typemap(dptype, TYPE)(cPtr, true);$excode
+ void* cPtr = $imcall;
+ auto ret = (cPtr is null) ? null : new $typemap(dtype, TYPE)(cPtr, true);$excode
return ret;
}
@@ -162,7 +162,7 @@ private void* swigCPtr;
private bool swigCMemOwn;
public this(void* cObject, bool ownCObject) {
- super($wrapdmodule.$dclassnameSmartPtrUpcast(cObject), ownCObject);
+ super($imdmodule.$dclassnameSmartPtrUpcast(cObject), ownCObject);
swigCPtr = cObject;
swigCMemOwn = ownCObject;
}
@@ -177,7 +177,7 @@ public static void* swigGetCPtr($dclassname obj) {
if (swigCPtr !is null) {
if (swigCMemOwn) {
swigCMemOwn = false;
- $wcall;
+ $imcall;
}
swigCPtr = null;
}
@@ -189,7 +189,7 @@ public static void* swigGetCPtr($dclassname obj) {
if (swigCPtr !is null) {
if (swigCMemOwn) {
swigCMemOwn = false;
- $wcall;
+ $imcall;
}
swigCPtr = null;
super.dispose();
diff --git a/Lib/d/dclassgen.swg b/Lib/d/dclassgen.swg
index bc73d7b6a..8c08b9dc4 100644
--- a/Lib/d/dclassgen.swg
+++ b/Lib/d/dclassgen.swg
@@ -21,7 +21,7 @@
*/
%typemap(dconstructor, excode=SWIGEXCODE,directorconnect="\n swigDirectorConnect();") SWIGTYPE {
- this($wcall, true);$excode$directorconnect
+ this($imcall, true);$excode$directorconnect
}
%typemap(ddestructor) SWIGTYPE %{
@@ -38,7 +38,7 @@
if (swigCPtr !is null) {
if (swigCMemOwn) {
swigCMemOwn = false;
- $wcall;
+ $imcall;
}
swigCPtr = null;
}
@@ -50,7 +50,7 @@
if (swigCPtr !is null) {
if (swigCMemOwn) {
swigCMemOwn = false;
- $wcall;
+ $imcall;
}
swigCPtr = null;
super.dispose();
@@ -88,7 +88,7 @@ public static void* swigGetCPtr($dclassname obj) {
private void* swigCPtr;
public this(void* cObject, bool ownCObject) {
- super($wrapdmodule.$dclassnameUpcast(cObject), ownCObject);
+ super($imdmodule.$dclassnameUpcast(cObject), ownCObject);
swigCPtr = cObject;
}
diff --git a/Lib/d/denums.swg b/Lib/d/denums.swg
index 2632679ba..a216527b2 100644
--- a/Lib/d/denums.swg
+++ b/Lib/d/denums.swg
@@ -9,9 +9,9 @@
* Typemaps for enumeration types.
*/
-%typemap(cwtype) enum SWIGTYPE "int"
-%typemap(dwtype) enum SWIGTYPE "int"
-%typemap(dptype, cprimitive="1") enum SWIGTYPE "$dclassname"
+%typemap(ctype) enum SWIGTYPE "int"
+%typemap(imtype) enum SWIGTYPE "int"
+%typemap(dtype, cprimitive="1") enum SWIGTYPE "$dclassname"
%typecheck(SWIG_TYPECHECK_POINTER) enum SWIGTYPE ""
@@ -21,11 +21,11 @@
%typemap(directorout) enum SWIGTYPE %{ $result = ($1_ltype)$input; %}
%typemap(directorin) enum SWIGTYPE "$input = $1;"
%typemap(ddirectorin) enum SWIGTYPE "cast($dclassname)$winput"
-%typemap(ddirectorout) enum SWIGTYPE "cast(int)$dpcall"
+%typemap(ddirectorout) enum SWIGTYPE "cast(int)$dcall"
%typemap(din) enum SWIGTYPE "cast(int)$dinput"
%typemap(dout, excode=SWIGEXCODE) enum SWIGTYPE {
- $dclassname ret = cast($dclassname)$wcall;$excode
+ $dclassname ret = cast($dclassname)$imcall;$excode
return ret;
}
@@ -34,9 +34,9 @@
* Typemaps for (const) references to enumeration types.
*/
-%typemap(cwtype) const enum SWIGTYPE & "int"
-%typemap(dwtype) const enum SWIGTYPE & "int"
-%typemap(dptype) const enum SWIGTYPE & "$*dclassname"
+%typemap(ctype) const enum SWIGTYPE & "int"
+%typemap(imtype) const enum SWIGTYPE & "int"
+%typemap(dtype) const enum SWIGTYPE & "$*dclassname"
%typecheck(SWIG_TYPECHECK_POINTER) const enum SWIGTYPE & ""
@@ -51,10 +51,10 @@
$result = &temp; %}
%typemap(ddirectorin) const enum SWIGTYPE & "cast($*dclassname)$winput"
-%typemap(ddirectorout) const enum SWIGTYPE & "cast(int)$dpcall"
+%typemap(ddirectorout) const enum SWIGTYPE & "cast(int)$dcall"
%typemap(din) const enum SWIGTYPE & "cast(int)$dinput"
%typemap(dout, excode=SWIGEXCODE) const enum SWIGTYPE & {
- $*dclassname ret = cast($*dclassname)$wcall;$excode
+ $*dclassname ret = cast($*dclassname)$imcall;$excode
return ret;
}
diff --git a/Lib/d/dexception.swg b/Lib/d/dexception.swg
index f45cf7bfb..1aadbaada 100644
--- a/Lib/d/dexception.swg
+++ b/Lib/d/dexception.swg
@@ -6,7 +6,7 @@
// Code which is inserted into the dout typemaps and class constructors via
// excode if exceptions can be thrown.
-%define SWIGEXCODE "\n if ($wrapdmodule.SwigPendingException.isPending) throw $wrapdmodule.SwigPendingException.retrieve();" %enddef
+%define SWIGEXCODE "\n if ($imdmodule.SwigPendingException.isPending) throw $imdmodule.SwigPendingException.retrieve();" %enddef
%typemap(throws, canthrow=1) int,
long,
diff --git a/Lib/d/dhead.swg b/Lib/d/dhead.swg
index cb2b41079..4326b7f8c 100644
--- a/Lib/d/dhead.swg
+++ b/Lib/d/dhead.swg
@@ -64,7 +64,7 @@ SWIGEXPORT void SWIGRegisterExceptionCallbacks_$module(
%}
#if (SWIG_D_VERSION == 1)
-%pragma(d) wrapdmoduleimports=%{
+%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;
@@ -72,7 +72,7 @@ static import tango.core.Thread;
static import tango.stdc.stringz;
%}
-%pragma(d) wrapdmodulecode=%{
+%pragma(d) imdmodulecode=%{
private class SwigExceptionHelper {
static this() {
swigRegisterExceptionCallbacks(
@@ -169,11 +169,11 @@ private:
alias void function(char* message) SwigExceptionCallback;
%}
#else
-%pragma(d) wrapdmoduleimports=%{
+%pragma(d) imdmoduleimports=%{
static import std.conv;
%}
-%pragma(d) wrapdmodulecode=%{
+%pragma(d) imdmodulecode=%{
private class SwigExceptionHelper {
static this() {
// The D1/Tango version maps C++ exceptions to multiple exception types.
@@ -265,9 +265,9 @@ SWIGEXPORT void SWIGRegisterStringCallback_$module(SWIG_DStringHelperCallback ca
%}
#if (SWIG_D_VERSION == 1)
-%pragma(d) wrapdmoduleimports = "static import tango.stdc.stringz;";
+%pragma(d) imdmoduleimports = "static import tango.stdc.stringz;";
-%pragma(d) wrapdmodulecode = %{
+%pragma(d) imdmodulecode = %{
private class SwigStringHelper {
static this() {
swigRegisterStringCallback(&createString);
@@ -281,12 +281,12 @@ private class SwigStringHelper {
alias char* function(char* cString) SwigStringCallback;
%}
#else
-%pragma(d) wrapdmoduleimports = %{
+%pragma(d) imdmoduleimports = %{
static import std.conv;
static import std.string;
%}
-%pragma(d) wrapdmodulecode = %{
+%pragma(d) imdmodulecode = %{
private class SwigStringHelper {
static this() {
swigRegisterStringCallback(&createString);
diff --git a/Lib/d/dmemberfunctionpointers.swg b/Lib/d/dmemberfunctionpointers.swg
index 2774858f4..c33ff3840 100644
--- a/Lib/d/dmemberfunctionpointers.swg
+++ b/Lib/d/dmemberfunctionpointers.swg
@@ -5,9 +5,9 @@
* ----------------------------------------------------------------------------- */
-%typemap(cwtype) SWIGTYPE (CLASS::*) "char *"
-%typemap(dwtype) SWIGTYPE (CLASS::*) "char*"
-%typemap(dptype) SWIGTYPE (CLASS::*) "$dclassname"
+%typemap(ctype) SWIGTYPE (CLASS::*) "char *"
+%typemap(imtype) SWIGTYPE (CLASS::*) "char*"
+%typemap(dtype) SWIGTYPE (CLASS::*) "$dclassname"
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE (CLASS::*)
@@ -34,11 +34,11 @@
%typemap(ddirectorin) SWIGTYPE (CLASS::*)
"($winput is null) ? null : new $dclassname($winput, false)"
-%typemap(ddirectorout) SWIGTYPE (CLASS::*) "$dclassname.swigGetCPtr($dpcall)"
+%typemap(ddirectorout) SWIGTYPE (CLASS::*) "$dclassname.swigGetCPtr($dcall)"
%typemap(din) SWIGTYPE (CLASS::*) "$dclassname.swigGetCMemberPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIGTYPE (CLASS::*) {
- char* cMemberPtr = $wcall;
+ char* cMemberPtr = $imcall;
$dclassname ret = (cMemberPtr is null) ? null : new $dclassname(cMemberPtr, $owner);$excode
return ret;
}
diff --git a/Lib/d/dprimitives.swg b/Lib/d/dprimitives.swg
index 94999af2c..53a4b89da 100644
--- a/Lib/d/dprimitives.swg
+++ b/Lib/d/dprimitives.swg
@@ -10,16 +10,16 @@
* cases are handeled below.
*/
%define SWIG_D_PRIMITIVE(TYPE, DTYPE)
-%typemap(cwtype) TYPE, const TYPE & "TYPE"
-%typemap(dwtype) TYPE, const TYPE & "DTYPE"
-%typemap(dptype, cprimitive="1") TYPE, const TYPE & "DTYPE"
+%typemap(ctype) TYPE, const TYPE & "TYPE"
+%typemap(imtype) TYPE, const TYPE & "DTYPE"
+%typemap(dtype, cprimitive="1") TYPE, const TYPE & "DTYPE"
%typemap(in) TYPE "$1 = ($1_ltype)$input;"
%typemap(out) TYPE "$result = $1;"
%typemap(directorin) TYPE "$input = $1;"
%typemap(directorout) TYPE "$result = ($1_ltype)$input;"
%typemap(ddirectorin) TYPE "$winput"
-%typemap(ddirectorout) TYPE "$dpcall"
+%typemap(ddirectorout) TYPE "$dcall"
%typemap(in) const TYPE & ($*1_ltype temp)
%{ temp = ($*1_ltype)$input;
@@ -31,11 +31,11 @@
temp = ($*1_ltype)$input;
$result = &temp; %}
%typemap(ddirectorin) const TYPE & "$winput"
-%typemap(ddirectorout) const TYPE & "$dpcall"
+%typemap(ddirectorout) const TYPE & "$dcall"
%typemap(din) TYPE, const TYPE & "$dinput"
%typemap(dout, excode=SWIGEXCODE) TYPE, const TYPE & {
- auto ret = $wcall;$excode
+ auto ret = $imcall;$excode
return ret;
}
%enddef
@@ -60,8 +60,8 @@ SWIG_D_PRIMITIVE(double, double)
// The C++ boolean type needs some special casing since it is not part of the
// C standard and is thus represented as unsigned int in the C wrapper layer.
-%typemap(cwtype) bool, const bool & "unsigned int"
-%typemap(dwtype) bool, const bool & "uint"
+%typemap(ctype) bool, const bool & "unsigned int"
+%typemap(imtype) bool, const bool & "uint"
%typemap(in) bool "$1 = $input ? true : false;"
%typemap(in) const bool & ($*1_ltype temp)
@@ -78,7 +78,7 @@ SWIG_D_PRIMITIVE(double, double)
%typemap(ddirectorin) bool "($winput ? true : false)"
%typemap(dout, excode=SWIGEXCODE) bool, const bool & {
- bool ret = $wcall ? true : false;$excode
+ bool ret = $imcall ? true : false;$excode
return ret;
}
diff --git a/Lib/d/dstrings.swg b/Lib/d/dstrings.swg
index a145c8d75..02895c153 100644
--- a/Lib/d/dstrings.swg
+++ b/Lib/d/dstrings.swg
@@ -5,9 +5,9 @@
* ----------------------------------------------------------------------------- */
%define SWIGD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
-%typemap(cwtype) char *, char *&, char[ANY], char[] "char *"
-%typemap(dwtype) char *, char *&, char[ANY], char[] #DW_STRING_TYPE
-%typemap(dptype) char *, char *&, char[ANY], char[] #DP_STRING_TYPE
+%typemap(ctype) char *, char *&, char[ANY], char[] "char *"
+%typemap(imtype) char *, char *&, char[ANY], char[] #DW_STRING_TYPE
+%typemap(dtype) char *, char *&, char[ANY], char[] #DP_STRING_TYPE
/*
@@ -19,7 +19,7 @@
%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * %{ $result = ($1_ltype)$input; %}
%typemap(directorin) char * %{ $input = SWIG_d_string_callback((const char *)$1); %}
%typemap(ddirectorin) char * "FROM_STRINGZ($winput)"
-%typemap(ddirectorout) char * "TO_STRINGZ($dpcall)"
+%typemap(ddirectorout) char * "TO_STRINGZ($dcall)"
/*
@@ -44,12 +44,12 @@
%typemap(directorin) char[ANY], char[] %{ $input = SWIG_d_string_callback((const char *)$1); %}
%typemap(ddirectorin) char[ANY], char[] "$winput"
-%typemap(ddirectorout) char[ANY], char[] "$dpcall"
+%typemap(ddirectorout) char[ANY], char[] "$dcall"
%typemap(din) char *, char *&, char[ANY], char[] "($dinput ? TO_STRINGZ($dinput) : null)"
%typemap(dout, excode=SWIGEXCODE) char *, char *&, char[ANY], char[] {
- DP_STRING_TYPE ret = FROM_STRINGZ ## ($wcall);$excode
+ DP_STRING_TYPE ret = FROM_STRINGZ ## ($imcall);$excode
return ret;
}
diff --git a/Lib/d/dswigtype.swg b/Lib/d/dswigtype.swg
index ed2fb531d..5bb0bd951 100644
--- a/Lib/d/dswigtype.swg
+++ b/Lib/d/dswigtype.swg
@@ -4,25 +4,25 @@
* Typemaps for non-primitive types (C/C++ classes and structs).
* ----------------------------------------------------------------------------- */
-%typemap(cwtype) SWIGTYPE "void *"
-%typemap(dwtype) SWIGTYPE "void*"
-%typemap(dptype) SWIGTYPE "$&dclassname"
+%typemap(ctype) SWIGTYPE "void *"
+%typemap(imtype) SWIGTYPE "void*"
+%typemap(dtype) SWIGTYPE "$&dclassname"
-%typemap(cwtype) SWIGTYPE [] "void *"
-%typemap(dwtype) SWIGTYPE [] "void*"
-%typemap(dptype) SWIGTYPE [] "$dclassname"
+%typemap(ctype) SWIGTYPE [] "void *"
+%typemap(imtype) SWIGTYPE [] "void*"
+%typemap(dtype) SWIGTYPE [] "$dclassname"
-%typemap(cwtype) SWIGTYPE * "void *"
-%typemap(dwtype) SWIGTYPE * "void*"
-%typemap(dptype, nativepointer="$dptype") SWIGTYPE * "$dclassname"
+%typemap(ctype) SWIGTYPE * "void *"
+%typemap(imtype) SWIGTYPE * "void*"
+%typemap(dtype, nativepointer="$dtype") SWIGTYPE * "$dclassname"
-%typemap(cwtype) SWIGTYPE & "void *"
-%typemap(dwtype) SWIGTYPE & "void*"
-%typemap(dptype) SWIGTYPE & "$dclassname"
+%typemap(ctype) SWIGTYPE & "void *"
+%typemap(imtype) SWIGTYPE & "void*"
+%typemap(dtype) SWIGTYPE & "$dclassname"
-%typemap(cwtype) SWIGTYPE *const& "void *"
-%typemap(dwtype) SWIGTYPE *const& "void*"
-%typemap(dptype) SWIGTYPE *const& "$*dclassname"
+%typemap(ctype) SWIGTYPE *const& "void *"
+%typemap(imtype) SWIGTYPE *const& "void*"
+%typemap(dtype) SWIGTYPE *const& "$*dclassname"
%typecheck(SWIG_TYPECHECK_POINTER)
SWIGTYPE,
@@ -66,11 +66,11 @@
$result = *($&1_ltype)$input; %}
%typemap(ddirectorin) SWIGTYPE "new $&dclassname($winput, false)"
-%typemap(ddirectorout) SWIGTYPE "$&dclassname.swigGetCPtr($dpcall)"
+%typemap(ddirectorout) SWIGTYPE "$&dclassname.swigGetCPtr($dcall)"
%typemap(din) SWIGTYPE "$&dclassname.swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIGTYPE {
- $&dclassname ret = new $&dclassname($wcall, true);$excode
+ $&dclassname ret = new $&dclassname($imcall, true);$excode
return ret;
}
@@ -88,21 +88,21 @@
"$result = ($1_ltype)$input;"
%typemap(ddirectorin,
- nativepointer="cast($dptype)$winput"
+ nativepointer="cast($dtype)$winput"
) SWIGTYPE * "($winput is null) ? null : new $dclassname($winput, false)"
%typemap(ddirectorout,
- nativepointer="cast(void*)$dpcall"
-) SWIGTYPE * "$dclassname.swigGetCPtr($dpcall)"
+ nativepointer="cast(void*)$dcall"
+) SWIGTYPE * "$dclassname.swigGetCPtr($dcall)"
%typemap(din,
nativepointer="cast(void*)$dinput"
) SWIGTYPE * "$dclassname.swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE,
- nativepointer="{\n auto ret = cast($dptype)$wcall;$excode\n return ret;\n}"
+ nativepointer="{\n auto ret = cast($dtype)$imcall;$excode\n return ret;\n}"
) SWIGTYPE * {
- void* cPtr = $wcall;
+ void* cPtr = $imcall;
$dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode
return ret;
}
@@ -132,11 +132,11 @@
$result = ($1_ltype)$input; %}
%typemap(ddirectorin) SWIGTYPE & "new $dclassname($winput, false)"
-%typemap(ddirectorout) SWIGTYPE & "$dclassname.swigGetCPtr($dpcall)"
+%typemap(ddirectorout) SWIGTYPE & "$dclassname.swigGetCPtr($dcall)"
%typemap(din) SWIGTYPE & "$dclassname.swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIGTYPE & {
- $dclassname ret = new $dclassname($wcall, $owner);$excode
+ $dclassname ret = new $dclassname($imcall, $owner);$excode
return ret;
}
@@ -150,7 +150,7 @@
%typemap(din) SWIGTYPE [] "$dclassname.swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIGTYPE [] {
- void* cPtr = $wcall;
+ void* cPtr = $imcall;
$dclassname ret = (cPtr is null) ? null : new $dclassname(cPtr, $owner);$excode
return ret;
}
@@ -171,7 +171,7 @@
%typemap(din) SWIGTYPE *const& "$*dclassname.swigGetCPtr($dinput)"
%typemap(dout, excode=SWIGEXCODE) SWIGTYPE *const& {
- void* cPtr = $wcall;
+ void* cPtr = $imcall;
$*dclassname ret = (cPtr is null) ? null : new $*dclassname(cPtr, $owner);$excode
return ret;
}
diff --git a/Lib/d/dvoid.swg b/Lib/d/dvoid.swg
index a08da5e32..805f1e71e 100644
--- a/Lib/d/dvoid.swg
+++ b/Lib/d/dvoid.swg
@@ -4,15 +4,15 @@
* Typemaps for handling void function return types and empty parameter lists.
* ----------------------------------------------------------------------------- */
-%typemap(cwtype) void "void"
-%typemap(dwtype) void "void"
-%typemap(dptype, cprimitive="1") void "void"
+%typemap(ctype) void "void"
+%typemap(imtype) void "void"
+%typemap(dtype, cprimitive="1") void "void"
%typemap(out, null="") void ""
%typemap(ddirectorin) void "$winput"
-%typemap(ddirectorout) void "$dpcall"
+%typemap(ddirectorout) void "$dcall"
%typemap(directorin) void ""
%typemap(dout, excode=SWIGEXCODE) void {
- $wcall;$excode
+ $imcall;$excode
}
diff --git a/Lib/d/std_string.i b/Lib/d/std_string.i
index 4938cfdf7..7a4accf18 100644
--- a/Lib/d/std_string.i
+++ b/Lib/d/std_string.i
@@ -21,9 +21,9 @@ class string;
%define SWIGD_STD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
// string
-%typemap(cwtype) string, const string & "char *"
-%typemap(dwtype) string, const string & #DW_STRING_TYPE
-%typemap(dptype) string, const string & #DP_STRING_TYPE
+%typemap(ctype) string, const string & "char *"
+%typemap(imtype) string, const string & #DW_STRING_TYPE
+%typemap(dtype) string, const string & #DP_STRING_TYPE
%typemap(in, canthrow=1) string, const string &
%{ if (!$input) {
@@ -44,7 +44,7 @@ class string;
%typemap(din) string, const string & "($dinput ? TO_STRINGZ($dinput) : null)"
%typemap(dout, excode=SWIGEXCODE) string, const string & {
- DP_STRING_TYPE ret = FROM_STRINGZ($wcall);$excode
+ DP_STRING_TYPE ret = FROM_STRINGZ($imcall);$excode
return ret;
}
@@ -68,7 +68,7 @@ class string;
$result = &$1_str; %}
%typemap(ddirectorin) string, const string & "FROM_STRINGZ($winput)"
-%typemap(ddirectorout) string, const string & "TO_STRINGZ($dpcall)"
+%typemap(ddirectorout) string, const string & "TO_STRINGZ($dcall)"
%typemap(throws, canthrow=1) string, const string &
%{ SWIG_DSetPendingException(SWIG_DException, $1.c_str());
diff --git a/Lib/d/std_vector.i b/Lib/d/std_vector.i
index cdaf1e30b..b7d4e223f 100644
--- a/Lib/d/std_vector.i
+++ b/Lib/d/std_vector.i
@@ -21,11 +21,11 @@
%include
// MACRO for use within the std::vector class body
-%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CONST_REFERENCE, CWTYPE...)
+%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CONST_REFERENCE, CTYPE...)
#if (SWIG_D_VERSION == 1)
-%typemap(dimports) std::vector< CWTYPE > "static import tango.core.Exception;"
-%typemap(dcode) std::vector< CWTYPE > %{
-public this($typemap(dptype, CWTYPE)[] values) {
+%typemap(dimports) std::vector< CTYPE > "static import tango.core.Exception;"
+%typemap(dcode) std::vector< CTYPE > %{
+public this($typemap(dtype, CTYPE)[] values) {
this();
append(values);
}
@@ -36,7 +36,7 @@ alias push_back opCatAssign;
alias size length;
alias opSlice slice;
-public $typemap(dptype, CWTYPE) opIndexAssign($typemap(dptype, CWTYPE) value, size_t index) {
+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.");
}
@@ -44,28 +44,28 @@ public $typemap(dptype, CWTYPE) opIndexAssign($typemap(dptype, CWTYPE) value, si
return value;
}
-public $typemap(dptype, CWTYPE) opIndex(size_t index) {
+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(dptype, CWTYPE)[] value...) {
+public void append($typemap(dtype, CTYPE)[] value...) {
foreach (v; value) {
add(v);
}
}
-public $typemap(dptype, CWTYPE)[] opSlice() {
- $typemap(dptype, CWTYPE)[] array = new $typemap(dptype, CWTYPE)[size()];
+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(dptype, CWTYPE) value) dg) {
+public int opApply(int delegate(ref $typemap(dtype, CTYPE) value) dg) {
int result;
size_t currentSize = size();
@@ -77,7 +77,7 @@ public int opApply(int delegate(ref $typemap(dptype, CWTYPE) value) dg) {
return result;
}
-public int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) dg) {
+public int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) {
int result;
size_t currentSize = size();
@@ -104,10 +104,10 @@ public void capacity(size_t value) {
public:
typedef size_t size_type;
- typedef CWTYPE value_type;
+ typedef CTYPE value_type;
typedef CONST_REFERENCE const_reference;
void clear();
- void push_back(CWTYPE const& x);
+ void push_back(CTYPE const& x);
size_type size() const;
size_type capacity() const;
void reserve(size_type n) throw (std::length_error);
@@ -115,8 +115,8 @@ public void capacity(size_t value) {
vector(const vector &other);
%extend {
vector(size_type capacity) throw (std::length_error) {
- std::vector< CWTYPE >* pv = 0;
- pv = new std::vector< CWTYPE >();
+ std::vector< CTYPE >* pv = 0;
+ pv = new std::vector< CTYPE >();
// Might throw std::length_error.
pv->reserve(capacity);
@@ -133,7 +133,7 @@ public void capacity(size_t value) {
throw std::out_of_range("Tried to remove last element from empty vector.");
}
- std::vector< CWTYPE >::const_reference value = $self->back();
+ std::vector< CTYPE >::const_reference value = $self->back();
$self->pop_back();
return value;
}
@@ -143,8 +143,8 @@ public void capacity(size_t value) {
throw std::out_of_range("Tried to remove element with invalid index.");
}
- std::vector< CWTYPE >::iterator it = $self->begin() + index;
- std::vector< CWTYPE >::const_reference value = *it;
+ std::vector< CTYPE >::iterator it = $self->begin() + index;
+ std::vector< CTYPE >::const_reference value = *it;
$self->erase(it);
return value;
}
@@ -161,11 +161,11 @@ public void capacity(size_t value) {
}
}
- // Use CWTYPE const& instead of const_reference to work around SWIG code
+ // 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, CWTYPE const& val) throw (std::out_of_range) {
+ 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.");
}
@@ -179,15 +179,15 @@ public void capacity(size_t value) {
#else
-%typemap(dimports) std::vector< CWTYPE > %{
+%typemap(dimports) std::vector< CTYPE > %{
static import std.algorithm;
static import std.exception;
static import std.range;
static import std.traits;
%}
-%typemap(dcode) std::vector< CWTYPE > %{
+%typemap(dcode) std::vector< CTYPE > %{
alias size_t KeyType;
-alias $typemap(dptype, CWTYPE) ValueType;
+alias $typemap(dtype, CTYPE) ValueType;
this(ValueType[] values...) {
this();
@@ -198,17 +198,17 @@ this(ValueType[] values...) {
}
struct Range {
- private $typemap(dptype, std::vector< CWTYPE >) _outer;
+ private $typemap(dtype, std::vector< CTYPE >) _outer;
private size_t _a, _b;
- this($typemap(dptype, std::vector< CWTYPE >) data, size_t a, size_t b) {
+ this($typemap(dtype, std::vector< CTYPE >) data, size_t a, size_t b) {
_outer = data;
_a = a;
_b = b;
}
@property bool empty() const {
- assert((cast($typemap(dptype, std::vector< CWTYPE >))_outer).length >= _b);
+ assert((cast($typemap(dtype, std::vector< CTYPE >))_outer).length >= _b);
return _a >= _b;
}
@@ -411,7 +411,7 @@ Range linearRemove(Range r) {
}
alias remove stableLinearRemove;
-int opApply(int delegate(ref $typemap(dptype, CWTYPE) value) dg) {
+int opApply(int delegate(ref $typemap(dtype, CTYPE) value) dg) {
int result;
size_t currentSize = size();
@@ -423,7 +423,7 @@ int opApply(int delegate(ref $typemap(dptype, CWTYPE) value) dg) {
return result;
}
-int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) dg) {
+int opApply(int delegate(ref size_t index, ref $typemap(dtype, CTYPE) value) dg) {
int result;
size_t currentSize = size();
@@ -442,11 +442,11 @@ int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) d
public:
typedef size_t size_type;
- typedef CWTYPE value_type;
+ typedef CTYPE value_type;
typedef CONST_REFERENCE const_reference;
bool empty() const;
void clear();
- void push_back(CWTYPE const& x);
+ void push_back(CTYPE const& x);
void pop_back();
size_type size() const;
size_type capacity() const;
@@ -455,8 +455,8 @@ int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) d
vector(const vector &other);
%extend {
vector(size_type capacity) throw (std::length_error) {
- std::vector< CWTYPE >* pv = 0;
- pv = new std::vector< CWTYPE >();
+ std::vector< CTYPE >* pv = 0;
+ pv = new std::vector< CTYPE >();
// Might throw std::length_error.
pv->reserve(capacity);
@@ -469,7 +469,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) d
throw std::out_of_range("Tried to remove last element from empty vector.");
}
- std::vector< CWTYPE >::const_reference value = $self->back();
+ std::vector< CTYPE >::const_reference value = $self->back();
$self->pop_back();
return value;
}
@@ -479,26 +479,26 @@ int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) d
throw std::out_of_range("Tried to remove element with invalid index.");
}
- std::vector< CWTYPE >::iterator it = $self->begin() + index;
- std::vector< CWTYPE >::const_reference value = *it;
+ std::vector< CTYPE >::iterator it = $self->begin() + index;
+ std::vector< CTYPE >::const_reference value = *it;
$self->erase(it);
return value;
}
void removeBack(size_type how_many) throw (std::out_of_range) {
- std::vector< CWTYPE >::iterator end = $self->end();
- std::vector< CWTYPE >::iterator start = end - how_many;
+ std::vector< CTYPE >::iterator end = $self->end();
+ std::vector< CTYPE >::iterator start = end - how_many;
$self->erase(start, end);
}
void linearRemove(size_type start_index, size_type end_index) throw (std::out_of_range) {
- std::vector< CWTYPE >::iterator start = $self->begin() + start_index;
- std::vector< CWTYPE >::iterator end = $self->begin() + end_index;
+ std::vector< CTYPE >::iterator start = $self->begin() + start_index;
+ std::vector< CTYPE >::iterator end = $self->begin() + end_index;
$self->erase(start, end);
}
- void insertAt(size_type index, CWTYPE const& x) throw (std::out_of_range) {
- std::vector< CWTYPE >::iterator it = $self->begin() + index;
+ void insertAt(size_type index, CTYPE const& x) throw (std::out_of_range) {
+ std::vector< CTYPE >::iterator it = $self->begin() + index;
$self->insert(it, x);
}
}
@@ -513,11 +513,11 @@ int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) d
return (*$self)[index];
}
}
- // Use CWTYPE const& instead of const_reference to work around SWIG code
+ // 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, CWTYPE const& val) throw (std::out_of_range) {
+ 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.");
}
@@ -532,7 +532,7 @@ int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) d
// Extra methods added to the collection class if operator== is defined for the class being wrapped
// The class will then implement IList<>, which adds extra functionality
-%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CWTYPE...)
+%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE...)
%extend {
}
%enddef
@@ -541,11 +541,11 @@ int opApply(int delegate(ref size_t index, ref $typemap(dptype, CWTYPE) value) d
#define %arg(X...) X
// Macros for std::vector class specializations/enhancements
-%define SWIG_STD_VECTOR_ENHANCED(CWTYPE...)
+%define SWIG_STD_VECTOR_ENHANCED(CTYPE...)
namespace std {
- template<> class vector {
- SWIG_STD_VECTOR_MINIMUM_INTERNAL(%arg(CWTYPE const&), %arg(CWTYPE))
- SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CWTYPE)
+ template<> class vector {
+ SWIG_STD_VECTOR_MINIMUM_INTERNAL(%arg(CTYPE const&), %arg(CTYPE))
+ SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE)
};
}
%enddef
diff --git a/Lib/d/typemaps.i b/Lib/d/typemaps.i
index cd5636562..dcbd7a1cb 100644
--- a/Lib/d/typemaps.i
+++ b/Lib/d/typemaps.i
@@ -53,13 +53,13 @@ In D you could then use it like this:
double answer = fadd(10.0, 20.0);
*/
-%define INPUT_TYPEMAP(TYPE, CWTYPE, DTYPE)
-%typemap(cwtype) TYPE *INPUT, TYPE &INPUT "CWTYPE"
-%typemap(dwtype) TYPE *INPUT, TYPE &INPUT "DTYPE"
-%typemap(dptype) TYPE *INPUT, TYPE &INPUT "DTYPE"
+%define INPUT_TYPEMAP(TYPE, CTYPE, DTYPE)
+%typemap(ctype) TYPE *INPUT, TYPE &INPUT "CTYPE"
+%typemap(imtype) TYPE *INPUT, TYPE &INPUT "DTYPE"
+%typemap(dtype) TYPE *INPUT, TYPE &INPUT "DTYPE"
%typemap(din) TYPE *INPUT, TYPE &INPUT "$dinput"
%typemap(ddirectorin) TYPE *INPUT, TYPE &INPUT "$winput"
-%typemap(ddirectorout) TYPE *INPUT, TYPE &INPUT "$dpcall"
+%typemap(ddirectorout) TYPE *INPUT, TYPE &INPUT "$dcall"
%typemap(in) TYPE *INPUT, TYPE &INPUT
%{ $1 = ($1_ltype)&$input; %}
@@ -68,10 +68,10 @@ In D you could then use it like this:
%{ $result = ($1_ltype)&$input; %}
%typemap(directorin) TYPE &INPUT
-%{ $input = (CWTYPE *)$1; %}
+%{ $input = (CTYPE *)$1; %}
%typemap(directorin) TYPE *INPUT
-%{ $input = (CWTYPE *)$1; %}
+%{ $input = (CTYPE *)$1; %}
%typemap(typecheck) TYPE *INPUT = TYPE;
%typemap(typecheck) TYPE &INPUT = TYPE;
@@ -93,7 +93,7 @@ INPUT_TYPEMAP(float, float, float)
INPUT_TYPEMAP(double, double, double)
INPUT_TYPEMAP(enum SWIGTYPE, unsigned int, int)
-%typemap(dptype) enum SWIGTYPE *INPUT, enum SWIGTYPE &INPUT "$*dclassname"
+%typemap(dtype) enum SWIGTYPE *INPUT, enum SWIGTYPE &INPUT "$*dclassname"
#undef INPUT_TYPEMAP
@@ -148,13 +148,13 @@ value returned in the second output parameter. In D you would use it like this:
double fraction = modf(5, dptr);
*/
-%define OUTPUT_TYPEMAP(TYPE, CWTYPE, DTYPE, TYPECHECKPRECEDENCE)
-%typemap(cwtype) TYPE *OUTPUT, TYPE &OUTPUT "CWTYPE *"
-%typemap(dwtype) TYPE *OUTPUT, TYPE &OUTPUT "out DTYPE"
-%typemap(dptype) TYPE *OUTPUT, TYPE &OUTPUT "out DTYPE"
+%define OUTPUT_TYPEMAP(TYPE, CTYPE, DTYPE, TYPECHECKPRECEDENCE)
+%typemap(ctype) TYPE *OUTPUT, TYPE &OUTPUT "CTYPE *"
+%typemap(imtype) TYPE *OUTPUT, TYPE &OUTPUT "out DTYPE"
+%typemap(dtype) TYPE *OUTPUT, TYPE &OUTPUT "out DTYPE"
%typemap(din) TYPE *OUTPUT, TYPE &OUTPUT "$dinput"
%typemap(ddirectorin) TYPE *OUTPUT, TYPE &OUTPUT "$winput"
-%typemap(ddirectorout) TYPE *OUTPUT, TYPE &OUTPUT "$dpcall"
+%typemap(ddirectorout) TYPE *OUTPUT, TYPE &OUTPUT "$dcall"
%typemap(in) TYPE *OUTPUT, TYPE &OUTPUT
@@ -190,7 +190,7 @@ OUTPUT_TYPEMAP(float, float, float, FLOAT_PTR)
OUTPUT_TYPEMAP(double, double, double, DOUBLE_PTR)
OUTPUT_TYPEMAP(enum SWIGTYPE, unsigned int, int, INT32_PTR)
-%typemap(dptype) enum SWIGTYPE *OUTPUT, enum SWIGTYPE &OUTPUT "out $*dclassname"
+%typemap(dtype) enum SWIGTYPE *OUTPUT, enum SWIGTYPE &OUTPUT "out $*dclassname"
#undef OUTPUT_TYPEMAP
@@ -253,13 +253,13 @@ languages in that the scripting languages will return the output value as part
of the function return value.
*/
-%define INOUT_TYPEMAP(TYPE, CWTYPE, DTYPE, TYPECHECKPRECEDENCE)
-%typemap(cwtype) TYPE *INOUT, TYPE &INOUT "CWTYPE *"
-%typemap(dwtype) TYPE *INOUT, TYPE &INOUT "ref DTYPE"
-%typemap(dptype) TYPE *INOUT, TYPE &INOUT "ref DTYPE"
+%define INOUT_TYPEMAP(TYPE, CTYPE, DTYPE, TYPECHECKPRECEDENCE)
+%typemap(ctype) TYPE *INOUT, TYPE &INOUT "CTYPE *"
+%typemap(imtype) TYPE *INOUT, TYPE &INOUT "ref DTYPE"
+%typemap(dtype) TYPE *INOUT, TYPE &INOUT "ref DTYPE"
%typemap(din) TYPE *INOUT, TYPE &INOUT "$dinput"
%typemap(ddirectorin) TYPE *INOUT, TYPE &INOUT "$winput"
-%typemap(ddirectorout) TYPE *INOUT, TYPE &INOUT "$dpcall"
+%typemap(ddirectorout) TYPE *INOUT, TYPE &INOUT "$dcall"
%typemap(in) TYPE *INOUT, TYPE &INOUT
%{ $1 = ($1_ltype)$input; %}
@@ -293,6 +293,6 @@ INOUT_TYPEMAP(float, float, float, FLOAT_PTR)
INOUT_TYPEMAP(double, double, double, DOUBLE_PTR)
INOUT_TYPEMAP(enum SWIGTYPE, unsigned int, int, INT32_PTR)
-%typemap(dptype) enum SWIGTYPE *INOUT, enum SWIGTYPE &INOUT "ref $*dclassname"
+%typemap(dtype) enum SWIGTYPE *INOUT, enum SWIGTYPE &INOUT "ref $*dclassname"
#undef INOUT_TYPEMAP
diff --git a/Source/Include/swigwarn.h b/Source/Include/swigwarn.h
index d7d11b368..b13015994 100644
--- a/Source/Include/swigwarn.h
+++ b/Source/Include/swigwarn.h
@@ -201,9 +201,9 @@
/* Feel free to claim any number in this space that's not currently being used. Just make sure you
add an entry here */
-#define WARN_D_TYPEMAP_CWTYPE_UNDEF 700
-#define WARN_D_TYPEMAP_DWTYPE_UNDEF 701
-#define WARN_D_TYPEMAP_DPTYPE_UNDEF 702
+#define WARN_D_TYPEMAP_CTYPE_UNDEF 700
+#define WARN_D_TYPEMAP_IMTYPE_UNDEF 701
+#define WARN_D_TYPEMAP_DTYPE_UNDEF 702
#define WARN_D_MULTIPLE_INHERITANCE 703
#define WARN_D_TYPEMAP_CLASSMOD_UNDEF 704
#define WARN_D_TYPEMAP_DBODY_UNDEF 705
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
index c726ac022..63da28a81 100644
--- a/Source/Modules/d.cxx
+++ b/Source/Modules/d.cxx
@@ -91,10 +91,10 @@ class D : public Language {
* Names of generated D entities.
*/
// The name of the D module containing the interface to the C wrapper.
- String *wrap_dmodule_name;
+ String *im_dmodule_name;
// The fully qualified name of the wrap D module (package name included).
- String *wrap_dmodule_fq_name;
+ String *im_dmodule_fq_name;
// The name of the proxy module which exposes the (SWIG) module contents as a
// D module.
@@ -120,12 +120,12 @@ class D : public Language {
/*
* Variables temporarily holding the generated D code.
*/
- // Import statements written to the wrap D module header set via
- // %pragma(d) wrapdmoduleimports.
- String *wrap_dmodule_imports;
+ // Import statements written to the intermediary D module header set via
+ // %pragma(d) imdmoduleimports.
+ String *im_dmodule_imports;
- // The code for the wrap D module body.
- String *wrap_dmodule_code;
+ // The code for the intermediary D module body.
+ String *im_dmodule_code;
// Import statements for all proxy modules (the main proxy module and, if in
// split proxy module mode, the proxy class modules) from
@@ -140,7 +140,7 @@ class D : public Language {
// module. If not in split proxy mode, this contains the whole proxy code.
String *proxy_dmodule_code;
- // The D code generated for the currently wrapped enum.
+ // The D code generated for the currently processed enum.
String *proxy_enum_code;
/*
@@ -176,14 +176,14 @@ class D : public Language {
/*
* Code for dynamically loading the wrapper library on the D side.
*/
- // D code which is inserted into the wrapper module if dynamic linking is used.
+ // D code which is inserted into the im D module if dynamic linking is used.
String *wrapper_loader_code;
// The D code to bind a function pointer to a library symbol.
String *wrapper_loader_bind_command;
- // The cumulated binding commands binding all wrapper functions to the C/C++
- // library symbols.
+ // The cumulated binding commands binding all the functions declared in the
+ // intermediary D module to the C/C++ library symbols.
String *wrapper_loader_bind_code;
/*
@@ -231,15 +231,15 @@ public:
upcasts_code(NULL),
director_callback_typedefs(NULL),
director_callback_pointers(NULL),
- wrap_dmodule_name(NULL),
- wrap_dmodule_fq_name(NULL),
+ im_dmodule_name(NULL),
+ im_dmodule_fq_name(NULL),
proxy_dmodule_name(NULL),
proxy_dmodule_fq_name(NULL),
package(NULL),
dmodule_directory(NULL),
wrap_library_name(NULL),
- wrap_dmodule_imports(NULL),
- wrap_dmodule_code(NULL),
+ im_dmodule_imports(NULL),
+ im_dmodule_code(NULL),
global_proxy_imports(NULL),
proxy_dmodule_imports(NULL),
proxy_dmodule_code(NULL),
@@ -335,8 +335,8 @@ public:
Node *optionsnode = Getattr(Getattr(n, "module"), "options");
if (optionsnode) {
- if (Getattr(optionsnode, "wrapdmodulename")) {
- wrap_dmodule_name = Copy(Getattr(optionsnode, "wrapdmodulename"));
+ if (Getattr(optionsnode, "imdmodulename")) {
+ im_dmodule_name = Copy(Getattr(optionsnode, "imdmodulename"));
}
if (Getattr(optionsnode, "directors")) {
@@ -423,14 +423,14 @@ public:
// Make the wrap and proxy D module names.
// The wrap module name can be set in the module directive.
- if (!wrap_dmodule_name) {
- wrap_dmodule_name = NewStringf("%s_wrap", Getattr(n, "name"));
+ if (!im_dmodule_name) {
+ im_dmodule_name = NewStringf("%s_im", Getattr(n, "name"));
}
- wrap_dmodule_fq_name = NewStringf("%s%s", package, wrap_dmodule_name);
+ im_dmodule_fq_name = NewStringf("%s%s", package, im_dmodule_name);
proxy_dmodule_name = Copy(Getattr(n, "name"));
proxy_dmodule_fq_name = NewStringf("%s%s", package, proxy_dmodule_name);
- wrap_dmodule_code = NewString("");
+ im_dmodule_code = NewString("");
proxy_class_imports = NewString("");
proxy_class_enums_code = NewString("");
proxy_class_body_code = NewString("");
@@ -439,7 +439,7 @@ public:
destructor_call = NewString("");
proxy_dmodule_code = NewString("");
proxy_dmodule_imports = NewString("");
- wrap_dmodule_imports = NewString("");
+ im_dmodule_imports = NewString("");
upcasts_code = NewString("");
global_proxy_imports = NewString("");
wrapper_loader_code = NewString("");
@@ -450,10 +450,9 @@ public:
n_dmethods = 0;
// By default, expect the dynamically loaded wrapper library to be named
- // like the wrapper D module (i.e. [lib]_wrap[.so/.dll] unless the
- // user overrides it).
+ // [lib]_wrap[.so/.dll].
if (!wrap_library_name)
- wrap_library_name = Copy(wrap_dmodule_name);
+ wrap_library_name = NewStringf("%s_wrap", Getattr(n, "name"));
Swig_banner(f_begin);
@@ -496,9 +495,9 @@ public:
// Generate the wrap D module.
// TODO: Add support for »static« linking.
{
- String *filen = NewStringf("%s%s.d", dmodule_directory, wrap_dmodule_name);
- File *wrap_d_file = NewFile(filen, "w", SWIG_output_files());
- if (!wrap_d_file) {
+ String *filen = NewStringf("%s%s.d", dmodule_directory, im_dmodule_name);
+ File *im_d_file = NewFile(filen, "w", SWIG_output_files());
+ if (!im_d_file) {
FileErrorDisplay(filen);
SWIG_exit(EXIT_FAILURE);
}
@@ -507,22 +506,22 @@ public:
filen = NULL;
// Start writing out the intermediary class file.
- emitBanner(wrap_d_file);
+ emitBanner(im_d_file);
- Printf(wrap_d_file, "module %s;\n", wrap_dmodule_fq_name);
+ Printf(im_d_file, "module %s;\n", im_dmodule_fq_name);
- Printv(wrap_d_file, wrap_dmodule_imports, "\n", NIL);
+ Printv(im_d_file, im_dmodule_imports, "\n", NIL);
Replaceall(wrapper_loader_code, "$wraplibrary", wrap_library_name);
Replaceall(wrapper_loader_code, "$wrapperloaderbindcode", wrapper_loader_bind_code);
Replaceall(wrapper_loader_code, "$module", proxy_dmodule_name);
- Printf(wrap_d_file, "%s\n", wrapper_loader_code);
+ Printf(im_d_file, "%s\n", wrapper_loader_code);
// Add the wrapper function declarations.
- replaceModuleVariables(wrap_dmodule_code);
- Printv(wrap_d_file, wrap_dmodule_code, NIL);
+ replaceModuleVariables(im_dmodule_code);
+ Printv(im_d_file, im_dmodule_code, NIL);
- Close(wrap_d_file);
+ Close(im_d_file);
}
// Generate the D proxy module for the wrapped module.
@@ -540,7 +539,7 @@ public:
emitBanner(proxy_d_file);
Printf(proxy_d_file, "module %s;\n", proxy_dmodule_fq_name);
- Printf(proxy_d_file, "\nstatic import %s;\n", wrap_dmodule_fq_name);
+ Printf(proxy_d_file, "\nstatic import %s;\n", im_dmodule_fq_name);
Printv(proxy_d_file, global_proxy_imports, NIL);
Printv(proxy_d_file, proxy_dmodule_imports, NIL);
Printv(proxy_d_file, "\n", NIL);
@@ -588,12 +587,12 @@ public:
unknown_types = NULL;
Delete(filenames_list);
filenames_list = NULL;
- Delete(wrap_dmodule_name);
- wrap_dmodule_name = NULL;
- Delete(wrap_dmodule_fq_name);
- wrap_dmodule_fq_name = NULL;
- Delete(wrap_dmodule_code);
- wrap_dmodule_code = NULL;
+ Delete(im_dmodule_name);
+ im_dmodule_name = NULL;
+ Delete(im_dmodule_fq_name);
+ im_dmodule_fq_name = NULL;
+ Delete(im_dmodule_code);
+ im_dmodule_code = NULL;
Delete(proxy_class_imports);
proxy_class_imports = NULL;
Delete(proxy_class_enums_code);
@@ -614,8 +613,8 @@ public:
proxy_dmodule_code = NULL;
Delete(proxy_dmodule_imports);
proxy_dmodule_imports = NULL;
- Delete(wrap_dmodule_imports);
- wrap_dmodule_imports = NULL;
+ Delete(im_dmodule_imports);
+ im_dmodule_imports = NULL;
Delete(upcasts_code);
upcasts_code = NULL;
Delete(global_proxy_imports);
@@ -681,17 +680,17 @@ public:
* D::pragmaDirective()
*
* Valid Pragmas:
- * wrapdmodulecode - text (D code) is copied verbatim to the wrap module
- * wrapdmoduleimports - import statements for the wrap module
+ * imdmodulecode - text (D code) is copied verbatim to the wrap module
+ * imdmoduleimports - import statements for the im D module
*
* proxydmodulecode - text (D code) is copied verbatim to the proxy module
* (the main proxy module if in split proxy mode).
* globalproxyimports - import statements inserted into _all_ proxy modules.
*
* wrapperloadercode - D code for loading the wrapper library (is copied to
- * the wrap D module).
+ * the im D module).
* wrapperloaderbindcommand - D code for binding a symbol from the wrapper
- * library to the declaration in the wrap D module.
+ * library to the declaration in the im D module.
* --------------------------------------------------------------------------- */
virtual int pragmaDirective(Node *n) {
if (!ImportMode) {
@@ -703,12 +702,12 @@ public:
String *strvalue = NewString(value);
Replaceall(strvalue, "\\\"", "\"");
- if (Strcmp(code, "wrapdmodulecode") == 0) {
- Printf(wrap_dmodule_code, "%s\n", strvalue);
- } else if (Strcmp(code, "wrapdmoduleimports") == 0) {
+ if (Strcmp(code, "imdmodulecode") == 0) {
+ Printf(im_dmodule_code, "%s\n", strvalue);
+ } else if (Strcmp(code, "imdmoduleimports") == 0) {
replaceImportTypeMacros(strvalue);
Chop(strvalue);
- Printf(wrap_dmodule_imports, "%s\n", strvalue);
+ Printf(im_dmodule_imports, "%s\n", strvalue);
} else if (Strcmp(code, "proxydmodulecode") == 0) {
Printf(proxy_dmodule_code, "%s\n", strvalue);
} else if (Strcmp(code, "globalproxyimports") == 0) {
@@ -1035,24 +1034,24 @@ public:
// Typemaps were attached earlier to the node, get the return type of the
// call to the C++ constructor wrapper.
- const String *wrapper_return_type = lookupDTypemap(n, "dwtype", true);
+ const String *wrapper_return_type = lookupDTypemap(n, "imtype", true);
- String *dwtypeout = Getattr(n, "tmap:dwtype:out");
- if (dwtypeout) {
- // The type in the dwtype typemap's out attribute overrides the type in
+ String *imtypeout = Getattr(n, "tmap:imtype:out");
+ if (imtypeout) {
+ // The type in the imtype typemap's out attribute overrides the type in
// the typemap itself.
- wrapper_return_type = dwtypeout;
+ wrapper_return_type = imtypeout;
}
Printf(proxy_constructor_code, "\n%s this(", methodmods);
Printf(helper_code, "static private %s SwigConstruct%s(",
wrapper_return_type, proxy_class_name);
- Printv(imcall, wrap_dmodule_fq_name, ".", mangled_overname, "(", NIL);
+ Printv(imcall, im_dmodule_fq_name, ".", mangled_overname, "(", NIL);
/* Attach the non-standard typemaps to the parameter list */
Swig_typemap_attach_parms("in", l, NULL);
- Swig_typemap_attach_parms("dptype", l, NULL);
+ Swig_typemap_attach_parms("dtype", l, NULL);
Swig_typemap_attach_parms("din", l, NULL);
emit_mark_varargs(l);
@@ -1078,12 +1077,12 @@ public:
String *param_type = NewString("");
// Get the D parameter type.
- if ((tm = lookupDTypemap(p, "dptype", true))) {
- const String *inattributes = Getattr(p, "tmap:dptype:inattributes");
+ if ((tm = lookupDTypemap(p, "dtype", true))) {
+ const String *inattributes = Getattr(p, "tmap:dtype:inattributes");
Printf(param_type, "%s%s", inattributes ? inattributes : empty_string, tm);
} else {
- Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
- "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ Swig_warning(WARN_D_TYPEMAP_DTYPE_UNDEF, input_file, line_number,
+ "No dtype typemap defined for %s\n", SwigType_str(pt, 0));
}
if (gencomma)
@@ -1093,7 +1092,7 @@ public:
String *parmtype = 0;
// Get the D code to convert the parameter value to the type used in the
- // wrapper D module.
+ // intermediary D module.
if ((tm = lookupDTypemap(p, "din"))) {
Replaceall(tm, "$dinput", arg);
String *pre = Getattr(p, "tmap:din:pre");
@@ -1198,10 +1197,10 @@ public:
Printf(helper_code, "\n}\n");
String *helper_name = NewStringf("%s.SwigConstruct%s(%s)",
proxy_class_name, proxy_class_name, helper_args);
- Replaceall(proxy_constructor_code, "$wcall", helper_name);
+ Replaceall(proxy_constructor_code, "$imcall", helper_name);
Delete(helper_name);
} else {
- Replaceall(proxy_constructor_code, "$wcall", imcall);
+ Replaceall(proxy_constructor_code, "$imcall", imcall);
}
Printv(proxy_class_body_code, proxy_constructor_code, "\n", NIL);
@@ -1224,7 +1223,7 @@ public:
virtual int destructorHandler(Node *n) {
Language::destructorHandler(n);
String *symname = Getattr(n, "sym:name");
- Printv(destructor_call, wrap_dmodule_fq_name, ".", Swig_name_destroy(NSPACE_TODO,symname), "(cast(void*)swigCPtr)", NIL);
+ Printv(destructor_call, im_dmodule_fq_name, ".", Swig_name_destroy(NSPACE_TODO,symname), "(cast(void*)swigCPtr)", NIL);
return SWIG_OK;
}
@@ -1254,7 +1253,7 @@ public:
emitBanner(class_file);
Printf(class_file, "module %s%s;\n", package, proxy_class_name);
- Printf(class_file, "\nstatic import %s;\n", wrap_dmodule_fq_name);
+ Printf(class_file, "\nstatic import %s;\n", im_dmodule_fq_name);
}
Clear(proxy_class_imports);
@@ -1342,23 +1341,23 @@ public:
ParmList *l = Getattr(n, "parms");
// Attach the non-standard typemaps to the parameter list.
- Swig_typemap_attach_parms("dptype", l, NULL);
+ Swig_typemap_attach_parms("dtype", l, NULL);
// Get D return type.
String *return_type = NewString("");
String *tm;
- if ((tm = lookupDTypemap(n, "dptype"))) {
- String *dptypeout = Getattr(n, "tmap:dptype:out");
- if (dptypeout) {
+ if ((tm = lookupDTypemap(n, "dtype"))) {
+ String *dtypeout = Getattr(n, "tmap:dtype:out");
+ if (dtypeout) {
// The type in the out attribute of the typemap overrides the type
- // in the dptype typemap.
- tm = dptypeout;
+ // in the dtype typemap.
+ tm = dtypeout;
replaceClassname(tm, t);
}
Printf(return_type, "%s", tm);
} else {
- Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
- "No dptype typemap defined for %s\n", SwigType_str(t, 0));
+ Swig_warning(WARN_D_TYPEMAP_DTYPE_UNDEF, input_file, line_number,
+ "No dtype typemap defined for %s\n", SwigType_str(t, 0));
}
const String *itemname = wrapping_member_flag ? variable_name : symname;
@@ -1448,33 +1447,33 @@ public:
String *wname = Swig_name_wrapper(overloaded_name);
/* Attach the non-standard typemaps to the parameter list. */
- Swig_typemap_attach_parms("cwtype", l, f);
- Swig_typemap_attach_parms("dwtype", l, f);
+ Swig_typemap_attach_parms("ctype", l, f);
+ Swig_typemap_attach_parms("imtype", l, f);
/* Get return types */
- if ((tm = lookupDTypemap(n, "cwtype"))) {
- String *cwtypeout = Getattr(n, "tmap:cwtype:out");
- if (cwtypeout) {
- // The type in the cwtype typemap's out attribute overrides the type in
+ if ((tm = lookupDTypemap(n, "ctype"))) {
+ String *ctypeout = Getattr(n, "tmap:ctype:out");
+ if (ctypeout) {
+ // The type in the ctype typemap's out attribute overrides the type in
// the typemap itself.
- tm = cwtypeout;
+ tm = ctypeout;
}
Printf(c_return_type, "%s", tm);
} else {
- Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number,
- "No cwtype typemap defined for %s\n", SwigType_str(t, 0));
+ Swig_warning(WARN_D_TYPEMAP_CTYPE_UNDEF, input_file, line_number,
+ "No ctype typemap defined for %s\n", SwigType_str(t, 0));
}
- if ((tm = lookupDTypemap(n, "dwtype"))) {
- String *dwtypeout = Getattr(n, "tmap:dwtype:out");
- if (dwtypeout) {
- // The type in the dwtype typemap's out attribute overrides the type in
+ if ((tm = lookupDTypemap(n, "imtype"))) {
+ String *imtypeout = Getattr(n, "tmap:imtype:out");
+ if (imtypeout) {
+ // The type in the imtype typemap's out attribute overrides the type in
// the typemap itself.
- tm = dwtypeout;
+ tm = imtypeout;
}
Printf(im_return_type, "%s", tm);
} else {
- Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number, "No dwtype typemap defined for %s\n", SwigType_str(t, 0));
+ Swig_warning(WARN_D_TYPEMAP_IMTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(t, 0));
}
is_void_return = (Cmp(c_return_type, "void") == 0);
@@ -1501,9 +1500,9 @@ public:
return SWIG_OK;
}
- // Collect the parameter list for the wrap D module declaration of the
- // generated wrapper function.
- String *wrap_dmodule_parameters = NewString("(");
+ // Collect the parameter list for the intermediary D module declaration of
+ // the generated wrapper function.
+ String *im_dmodule_parameters = NewString("(");
/* Get number of required and total arguments */
num_arguments = emit_num_arguments(l);
@@ -1525,25 +1524,25 @@ public:
Printf(arg, "j%s", ln);
- /* Get the cwtype types of the parameter */
- if ((tm = lookupDTypemap(p, "cwtype", true))) {
+ /* Get the ctype types of the parameter */
+ if ((tm = lookupDTypemap(p, "ctype", true))) {
Printv(c_param_type, tm, NIL);
} else {
- Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number, "No cwtype typemap defined for %s\n", SwigType_str(pt, 0));
+ Swig_warning(WARN_D_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s\n", SwigType_str(pt, 0));
}
/* Get the intermediary class parameter types of the parameter */
- if ((tm = lookupDTypemap(p, "dwtype", true))) {
- const String *inattributes = Getattr(p, "tmap:dwtype:inattributes");
+ if ((tm = lookupDTypemap(p, "imtype", true))) {
+ const String *inattributes = Getattr(p, "tmap:imtype:inattributes");
Printf(im_param_type, "%s%s", inattributes ? inattributes : empty_string, tm);
} else {
- Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number, "No dwtype typemap defined for %s\n", SwigType_str(pt, 0));
+ Swig_warning(WARN_D_TYPEMAP_IMTYPE_UNDEF, input_file, line_number, "No imtype typemap defined for %s\n", SwigType_str(pt, 0));
}
/* Add parameter to intermediary class method */
if (gencomma)
- Printf(wrap_dmodule_parameters, ", ");
- Printf(wrap_dmodule_parameters, "%s %s", im_param_type, arg);
+ Printf(im_dmodule_parameters, ", ");
+ Printf(im_dmodule_parameters, "%s %s", im_param_type, arg);
// Add parameter to C function
Printv(f->def, gencomma ? ", " : "", c_param_type, " ", arg, NIL);
@@ -1674,11 +1673,11 @@ public:
}
}
- // Complete D wrapper parameter list and emit the declaration/binding code.
- Printv(wrap_dmodule_parameters, ")", NIL);
- writeWrapDModuleFunction(overloaded_name, im_return_type,
- wrap_dmodule_parameters, wname);
- Delete(wrap_dmodule_parameters);
+ // Complete D im parameter list and emit the declaration/binding code.
+ Printv(im_dmodule_parameters, ")", NIL);
+ writeImDModuleFunction(overloaded_name, im_return_type,
+ im_dmodule_parameters, wname);
+ Delete(im_dmodule_parameters);
// Finish C function header.
Printf(f->def, ") {");
@@ -1931,32 +1930,32 @@ public:
/* Create the intermediate class wrapper */
Parm *tp = NewParm(returntype, empty_str, n);
- tm = lookupDTypemap(tp, "dwtype");
+ tm = lookupDTypemap(tp, "imtype");
if (tm) {
- String *dwtypeout = Getattr(tp, "tmap:dwtype:out");
- if (dwtypeout) {
- // The type in the dwtype typemap's out attribute overrides the type
+ String *imtypeout = Getattr(tp, "tmap:imtype:out");
+ if (imtypeout) {
+ // The type in the imtype typemap's out attribute overrides the type
// in the typemap.
- tm = dwtypeout;
+ tm = imtypeout;
}
Printf(callback_def, "\nprivate extern(C) %s swigDirectorCallback_%s_%s(void* dObject", tm, classname, overloaded_name);
Printv(proxy_callback_return_type, tm, NIL);
} else {
- Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number,
- "No dwtype typemap defined for %s\n", SwigType_str(returntype, 0));
+ Swig_warning(WARN_D_TYPEMAP_IMTYPE_UNDEF, input_file, line_number,
+ "No imtype typemap defined for %s\n", SwigType_str(returntype, 0));
}
Parm *retpm = NewParm(returntype, empty_str, n);
- if ((c_ret_type = Swig_typemap_lookup("cwtype", retpm, "", 0))) {
+ if ((c_ret_type = Swig_typemap_lookup("ctype", retpm, "", 0))) {
if (!is_void && !ignored_method) {
String *jretval_decl = NewStringf("%s jresult", c_ret_type);
Wrapper_add_localv(w, "jresult", jretval_decl, "= 0", NIL);
Delete(jretval_decl);
}
} else {
- Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number,
- "No cwtype typemap defined for %s for use in %s::%s (skipping director method)\n",
+ Swig_warning(WARN_D_TYPEMAP_CTYPE_UNDEF, input_file, line_number,
+ "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(returntype, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
@@ -1980,9 +1979,9 @@ public:
// Attach the standard typemaps.
Swig_typemap_attach_parms("out", l, 0);
- Swig_typemap_attach_parms("cwtype", l, 0);
- Swig_typemap_attach_parms("dwtype", l, 0);
- Swig_typemap_attach_parms("dptype", l, 0);
+ Swig_typemap_attach_parms("ctype", l, 0);
+ Swig_typemap_attach_parms("imtype", l, 0);
+ Swig_typemap_attach_parms("dtype", l, 0);
Swig_typemap_attach_parms("directorin", l, 0);
Swig_typemap_attach_parms("ddirectorin", l, 0);
@@ -2026,12 +2025,12 @@ public:
Printf(dcallback_call_args, ", %s", arg);
/* Get parameter's intermediary C type */
- if ((c_param_type = lookupDTypemap(p, "cwtype", true))) {
- String *cwtypeout = Getattr(p, "tmap:cwtype:out");
- if (cwtypeout) {
- // The type in the cwtype typemap's out attribute overrides the type
+ if ((c_param_type = lookupDTypemap(p, "ctype", true))) {
+ String *ctypeout = Getattr(p, "tmap:ctype:out");
+ if (ctypeout) {
+ // The type in the ctype typemap's out attribute overrides the type
// in the typemap itself.
- c_param_type = cwtypeout;
+ c_param_type = ctypeout;
}
Parm *tp = NewParm(c_param_type, empty_str, n);
@@ -2060,14 +2059,14 @@ public:
/* Add parameter to the intermediate class code if generating the
* intermediate's upcall code */
- if ((tm = lookupDTypemap(p, "dwtype", true))) {
- String *dwtypeout = Getattr(p, "tmap:dwtype:out");
- if (dwtypeout) {
- // The type in the dwtype typemap's out attribute overrides the
+ if ((tm = lookupDTypemap(p, "imtype", true))) {
+ String *imtypeout = Getattr(p, "tmap:imtype:out");
+ if (imtypeout) {
+ // The type in the imtype typemap's out attribute overrides the
// type in the typemap itself.
- tm = dwtypeout;
+ tm = imtypeout;
}
- const String *im_directorinattributes = Getattr(p, "tmap:dwtype:directorinattributes");
+ const String *im_directorinattributes = Getattr(p, "tmap:imtype:directorinattributes");
// TODO: Is this copy really needed?
String *din = Copy(lookupDTypemap(p, "ddirectorin", true));
@@ -2093,11 +2092,11 @@ public:
// Get the parameter type in the proxy D class (used later when
// generating the overload checking code for the directorConnect
// function).
- if ((tm = lookupDTypemap(p, "dptype", true))) {
+ if ((tm = lookupDTypemap(p, "dtype", true))) {
Printf(proxy_method_param_list, "%s", tm);
} else {
- Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
- "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ Swig_warning(WARN_D_TYPEMAP_DTYPE_UNDEF, input_file, line_number,
+ "No dtype typemap defined for %s\n", SwigType_str(pt, 0));
}
} else {
Swig_warning(WARN_D_TYPEMAP_DDIRECTORIN_UNDEF, input_file, line_number,
@@ -2106,8 +2105,8 @@ public:
output_director = false;
}
} else {
- Swig_warning(WARN_D_TYPEMAP_DWTYPE_UNDEF, input_file, line_number,
- "No dwtype typemap defined for %s for use in %s::%s (skipping director method)\n",
+ Swig_warning(WARN_D_TYPEMAP_IMTYPE_UNDEF, input_file, line_number,
+ "No imtype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
}
@@ -2133,8 +2132,8 @@ public:
Delete(tp);
} else {
- Swig_warning(WARN_D_TYPEMAP_CWTYPE_UNDEF, input_file, line_number,
- "No cwtype typemap defined for %s for use in %s::%s (skipping director method)\n",
+ Swig_warning(WARN_D_TYPEMAP_CTYPE_UNDEF, input_file, line_number,
+ "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
output_director = false;
p = nextSibling(p);
@@ -2198,7 +2197,7 @@ public:
// RESEARCH: What happens if there is no ddirectorout typemap?
if ((tm = lookupDTypemap(tp, "ddirectorout"))) {
- Replaceall(tm, "$dpcall", upcall);
+ Replaceall(tm, "$dcall", upcall);
Printf(callback_code, " return %s;\n", tm);
}
@@ -2288,18 +2287,18 @@ public:
// the full return type any longer after Language::functionHandler has
// returned.
Parm *tp = NewParm(returntype, empty_str, n);
- String *dp_return_type = lookupDTypemap(tp, "dptype");
+ String *dp_return_type = lookupDTypemap(tp, "dtype");
if (dp_return_type) {
- String *dptypeout = Getattr(n, "tmap:dptype:out");
- if (dptypeout) {
- // The type in the dptype typemap's out attribute overrides the type
+ String *dtypeout = Getattr(n, "tmap:dtype:out");
+ if (dtypeout) {
+ // The type in the dtype typemap's out attribute overrides the type
// in the typemap itself.
- dp_return_type = dptypeout;
+ dp_return_type = dtypeout;
replaceClassname(dp_return_type, returntype);
}
} else {
- Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
- "No dptype typemap defined for %s\n", SwigType_str(type, 0));
+ Swig_warning(WARN_D_TYPEMAP_DTYPE_UNDEF, input_file, line_number,
+ "No dtype typemap defined for %s\n", SwigType_str(type, 0));
dp_return_type = NewString("");
}
@@ -2313,10 +2312,10 @@ public:
Printf(director_callback_typedefs, "(void *dobj%s);\n", callback_typedef_parms);
Printf(director_callback_pointers, " SWIG_Callback%s_t swig_callback_%s;\n", methid, overloaded_name);
- // Write the type alias for the callback to the wrap D module.
+ // Write the type alias for the callback to the intermediary D module.
String* proxy_callback_type = NewString("");
Printf(proxy_callback_type, "SwigDirector_%s_Callback%s", classname, methid);
- Printf(wrap_dmodule_code, "alias extern(C) %s function(void*%s) %s;\n", proxy_callback_return_type, delegate_parms, proxy_callback_type);
+ Printf(im_dmodule_code, "alias extern(C) %s function(void*%s) %s;\n", proxy_callback_return_type, delegate_parms, proxy_callback_type);
Delete(proxy_callback_type);
}
@@ -2519,21 +2518,21 @@ protected:
private:
/* ---------------------------------------------------------------------------
- * D::writeWrapDModuleFunction()
+ * D::writeImDModuleFunction()
*
* Writes a function declaration for the given (C) wrapper function to the
- * wrap D module.
+ * intermediary D module.
*
- * d_name - The name the function in the D wrap module will get.
+ * d_name - The name the function in the intermediary D module will get.
* wrapper_function_name - The name of the exported function in the C wrapper
* (usually d_name prefixed by »D_«).
* --------------------------------------------------------------------------- */
- void writeWrapDModuleFunction(const_String_or_char_ptr d_name,
+ void writeImDModuleFunction(const_String_or_char_ptr d_name,
const_String_or_char_ptr return_type, const_String_or_char_ptr parameters,
const_String_or_char_ptr wrapper_function_name) {
// TODO: Add support for static linking here.
- Printf(wrap_dmodule_code, "extern(C) %s function%s %s;\n", return_type,
+ Printf(im_dmodule_code, "extern(C) %s function%s %s;\n", return_type,
parameters, d_name);
Printv(wrapper_loader_bind_code, wrapper_loader_bind_command, NIL);
Replaceall(wrapper_loader_bind_code, "$function", d_name);
@@ -2548,7 +2547,7 @@ private:
*
* The Node must contain two extra attributes.
* - "proxyfuncname": The name of the D proxy function.
- * - "imfuncname": The corresponding function in the wrap D module.
+ * - "imfuncname": The corresponding function in the intermediary D module.
* --------------------------------------------------------------------------- */
void writeProxyClassFunction(Node *n) {
SwigType *t = Getattr(n, "type");
@@ -2585,22 +2584,22 @@ private:
/* Attach the non-standard typemaps to the parameter list */
Swig_typemap_attach_parms("in", l, NULL);
- Swig_typemap_attach_parms("dptype", l, NULL);
+ Swig_typemap_attach_parms("dtype", l, NULL);
Swig_typemap_attach_parms("din", l, NULL);
// Get return types.
- if ((tm = lookupDTypemap(n, "dptype"))) {
- String *dptypeout = Getattr(n, "tmap:dptype:out");
- if (dptypeout) {
- // The type in the dptype typemap's out attribute overrides the type in
+ if ((tm = lookupDTypemap(n, "dtype"))) {
+ String *dtypeout = Getattr(n, "tmap:dtype:out");
+ if (dtypeout) {
+ // The type in the dtype typemap's out attribute overrides the type in
// the typemap.
- tm = dptypeout;
+ tm = dtypeout;
replaceClassname(tm, t);
}
Printf(return_type, "%s", tm);
} else {
- Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
- "No dptype typemap defined for %s\n", SwigType_str(t, 0));
+ Swig_warning(WARN_D_TYPEMAP_DTYPE_UNDEF, input_file, line_number,
+ "No dtype typemap defined for %s\n", SwigType_str(t, 0));
}
if (wrapping_member_flag) {
@@ -2644,7 +2643,7 @@ private:
Printf(function_code, "%s %s(", return_type, proxy_function_name);
// Write the wrapper function call up to the parameter list.
- Printv(imcall, wrap_dmodule_fq_name, ".$imfuncname(", NIL);
+ Printv(imcall, im_dmodule_fq_name, ".$imfuncname(", NIL);
if (!static_flag) {
Printf(imcall, "cast(void*)swigCPtr");
}
@@ -2714,12 +2713,12 @@ private:
{
String *proxy_type = NewString("");
- if ((tm = lookupDTypemap(p, "dptype"))) {
- const String *inattributes = Getattr(p, "tmap:dptype:inattributes");
+ if ((tm = lookupDTypemap(p, "dtype"))) {
+ const String *inattributes = Getattr(p, "tmap:dtype:inattributes");
Printf(proxy_type, "%s%s", inattributes ? inattributes : empty_string, tm);
} else {
- Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
- "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ Swig_warning(WARN_D_TYPEMAP_DTYPE_UNDEF, input_file, line_number,
+ "No dtype typemap defined for %s\n", SwigType_str(pt, 0));
}
if (gencomma >= 2)
@@ -2801,7 +2800,7 @@ private:
} else {
Replaceall(imcall, "$imfuncname", intermediary_function_name);
}
- Replaceall(tm, "$wcall", imcall);
+ Replaceall(tm, "$imcall", imcall);
} else {
Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,
"No dout typemap defined for %s\n", SwigType_str(t, 0));
@@ -2851,22 +2850,22 @@ private:
}
/* Attach the non-standard typemaps to the parameter list */
- Swig_typemap_attach_parms("dptype", l, NULL);
+ Swig_typemap_attach_parms("dtype", l, NULL);
Swig_typemap_attach_parms("din", l, NULL);
/* Get return types */
- if ((tm = lookupDTypemap(n, "dptype"))) {
- String *dptypeout = Getattr(n, "tmap:dptype:out");
- if (dptypeout) {
- // The type in the dptype typemap's out attribute overrides the type in
+ if ((tm = lookupDTypemap(n, "dtype"))) {
+ String *dtypeout = Getattr(n, "tmap:dtype:out");
+ if (dtypeout) {
+ // The type in the dtype typemap's out attribute overrides the type in
// the typemap.
- tm = dptypeout;
+ tm = dtypeout;
replaceClassname(tm, t);
}
Printf(return_type, "%s", tm);
} else {
- Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
- "No dptype typemap defined for %s\n", SwigType_str(t, 0));
+ Swig_warning(WARN_D_TYPEMAP_DTYPE_UNDEF, input_file, line_number,
+ "No dtype typemap defined for %s\n", SwigType_str(t, 0));
}
/* Change function name for global variables */
@@ -2878,7 +2877,7 @@ private:
}
/* Start generating the function */
- const String *outattributes = Getattr(n, "tmap:dptype:outattributes");
+ const String *outattributes = Getattr(n, "tmap:dtype:outattributes");
if (outattributes)
Printf(function_code, " %s\n", outattributes);
@@ -2888,7 +2887,7 @@ private:
methodmods = methodmods ? methodmods : empty_string;
Printf(function_code, "\n%s%s %s(", methodmods, return_type, func_name);
- Printv(imcall, wrap_dmodule_fq_name, ".", overloaded_name, "(", NIL);
+ Printv(imcall, im_dmodule_fq_name, ".", overloaded_name, "(", NIL);
/* Get number of required and total arguments */
num_arguments = emit_num_arguments(l);
@@ -2908,12 +2907,12 @@ private:
String *param_type = NewString("");
// Get the D parameter type.
- if ((tm = lookupDTypemap(p, "dptype", true))) {
- const String *inattributes = Getattr(p, "tmap:dptype:inattributes");
+ if ((tm = lookupDTypemap(p, "dtype", true))) {
+ const String *inattributes = Getattr(p, "tmap:dtype:inattributes");
Printf(param_type, "%s%s", inattributes ? inattributes : empty_string, tm);
} else {
- Swig_warning(WARN_D_TYPEMAP_DPTYPE_UNDEF, input_file, line_number,
- "No dptype typemap defined for %s\n", SwigType_str(pt, 0));
+ Swig_warning(WARN_D_TYPEMAP_DTYPE_UNDEF, input_file, line_number,
+ "No dtype typemap defined for %s\n", SwigType_str(pt, 0));
}
if (gencomma)
@@ -3003,7 +3002,7 @@ private:
else
Replaceall(tm, "$owner", "false");
replaceClassname(tm, t);
- Replaceall(tm, "$wcall", imcall);
+ Replaceall(tm, "$imcall", imcall);
} else {
Swig_warning(WARN_D_TYPEMAP_DOUT_UNDEF, input_file, line_number,
"No dout typemap defined for %s\n", SwigType_str(t, 0));
@@ -3214,9 +3213,9 @@ private:
Printv(dispose_code, tm, NIL);
if (*Char(destructor_call)) {
- Replaceall(dispose_code, "$wcall", destructor_call);
+ Replaceall(dispose_code, "$imcall", destructor_call);
} else {
- Replaceall(dispose_code, "$wcall", "throw new object.Exception(\"C++ destructor does not have public access\")");
+ Replaceall(dispose_code, "$imcall", "throw new object.Exception(\"C++ destructor does not have public access\")");
}
if (*Char(dispose_code)) {
@@ -3271,7 +3270,7 @@ private:
String *upcast_wrapper_name = Swig_name_wrapper(upcast_name);
- writeWrapDModuleFunction(upcast_name, "void*", "(void* objectRef)",
+ writeImDModuleFunction(upcast_name, "void*", "(void* objectRef)",
upcast_wrapper_name);
if (smartptr) {
@@ -3342,7 +3341,7 @@ private:
emitBanner(class_file);
Printf(class_file, "module %s%s;\n", package, classname);
- Printf(class_file, "\nstatic import %s;\n", wrap_dmodule_fq_name);
+ Printf(class_file, "\nstatic import %s;\n", im_dmodule_fq_name);
imports_target = NewString("");
code_target = NewString("");
@@ -3415,12 +3414,12 @@ private:
String *return_type = Getattr(udata, "return_type");
String *param_list = Getattr(udata, "param_list");
String *methid = Getattr(udata, "class_methodidx");
- Printf(proxy_class_body_code, " %s.SwigDirector_%s_Callback%s callback%s;\n", wrap_dmodule_fq_name, proxy_class_name, methid, methid);
+ Printf(proxy_class_body_code, " %s.SwigDirector_%s_Callback%s callback%s;\n", im_dmodule_fq_name, proxy_class_name, methid, methid);
Printf(proxy_class_body_code, " if (swigIsMethodOverridden!(%s delegate(%s), %s function(%s), %s)()) {\n", return_type, param_list, return_type, param_list, method);
Printf(proxy_class_body_code, " callback%s = &swigDirectorCallback_%s_%s;\n", methid, proxy_class_name, overloaded_name);
Printf(proxy_class_body_code, " }\n\n");
}
- Printf(proxy_class_body_code, " %s.%s_director_connect(cast(void*)swigCPtr, cast(void*)this", wrap_dmodule_fq_name, proxy_class_name);
+ Printf(proxy_class_body_code, " %s.%s_director_connect(cast(void*)swigCPtr, cast(void*)this", im_dmodule_fq_name, proxy_class_name);
for (i = first_class_dmethod; i < curr_class_dmethod; ++i) {
UpcallData *udata = Getitem(dmethods_seq, i);
String *methid = Getattr(udata, "class_methodidx");
@@ -3478,7 +3477,7 @@ private:
Replaceall(wrapper_loader_bind_code, "$function", connect_name);
Replaceall(wrapper_loader_bind_code, "$symbol", Swig_name_wrapper(connect_name));
- Printf(wrap_dmodule_code, "extern(C) void function(void* cObject, void* dObject");
+ Printf(im_dmodule_code, "extern(C) void function(void* cObject, void* dObject");
code_wrap = NewWrapper();
Printf(code_wrap->def, "SWIGEXPORT void D_%s(void *objarg, void *dobj", connect_name);
@@ -3495,12 +3494,12 @@ private:
Printf(code_wrap->def, ", SwigDirector_%s::SWIG_Callback%s_t callback%s", sym_name, methid, methid);
Printf(code_wrap->code, ", callback%s", methid);
- Printf(wrap_dmodule_code, ", SwigDirector_%s_Callback%s callback%s", sym_name, methid, methid);
+ Printf(im_dmodule_code, ", SwigDirector_%s_Callback%s callback%s", sym_name, methid, methid);
}
Printf(code_wrap->def, ") {\n");
Printf(code_wrap->code, ");\n");
- Printf(wrap_dmodule_code, ") %s;\n", connect_name);
+ Printf(im_dmodule_code, ") %s;\n", connect_name);
Printf(code_wrap->code, " }\n");
Printf(code_wrap->code, "}\n");
@@ -3647,8 +3646,8 @@ private:
* --------------------------------------------------------------------------- */
void assertClassNameValidity(const String* class_name) const {
if (split_proxy_dmodule) {
- if (Cmp(class_name, wrap_dmodule_name) == 0) {
- Swig_error(input_file, line_number, "Class name cannot be equal to wrap D module name: %s\n",
+ if (Cmp(class_name, im_dmodule_name) == 0) {
+ Swig_error(input_file, line_number, "Class name cannot be equal to intermediary D module name: %s\n",
class_name);
SWIG_exit(EXIT_FAILURE);
}
@@ -3691,7 +3690,7 @@ private:
// Now that we got rid of the pointers, see if we are dealing with a
// primitive type.
- String *dptype = 0;
+ String *dtype = 0;
if (SwigType_isfunction(stripped_type) && indirection_count > 0) {
// type was a function pointer, split it up.
SwigType_add_pointer(stripped_type);
@@ -3736,29 +3735,29 @@ private:
}
}
- dptype = NewStringf("%s function(%s)", return_dtype, param_list);
+ dtype = NewStringf("%s function(%s)", return_dtype, param_list);
Delete(param_list);
Delete(param_dtypes);
Delete(return_dtype);
} else {
Hash *attributes = NewHash();
const String *tm =
- lookupCodeTypemap(node, "dptype", stripped_type, WARN_NONE, attributes);
- if(!GetFlag(attributes, "tmap:dptype:cprimitive")) {
- dptype = 0;
+ lookupCodeTypemap(node, "dtype", stripped_type, WARN_NONE, attributes);
+ if(!GetFlag(attributes, "tmap:dtype:cprimitive")) {
+ dtype = 0;
} else {
- dptype = Copy(tm);
+ dtype = Copy(tm);
// We need to call replaceClassname here with the stripped type to avoid
// $dclassname in the enum typemaps being replaced later with the full
// type.
- replaceClassname(dptype, stripped_type);
+ replaceClassname(dtype, stripped_type);
}
Delete(attributes);
}
Delete(stripped_type);
- if (!dptype) {
+ if (!dtype) {
// The type passed is no primitive type.
return 0;
}
@@ -3766,16 +3765,16 @@ private:
// The type is ultimately a primitive type, now append the right number of
// indirection levels (pointers).
for (int i = 0; i < indirection_count; ++i) {
- Append(dptype, "*");
+ Append(dtype, "*");
}
// Add a level of indirection for a mutable reference since it is wrapped
// as a pointer.
if (mutable_ref) {
- Append(dptype, "*");
+ Append(dtype, "*");
}
- return dptype;
+ return dtype;
}
/* ---------------------------------------------------------------------------
@@ -3854,12 +3853,12 @@ private:
String *np_key = NewStringf("tmap:%s:nativepointer", method);
String *np_value = Getattr(n, np_key);
Delete(np_key);
- String *dptype;
- if (np_value && (dptype = getPrimitiveDptype(n, type))) {
+ String *dtype;
+ if (np_value && (dtype = getPrimitiveDptype(n, type))) {
// If the typemap in question has a »nativepointer« attribute and we
// are dealing with a primitive type, use it instead.
result = Copy(np_value);
- Replaceall(result, "$dptype", dptype);
+ Replaceall(result, "$dtype", dtype);
}
replaceClassname(result, type);
@@ -4007,11 +4006,11 @@ private:
/* ---------------------------------------------------------------------------
* D::replaceModuleVariables()
*
- * Replaces the $wrapdmodule and $module variables with their values in the
+ * Replaces the $imdmodule and $module variables with their values in the
* target string.
* --------------------------------------------------------------------------- */
void replaceModuleVariables(String *target) const {
- Replaceall(target, "$wrapdmodule", wrap_dmodule_fq_name);
+ Replaceall(target, "$imdmodule", im_dmodule_fq_name);
Replaceall(target, "$module", proxy_dmodule_name);
}
From d87c312fd0db86072633e4d219452c26d0d76f43 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Mon, 29 Nov 2010 07:49:42 +0000
Subject: [PATCH 028/317] Corrections to calls to SwigType_manglestr to use a
genuine SwigType
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12320 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/Modules/go.cxx | 4 ++--
Source/Modules/lua.cxx | 2 +-
Source/Modules/mzscheme.cxx | 2 +-
Source/Modules/tcl8.cxx | 5 +----
4 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx
index 6e8d2c09a..ac8ba333d 100644
--- a/Source/Modules/go.cxx
+++ b/Source/Modules/go.cxx
@@ -1128,7 +1128,7 @@ private:
Parm *base_parm = NULL;
if (base && !isStatic(n)) {
- SwigType *base_type = Copy(Getattr(class_node, "classtype"));
+ SwigType *base_type = Copy(getClassType());
SwigType_add_pointer(base_type);
base_parm = NewParm(base_type, NewString("arg1"), n);
set_nextSibling(base_parm, parms);
@@ -1244,7 +1244,7 @@ private:
Parm *base_parm = NULL;
if (base && !isStatic(n)) {
- SwigType *base_type = Copy(Getattr(class_node, "classtype"));
+ SwigType *base_type = Copy(getClassType());
SwigType_add_pointer(base_type);
base_parm = NewParm(base_type, NewString("arg1"), n);
set_nextSibling(base_parm, parms);
diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx
index d240d3d6f..d0cbc9195 100644
--- a/Source/Modules/lua.cxx
+++ b/Source/Modules/lua.cxx
@@ -919,7 +919,7 @@ public:
String *wrap_class = NewStringf("&_wrap_class_%s", mangled_classname);
SwigType_remember_clientdata(t, wrap_class);
- String *rt = Copy(Getattr(n, "classtype"));
+ String *rt = Copy(getClassType());
SwigType_add_pointer(rt);
// Register the class structure with the type checker
diff --git a/Source/Modules/mzscheme.cxx b/Source/Modules/mzscheme.cxx
index 0bc3c8a68..d071dc870 100644
--- a/Source/Modules/mzscheme.cxx
+++ b/Source/Modules/mzscheme.cxx
@@ -682,7 +682,7 @@ public:
String *mangled_classname = 0;
String *real_classname = 0;
String *scm_structname = NewString("");
- SwigType *ctype_ptr = NewStringf("p.%s", Getattr(n, "classtype"));
+ SwigType *ctype_ptr = NewStringf("p.%s", getClassType());
SwigType *t = NewStringf("p.%s", Getattr(n, "name"));
swigtype_ptr = SwigType_manglestr(t);
diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx
index b6b4c6965..dfdd71b64 100644
--- a/Source/Modules/tcl8.cxx
+++ b/Source/Modules/tcl8.cxx
@@ -783,10 +783,7 @@ public:
String *wrap_class = NewStringf("&_wrap_class_%s", mangled_classname);
SwigType_remember_clientdata(t, wrap_class);
- // t = Copy(Getattr(n,"classtype"));
- // SwigType_add_pointer(t);
-
- String *rt = Copy(Getattr(n, "classtype"));
+ String *rt = Copy(getClassType());
SwigType_add_pointer(rt);
// Register the class structure with the type checker
From 24591490c2ffc260583e853aa7106048fcb09928 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Fri, 3 Dec 2010 17:29:07 +0000
Subject: [PATCH 029/317] Mention SWIG_FEATURES for running the test-suite
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12321 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Doc/Manual/Extending.html | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/Doc/Manual/Extending.html b/Doc/Manual/Extending.html
index 072f28963..35ccc4e15 100644
--- a/Doc/Manual/Extending.html
+++ b/Doc/Manual/Extending.html
@@ -3477,6 +3477,24 @@ A debugger can also be invoked easily on an individual test, for example gdb:
make ret_by_value.ctest RUNTOOL="gdb --args"
+
+SWIG reads the SWIG_FEATURES environment variable to obtain options in addition to those passed on the command line.
+This is particularly useful as the entire test-suite or a particular testcase can be run customized by using additional
+arguments, for example the -O optimization flag can be added in, as shown below for the bash shell:
+
+
+
+env SWIG_FEATURES=-O make check-python-test-suite
+
+
+
+The syntax for setting environment variables varies from one shell to the next, but it also works as shown in the example below, where some typemap debugging is added in:
+
+
+
+make ret_by_value.ctest SWIG_FEATURES="-debug-tmsearch"
+
+
36.10.13 Documentation
From 02750e80a3f24c3f2cd86bf0cfc52b8d537cfc16 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Mon, 6 Dec 2010 20:43:56 +0000
Subject: [PATCH 030/317] Fix #3127394 - use of network paths on Windows/MSys.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12322 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 3 +++
Source/Swig/misc.c | 18 +++++++++++++-----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/CHANGES.current b/CHANGES.current
index 0b0bc59e7..d91779931 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (in progress)
===========================
+2010-12-06: wsfulton
+ Fix #3127394 - use of network paths on Windows/MSys.
+
2010-11-18: klickverbot
[D] Added the D language module.
diff --git a/Source/Swig/misc.c b/Source/Swig/misc.c
index 73510b513..9868ee844 100644
--- a/Source/Swig/misc.c
+++ b/Source/Swig/misc.c
@@ -220,7 +220,14 @@ String *Swig_new_subdirectory(String *basedirectory, String *subdirectory) {
* ----------------------------------------------------------------------------- */
void Swig_filename_correct(String *filename) {
- (void)filename;
+ int network_path = 0;
+ if (Len(filename) >= 2) {
+ const char *fname = Char(filename);
+ if (fname[0] == '\\' && fname[1] == '\\')
+ network_path = 1;
+ if (fname[0] == '/' && fname[1] == '/')
+ network_path = 1;
+ }
#if defined(_WIN32) || defined(MACSWIG)
/* accept Unix path separator on non-Unix systems */
Replaceall(filename, "/", SWIG_FILE_DELIMITER);
@@ -232,6 +239,9 @@ void Swig_filename_correct(String *filename) {
/* remove all duplicate file name delimiters */
while (Replaceall(filename, SWIG_FILE_DELIMITER SWIG_FILE_DELIMITER, SWIG_FILE_DELIMITER)) {
}
+ /* Network paths can start with a double slash on Windows - unremove the duplicate slash we just removed */
+ if (network_path)
+ Insert(filename, 0, SWIG_FILE_DELIMITER);
}
/* -----------------------------------------------------------------------------
@@ -242,13 +252,11 @@ void Swig_filename_correct(String *filename) {
String *Swig_filename_escape(String *filename) {
String *adjusted_filename = Copy(filename);
+ Swig_filename_correct(adjusted_filename);
#if defined(_WIN32) /* Note not on Cygwin else filename is displayed with double '/' */
- /* remove all double '\' in case any already present */
- while (Replaceall(adjusted_filename, "\\\\", "\\")) {
- }
Replaceall(adjusted_filename, "\\", "\\\\");
#endif
- return adjusted_filename;
+ return adjusted_filename;
}
/* -----------------------------------------------------------------------------
From 6d75f6cc1c99e66445f376455fccc6052b2a53b5 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor
Date: Tue, 7 Dec 2010 20:01:59 +0000
Subject: [PATCH 031/317] Disable Go (6g/8g) if the version is too old.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12323 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
configure.in | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/configure.in b/configure.in
index 5383c40c7..f9410fdf8 100644
--- a/configure.in
+++ b/configure.in
@@ -2009,6 +2009,12 @@ else
GOGCC=false
if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then
GOGCC=true
+ else
+ go_version=`$GO -V | sed -e 's/.*version \([[0-9]]*\).*/\1/'`
+ if test "$go_version" -lt 6707; then
+ AC_MSG_NOTICE([Installed Go too old; disabling Go])
+ GO=
+ fi
fi
fi
From 8467a6926e36628f907a3940474aca80eb78b4a1 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor
Date: Tue, 7 Dec 2010 20:03:47 +0000
Subject: [PATCH 032/317] We disable Go if the compiler is too old.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12324 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CHANGES.current b/CHANGES.current
index d91779931..b8b1b51fa 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,11 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (in progress)
===========================
+2010-12-07: iant
+ *** POTENTIAL INCOMPATIBILITY ***
+ Check that we are using a sufficiently new version of the
+ 6g or 8g Go compiler. If not, disable Go.
+
2010-12-06: wsfulton
Fix #3127394 - use of network paths on Windows/MSys.
From 61fefd8cc4c5cb71cdc15dd758a44407bd0d46fe Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Tue, 7 Dec 2010 20:12:17 +0000
Subject: [PATCH 033/317] Remove bad usage of a String rather than SwigType for
csharp directors
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12325 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/Modules/csharp.cxx | 25 +++++--------------------
1 file changed, 5 insertions(+), 20 deletions(-)
diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
index e0c4a4332..6ecd18aed 100644
--- a/Source/Modules/csharp.cxx
+++ b/Source/Modules/csharp.cxx
@@ -3641,17 +3641,13 @@ public:
if (ctypeout)
c_param_type = ctypeout;
- Parm *tp = NewParm(c_param_type, empty_str, n);
- String *desc_tm = NULL;
-
/* Add to local variables */
Printf(c_decl, "%s %s", c_param_type, arg);
if (!ignored_method)
Wrapper_add_localv(w, arg, c_decl, (!(SwigType_ispointer(pt) || SwigType_isreference(pt)) ? "" : "= 0"), NIL);
/* Add input marshalling code */
- if ((desc_tm = Swig_typemap_lookup("directorin", tp, "", 0))
- && (tm = Getattr(p, "tmap:directorin"))) {
+ if ((tm = Getattr(p, "tmap:directorin"))) {
Replaceall(tm, "$input", arg);
Replaceall(tm, "$owner", "0");
@@ -3716,24 +3712,13 @@ public:
p = Getattr(p, "tmap:directorin:next");
- Delete(desc_tm);
} else {
- if (!desc_tm) {
- Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number,
- "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
- SwigType_str(c_param_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
- p = nextSibling(p);
- } else if (!tm) {
- Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number,
- "No or improper directorin typemap defined for argument %s for use in %s::%s (skipping director method)\n",
- SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
- p = nextSibling(p);
- }
-
+ Swig_warning(WARN_CSHARP_TYPEMAP_CSDIRECTORIN_UNDEF, input_file, line_number,
+ "No or improper directorin typemap defined for argument %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ p = nextSibling(p);
output_director = false;
}
-
- Delete(tp);
} else {
Swig_warning(WARN_CSHARP_TYPEMAP_CTYPE_UNDEF, input_file, line_number, "No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
From f4e5cd4f882d5001acc93d029cd141bf07c390e3 Mon Sep 17 00:00:00 2001
From: Stefan Zager
Date: Tue, 7 Dec 2010 20:32:19 +0000
Subject: [PATCH 034/317] Branch for development of -builtin option for python.
With this option, swig will produce new built-in python
types for all wrapped classes. Built-in types offer a
substantial performance benefit compared to the current
shadow class implementation.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12326 626c5289-ae23-0410-ae9c-e8d60b6d4f22
From 5558d0092acaf666804421795a7e631fe8dcec88 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Tue, 7 Dec 2010 21:15:05 +0000
Subject: [PATCH 035/317] Remove bad usage of a String rather than SwigType for
D directors
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12330 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/Modules/d.cxx | 30 +++++++-----------------------
1 file changed, 7 insertions(+), 23 deletions(-)
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
index 63da28a81..986079d65 100644
--- a/Source/Modules/d.cxx
+++ b/Source/Modules/d.cxx
@@ -2033,17 +2033,13 @@ public:
c_param_type = ctypeout;
}
- Parm *tp = NewParm(c_param_type, empty_str, n);
- String *desc_tm = NULL;
-
/* Add to local variables */
Printf(c_decl, "%s %s", c_param_type, arg);
if (!ignored_method)
Wrapper_add_localv(w, arg, c_decl, (!(SwigType_ispointer(pt) || SwigType_isreference(pt)) ? "" : "= 0"), NIL);
/* Add input marshalling code */
- if ((desc_tm = Swig_typemap_lookup("directorin", tp, "", 0))
- && (tm = Getattr(p, "tmap:directorin"))) {
+ if ((tm = Getattr(p, "tmap:directorin"))) {
Replaceall(tm, "$input", arg);
Replaceall(tm, "$owner", "0");
@@ -2068,7 +2064,7 @@ public:
}
const String *im_directorinattributes = Getattr(p, "tmap:imtype:directorinattributes");
- // TODO: Is this copy really needed?
+ // TODO: Is this copy really needed?
String *din = Copy(lookupDTypemap(p, "ddirectorin", true));
if (din) {
@@ -2087,7 +2083,7 @@ public:
Printv(imcall_args, ln, NIL);
}
- Delete(din);
+ Delete(din);
// Get the parameter type in the proxy D class (used later when
// generating the overload checking code for the directorConnect
@@ -2112,25 +2108,13 @@ public:
}
p = Getattr(p, "tmap:directorin:next");
-
- Delete(desc_tm);
} else {
- if (!desc_tm) {
- Swig_warning(WARN_D_TYPEMAP_DDIRECTORIN_UNDEF, input_file, line_number,
- "No or improper directorin typemap defined for %s for use in %s::%s (skipping director method)\n",
- SwigType_str(c_param_type, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
- p = nextSibling(p);
- } else if (!tm) {
- Swig_warning(WARN_D_TYPEMAP_DDIRECTORIN_UNDEF, input_file, line_number,
- "No or improper directorin typemap defined for argument %s for use in %s::%s (skipping director method)\n",
- SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
- p = nextSibling(p);
- }
-
+ Swig_warning(WARN_D_TYPEMAP_DDIRECTORIN_UNDEF, input_file, line_number,
+ "No or improper directorin typemap defined for argument %s for use in %s::%s (skipping director method)\n",
+ SwigType_str(pt, 0), SwigType_namestr(c_classname), SwigType_namestr(name));
+ p = nextSibling(p);
output_director = false;
}
-
- Delete(tp);
} else {
Swig_warning(WARN_D_TYPEMAP_CTYPE_UNDEF, input_file, line_number,
"No ctype typemap defined for %s for use in %s::%s (skipping director method)\n",
From ee3a6623dadeb5d06e19dcbd7372fa049e9ef4b2 Mon Sep 17 00:00:00 2001
From: Stefan Zager
Date: Tue, 7 Dec 2010 21:50:00 +0000
Subject: [PATCH 036/317] First cut. Works for wrapping OpenAccess, but
there's plenty left to do.
Currently, the test suite hurls at director_stl.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12332 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/python/builtin.swg | 28 +
Lib/python/pycontainer.swg | 5 +
Lib/python/pyinit.swg | 12 +-
Lib/python/pyiterators.swg | 23 +
Lib/python/pyrun.swg | 208 ++--
Lib/python/pyruntime.swg | 1 +
Lib/python/pytypemaps.swg | 17 +
Source/Modules/python.cxx | 2266 +++++++++++++++++++++---------------
8 files changed, 1520 insertions(+), 1040 deletions(-)
create mode 100644 Lib/python/builtin.swg
diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg
new file mode 100644
index 000000000..556b113af
--- /dev/null
+++ b/Lib/python/builtin.swg
@@ -0,0 +1,28 @@
+#ifdef __cplusplus
+
+namespace {
+
+template struct PySwigBuiltin : public SwigPyObject {
+
+ typedef PySwigBuiltin<_Tp> this_type;
+ typedef _Tp obj_type;
+ typedef obj_type* pointer;
+ typedef obj_type& reference;
+
+ static PyMethodDef methods[];
+ static PyTypeObject pytype;
+ static SwigPyClientData clientdata;
+};
+
+template void py_builtin_dealloc (PyObject *pyobj)
+{
+ typedef PySwigBuiltin<_Tp> builtin_type;
+ builtin_type *obj = (builtin_type*) pyobj;
+ if (obj->own)
+ delete reinterpret_cast<_Tp*>(obj->ptr);
+ (*pyobj->ob_type->tp_free)(pyobj);
+}
+
+} // namespace {
+
+#endif
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index 40506e15b..27e145362 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -580,6 +580,9 @@ namespace swig
%fragment("SwigPySequence_Cont");
+# if defined(SWIGPYTHON_BUILTIN)
+ %feature("tp_iter") Sequence "&swig::make_output_iterator_builtin< Sequence >";
+# else
%newobject iterator(PyObject **PYTHON_SELF);
%extend {
swig::SwigPyIterator* iterator(PyObject **PYTHON_SELF) {
@@ -588,6 +591,8 @@ namespace swig
%pythoncode {def __iter__(self): return self.iterator()}
}
+# endif // SWIGPYTHON_BUILTIN
+
#endif //SWIG_EXPORT_ITERATOR_METHODS
%enddef
diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg
index 5af8d2491..5ee13f34b 100644
--- a/Lib/python/pyinit.swg
+++ b/Lib/python/pyinit.swg
@@ -320,7 +320,8 @@ SWIGEXPORT
void
#endif
SWIG_init(void) {
- PyObject *m, *d;
+ PyObject *m, *d, *md;
+ PyTypeObject *builtin_type;
#if PY_VERSION_HEX >= 0x03000000
static struct PyModuleDef SWIG_module = {
PyModuleDef_HEAD_INIT,
@@ -335,6 +336,13 @@ SWIG_init(void) {
};
#endif
+#if defined(SWIGPYTHON_BUILTIN)
+ PyTypeObject *builtin_pytype = 0;
+ swig_type_info *builtin_basetype = 0;
+
+ SWIG_Python_builtin_imports();
+#endif
+
/* Fix SwigMethods to carry the callback ptrs when needed */
SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial);
@@ -343,7 +351,7 @@ SWIG_init(void) {
#else
m = Py_InitModule((char *) SWIG_name, SwigMethods);
#endif
- d = PyModule_GetDict(m);
+ md = d = PyModule_GetDict(m);
SWIG_InitializeModule(0);
SWIG_InstallConstants(d,swig_const_table);
diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg
index 3c39f9710..ecbc54270 100644
--- a/Lib/python/pyiterators.swg
+++ b/Lib/python/pyiterators.swg
@@ -302,6 +302,24 @@ namespace swig {
{
return new SwigPyIteratorOpen_T(current, seq);
}
+
+ template
+ inline PyObject* make_output_iterator_builtin (PyObject *pyself)
+ {
+ SwigPyObject *builtin_obj = (SwigPyObject*) pyself;
+ Sequence *seq = reinterpret_cast< Sequence * >(builtin_obj->ptr);
+ if (!seq)
+ return SWIG_Py_Void();
+ SwigPyIterator *iter = make_output_iterator(seq->begin(), seq->begin(), seq->end(), pyself);
+ return SWIG_NewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN);
+ }
+
+ template <>
+ inline PyObject* make_output_iterator_builtin (PyObject *pyself)
+ {
+ Py_INCREF(pyself);
+ return pyself;
+ }
}
}
@@ -329,9 +347,14 @@ namespace swig
%newobject SwigPyIterator::operator - (ptrdiff_t n) const;
%nodirector SwigPyIterator;
+
+#if defined(SWIGPYTHON_BUILTIN)
+ %feature("tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin";
+#else
%extend SwigPyIterator {
%pythoncode {def __iter__(self): return self}
}
+#endif
%catches(swig::stop_iteration) SwigPyIterator::value() const;
%catches(swig::stop_iteration) SwigPyIterator::incr(size_t n = 1);
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index 5043e6ec0..432d5dcf6 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -244,6 +244,7 @@ typedef struct {
PyObject *destroy;
int delargs;
int implicitconv;
+ PyTypeObject *pytype;
} SwigPyClientData;
SWIGRUNTIMEINLINE int
@@ -310,6 +311,7 @@ SwigPyClientData_New(PyObject* obj)
data->delargs = 0;
}
data->implicitconv = 0;
+ data->pytype = 0;
return data;
}
}
@@ -1064,91 +1066,101 @@ SWIG_Python_AcquirePtr(PyObject *obj, int own) {
SWIGRUNTIME int
SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) {
- if (!obj) return SWIG_ERROR;
- if (obj == Py_None) {
- if (ptr) *ptr = 0;
- return SWIG_OK;
- } else {
+ if (!obj) return SWIG_ERROR;
+ if (obj == Py_None) {
+ if (ptr) *ptr = 0;
+ return SWIG_OK;
+ }
+ if (ty && ty->clientdata && ((SwigPyClientData*) ty->clientdata)->pytype) {
+ PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype;
+ PyTypeObject *obj_tp;
+ for (obj_tp = obj->ob_type; obj_tp; obj_tp = obj_tp->tp_base) {
+ if (obj_tp == target_tp) {
+ if (ptr)
+ *ptr = ((SwigPyObject*) obj)->ptr;
+ return SWIG_OK;
+ }
+ }
+ }
SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj);
if (own)
- *own = 0;
+ *own = 0;
while (sobj) {
- void *vptr = sobj->ptr;
- if (ty) {
- swig_type_info *to = sobj->ty;
- if (to == ty) {
- /* no type cast needed */
- if (ptr) *ptr = vptr;
- break;
+ void *vptr = sobj->ptr;
+ if (ty) {
+ swig_type_info *to = sobj->ty;
+ if (to == ty) {
+ /* no type cast needed */
+ if (ptr) *ptr = vptr;
+ break;
+ } else {
+ swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
+ if (!tc) {
+ sobj = (SwigPyObject *)sobj->next;
+ } else {
+ if (ptr) {
+ int newmemory = 0;
+ *ptr = SWIG_TypeCast(tc,vptr,&newmemory);
+ if (newmemory == SWIG_CAST_NEW_MEMORY) {
+ assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
+ if (own)
+ *own = *own | SWIG_CAST_NEW_MEMORY;
+ }
+ }
+ break;
+ }
+ }
} else {
- swig_cast_info *tc = SWIG_TypeCheck(to->name,ty);
- if (!tc) {
- sobj = (SwigPyObject *)sobj->next;
- } else {
- if (ptr) {
- int newmemory = 0;
- *ptr = SWIG_TypeCast(tc,vptr,&newmemory);
- if (newmemory == SWIG_CAST_NEW_MEMORY) {
- assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
- if (own)
- *own = *own | SWIG_CAST_NEW_MEMORY;
- }
- }
+ if (ptr) *ptr = vptr;
break;
- }
}
- } else {
- if (ptr) *ptr = vptr;
- break;
- }
}
if (sobj) {
- if (own)
- *own = *own | sobj->own;
- if (flags & SWIG_POINTER_DISOWN) {
- sobj->own = 0;
- }
- return SWIG_OK;
- } else {
- int res = SWIG_ERROR;
- if (flags & SWIG_POINTER_IMPLICIT_CONV) {
- SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
- if (data && !data->implicitconv) {
- PyObject *klass = data->klass;
- if (klass) {
- PyObject *impconv;
- data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/
- impconv = SWIG_Python_CallFunctor(klass, obj);
- data->implicitconv = 0;
- if (PyErr_Occurred()) {
- PyErr_Clear();
- impconv = 0;
- }
- if (impconv) {
- SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv);
- if (iobj) {
- void *vptr;
- res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0);
- if (SWIG_IsOK(res)) {
- if (ptr) {
- *ptr = vptr;
- /* transfer the ownership to 'ptr' */
- iobj->own = 0;
- res = SWIG_AddCast(res);
- res = SWIG_AddNewMask(res);
- } else {
- res = SWIG_AddCast(res);
- }
- }
- }
- Py_DECREF(impconv);
- }
- }
+ if (own)
+ *own = *own | sobj->own;
+ if (flags & SWIG_POINTER_DISOWN) {
+ sobj->own = 0;
}
- }
- return res;
+ return SWIG_OK;
+ } else {
+ int res = SWIG_ERROR;
+ if (flags & SWIG_POINTER_IMPLICIT_CONV) {
+ SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
+ if (data && !data->implicitconv) {
+ PyObject *klass = data->klass;
+ if (klass) {
+ PyObject *impconv;
+ data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/
+ impconv = SWIG_Python_CallFunctor(klass, obj);
+ data->implicitconv = 0;
+ if (PyErr_Occurred()) {
+ PyErr_Clear();
+ impconv = 0;
+ }
+ if (impconv) {
+ SwigPyObject *iobj = SWIG_Python_GetSwigThis(impconv);
+ if (iobj) {
+ void *vptr;
+ res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0);
+ if (SWIG_IsOK(res)) {
+ if (ptr) {
+ *ptr = vptr;
+ /* transfer the ownership to 'ptr' */
+ iobj->own = 0;
+ res = SWIG_AddCast(res);
+ res = SWIG_AddNewMask(res);
+ } else {
+ res = SWIG_AddCast(res);
+ }
+ }
+ }
+ Py_DECREF(impconv);
+ }
+ }
+ }
+ }
+ return res;
}
- }
}
/* Convert a function ptr value */
@@ -1319,21 +1331,32 @@ SWIG_Python_InitShadowInstance(PyObject *args) {
SWIGRUNTIME PyObject *
SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
- if (!ptr) {
- return SWIG_Py_Void();
- } else {
- int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
- PyObject *robj = SwigPyObject_New(ptr, type, own);
+ if (!ptr)
+ return SWIG_Py_Void();
+
SwigPyClientData *clientdata = type ? (SwigPyClientData *)(type->clientdata) : 0;
+ int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
+ if (clientdata && clientdata->pytype) {
+ SwigPyObject *newobj = PyObject_New(SwigPyObject, clientdata->pytype);
+ if (newobj) {
+ newobj->ptr = ptr;
+ newobj->ty = type;
+ newobj->own = own;
+ newobj->next = 0;
+ return (PyObject*) newobj;
+ }
+ return SWIG_Py_Void();
+ }
+
+ PyObject *robj = SwigPyObject_New(ptr, type, own);
if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) {
- PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj);
- if (inst) {
- Py_DECREF(robj);
- robj = inst;
- }
+ PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj);
+ if (inst) {
+ Py_DECREF(robj);
+ robj = inst;
+ }
}
return robj;
- }
}
/* Create a new packed object */
@@ -1343,6 +1366,19 @@ SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void();
}
+SWIGRUNTIME int
+SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int flags) {
+ assert(self);
+ SwigPyClientData *clientdata = (SwigPyClientData *)(type->clientdata);
+ assert(clientdata);
+ assert(clientdata->pytype);
+ int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
+ SwigPyObject *newobj = (SwigPyObject*) self;
+ newobj->ptr = ptr;
+ newobj->own = own;
+ return 0;
+}
+
/* -----------------------------------------------------------------------------*
* Get type list
* -----------------------------------------------------------------------------*/
diff --git a/Lib/python/pyruntime.swg b/Lib/python/pyruntime.swg
index 00f15a144..77abd47bd 100644
--- a/Lib/python/pyruntime.swg
+++ b/Lib/python/pyruntime.swg
@@ -11,3 +11,4 @@
%insert(runtime) "pyapi.swg"; /* Python API */
%insert(runtime) "pyrun.swg"; /* Python run-time code */
+%insert(runtime) "builtin.swg"; /* Specialization for classes with single inheritance */
diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg
index 817ed1d90..0cc1e976c 100644
--- a/Lib/python/pytypemaps.swg
+++ b/Lib/python/pytypemaps.swg
@@ -96,3 +96,20 @@
}
+/* -------------------------------------------------------------
+ * Output typemap for the __init__ method of a built-in type.
+ * ------------------------------------------------------------ */
+
+/* Pointers, references */
+%typemap(builtin_init,noblock=1) SWIGTYPE *, SWIGTYPE &, SWIGTYPE[] {
+ %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr($1), $descriptor, $owner | %newpointer_flags));
+}
+
+%typemap(builtin_init, noblock=1) SWIGTYPE *const& {
+ %set_output(SWIG_Python_NewBuiltinObj(self, %as_voidptr(*$1), $*descriptor, $owner | %newpointer_flags));
+}
+
+/* Return by value */
+%typemap(builtin_init, noblock=1) SWIGTYPE {
+ %set_output(SWIG_Python_NewBuiltinObj(self, %new_copy($1, $ltype), $&descriptor, SWIG_POINTER_OWN | %newpointer_flags));
+}
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 6d5f500a4..6d6b060d3 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -21,6 +21,7 @@ static int treduce = SWIG_cparse_template_reduce(0);
#include
#define PYSHADOW_MEMBER 0x2
+#define WARN_PYTHON_MULTIPLE_INH 405
static String *const_code = 0;
static String *module = 0;
@@ -43,8 +44,10 @@ static File *f_init = 0;
static File *f_shadow_py = 0;
static String *f_shadow = 0;
static String *f_shadow_imports = 0;
+static String *f_shadow_import_stmts = 0;
static String *f_shadow_stubs = 0;
+
static String *methods;
static String *class_name;
static String *shadow_indent = 0;
@@ -56,6 +59,12 @@ static int no_header_file = 0;
static int py3 = 0;
+static Hash *class_members = 0;
+
+static int builtin = 0;
+static File *f_builtins = 0;
+static String *builtin_tp_init = 0;
+
/* C++ Support + Shadow Classes */
static int have_constructor;
@@ -154,9 +163,18 @@ static const char *usage3 = (char *) "\
Function annotation \n\
\n";
+static String*
+getSlot (Node *n, const char *key)
+{
+ static String *slot_default = NewString("0");
+ String *val = Getattr(n, key);
+ return val ? val : slot_default;
+}
+
+
class PYTHON:public Language {
public:
- PYTHON() {
+ PYTHON() {
/* Add code to manage protected constructors and directors */
director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code,
@@ -430,9 +448,13 @@ public:
fputs(usage2, stdout);
fputs(usage3, stdout);
} else if (strcmp(argv[i], "-py3") == 0) {
- py3 = 1;
- Swig_mark_arg(i);
- }
+ py3 = 1;
+ Swig_mark_arg(i);
+ } else if (strcmp(argv[i], "-builtin") == 0) {
+ builtin = 1;
+ Preprocessor_define("SWIGPYTHON_BUILTIN", 0);
+ Swig_mark_arg(i);
+ }
}
} /* for */
@@ -532,6 +554,11 @@ public:
f_directors_h = NewString("");
f_directors = NewString("");
+ if (builtin) {
+ f_builtins = NewString("");
+ Printf(f_builtins, "namespace {\n\n");
+ }
+
if (directorsEnabled()) {
if (!no_header_file) {
f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files());
@@ -610,6 +637,10 @@ public:
Printf(f_runtime, "#define SWIG_PYTHON_CLASSIC\n");
}
+ if (builtin) {
+ Printf(f_runtime, "#define SWIGPYTHON_BUILTIN\n");
+ }
+
Printf(f_runtime, "\n");
Printf(f_header, "#if (PY_VERSION_HEX <= 0x02000000)\n");
@@ -668,155 +699,164 @@ public:
/* If shadow classing is enabled, we're going to change the module name to "_module" */
if (shadow) {
- String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module));
- // If we don't have an interface then change the module name X to _X
- if (interface)
- module = interface;
- else
- Insert(module, 0, "_");
- if ((f_shadow_py = NewFile(filen, "w", SWIG_output_files())) == 0) {
- FileErrorDisplay(filen);
- SWIG_exit(EXIT_FAILURE);
- }
- Delete(filen);
- filen = NULL;
-
- f_shadow = NewString("");
- f_shadow_imports = NewString("");
- f_shadow_stubs = NewString("");
-
- Swig_register_filebyname("shadow", f_shadow);
- Swig_register_filebyname("python", f_shadow);
-
- Swig_banner_target_lang(f_shadow, "#");
-
- if (!modern) {
- Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
- }
-
- if (mod_docstring && Len(mod_docstring)) {
- Printv(f_shadow, "\n\"\"\"\n", mod_docstring, "\n\"\"\"\n", NIL);
- Delete(mod_docstring);
- mod_docstring = NULL;
- }
-
- Printv(f_shadow, "\nfrom sys import version_info\n", NULL);
-
- if(fastproxy)
- {
- Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL);
- Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module);
- Printv(f_shadow, "else:\n", NULL);
- Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL);
- }
- /* Import the C-extension module. This should be a relative import,
- * since the shadow module may also have been imported by a relative
- * import, and there is thus no guarantee that the C-extension is on
- * sys.path. Relative imports must be explicitly specified from 2.6.0
- * onwards (implicit relative imports will raise a DeprecationWarning
- * in 2.6, and fail in 2.7 onwards), but the relative import syntax
- * isn't available in python 2.4 or earlier, so we have to write some
- * code conditional on the python version.
- */
- Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL);
- Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL);
- Printv(f_shadow, tab8, "from os.path import dirname\n", NULL);
- Printv(f_shadow, tab8, "import imp\n", NULL);
- Printv(f_shadow, tab8, "fp = None\n", NULL);
- Printv(f_shadow, tab8, "try:\n", NULL);
- Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module);
- Printf(f_shadow, tab8 "except ImportError:\n");
- /* At here, the module may already loaded, so simply import it. */
- Printf(f_shadow, tab4 tab8 "import %s\n", module);
- Printf(f_shadow, tab4 tab8 "return %s\n", module);
- Printv(f_shadow, tab8 "if fp is not None:\n", NULL);
- Printv(f_shadow, tab4 tab8 "try:\n", NULL);
- Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
- Printv(f_shadow, tab4 tab8, "finally:\n", NULL);
- Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL);
- Printv(f_shadow, tab4 tab8, "return _mod\n", NULL);
- Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
- Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
- Printv(f_shadow, "else:\n", NULL);
- Printf(f_shadow, tab4 "import %s\n", module);
-
- /* Delete the version_info symbol since we don't use it elsewhere in the
- * module. */
- Printv(f_shadow, "del version_info\n", NULL);
-
- if (modern || !classic) {
- Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL);
- }
- /* if (!modern) */
- /* always needed, a class can be forced to be no-modern, such as an exception */
- {
- // Python-2.2 object hack
- Printv(f_shadow,
- "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n",
- tab4, "if (name == \"thisown\"): return self.this.own(value)\n",
- tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n",
-#ifdef USE_THISOWN
- tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n",
-#endif
- tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n",
-#ifdef USE_THISOWN
- tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n",
-#else
- tab4, "if (not static) or hasattr(self,name):\n",
-#endif
- tab4, tab4, "self.__dict__[name] = value\n",
- tab4, "else:\n",
- tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n",
- "def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL);
-
- Printv(f_shadow,
- "def _swig_getattr(self,class_type,name):\n",
- tab4, "if (name == \"thisown\"): return self.this.own()\n",
- tab4, "method = class_type.__swig_getmethods__.get(name,None)\n",
- tab4, "if method: return method(self)\n", tab4, "raise AttributeError(name)\n\n", NIL);
-
- Printv(f_shadow,
- "def _swig_repr(self):\n",
- tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n",
- tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL);
-
- if (!classic) {
- /* Usage of types.ObjectType is deprecated.
- * But don't sure wether this would broken old Python?
- */
- Printv(f_shadow,
-// "import types\n",
- "try:\n",
-// " _object = types.ObjectType\n",
- " _object = object\n",
- " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
-// "del types\n",
- "\n\n", NIL);
+ String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module));
+ // If we don't have an interface then change the module name X to _X
+ if (interface)
+ module = interface;
+ else
+ Insert(module, 0, "_");
+ if ((f_shadow_py = NewFile(filen, "w", SWIG_output_files())) == 0) {
+ FileErrorDisplay(filen);
+ SWIG_exit(EXIT_FAILURE);
}
- }
- if (modern) {
- Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n",
+ Delete(filen);
+ filen = NULL;
+
+ f_shadow = NewString("");
+ f_shadow_imports = NewString("");
+ f_shadow_import_stmts = NewString("");
+ f_shadow_stubs = NewString("");
+
+ Printv(f_shadow_import_stmts, "SWIGINTERN void\n", NIL);
+ Printv(f_shadow_import_stmts, "SWIG_Python_builtin_imports()\n", NIL);
+ Printv(f_shadow_import_stmts, "{\n", NIL);
+ Printv(f_shadow_import_stmts, tab4 "PyObject *import_str = NULL;\n", NIL);
+
+ Swig_register_filebyname("shadow", f_shadow);
+ Swig_register_filebyname("python", f_shadow);
+
+ Swig_banner_target_lang(f_shadow, "#");
+
+ if (!modern) {
+ Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
+ }
+
+ if (mod_docstring && Len(mod_docstring)) {
+ Printv(f_shadow, "\"\"\"\n", mod_docstring, "\n\"\"\"\n\n", NIL);
+ Delete(mod_docstring);
+ mod_docstring = NULL;
+ }
+
+ Printv(f_shadow, "\nfrom sys import version_info\n", NULL);
+
+ if (!builtin && fastproxy) {
+ Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL);
+ Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module);
+ Printv(f_shadow, "else:\n", NULL);
+ Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL);
+ }
+
+ /* Import the C-extension module. This should be a relative import,
+ * since the shadow module may also have been imported by a relative
+ * import, and there is thus no guarantee that the C-extension is on
+ * sys.path. Relative imports must be explicitly specified from 2.6.0
+ * onwards (implicit relative imports will raise a DeprecationWarning
+ * in 2.6, and fail in 2.7 onwards), but the relative import syntax
+ * isn't available in python 2.4 or earlier, so we have to write some
+ * code conditional on the python version.
+ */
+ Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL);
+ Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL);
+ Printv(f_shadow, tab8, "from os.path import dirname\n", NULL);
+ Printv(f_shadow, tab8, "import imp\n", NULL);
+ Printv(f_shadow, tab8, "fp = None\n", NULL);
+ Printv(f_shadow, tab8, "try:\n", NULL);
+ Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module);
+ Printf(f_shadow, tab8 "except ImportError:\n");
+ /* At here, the module may already loaded, so simply import it. */
+ Printf(f_shadow, tab4 tab8 "import %s\n", module);
+ Printf(f_shadow, tab4 tab8 "return %s\n", module);
+ Printv(f_shadow, tab8 "if fp is not None:\n", NULL);
+ Printv(f_shadow, tab4 tab8 "try:\n", NULL);
+ Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
+ Printv(f_shadow, tab4 tab8, "finally:\n", NULL);
+ Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL);
+ Printv(f_shadow, tab4 tab8, "return _mod\n", NULL);
+ Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
+ Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
+ Printv(f_shadow, "else:\n", NULL);
+ Printf(f_shadow, tab4 "import %s\n", module);
+
+ /* Delete the version_info symbol since we don't use it elsewhere in the
+ * module. */
+ Printv(f_shadow, "del version_info\n", NULL);
+
+ if (builtin) {
+ Printf(f_shadow, "from %s import *\n", module);
+ }
+ if (modern || !classic) {
+ Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL);
+ }
+ /* if (!modern) */
+ /* always needed, a class can be forced to be no-modern, such as an exception */
+ {
+ // Python-2.2 object hack
+ Printv(f_shadow,
+ "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n",
+ tab4, "if (name == \"thisown\"): return self.this.own(value)\n",
+ tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n",
#ifdef USE_THISOWN
- tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n",
-#else
- tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n",
+ tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n",
#endif
- tab4, tab4, tab4, "set(self,name,value)\n",
- tab4, tab4, "else:\n",
- tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL);
- }
+ tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n",
+#ifdef USE_THISOWN
+ tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n",
+#else
+ tab4, "if (not static) or hasattr(self,name):\n",
+#endif
+ tab4, tab4, "self.__dict__[name] = value\n",
+ tab4, "else:\n",
+ tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n",
+ "def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL);
- if (directorsEnabled()) {
- // Try loading weakref.proxy, which is only available in Python 2.1 and higher
- Printv(f_shadow,
- "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL);
- }
- // Include some information in the code
- Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\
+ Printv(f_shadow,
+ "def _swig_getattr(self,class_type,name):\n",
+ tab4, "if (name == \"thisown\"): return self.this.own()\n",
+ tab4, "method = class_type.__swig_getmethods__.get(name,None)\n",
+ tab4, "if method: return method(self)\n", tab4, "raise AttributeError(name)\n\n", NIL);
+
+ Printv(f_shadow,
+ "def _swig_repr(self):\n",
+ tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n",
+ tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL);
+
+ if (!classic) {
+ /* Usage of types.ObjectType is deprecated.
+ * But don't sure wether this would broken old Python?
+ */
+ Printv(f_shadow,
+ // "import types\n",
+ "try:\n",
+ // " _object = types.ObjectType\n",
+ " _object = object\n",
+ " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
+ // "del types\n",
+ "\n\n", NIL);
+ }
+ }
+ if (modern) {
+ Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n",
+#ifdef USE_THISOWN
+ tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n",
+#else
+ tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n",
+#endif
+ tab4, tab4, tab4, "set(self,name,value)\n",
+ tab4, tab4, "else:\n",
+ tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL);
+ }
+
+ if (directorsEnabled()) {
+ // Try loading weakref.proxy, which is only available in Python 2.1 and higher
+ Printv(f_shadow,
+ "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL);
+ }
+ }
+
+ // Include some information in the code
+ Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\
------------------------------------------------*/\n", module);
- }
-
Printf(f_header, "#if PY_VERSION_HEX >= 0x03000000\n");
Printf(f_header, "# define SWIG_init PyInit_%s\n\n", module);
Printf(f_header, "#else\n");
@@ -833,6 +873,11 @@ public:
/* the method exported for replacement of new.instancemethod in Python 3 */
add_pyinstancemethod_new();
+ if (builtin) {
+ Printf(f_init, "PyTypeObject *builtin_pytype = 0;\n");
+ Printf(f_init, "swig_type_info *builtin_basetype = 0;\n");
+ }
+
/* emit code */
Language::top(n);
@@ -858,17 +903,23 @@ public:
Printf(f_init, " return;\n");
Printf(f_init, "#endif\n");
Printf(f_init, "}\n");
+ if (builtin)
+ Printf(f_builtins, "} // namespace {\n\n");
Printf(f_wrappers, "#ifdef __cplusplus\n");
Printf(f_wrappers, "}\n");
Printf(f_wrappers, "#endif\n");
if (shadow) {
- Printv(f_shadow_py, f_shadow, "\n", NIL);
- Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
+ if (builtin) {
+ Printv(f_shadow_import_stmts, "}\n", NIL);
+ Printv(f_header, f_shadow_import_stmts, NIL);
+ }
+ Printv(f_shadow_py, f_shadow, "\n", NIL);
+ Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
- Close(f_shadow_py);
- Delete(f_shadow_py);
+ Close(f_shadow_py);
+ Delete(f_shadow_py);
}
/* Close all of the files */
@@ -885,10 +936,13 @@ public:
}
Dump(f_wrappers, f_begin);
+ if (builtin)
+ Dump(f_builtins, f_begin);
Wrapper_pretty_print(f_init, f_begin);
Delete(f_header);
Delete(f_wrappers);
+ Delete(f_builtins);
Delete(f_init);
Delete(f_directors);
Delete(f_directors_h);
@@ -943,12 +997,24 @@ public:
if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) {
Printf(import, "_%s\n", modname);
if (!Strstr(f_shadow_imports, import)) {
- if (pkg && (!package || Strcmp(pkg, package) != 0)) {
- Printf(f_shadow, "import %s.%s\n", pkg, modname);
- } else {
- Printf(f_shadow, "import %s\n", modname);
- }
- Printv(f_shadow_imports, import, NULL);
+ if (pkg && (!package || Strcmp(pkg, package) != 0)) {
+ if (builtin) {
+ Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s.%s\");\n", pkg, modname);
+ Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n");
+ Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n");
+ } else {
+ Printf(f_shadow, "import %s.%s\n", pkg, modname);
+ }
+ } else {
+ if (builtin) {
+ Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s\");\n", modname);
+ Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n");
+ Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n");
+ } else {
+ Printf(f_shadow, "import %s\n", modname);
+ }
+ }
+ Printv(f_shadow_imports, import, NULL);
}
}
}
@@ -1696,21 +1762,11 @@ public:
* add_method()
* ------------------------------------------------------------ */
- void add_method(String *name, String *function, int kw, Node *n = 0, int funpack = 0, int num_required = -1, int num_arguments = -1) {
+ void add_method(String *name, String *function, int kw, Node *n = 0, int = 0, int = -1, int = -1) {
if (!kw) {
- if (n && funpack) {
- if (num_required == 0 && num_arguments == 0) {
- Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_NOARGS, ", name, function);
- } else if (num_required == 1 && num_arguments == 1) {
- Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, ", name, function);
- } else {
- Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function);
- }
- } else {
Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function);
- }
} else {
- Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function);
+ Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function);
}
if (!n) {
@@ -1741,11 +1797,12 @@ public:
/* ------------------------------------------------------------
* dispatchFunction()
* ------------------------------------------------------------ */
- void dispatchFunction(Node *n, int funpack = 0) {
+ void dispatchFunction(Node *n, int funpack = 0, bool builtin_self = false, bool constructor = false) {
/* Last node in overloaded chain */
int maxargs;
+ char const *wrap_return = (builtin_self && constructor) ? "int " : "PyObject *";
String *tmp = NewString("");
String *dispatch;
const char *dispatch_code = funpack ? "return %s(self, argc, argv);" : "return %s(self, args);";
@@ -1762,23 +1819,29 @@ public:
String *symname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(symname);
- Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL);
+ Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL);
Wrapper_add_local(f, "argc", "int argc");
Printf(tmp, "PyObject *argv[%d]", maxargs + 1);
Wrapper_add_local(f, "argv", tmp);
if (!fastunpack) {
- Wrapper_add_local(f, "ii", "int ii");
- Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
- Append(f->code, "argc = (int)PyObject_Length(args);\n");
- Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", maxargs);
- Append(f->code, "argv[ii] = PyTuple_GET_ITEM(args,ii);\n");
- Append(f->code, "}\n");
+ bool add_self = builtin_self && !constructor;
+ Wrapper_add_local(f, "ii", "int ii");
+ if (maxargs - (add_self ? 1 : 0) > 0)
+ Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
+ Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n");
+ if (add_self)
+ Append(f->code, "argv[0] = self;\n");
+ Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs-1 : maxargs);
+ Printf(f->code, "argv[ii%s] = PyTuple_GET_ITEM(args,ii);\n", add_self ? " + 1" : "");
+ Append(f->code, "}\n");
+ if (add_self)
+ Append(f->code, "argc++;\n");
} else {
- String *iname = Getattr(n, "sym:name");
- Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs);
- Append(f->code, "--argc;\n");
+ String *iname = Getattr(n, "sym:name");
+ Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs);
+ Append(f->code, "--argc;\n");
}
Replaceall(dispatch, "$args", "self,args");
@@ -1800,16 +1863,17 @@ public:
Append(f->code, "fail:\n");
Printf(f->code, "SWIG_SetErrorMsg(PyExc_NotImplementedError,"
"\"Wrong number or type of arguments for overloaded function '%s'.\\n\"" "\n\" Possible C/C++ prototypes are:\\n\"%s);\n", symname, protoTypes);
- Append(f->code, "return NULL;\n");
+ Printf(f->code, "return (%s) 0;\n", wrap_return);
Delete(protoTypes);
}
Printv(f->code, "}\n", NIL);
Wrapper_print(f, f_wrappers);
Node *p = Getattr(n, "sym:previousSibling");
- add_method(symname, wname, 0, p);
+ if (!builtin_self)
+ add_method(symname, wname, 0, p);
/* Create a shadow for this function (if enabled and not in a member function) */
- if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) {
+ if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
emitFunctionShadowHelper(n, f_shadow_stubs, symname, 0);
}
DelWrapper(f);
@@ -1838,12 +1902,14 @@ public:
String *iname = Getattr(n, "sym:name");
SwigType *d = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
+
int director_method = 0;
Parm *p;
int i;
char source[64];
Wrapper *f;
+ String *self_parse;
String *parse_args;
String *arglist;
String *get_pointers;
@@ -1855,6 +1921,8 @@ public:
int num_required;
int num_arguments;
+ int tuple_required;
+ int tuple_arguments;
int varargs = 0;
int allow_kwargs = check_kwargs(n);
@@ -1873,7 +1941,10 @@ public:
handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0);
Delete(cname);
}
-
+ bool builtin_self = builtin && in_class && (constructor || (l && Getattr(l, "self")));
+ bool builtin_ctor = builtin_self && constructor;
+ char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)";
+ char const *wrap_return = builtin_ctor ? "int " : "PyObject *";
if (Getattr(n, "sym:overloaded")) {
overname = Getattr(n, "sym:overname");
@@ -1883,6 +1954,7 @@ public:
}
f = NewWrapper();
+ self_parse = NewString("");
parse_args = NewString("");
arglist = NewString("");
get_pointers = NewString("");
@@ -1892,8 +1964,11 @@ public:
int allow_thread = threads_enable(n);
- Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0");
-
+ if (builtin_ctor)
+ Wrapper_add_local(f, "resultobj", "int resultobj = 0");
+ else
+ Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0");
+
// Emit all of the local variables for holding arguments.
emit_parameter_variables(l, f);
@@ -1901,8 +1976,12 @@ public:
emit_attach_parmmaps(l, f);
Setattr(n, "wrap:parms", l);
/* Get number of required and total arguments */
- num_arguments = emit_num_arguments(l);
- num_required = emit_num_required(l);
+ tuple_arguments = num_arguments = emit_num_arguments(l);
+ tuple_required = num_required = emit_num_required(l);
+ if (builtin_self && !constructor) {
+ --tuple_arguments;
+ --tuple_required;
+ }
if (((num_arguments == 0) && (num_required == 0)) || ((num_arguments == 1) && (num_required == 1) && Getattr(l, "self")))
allow_kwargs = 0;
varargs = emit_isvarargs(l);
@@ -1914,9 +1993,9 @@ public:
if (!allow_kwargs || Getattr(n, "sym:overloaded")) {
if (!varargs) {
- Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL);
+ Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
} else {
- Printv(f->def, "SWIGINTERN PyObject *", wname, "__varargs__", "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *varargs) {", NIL);
+ Printv(f->def, "SWIGINTERN ", wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL);
}
if (allow_kwargs) {
Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions (%s).\n", Swig_name_decl(n));
@@ -1927,13 +2006,15 @@ public:
Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, "Can't wrap varargs with keyword arguments enabled\n");
varargs = 0;
}
- Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *kwargs) {", NIL);
+ Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL);
}
- if (!allow_kwargs) {
- Append(parse_args, " if (!PyArg_ParseTuple(args,(char *)\"");
- } else {
- Append(parse_args, " if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\"");
- Append(arglist, ",kwnames");
+ if (!builtin || !in_class || tuple_arguments > 0) {
+ if (!allow_kwargs) {
+ Append(parse_args, " if (!PyArg_ParseTuple(args,(char *)\"");
+ } else {
+ Append(parse_args, " if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\"");
+ Append(arglist, ",kwnames");
+ }
}
int funpack = modernargs && fastunpack && !varargs && !allow_kwargs;
@@ -1967,6 +2048,9 @@ public:
}
}
+ if (builtin_self && !builtin_ctor)
+ Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0");
+
int use_parse = 0;
Append(kwargs, "{");
for (i = 0, p = l; i < num_arguments; i++) {
@@ -1977,17 +2061,17 @@ public:
SwigType *pt = Getattr(p, "type");
String *pn = Getattr(p, "name");
String *ln = Getattr(p, "lname");
- if (funpack) {
- sprintf(source, "swig_obj[%d]", i);
- } else {
- sprintf(source, "obj%d", i);
+ if (funpack)
+ sprintf(source, "swig_obj[%d]", builtin_ctor ? i + 1 : i);
+ else
+ sprintf(source, "obj%d", builtin_ctor ? i + 1 : i);
+
+ if (!builtin_self || builtin_ctor || i > 0) {
+ Putc(',', arglist);
+ if (i == num_required)
+ Putc('|', parse_args); /* Optional argument separator */
}
-
- Putc(',', arglist);
- if (i == num_required)
- Putc('|', parse_args); /* Optional argument separator */
-
/* Keyword argument handling */
if (allow_kwargs) {
if (Len(pn)) {
@@ -2034,10 +2118,12 @@ public:
Setattr(p, "implicitconv", convflag);
}
- Putc('O', parse_args);
+ if (i > 0 || !builtin_self || builtin_ctor)
+ Putc('O', parse_args);
if (!funpack) {
Wrapper_add_localv(f, source, "PyObject *", source, "= 0", NIL);
- Printf(arglist, "&%s", source);
+ if (!builtin_self || builtin_ctor || i > 0)
+ Printf(arglist, "&%s", source);
}
if (i >= num_required)
Printv(get_pointers, "if (", source, ") {\n", NIL);
@@ -2048,7 +2134,8 @@ public:
} else {
use_parse = 1;
Append(parse_args, parse);
- Printf(arglist, "&%s", ln);
+ if (!builtin_self || builtin_ctor || i > 0)
+ Printf(arglist, "&%s", ln);
}
p = Getattr(p, "tmap:in:next");
continue;
@@ -2064,7 +2151,7 @@ public:
Printv(f->locals, " char * kwnames[] = ", kwargs, ";\n", NIL);
}
- if (use_parse || allow_kwargs || !modernargs) {
+ if (tuple_arguments > 0 && (use_parse || allow_kwargs || !modernargs)) {
Printf(parse_args, ":%s\"", iname);
Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL);
funpack = 0;
@@ -2074,16 +2161,16 @@ public:
Clear(f->def);
if (overname) {
if (noargs) {
- Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
+ Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
} else {
- Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), int nobjs, PyObject **swig_obj) {", NIL);
+ Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL);
}
Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments);
} else {
if (noargs) {
- Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL);
+ Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
} else {
- Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL);
+ Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
}
if (onearg) {
Printf(parse_args, "if (!args) SWIG_fail;\n");
@@ -2094,14 +2181,14 @@ public:
Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", iname, num_required, num_arguments);
}
}
- } else {
- Printf(parse_args, "if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, num_required, num_arguments);
+ } else if (tuple_arguments > 0) {
+ Printf(parse_args, "if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, tuple_required, tuple_arguments);
Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL);
}
}
/* Now piece together the first part of the wrapper function */
- Printv(f->code, parse_args, get_pointers, NIL);
+ Printv(f->code, self_parse, parse_args, get_pointers, NIL);
/* Check for trailing varargs */
if (varargs) {
@@ -2227,7 +2314,14 @@ public:
/* This part below still needs cleanup */
/* Return the function value */
- if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) {
+ if (builtin_ctor) {
+ Printf(f->code, "%s\n", actioncode);
+ tm = Swig_typemap_lookup("builtin_init", n, "result", f);
+ } else {
+ tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode);
+ }
+
+ if (tm) {
if (funpack) {
Replaceall(tm, "$self", "swig_obj[0]");
} else {
@@ -2329,7 +2423,10 @@ public:
if (need_cleanup) {
Printv(f->code, cleanup, NIL);
}
- Printv(f->code, " return NULL;\n", NIL);
+ if (builtin_self && constructor)
+ Printv(f->code, " return 0;\n", NIL);
+ else
+ Printv(f->code, " return NULL;\n", NIL);
if (funpack) {
@@ -2363,12 +2460,13 @@ public:
if (varargs) {
DelWrapper(f);
f = NewWrapper();
- Printv(f->def, "SWIGINTERN PyObject *", wname, "(PyObject *self, PyObject *args) {", NIL);
- Wrapper_add_local(f, "resultobj", "PyObject *resultobj");
+ Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL);
+ Wrapper_add_local(f, "resultobj", constructor && builtin_self ? "int resultobj" : "PyObject *resultobj");
Wrapper_add_local(f, "varargs", "PyObject *varargs");
Wrapper_add_local(f, "newargs", "PyObject *newargs");
- Printf(f->code, "newargs = PyTuple_GetSlice(args,0,%d);\n", num_arguments);
- Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_arguments);
+ int first_arg = builtin_self ? 1 : 0;
+ Printf(f->code, "newargs = PyTuple_GetSlice(args,%d,%d);\n", first_arg, first_arg + num_arguments);
+ Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", first_arg + num_arguments);
Printf(f->code, "resultobj = %s__varargs__(self,newargs,varargs);\n", wname);
Append(f->code, "Py_XDECREF(newargs);\n");
Append(f->code, "Py_XDECREF(varargs);\n");
@@ -2379,17 +2477,19 @@ public:
/* Now register the function with the interpreter. */
if (!Getattr(n, "sym:overloaded")) {
- add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments);
+ if (!builtin_self)
+ add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments);
/* Create a shadow for this function (if enabled and not in a member function) */
- if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) {
+ if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
emitFunctionShadowHelper(n, in_class ? f_shadow_stubs : f_shadow, iname, allow_kwargs);
}
} else {
if (!Getattr(n, "sym:nextSibling")) {
- dispatchFunction(n, funpack);
+ dispatchFunction(n, funpack, builtin_self, constructor);
}
}
+ Delete(self_parse);
Delete(parse_args);
Delete(arglist);
Delete(get_pointers);
@@ -2428,17 +2528,14 @@ public:
if (!have_globals) {
Printf(f_init, "\t PyDict_SetItemString(d,(char*)\"%s\", SWIG_globals());\n", global_name);
have_globals = 1;
- if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) {
+ if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
Printf(f_shadow_stubs, "%s = %s.%s\n", global_name, module, global_name);
}
}
int assignable = is_assignable(n);
- if ((shadow) && !assignable) {
- if (!in_class) {
+ if (!builtin && (shadow) && !assignable && !in_class)
Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname);
- }
- }
String *getname = Swig_name_get(NSPACE_TODO, iname);
String *setname = Swig_name_set(NSPACE_TODO, iname);
@@ -2516,57 +2613,69 @@ public:
* constantWrapper()
* ------------------------------------------------------------ */
- virtual int constantWrapper(Node *n) {
- String *name = Getattr(n, "name");
- String *iname = Getattr(n, "sym:name");
- SwigType *type = Getattr(n, "type");
- String *rawval = Getattr(n, "rawval");
- String *value = rawval ? rawval : Getattr(n, "value");
- String *tm;
- int have_tm = 0;
+ virtual int constantWrapper(Node *n) {
+ String *name = Getattr(n, "name");
+ String *iname = Getattr(n, "sym:name");
+ SwigType *type = Getattr(n, "type");
+ String *rawval = Getattr(n, "rawval");
+ String *value = rawval ? rawval : Getattr(n, "value");
+ String *tm;
+ int have_tm = 0;
- if (!addSymbol(iname, n))
- return SWIG_ERROR;
+ if (!addSymbol(iname, n))
+ return SWIG_ERROR;
- /* Special hook for member pointer */
- if (SwigType_type(type) == T_MPOINTER) {
- String *wname = Swig_name_wrapper(iname);
- String *str = SwigType_str(type, wname);
- Printf(f_header, "static %s = %s;\n", str, value);
- Delete(str);
- value = wname;
- }
- if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
- Replaceall(tm, "$source", value);
- Replaceall(tm, "$target", name);
- Replaceall(tm, "$value", value);
- Printf(const_code, "%s,\n", tm);
- Delete(tm);
- have_tm = 1;
- }
- if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
- Replaceall(tm, "$source", value);
- Replaceall(tm, "$target", name);
- Replaceall(tm, "$value", value);
- Printf(f_init, "%s\n", tm);
- Delete(tm);
- have_tm = 1;
- }
- if (!have_tm) {
- Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n");
- return SWIG_NOWRAP;
- }
- if ((shadow) && (!(shadow & PYSHADOW_MEMBER))) {
- if (!in_class) {
- Printv(f_shadow, iname, " = ", module, ".", iname, "\n", NIL);
- } else {
- if (!(Getattr(n, "feature:python:callback"))) {
- Printv(f_shadow_stubs, iname, " = ", module, ".", iname, "\n", NIL);
+ /* Special hook for member pointer */
+ if (SwigType_type(type) == T_MPOINTER) {
+ String *wname = Swig_name_wrapper(iname);
+ String *str = SwigType_str(type, wname);
+ Printf(f_header, "static %s = %s;\n", str, value);
+ Delete(str);
+ value = wname;
}
- }
+
+ if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
+ Replaceall(tm, "$source", value);
+ Replaceall(tm, "$target", name);
+ Replaceall(tm, "$value", value);
+ Printf(const_code, "%s,\n", tm);
+ Delete(tm);
+ have_tm = 1;
+ }
+
+ if (builtin && in_class) {
+ Swig_require("builtin_constantWrapper", n, "*sym:name", "builtin_sym:name", NIL);
+ Setattr(n, "sym:name", Getattr(n, "builtin_sym:name"));
+ }
+
+ if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
+ Replaceall(tm, "$source", value);
+ Replaceall(tm, "$target", name);
+ Replaceall(tm, "$value", value);
+ Printf(f_init, "%s\n", tm);
+ Delete(tm);
+ have_tm = 1;
+ }
+
+ if (builtin && in_class)
+ Swig_restore(n);
+
+ if (!have_tm) {
+ Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n");
+ return SWIG_NOWRAP;
+ }
+
+ if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
+ if (!in_class) {
+ Printv(f_shadow, iname, " = ", module, ".", iname, "\n", NIL);
+ } else {
+ if (!(Getattr(n, "feature:python:callback"))) {
+ Printv(f_shadow_stubs, iname, " = ", module, ".", iname, "\n", NIL);
+ }
+ }
+ }
+ return SWIG_OK;
}
- return SWIG_OK;
- }
/* ------------------------------------------------------------
@@ -2581,7 +2690,7 @@ public:
return SWIG_ERROR;
add_method(name, wrapname, 0);
- if (shadow) {
+ if (!builtin && shadow) {
Printv(f_shadow_stubs, name, " = ", module, ".", name, "\n", NIL);
}
return SWIG_OK;
@@ -2796,261 +2905,434 @@ public:
/* ------------------------------------------------------------
* classDeclaration()
* ------------------------------------------------------------ */
-
- virtual int classDeclaration(Node *n) {
- if (shadow && !Getattr(n, "feature:onlychildren")) {
- Node *mod = Getattr(n, "module");
- if (mod) {
- String *importname = NewString("");
- String *modname = Getattr(mod, "name");
- if (Strcmp(modname, mainmodule) != 0) {
- // check if the module has a package option
- Node *options = Getattr(mod, "options");
- String *pkg = options ? Getattr(options, "package") : 0;
- if (pkg && (!package || Strcmp(pkg, package) != 0)) {
- Printf(importname, "%s.", pkg);
- }
- Printf(importname, "%s.", modname);
+
+ virtual bool get_single_base (Node *n, Node **base = NULL)
+ {
+ if (base)
+ *base = NULL;
+ if (Getattr(n, "single_inh"))
+ return true;
+ List *baselist = Getattr(n, "bases");
+ if (!baselist || Len(baselist) == 0) {
+ Setattr(n, "single_inh", "1");
+ return true;
}
- Append(importname, Getattr(n, "sym:name"));
- Setattr(n, "python:proxy", importname);
- }
+ if (baselist && Len(baselist) == 1) {
+ Iterator b = First(baselist);
+ if (this->get_single_base(b.item)) {
+ if (base)
+ *base = b.item;
+ Setattr(n, "single_inh", "1");
+ return true;
+ }
+ }
+ return false;
+ }
+
+ virtual int classDeclaration(Node *n) {
+ if (shadow && !Getattr(n, "feature:onlychildren")) {
+ Node *mod = Getattr(n, "module");
+ if (mod) {
+ String *importname = NewString("");
+ String *modname = Getattr(mod, "name");
+ if (Strcmp(modname, mainmodule) != 0) {
+ // check if the module has a package option
+ Node *options = Getattr(mod, "options");
+ String *pkg = options ? Getattr(options, "package") : 0;
+ if (pkg && (!package || Strcmp(pkg, package) != 0)) {
+ Printf(importname, "%s.", pkg);
+ }
+ Printf(importname, "%s.", modname);
+ }
+ Append(importname, Getattr(n, "sym:name"));
+ Setattr(n, "python:proxy", importname);
+ }
+ }
+ int result = Language::classDeclaration(n);
+ return result;
}
- return Language::classDeclaration(n);
- }
/* ------------------------------------------------------------
* classHandler()
* ------------------------------------------------------------ */
- virtual int classHandler(Node *n) {
- int oldclassic = classic;
- int oldmodern = modern;
- File *f_shadow_file = f_shadow;
-
- if (shadow) {
-
- /* Create new strings for building up a wrapper function */
- have_constructor = 0;
- have_repr = 0;
-
- if (GetFlag(n, "feature:classic")) {
- classic = 1;
- modern = 0;
- }
- if (GetFlag(n, "feature:modern")) {
- classic = 0;
- modern = 1;
- }
- if (GetFlag(n, "feature:exceptionclass")) {
- classic = 1;
- modern = 0;
- }
-
- shadow_indent = (String *) tab4;
-
- class_name = Getattr(n, "sym:name");
- real_classname = Getattr(n, "name");
-
- if (!addSymbol(class_name, n))
- return SWIG_ERROR;
-
- /* Handle inheritance */
- String *base_class = NewString("");
- List *baselist = Getattr(n, "bases");
- if (baselist && Len(baselist)) {
- Iterator b;
- b = First(baselist);
- while (b.item) {
- String *bname = Getattr(b.item, "python:proxy");
- bool ignore = GetFlag(b.item, "feature:ignore") ? true : false;
- if (!bname || ignore) {
- if (!bname && !ignore) {
- Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n),
- "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name")));
- }
- b = Next(b);
- continue;
- }
- Printv(base_class, bname, NIL);
- b = Next(b);
- if (b.item) {
- Putc(',', base_class);
- }
- }
- }
-
- /* dealing with abstract base class */
- String *abcs = Getattr(n, "feature:python:abc");
- if (py3 && abcs) {
- if (Len(base_class)) {
- Putc(',', base_class);
- }
- Printv(base_class, abcs, NIL);
- }
-
- Printv(f_shadow, "class ", class_name, NIL);
-
- if (Len(base_class)) {
- Printf(f_shadow, "(%s)", base_class);
- } else {
- if (!classic) {
- Printf(f_shadow, modern ? "(object)" : "(_object)");
- }
- if (GetFlag(n, "feature:exceptionclass") ) {
- Printf(f_shadow, "(Exception)");
- }
- }
- Printf(f_shadow, ":\n");
- if (have_docstring(n)) {
- String *str = docstring(n, AUTODOC_CLASS, tab4);
- if (str && Len(str))
- Printv(f_shadow, tab4, str, "\n", NIL);
- }
- if (!modern) {
- Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL);
- if (Len(base_class)) {
- Printf(f_shadow, "%sfor _s in [%s]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))\n", tab4, base_class);
- }
-
- if (!GetFlag(n, "feature:python:nondynamic")) {
- Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", NIL);
- } else {
- Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", NIL);
- }
-
- Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL);
- if (Len(base_class)) {
- Printf(f_shadow, "%sfor _s in [%s]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))\n", tab4, base_class);
- }
-
- Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL);
- } else {
- Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL);
- /* Add static attribute */
- if (GetFlag(n, "feature:python:nondynamic")) {
- Printv(f_shadow_file,
- tab4, "__setattr__ = _swig_setattr_nondynamic_method(object.__setattr__)\n",
- tab4, "class __metaclass__(type):\n", tab4, tab4, "__setattr__ = _swig_setattr_nondynamic_method(type.__setattr__)\n", NIL);
- }
- }
- }
-
- /* Emit all of the members */
-
- in_class = 1;
-
- /* Overide the shadow file so we can capture its methods */
- f_shadow = NewString("");
-
- Language::classHandler(n);
- in_class = 0;
-
- /* Complete the class */
- if (shadow) {
- /* Generate a class registration function */
- {
- String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers)
- SwigType *smart = 0;
- if (smartptr) {
- SwigType *cpt = Swig_cparse_type(smartptr);
- if (cpt) {
- smart = SwigType_typedef_resolve_all(cpt);
- Delete(cpt);
- } else {
- // TODO: report line number of where the feature comes from
- Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname);
- }
- }
- SwigType *ct = Copy(smart ? smart : real_classname);
- SwigType_add_pointer(ct);
- SwigType *realct = Copy(real_classname);
- SwigType_add_pointer(realct);
- SwigType_remember(realct);
- Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
- Printv(f_wrappers, " PyObject *obj;\n", NIL);
- if (modernargs) {
- if (fastunpack) {
- Printv(f_wrappers, " if (!SWIG_Python_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
- } else {
- Printv(f_wrappers, " if (!PyArg_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
- }
- } else {
- Printv(f_wrappers, " if (!PyArg_ParseTuple(args,(char*)\"O:swigregister\", &obj)) return NULL;\n", NIL);
- }
-
- Printv(f_wrappers,
- " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n",
- " return SWIG_Py_Void();\n", "}\n\n", NIL);
- String *cname = NewStringf("%s_swigregister", class_name);
- add_method(cname, cname, 0);
- Delete(smart);
- Delete(cname);
- Delete(ct);
- Delete(realct);
- }
- if (!have_constructor) {
- Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
- } else if (fastinit) {
-
- Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
- Printv(f_wrappers, " return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL);
- String *cname = NewStringf("%s_swiginit", class_name);
- add_method(cname, cname, 0);
- Delete(cname);
- }
- if (!have_repr) {
- /* Supply a repr method for this class */
- String *rname = SwigType_namestr(real_classname);
- if (new_repr) {
- Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL);
- } else {
- Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL);
+ void builtin_pre_decl (Node *n, Node *base_node)
+ {
+ String *name = Getattr(n, "name");
+ String *rname = SwigType_namestr(name);
+ Printf(f_init, " builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname);
+ Printf(f_init, " builtin_pytype->tp_new = PyType_GenericNew;\n");
+ if (base_node) {
+ String *base_name = Copy(Getattr(base_node, "name"));
+ SwigType_add_pointer(base_name);
+ String *base_mname = SwigType_manglestr(base_name);
+ Printf(f_init, " builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname);
+ Printf(f_init, " if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n");
+ Printf(f_init, " builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n");
+ Printf(f_init, " }\n");
+ Delete(base_mname);
+ Delete(base_name);
}
+ Printf(f_init, " builtin_pytype->tp_dict = d = PyDict_New();\n");
Delete(rname);
- }
-
-
- /* Now emit methods */
- Printv(f_shadow_file, f_shadow, NIL);
-
- /* Now the Ptr class */
- if (classptr) {
- Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL);
- if (!modern) {
- Printv(f_shadow_file,
- tab8, "try: self.this.append(this)\n",
- tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL);
- } else {
- Printv(f_shadow_file,
- tab8, "try: self.this.append(this)\n",
- tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL);
- }
- }
-
- if (fastproxy) {
- List *shadow_list = Getattr(n, "shadow_methods");
- for (int i = 0; i < Len(shadow_list); ++i) {
- String *symname = Getitem(shadow_list, i);
- Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name);
- }
- }
- Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name);
- Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name);
-
- shadow_indent = 0;
- Printf(f_shadow_file, "%s\n", f_shadow_stubs);
- Clear(f_shadow_stubs);
}
- classic = oldclassic;
- modern = oldmodern;
- /* Restore shadow file back to original version */
- Delete(f_shadow);
- f_shadow = f_shadow_file;
+ void builtin_post_decl (File *f, Node *n)
+ {
+ String *name = Getattr(n, "name");
+ String *pname = Copy(name);
+ SwigType_add_pointer(pname);
+ String *symname = Getattr(n, "sym:name");
+ String *rname = SwigType_namestr(name);
+ String *mname = SwigType_manglestr(pname);
+ String *templ = NewString("");
+ Printf(templ, "PySwigBuiltin< %s >", rname);
+ char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0";
- return SWIG_OK;
- }
+ // Check for non-public destructor, in which case tp_dealloc should be "0"
+ String *tp_dealloc = NewString("");
+ String *dtor_name = NewString("delete");
+ if (Getattr(class_members, "delete"))
+ Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname);
+ else
+ Printv(tp_dealloc, "0", NIL);
+ Delete(dtor_name);
+
+ Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname);
+ Printf(f, " PyObject_HEAD_INIT(NULL)\n");
+ Printf(f, " 0, /*ob_size*/\n");
+ Printf(f, " \"%s\", /*tp_name*/\n", symname);
+ Printf(f, " sizeof(%s), /*tp_basicsize*/\n", templ);
+ Printf(f, " %s, /*tp_itemsize*/\n", getSlot(n, "feature:tp_itemsize"));
+ Printf(f, " %s, /*tp_dealloc*/\n", tp_dealloc);
+ Printf(f, " %s, /*tp_print*/\n", getSlot(n, "feature:tp_print"));
+ Printf(f, " %s, /*tp_getattr*/\n", getSlot(n, "feature:tp_getattr"));
+ Printf(f, " %s, /*tp_setattr*/\n", getSlot(n, "feature:tp_setattr"));
+ Printf(f, " %s, /*tp_compare*/\n", getSlot(n, "feature:tp_compare"));
+ Printf(f, " %s, /*tp_repr*/\n", getSlot(n, "feature:tp_repr"));
+ Printf(f, " %s, /*tp_as_number*/\n", getSlot(n, "feature:tp_as_number"));
+ Printf(f, " %s, /*tp_as_sequence*/\n", getSlot(n, "feature:tp_as_sequence"));
+ Printf(f, " %s, /*tp_as_mapping*/\n", getSlot(n, "feature:tp_as_mapping"));
+ Printf(f, " %s, /*tp_hash */\n", getSlot(n, "feature:tp_hash"));
+ Printf(f, " %s, /*tp_call*/\n", getSlot(n, "feature:tp_call"));
+ Printf(f, " %s, /*tp_str*/\n", getSlot(n, "feature:tp_str"));
+ Printf(f, " %s, /*tp_getattro*/\n", getSlot(n, "feature:tp_getattro"));
+ Printf(f, " %s, /*tp_setattro*/\n", getSlot(n, "feature:tp_setattro"));
+ Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer"));
+ Printf(f, " Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags*/\n");
+ Printf(f, " \"%s\", /* tp_doc */\n", rname);
+ Printf(f, " %s, /* tp_traverse */\n", getSlot(n, "feature:tp_traverse"));
+ Printf(f, " %s, /* tp_clear */\n", getSlot(n, "feature:tp_clear"));
+ Printf(f, " %s, /* tp_richcompare */\n", getSlot(n, "feature:tp_richcompare"));
+ Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset"));
+ Printf(f, " %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter"));
+ Printf(f, " %s, /* tp_iternext */\n", getSlot(n, "feature:tp_iternext"));
+ Printf(f, " %s::methods, /* tp_methods */\n", templ);
+ Printf(f, " %s, /* tp_members */\n", getSlot(n, "feature:tp_members"));
+ Printf(f, " %s, /* tp_getset */\n", getSlot(n, "feature:tp_getset"));
+ Printf(f, " %s, /* tp_base */\n", getSlot(n, "feature:tp_base"));
+ Printf(f, " %s, /* tp_dict */\n", getSlot(n, "feature:tp_dict"));
+ Printf(f, " %s, /* tp_descr_get */\n", getSlot(n, "feature:tp_descr_get"));
+ Printf(f, " %s, /* tp_descr_set */\n", getSlot(n, "feature:tp_descr_set"));
+ Printf(f, " %s, /* tp_dictoffset */\n", getSlot(n, "feature:tp_dictoffset"));
+ Printf(f, " (initproc)%s, /* tp_init */\n", tp_init);
+ Printf(f, " %s, /* tp_alloc */\n", getSlot(n, "feature:tp_alloc"));
+ Printf(f, " 0, /* tp_new */\n");
+ Printf(f, " %s /* tp_free */\n", getSlot(n, "feature:tp_free"));
+ Printf(f, "};\n\n");
+
+ String *clientdata = NewString("");
+ Printf(clientdata, "&%s::clientdata", templ);
+ SwigType_remember_clientdata(pname, clientdata);
+
+ Printf(f, "template <> SwigPyClientData %s::clientdata = {0, 0, 0, 0, 0, 0, &%s::pytype};\n\n", templ, templ);
+
+ Printv(f_init, " d = md;\n", NIL);
+ Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL);
+ Printf(f_init, " fprintf(stderr, \"Couldn't create type %s\");\n", symname);
+ Printv(f_init, " return;\n", NIL);
+ Printv(f_init, " }\n", NIL);
+ Printv(f_init, " Py_INCREF(builtin_pytype);\n", NIL);
+ Printf(f_init, " PyModule_AddObject(m, \"%s\", (PyObject*) builtin_pytype);\n", symname);
+
+ Delete(clientdata);
+ Delete(templ);
+ Delete(mname);
+ Delete(rname);
+ Delete(pname);
+ Delete(tp_dealloc);
+ }
+
+ virtual int classHandler(Node *n) {
+ int oldclassic = classic;
+ int oldmodern = modern;
+ File *f_shadow_file = f_shadow;
+ bool single_inh = false;
+ Node *base_node = NULL;
+
+ if (shadow) {
+
+ /* Create new strings for building up a wrapper function */
+ have_constructor = 0;
+ have_repr = 0;
+
+ if (GetFlag(n, "feature:classic")) {
+ classic = 1;
+ modern = 0;
+ }
+ if (GetFlag(n, "feature:modern")) {
+ classic = 0;
+ modern = 1;
+ }
+ if (GetFlag(n, "feature:exceptionclass")) {
+ classic = 1;
+ modern = 0;
+ }
+
+ class_name = Getattr(n, "sym:name");
+ real_classname = Getattr(n, "name");
+
+ if (!addSymbol(class_name, n))
+ return SWIG_ERROR;
+
+ single_inh = builtin && get_single_base(n, &base_node);
+ if (builtin && !single_inh) {
+ Swig_warning(WARN_PYTHON_MULTIPLE_INH, Getfile(n), Getline(n),
+ "Class '%s' ignored, because it has multiple inheritance, which is incompatible with the '-builtin' option.\n", real_classname);
+ return SWIG_OK;
+ }
+
+ shadow_indent = (String *) tab4;
+
+ /* Handle inheritance */
+ String *base_class = NewString("");
+ List *baselist = Getattr(n, "bases");
+ if (baselist && Len(baselist)) {
+ Iterator b;
+ b = First(baselist);
+ while (b.item) {
+ String *bname = Getattr(b.item, "python:proxy");
+ bool ignore = GetFlag(b.item, "feature:ignore") ? true : false;
+ if (!bname || ignore) {
+ if (!bname && !ignore) {
+ Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n),
+ "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name")));
+ }
+ b = Next(b);
+ continue;
+ }
+ Printv(base_class, bname, NIL);
+ b = Next(b);
+ if (b.item) {
+ Putc(',', base_class);
+ }
+ }
+ }
+
+ /* dealing with abstract base class */
+ String *abcs = Getattr(n, "feature:python:abc");
+ if (py3 && abcs) {
+ if (Len(base_class)) {
+ Putc(',', base_class);
+ }
+ Printv(base_class, abcs, NIL);
+ }
+
+ if (!single_inh) {
+ Printv(f_shadow, "class ", class_name, NIL);
+
+ if (Len(base_class)) {
+ Printf(f_shadow, "(%s)", base_class);
+ } else {
+ if (!classic) {
+ Printf(f_shadow, modern ? "(object)" : "(_object)");
+ }
+ if (GetFlag(n, "feature:exceptionclass") ) {
+ Printf(f_shadow, "(Exception)");
+ }
+ }
+
+ Printf(f_shadow, ":\n");
+ if (have_docstring(n)) {
+ String *str = docstring(n, AUTODOC_CLASS, tab4);
+ if (str && Len(str))
+ Printv(f_shadow, tab4, str, "\n", NIL);
+ }
+
+ if (!modern) {
+ Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL);
+ if (Len(base_class)) {
+ Printf(f_shadow, "%sfor _s in [%s]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))\n", tab4, base_class);
+ }
+
+ if (!GetFlag(n, "feature:python:nondynamic")) {
+ Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", NIL);
+ } else {
+ Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", NIL);
+ }
+
+ Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL);
+ if (Len(base_class)) {
+ Printf(f_shadow, "%sfor _s in [%s]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))\n", tab4, base_class);
+ }
+
+ Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL);
+ } else {
+ Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL);
+ /* Add static attribute */
+ if (GetFlag(n, "feature:python:nondynamic")) {
+ Printv(f_shadow_file,
+ tab4, "__setattr__ = _swig_setattr_nondynamic_method(object.__setattr__)\n",
+ tab4, "class __metaclass__(type):\n", tab4, tab4, "__setattr__ = _swig_setattr_nondynamic_method(type.__setattr__)\n", NIL);
+ }
+ }
+ }
+ }
+
+ /* Emit all of the members */
+
+ in_class = 1;
+ if (single_inh) {
+ class_members = NewHash();
+ builtin_pre_decl(n, base_node);
+ }
+
+ /* Overide the shadow file so we can capture its methods */
+ f_shadow = NewString("");
+
+ Language::classHandler(n);
+
+ in_class = 0;
+
+ /* Complete the class */
+ if (shadow) {
+ /* Generate a class registration function */
+ if (!single_inh) {
+ String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers)
+ SwigType *smart = 0;
+ if (smartptr) {
+ SwigType *cpt = Swig_cparse_type(smartptr);
+ if (cpt) {
+ smart = SwigType_typedef_resolve_all(cpt);
+ Delete(cpt);
+ } else {
+ // TODO: report line number of where the feature comes from
+ Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname);
+ }
+ }
+ SwigType *ct = Copy(smart ? smart : real_classname);
+ SwigType_add_pointer(ct);
+ SwigType *realct = Copy(real_classname);
+ SwigType_add_pointer(realct);
+ SwigType_remember(realct);
+ Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
+ Printv(f_wrappers, " PyObject *obj;\n", NIL);
+ if (modernargs) {
+ if (fastunpack) {
+ Printv(f_wrappers, " if (!SWIG_Python_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
+ } else {
+ Printv(f_wrappers, " if (!PyArg_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
+ }
+ } else {
+ Printv(f_wrappers, " if (!PyArg_ParseTuple(args,(char*)\"O:swigregister\", &obj)) return NULL;\n", NIL);
+ }
+
+ Printv(f_wrappers,
+ " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n",
+ " return SWIG_Py_Void();\n", "}\n\n", NIL);
+ String *cname = NewStringf("%s_swigregister", class_name);
+ add_method(cname, cname, 0);
+ Delete(smart);
+ Delete(cname);
+ Delete(ct);
+ Delete(realct);
+ }
+ if (!have_constructor) {
+ if (!single_inh)
+ Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
+ } else if (fastinit && !single_inh) {
+
+ Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
+ Printv(f_wrappers, " return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL);
+ String *cname = NewStringf("%s_swiginit", class_name);
+ add_method(cname, cname, 0);
+ Delete(cname);
+ }
+ if (!have_repr && !single_inh) {
+ /* Supply a repr method for this class */
+ String *rname = SwigType_namestr(real_classname);
+ if (new_repr) {
+ Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL);
+ } else {
+ Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL);
+ }
+ Delete(rname);
+ }
+
+ if (single_inh) {
+ builtin_post_decl(f_builtins, n);
+ String *rname = SwigType_namestr(real_classname);
+ Printf(f_builtins, "template <> PyMethodDef PySwigBuiltin< %s >::methods[] = {\n", rname);
+ Delete(rname);
+ }
+
+ if (builtin_tp_init) {
+ Delete(builtin_tp_init);
+ builtin_tp_init = 0;
+ }
+
+ /* Now emit methods */
+ if (!single_inh)
+ Printv(f_shadow_file, f_shadow, NIL);
+
+ /* Now the Ptr class */
+ if (classptr && !single_inh) {
+ Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL);
+ if (!modern) {
+ Printv(f_shadow_file,
+ tab8, "try: self.this.append(this)\n",
+ tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL);
+ } else {
+ Printv(f_shadow_file,
+ tab8, "try: self.this.append(this)\n",
+ tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL);
+ }
+ }
+
+ if (!single_inh) {
+ if (fastproxy) {
+ List *shadow_list = Getattr(n, "shadow_methods");
+ for (int i = 0; i < Len(shadow_list); ++i) {
+ String *symname = Getitem(shadow_list, i);
+ Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name);
+ }
+ }
+ Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name);
+ Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name);
+
+ shadow_indent = 0;
+ Printf(f_shadow_file, "%s\n", f_shadow_stubs);
+ }
+ shadow_indent = 0;
+ Clear(f_shadow_stubs);
+ }
+
+ if (single_inh) {
+ Dump(f_shadow, f_builtins);
+ Printf(f_builtins, " {NULL} // Sentinel\n};\n\n");
+ Delete(class_members);
+ class_members = 0;
+ }
+
+ classic = oldclassic;
+ modern = oldmodern;
+
+ /* Restore shadow file back to original version */
+ Delete(f_shadow);
+ f_shadow = f_shadow_file;
+
+ return SWIG_OK;
+ }
/* ------------------------------------------------------------
* functionHandler() - Mainly overloaded for callback handling
@@ -3076,495 +3358,575 @@ public:
* memberfunctionHandler()
* ------------------------------------------------------------ */
- virtual int memberfunctionHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
- int oldshadow;
+ virtual int memberfunctionHandler(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ int oldshadow;
- /* Create the default member function */
- oldshadow = shadow; /* Disable shadowing when wrapping member functions */
- if (shadow)
- shadow = shadow | PYSHADOW_MEMBER;
- Language::memberfunctionHandler(n);
- shadow = oldshadow;
+ /* Create the default member function */
+ oldshadow = shadow; /* Disable shadowing when wrapping member functions */
+ if (shadow)
+ shadow = shadow | PYSHADOW_MEMBER;
+ Language::memberfunctionHandler(n);
+ shadow = oldshadow;
- if (!Getattr(n, "sym:nextSibling")) {
- if (shadow) {
- int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
- int fproxy = fastproxy;
- if (Strcmp(symname, "__repr__") == 0) {
- have_repr = 1;
- }
- if (Getattr(n, "feature:shadow")) {
- String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
- String *pyaction = NewStringf("%s.%s", module, Swig_name_member(NSPACE_TODO, class_name, symname));
- Replaceall(pycode, "$action", pyaction);
- Delete(pyaction);
- Printv(f_shadow, pycode, "\n", NIL);
- Delete(pycode);
- fproxy = 0;
- } else {
- String *parms = make_pyParmList(n, true, false, allow_kwargs);
- String *callParms = make_pyParmList(n, true, true, allow_kwargs);
- if (!have_addtofunc(n)) {
- if (!fastproxy || olddefs) {
- Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL);
- Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
+ if (!Getattr(n, "sym:nextSibling")) {
+ if (builtin && in_class) {
+ String *name = Getattr(n, "name");
+ if (checkAttribute(n, "access", "public") && strncmp(Char(name), "operator ", 9) && !Getattr(class_members, name)) {
+ String *fullname = Swig_name_member(NULL, class_name, symname);
+ String *wname = Swig_name_wrapper(fullname);
+ Setattr(class_members, name, name);
+ ParmList *parms = Getattr(n, "parms");
+ bool noArgs = !parms || Len(parms) == 0;
+ String *pyflags = NewString(noArgs ? "METH_NOARGS" : "METH_VARARGS");
+ Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags));
+ Delete(name);
+ Delete(fullname);
+ Delete(wname);
+ Delete(pyflags);
+ }
+ } else if (shadow) {
+ int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
+ int fproxy = fastproxy;
+ if (Strcmp(symname, "__repr__") == 0) {
+ have_repr = 1;
+ }
+ if (Getattr(n, "feature:shadow")) {
+ String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
+ String *pyaction = NewStringf("%s.%s", module, Swig_name_member(NSPACE_TODO, class_name, symname));
+ Replaceall(pycode, "$action", pyaction);
+ Delete(pyaction);
+ Printv(f_shadow, pycode, "\n", NIL);
+ Delete(pycode);
+ fproxy = 0;
+ } else {
+ String *parms = make_pyParmList(n, true, false, allow_kwargs);
+ String *callParms = make_pyParmList(n, true, true, allow_kwargs);
+ if (!have_addtofunc(n)) {
+ if (!fastproxy || olddefs) {
+ Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL);
+ Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
+ }
+ } else {
+ Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL);
+ Printv(f_shadow, "\n", NIL);
+ if (have_docstring(n))
+ Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL);
+ if (have_pythonprepend(n)) {
+ fproxy = 0;
+ Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
+ }
+ if (have_pythonappend(n)) {
+ fproxy = 0;
+ Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
+ Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
+ Printv(f_shadow, tab8, "return val\n\n", NIL);
+ } else {
+ Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL);
+ }
+ }
+ }
+ if (fproxy) {
+ List *shadow_list = Getattr(getCurrentClass(), "shadow_methods");
+ if (!shadow_list) {
+ shadow_list = NewList();
+ Setattr(getCurrentClass(), "shadow_methods", shadow_list);
+ Delete(shadow_list);
+ }
+ Append(shadow_list, symname);
+ }
}
- } else {
- Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL);
- Printv(f_shadow, "\n", NIL);
- if (have_docstring(n))
- Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL);
- if (have_pythonprepend(n)) {
- fproxy = 0;
- Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
- }
- if (have_pythonappend(n)) {
- fproxy = 0;
- Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
- Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
- Printv(f_shadow, tab8, "return val\n\n", NIL);
- } else {
- Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL);
- }
- }
}
- if (fproxy) {
- List *shadow_list = Getattr(getCurrentClass(), "shadow_methods");
- if (!shadow_list) {
- shadow_list = NewList();
- Setattr(getCurrentClass(), "shadow_methods", shadow_list);
- Delete(shadow_list);
- }
- Append(shadow_list, symname);
- }
- }
+ return SWIG_OK;
}
- return SWIG_OK;
- }
/* ------------------------------------------------------------
* staticmemberfunctionHandler()
* ------------------------------------------------------------ */
- virtual int staticmemberfunctionHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
- Language::staticmemberfunctionHandler(n);
+ virtual int staticmemberfunctionHandler(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ if (builtin && in_class) {
+ Swig_save("builtin_memberconstantHandler", n, "builtin_sym:name", NIL);
+ Setattr(n, "builtin_sym:name", symname);
+ }
+ Language::staticmemberfunctionHandler(n);
+ if (builtin && in_class) {
+ Swig_restore(n);
+ }
- if (Getattr(n, "sym:nextSibling")) {
- return SWIG_OK;
+ if (Getattr(n, "sym:nextSibling")) {
+ return SWIG_OK;
+ }
+
+ if (builtin && in_class) {
+ String *name = Getattr(n, "name");
+ if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) {
+ String *fullname = Swig_name_member(NULL, class_name, name);
+ String *wname = Swig_name_wrapper(fullname);
+ Setattr(class_members, name, name);
+ String *pyflags = NewString("METH_VARARGS|METH_STATIC");
+ Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags));
+ Delete(name);
+ Delete(fullname);
+ Delete(wname);
+ Delete(pyflags);
+ }
+ } else if (shadow ) {
+ if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) {
+ int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
+ String *parms = make_pyParmList(n, false, false, kw);
+ String *callParms = make_pyParmList(n, false, true, kw);
+ Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL);
+ if (have_docstring(n))
+ Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL);
+ if (have_pythonprepend(n))
+ Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
+ if (have_pythonappend(n)) {
+ Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
+ Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
+ Printv(f_shadow, tab8, "return val\n\n", NIL);
+ } else {
+ Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL);
+ }
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", symname, ")\n", NIL);
+
+ if (!modern) {
+ Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL);
+ }
+
+ } else {
+ if (!modern) {
+ Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
+ }
+ if (!classic) {
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL);
+ }
+ }
+ }
+ return SWIG_OK;
}
- if (shadow) {
- if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) {
- int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
- String *parms = make_pyParmList(n, false, false, kw);
- String *callParms = make_pyParmList(n, false, true, kw);
- Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL);
- if (have_docstring(n))
- Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL);
- if (have_pythonprepend(n))
- Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
- if (have_pythonappend(n)) {
- Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
- Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
- Printv(f_shadow, tab8, "return val\n\n", NIL);
- } else {
- Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL);
- }
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", symname, ")\n", NIL);
-
- if (!modern) {
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL);
- }
-
- } else {
- if (!modern) {
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
- }
- if (!classic) {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL);
- }
- }
- }
- return SWIG_OK;
- }
-
/* ------------------------------------------------------------
* constructorDeclaration()
* ------------------------------------------------------------ */
- virtual int constructorHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
- int oldshadow = shadow;
- int use_director = Swig_directorclass(n);
+ virtual int constructorHandler(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ int oldshadow = shadow;
+ int use_director = Swig_directorclass(n);
- /*
- * If we're wrapping the constructor of a C++ director class, prepend a new parameter
- * to receive the scripting language object (e.g. 'self')
- *
- */
- Swig_save("python:constructorHandler", n, "parms", NIL);
- if (use_director) {
- Parm *parms = Getattr(n, "parms");
- Parm *self;
- String *name = NewString("self");
- String *type = NewString("PyObject");
- SwigType_add_pointer(type);
- self = NewParm(type, name, n);
- Delete(type);
- Delete(name);
- Setattr(self, "lname", "O");
- if (parms)
- set_nextSibling(self, parms);
- Setattr(n, "parms", self);
- Setattr(n, "wrap:self", "1");
- Setattr(n, "hidden", "1");
- Delete(self);
- }
-
- if (shadow)
- shadow = shadow | PYSHADOW_MEMBER;
- Language::constructorHandler(n);
- shadow = oldshadow;
-
- Delattr(n, "wrap:self");
- Swig_restore(n);
-
- if (!Getattr(n, "sym:nextSibling")) {
- if (shadow) {
- int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0;
- int handled_as_init = 0;
- if (!have_constructor) {
- String *nname = Getattr(n, "sym:name");
- String *sname = Getattr(getCurrentClass(), "sym:name");
- String *cname = Swig_name_construct(NSPACE_TODO, sname);
- handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0);
- Delete(cname);
+ /*
+ * If we're wrapping the constructor of a C++ director class, prepend a new parameter
+ * to receive the scripting language object (e.g. 'self')
+ *
+ */
+ Swig_save("python:constructorHandler", n, "parms", NIL);
+ if (use_director) {
+ Parm *parms = Getattr(n, "parms");
+ Parm *self;
+ String *name = NewString("self");
+ String *type = NewString("PyObject");
+ SwigType_add_pointer(type);
+ self = NewParm(type, name, n);
+ Delete(type);
+ Delete(name);
+ Setattr(self, "lname", "O");
+ if (parms)
+ set_nextSibling(self, parms);
+ Setattr(n, "parms", self);
+ Setattr(n, "wrap:self", "1");
+ Setattr(n, "hidden", "1");
+ Delete(self);
}
+
+ if (shadow)
+ shadow = shadow | PYSHADOW_MEMBER;
+ Language::constructorHandler(n);
+ shadow = oldshadow;
+
+ Delattr(n, "wrap:self");
+ Swig_restore(n);
+
+ if (!Getattr(n, "sym:nextSibling")) {
+ if (builtin && in_class) {
+ String *name = NewString("new");
+ if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) {
+ Setattr(class_members, name, name);
+ String *fullname = Swig_name_member(NULL, name, class_name);
+ if (!builtin_tp_init)
+ builtin_tp_init = Swig_name_wrapper(fullname);
+ /*
+ ParmList *parms = Getattr(n, "parms");
+ char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS";
+ Printf(f_shadow, " { \"__init__\", (PyCFunction) %s, %s, \"\" },\n", builtin_tp_init, Char(pyflags));
+ */
+ Delete(fullname);
+ }
+ Delete(name);
+ } else if (shadow) {
+ int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0;
+ int handled_as_init = 0;
+ if (!have_constructor) {
+ String *nname = Getattr(n, "sym:name");
+ String *sname = Getattr(getCurrentClass(), "sym:name");
+ String *cname = Swig_name_construct(NSPACE_TODO, sname);
+ handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0);
+ Delete(cname);
+ }
- if (!have_constructor && handled_as_init) {
- if (Getattr(n, "feature:shadow")) {
- String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
- String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname));
- Replaceall(pycode, "$action", pyaction);
- Delete(pyaction);
- Printv(f_shadow, pycode, "\n", NIL);
- Delete(pycode);
- } else {
- String *pass_self = NewString("");
- Node *parent = Swig_methodclass(n);
- String *classname = Swig_class_name(parent);
- String *rclassname = Swig_class_name(getCurrentClass());
- assert(rclassname);
+ if (!have_constructor && handled_as_init) {
+ if (Getattr(n, "feature:shadow")) {
+ String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
+ String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname));
+ Replaceall(pycode, "$action", pyaction);
+ Delete(pyaction);
+ Printv(f_shadow, pycode, "\n", NIL);
+ Delete(pycode);
+ } else {
+ String *pass_self = NewString("");
+ Node *parent = Swig_methodclass(n);
+ String *classname = Swig_class_name(parent);
+ String *rclassname = Swig_class_name(getCurrentClass());
+ assert(rclassname);
- String *parms = make_pyParmList(n, true, false, allow_kwargs);
- /* Pass 'self' only if using director */
- String *callParms = make_pyParmList(n, false, true, allow_kwargs);
+ String *parms = make_pyParmList(n, true, false, allow_kwargs);
+ /* Pass 'self' only if using director */
+ String *callParms = make_pyParmList(n, false, true, allow_kwargs);
- if (use_director) {
- Insert(callParms, 0, "_self, ");
- Printv(pass_self, tab8, NIL);
- Printf(pass_self, "if self.__class__ == %s:\n", classname);
- //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL);
- Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL);
- }
+ if (use_director) {
+ Insert(callParms, 0, "_self, ");
+ Printv(pass_self, tab8, NIL);
+ Printf(pass_self, "if self.__class__ == %s:\n", classname);
+ //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL);
+ Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL);
+ }
- Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL);
- if (have_docstring(n))
- Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL);
- if (have_pythonprepend(n))
- Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
- Printv(f_shadow, pass_self, NIL);
- if (fastinit) {
- Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL);
- } else {
- Printv(f_shadow,
- tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n",
- tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL);
- }
- if (have_pythonappend(n))
- Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL);
- Delete(pass_self);
- }
- have_constructor = 1;
- } else {
- /* Hmmm. We seem to be creating a different constructor. We're just going to create a
- function for it. */
+ Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL);
+ if (have_docstring(n))
+ Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL);
+ if (have_pythonprepend(n))
+ Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
+ Printv(f_shadow, pass_self, NIL);
+ if (fastinit) {
+ Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL);
+ } else {
+ Printv(f_shadow,
+ tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n",
+ tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL);
+ }
+ if (have_pythonappend(n))
+ Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL);
+ Delete(pass_self);
+ }
+ have_constructor = 1;
+ } else {
+ /* Hmmm. We seem to be creating a different constructor. We're just going to create a
+ function for it. */
- if (Getattr(n, "feature:shadow")) {
- String *pycode = pythoncode(Getattr(n, "feature:shadow"), "");
- String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname));
- Replaceall(pycode, "$action", pyaction);
- Delete(pyaction);
- Printv(f_shadow_stubs, pycode, "\n", NIL);
- Delete(pycode);
- } else {
- String *parms = make_pyParmList(n, false, false, allow_kwargs);
- String *callParms = make_pyParmList(n, false, true, allow_kwargs);
+ if (Getattr(n, "feature:shadow")) {
+ String *pycode = pythoncode(Getattr(n, "feature:shadow"), "");
+ String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname));
+ Replaceall(pycode, "$action", pyaction);
+ Delete(pyaction);
+ Printv(f_shadow_stubs, pycode, "\n", NIL);
+ Delete(pycode);
+ } else {
+ String *parms = make_pyParmList(n, false, false, allow_kwargs);
+ String *callParms = make_pyParmList(n, false, true, allow_kwargs);
- Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL);
- if (have_docstring(n))
- Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL);
- if (have_pythonprepend(n))
- Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL);
- Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", NIL);
+ Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL);
+ if (have_docstring(n))
+ Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL);
+ if (have_pythonprepend(n))
+ Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL);
+ Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", NIL);
#ifdef USE_THISOWN
- Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL);
+ Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL);
#endif
- if (have_pythonappend(n))
- Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL);
- Printv(f_shadow_stubs, tab4, "return val\n", NIL);
- }
+ if (have_pythonappend(n))
+ Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL);
+ Printv(f_shadow_stubs, tab4, "return val\n", NIL);
+ }
+ }
+ }
}
- }
+ return SWIG_OK;
}
- return SWIG_OK;
- }
/* ------------------------------------------------------------
* destructorHandler()
* ------------------------------------------------------------ */
- virtual int destructorHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
- int oldshadow = shadow;
-
- if (shadow)
- shadow = shadow | PYSHADOW_MEMBER;
- //Setattr(n,"emit:dealloc","1");
- Language::destructorHandler(n);
- shadow = oldshadow;
- if (shadow) {
- if (Getattr(n, "feature:shadow")) {
- String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
- String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(NSPACE_TODO, symname));
- Replaceall(pycode, "$action", pyaction);
- Delete(pyaction);
- Printv(f_shadow, pycode, "\n", NIL);
- Delete(pycode);
- } else {
- Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL);
- if (!have_pythonprepend(n) && !have_pythonappend(n)) {
- if (proxydel) {
- Printv(f_shadow, tab4, "__del__ = lambda self : None;\n", NIL);
- }
- return SWIG_OK;
+ virtual int destructorHandler(Node *n) {
+ if (builtin && in_class) {
+ String *name = NewString("delete");
+ if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) {
+ Setattr(class_members, name, name);
+ /*
+ String *fullname = Swig_name_member(NULL, name, class_name);
+ String *wname = Swig_name_wrapper(fullname);
+ ParmList *parms = Getattr(n, "parms");
+ char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS";
+ Printf(f_shadow, " { \"__del__\", (PyCFunction) %s, %s, \"\" },\n", wname, Char(pyflags));
+ Delete(fullname);
+ Delete(wname);
+ */
+ }
+ Delete(name);
+ return SWIG_OK;
}
- Printv(f_shadow, tab4, "def __del__(self):\n", NIL);
- if (have_docstring(n))
- Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL);
- if (have_pythonprepend(n))
- Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
+
+ String *symname = Getattr(n, "sym:name");
+ int oldshadow = shadow;
+
+ if (shadow)
+ shadow = shadow | PYSHADOW_MEMBER;
+ //Setattr(n,"emit:dealloc","1");
+ Language::destructorHandler(n);
+ shadow = oldshadow;
+
+ if (shadow) {
+ if (Getattr(n, "feature:shadow")) {
+ String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
+ String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(NSPACE_TODO, symname));
+ Replaceall(pycode, "$action", pyaction);
+ Delete(pyaction);
+ Printv(f_shadow, pycode, "\n", NIL);
+ Delete(pycode);
+ } else {
+ Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL);
+ if (!have_pythonprepend(n) && !have_pythonappend(n)) {
+ if (proxydel) {
+ Printv(f_shadow, tab4, "__del__ = lambda self : None;\n", NIL);
+ }
+ return SWIG_OK;
+ }
+ Printv(f_shadow, tab4, "def __del__(self):\n", NIL);
+ if (have_docstring(n))
+ Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL);
+ if (have_pythonprepend(n))
+ Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
#ifdef USE_THISOWN
- Printv(f_shadow, tab8, "try:\n", NIL);
- Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL);
- Printv(f_shadow, tab8, "except: pass\n", NIL);
+ Printv(f_shadow, tab8, "try:\n", NIL);
+ Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL);
+ Printv(f_shadow, tab8, "except: pass\n", NIL);
#else
#endif
- if (have_pythonappend(n))
- Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
- Printv(f_shadow, tab8, "pass\n", NIL);
- Printv(f_shadow, "\n", NIL);
- }
- }
- return SWIG_OK;
- }
-
- /* ------------------------------------------------------------
- * membervariableHandler()
- * ------------------------------------------------------------ */
-
- virtual int membervariableHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
-
- int oldshadow = shadow;
- if (shadow)
- shadow = shadow | PYSHADOW_MEMBER;
- Language::membervariableHandler(n);
- shadow = oldshadow;
-
- if (shadow) {
- String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
- String *setname = Swig_name_set(NSPACE_TODO, mname);
- String *getname = Swig_name_get(NSPACE_TODO, mname);
- if (shadow) {
- int assignable = is_assignable(n);
- if (!modern) {
- if (assignable) {
- Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
- }
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
+ if (have_pythonappend(n))
+ Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
+ Printv(f_shadow, tab8, "pass\n", NIL);
+ Printv(f_shadow, "\n", NIL);
+ }
}
- if (!classic) {
- if (!assignable) {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
- } else {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
- }
+ return SWIG_OK;
+ }
+
+ /* ------------------------------------------------------------
+ * membervariableHandler()
+ * ------------------------------------------------------------ */
+
+ virtual int membervariableHandler(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+
+ int oldshadow = shadow;
+ if (shadow)
+ shadow = shadow | PYSHADOW_MEMBER;
+ Language::membervariableHandler(n);
+ shadow = oldshadow;
+
+ if (builtin && in_class) {
+ } else if (shadow) {
+ String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
+ String *setname = Swig_name_set(NSPACE_TODO, mname);
+ String *getname = Swig_name_get(NSPACE_TODO, mname);
+ int assignable = is_assignable(n);
+ if (!modern) {
+ if (assignable) {
+ Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
+ }
+ Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
+ }
+ if (!classic) {
+ if (!assignable) {
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
+ } else {
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
+ }
+ }
+ Delete(mname);
+ Delete(setname);
+ Delete(getname);
}
- }
- Delete(mname);
- Delete(setname);
- Delete(getname);
+
+ return SWIG_OK;
}
- return SWIG_OK;
- }
+ /* ------------------------------------------------------------
+ * staticmembervariableHandler()
+ * ------------------------------------------------------------ */
- /* ------------------------------------------------------------
- * staticmembervariableHandler()
- * ------------------------------------------------------------ */
+ virtual int staticmembervariableHandler(Node *n) {
+ Swig_save("builtin_staticmembervariableHandler", n, "builtin_symname", NIL);
+ Language::staticmembervariableHandler(n);
+ Swig_restore(n);
- virtual int staticmembervariableHandler(Node *n) {
- Language::staticmembervariableHandler(n);
+ if (GetFlag(n, "wrappedasconstant"))
+ return SWIG_OK;
- if (shadow && !GetFlag(n, "wrappedasconstant")) {
- String *symname = Getattr(n, "sym:name");
- if (GetFlag(n, "hasconsttype")) {
- String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
- Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname);
- Delete(mname);
- } else {
- String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
- String *getname = Swig_name_get(NSPACE_TODO, mname);
- String *wrapgetname = Swig_name_wrapper(getname);
- String *vargetname = NewStringf("Swig_var_%s", getname);
- String *setname = Swig_name_set(NSPACE_TODO, mname);
- String *wrapsetname = Swig_name_wrapper(setname);
- String *varsetname = NewStringf("Swig_var_%s", setname);
+ String *symname = Getattr(n, "sym:name");
- Wrapper *f = NewWrapper();
- Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL);
- Printv(f->code, " return ", vargetname, "();\n", NIL);
- Append(f->code, "}\n");
- add_method(getname, wrapgetname, 0);
- Wrapper_print(f, f_wrappers);
- DelWrapper(f);
- int assignable = is_assignable(n);
- if (assignable) {
- Wrapper *f = NewWrapper();
- Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL);
- Wrapper_add_local(f, "value", "PyObject *value");
- Wrapper_add_local(f, "res", "int res");
- Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n");
- Printv(f->code, "res = ", varsetname, "(value);\n", NIL);
- Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n");
- Append(f->code, "}\n");
- Wrapper_print(f, f_wrappers);
- add_method(setname, wrapsetname, 0);
- DelWrapper(f);
+ if (shadow) {
+ if (GetFlag(n, "hasconsttype")) {
+ String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
+ Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname);
+ Delete(mname);
+ } else {
+ String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
+ String *getname = Swig_name_get(NSPACE_TODO, mname);
+ String *wrapgetname = Swig_name_wrapper(getname);
+ String *vargetname = NewStringf("Swig_var_%s", getname);
+ String *setname = Swig_name_set(NSPACE_TODO, mname);
+ String *wrapsetname = Swig_name_wrapper(setname);
+ String *varsetname = NewStringf("Swig_var_%s", setname);
+
+ Wrapper *f = NewWrapper();
+ Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL);
+ Printv(f->code, " return ", vargetname, "();\n", NIL);
+ Append(f->code, "}\n");
+ add_method(getname, wrapgetname, 0);
+ Wrapper_print(f, f_wrappers);
+ DelWrapper(f);
+ int assignable = is_assignable(n);
+ if (assignable) {
+ Wrapper *f = NewWrapper();
+ Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL);
+ Wrapper_add_local(f, "value", "PyObject *value");
+ Wrapper_add_local(f, "res", "int res");
+ Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n");
+ Printv(f->code, "res = ", varsetname, "(value);\n", NIL);
+ Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n");
+ Append(f->code, "}\n");
+ Wrapper_print(f, f_wrappers);
+ add_method(setname, wrapsetname, 0);
+ DelWrapper(f);
+ }
+ if (!modern) {
+ if (assignable) {
+ Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
+ }
+ Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
+ }
+ if (!classic) {
+ if (!assignable) {
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
+ } else {
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
+ }
+ }
+ Delete(mname);
+ Delete(getname);
+ Delete(wrapgetname);
+ Delete(vargetname);
+ Delete(setname);
+ Delete(wrapsetname);
+ Delete(varsetname);
+ }
}
- if (!modern) {
- if (assignable) {
- Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
- }
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
+ return SWIG_OK;
+ }
+
+ /* ------------------------------------------------------------
+ * memberconstantHandler()
+ * ------------------------------------------------------------ */
+
+ virtual int memberconstantHandler(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ if (builtin && in_class) {
+ Swig_save("builtin_memberconstantHandler", n, "builtin_sym:name", NIL);
+ Setattr(n, "builtin_sym:name", symname);
}
- if (!classic) {
- if (!assignable) {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
- } else {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
- }
+ int oldshadow = shadow;
+ if (shadow)
+ shadow = shadow | PYSHADOW_MEMBER;
+ Language::memberconstantHandler(n);
+ shadow = oldshadow;
+
+ if (builtin && in_class) {
+ Swig_restore(n);
+ } else if (shadow) {
+ Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
}
- Delete(mname);
- Delete(getname);
- Delete(wrapgetname);
- Delete(vargetname);
- Delete(setname);
- Delete(wrapsetname);
- Delete(varsetname);
- }
+ return SWIG_OK;
}
- return SWIG_OK;
- }
- /* ------------------------------------------------------------
- * memberconstantHandler()
- * ------------------------------------------------------------ */
+ /* ------------------------------------------------------------
+ * insertDirective()
+ *
+ * Hook for %insert directive. We're going to look for special %shadow inserts
+ * as a special case so we can do indenting correctly
+ * ------------------------------------------------------------ */
- virtual int memberconstantHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
- int oldshadow = shadow;
- if (shadow)
- shadow = shadow | PYSHADOW_MEMBER;
- Language::memberconstantHandler(n);
- shadow = oldshadow;
+ virtual int insertDirective(Node *n) {
+ String *code = Getattr(n, "code");
+ String *section = Getattr(n, "section");
- if (shadow) {
- Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
+ if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) {
+ if (shadow) {
+ String *pycode = pythoncode(code, shadow_indent);
+ Printv(f_shadow, pycode, NIL);
+ Delete(pycode);
+ }
+ } else {
+ Language::insertDirective(n);
+ }
+ return SWIG_OK;
}
- return SWIG_OK;
- }
- /* ------------------------------------------------------------
- * insertDirective()
- *
- * Hook for %insert directive. We're going to look for special %shadow inserts
- * as a special case so we can do indenting correctly
- * ------------------------------------------------------------ */
+ virtual String *runtimeCode() {
+ String *s = NewString("");
+ String *shead = Swig_include_sys("pyhead.swg");
+ if (!shead) {
+ Printf(stderr, "*** Unable to open 'pyhead.swg'\n");
+ } else {
+ Append(s, shead);
+ Delete(shead);
+ }
+ String *serrors = Swig_include_sys("pyerrors.swg");
+ if (!serrors) {
+ Printf(stderr, "*** Unable to open 'pyerrors.swg'\n");
+ } else {
+ Append(s, serrors);
+ Delete(serrors);
+ }
+ String *sthread = Swig_include_sys("pythreads.swg");
+ if (!sthread) {
+ Printf(stderr, "*** Unable to open 'pythreads.swg'\n");
+ } else {
+ Append(s, sthread);
+ Delete(sthread);
+ }
+ String *sapi = Swig_include_sys("pyapi.swg");
+ if (!sapi) {
+ Printf(stderr, "*** Unable to open 'pyapi.swg'\n");
+ } else {
+ Append(s, sapi);
+ Delete(sapi);
+ }
+ String *srun = Swig_include_sys("pyrun.swg");
+ if (!srun) {
+ Printf(stderr, "*** Unable to open 'pyrun.swg'\n");
+ } else {
+ Append(s, srun);
+ Delete(srun);
+ }
+ return s;
+ }
- virtual int insertDirective(Node *n) {
- String *code = Getattr(n, "code");
- String *section = Getattr(n, "section");
-
- if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) {
- if (shadow) {
- String *pycode = pythoncode(code, shadow_indent);
- Printv(f_shadow, pycode, NIL);
- Delete(pycode);
- }
- } else {
- Language::insertDirective(n);
+ virtual String *defaultExternalRuntimeFilename() {
+ return NewString("swigpyrun.h");
}
- return SWIG_OK;
- }
-
- virtual String *runtimeCode() {
- String *s = NewString("");
- String *shead = Swig_include_sys("pyhead.swg");
- if (!shead) {
- Printf(stderr, "*** Unable to open 'pyhead.swg'\n");
- } else {
- Append(s, shead);
- Delete(shead);
- }
- String *serrors = Swig_include_sys("pyerrors.swg");
- if (!serrors) {
- Printf(stderr, "*** Unable to open 'pyerrors.swg'\n");
- } else {
- Append(s, serrors);
- Delete(serrors);
- }
- String *sthread = Swig_include_sys("pythreads.swg");
- if (!sthread) {
- Printf(stderr, "*** Unable to open 'pythreads.swg'\n");
- } else {
- Append(s, sthread);
- Delete(sthread);
- }
- String *sapi = Swig_include_sys("pyapi.swg");
- if (!sapi) {
- Printf(stderr, "*** Unable to open 'pyapi.swg'\n");
- } else {
- Append(s, sapi);
- Delete(sapi);
- }
- String *srun = Swig_include_sys("pyrun.swg");
- if (!srun) {
- Printf(stderr, "*** Unable to open 'pyrun.swg'\n");
- } else {
- Append(s, srun);
- Delete(srun);
- }
- return s;
- }
-
- virtual String *defaultExternalRuntimeFilename() {
- return NewString("swigpyrun.h");
- }
};
From 56dfa781ff20e093d8a50e74905e4422bb8ac224 Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Wed, 8 Dec 2010 16:57:32 +0000
Subject: [PATCH 037/317] Only check for Go version if a compiler was found.
This fixes a syntax error in the code which would occur when no Go compiler was found at all.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12333 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
configure.in | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/configure.in b/configure.in
index f9410fdf8..fa0372d9a 100644
--- a/configure.in
+++ b/configure.in
@@ -2006,17 +2006,18 @@ else
GO="$GOBIN"
fi
- GOGCC=false
- if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then
- GOGCC=true
- else
- go_version=`$GO -V | sed -e 's/.*version \([[0-9]]*\).*/\1/'`
- if test "$go_version" -lt 6707; then
- AC_MSG_NOTICE([Installed Go too old; disabling Go])
- GO=
- fi
+ if test -n "$GO" ; then
+ GOGCC=false
+ if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then
+ GOGCC=true
+ else
+ go_version=`$GO -V | sed -e 's/.*version \([[0-9]]*\).*/\1/'`
+ if test "$go_version" -lt 6707; then
+ AC_MSG_NOTICE([Installed Go too old; disabling Go])
+ GO=
+ fi
+ fi
fi
-
fi
AC_SUBST(GOGCC)
From e120dfcc706717fc9373d023cfbdaba3f0340dd8 Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Wed, 8 Dec 2010 16:57:55 +0000
Subject: [PATCH 038/317] D compiler sanity checks in configure; check D2 by
default if no D1 compiler can be found.
For both D1 and D2, if the compiler has not been specified explicitly via a command line option, the configure script tries to compile a minimal program stub. Only if this succeeds, the respective compiler is enabled.
If neither a working D1 nor a working D2 compiler has been found, D is skipped completely as usual.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12334 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/Makefile.in | 14 ++++++++-----
configure.in | 48 ++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 55 insertions(+), 7 deletions(-)
diff --git a/Examples/Makefile.in b/Examples/Makefile.in
index 5d5590311..44794255c 100644
--- a/Examples/Makefile.in
+++ b/Examples/Makefile.in
@@ -1219,6 +1219,10 @@ go_clean:
DLIBPREFIX = @DLIBPREFIX@
+ifeq (,$(D_VERSION))
+ D_VERSION = @DDEFAULTVERSION@
+endif
+
ifeq (2,$(D_VERSION))
SWIGD = $(SWIG) -d -d2
DCOMPILER = @D2COMPILER@
@@ -1229,7 +1233,7 @@ endif
ifeq (dmd,$(DCOMPILER))
# DMD is 32bit only by now
- CFLAGS += -m32
+ DCFLAGS = -m32
endif
# ----------------------------------------------------------------
@@ -1238,8 +1242,8 @@ endif
d: $(SRCS)
$(SWIGD) $(SWIGOPT) $(INTERFACEPATH)
- $(CC) -c $(CCSHARED) $(CFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES)
- $(LDSHARED) $(CFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
+ $(CC) -c $(CCSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(ISRCS) $(INCLUDES)
+ $(LDSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
# ----------------------------------------------------------------
# Build a dynamically loadable D wrapper for a C++ module
@@ -1247,8 +1251,8 @@ d: $(SRCS)
d_cpp: $(SRCS)
$(SWIGD) -c++ $(SWIGOPT) $(INTERFACEPATH)
- $(CXX) -c $(CCSHARED) $(CFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES)
- $(CXXSHARED) $(CFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
+ $(CXX) -c $(CCSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_CFLAGS) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(INCLUDES)
+ $(CXXSHARED) $(CFLAGS) $(DCFLAGS) $(EXTRA_LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(DLIBPREFIX)$(TARGET)$(SO)
# ----------------------------------------------------------------
# Compile D files
diff --git a/configure.in b/configure.in
index fa0372d9a..20558ec95 100644
--- a/configure.in
+++ b/configure.in
@@ -2028,25 +2028,68 @@ AC_SUBST(GO)
#----------------------------------------------------------------
AC_ARG_WITH(d, AS_HELP_STRING([--without-d], [Disable D]), [with_d="$withval"], [with_d=yes])
-AC_ARG_WITH(d1-compiler, [ --with-d1-compiler=path Set location of D1 compiler (DMD compatible)],[D1COMPILERBIN="$withval"], [D1COMPILERBIN=])
+AC_ARG_WITH(d1-compiler, [ --with-d1-compiler=path Set location of D1/Tango compiler (DMD compatible)],[D1COMPILERBIN="$withval"], [D1COMPILERBIN=])
AC_ARG_WITH(d2-compiler, [ --with-d2-compiler=path Set location of D2 compiler (DMD compatible)],[D2COMPILERBIN="$withval"], [D2COMPILERBIN=])
+
# First, check for "--without-d" or "--with-d=no".
if test x"${with_d}" = xno -o x"${with_alllang}" = xno ; then
AC_MSG_NOTICE([Disabling D])
D1COMPILER=
D2COMPILER=
else
+ old_ac_ext=$ac_ext
+ ac_ext=d
+
if test -z "$D1COMPILERBIN" ; then
AC_CHECK_PROGS(D1COMPILER, dmd ldmd gdmd)
+
+ AC_MSG_CHECKING(whether the D1/Tango compiler works)
+ cat > conftest.$ac_ext <<_ACEOF
+import tango.io.Stdout;
+void main() {
+}
+_ACEOF
+ rm -f conftest.$ac_objext
+ AS_IF(
+ [_AC_DO_STDERR($D1COMPILER conftest.$ac_ext) && test ! -s conftest.err && test -s conftest.$ac_objext],
+ [AC_MSG_RESULT([yes])],
+ [_AC_MSG_LOG_CONFTEST AC_MSG_RESULT([no])
+ D1COMPILER=]
+ )
+ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
else
D1COMPILER="$D1COMPILERBIN"
fi
+
if test -z "$D2COMPILERBIN" ; then
AC_CHECK_PROGS(D2COMPILER, dmd gdmd)
+
+ AC_MSG_CHECKING(whether the D2 compiler works)
+ cat > conftest.$ac_ext <<_ACEOF
+import std.algorithm;
+void main() {
+}
+_ACEOF
+ rm -f conftest.$ac_objext
+ AS_IF(
+ [_AC_DO_STDERR($D2COMPILER conftest.$ac_ext) && test ! -s conftest.err && test -s conftest.$ac_objext],
+ [AC_MSG_RESULT([yes])],
+ [_AC_MSG_LOG_CONFTEST AC_MSG_RESULT([no])
+ D2COMPILER=]
+ )
+ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
else
D2COMPILER="$D2COMPILERBIN"
fi
+
+ ac_ext=$old_ac_ext
+fi
+
+if test -n "$D1COMPILER"; then
+ DDEFAULTVERSION=1
+elif test -n "$D2COMPILER"; then
+ DDEFAULTVERSION=2
fi
# Do not prefix library file names with "lib" on Windows.
@@ -2057,6 +2100,7 @@ esac
AC_SUBST(D1COMPILER)
AC_SUBST(D2COMPILER)
+AC_SUBST(DDEFAULTVERSION)
AC_SUBST(DLIBPREFIX)
#----------------------------------------------------------------
@@ -2216,7 +2260,7 @@ fi
AC_SUBST(SKIP_GO)
SKIP_D=
-if test -z "$D1COMPILER" && test -z "$D2COMPILER" ; then
+if test -z "$DDEFAULTVERSION" ; then
SKIP_D="1"
fi
AC_SUBST(SKIP_D)
From 79034755715aca918d1ed23454516e0f8d9ab577 Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Wed, 8 Dec 2010 16:58:14 +0000
Subject: [PATCH 039/317] [D] Workaround for an argument handling discrepancy
between DMD and LDC.
See http://dsource.org/projects/ldc/ticket/380 for the corresponding LDC ticket.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12335 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/Makefile.in | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Examples/Makefile.in b/Examples/Makefile.in
index 44794255c..1a02c4186 100644
--- a/Examples/Makefile.in
+++ b/Examples/Makefile.in
@@ -1258,8 +1258,10 @@ d_cpp: $(SRCS)
# Compile D files
# ----------------------------------------------------------------
+# Clear the DFLAGS environment variable for the compiler call itself
+# to work around a discrepancy in argument handling between DMD and LDC.
d_compile: $(SRCS)
- $(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS)
+ DFLAGS="" $(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS)
# -----------------------------------------------------------------
# Clean the D examples
From 32769435fd4f5c0ab7dde07feac70c0da1f19ebd Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Wed, 8 Dec 2010 19:35:03 +0000
Subject: [PATCH 040/317] More extensive member function pointer test
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12336 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/test-suite/common.mk | 1 +
Examples/test-suite/member_funcptr_galore.i | 83 +++++++++++++++++++++
2 files changed, 84 insertions(+)
create mode 100644 Examples/test-suite/member_funcptr_galore.i
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index f0fe4af1c..833e1532b 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -231,6 +231,7 @@ CPP_TEST_CASES += \
li_windows \
long_long_apply \
memberin_extend \
+ member_funcptr_galore \
member_pointer \
member_template \
minherit \
diff --git a/Examples/test-suite/member_funcptr_galore.i b/Examples/test-suite/member_funcptr_galore.i
new file mode 100644
index 000000000..02ff02be0
--- /dev/null
+++ b/Examples/test-suite/member_funcptr_galore.i
@@ -0,0 +1,83 @@
+%module member_pointer
+
+%inline %{
+
+namespace FunkSpace {
+struct Funktions {
+ int addByValue(const int &a, int b) { return a+b; }
+ int * addByPointer(const int &a, int b) { static int val; val = a+b; return &val; }
+ int & addByReference(const int &a, int b) { static int val; val = a+b; return val; }
+};
+}
+
+template struct Thing {};
+namespace Space {
+class Shape {
+public:
+ double x, y;
+ double *z;
+
+ void move(double dx, double dy);
+ virtual double area(Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int));
+ virtual double abc(Thing ts, Thing< const Space::Shape * > tda[]);
+};
+}
+
+extern double do_op(Space::Shape *s, double (Space::Shape::*m)(void));
+
+/* Functions that return member pointers */
+
+extern double (Space::Shape::*areapt())(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int));
+extern double (Space::Shape::*abcpt())(Thing, Thing< const Space::Shape * > tda[]);
+
+/* Global variables that are member pointers */
+extern double (Space::Shape::*areavar)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int));
+extern double (Space::Shape::*abcvar)(Thing, Thing< const Space::Shape * >[]);
+
+%}
+
+%{
+void Space::Shape::move(double dx, double dy) {
+ x += dx;
+ y += dy;
+}
+
+double do_op(Space::Shape *s, double (Space::Shape::*m)(void)) {
+ return (s->*m)();
+}
+
+double (Space::Shape::*areapt(Space::Shape &ref, int & (FunkSpace::Funktions::*d)(const int &, int)))(Space::Shape &, int & (FunkSpace::Funktions::*d)(const int &, int)) {
+ return &Space::Shape::area;
+}
+
+double (Space::Shape::*abcpt())(Thing, Thing< const Space::Shape * >[]) {
+ return &Space::Shape::abc;
+}
+
+/* Member pointer variables */
+double (Space::Shape::*areavar)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) = &Space::Shape::area;
+double (Space::Shape::*abcvar)(Thing, Thing< const Space::Shape * >[]) = &Space::Shape::abc;
+%}
+
+
+/* Some constants */
+%constant double (Space::Shape::*AREAPT)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int)) = &Space::Shape::area;
+%constant double (Space::Shape::*PERIMPT)(Thing, Thing< const Space::Shape * >[]) = &Space::Shape::abc;
+%constant double (Space::Shape::*NULLPT)(void) = 0;
+
+%inline %{
+
+int call1(int (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return (f.*d)(a, b); }
+int call2(int * (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return *(f.*d)(a, b); }
+int call3(int & (FunkSpace::Funktions::*d)(const int &, int), int a, int b) { FunkSpace::Funktions f; return (f.*d)(a, b); }
+%}
+
+%constant int (FunkSpace::Funktions::*ADD_BY_VALUE)(const int &, int) = &FunkSpace::Funktions::addByValue;
+%constant int * (FunkSpace::Funktions::*ADD_BY_POINTER)(const int &, int) = &FunkSpace::Funktions::addByPointer;
+%constant int & (FunkSpace::Funktions::*ADD_BY_REFERENCE)(const int &, int) = &FunkSpace::Funktions::addByReference;
+
+%inline %{
+// parameter that is a member pointer containing a function ptr, urgh :)
+int unreal1(double (Space::Shape::*memptr)(Space::Shape &, int & (FunkSpace::Funktions::*)(const int &, int))) { return 0; }
+int unreal2(double (Space::Shape::*memptr)(Thing)) { return 0; }
+%}
From c8c3e13065d244a53d1b901f501bcd1785e187f9 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Wed, 8 Dec 2010 19:35:52 +0000
Subject: [PATCH 041/317] function prototype in comment fix
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12337 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/DOH/string.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Source/DOH/string.c b/Source/DOH/string.c
index 05ae6e963..142b88c4d 100644
--- a/Source/DOH/string.c
+++ b/Source/DOH/string.c
@@ -1073,7 +1073,7 @@ DOHString *DohNewStringEmpty(void) {
}
/* -----------------------------------------------------------------------------
- * NewStringWithSize(const char *c, int len) - Create a new string
+ * NewStringWithSize(const DOH *so, int len) - Create a new string
* ----------------------------------------------------------------------------- */
DOHString *DohNewStringWithSize(const DOH *so, int len) {
From 64852460a0c70c0511bf5285980786a8500cdb7a Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Wed, 8 Dec 2010 19:56:14 +0000
Subject: [PATCH 042/317] Fix wallkw runtime test since D was added
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12338 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/test-suite/java/wallkw_runme.java | 2 +-
Examples/test-suite/wallkw.i | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/Examples/test-suite/java/wallkw_runme.java b/Examples/test-suite/java/wallkw_runme.java
index 028c2a32f..3b1007291 100644
--- a/Examples/test-suite/java/wallkw_runme.java
+++ b/Examples/test-suite/java/wallkw_runme.java
@@ -19,7 +19,7 @@ public class wallkw_runme {
throw new RuntimeException("delegate keyword fail");
if (!wallkw._pass().equals("pass"))
throw new RuntimeException("pass keyword fail");
- if (!wallkw.C_alias().equals("alias"))
+ if (!wallkw._alias().equals("alias"))
throw new RuntimeException("alias keyword fail");
}
}
diff --git a/Examples/test-suite/wallkw.i b/Examples/test-suite/wallkw.i
index 0ac383bcd..1a5866088 100644
--- a/Examples/test-suite/wallkw.i
+++ b/Examples/test-suite/wallkw.i
@@ -5,12 +5,14 @@
%warnfilter(SWIGWARN_PARSE_KEYWORD) clone; // 'clone' is a php keyword, renamed as 'c_clone'
%warnfilter(SWIGWARN_PARSE_KEYWORD) delegate; // 'delegate' is a C# keyword, renaming to '_delegate'
%warnfilter(SWIGWARN_PARSE_KEYWORD) pass; // 'pass' is a python keyword, renaming to '_pass'
-%warnfilter(SWIGWARN_PARSE_KEYWORD) alias; // 'alias' is a ruby keyword, renaming to 'C_alias'
+%warnfilter(SWIGWARN_PARSE_KEYWORD) alias; // 'alias' is a D keyword, renaming to '_alias'
+%warnfilter(SWIGWARN_PARSE_KEYWORD) rescue; // 'rescue' is a ruby keyword, renaming to 'C_rescue'
%inline %{
const char * clone() { return "clone"; }
const char * delegate() { return "delegate"; }
const char * pass() { return "pass"; }
const char * alias() { return "alias"; }
+const char * rescue() { return "rescue"; }
%}
From 93b030ec6a38301cb6a48278e52ef7e9d82bdc7c Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Wed, 8 Dec 2010 19:58:19 +0000
Subject: [PATCH 043/317] Fix wallkw runtime test since D was added
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12339 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/test-suite/java/wallkw_runme.java | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Examples/test-suite/java/wallkw_runme.java b/Examples/test-suite/java/wallkw_runme.java
index 3b1007291..7695cda24 100644
--- a/Examples/test-suite/java/wallkw_runme.java
+++ b/Examples/test-suite/java/wallkw_runme.java
@@ -21,5 +21,7 @@ public class wallkw_runme {
throw new RuntimeException("pass keyword fail");
if (!wallkw._alias().equals("alias"))
throw new RuntimeException("alias keyword fail");
+ if (!wallkw.C_rescue().equals("rescue"))
+ throw new RuntimeException("rescue keyword fail");
}
}
From 399ae62561459b913bb25a4aab03642ff52d8c4b Mon Sep 17 00:00:00 2001
From: Stefan Zager
Date: Wed, 8 Dec 2010 21:57:27 +0000
Subject: [PATCH 044/317] Basic director support (passes first few director
tests). Now fails on iadd_runme, because member variable support is missing.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12340 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/python/director.swg | 11 ++++++
Lib/python/pyrun.swg | 2 +
Source/Modules/python.cxx | 81 +++++++++++++++++++++++++--------------
3 files changed, 66 insertions(+), 28 deletions(-)
diff --git a/Lib/python/director.swg b/Lib/python/director.swg
index fcd174711..00ab9b03f 100644
--- a/Lib/python/director.swg
+++ b/Lib/python/director.swg
@@ -459,6 +459,17 @@ namespace Swig {
}
return own;
}
+
+ template
+ static PyObject* pyobj_disown (PyObject *pyobj, PyObject *SWIGUNUSEDPARM(args))
+ {
+ SwigPyObject *sobj = (SwigPyObject *) pyobj;
+ sobj->own = 0;
+ Director *d = SWIG_DIRECTOR_CAST(reinterpret_cast<_Tp*>(sobj->ptr));
+ if (d) d->swig_disown();
+ return SWIG_Py_Void();
+ }
+
};
#ifdef __THREAD__
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index 432d5dcf6..6221dbcc1 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -1376,6 +1376,8 @@ SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int f
SwigPyObject *newobj = (SwigPyObject*) self;
newobj->ptr = ptr;
newobj->own = own;
+ newobj->ty = type;
+ newobj->next = 0;
return 0;
}
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 6d6b060d3..618f15f9e 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -873,11 +873,6 @@ public:
/* the method exported for replacement of new.instancemethod in Python 3 */
add_pyinstancemethod_new();
- if (builtin) {
- Printf(f_init, "PyTypeObject *builtin_pytype = 0;\n");
- Printf(f_init, "swig_type_info *builtin_basetype = 0;\n");
- }
-
/* emit code */
Language::top(n);
@@ -1826,7 +1821,8 @@ public:
Wrapper_add_local(f, "argv", tmp);
if (!fastunpack) {
- bool add_self = builtin_self && !constructor;
+ bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass()));
+ bool add_self = builtin_self && (!constructor || director_class);
Wrapper_add_local(f, "ii", "int ii");
if (maxargs - (add_self ? 1 : 0) > 0)
Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
@@ -1943,6 +1939,7 @@ public:
}
bool builtin_self = builtin && in_class && (constructor || (l && Getattr(l, "self")));
bool builtin_ctor = builtin_self && constructor;
+ bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass()));
char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)";
char const *wrap_return = builtin_ctor ? "int " : "PyObject *";
@@ -1978,7 +1975,7 @@ public:
/* Get number of required and total arguments */
tuple_arguments = num_arguments = emit_num_arguments(l);
tuple_required = num_required = emit_num_required(l);
- if (builtin_self && !constructor) {
+ if (builtin_self && (!constructor || (constructor && director_class))) {
--tuple_arguments;
--tuple_required;
}
@@ -2051,9 +2048,13 @@ public:
if (builtin_self && !builtin_ctor)
Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0");
+ if (constructor && director_class)
+ Printv(self_parse, funpack ? "swig_obj[1]" : "obj1", " = self;\n", NIL);
+
int use_parse = 0;
Append(kwargs, "{");
for (i = 0, p = l; i < num_arguments; i++) {
+ bool parse_from_tuple = (i > 0 || !builtin_self || (builtin_ctor && !director_class));
while (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
}
@@ -2066,7 +2067,7 @@ public:
else
sprintf(source, "obj%d", builtin_ctor ? i + 1 : i);
- if (!builtin_self || builtin_ctor || i > 0) {
+ if (parse_from_tuple) {
Putc(',', arglist);
if (i == num_required)
Putc('|', parse_args); /* Optional argument separator */
@@ -2118,11 +2119,13 @@ public:
Setattr(p, "implicitconv", convflag);
}
- if (i > 0 || !builtin_self || builtin_ctor)
+ bool parse_from_tuple = (i > 0 || !builtin_self || (builtin_ctor && !director_class));
+
+ if (parse_from_tuple)
Putc('O', parse_args);
if (!funpack) {
Wrapper_add_localv(f, source, "PyObject *", source, "= 0", NIL);
- if (!builtin_self || builtin_ctor || i > 0)
+ if (parse_from_tuple)
Printf(arglist, "&%s", source);
}
if (i >= num_required)
@@ -2134,7 +2137,7 @@ public:
} else {
use_parse = 1;
Append(parse_args, parse);
- if (!builtin_self || builtin_ctor || i > 0)
+ if (parse_from_tuple)
Printf(arglist, "&%s", ln);
}
p = Getattr(p, "tmap:in:next");
@@ -2882,17 +2885,21 @@ public:
result = Language::classDirectorDisown(n);
shadow = oldshadow;
if (shadow) {
- String *symname = Getattr(n, "sym:name");
- String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name"));
- Printv(f_shadow, tab4, "def __disown__(self):\n", NIL);
+ if (builtin) {
+ Printf(f_shadow, tab4, "{ \"disown\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", real_classname);
+ } else {
+ String *symname = Getattr(n, "sym:name");
+ String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name"));
+ Printv(f_shadow, tab4, "def __disown__(self):\n", NIL);
#ifdef USE_THISOWN
- Printv(f_shadow, tab8, "self.thisown = 0\n", NIL);
+ Printv(f_shadow, tab8, "self.thisown = 0\n", NIL);
#else
- Printv(f_shadow, tab8, "self.this.disown()\n", NIL);
+ Printv(f_shadow, tab8, "self.this.disown()\n", NIL);
#endif
- Printv(f_shadow, tab8, module, ".", mrename, "(self)\n", NIL);
- Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL);
- Delete(mrename);
+ Printv(f_shadow, tab8, module, ".", mrename, "(self)\n", NIL);
+ Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL);
+ Delete(mrename);
+ }
}
return result;
}
@@ -2960,20 +2967,23 @@ public:
{
String *name = Getattr(n, "name");
String *rname = SwigType_namestr(name);
- Printf(f_init, " builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname);
- Printf(f_init, " builtin_pytype->tp_new = PyType_GenericNew;\n");
+ Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname);
+ Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n");
if (base_node) {
String *base_name = Copy(Getattr(base_node, "name"));
SwigType_add_pointer(base_name);
String *base_mname = SwigType_manglestr(base_name);
- Printf(f_init, " builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname);
- Printf(f_init, " if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n");
- Printf(f_init, " builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n");
- Printf(f_init, " }\n");
+ Printf(f_init, tab4 "builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname);
+ Printf(f_init, tab4 "if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n");
+ Printf(f_init, tab8 "builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n");
+ Printf(f_init, tab4 "}\n");
Delete(base_mname);
Delete(base_name);
+ } else {
+ //Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL);
+ Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL);
}
- Printf(f_init, " builtin_pytype->tp_dict = d = PyDict_New();\n");
+ Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n");
Delete(rname);
}
@@ -3019,7 +3029,7 @@ public:
Printf(f, " %s, /*tp_getattro*/\n", getSlot(n, "feature:tp_getattro"));
Printf(f, " %s, /*tp_setattro*/\n", getSlot(n, "feature:tp_setattro"));
Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer"));
- Printf(f, " Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags*/\n");
+ Printf(f, " Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags*/\n");
Printf(f, " \"%s\", /* tp_doc */\n", rname);
Printf(f, " %s, /* tp_traverse */\n", getSlot(n, "feature:tp_traverse"));
Printf(f, " %s, /* tp_clear */\n", getSlot(n, "feature:tp_clear"));
@@ -3200,6 +3210,21 @@ public:
/* Overide the shadow file so we can capture its methods */
f_shadow = NewString("");
+ // Set up type check for director class constructor
+ Clear(none_comparison);
+ if (builtin && Swig_directorclass(n)) {
+ String *p_real_classname = Copy(real_classname);
+ SwigType_add_pointer(p_real_classname);
+ String *mangle = SwigType_manglestr(p_real_classname);
+ String *descriptor = NewStringf("SWIGTYPE%s", mangle);
+ Printv(none_comparison, "self->ob_type != ((SwigPyClientData*) (", descriptor, ")->clientdata)->pytype", NIL);
+ Delete(descriptor);
+ Delete(mangle);
+ Delete(p_real_classname);
+ } else {
+ Printv(none_comparison, "$arg != Py_None", NIL);
+ }
+
Language::classHandler(n);
in_class = 0;
@@ -3551,7 +3576,7 @@ public:
if (!Getattr(n, "sym:nextSibling")) {
if (builtin && in_class) {
String *name = NewString("new");
- if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) {
+ if ((use_director || checkAttribute(n, "access", "public")) && !Getattr(class_members, name)) {
Setattr(class_members, name, name);
String *fullname = Swig_name_member(NULL, name, class_name);
if (!builtin_tp_init)
From 2ccdf35dd62fe639e35e81ab149aa98bdfba8d87 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 9 Dec 2010 07:39:19 +0000
Subject: [PATCH 045/317] more standard configure messages for checking Go
version
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12341 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
configure.in | 38 +++++++++++++++++++++-----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/configure.in b/configure.in
index 20558ec95..ff4fc0def 100644
--- a/configure.in
+++ b/configure.in
@@ -1995,29 +1995,33 @@ AC_ARG_WITH(go, AS_HELP_STRING([--without-go], [Disable Go])
AS_HELP_STRING([--with-go=path], [Set location of Go compiler]),[GOBIN="$withval"], [GOBIN=yes])
if test x"${GOBIN}" = xno -o x"${with_alllang}" = xno ; then
-AC_MSG_NOTICE([Disabling Go])
-GO=
-GOGCC=false
+ AC_MSG_NOTICE([Disabling Go])
+ GO=
+ GOGCC=false
else
- if test "x$GOBIN" = xyes; then
- AC_CHECK_PROGS(GO, 6g 8g gccgo)
- else
- GO="$GOBIN"
- fi
+ if test "x$GOBIN" = xyes; then
+ AC_CHECK_PROGS(GO, 6g 8g gccgo)
+ else
+ GO="$GOBIN"
+ fi
- if test -n "$GO" ; then
- GOGCC=false
- if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then
- GOGCC=true
+ if test -n "$GO" ; then
+ GOGCC=false
+ if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then
+ GOGCC=true
+ else
+ AC_MSG_CHECKING([whether Go ($GO) version is too old])
+ go_version=`$GO -V | sed -e 's/.*version \([[0-9]]*\).*/\1/'`
+ go_min_version=6707
+ if test "$go_version" -lt $go_min_version; then
+ AC_MSG_RESULT([yes - minimum version is $go_min_version])
+ GO=
else
- go_version=`$GO -V | sed -e 's/.*version \([[0-9]]*\).*/\1/'`
- if test "$go_version" -lt 6707; then
- AC_MSG_NOTICE([Installed Go too old; disabling Go])
- GO=
- fi
+ AC_MSG_RESULT([no])
fi
fi
+ fi
fi
AC_SUBST(GOGCC)
From 0148d7eb75b174a87d581998fa792fe4d0f01a80 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 9 Dec 2010 07:42:24 +0000
Subject: [PATCH 046/317] Specify minimum Go version for users who read the
CHANGES file
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12342 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/CHANGES.current b/CHANGES.current
index b8b1b51fa..e42223da0 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -6,9 +6,11 @@ Version 2.0.2 (in progress)
===========================
2010-12-07: iant
- *** POTENTIAL INCOMPATIBILITY ***
Check that we are using a sufficiently new version of the
- 6g or 8g Go compiler. If not, disable Go.
+ 6g or 8g Go compiler during configure time. If not, disable Go.
+ Minimum version is now 6707.
+
+ *** POTENTIAL INCOMPATIBILITY ***
2010-12-06: wsfulton
Fix #3127394 - use of network paths on Windows/MSys.
From 569470c4b9a5523327cd53e10785c53ba66bea29 Mon Sep 17 00:00:00 2001
From: Olly Betts
Date: Fri, 10 Dec 2010 05:52:45 +0000
Subject: [PATCH 047/317] Fix typo (extra ')') in Python docs (SF#3131673).
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12343 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Doc/Manual/Python.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html
index 23271e649..084ad3eab 100644
--- a/Doc/Manual/Python.html
+++ b/Doc/Manual/Python.html
@@ -4592,7 +4592,7 @@ static int convert_darray(PyObject *input, double *ptr, int size) {
%}
%typemap(in) double [ANY](double temp[$1_dim0]) {
- if (!convert_darray($input,temp,$1_dim0))) {
+ if (!convert_darray($input,temp,$1_dim0)) {
return NULL;
}
$1 = &temp[0];
From 18cede40d2f43ade62c1ef888a5476105dd6398f Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Sun, 12 Dec 2010 20:02:09 +0000
Subject: [PATCH 048/317] Only check if D compiler works if the compiler was
found
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12344 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
configure.in | 44 ++++++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/configure.in b/configure.in
index ff4fc0def..50f396226 100644
--- a/configure.in
+++ b/configure.in
@@ -2048,20 +2048,22 @@ else
if test -z "$D1COMPILERBIN" ; then
AC_CHECK_PROGS(D1COMPILER, dmd ldmd gdmd)
- AC_MSG_CHECKING(whether the D1/Tango compiler works)
- cat > conftest.$ac_ext <<_ACEOF
+ if test -n "$D1COMPILER" ; then
+ AC_MSG_CHECKING(whether the D1/Tango compiler works)
+ cat > conftest.$ac_ext <<_ACEOF
import tango.io.Stdout;
void main() {
}
_ACEOF
- rm -f conftest.$ac_objext
- AS_IF(
- [_AC_DO_STDERR($D1COMPILER conftest.$ac_ext) && test ! -s conftest.err && test -s conftest.$ac_objext],
- [AC_MSG_RESULT([yes])],
- [_AC_MSG_LOG_CONFTEST AC_MSG_RESULT([no])
- D1COMPILER=]
- )
- rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ rm -f conftest.$ac_objext
+ AS_IF(
+ [_AC_DO_STDERR($D1COMPILER conftest.$ac_ext) && test ! -s conftest.err && test -s conftest.$ac_objext],
+ [AC_MSG_RESULT([yes])],
+ [_AC_MSG_LOG_CONFTEST AC_MSG_RESULT([no])
+ D1COMPILER=]
+ )
+ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ fi
else
D1COMPILER="$D1COMPILERBIN"
fi
@@ -2069,20 +2071,22 @@ _ACEOF
if test -z "$D2COMPILERBIN" ; then
AC_CHECK_PROGS(D2COMPILER, dmd gdmd)
- AC_MSG_CHECKING(whether the D2 compiler works)
- cat > conftest.$ac_ext <<_ACEOF
+ if test -n "$D2COMPILER" ; then
+ AC_MSG_CHECKING(whether the D2 compiler works)
+ cat > conftest.$ac_ext <<_ACEOF
import std.algorithm;
void main() {
}
_ACEOF
- rm -f conftest.$ac_objext
- AS_IF(
- [_AC_DO_STDERR($D2COMPILER conftest.$ac_ext) && test ! -s conftest.err && test -s conftest.$ac_objext],
- [AC_MSG_RESULT([yes])],
- [_AC_MSG_LOG_CONFTEST AC_MSG_RESULT([no])
- D2COMPILER=]
- )
- rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ rm -f conftest.$ac_objext
+ AS_IF(
+ [_AC_DO_STDERR($D2COMPILER conftest.$ac_ext) && test ! -s conftest.err && test -s conftest.$ac_objext],
+ [AC_MSG_RESULT([yes])],
+ [_AC_MSG_LOG_CONFTEST AC_MSG_RESULT([no])
+ D2COMPILER=]
+ )
+ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ fi
else
D2COMPILER="$D2COMPILERBIN"
fi
From b1682d4d8010991d1735778fc2a873a198d3391b Mon Sep 17 00:00:00 2001
From: Stefan Zager
Date: Tue, 14 Dec 2010 00:08:45 +0000
Subject: [PATCH 049/317] Added support for operator overrides
(PyNumberMethods) and member variable access.
test suite now croaks on inplaceadd.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12345 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/python/builtin.swg | 40 +
Lib/python/pyopers.swg | 82 +-
Lib/python/pyrun.swg | 7 +-
Source/Modules/python.cxx | 3559 +++++++++++++++++++------------------
4 files changed, 1933 insertions(+), 1755 deletions(-)
diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg
index 556b113af..fde5339d5 100644
--- a/Lib/python/builtin.swg
+++ b/Lib/python/builtin.swg
@@ -1,3 +1,18 @@
+extern int
+pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure)
+{
+ if (!closure)
+ return -1;
+ PyObject *tuple = PyTuple_New(1);
+ assert(tuple);
+ PyTuple_SET_ITEM(tuple, 0, val);
+ Py_XINCREF(val);
+ PyObject *result = ((PyCFunction) closure)(obj, tuple);
+ Py_DECREF(tuple);
+ Py_XDECREF(result);
+ return result ? 0 : -1;
+}
+
#ifdef __cplusplus
namespace {
@@ -10,6 +25,8 @@ template struct PySwigBuiltin : public SwigPyObject {
typedef obj_type& reference;
static PyMethodDef methods[];
+ static PyGetSetDef getset[];
+ static PyNumberMethods number_methods;
static PyTypeObject pytype;
static SwigPyClientData clientdata;
};
@@ -23,6 +40,29 @@ template void py_builtin_dealloc (PyObject *pyobj)
(*pyobj->ob_type->tp_free)(pyobj);
}
+template PyObject*
+pyswig_binaryfunc_closure (PyObject *a, PyObject *b)
+{
+ PyObject *tuple = PyTuple_New(1);
+ assert(tuple);
+ PyTuple_SET_ITEM(tuple, 0, b);
+ PyObject *result = func(a, tuple);
+ Py_DECREF(tuple);
+ return result;
+}
+
+template PyObject*
+pyswig_ternaryfunc_closure (PyObject *a, PyObject *b, PyObject *c)
+{
+ PyObject *tuple = PyTuple_New(2);
+ assert(tuple);
+ PyTuple_SET_ITEM(tuple, 0, b);
+ PyTuple_SET_ITEM(tuple, 1, c);
+ PyObject *result = func(a, tuple);
+ Py_DECREF(tuple);
+ return result;
+}
+
} // namespace {
#endif
diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg
index 30775b84e..3074eaa9e 100644
--- a/Lib/python/pyopers.swg
+++ b/Lib/python/pyopers.swg
@@ -5,41 +5,53 @@
#ifdef __cplusplus
-#define %pybinoperator(pyname,oper) %rename(pyname) oper; %pythonmaybecall oper
-
-%pybinoperator(__add__, *::operator+);
-%pybinoperator(__pos__, *::operator+());
-%pybinoperator(__pos__, *::operator+() const);
-%pybinoperator(__sub__, *::operator-);
-%pybinoperator(__neg__, *::operator-());
-%pybinoperator(__neg__, *::operator-() const);
-%pybinoperator(__mul__, *::operator*);
-%pybinoperator(__div__, *::operator/);
-%pybinoperator(__mod__, *::operator%);
-%pybinoperator(__lshift__, *::operator<<);
-%pybinoperator(__rshift__, *::operator>>);
-%pybinoperator(__and__, *::operator&);
-%pybinoperator(__or__, *::operator|);
-%pybinoperator(__xor__, *::operator^);
-%pybinoperator(__lt__, *::operator<);
-%pybinoperator(__le__, *::operator<=);
-%pybinoperator(__gt__, *::operator>);
-%pybinoperator(__ge__, *::operator>=);
-%pybinoperator(__eq__, *::operator==);
-%pybinoperator(__ne__, *::operator!=);
+#if defined(SWIGPYTHON_BUILTIN)
+#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper; %feature("pyslot", #slot, functype=#functp) oper;
+#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("pycompare", #comptype) oper;
+#else
+#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper
+#define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype)
+#endif
+%pybinoperator(__add__, *::operator+, binary_func, nb_add);
+%pybinoperator(__pos__, *::operator+(), unary_func, nb_positive);
+%pybinoperator(__pos__, *::operator+() const, unary_func, nb_positive);
+%pybinoperator(__sub__, *::operator-, binary_func, nb_subtract);
+%pybinoperator(__neg__, *::operator-(), unary_func, nb_negative);
+%pybinoperator(__neg__, *::operator-() const, unary_func, nb_negative);
+%pybinoperator(__mul__, *::operator*, binary_func, nb_multiply);
+%pybinoperator(__div__, *::operator/, binary_func, nb_div);
+%pybinoperator(__mod__, *::operator%, binary_func, nb_remainder);
+%pybinoperator(__lshift__, *::operator<<, binary_func, nb_lshift);
+%pybinoperator(__rshift__, *::operator>>, binary_func, nb_rshift);
+%pybinoperator(__and__, *::operator&, binary_func, nb_and);
+%pybinoperator(__or__, *::operator|, binary_func, nb_or);
+%pybinoperator(__xor__, *::operator^, binary_func, nb_xor);
+%pycompare(__lt__, *::operator<, Py_LT);
+%pycompare(__le__, *::operator<=, Py_LE);
+%pycompare(__gt__, *::operator>, Py_GT);
+%pycompare(__ge__, *::operator>=, Py_GE);
+%pycompare(__eq__, *::operator==, Py_EQ);
+%pycompare(__ne__, *::operator!=, Py_NE);
+%feature("pyslot", "nb_truediv", functype="binary_func") *::operator/;
/* Special cases */
%rename(__invert__) *::operator~;
+%feature("pyslot", "nb_invert", functype="unary_func") *::operator~;
%rename(__call__) *::operator();
+%feature("pyslot", "tp_call", functype="ternary_func") *::operator();
+#if defined(SWIGPYTHON_BUILTIN)
+%pybinoperator(__nonzero__, *::operator bool, unary_func, nb_nonzero);
+#else
%feature("shadow") *::operator bool %{
def __nonzero__(self):
return $action(self)
__bool__ = __nonzero__
%};
%rename(__nonzero__) *::operator bool;
+#endif
/* Ignored operators */
%ignoreoperator(LNOT) operator!;
@@ -90,18 +102,22 @@ __bool__ = __nonzero__
*/
-#define %pyinplaceoper(SwigPyOper, Oper) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
+#if defined(SWIGPYTHON_BUILTIN)
+#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %rename(SwigPyOper) Oper; %feature("pyslot", #slot, functype=#functp) Oper;
+#else
+#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
+#endif
-%pyinplaceoper(__iadd__ , *::operator +=);
-%pyinplaceoper(__isub__ , *::operator -=);
-%pyinplaceoper(__imul__ , *::operator *=);
-%pyinplaceoper(__idiv__ , *::operator /=);
-%pyinplaceoper(__imod__ , *::operator %=);
-%pyinplaceoper(__iand__ , *::operator &=);
-%pyinplaceoper(__ior__ , *::operator |=);
-%pyinplaceoper(__ixor__ , *::operator ^=);
-%pyinplaceoper(__ilshift__, *::operator <<=);
-%pyinplaceoper(__irshift__, *::operator >>=);
+%pyinplaceoper(__iadd__ , *::operator +=, binary_func, nb_inplace_add);
+%pyinplaceoper(__isub__ , *::operator -=, binary_func, nb_inplace_subtract);
+%pyinplaceoper(__imul__ , *::operator *=, binary_func, nb_inplace_multiply);
+%pyinplaceoper(__idiv__ , *::operator /=, binary_func, nb_inplace_divide);
+%pyinplaceoper(__imod__ , *::operator %=, binary_func, nb_inplace_remainder);
+%pyinplaceoper(__iand__ , *::operator &=, binary_func, nb_inplace_and);
+%pyinplaceoper(__ior__ , *::operator |=, binary_func, nb_inplace_or);
+%pyinplaceoper(__ixor__ , *::operator ^=, binary_func, nb_inplace_xor);
+%pyinplaceoper(__ilshift__, *::operator <<=, binary_func, nb_inplace_lshift);
+%pyinplaceoper(__irshift__, *::operator >>=, binary_func, nb_inplace_rshift);
/* Finally, in python we need to mark the binary operations to fail as
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index 6221dbcc1..3f93c4575 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -1076,8 +1076,13 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
PyTypeObject *obj_tp;
for (obj_tp = obj->ob_type; obj_tp; obj_tp = obj_tp->tp_base) {
if (obj_tp == target_tp) {
+ SwigPyObject *sobj = (SwigPyObject*) obj;
+ if (own)
+ *own = *own | sobj->own;
+ if (flags & SWIG_POINTER_DISOWN)
+ sobj->own = 0;
if (ptr)
- *ptr = ((SwigPyObject*) obj)->ptr;
+ *ptr = sobj->ptr;
return SWIG_OK;
}
}
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 618f15f9e..55bfd8815 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -1,3 +1,4 @@
+/* mode: c++; c-basic-offset: 2 */
/* -----------------------------------------------------------------------------
* This file is part of SWIG, which is licensed as a whole under version 3
* (or any later version) of the GNU General Public License. Some additional
@@ -46,7 +47,7 @@ static String *f_shadow = 0;
static String *f_shadow_imports = 0;
static String *f_shadow_import_stmts = 0;
static String *f_shadow_stubs = 0;
-
+static Hash *builtin_getset = 0;
static String *methods;
static String *class_name;
@@ -166,15 +167,15 @@ static const char *usage3 = (char *) "\
static String*
getSlot (Node *n, const char *key)
{
- static String *slot_default = NewString("0");
- String *val = Getattr(n, key);
- return val ? val : slot_default;
+ static String *slot_default = NewString("0");
+ String *val = Getattr(n, key);
+ return val ? val : slot_default;
}
class PYTHON:public Language {
public:
- PYTHON() {
+ PYTHON() {
/* Add code to manage protected constructors and directors */
director_prot_ctor_code = NewString("");
Printv(director_prot_ctor_code,
@@ -448,20 +449,20 @@ public:
fputs(usage2, stdout);
fputs(usage3, stdout);
} else if (strcmp(argv[i], "-py3") == 0) {
- py3 = 1;
- Swig_mark_arg(i);
+ py3 = 1;
+ Swig_mark_arg(i);
} else if (strcmp(argv[i], "-builtin") == 0) {
- builtin = 1;
- Preprocessor_define("SWIGPYTHON_BUILTIN", 0);
- Swig_mark_arg(i);
+ builtin = 1;
+ Preprocessor_define("SWIGPYTHON_BUILTIN", 0);
+ Swig_mark_arg(i);
}
}
} /* for */
if (py3) {
- /* force disable features that not compatible with Python 3.x */
- classic = 0;
+ /* force disable features that not compatible with Python 3.x */
+ classic = 0;
}
if (cppcast) {
@@ -553,10 +554,11 @@ public:
f_wrappers = NewString("");
f_directors_h = NewString("");
f_directors = NewString("");
+ builtin_getset = NewHash();
if (builtin) {
- f_builtins = NewString("");
- Printf(f_builtins, "namespace {\n\n");
+ f_builtins = NewString("");
+ Printf(f_builtins, "namespace {\n\n");
}
if (directorsEnabled()) {
@@ -699,159 +701,159 @@ public:
/* If shadow classing is enabled, we're going to change the module name to "_module" */
if (shadow) {
- String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module));
- // If we don't have an interface then change the module name X to _X
- if (interface)
- module = interface;
- else
- Insert(module, 0, "_");
- if ((f_shadow_py = NewFile(filen, "w", SWIG_output_files())) == 0) {
- FileErrorDisplay(filen);
- SWIG_exit(EXIT_FAILURE);
- }
- Delete(filen);
- filen = NULL;
+ String *filen = NewStringf("%s%s.py", SWIG_output_directory(), Char(module));
+ // If we don't have an interface then change the module name X to _X
+ if (interface)
+ module = interface;
+ else
+ Insert(module, 0, "_");
+ if ((f_shadow_py = NewFile(filen, "w", SWIG_output_files())) == 0) {
+ FileErrorDisplay(filen);
+ SWIG_exit(EXIT_FAILURE);
+ }
+ Delete(filen);
+ filen = NULL;
- f_shadow = NewString("");
- f_shadow_imports = NewString("");
- f_shadow_import_stmts = NewString("");
- f_shadow_stubs = NewString("");
+ f_shadow = NewString("");
+ f_shadow_imports = NewString("");
+ f_shadow_import_stmts = NewString("");
+ f_shadow_stubs = NewString("");
- Printv(f_shadow_import_stmts, "SWIGINTERN void\n", NIL);
- Printv(f_shadow_import_stmts, "SWIG_Python_builtin_imports()\n", NIL);
- Printv(f_shadow_import_stmts, "{\n", NIL);
- Printv(f_shadow_import_stmts, tab4 "PyObject *import_str = NULL;\n", NIL);
+ Printv(f_shadow_import_stmts, "SWIGINTERN void\n", NIL);
+ Printv(f_shadow_import_stmts, "SWIG_Python_builtin_imports()\n", NIL);
+ Printv(f_shadow_import_stmts, "{\n", NIL);
+ Printv(f_shadow_import_stmts, tab4 "PyObject *import_str = NULL;\n", NIL);
- Swig_register_filebyname("shadow", f_shadow);
- Swig_register_filebyname("python", f_shadow);
+ Swig_register_filebyname("shadow", f_shadow);
+ Swig_register_filebyname("python", f_shadow);
- Swig_banner_target_lang(f_shadow, "#");
+ Swig_banner_target_lang(f_shadow, "#");
- if (!modern) {
- Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
- }
+ if (!modern) {
+ Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
+ }
- if (mod_docstring && Len(mod_docstring)) {
- Printv(f_shadow, "\"\"\"\n", mod_docstring, "\n\"\"\"\n\n", NIL);
- Delete(mod_docstring);
- mod_docstring = NULL;
- }
+ if (mod_docstring && Len(mod_docstring)) {
+ Printv(f_shadow, "\"\"\"\n", mod_docstring, "\n\"\"\"\n\n", NIL);
+ Delete(mod_docstring);
+ mod_docstring = NULL;
+ }
- Printv(f_shadow, "\nfrom sys import version_info\n", NULL);
+ Printv(f_shadow, "\nfrom sys import version_info\n", NULL);
- if (!builtin && fastproxy) {
- Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL);
- Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module);
- Printv(f_shadow, "else:\n", NULL);
- Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL);
- }
-
- /* Import the C-extension module. This should be a relative import,
- * since the shadow module may also have been imported by a relative
- * import, and there is thus no guarantee that the C-extension is on
- * sys.path. Relative imports must be explicitly specified from 2.6.0
- * onwards (implicit relative imports will raise a DeprecationWarning
- * in 2.6, and fail in 2.7 onwards), but the relative import syntax
- * isn't available in python 2.4 or earlier, so we have to write some
- * code conditional on the python version.
- */
- Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL);
- Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL);
- Printv(f_shadow, tab8, "from os.path import dirname\n", NULL);
- Printv(f_shadow, tab8, "import imp\n", NULL);
- Printv(f_shadow, tab8, "fp = None\n", NULL);
- Printv(f_shadow, tab8, "try:\n", NULL);
- Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module);
- Printf(f_shadow, tab8 "except ImportError:\n");
- /* At here, the module may already loaded, so simply import it. */
- Printf(f_shadow, tab4 tab8 "import %s\n", module);
- Printf(f_shadow, tab4 tab8 "return %s\n", module);
- Printv(f_shadow, tab8 "if fp is not None:\n", NULL);
- Printv(f_shadow, tab4 tab8 "try:\n", NULL);
- Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
- Printv(f_shadow, tab4 tab8, "finally:\n", NULL);
- Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL);
- Printv(f_shadow, tab4 tab8, "return _mod\n", NULL);
- Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
- Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
+ if (!builtin && fastproxy) {
+ Printv(f_shadow, "if version_info >= (3,0,0):\n", NULL);
+ Printf(f_shadow, tab4 "new_instancemethod = lambda func, inst, cls: %s.SWIG_PyInstanceMethod_New(func)\n", module);
Printv(f_shadow, "else:\n", NULL);
- Printf(f_shadow, tab4 "import %s\n", module);
+ Printv(f_shadow, tab4, "from new import instancemethod as new_instancemethod\n", NULL);
+ }
- /* Delete the version_info symbol since we don't use it elsewhere in the
- * module. */
- Printv(f_shadow, "del version_info\n", NULL);
+ /* Import the C-extension module. This should be a relative import,
+ * since the shadow module may also have been imported by a relative
+ * import, and there is thus no guarantee that the C-extension is on
+ * sys.path. Relative imports must be explicitly specified from 2.6.0
+ * onwards (implicit relative imports will raise a DeprecationWarning
+ * in 2.6, and fail in 2.7 onwards), but the relative import syntax
+ * isn't available in python 2.4 or earlier, so we have to write some
+ * code conditional on the python version.
+ */
+ Printv(f_shadow, "if version_info >= (2,6,0):\n", NULL);
+ Printv(f_shadow, tab4, "def swig_import_helper():\n", NULL);
+ Printv(f_shadow, tab8, "from os.path import dirname\n", NULL);
+ Printv(f_shadow, tab8, "import imp\n", NULL);
+ Printv(f_shadow, tab8, "fp = None\n", NULL);
+ Printv(f_shadow, tab8, "try:\n", NULL);
+ Printf(f_shadow, tab4 tab8 "fp, pathname, description = imp.find_module('%s', [dirname(__file__)])\n", module);
+ Printf(f_shadow, tab8 "except ImportError:\n");
+ /* At here, the module may already loaded, so simply import it. */
+ Printf(f_shadow, tab4 tab8 "import %s\n", module);
+ Printf(f_shadow, tab4 tab8 "return %s\n", module);
+ Printv(f_shadow, tab8 "if fp is not None:\n", NULL);
+ Printv(f_shadow, tab4 tab8 "try:\n", NULL);
+ Printf(f_shadow, tab8 tab8 "_mod = imp.load_module('%s', fp, pathname, description)\n", module);
+ Printv(f_shadow, tab4 tab8, "finally:\n", NULL);
+ Printv(f_shadow, tab8 tab8, "fp.close()\n", NULL);
+ Printv(f_shadow, tab4 tab8, "return _mod\n", NULL);
+ Printf(f_shadow, tab4 "%s = swig_import_helper()\n", module);
+ Printv(f_shadow, tab4, "del swig_import_helper\n", NULL);
+ Printv(f_shadow, "else:\n", NULL);
+ Printf(f_shadow, tab4 "import %s\n", module);
- if (builtin) {
- Printf(f_shadow, "from %s import *\n", module);
- }
- if (modern || !classic) {
- Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL);
- }
- /* if (!modern) */
- /* always needed, a class can be forced to be no-modern, such as an exception */
- {
- // Python-2.2 object hack
- Printv(f_shadow,
- "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n",
- tab4, "if (name == \"thisown\"): return self.this.own(value)\n",
- tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n",
+ /* Delete the version_info symbol since we don't use it elsewhere in the
+ * module. */
+ Printv(f_shadow, "del version_info\n", NULL);
+
+ if (builtin) {
+ Printf(f_shadow, "from %s import *\n", module);
+ }
+ if (modern || !classic) {
+ Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL);
+ }
+ /* if (!modern) */
+ /* always needed, a class can be forced to be no-modern, such as an exception */
+ {
+ // Python-2.2 object hack
+ Printv(f_shadow,
+ "def _swig_setattr_nondynamic(self,class_type,name,value,static=1):\n",
+ tab4, "if (name == \"thisown\"): return self.this.own(value)\n",
+ tab4, "if (name == \"this\"):\n", tab4, tab4, "if type(value).__name__ == 'SwigPyObject':\n", tab4, tab8, "self.__dict__[name] = value\n",
#ifdef USE_THISOWN
- tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n",
+ tab4, tab8, "if hasattr(value,\"thisown\"): self.__dict__[\"thisown\"] = value.thisown\n", tab4, tab8, "del value.thisown\n",
#endif
- tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n",
+ tab4, tab8, "return\n", tab4, "method = class_type.__swig_setmethods__.get(name,None)\n", tab4, "if method: return method(self,value)\n",
#ifdef USE_THISOWN
- tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n",
+ tab4, "if (not static) or hasattr(self,name) or (name == \"thisown\"):\n",
#else
- tab4, "if (not static) or hasattr(self,name):\n",
+ tab4, "if (not static) or hasattr(self,name):\n",
#endif
- tab4, tab4, "self.__dict__[name] = value\n",
- tab4, "else:\n",
- tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n",
- "def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL);
+ tab4, tab4, "self.__dict__[name] = value\n",
+ tab4, "else:\n",
+ tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n\n",
+ "def _swig_setattr(self,class_type,name,value):\n", tab4, "return _swig_setattr_nondynamic(self,class_type,name,value,0)\n\n", NIL);
- Printv(f_shadow,
- "def _swig_getattr(self,class_type,name):\n",
- tab4, "if (name == \"thisown\"): return self.this.own()\n",
- tab4, "method = class_type.__swig_getmethods__.get(name,None)\n",
- tab4, "if method: return method(self)\n", tab4, "raise AttributeError(name)\n\n", NIL);
+ Printv(f_shadow,
+ "def _swig_getattr(self,class_type,name):\n",
+ tab4, "if (name == \"thisown\"): return self.this.own()\n",
+ tab4, "method = class_type.__swig_getmethods__.get(name,None)\n",
+ tab4, "if method: return method(self)\n", tab4, "raise AttributeError(name)\n\n", NIL);
- Printv(f_shadow,
- "def _swig_repr(self):\n",
- tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n",
- tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL);
+ Printv(f_shadow,
+ "def _swig_repr(self):\n",
+ tab4, "try: strthis = \"proxy of \" + self.this.__repr__()\n",
+ tab4, "except: strthis = \"\"\n", tab4, "return \"<%s.%s; %s >\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", NIL);
- if (!classic) {
- /* Usage of types.ObjectType is deprecated.
- * But don't sure wether this would broken old Python?
- */
- Printv(f_shadow,
- // "import types\n",
- "try:\n",
- // " _object = types.ObjectType\n",
- " _object = object\n",
- " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
- // "del types\n",
- "\n\n", NIL);
- }
+ if (!classic) {
+ /* Usage of types.ObjectType is deprecated.
+ * But don't sure wether this would broken old Python?
+ */
+ Printv(f_shadow,
+ // "import types\n",
+ "try:\n",
+ // " _object = types.ObjectType\n",
+ " _object = object\n",
+ " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
+ // "del types\n",
+ "\n\n", NIL);
}
- if (modern) {
- Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n",
+ }
+ if (modern) {
+ Printv(f_shadow, "def _swig_setattr_nondynamic_method(set):\n", tab4, "def set_attr(self,name,value):\n",
#ifdef USE_THISOWN
- tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n",
+ tab4, tab4, "if hasattr(self,name) or (name in (\"this\", \"thisown\")):\n",
#else
- tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n",
+ tab4, tab4, "if (name == \"thisown\"): return self.this.own(value)\n", tab4, tab4, "if hasattr(self,name) or (name == \"this\"):\n",
#endif
- tab4, tab4, tab4, "set(self,name,value)\n",
- tab4, tab4, "else:\n",
- tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL);
- }
+ tab4, tab4, tab4, "set(self,name,value)\n",
+ tab4, tab4, "else:\n",
+ tab4, tab4, tab4, "raise AttributeError(\"You cannot add attributes to %s\" % self)\n", tab4, "return set_attr\n\n\n", NIL);
+ }
- if (directorsEnabled()) {
- // Try loading weakref.proxy, which is only available in Python 2.1 and higher
- Printv(f_shadow,
- "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL);
- }
- }
+ if (directorsEnabled()) {
+ // Try loading weakref.proxy, which is only available in Python 2.1 and higher
+ Printv(f_shadow,
+ "try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL);
+ }
+ }
// Include some information in the code
Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\
@@ -899,22 +901,22 @@ public:
Printf(f_init, "#endif\n");
Printf(f_init, "}\n");
if (builtin)
- Printf(f_builtins, "} // namespace {\n\n");
+ Printf(f_builtins, "} // namespace {\n\n");
Printf(f_wrappers, "#ifdef __cplusplus\n");
Printf(f_wrappers, "}\n");
Printf(f_wrappers, "#endif\n");
if (shadow) {
- if (builtin) {
- Printv(f_shadow_import_stmts, "}\n", NIL);
- Printv(f_header, f_shadow_import_stmts, NIL);
- }
- Printv(f_shadow_py, f_shadow, "\n", NIL);
- Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
+ if (builtin) {
+ Printv(f_shadow_import_stmts, "}\n", NIL);
+ Printv(f_header, f_shadow_import_stmts, NIL);
+ }
+ Printv(f_shadow_py, f_shadow, "\n", NIL);
+ Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
- Close(f_shadow_py);
- Delete(f_shadow_py);
+ Close(f_shadow_py);
+ Delete(f_shadow_py);
}
/* Close all of the files */
@@ -932,7 +934,7 @@ public:
Dump(f_wrappers, f_begin);
if (builtin)
- Dump(f_builtins, f_begin);
+ Dump(f_builtins, f_begin);
Wrapper_pretty_print(f_init, f_begin);
Delete(f_header);
@@ -992,24 +994,24 @@ public:
if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) {
Printf(import, "_%s\n", modname);
if (!Strstr(f_shadow_imports, import)) {
- if (pkg && (!package || Strcmp(pkg, package) != 0)) {
- if (builtin) {
- Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s.%s\");\n", pkg, modname);
- Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n");
- Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n");
- } else {
- Printf(f_shadow, "import %s.%s\n", pkg, modname);
- }
+ if (pkg && (!package || Strcmp(pkg, package) != 0)) {
+ if (builtin) {
+ Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s.%s\");\n", pkg, modname);
+ Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n");
+ Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n");
} else {
- if (builtin) {
- Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s\");\n", modname);
- Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n");
- Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n");
- } else {
- Printf(f_shadow, "import %s\n", modname);
- }
+ Printf(f_shadow, "import %s.%s\n", pkg, modname);
}
- Printv(f_shadow_imports, import, NULL);
+ } else {
+ if (builtin) {
+ Printf(f_shadow_import_stmts, tab4 "import_str = PyString_FromString(\"%s\");\n", modname);
+ Printf(f_shadow_import_stmts, tab4 "PyImport_Import(import_str);\n");
+ Printf(f_shadow_import_stmts, tab4 "Py_XDECREF(import_str);\n");
+ } else {
+ Printf(f_shadow, "import %s\n", modname);
+ }
+ }
+ Printv(f_shadow_imports, import, NULL);
}
}
}
@@ -1026,12 +1028,12 @@ public:
* module. Using proper argument and calling style for
* given node n.
* ------------------------------------------------------------ */
- String *funcCall(String *name, String *parms) {
+ String *funcCall(String *name, String *parms) {
String *str = NewString("");
Printv(str, module, ".", name, "(", parms, ")", NIL);
return str;
- }
+ }
/* ------------------------------------------------------------
@@ -1200,7 +1202,7 @@ public:
return doc;
}
- /* -----------------------------------------------------------------------------
+ /* -----------------------------------------------------------------------------
* makeParameterName()
* Note: the generated name should consist with that in kwnames[]
*
@@ -1585,26 +1587,26 @@ public:
if (is_real_overloaded(n) ||
GetFlag(n, "feature:compactdefaultargs") ||
!is_primitive_defaultargs(n))
- {
- String *parms = NewString("");
- if(in_class)
- Printf(parms, "self, ");
- Printf(parms, "*args");
- if (kw)
- Printf(parms, ", **kwargs");
- return parms;
- }
+ {
+ String *parms = NewString("");
+ if(in_class)
+ Printf(parms, "self, ");
+ Printf(parms, "*args");
+ if (kw)
+ Printf(parms, ", **kwargs");
+ return parms;
+ }
bool funcanno = py3 ? true : false;
String *params = NewString("");
String *_params = make_autodocParmList(n, false, is_calling, funcanno);
if (in_class)
- {
- Printf(params, "self");
- if(Len(_params) > 0)
- Printf(params, ", ");
- }
+ {
+ Printf(params, "self");
+ if(Len(_params) > 0)
+ Printf(params, ", ");
+ }
Printv(params, _params, NULL);
@@ -1707,7 +1709,7 @@ public:
if (ret) ret = SwigType_str(ret, 0);
}
return (ret && py3) ? NewStringf(" -> \"%s\" ", ret)
- : NewString("");
+ : NewString("");
}
/* ------------------------------------------------------------
@@ -1731,7 +1733,7 @@ public:
Printv(f_dest, pythoncode(pythonappend(n), " "), "\n", NIL);
Printv(f_dest, " return val\n", NIL);
} else {
- Printv(f_dest, " return ", funcCall(name, callParms), "\n", NIL);
+ Printv(f_dest, " return ", funcCall(name, callParms), "\n", NIL);
}
if (Getattr(n, "feature:python:callback") || !have_addtofunc(n)) {
@@ -1748,7 +1750,7 @@ public:
int check_kwargs(Node *n) {
return (use_kw || GetFlag(n, "feature:kwargs"))
- && !GetFlag(n, "memberset") && !GetFlag(n, "memberget");
+ && !GetFlag(n, "memberset") && !GetFlag(n, "memberget");
}
@@ -1759,9 +1761,9 @@ public:
void add_method(String *name, String *function, int kw, Node *n = 0, int = 0, int = -1, int = -1) {
if (!kw) {
- Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function);
+ Printf(methods, "\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function);
} else {
- Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function);
+ Printf(methods, "\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function);
}
if (!n) {
@@ -1792,7 +1794,7 @@ public:
/* ------------------------------------------------------------
* dispatchFunction()
* ------------------------------------------------------------ */
- void dispatchFunction(Node *n, int funpack = 0, bool builtin_self = false, bool constructor = false) {
+ void dispatchFunction(Node *n, String *linkage, int funpack = 0, bool builtin_self = false, bool constructor = false) {
/* Last node in overloaded chain */
int maxargs;
@@ -1814,30 +1816,30 @@ public:
String *symname = Getattr(n, "sym:name");
String *wname = Swig_name_wrapper(symname);
- Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL);
+ Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL);
Wrapper_add_local(f, "argc", "int argc");
Printf(tmp, "PyObject *argv[%d]", maxargs + 1);
Wrapper_add_local(f, "argv", tmp);
if (!fastunpack) {
- bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass()));
- bool add_self = builtin_self && (!constructor || director_class);
- Wrapper_add_local(f, "ii", "int ii");
- if (maxargs - (add_self ? 1 : 0) > 0)
- Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
- Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n");
- if (add_self)
- Append(f->code, "argv[0] = self;\n");
- Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs-1 : maxargs);
- Printf(f->code, "argv[ii%s] = PyTuple_GET_ITEM(args,ii);\n", add_self ? " + 1" : "");
- Append(f->code, "}\n");
- if (add_self)
- Append(f->code, "argc++;\n");
+ bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass()));
+ bool add_self = builtin_self && (!constructor || director_class);
+ Wrapper_add_local(f, "ii", "int ii");
+ if (maxargs - (add_self ? 1 : 0) > 0)
+ Append(f->code, "if (!PyTuple_Check(args)) SWIG_fail;\n");
+ Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n");
+ if (add_self)
+ Append(f->code, "argv[0] = self;\n");
+ Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs-1 : maxargs);
+ Printf(f->code, "argv[ii%s] = PyTuple_GET_ITEM(args,ii);\n", add_self ? " + 1" : "");
+ Append(f->code, "}\n");
+ if (add_self)
+ Append(f->code, "argc++;\n");
} else {
- String *iname = Getattr(n, "sym:name");
- Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs);
- Append(f->code, "--argc;\n");
+ String *iname = Getattr(n, "sym:name");
+ Printf(f->code, "if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs);
+ Append(f->code, "--argc;\n");
}
Replaceall(dispatch, "$args", "self,args");
@@ -1866,7 +1868,7 @@ public:
Wrapper_print(f, f_wrappers);
Node *p = Getattr(n, "sym:previousSibling");
if (!builtin_self)
- add_method(symname, wname, 0, p);
+ add_method(symname, wname, 0, p);
/* Create a shadow for this function (if enabled and not in a member function) */
if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
@@ -1940,8 +1942,23 @@ public:
bool builtin_self = builtin && in_class && (constructor || (l && Getattr(l, "self")));
bool builtin_ctor = builtin_self && constructor;
bool director_class = (getCurrentClass() && Swig_directorclass(getCurrentClass()));
+ bool builtin_getter = (builtin && GetFlag(n, "memberget"));
+ bool builtin_setter = (builtin && GetFlag(n, "memberset") && !builtin_getter);
char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)";
char const *wrap_return = builtin_ctor ? "int " : "PyObject *";
+ String *linkage = NewString("SWIGINTERN ");
+ String *slot = Getattr(n, "feature:pyslot");
+ if (builtin_setter || builtin_getter) {
+ Clear(linkage);
+ Printv(linkage, "extern ", NIL);
+ }
+ if (slot) {
+ String *functype = Getattr(n, "feature:pyslot:functype");
+ if (!strcmp(Char(functype), "binary_func") || !strcmp(Char(functype), "ternary_func")) {
+ Clear(linkage);
+ Printv(linkage, "extern ", NIL);
+ }
+ }
if (Getattr(n, "sym:overloaded")) {
overname = Getattr(n, "sym:overname");
@@ -1962,9 +1979,9 @@ public:
int allow_thread = threads_enable(n);
if (builtin_ctor)
- Wrapper_add_local(f, "resultobj", "int resultobj = 0");
+ Wrapper_add_local(f, "resultobj", "int resultobj = 0");
else
- Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0");
+ Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0");
// Emit all of the local variables for holding arguments.
emit_parameter_variables(l, f);
@@ -1976,8 +1993,8 @@ public:
tuple_arguments = num_arguments = emit_num_arguments(l);
tuple_required = num_required = emit_num_required(l);
if (builtin_self && (!constructor || (constructor && director_class))) {
- --tuple_arguments;
- --tuple_required;
+ --tuple_arguments;
+ --tuple_required;
}
if (((num_arguments == 0) && (num_required == 0)) || ((num_arguments == 1) && (num_required == 1) && Getattr(l, "self")))
allow_kwargs = 0;
@@ -1990,9 +2007,9 @@ public:
if (!allow_kwargs || Getattr(n, "sym:overloaded")) {
if (!varargs) {
- Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
+ Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
} else {
- Printv(f->def, "SWIGINTERN ", wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL);
+ Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL);
}
if (allow_kwargs) {
Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions (%s).\n", Swig_name_decl(n));
@@ -2003,15 +2020,15 @@ public:
Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, "Can't wrap varargs with keyword arguments enabled\n");
varargs = 0;
}
- Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL);
+ Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL);
}
if (!builtin || !in_class || tuple_arguments > 0) {
- if (!allow_kwargs) {
- Append(parse_args, " if (!PyArg_ParseTuple(args,(char *)\"");
- } else {
- Append(parse_args, " if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\"");
- Append(arglist, ",kwnames");
- }
+ if (!allow_kwargs) {
+ Append(parse_args, " if (!PyArg_ParseTuple(args,(char *)\"");
+ } else {
+ Append(parse_args, " if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\"");
+ Append(arglist, ",kwnames");
+ }
}
int funpack = modernargs && fastunpack && !varargs && !allow_kwargs;
@@ -2046,10 +2063,10 @@ public:
}
if (builtin_self && !builtin_ctor)
- Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0");
+ Printf(self_parse, "%s = self;\n", funpack ? "swig_obj[0]" : "obj0");
- if (constructor && director_class)
- Printv(self_parse, funpack ? "swig_obj[1]" : "obj1", " = self;\n", NIL);
+ if (builtin_ctor && director_class)
+ Printv(self_parse, funpack ? "swig_obj[1]" : "obj1", " = self;\n", NIL);
int use_parse = 0;
Append(kwargs, "{");
@@ -2063,14 +2080,14 @@ public:
String *pn = Getattr(p, "name");
String *ln = Getattr(p, "lname");
if (funpack)
- sprintf(source, "swig_obj[%d]", builtin_ctor ? i + 1 : i);
+ sprintf(source, "swig_obj[%d]", builtin_ctor ? i + 1 : i);
else
sprintf(source, "obj%d", builtin_ctor ? i + 1 : i);
if (parse_from_tuple) {
- Putc(',', arglist);
- if (i == num_required)
- Putc('|', parse_args); /* Optional argument separator */
+ Putc(',', arglist);
+ if (i == num_required)
+ Putc('|', parse_args); /* Optional argument separator */
}
/* Keyword argument handling */
@@ -2122,11 +2139,11 @@ public:
bool parse_from_tuple = (i > 0 || !builtin_self || (builtin_ctor && !director_class));
if (parse_from_tuple)
- Putc('O', parse_args);
+ Putc('O', parse_args);
if (!funpack) {
Wrapper_add_localv(f, source, "PyObject *", source, "= 0", NIL);
if (parse_from_tuple)
- Printf(arglist, "&%s", source);
+ Printf(arglist, "&%s", source);
}
if (i >= num_required)
Printv(get_pointers, "if (", source, ") {\n", NIL);
@@ -2138,7 +2155,7 @@ public:
use_parse = 1;
Append(parse_args, parse);
if (parse_from_tuple)
- Printf(arglist, "&%s", ln);
+ Printf(arglist, "&%s", ln);
}
p = Getattr(p, "tmap:in:next");
continue;
@@ -2164,16 +2181,16 @@ public:
Clear(f->def);
if (overname) {
if (noargs) {
- Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
+ Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
} else {
- Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL);
+ Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", int nobjs, PyObject **swig_obj) {", NIL);
}
Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments);
} else {
if (noargs) {
- Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
+ Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
} else {
- Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
+ Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args) {", NIL);
}
if (onearg) {
Printf(parse_args, "if (!args) SWIG_fail;\n");
@@ -2318,10 +2335,10 @@ public:
/* Return the function value */
if (builtin_ctor) {
- Printf(f->code, "%s\n", actioncode);
- tm = Swig_typemap_lookup("builtin_init", n, "result", f);
+ Printf(f->code, "%s\n", actioncode);
+ tm = Swig_typemap_lookup("builtin_init", n, "result", f);
} else {
- tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode);
+ tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode);
}
if (tm) {
@@ -2426,10 +2443,10 @@ public:
if (need_cleanup) {
Printv(f->code, cleanup, NIL);
}
- if (builtin_self && constructor)
- Printv(f->code, " return 0;\n", NIL);
+ if (builtin_ctor)
+ Printv(f->code, " return 0;\n", NIL);
else
- Printv(f->code, " return NULL;\n", NIL);
+ Printv(f->code, " return NULL;\n", NIL);
if (funpack) {
@@ -2463,7 +2480,7 @@ public:
if (varargs) {
DelWrapper(f);
f = NewWrapper();
- Printv(f->def, "SWIGINTERN ", wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL);
+ Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args) {", NIL);
Wrapper_add_local(f, "resultobj", constructor && builtin_self ? "int resultobj" : "PyObject *resultobj");
Wrapper_add_local(f, "varargs", "PyObject *varargs");
Wrapper_add_local(f, "newargs", "PyObject *newargs");
@@ -2480,8 +2497,8 @@ public:
/* Now register the function with the interpreter. */
if (!Getattr(n, "sym:overloaded")) {
- if (!builtin_self)
- add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments);
+ if (!builtin_self)
+ add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments);
/* Create a shadow for this function (if enabled and not in a member function) */
if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
@@ -2489,11 +2506,53 @@ public:
}
} else {
if (!Getattr(n, "sym:nextSibling")) {
- dispatchFunction(n, funpack, builtin_self, constructor);
+ dispatchFunction(n, linkage, funpack, builtin_self, constructor);
}
}
+
+ String *wrapper_name = Swig_name_wrapper(iname);
+
+ /* If this is a builtin type, create a PyGetSetDef entry for this member variable. */
+ if (builtin_getter) {
+ Hash *h = Getattr(builtin_getset, name);
+ if (!h) {
+ h = NewHash();
+ Setattr(builtin_getset, name, h);
+ Delete(h);
+ }
+ Setattr(h, "getter", wrapper_name);
+ }
+ if (builtin_setter) {
+ Hash *h = Getattr(builtin_getset, name);
+ if (!h) {
+ h = NewHash();
+ Setattr(builtin_getset, name, h);
+ Delete(h);
+ }
+ Setattr(h, "setter", wrapper_name);
+ }
+
+ /* Handle builtin operator overloads */
+ if (slot) {
+ String *functype = Getattr(n, "feature:pyslot:functype");
+ String *feature_name = NewStringf("feature:%s", slot);
+ String *closure_name = NewString("");
+ if (!strcmp(Char(functype), "binary_func")) {
+ Printf(closure_name, "pyswig_binaryfunc_closure< %s >", wrapper_name);
+ } else if (!strcmp(Char(functype), "ternary_func")) {
+ Printf(closure_name, "pyswig_ternaryfunc_closure< %s >", wrapper_name);
+ } else {
+ Append(closure_name, wrapper_name);
+ }
+ Node *parent = Swig_methodclass(n);
+ Setattr(parent, feature_name, closure_name);
+ Delete(feature_name);
+ Delete(closure_name);
+ }
+
Delete(self_parse);
Delete(parse_args);
+ Delete(linkage);
Delete(arglist);
Delete(get_pointers);
Delete(cleanup);
@@ -2501,6 +2560,7 @@ public:
Delete(kwargs);
Delete(wname);
DelWrapper(f);
+ Delete(wrapper_name);
return SWIG_OK;
}
@@ -2538,7 +2598,7 @@ public:
int assignable = is_assignable(n);
if (!builtin && (shadow) && !assignable && !in_class)
- Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname);
+ Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname);
String *getname = Swig_name_get(NSPACE_TODO, iname);
String *setname = Swig_name_set(NSPACE_TODO, iname);
@@ -2616,70 +2676,70 @@ public:
* constantWrapper()
* ------------------------------------------------------------ */
- virtual int constantWrapper(Node *n) {
- String *name = Getattr(n, "name");
- String *iname = Getattr(n, "sym:name");
- SwigType *type = Getattr(n, "type");
- String *rawval = Getattr(n, "rawval");
- String *value = rawval ? rawval : Getattr(n, "value");
- String *tm;
- int have_tm = 0;
+ virtual int constantWrapper(Node *n) {
+ String *name = Getattr(n, "name");
+ String *iname = Getattr(n, "sym:name");
+ SwigType *type = Getattr(n, "type");
+ String *rawval = Getattr(n, "rawval");
+ String *value = rawval ? rawval : Getattr(n, "value");
+ String *tm;
+ int have_tm = 0;
- if (!addSymbol(iname, n))
- return SWIG_ERROR;
+ if (!addSymbol(iname, n))
+ return SWIG_ERROR;
- /* Special hook for member pointer */
- if (SwigType_type(type) == T_MPOINTER) {
- String *wname = Swig_name_wrapper(iname);
- String *str = SwigType_str(type, wname);
- Printf(f_header, "static %s = %s;\n", str, value);
- Delete(str);
- value = wname;
- }
-
- if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
- Replaceall(tm, "$source", value);
- Replaceall(tm, "$target", name);
- Replaceall(tm, "$value", value);
- Printf(const_code, "%s,\n", tm);
- Delete(tm);
- have_tm = 1;
- }
-
- if (builtin && in_class) {
- Swig_require("builtin_constantWrapper", n, "*sym:name", "builtin_sym:name", NIL);
- Setattr(n, "sym:name", Getattr(n, "builtin_sym:name"));
- }
-
- if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
- Replaceall(tm, "$source", value);
- Replaceall(tm, "$target", name);
- Replaceall(tm, "$value", value);
- Printf(f_init, "%s\n", tm);
- Delete(tm);
- have_tm = 1;
- }
-
- if (builtin && in_class)
- Swig_restore(n);
-
- if (!have_tm) {
- Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n");
- return SWIG_NOWRAP;
- }
-
- if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
- if (!in_class) {
- Printv(f_shadow, iname, " = ", module, ".", iname, "\n", NIL);
- } else {
- if (!(Getattr(n, "feature:python:callback"))) {
- Printv(f_shadow_stubs, iname, " = ", module, ".", iname, "\n", NIL);
- }
- }
- }
- return SWIG_OK;
+ /* Special hook for member pointer */
+ if (SwigType_type(type) == T_MPOINTER) {
+ String *wname = Swig_name_wrapper(iname);
+ String *str = SwigType_str(type, wname);
+ Printf(f_header, "static %s = %s;\n", str, value);
+ Delete(str);
+ value = wname;
}
+ if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
+ Replaceall(tm, "$source", value);
+ Replaceall(tm, "$target", name);
+ Replaceall(tm, "$value", value);
+ Printf(const_code, "%s,\n", tm);
+ Delete(tm);
+ have_tm = 1;
+ }
+
+ if (builtin && in_class) {
+ Swig_require("builtin_constantWrapper", n, "*sym:name", "builtin_sym:name", NIL);
+ Setattr(n, "sym:name", Getattr(n, "builtin_sym:name"));
+ }
+
+ if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
+ Replaceall(tm, "$source", value);
+ Replaceall(tm, "$target", name);
+ Replaceall(tm, "$value", value);
+ Printf(f_init, "%s\n", tm);
+ Delete(tm);
+ have_tm = 1;
+ }
+
+ if (builtin && in_class)
+ Swig_restore(n);
+
+ if (!have_tm) {
+ Swig_warning(WARN_TYPEMAP_CONST_UNDEF, input_file, line_number, "Unsupported constant value.\n");
+ return SWIG_NOWRAP;
+ }
+
+ if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
+ if (!in_class) {
+ Printv(f_shadow, iname, " = ", module, ".", iname, "\n", NIL);
+ } else {
+ if (!(Getattr(n, "feature:python:callback"))) {
+ Printv(f_shadow_stubs, iname, " = ", module, ".", iname, "\n", NIL);
+ }
+ }
+ }
+ return SWIG_OK;
+ }
+
/* ------------------------------------------------------------
* nativeWrapper()
@@ -2701,17 +2761,17 @@ public:
-/* ----------------------------------------------------------------------------
- * BEGIN C++ Director Class modifications
- * ------------------------------------------------------------------------- */
+ /* ----------------------------------------------------------------------------
+ * BEGIN C++ Director Class modifications
+ * ------------------------------------------------------------------------- */
-/* C++/Python polymorphism demo code, copyright (C) 2002 Mark Rose
- *
- * TODO
- *
- * Move some boilerplate code generation to Swig_...() functions.
- *
- */
+ /* C++/Python polymorphism demo code, copyright (C) 2002 Mark Rose
+ *
+ * TODO
+ *
+ * Move some boilerplate code generation to Swig_...() functions.
+ *
+ */
/* ---------------------------------------------------------------
* classDirectorMethod()
@@ -2823,13 +2883,13 @@ public:
if (dirprot_mode()) {
/*
- This implementation uses a std::map.
+ This implementation uses a std::map.
- It should be possible to rewrite it using a more elegant way,
- like copying the Java approach for the 'override' array.
+ It should be possible to rewrite it using a more elegant way,
+ like copying the Java approach for the 'override' array.
- But for now, this seems to be the least intrusive way.
- */
+ But for now, this seems to be the least intrusive way.
+ */
Printf(f_directors_h, "\n\n");
Printf(f_directors_h, "/* Internal Director utilities */\n");
Printf(f_directors_h, "public:\n");
@@ -2885,480 +2945,538 @@ public:
result = Language::classDirectorDisown(n);
shadow = oldshadow;
if (shadow) {
- if (builtin) {
- Printf(f_shadow, tab4, "{ \"disown\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", real_classname);
- } else {
- String *symname = Getattr(n, "sym:name");
- String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name"));
- Printv(f_shadow, tab4, "def __disown__(self):\n", NIL);
+ if (builtin) {
+ Printf(f_shadow, tab4, "{ \"disown\", (PyCFunction) Swig::Director::pyobj_disown< %s >, METH_NOARGS, \"\" },\n", real_classname);
+ } else {
+ String *symname = Getattr(n, "sym:name");
+ String *mrename = Swig_name_disown(NSPACE_TODO, symname); //Getattr(n, "name"));
+ Printv(f_shadow, tab4, "def __disown__(self):\n", NIL);
#ifdef USE_THISOWN
- Printv(f_shadow, tab8, "self.thisown = 0\n", NIL);
+ Printv(f_shadow, tab8, "self.thisown = 0\n", NIL);
#else
- Printv(f_shadow, tab8, "self.this.disown()\n", NIL);
+ Printv(f_shadow, tab8, "self.this.disown()\n", NIL);
#endif
- Printv(f_shadow, tab8, module, ".", mrename, "(self)\n", NIL);
- Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL);
- Delete(mrename);
- }
+ Printv(f_shadow, tab8, module, ".", mrename, "(self)\n", NIL);
+ Printv(f_shadow, tab8, "return weakref_proxy(self)\n", NIL);
+ Delete(mrename);
+ }
}
return result;
}
-/* ----------------------------------------------------------------------------
- * END of C++ Director Class modifications
- * ------------------------------------------------------------------------- */
+ /* ----------------------------------------------------------------------------
+ * END of C++ Director Class modifications
+ * ------------------------------------------------------------------------- */
/* ------------------------------------------------------------
* classDeclaration()
* ------------------------------------------------------------ */
- virtual bool get_single_base (Node *n, Node **base = NULL)
- {
+ virtual bool get_single_base (Node *n, Node **base = NULL)
+ {
+ if (base)
+ *base = NULL;
+ if (Getattr(n, "single_inh"))
+ return true;
+ List *baselist = Getattr(n, "bases");
+ if (!baselist || Len(baselist) == 0) {
+ Setattr(n, "single_inh", "1");
+ return true;
+ }
+ if (baselist && Len(baselist) == 1) {
+ Iterator b = First(baselist);
+ if (this->get_single_base(b.item)) {
if (base)
- *base = NULL;
- if (Getattr(n, "single_inh"))
- return true;
- List *baselist = Getattr(n, "bases");
- if (!baselist || Len(baselist) == 0) {
- Setattr(n, "single_inh", "1");
- return true;
- }
- if (baselist && Len(baselist) == 1) {
- Iterator b = First(baselist);
- if (this->get_single_base(b.item)) {
- if (base)
- *base = b.item;
- Setattr(n, "single_inh", "1");
- return true;
- }
- }
- return false;
+ *base = b.item;
+ Setattr(n, "single_inh", "1");
+ return true;
+ }
}
+ return false;
+ }
- virtual int classDeclaration(Node *n) {
- if (shadow && !Getattr(n, "feature:onlychildren")) {
- Node *mod = Getattr(n, "module");
- if (mod) {
- String *importname = NewString("");
- String *modname = Getattr(mod, "name");
- if (Strcmp(modname, mainmodule) != 0) {
- // check if the module has a package option
- Node *options = Getattr(mod, "options");
- String *pkg = options ? Getattr(options, "package") : 0;
- if (pkg && (!package || Strcmp(pkg, package) != 0)) {
- Printf(importname, "%s.", pkg);
- }
- Printf(importname, "%s.", modname);
- }
- Append(importname, Getattr(n, "sym:name"));
- Setattr(n, "python:proxy", importname);
- }
+ virtual int classDeclaration(Node *n) {
+ if (shadow && !Getattr(n, "feature:onlychildren")) {
+ Node *mod = Getattr(n, "module");
+ if (mod) {
+ String *importname = NewString("");
+ String *modname = Getattr(mod, "name");
+ if (Strcmp(modname, mainmodule) != 0) {
+ // check if the module has a package option
+ Node *options = Getattr(mod, "options");
+ String *pkg = options ? Getattr(options, "package") : 0;
+ if (pkg && (!package || Strcmp(pkg, package) != 0)) {
+ Printf(importname, "%s.", pkg);
+ }
+ Printf(importname, "%s.", modname);
}
- int result = Language::classDeclaration(n);
- return result;
+ Append(importname, Getattr(n, "sym:name"));
+ Setattr(n, "python:proxy", importname);
+ }
}
+ int result = Language::classDeclaration(n);
+ return result;
+ }
/* ------------------------------------------------------------
* classHandler()
* ------------------------------------------------------------ */
- void builtin_pre_decl (Node *n, Node *base_node)
- {
- String *name = Getattr(n, "name");
- String *rname = SwigType_namestr(name);
- Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname);
- Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n");
- if (base_node) {
- String *base_name = Copy(Getattr(base_node, "name"));
- SwigType_add_pointer(base_name);
- String *base_mname = SwigType_manglestr(base_name);
- Printf(f_init, tab4 "builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname);
- Printf(f_init, tab4 "if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n");
- Printf(f_init, tab8 "builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n");
- Printf(f_init, tab4 "}\n");
- Delete(base_mname);
- Delete(base_name);
- } else {
- //Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL);
- Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL);
- }
- Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n");
- Delete(rname);
+ void builtin_pre_decl (Node *n, Node *base_node)
+ {
+ String *name = Getattr(n, "name");
+ String *rname = SwigType_namestr(name);
+ Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname);
+ Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n");
+ if (base_node) {
+ String *base_name = Copy(Getattr(base_node, "name"));
+ SwigType_add_pointer(base_name);
+ String *base_mname = SwigType_manglestr(base_name);
+ Printf(f_init, tab4 "builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname);
+ Printf(f_init, tab4 "if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype) {\n");
+ Printf(f_init, tab8 "builtin_pytype->tp_base = ((SwigPyClientData*) builtin_basetype->clientdata)->pytype;\n");
+ Printf(f_init, tab4 "}\n");
+ Delete(base_mname);
+ Delete(base_name);
+ } else {
+ //Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL);
+ Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL);
}
+ Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n");
+ Delete(rname);
+ }
- void builtin_post_decl (File *f, Node *n)
- {
- String *name = Getattr(n, "name");
- String *pname = Copy(name);
- SwigType_add_pointer(pname);
- String *symname = Getattr(n, "sym:name");
- String *rname = SwigType_namestr(name);
- String *mname = SwigType_manglestr(pname);
- String *templ = NewString("");
- Printf(templ, "PySwigBuiltin< %s >", rname);
- char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0";
+ void builtin_post_decl (File *f, Node *n)
+ {
+ String *name = Getattr(n, "name");
+ String *pname = Copy(name);
+ SwigType_add_pointer(pname);
+ String *symname = Getattr(n, "sym:name");
+ String *rname = SwigType_namestr(name);
+ String *mname = SwigType_manglestr(pname);
+ String *templ = NewString("");
+ Printf(templ, "PySwigBuiltin< %s >", rname);
+ char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0";
- // Check for non-public destructor, in which case tp_dealloc should be "0"
- String *tp_dealloc = NewString("");
- String *dtor_name = NewString("delete");
- if (Getattr(class_members, "delete"))
- Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname);
- else
- Printv(tp_dealloc, "0", NIL);
- Delete(dtor_name);
+ // Check for non-public destructor, in which case tp_dealloc should be "0"
+ String *tp_dealloc = NewString("");
+ String *dtor_name = NewString("delete");
+ if (Getattr(class_members, "delete"))
+ Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname);
+ else
+ Printv(tp_dealloc, "0", NIL);
+ Delete(dtor_name);
- Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname);
- Printf(f, " PyObject_HEAD_INIT(NULL)\n");
- Printf(f, " 0, /*ob_size*/\n");
- Printf(f, " \"%s\", /*tp_name*/\n", symname);
- Printf(f, " sizeof(%s), /*tp_basicsize*/\n", templ);
- Printf(f, " %s, /*tp_itemsize*/\n", getSlot(n, "feature:tp_itemsize"));
- Printf(f, " %s, /*tp_dealloc*/\n", tp_dealloc);
- Printf(f, " %s, /*tp_print*/\n", getSlot(n, "feature:tp_print"));
- Printf(f, " %s, /*tp_getattr*/\n", getSlot(n, "feature:tp_getattr"));
- Printf(f, " %s, /*tp_setattr*/\n", getSlot(n, "feature:tp_setattr"));
- Printf(f, " %s, /*tp_compare*/\n", getSlot(n, "feature:tp_compare"));
- Printf(f, " %s, /*tp_repr*/\n", getSlot(n, "feature:tp_repr"));
- Printf(f, " %s, /*tp_as_number*/\n", getSlot(n, "feature:tp_as_number"));
- Printf(f, " %s, /*tp_as_sequence*/\n", getSlot(n, "feature:tp_as_sequence"));
- Printf(f, " %s, /*tp_as_mapping*/\n", getSlot(n, "feature:tp_as_mapping"));
- Printf(f, " %s, /*tp_hash */\n", getSlot(n, "feature:tp_hash"));
- Printf(f, " %s, /*tp_call*/\n", getSlot(n, "feature:tp_call"));
- Printf(f, " %s, /*tp_str*/\n", getSlot(n, "feature:tp_str"));
- Printf(f, " %s, /*tp_getattro*/\n", getSlot(n, "feature:tp_getattro"));
- Printf(f, " %s, /*tp_setattro*/\n", getSlot(n, "feature:tp_setattro"));
- Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer"));
- Printf(f, " Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_RICHCOMPARE, /*tp_flags*/\n");
- Printf(f, " \"%s\", /* tp_doc */\n", rname);
- Printf(f, " %s, /* tp_traverse */\n", getSlot(n, "feature:tp_traverse"));
- Printf(f, " %s, /* tp_clear */\n", getSlot(n, "feature:tp_clear"));
- Printf(f, " %s, /* tp_richcompare */\n", getSlot(n, "feature:tp_richcompare"));
- Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset"));
- Printf(f, " %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter"));
- Printf(f, " %s, /* tp_iternext */\n", getSlot(n, "feature:tp_iternext"));
- Printf(f, " %s::methods, /* tp_methods */\n", templ);
- Printf(f, " %s, /* tp_members */\n", getSlot(n, "feature:tp_members"));
- Printf(f, " %s, /* tp_getset */\n", getSlot(n, "feature:tp_getset"));
- Printf(f, " %s, /* tp_base */\n", getSlot(n, "feature:tp_base"));
- Printf(f, " %s, /* tp_dict */\n", getSlot(n, "feature:tp_dict"));
- Printf(f, " %s, /* tp_descr_get */\n", getSlot(n, "feature:tp_descr_get"));
- Printf(f, " %s, /* tp_descr_set */\n", getSlot(n, "feature:tp_descr_set"));
- Printf(f, " %s, /* tp_dictoffset */\n", getSlot(n, "feature:tp_dictoffset"));
- Printf(f, " (initproc)%s, /* tp_init */\n", tp_init);
- Printf(f, " %s, /* tp_alloc */\n", getSlot(n, "feature:tp_alloc"));
- Printf(f, " 0, /* tp_new */\n");
- Printf(f, " %s /* tp_free */\n", getSlot(n, "feature:tp_free"));
- Printf(f, "};\n\n");
+ Printf(f, "template <> PyGetSetDef PySwigBuiltin< %s >::getset[] = {\n", rname);
+ for (DohIterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) {
+ String *mname = member_iter.key;
+ Hash *mgetset = member_iter.item;
+ String *getter = Getattr(mgetset, "getter");
+ String *setter = Getattr(mgetset, "setter");
+ Printf(f, tab4 "{ const_cast(\"%s\"), (getter) %s, (setter) pyswig_setter_closure, const_cast(\"%s.%s\"), (void*) &%s },\n",
+ mname, getter ? getter : "0", name, mname, setter ? setter : "0");
+ }
+ Printv(f, " {NULL} // Sentinel\n", NIL);
+ Printv(f, "};\n\n", NIL);
+ Clear(builtin_getset);
+
+ Printf(f, "template <> PyNumberMethods PySwigBuiltin< %s >::number_methods = {\n", rname);
+ Printf(f, " (binaryfunc) %s, // nb_add;\n", getSlot(n, "feature:nb_add"));
+ Printf(f, " (binaryfunc) %s, // nb_subtract;\n", getSlot(n, "feature:nb_subtract"));
+ Printf(f, " (binaryfunc) %s, // nb_multiply;\n", getSlot(n, "feature:nb_multiply"));
+ Printf(f, " (binaryfunc) %s, // nb_divide;\n", getSlot(n, "feature:nb_divide"));
+ Printf(f, " (binaryfunc) %s, // nb_remainder;\n", getSlot(n, "feature:nb_remainder"));
+ Printf(f, " (binaryfunc) %s, // nb_divmod;\n", getSlot(n, "feature:nb_divmod"));
+ Printf(f, " (ternaryfunc) %s, // nb_power;\n", getSlot(n, "feature:nb_power"));
+ Printf(f, " (unaryfunc) %s, // nb_negative;\n", getSlot(n, "feature:nb_negative"));
+ Printf(f, " (unaryfunc) %s, // nb_positive;\n", getSlot(n, "feature:nb_positive"));
+ Printf(f, " (unaryfunc) %s, // nb_absolute;\n", getSlot(n, "feature:nb_absolute"));
+ Printf(f, " (inquiry) %s, // nb_nonzero;\n", getSlot(n, "feature:nb_nonzero"));
+ Printf(f, " (unaryfunc) %s, // nb_invert;\n", getSlot(n, "feature:nb_invert"));
+ Printf(f, " (binaryfunc) %s, // nb_lshift;\n", getSlot(n, "feature:nb_lshift"));
+ Printf(f, " (binaryfunc) %s, // nb_rshift;\n", getSlot(n, "feature:nb_rshift"));
+ Printf(f, " (binaryfunc) %s, // nb_and;\n", getSlot(n, "feature:nb_and"));
+ Printf(f, " (binaryfunc) %s, // nb_xor;\n", getSlot(n, "feature:nb_xor"));
+ Printf(f, " (binaryfunc) %s, // nb_or;\n", getSlot(n, "feature:nb_or"));
+ Printf(f, " (coercion) %s, // nb_coerce;\n", getSlot(n, "feature:nb_coerce"));
+ Printf(f, " (unaryfunc) %s, // nb_int;\n", getSlot(n, "feature:nb_int"));
+ Printf(f, " (unaryfunc) %s, // nb_long;\n", getSlot(n, "feature:nb_long"));
+ Printf(f, " (unaryfunc) %s, // nb_float;\n", getSlot(n, "feature:nb_float"));
+ Printf(f, " (unaryfunc) %s, // nb_oct;\n", getSlot(n, "feature:nb_oct"));
+ Printf(f, " (unaryfunc) %s, // nb_hex;\n", getSlot(n, "feature:nb_hex"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_add;\n", getSlot(n, "feature:nb_inplace_add"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_subtract;\n", getSlot(n, "feature:nb_inplace_subtract"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_multiply;\n", getSlot(n, "feature:nb_inplace_multiply"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_divide;\n", getSlot(n, "feature:nb_inplace_divide"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_remainder;\n", getSlot(n, "feature:nb_inplace_remainder"));
+ Printf(f, " (ternaryfunc) %s, // nb_inplace_power;\n", getSlot(n, "feature:nb_inplace_power"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_lshift;\n", getSlot(n, "feature:nb_inplace_lshift"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_rshift;\n", getSlot(n, "feature:nb_inplace_rshift"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_and;\n", getSlot(n, "feature:nb_inplace_and"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_xor;\n", getSlot(n, "feature:nb_inplace_xor"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_or;\n", getSlot(n, "feature:nb_inplace_or"));
+ Printf(f, " (binaryfunc) %s, // nb_floor_divide;\n", getSlot(n, "feature:nb_floor_divide"));
+ Printf(f, " (binaryfunc) %s, // nb_true_divide;\n", getSlot(n, "feature:nb_true_divide"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_floor_divide;\n", getSlot(n, "feature:nb_inplace_floor_divide"));
+ Printf(f, " (binaryfunc) %s, // nb_inplace_true_divide;\n", getSlot(n, "feature:nb_inplace_true_divide"));
+ Printf(f, " (unaryfunc) %s, // nb_index;\n", getSlot(n, "feature:nb_index"));
+ Printf(f, "};\n\n");
- String *clientdata = NewString("");
- Printf(clientdata, "&%s::clientdata", templ);
- SwigType_remember_clientdata(pname, clientdata);
+ String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES");
+ // TODO: Add more flags based on slots
+ Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname);
+ Printf(f, " PyObject_HEAD_INIT(NULL)\n");
+ Printf(f, " 0, /*ob_size*/\n");
+ Printf(f, " \"%s\", /*tp_name*/\n", symname);
+ Printf(f, " sizeof(%s), /*tp_basicsize*/\n", templ);
+ Printf(f, " %s, /*tp_itemsize*/\n", getSlot(n, "feature:tp_itemsize"));
+ Printf(f, " %s, /*tp_dealloc*/\n", tp_dealloc);
+ Printf(f, " %s, /*tp_print*/\n", getSlot(n, "feature:tp_print"));
+ Printf(f, " %s, /*tp_getattr*/\n", getSlot(n, "feature:tp_getattr"));
+ Printf(f, " %s, /*tp_setattr*/\n", getSlot(n, "feature:tp_setattr"));
+ Printf(f, " %s, /*tp_compare*/\n", getSlot(n, "feature:tp_compare"));
+ Printf(f, " %s, /*tp_repr*/\n", getSlot(n, "feature:tp_repr"));
+ Printf(f, " &%s::number_methods, /*tp_as_number*/\n", templ);
+ Printf(f, " %s, /*tp_as_sequence*/\n", getSlot(n, "feature:tp_as_sequence"));
+ Printf(f, " %s, /*tp_as_mapping*/\n", getSlot(n, "feature:tp_as_mapping"));
+ Printf(f, " %s, /*tp_hash */\n", getSlot(n, "feature:tp_hash"));
+ Printf(f, " %s, /*tp_call*/\n", getSlot(n, "feature:tp_call"));
+ Printf(f, " %s, /*tp_str*/\n", getSlot(n, "feature:tp_str"));
+ Printf(f, " %s, /*tp_getattro*/\n", getSlot(n, "feature:tp_getattro"));
+ Printf(f, " %s, /*tp_setattro*/\n", getSlot(n, "feature:tp_setattro"));
+ Printf(f, " %s, /*tp_as_buffer*/\n", getSlot(n, "feature:tp_as_buffer"));
+ Printf(f, " %s, /*tp_flags*/\n", tp_flags);
+ Printf(f, " \"%s\", /* tp_doc */\n", rname);
+ Printf(f, " %s, /* tp_traverse */\n", getSlot(n, "feature:tp_traverse"));
+ Printf(f, " %s, /* tp_clear */\n", getSlot(n, "feature:tp_clear"));
+ Printf(f, " %s, /* tp_richcompare */\n", getSlot(n, "feature:tp_richcompare"));
+ Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset"));
+ Printf(f, " %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter"));
+ Printf(f, " %s, /* tp_iternext */\n", getSlot(n, "feature:tp_iternext"));
+ Printf(f, " %s::methods, /* tp_methods */\n", templ);
+ Printf(f, " %s, /* tp_members */\n", getSlot(n, "feature:tp_members"));
+ Printf(f, " %s::getset, /* tp_getset */\n", templ);
+ Printf(f, " %s, /* tp_base */\n", getSlot(n, "feature:tp_base"));
+ Printf(f, " %s, /* tp_dict */\n", getSlot(n, "feature:tp_dict"));
+ Printf(f, " %s, /* tp_descr_get */\n", getSlot(n, "feature:tp_descr_get"));
+ Printf(f, " %s, /* tp_descr_set */\n", getSlot(n, "feature:tp_descr_set"));
+ Printf(f, " %s, /* tp_dictoffset */\n", getSlot(n, "feature:tp_dictoffset"));
+ Printf(f, " (initproc)%s, /* tp_init */\n", tp_init);
+ Printf(f, " %s, /* tp_alloc */\n", getSlot(n, "feature:tp_alloc"));
+ Printf(f, " 0, /* tp_new */\n");
+ Printf(f, " %s /* tp_free */\n", getSlot(n, "feature:tp_free"));
+ Printf(f, "};\n\n");
- Printf(f, "template <> SwigPyClientData %s::clientdata = {0, 0, 0, 0, 0, 0, &%s::pytype};\n\n", templ, templ);
+ String *clientdata = NewString("");
+ Printf(clientdata, "&%s::clientdata", templ);
+ SwigType_remember_clientdata(pname, clientdata);
- Printv(f_init, " d = md;\n", NIL);
- Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL);
- Printf(f_init, " fprintf(stderr, \"Couldn't create type %s\");\n", symname);
- Printv(f_init, " return;\n", NIL);
- Printv(f_init, " }\n", NIL);
- Printv(f_init, " Py_INCREF(builtin_pytype);\n", NIL);
- Printf(f_init, " PyModule_AddObject(m, \"%s\", (PyObject*) builtin_pytype);\n", symname);
+ Printf(f, "template <> SwigPyClientData %s::clientdata = {0, 0, 0, 0, 0, 0, &%s::pytype};\n\n", templ, templ);
- Delete(clientdata);
- Delete(templ);
- Delete(mname);
- Delete(rname);
- Delete(pname);
- Delete(tp_dealloc);
- }
+ Printv(f_init, " d = md;\n", NIL);
+ Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL);
+ Printf(f_init, " fprintf(stderr, \"Couldn't create type %s\");\n", symname);
+ Printv(f_init, " return;\n", NIL);
+ Printv(f_init, " }\n", NIL);
+ Printv(f_init, " Py_INCREF(builtin_pytype);\n", NIL);
+ Printf(f_init, " PyModule_AddObject(m, \"%s\", (PyObject*) builtin_pytype);\n", symname);
- virtual int classHandler(Node *n) {
- int oldclassic = classic;
- int oldmodern = modern;
- File *f_shadow_file = f_shadow;
- bool single_inh = false;
- Node *base_node = NULL;
+ Delete(clientdata);
+ Delete(templ);
+ Delete(mname);
+ Delete(rname);
+ Delete(pname);
+ Delete(tp_dealloc);
+ Delete(tp_flags);
+ }
- if (shadow) {
+ virtual int classHandler(Node *n) {
+ int oldclassic = classic;
+ int oldmodern = modern;
+ File *f_shadow_file = f_shadow;
+ bool single_inh = false;
+ Node *base_node = NULL;
- /* Create new strings for building up a wrapper function */
- have_constructor = 0;
- have_repr = 0;
+ if (shadow) {
- if (GetFlag(n, "feature:classic")) {
- classic = 1;
- modern = 0;
- }
- if (GetFlag(n, "feature:modern")) {
- classic = 0;
- modern = 1;
- }
- if (GetFlag(n, "feature:exceptionclass")) {
- classic = 1;
- modern = 0;
- }
+ /* Create new strings for building up a wrapper function */
+ have_constructor = 0;
+ have_repr = 0;
- class_name = Getattr(n, "sym:name");
- real_classname = Getattr(n, "name");
+ if (GetFlag(n, "feature:classic")) {
+ classic = 1;
+ modern = 0;
+ }
+ if (GetFlag(n, "feature:modern")) {
+ classic = 0;
+ modern = 1;
+ }
+ if (GetFlag(n, "feature:exceptionclass")) {
+ classic = 1;
+ modern = 0;
+ }
- if (!addSymbol(class_name, n))
- return SWIG_ERROR;
+ class_name = Getattr(n, "sym:name");
+ real_classname = Getattr(n, "name");
- single_inh = builtin && get_single_base(n, &base_node);
- if (builtin && !single_inh) {
- Swig_warning(WARN_PYTHON_MULTIPLE_INH, Getfile(n), Getline(n),
- "Class '%s' ignored, because it has multiple inheritance, which is incompatible with the '-builtin' option.\n", real_classname);
- return SWIG_OK;
- }
-
- shadow_indent = (String *) tab4;
-
- /* Handle inheritance */
- String *base_class = NewString("");
- List *baselist = Getattr(n, "bases");
- if (baselist && Len(baselist)) {
- Iterator b;
- b = First(baselist);
- while (b.item) {
- String *bname = Getattr(b.item, "python:proxy");
- bool ignore = GetFlag(b.item, "feature:ignore") ? true : false;
- if (!bname || ignore) {
- if (!bname && !ignore) {
- Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n),
- "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name")));
- }
- b = Next(b);
- continue;
- }
- Printv(base_class, bname, NIL);
- b = Next(b);
- if (b.item) {
- Putc(',', base_class);
- }
- }
- }
-
- /* dealing with abstract base class */
- String *abcs = Getattr(n, "feature:python:abc");
- if (py3 && abcs) {
- if (Len(base_class)) {
- Putc(',', base_class);
- }
- Printv(base_class, abcs, NIL);
- }
-
- if (!single_inh) {
- Printv(f_shadow, "class ", class_name, NIL);
-
- if (Len(base_class)) {
- Printf(f_shadow, "(%s)", base_class);
- } else {
- if (!classic) {
- Printf(f_shadow, modern ? "(object)" : "(_object)");
- }
- if (GetFlag(n, "feature:exceptionclass") ) {
- Printf(f_shadow, "(Exception)");
- }
- }
-
- Printf(f_shadow, ":\n");
- if (have_docstring(n)) {
- String *str = docstring(n, AUTODOC_CLASS, tab4);
- if (str && Len(str))
- Printv(f_shadow, tab4, str, "\n", NIL);
- }
-
- if (!modern) {
- Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL);
- if (Len(base_class)) {
- Printf(f_shadow, "%sfor _s in [%s]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))\n", tab4, base_class);
- }
-
- if (!GetFlag(n, "feature:python:nondynamic")) {
- Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", NIL);
- } else {
- Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", NIL);
- }
-
- Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL);
- if (Len(base_class)) {
- Printf(f_shadow, "%sfor _s in [%s]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))\n", tab4, base_class);
- }
-
- Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL);
- } else {
- Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL);
- /* Add static attribute */
- if (GetFlag(n, "feature:python:nondynamic")) {
- Printv(f_shadow_file,
- tab4, "__setattr__ = _swig_setattr_nondynamic_method(object.__setattr__)\n",
- tab4, "class __metaclass__(type):\n", tab4, tab4, "__setattr__ = _swig_setattr_nondynamic_method(type.__setattr__)\n", NIL);
- }
- }
- }
- }
-
- /* Emit all of the members */
-
- in_class = 1;
- if (single_inh) {
- class_members = NewHash();
- builtin_pre_decl(n, base_node);
- }
-
- /* Overide the shadow file so we can capture its methods */
- f_shadow = NewString("");
-
- // Set up type check for director class constructor
- Clear(none_comparison);
- if (builtin && Swig_directorclass(n)) {
- String *p_real_classname = Copy(real_classname);
- SwigType_add_pointer(p_real_classname);
- String *mangle = SwigType_manglestr(p_real_classname);
- String *descriptor = NewStringf("SWIGTYPE%s", mangle);
- Printv(none_comparison, "self->ob_type != ((SwigPyClientData*) (", descriptor, ")->clientdata)->pytype", NIL);
- Delete(descriptor);
- Delete(mangle);
- Delete(p_real_classname);
- } else {
- Printv(none_comparison, "$arg != Py_None", NIL);
- }
-
- Language::classHandler(n);
-
- in_class = 0;
-
- /* Complete the class */
- if (shadow) {
- /* Generate a class registration function */
- if (!single_inh) {
- String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers)
- SwigType *smart = 0;
- if (smartptr) {
- SwigType *cpt = Swig_cparse_type(smartptr);
- if (cpt) {
- smart = SwigType_typedef_resolve_all(cpt);
- Delete(cpt);
- } else {
- // TODO: report line number of where the feature comes from
- Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname);
- }
- }
- SwigType *ct = Copy(smart ? smart : real_classname);
- SwigType_add_pointer(ct);
- SwigType *realct = Copy(real_classname);
- SwigType_add_pointer(realct);
- SwigType_remember(realct);
- Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
- Printv(f_wrappers, " PyObject *obj;\n", NIL);
- if (modernargs) {
- if (fastunpack) {
- Printv(f_wrappers, " if (!SWIG_Python_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
- } else {
- Printv(f_wrappers, " if (!PyArg_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
- }
- } else {
- Printv(f_wrappers, " if (!PyArg_ParseTuple(args,(char*)\"O:swigregister\", &obj)) return NULL;\n", NIL);
- }
-
- Printv(f_wrappers,
- " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n",
- " return SWIG_Py_Void();\n", "}\n\n", NIL);
- String *cname = NewStringf("%s_swigregister", class_name);
- add_method(cname, cname, 0);
- Delete(smart);
- Delete(cname);
- Delete(ct);
- Delete(realct);
- }
- if (!have_constructor) {
- if (!single_inh)
- Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
- } else if (fastinit && !single_inh) {
-
- Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
- Printv(f_wrappers, " return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL);
- String *cname = NewStringf("%s_swiginit", class_name);
- add_method(cname, cname, 0);
- Delete(cname);
- }
- if (!have_repr && !single_inh) {
- /* Supply a repr method for this class */
- String *rname = SwigType_namestr(real_classname);
- if (new_repr) {
- Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL);
- } else {
- Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL);
- }
- Delete(rname);
- }
-
- if (single_inh) {
- builtin_post_decl(f_builtins, n);
- String *rname = SwigType_namestr(real_classname);
- Printf(f_builtins, "template <> PyMethodDef PySwigBuiltin< %s >::methods[] = {\n", rname);
- Delete(rname);
- }
-
- if (builtin_tp_init) {
- Delete(builtin_tp_init);
- builtin_tp_init = 0;
- }
-
- /* Now emit methods */
- if (!single_inh)
- Printv(f_shadow_file, f_shadow, NIL);
-
- /* Now the Ptr class */
- if (classptr && !single_inh) {
- Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL);
- if (!modern) {
- Printv(f_shadow_file,
- tab8, "try: self.this.append(this)\n",
- tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL);
- } else {
- Printv(f_shadow_file,
- tab8, "try: self.this.append(this)\n",
- tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL);
- }
- }
-
- if (!single_inh) {
- if (fastproxy) {
- List *shadow_list = Getattr(n, "shadow_methods");
- for (int i = 0; i < Len(shadow_list); ++i) {
- String *symname = Getitem(shadow_list, i);
- Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name);
- }
- }
- Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name);
- Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name);
-
- shadow_indent = 0;
- Printf(f_shadow_file, "%s\n", f_shadow_stubs);
- }
- shadow_indent = 0;
- Clear(f_shadow_stubs);
- }
-
- if (single_inh) {
- Dump(f_shadow, f_builtins);
- Printf(f_builtins, " {NULL} // Sentinel\n};\n\n");
- Delete(class_members);
- class_members = 0;
- }
-
- classic = oldclassic;
- modern = oldmodern;
-
- /* Restore shadow file back to original version */
- Delete(f_shadow);
- f_shadow = f_shadow_file;
+ if (!addSymbol(class_name, n))
+ return SWIG_ERROR;
+ single_inh = builtin && get_single_base(n, &base_node);
+ if (builtin && !single_inh) {
+ Swig_warning(WARN_PYTHON_MULTIPLE_INH, Getfile(n), Getline(n),
+ "Class '%s' ignored, because it has multiple inheritance, which is incompatible with the '-builtin' option.\n", real_classname);
return SWIG_OK;
+ }
+
+ shadow_indent = (String *) tab4;
+
+ /* Handle inheritance */
+ String *base_class = NewString("");
+ List *baselist = Getattr(n, "bases");
+ if (baselist && Len(baselist)) {
+ Iterator b;
+ b = First(baselist);
+ while (b.item) {
+ String *bname = Getattr(b.item, "python:proxy");
+ bool ignore = GetFlag(b.item, "feature:ignore") ? true : false;
+ if (!bname || ignore) {
+ if (!bname && !ignore) {
+ Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n),
+ "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name")));
+ }
+ b = Next(b);
+ continue;
+ }
+ Printv(base_class, bname, NIL);
+ b = Next(b);
+ if (b.item) {
+ Putc(',', base_class);
+ }
+ }
+ }
+
+ /* dealing with abstract base class */
+ String *abcs = Getattr(n, "feature:python:abc");
+ if (py3 && abcs) {
+ if (Len(base_class)) {
+ Putc(',', base_class);
+ }
+ Printv(base_class, abcs, NIL);
+ }
+
+ if (!single_inh) {
+ Printv(f_shadow, "class ", class_name, NIL);
+
+ if (Len(base_class)) {
+ Printf(f_shadow, "(%s)", base_class);
+ } else {
+ if (!classic) {
+ Printf(f_shadow, modern ? "(object)" : "(_object)");
+ }
+ if (GetFlag(n, "feature:exceptionclass") ) {
+ Printf(f_shadow, "(Exception)");
+ }
+ }
+
+ Printf(f_shadow, ":\n");
+ if (have_docstring(n)) {
+ String *str = docstring(n, AUTODOC_CLASS, tab4);
+ if (str && Len(str))
+ Printv(f_shadow, tab4, str, "\n", NIL);
+ }
+
+ if (!modern) {
+ Printv(f_shadow, tab4, "__swig_setmethods__ = {}\n", NIL);
+ if (Len(base_class)) {
+ Printf(f_shadow, "%sfor _s in [%s]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))\n", tab4, base_class);
+ }
+
+ if (!GetFlag(n, "feature:python:nondynamic")) {
+ Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr(self, ", class_name, ", name, value)\n", NIL);
+ } else {
+ Printv(f_shadow, tab4, "__setattr__ = lambda self, name, value: _swig_setattr_nondynamic(self, ", class_name, ", name, value)\n", NIL);
+ }
+
+ Printv(f_shadow, tab4, "__swig_getmethods__ = {}\n", NIL);
+ if (Len(base_class)) {
+ Printf(f_shadow, "%sfor _s in [%s]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))\n", tab4, base_class);
+ }
+
+ Printv(f_shadow, tab4, "__getattr__ = lambda self, name: _swig_getattr(self, ", class_name, ", name)\n", NIL);
+ } else {
+ Printv(f_shadow, tab4, "thisown = _swig_property(lambda x: x.this.own(), ", "lambda x, v: x.this.own(v), doc='The membership flag')\n", NIL);
+ /* Add static attribute */
+ if (GetFlag(n, "feature:python:nondynamic")) {
+ Printv(f_shadow_file,
+ tab4, "__setattr__ = _swig_setattr_nondynamic_method(object.__setattr__)\n",
+ tab4, "class __metaclass__(type):\n", tab4, tab4, "__setattr__ = _swig_setattr_nondynamic_method(type.__setattr__)\n", NIL);
+ }
+ }
+ }
}
+ /* Emit all of the members */
+
+ in_class = 1;
+ if (single_inh) {
+ class_members = NewHash();
+ builtin_pre_decl(n, base_node);
+ }
+
+ /* Overide the shadow file so we can capture its methods */
+ f_shadow = NewString("");
+
+ // Set up type check for director class constructor
+ Clear(none_comparison);
+ if (builtin && Swig_directorclass(n)) {
+ String *p_real_classname = Copy(real_classname);
+ SwigType_add_pointer(p_real_classname);
+ String *mangle = SwigType_manglestr(p_real_classname);
+ String *descriptor = NewStringf("SWIGTYPE%s", mangle);
+ Printv(none_comparison, "self->ob_type != ((SwigPyClientData*) (", descriptor, ")->clientdata)->pytype", NIL);
+ Delete(descriptor);
+ Delete(mangle);
+ Delete(p_real_classname);
+ } else {
+ Printv(none_comparison, "$arg != Py_None", NIL);
+ }
+
+ Language::classHandler(n);
+
+ in_class = 0;
+
+ /* Complete the class */
+ if (shadow) {
+ /* Generate a class registration function */
+ if (!single_inh) {
+ String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers)
+ SwigType *smart = 0;
+ if (smartptr) {
+ SwigType *cpt = Swig_cparse_type(smartptr);
+ if (cpt) {
+ smart = SwigType_typedef_resolve_all(cpt);
+ Delete(cpt);
+ } else {
+ // TODO: report line number of where the feature comes from
+ Swig_error(Getfile(n), Getline(n), "Invalid type (%s) in 'smartptr' feature for class %s.\n", smartptr, real_classname);
+ }
+ }
+ SwigType *ct = Copy(smart ? smart : real_classname);
+ SwigType_add_pointer(ct);
+ SwigType *realct = Copy(real_classname);
+ SwigType_add_pointer(realct);
+ SwigType_remember(realct);
+ Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swigregister(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
+ Printv(f_wrappers, " PyObject *obj;\n", NIL);
+ if (modernargs) {
+ if (fastunpack) {
+ Printv(f_wrappers, " if (!SWIG_Python_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
+ } else {
+ Printv(f_wrappers, " if (!PyArg_UnpackTuple(args,(char*)\"swigregister\", 1, 1,&obj)) return NULL;\n", NIL);
+ }
+ } else {
+ Printv(f_wrappers, " if (!PyArg_ParseTuple(args,(char*)\"O:swigregister\", &obj)) return NULL;\n", NIL);
+ }
+
+ Printv(f_wrappers,
+ " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n",
+ " return SWIG_Py_Void();\n", "}\n\n", NIL);
+ String *cname = NewStringf("%s_swigregister", class_name);
+ add_method(cname, cname, 0);
+ Delete(smart);
+ Delete(cname);
+ Delete(ct);
+ Delete(realct);
+ }
+ if (!have_constructor) {
+ if (!single_inh)
+ Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
+ } else if (fastinit && !single_inh) {
+
+ Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
+ Printv(f_wrappers, " return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL);
+ String *cname = NewStringf("%s_swiginit", class_name);
+ add_method(cname, cname, 0);
+ Delete(cname);
+ }
+ if (!have_repr && !single_inh) {
+ /* Supply a repr method for this class */
+ String *rname = SwigType_namestr(real_classname);
+ if (new_repr) {
+ Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL);
+ } else {
+ Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"\" % (self.this,)\n", NIL);
+ }
+ Delete(rname);
+ }
+
+ if (single_inh) {
+ builtin_post_decl(f_builtins, n);
+ String *rname = SwigType_namestr(real_classname);
+ Printf(f_builtins, "template <> PyMethodDef PySwigBuiltin< %s >::methods[] = {\n", rname);
+ Delete(rname);
+ }
+
+ if (builtin_tp_init) {
+ Delete(builtin_tp_init);
+ builtin_tp_init = 0;
+ }
+
+ /* Now emit methods */
+ if (!single_inh)
+ Printv(f_shadow_file, f_shadow, NIL);
+
+ /* Now the Ptr class */
+ if (classptr && !single_inh) {
+ Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL);
+ if (!modern) {
+ Printv(f_shadow_file,
+ tab8, "try: self.this.append(this)\n",
+ tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL);
+ } else {
+ Printv(f_shadow_file,
+ tab8, "try: self.this.append(this)\n",
+ tab8, "except: self.this = this\n", tab8, "self.this.own(0)\n", tab8, "self.__class__ = ", class_name, "\n\n", NIL);
+ }
+ }
+
+ if (!single_inh) {
+ if (fastproxy) {
+ List *shadow_list = Getattr(n, "shadow_methods");
+ for (int i = 0; i < Len(shadow_list); ++i) {
+ String *symname = Getitem(shadow_list, i);
+ Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name);
+ }
+ }
+ Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name);
+ Printf(f_shadow_file, "%s_swigregister(%s)\n", class_name, class_name);
+
+ shadow_indent = 0;
+ Printf(f_shadow_file, "%s\n", f_shadow_stubs);
+ }
+ shadow_indent = 0;
+ Clear(f_shadow_stubs);
+ }
+
+ if (single_inh) {
+ Dump(f_shadow, f_builtins);
+ Printf(f_builtins, " {NULL} // Sentinel\n};\n\n");
+ Delete(class_members);
+ class_members = 0;
+ }
+
+ classic = oldclassic;
+ modern = oldmodern;
+
+ /* Restore shadow file back to original version */
+ Delete(f_shadow);
+ f_shadow = f_shadow_file;
+
+ return SWIG_OK;
+ }
+
/* ------------------------------------------------------------
* functionHandler() - Mainly overloaded for callback handling
* ------------------------------------------------------------ */
@@ -3383,575 +3501,574 @@ public:
* memberfunctionHandler()
* ------------------------------------------------------------ */
- virtual int memberfunctionHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
- int oldshadow;
+ virtual int memberfunctionHandler(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ int oldshadow;
- /* Create the default member function */
- oldshadow = shadow; /* Disable shadowing when wrapping member functions */
- if (shadow)
- shadow = shadow | PYSHADOW_MEMBER;
- Language::memberfunctionHandler(n);
- shadow = oldshadow;
+ /* Create the default member function */
+ oldshadow = shadow; /* Disable shadowing when wrapping member functions */
+ if (shadow)
+ shadow = shadow | PYSHADOW_MEMBER;
+ Language::memberfunctionHandler(n);
+ shadow = oldshadow;
- if (!Getattr(n, "sym:nextSibling")) {
- if (builtin && in_class) {
- String *name = Getattr(n, "name");
- if (checkAttribute(n, "access", "public") && strncmp(Char(name), "operator ", 9) && !Getattr(class_members, name)) {
- String *fullname = Swig_name_member(NULL, class_name, symname);
- String *wname = Swig_name_wrapper(fullname);
- Setattr(class_members, name, name);
- ParmList *parms = Getattr(n, "parms");
- bool noArgs = !parms || Len(parms) == 0;
- String *pyflags = NewString(noArgs ? "METH_NOARGS" : "METH_VARARGS");
- Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags));
- Delete(name);
- Delete(fullname);
- Delete(wname);
- Delete(pyflags);
- }
- } else if (shadow) {
- int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
- int fproxy = fastproxy;
- if (Strcmp(symname, "__repr__") == 0) {
- have_repr = 1;
- }
- if (Getattr(n, "feature:shadow")) {
- String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
- String *pyaction = NewStringf("%s.%s", module, Swig_name_member(NSPACE_TODO, class_name, symname));
- Replaceall(pycode, "$action", pyaction);
- Delete(pyaction);
- Printv(f_shadow, pycode, "\n", NIL);
- Delete(pycode);
- fproxy = 0;
- } else {
- String *parms = make_pyParmList(n, true, false, allow_kwargs);
- String *callParms = make_pyParmList(n, true, true, allow_kwargs);
- if (!have_addtofunc(n)) {
- if (!fastproxy || olddefs) {
- Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL);
- Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
- }
- } else {
- Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL);
- Printv(f_shadow, "\n", NIL);
- if (have_docstring(n))
- Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL);
- if (have_pythonprepend(n)) {
- fproxy = 0;
- Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
- }
- if (have_pythonappend(n)) {
- fproxy = 0;
- Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
- Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
- Printv(f_shadow, tab8, "return val\n\n", NIL);
- } else {
- Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL);
- }
- }
- }
- if (fproxy) {
- List *shadow_list = Getattr(getCurrentClass(), "shadow_methods");
- if (!shadow_list) {
- shadow_list = NewList();
- Setattr(getCurrentClass(), "shadow_methods", shadow_list);
- Delete(shadow_list);
- }
- Append(shadow_list, symname);
- }
- }
+ if (!Getattr(n, "sym:nextSibling")) {
+ if (builtin && in_class) {
+ String *name = Getattr(n, "name");
+ if (checkAttribute(n, "access", "public") && strncmp(Char(name), "operator ", 9) && !Getattr(class_members, name)) {
+ String *fullname = Swig_name_member(NULL, class_name, symname);
+ String *wname = Swig_name_wrapper(fullname);
+ Setattr(class_members, name, name);
+ ParmList *parms = Getattr(n, "parms");
+ bool noArgs = !parms || Len(parms) == 0;
+ String *pyflags = NewString("METH_VARARGS");
+ Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags));
+ Delete(name);
+ Delete(fullname);
+ Delete(wname);
+ Delete(pyflags);
}
- return SWIG_OK;
+ } else if (shadow) {
+ int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
+ int fproxy = fastproxy;
+ if (Strcmp(symname, "__repr__") == 0) {
+ have_repr = 1;
+ }
+ if (Getattr(n, "feature:shadow")) {
+ String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
+ String *pyaction = NewStringf("%s.%s", module, Swig_name_member(NSPACE_TODO, class_name, symname));
+ Replaceall(pycode, "$action", pyaction);
+ Delete(pyaction);
+ Printv(f_shadow, pycode, "\n", NIL);
+ Delete(pycode);
+ fproxy = 0;
+ } else {
+ String *parms = make_pyParmList(n, true, false, allow_kwargs);
+ String *callParms = make_pyParmList(n, true, true, allow_kwargs);
+ if (!have_addtofunc(n)) {
+ if (!fastproxy || olddefs) {
+ Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL);
+ Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
+ }
+ } else {
+ Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL);
+ Printv(f_shadow, "\n", NIL);
+ if (have_docstring(n))
+ Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL);
+ if (have_pythonprepend(n)) {
+ fproxy = 0;
+ Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
+ }
+ if (have_pythonappend(n)) {
+ fproxy = 0;
+ Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
+ Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
+ Printv(f_shadow, tab8, "return val\n\n", NIL);
+ } else {
+ Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL);
+ }
+ }
+ }
+ if (fproxy) {
+ List *shadow_list = Getattr(getCurrentClass(), "shadow_methods");
+ if (!shadow_list) {
+ shadow_list = NewList();
+ Setattr(getCurrentClass(), "shadow_methods", shadow_list);
+ Delete(shadow_list);
+ }
+ Append(shadow_list, symname);
+ }
+ }
}
+ return SWIG_OK;
+ }
/* ------------------------------------------------------------
* staticmemberfunctionHandler()
* ------------------------------------------------------------ */
- virtual int staticmemberfunctionHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
- if (builtin && in_class) {
- Swig_save("builtin_memberconstantHandler", n, "builtin_sym:name", NIL);
- Setattr(n, "builtin_sym:name", symname);
- }
- Language::staticmemberfunctionHandler(n);
- if (builtin && in_class) {
- Swig_restore(n);
- }
-
- if (Getattr(n, "sym:nextSibling")) {
- return SWIG_OK;
- }
-
- if (builtin && in_class) {
- String *name = Getattr(n, "name");
- if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) {
- String *fullname = Swig_name_member(NULL, class_name, name);
- String *wname = Swig_name_wrapper(fullname);
- Setattr(class_members, name, name);
- String *pyflags = NewString("METH_VARARGS|METH_STATIC");
- Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags));
- Delete(name);
- Delete(fullname);
- Delete(wname);
- Delete(pyflags);
- }
- } else if (shadow ) {
- if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) {
- int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
- String *parms = make_pyParmList(n, false, false, kw);
- String *callParms = make_pyParmList(n, false, true, kw);
- Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL);
- if (have_docstring(n))
- Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL);
- if (have_pythonprepend(n))
- Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
- if (have_pythonappend(n)) {
- Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
- Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
- Printv(f_shadow, tab8, "return val\n\n", NIL);
- } else {
- Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL);
- }
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", symname, ")\n", NIL);
-
- if (!modern) {
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL);
- }
-
- } else {
- if (!modern) {
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
- }
- if (!classic) {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL);
- }
- }
- }
- return SWIG_OK;
+ virtual int staticmemberfunctionHandler(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ if (builtin && in_class) {
+ Swig_save("builtin_memberconstantHandler", n, "builtin_sym:name", NIL);
+ Setattr(n, "builtin_sym:name", symname);
}
+ Language::staticmemberfunctionHandler(n);
+ if (builtin && in_class) {
+ Swig_restore(n);
+ }
+
+ if (Getattr(n, "sym:nextSibling")) {
+ return SWIG_OK;
+ }
+
+ if (builtin && in_class) {
+ String *name = Getattr(n, "name");
+ if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) {
+ String *fullname = Swig_name_member(NULL, class_name, name);
+ String *wname = Swig_name_wrapper(fullname);
+ Setattr(class_members, name, name);
+ String *pyflags = NewString("METH_VARARGS|METH_STATIC");
+ Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags));
+ Delete(name);
+ Delete(fullname);
+ Delete(wname);
+ Delete(pyflags);
+ }
+ } else if (shadow ) {
+ if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) {
+ int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
+ String *parms = make_pyParmList(n, false, false, kw);
+ String *callParms = make_pyParmList(n, false, true, kw);
+ Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL);
+ if (have_docstring(n))
+ Printv(f_shadow, tab8, docstring(n, AUTODOC_STATICFUNC, tab8), "\n", NIL);
+ if (have_pythonprepend(n))
+ Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
+ if (have_pythonappend(n)) {
+ Printv(f_shadow, tab8, "val = ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
+ Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
+ Printv(f_shadow, tab8, "return val\n\n", NIL);
+ } else {
+ Printv(f_shadow, tab8, "return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n\n", NIL);
+ }
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", symname, ")\n", NIL);
+
+ if (!modern) {
+ Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", symname, "\n", NIL);
+ }
+
+ } else {
+ if (!modern) {
+ Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
+ }
+ if (!classic) {
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL);
+ }
+ }
+ }
+ return SWIG_OK;
+ }
/* ------------------------------------------------------------
* constructorDeclaration()
* ------------------------------------------------------------ */
- virtual int constructorHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
- int oldshadow = shadow;
- int use_director = Swig_directorclass(n);
+ virtual int constructorHandler(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ int oldshadow = shadow;
+ int use_director = Swig_directorclass(n);
- /*
- * If we're wrapping the constructor of a C++ director class, prepend a new parameter
- * to receive the scripting language object (e.g. 'self')
- *
- */
- Swig_save("python:constructorHandler", n, "parms", NIL);
- if (use_director) {
- Parm *parms = Getattr(n, "parms");
- Parm *self;
- String *name = NewString("self");
- String *type = NewString("PyObject");
- SwigType_add_pointer(type);
- self = NewParm(type, name, n);
- Delete(type);
- Delete(name);
- Setattr(self, "lname", "O");
- if (parms)
- set_nextSibling(self, parms);
- Setattr(n, "parms", self);
- Setattr(n, "wrap:self", "1");
- Setattr(n, "hidden", "1");
- Delete(self);
+ /*
+ * If we're wrapping the constructor of a C++ director class, prepend a new parameter
+ * to receive the scripting language object (e.g. 'self')
+ *
+ */
+ Swig_save("python:constructorHandler", n, "parms", NIL);
+ if (use_director) {
+ Parm *parms = Getattr(n, "parms");
+ Parm *self;
+ String *name = NewString("self");
+ String *type = NewString("PyObject");
+ SwigType_add_pointer(type);
+ self = NewParm(type, name, n);
+ Delete(type);
+ Delete(name);
+ Setattr(self, "lname", "O");
+ if (parms)
+ set_nextSibling(self, parms);
+ Setattr(n, "parms", self);
+ Setattr(n, "wrap:self", "1");
+ Setattr(n, "hidden", "1");
+ Delete(self);
+ }
+
+ if (shadow)
+ shadow = shadow | PYSHADOW_MEMBER;
+ Language::constructorHandler(n);
+ shadow = oldshadow;
+
+ Delattr(n, "wrap:self");
+ Swig_restore(n);
+
+ if (!Getattr(n, "sym:nextSibling")) {
+ if (builtin && in_class) {
+ String *name = NewString("new");
+ if ((use_director || checkAttribute(n, "access", "public")) && !Getattr(class_members, name)) {
+ Setattr(class_members, name, name);
+ String *fullname = Swig_name_member(NULL, name, class_name);
+ if (!builtin_tp_init)
+ builtin_tp_init = Swig_name_wrapper(fullname);
+ /*
+ ParmList *parms = Getattr(n, "parms");
+ char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS";
+ Printf(f_shadow, " { \"__init__\", (PyCFunction) %s, %s, \"\" },\n", builtin_tp_init, Char(pyflags));
+ */
+ Delete(fullname);
+ }
+ Delete(name);
+ } else if (shadow) {
+ int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0;
+ int handled_as_init = 0;
+ if (!have_constructor) {
+ String *nname = Getattr(n, "sym:name");
+ String *sname = Getattr(getCurrentClass(), "sym:name");
+ String *cname = Swig_name_construct(NSPACE_TODO, sname);
+ handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0);
+ Delete(cname);
}
-
- if (shadow)
- shadow = shadow | PYSHADOW_MEMBER;
- Language::constructorHandler(n);
- shadow = oldshadow;
-
- Delattr(n, "wrap:self");
- Swig_restore(n);
-
- if (!Getattr(n, "sym:nextSibling")) {
- if (builtin && in_class) {
- String *name = NewString("new");
- if ((use_director || checkAttribute(n, "access", "public")) && !Getattr(class_members, name)) {
- Setattr(class_members, name, name);
- String *fullname = Swig_name_member(NULL, name, class_name);
- if (!builtin_tp_init)
- builtin_tp_init = Swig_name_wrapper(fullname);
- /*
- ParmList *parms = Getattr(n, "parms");
- char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS";
- Printf(f_shadow, " { \"__init__\", (PyCFunction) %s, %s, \"\" },\n", builtin_tp_init, Char(pyflags));
- */
- Delete(fullname);
- }
- Delete(name);
- } else if (shadow) {
- int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0;
- int handled_as_init = 0;
- if (!have_constructor) {
- String *nname = Getattr(n, "sym:name");
- String *sname = Getattr(getCurrentClass(), "sym:name");
- String *cname = Swig_name_construct(NSPACE_TODO, sname);
- handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0);
- Delete(cname);
- }
- if (!have_constructor && handled_as_init) {
- if (Getattr(n, "feature:shadow")) {
- String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
- String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname));
- Replaceall(pycode, "$action", pyaction);
- Delete(pyaction);
- Printv(f_shadow, pycode, "\n", NIL);
- Delete(pycode);
- } else {
- String *pass_self = NewString("");
- Node *parent = Swig_methodclass(n);
- String *classname = Swig_class_name(parent);
- String *rclassname = Swig_class_name(getCurrentClass());
- assert(rclassname);
+ if (!have_constructor && handled_as_init) {
+ if (Getattr(n, "feature:shadow")) {
+ String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
+ String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname));
+ Replaceall(pycode, "$action", pyaction);
+ Delete(pyaction);
+ Printv(f_shadow, pycode, "\n", NIL);
+ Delete(pycode);
+ } else {
+ String *pass_self = NewString("");
+ Node *parent = Swig_methodclass(n);
+ String *classname = Swig_class_name(parent);
+ String *rclassname = Swig_class_name(getCurrentClass());
+ assert(rclassname);
- String *parms = make_pyParmList(n, true, false, allow_kwargs);
- /* Pass 'self' only if using director */
- String *callParms = make_pyParmList(n, false, true, allow_kwargs);
+ String *parms = make_pyParmList(n, true, false, allow_kwargs);
+ /* Pass 'self' only if using director */
+ String *callParms = make_pyParmList(n, false, true, allow_kwargs);
- if (use_director) {
- Insert(callParms, 0, "_self, ");
- Printv(pass_self, tab8, NIL);
- Printf(pass_self, "if self.__class__ == %s:\n", classname);
- //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL);
- Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL);
- }
-
- Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL);
- if (have_docstring(n))
- Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL);
- if (have_pythonprepend(n))
- Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
- Printv(f_shadow, pass_self, NIL);
- if (fastinit) {
- Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL);
- } else {
- Printv(f_shadow,
- tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n",
- tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL);
- }
- if (have_pythonappend(n))
- Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL);
- Delete(pass_self);
- }
- have_constructor = 1;
- } else {
- /* Hmmm. We seem to be creating a different constructor. We're just going to create a
- function for it. */
-
- if (Getattr(n, "feature:shadow")) {
- String *pycode = pythoncode(Getattr(n, "feature:shadow"), "");
- String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname));
- Replaceall(pycode, "$action", pyaction);
- Delete(pyaction);
- Printv(f_shadow_stubs, pycode, "\n", NIL);
- Delete(pycode);
- } else {
- String *parms = make_pyParmList(n, false, false, allow_kwargs);
- String *callParms = make_pyParmList(n, false, true, allow_kwargs);
-
- Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL);
- if (have_docstring(n))
- Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL);
- if (have_pythonprepend(n))
- Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL);
- Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", NIL);
-#ifdef USE_THISOWN
- Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL);
-#endif
- if (have_pythonappend(n))
- Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL);
- Printv(f_shadow_stubs, tab4, "return val\n", NIL);
- }
- }
+ if (use_director) {
+ Insert(callParms, 0, "_self, ");
+ Printv(pass_self, tab8, NIL);
+ Printf(pass_self, "if self.__class__ == %s:\n", classname);
+ //Printv(pass_self, tab8, tab4, "args = (None,) + args\n", tab8, "else:\n", tab8, tab4, "args = (self,) + args\n", NIL);
+ Printv(pass_self, tab8, tab4, "_self = None\n", tab8, "else:\n", tab8, tab4, "_self = self\n", NIL);
}
+
+ Printv(f_shadow, tab4, "def __init__(", parms, ")", returnTypeAnnotation(n), ": \n", NIL);
+ if (have_docstring(n))
+ Printv(f_shadow, tab8, docstring(n, AUTODOC_CTOR, tab8), "\n", NIL);
+ if (have_pythonprepend(n))
+ Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
+ Printv(f_shadow, pass_self, NIL);
+ if (fastinit) {
+ Printv(f_shadow, tab8, module, ".", class_name, "_swiginit(self,", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), ")\n", NIL);
+ } else {
+ Printv(f_shadow,
+ tab8, "this = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n",
+ tab8, "try: self.this.append(this)\n", tab8, "except: self.this = this\n", NIL);
+ }
+ if (have_pythonappend(n))
+ Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n\n", NIL);
+ Delete(pass_self);
+ }
+ have_constructor = 1;
+ } else {
+ /* Hmmm. We seem to be creating a different constructor. We're just going to create a
+ function for it. */
+
+ if (Getattr(n, "feature:shadow")) {
+ String *pycode = pythoncode(Getattr(n, "feature:shadow"), "");
+ String *pyaction = NewStringf("%s.%s", module, Swig_name_construct(NSPACE_TODO, symname));
+ Replaceall(pycode, "$action", pyaction);
+ Delete(pyaction);
+ Printv(f_shadow_stubs, pycode, "\n", NIL);
+ Delete(pycode);
+ } else {
+ String *parms = make_pyParmList(n, false, false, allow_kwargs);
+ String *callParms = make_pyParmList(n, false, true, allow_kwargs);
+
+ Printv(f_shadow_stubs, "\ndef ", symname, "(", parms, ")", returnTypeAnnotation(n), ":\n", NIL);
+ if (have_docstring(n))
+ Printv(f_shadow_stubs, tab4, docstring(n, AUTODOC_CTOR, tab4), "\n", NIL);
+ if (have_pythonprepend(n))
+ Printv(f_shadow_stubs, pythoncode(pythonprepend(n), tab4), "\n", NIL);
+ Printv(f_shadow_stubs, tab4, "val = ", funcCall(Swig_name_construct(NSPACE_TODO, symname), callParms), "\n", NIL);
+#ifdef USE_THISOWN
+ Printv(f_shadow_stubs, tab4, "val.thisown = 1\n", NIL);
+#endif
+ if (have_pythonappend(n))
+ Printv(f_shadow_stubs, pythoncode(pythonappend(n), tab4), "\n", NIL);
+ Printv(f_shadow_stubs, tab4, "return val\n", NIL);
+ }
}
- return SWIG_OK;
+ }
}
+ return SWIG_OK;
+ }
/* ------------------------------------------------------------
* destructorHandler()
* ------------------------------------------------------------ */
- virtual int destructorHandler(Node *n) {
- if (builtin && in_class) {
- String *name = NewString("delete");
- if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) {
- Setattr(class_members, name, name);
- /*
- String *fullname = Swig_name_member(NULL, name, class_name);
- String *wname = Swig_name_wrapper(fullname);
- ParmList *parms = Getattr(n, "parms");
- char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS";
- Printf(f_shadow, " { \"__del__\", (PyCFunction) %s, %s, \"\" },\n", wname, Char(pyflags));
- Delete(fullname);
- Delete(wname);
- */
- }
- Delete(name);
- return SWIG_OK;
+ virtual int destructorHandler(Node *n) {
+ if (builtin && in_class) {
+ String *name = NewString("delete");
+ if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) {
+ Setattr(class_members, name, name);
+ /*
+ String *fullname = Swig_name_member(NULL, name, class_name);
+ String *wname = Swig_name_wrapper(fullname);
+ ParmList *parms = Getattr(n, "parms");
+ char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS";
+ Printf(f_shadow, " { \"__del__\", (PyCFunction) %s, %s, \"\" },\n", wname, Char(pyflags));
+ Delete(fullname);
+ Delete(wname);
+ */
+ }
+ Delete(name);
+ return SWIG_OK;
+ }
+
+ String *symname = Getattr(n, "sym:name");
+ int oldshadow = shadow;
+
+ if (shadow)
+ shadow = shadow | PYSHADOW_MEMBER;
+ //Setattr(n,"emit:dealloc","1");
+ Language::destructorHandler(n);
+ shadow = oldshadow;
+
+ if (shadow) {
+ if (Getattr(n, "feature:shadow")) {
+ String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
+ String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(NSPACE_TODO, symname));
+ Replaceall(pycode, "$action", pyaction);
+ Delete(pyaction);
+ Printv(f_shadow, pycode, "\n", NIL);
+ Delete(pycode);
+ } else {
+ Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL);
+ if (!have_pythonprepend(n) && !have_pythonappend(n)) {
+ if (proxydel) {
+ Printv(f_shadow, tab4, "__del__ = lambda self : None;\n", NIL);
+ }
+ return SWIG_OK;
}
-
- String *symname = Getattr(n, "sym:name");
- int oldshadow = shadow;
-
- if (shadow)
- shadow = shadow | PYSHADOW_MEMBER;
- //Setattr(n,"emit:dealloc","1");
- Language::destructorHandler(n);
- shadow = oldshadow;
-
- if (shadow) {
- if (Getattr(n, "feature:shadow")) {
- String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
- String *pyaction = NewStringf("%s.%s", module, Swig_name_destroy(NSPACE_TODO, symname));
- Replaceall(pycode, "$action", pyaction);
- Delete(pyaction);
- Printv(f_shadow, pycode, "\n", NIL);
- Delete(pycode);
- } else {
- Printv(f_shadow, tab4, "__swig_destroy__ = ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "\n", NIL);
- if (!have_pythonprepend(n) && !have_pythonappend(n)) {
- if (proxydel) {
- Printv(f_shadow, tab4, "__del__ = lambda self : None;\n", NIL);
- }
- return SWIG_OK;
- }
- Printv(f_shadow, tab4, "def __del__(self):\n", NIL);
- if (have_docstring(n))
- Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL);
- if (have_pythonprepend(n))
- Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
+ Printv(f_shadow, tab4, "def __del__(self):\n", NIL);
+ if (have_docstring(n))
+ Printv(f_shadow, tab8, docstring(n, AUTODOC_DTOR, tab8), "\n", NIL);
+ if (have_pythonprepend(n))
+ Printv(f_shadow, pythoncode(pythonprepend(n), tab8), "\n", NIL);
#ifdef USE_THISOWN
- Printv(f_shadow, tab8, "try:\n", NIL);
- Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL);
- Printv(f_shadow, tab8, "except: pass\n", NIL);
+ Printv(f_shadow, tab8, "try:\n", NIL);
+ Printv(f_shadow, tab8, tab4, "if self.thisown: ", module, ".", Swig_name_destroy(NSPACE_TODO, symname), "(self)\n", NIL);
+ Printv(f_shadow, tab8, "except: pass\n", NIL);
#else
#endif
- if (have_pythonappend(n))
- Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
- Printv(f_shadow, tab8, "pass\n", NIL);
- Printv(f_shadow, "\n", NIL);
- }
- }
- return SWIG_OK;
+ if (have_pythonappend(n))
+ Printv(f_shadow, pythoncode(pythonappend(n), tab8), "\n", NIL);
+ Printv(f_shadow, tab8, "pass\n", NIL);
+ Printv(f_shadow, "\n", NIL);
+ }
}
+ return SWIG_OK;
+ }
- /* ------------------------------------------------------------
- * membervariableHandler()
- * ------------------------------------------------------------ */
+ /* ------------------------------------------------------------
+ * membervariableHandler()
+ * ------------------------------------------------------------ */
- virtual int membervariableHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
+ virtual int membervariableHandler(Node *n) {
+ String *symname = Getattr(n, "sym:name");
- int oldshadow = shadow;
- if (shadow)
- shadow = shadow | PYSHADOW_MEMBER;
- Language::membervariableHandler(n);
- shadow = oldshadow;
+ int oldshadow = shadow;
+ if (shadow)
+ shadow = shadow | PYSHADOW_MEMBER;
+ Language::membervariableHandler(n);
+ shadow = oldshadow;
- if (builtin && in_class) {
- } else if (shadow) {
- String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
- String *setname = Swig_name_set(NSPACE_TODO, mname);
- String *getname = Swig_name_get(NSPACE_TODO, mname);
- int assignable = is_assignable(n);
- if (!modern) {
- if (assignable) {
- Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
- }
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
- }
- if (!classic) {
- if (!assignable) {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
- } else {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
- }
- }
- Delete(mname);
- Delete(setname);
- Delete(getname);
+ if (shadow && !builtin) {
+ String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
+ String *setname = Swig_name_set(NSPACE_TODO, mname);
+ String *getname = Swig_name_get(NSPACE_TODO, mname);
+ int assignable = is_assignable(n);
+ if (!modern) {
+ if (assignable) {
+ Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
}
-
- return SWIG_OK;
- }
-
- /* ------------------------------------------------------------
- * staticmembervariableHandler()
- * ------------------------------------------------------------ */
-
- virtual int staticmembervariableHandler(Node *n) {
- Swig_save("builtin_staticmembervariableHandler", n, "builtin_symname", NIL);
- Language::staticmembervariableHandler(n);
- Swig_restore(n);
-
- if (GetFlag(n, "wrappedasconstant"))
- return SWIG_OK;
-
- String *symname = Getattr(n, "sym:name");
-
- if (shadow) {
- if (GetFlag(n, "hasconsttype")) {
- String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
- Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname);
- Delete(mname);
- } else {
- String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
- String *getname = Swig_name_get(NSPACE_TODO, mname);
- String *wrapgetname = Swig_name_wrapper(getname);
- String *vargetname = NewStringf("Swig_var_%s", getname);
- String *setname = Swig_name_set(NSPACE_TODO, mname);
- String *wrapsetname = Swig_name_wrapper(setname);
- String *varsetname = NewStringf("Swig_var_%s", setname);
-
- Wrapper *f = NewWrapper();
- Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL);
- Printv(f->code, " return ", vargetname, "();\n", NIL);
- Append(f->code, "}\n");
- add_method(getname, wrapgetname, 0);
- Wrapper_print(f, f_wrappers);
- DelWrapper(f);
- int assignable = is_assignable(n);
- if (assignable) {
- Wrapper *f = NewWrapper();
- Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL);
- Wrapper_add_local(f, "value", "PyObject *value");
- Wrapper_add_local(f, "res", "int res");
- Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n");
- Printv(f->code, "res = ", varsetname, "(value);\n", NIL);
- Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n");
- Append(f->code, "}\n");
- Wrapper_print(f, f_wrappers);
- add_method(setname, wrapsetname, 0);
- DelWrapper(f);
- }
- if (!modern) {
- if (assignable) {
- Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
- }
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
- }
- if (!classic) {
- if (!assignable) {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
- } else {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
- }
- }
- Delete(mname);
- Delete(getname);
- Delete(wrapgetname);
- Delete(vargetname);
- Delete(setname);
- Delete(wrapsetname);
- Delete(varsetname);
- }
- }
- return SWIG_OK;
- }
-
- /* ------------------------------------------------------------
- * memberconstantHandler()
- * ------------------------------------------------------------ */
-
- virtual int memberconstantHandler(Node *n) {
- String *symname = Getattr(n, "sym:name");
- if (builtin && in_class) {
- Swig_save("builtin_memberconstantHandler", n, "builtin_sym:name", NIL);
- Setattr(n, "builtin_sym:name", symname);
- }
- int oldshadow = shadow;
- if (shadow)
- shadow = shadow | PYSHADOW_MEMBER;
- Language::memberconstantHandler(n);
- shadow = oldshadow;
-
- if (builtin && in_class) {
- Swig_restore(n);
- } else if (shadow) {
- Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
- }
- return SWIG_OK;
- }
-
- /* ------------------------------------------------------------
- * insertDirective()
- *
- * Hook for %insert directive. We're going to look for special %shadow inserts
- * as a special case so we can do indenting correctly
- * ------------------------------------------------------------ */
-
- virtual int insertDirective(Node *n) {
- String *code = Getattr(n, "code");
- String *section = Getattr(n, "section");
-
- if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) {
- if (shadow) {
- String *pycode = pythoncode(code, shadow_indent);
- Printv(f_shadow, pycode, NIL);
- Delete(pycode);
- }
+ Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
+ }
+ if (!classic) {
+ if (!assignable) {
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
} else {
- Language::insertDirective(n);
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
}
- return SWIG_OK;
+ }
+ Delete(mname);
+ Delete(setname);
+ Delete(getname);
}
- virtual String *runtimeCode() {
- String *s = NewString("");
- String *shead = Swig_include_sys("pyhead.swg");
- if (!shead) {
- Printf(stderr, "*** Unable to open 'pyhead.swg'\n");
- } else {
- Append(s, shead);
- Delete(shead);
- }
- String *serrors = Swig_include_sys("pyerrors.swg");
- if (!serrors) {
- Printf(stderr, "*** Unable to open 'pyerrors.swg'\n");
- } else {
- Append(s, serrors);
- Delete(serrors);
- }
- String *sthread = Swig_include_sys("pythreads.swg");
- if (!sthread) {
- Printf(stderr, "*** Unable to open 'pythreads.swg'\n");
- } else {
- Append(s, sthread);
- Delete(sthread);
- }
- String *sapi = Swig_include_sys("pyapi.swg");
- if (!sapi) {
- Printf(stderr, "*** Unable to open 'pyapi.swg'\n");
- } else {
- Append(s, sapi);
- Delete(sapi);
- }
- String *srun = Swig_include_sys("pyrun.swg");
- if (!srun) {
- Printf(stderr, "*** Unable to open 'pyrun.swg'\n");
- } else {
- Append(s, srun);
- Delete(srun);
- }
- return s;
- }
+ return SWIG_OK;
+ }
- virtual String *defaultExternalRuntimeFilename() {
- return NewString("swigpyrun.h");
+ /* ------------------------------------------------------------
+ * staticmembervariableHandler()
+ * ------------------------------------------------------------ */
+
+ virtual int staticmembervariableHandler(Node *n) {
+ Swig_save("builtin_staticmembervariableHandler", n, "builtin_symname", NIL);
+ Language::staticmembervariableHandler(n);
+ Swig_restore(n);
+
+ if (GetFlag(n, "wrappedasconstant"))
+ return SWIG_OK;
+
+ String *symname = Getattr(n, "sym:name");
+
+ if (shadow) {
+ if (GetFlag(n, "hasconsttype")) {
+ String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
+ Printf(f_shadow_stubs, "%s.%s = %s.%s.%s\n", class_name, symname, module, global_name, mname);
+ Delete(mname);
+ } else {
+ String *mname = Swig_name_member(NSPACE_TODO, class_name, symname);
+ String *getname = Swig_name_get(NSPACE_TODO, mname);
+ String *wrapgetname = Swig_name_wrapper(getname);
+ String *vargetname = NewStringf("Swig_var_%s", getname);
+ String *setname = Swig_name_set(NSPACE_TODO, mname);
+ String *wrapsetname = Swig_name_wrapper(setname);
+ String *varsetname = NewStringf("Swig_var_%s", setname);
+
+ Wrapper *f = NewWrapper();
+ Printv(f->def, "SWIGINTERN PyObject *", wrapgetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL);
+ Printv(f->code, " return ", vargetname, "();\n", NIL);
+ Append(f->code, "}\n");
+ add_method(getname, wrapgetname, 0);
+ Wrapper_print(f, f_wrappers);
+ DelWrapper(f);
+ int assignable = is_assignable(n);
+ if (assignable) {
+ Wrapper *f = NewWrapper();
+ Printv(f->def, "SWIGINTERN PyObject *", wrapsetname, "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL);
+ Wrapper_add_local(f, "value", "PyObject *value");
+ Wrapper_add_local(f, "res", "int res");
+ Append(f->code, "if (!PyArg_ParseTuple(args,(char *)\"O:set\",&value)) return NULL;\n");
+ Printv(f->code, "res = ", varsetname, "(value);\n", NIL);
+ Append(f->code, "return !res ? SWIG_Py_Void() : NULL;\n");
+ Append(f->code, "}\n");
+ Wrapper_print(f, f_wrappers);
+ add_method(setname, wrapsetname, 0);
+ DelWrapper(f);
+ }
+ if (!modern) {
+ if (assignable) {
+ Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
+ }
+ Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
+ }
+ if (!classic) {
+ if (!assignable) {
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
+ } else {
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
+ }
+ }
+ Delete(mname);
+ Delete(getname);
+ Delete(wrapgetname);
+ Delete(vargetname);
+ Delete(setname);
+ Delete(wrapsetname);
+ Delete(varsetname);
+ }
}
+ return SWIG_OK;
+ }
+
+ /* ------------------------------------------------------------
+ * memberconstantHandler()
+ * ------------------------------------------------------------ */
+
+ virtual int memberconstantHandler(Node *n) {
+ String *symname = Getattr(n, "sym:name");
+ if (builtin && in_class) {
+ Swig_save("builtin_memberconstantHandler", n, "builtin_sym:name", NIL);
+ Setattr(n, "builtin_sym:name", symname);
+ }
+ int oldshadow = shadow;
+ if (shadow)
+ shadow = shadow | PYSHADOW_MEMBER;
+ Language::memberconstantHandler(n);
+ shadow = oldshadow;
+
+ if (builtin && in_class) {
+ Swig_restore(n);
+ } else if (shadow) {
+ Printv(f_shadow, tab4, symname, " = ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
+ }
+ return SWIG_OK;
+ }
+
+ /* ------------------------------------------------------------
+ * insertDirective()
+ *
+ * Hook for %insert directive. We're going to look for special %shadow inserts
+ * as a special case so we can do indenting correctly
+ * ------------------------------------------------------------ */
+
+ virtual int insertDirective(Node *n) {
+ String *code = Getattr(n, "code");
+ String *section = Getattr(n, "section");
+
+ if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) {
+ if (shadow) {
+ String *pycode = pythoncode(code, shadow_indent);
+ Printv(f_shadow, pycode, NIL);
+ Delete(pycode);
+ }
+ } else {
+ Language::insertDirective(n);
+ }
+ return SWIG_OK;
+ }
+
+ virtual String *runtimeCode() {
+ String *s = NewString("");
+ String *shead = Swig_include_sys("pyhead.swg");
+ if (!shead) {
+ Printf(stderr, "*** Unable to open 'pyhead.swg'\n");
+ } else {
+ Append(s, shead);
+ Delete(shead);
+ }
+ String *serrors = Swig_include_sys("pyerrors.swg");
+ if (!serrors) {
+ Printf(stderr, "*** Unable to open 'pyerrors.swg'\n");
+ } else {
+ Append(s, serrors);
+ Delete(serrors);
+ }
+ String *sthread = Swig_include_sys("pythreads.swg");
+ if (!sthread) {
+ Printf(stderr, "*** Unable to open 'pythreads.swg'\n");
+ } else {
+ Append(s, sthread);
+ Delete(sthread);
+ }
+ String *sapi = Swig_include_sys("pyapi.swg");
+ if (!sapi) {
+ Printf(stderr, "*** Unable to open 'pyapi.swg'\n");
+ } else {
+ Append(s, sapi);
+ Delete(sapi);
+ }
+ String *srun = Swig_include_sys("pyrun.swg");
+ if (!srun) {
+ Printf(stderr, "*** Unable to open 'pyrun.swg'\n");
+ } else {
+ Append(s, srun);
+ Delete(srun);
+ }
+ return s;
+ }
+
+ virtual String *defaultExternalRuntimeFilename() {
+ return NewString("swigpyrun.h");
+ }
};
@@ -3964,489 +4081,489 @@ public:
* ** Moved it here due to internal error on gcc-2.96 **
* --------------------------------------------------------------- */
int PYTHON::classDirectorMethods(Node *n) {
- director_method_index = 0;
- return Language::classDirectorMethods(n);
+ director_method_index = 0;
+ return Language::classDirectorMethods(n);
}
int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
- int is_void = 0;
- int is_pointer = 0;
- String *decl;
- String *type;
- String *name;
- String *classname;
- String *c_classname = Getattr(parent, "name");
- String *declaration;
- ParmList *l;
- Wrapper *w;
- String *tm;
- String *wrap_args = NewString("");
- String *return_type;
- String *value = Getattr(n, "value");
- String *storage = Getattr(n, "storage");
- bool pure_virtual = false;
- int status = SWIG_OK;
- int idx;
- bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
+ int is_void = 0;
+ int is_pointer = 0;
+ String *decl;
+ String *type;
+ String *name;
+ String *classname;
+ String *c_classname = Getattr(parent, "name");
+ String *declaration;
+ ParmList *l;
+ Wrapper *w;
+ String *tm;
+ String *wrap_args = NewString("");
+ String *return_type;
+ String *value = Getattr(n, "value");
+ String *storage = Getattr(n, "storage");
+ bool pure_virtual = false;
+ int status = SWIG_OK;
+ int idx;
+ bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
- if (Cmp(storage, "virtual") == 0) {
- if (Cmp(value, "0") == 0) {
- pure_virtual = true;
+ if (Cmp(storage, "virtual") == 0) {
+ if (Cmp(value, "0") == 0) {
+ pure_virtual = true;
+ }
}
- }
- classname = Getattr(parent, "sym:name");
- type = Getattr(n, "type");
- name = Getattr(n, "name");
+ classname = Getattr(parent, "sym:name");
+ type = Getattr(n, "type");
+ name = Getattr(n, "name");
- w = NewWrapper();
- declaration = NewString("");
+ w = NewWrapper();
+ declaration = NewString("");
- /* determine if the method returns a pointer */
- decl = Getattr(n, "decl");
- is_pointer = SwigType_ispointer_return(decl);
- is_void = (!Cmp(type, "void") && !is_pointer);
+ /* determine if the method returns a pointer */
+ decl = Getattr(n, "decl");
+ is_pointer = SwigType_ispointer_return(decl);
+ is_void = (!Cmp(type, "void") && !is_pointer);
- /* form complete return type */
- return_type = Copy(type);
- {
- SwigType *t = Copy(decl);
- SwigType *f = 0;
- f = SwigType_pop_function(t);
- SwigType_push(return_type, t);
- Delete(f);
- Delete(t);
- }
+ /* form complete return type */
+ return_type = Copy(type);
+ {
+ SwigType *t = Copy(decl);
+ SwigType *f = 0;
+ f = SwigType_pop_function(t);
+ SwigType_push(return_type, t);
+ Delete(f);
+ Delete(t);
+ }
- /* virtual method definition */
- l = Getattr(n, "parms");
- String *target;
- String *pclassname = NewStringf("SwigDirector_%s", classname);
- String *qualified_name = NewStringf("%s::%s", pclassname, name);
- SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
- target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
- Printf(w->def, "%s", target);
- Delete(qualified_name);
- Delete(target);
- /* header declaration */
- target = Swig_method_decl(rtype, decl, name, l, 0, 1);
- Printf(declaration, " virtual %s", target);
- Delete(target);
+ /* virtual method definition */
+ l = Getattr(n, "parms");
+ String *target;
+ String *pclassname = NewStringf("SwigDirector_%s", classname);
+ String *qualified_name = NewStringf("%s::%s", pclassname, name);
+ SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
+ target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
+ Printf(w->def, "%s", target);
+ Delete(qualified_name);
+ Delete(target);
+ /* header declaration */
+ target = Swig_method_decl(rtype, decl, name, l, 0, 1);
+ Printf(declaration, " virtual %s", target);
+ Delete(target);
- // Get any exception classes in the throws typemap
- ParmList *throw_parm_list = 0;
+ // Get any exception classes in the throws typemap
+ ParmList *throw_parm_list = 0;
- if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
- Parm *p;
- int gencomma = 0;
+ if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
+ Parm *p;
+ int gencomma = 0;
- Append(w->def, " throw(");
- Append(declaration, " throw(");
+ Append(w->def, " throw(");
+ Append(declaration, " throw(");
- if (throw_parm_list)
- Swig_typemap_attach_parms("throws", throw_parm_list, 0);
- for (p = throw_parm_list; p; p = nextSibling(p)) {
- if ((tm = Getattr(p, "tmap:throws"))) {
- if (gencomma++) {
- Append(w->def, ", ");
- Append(declaration, ", ");
+ if (throw_parm_list)
+ Swig_typemap_attach_parms("throws", throw_parm_list, 0);
+ for (p = throw_parm_list; p; p = nextSibling(p)) {
+ if ((tm = Getattr(p, "tmap:throws"))) {
+ if (gencomma++) {
+ Append(w->def, ", ");
+ Append(declaration, ", ");
+ }
+ String *str = SwigType_str(Getattr(p, "type"), 0);
+ Append(w->def, str);
+ Append(declaration, str);
+ Delete(str);
}
- String *str = SwigType_str(Getattr(p, "type"), 0);
- Append(w->def, str);
- Append(declaration, str);
- Delete(str);
+ }
+
+ Append(w->def, ")");
+ Append(declaration, ")");
+ }
+
+ Append(w->def, " {");
+ Append(declaration, ";\n");
+
+ /* declare method return value
+ * if the return value is a reference or const reference, a specialized typemap must
+ * handle it, including declaration of c_result ($result).
+ */
+ if (!is_void) {
+ if (!(ignored_method && !pure_virtual)) {
+ String *cres = SwigType_lstr(return_type, "c_result");
+ Printf(w->code, "%s;\n", cres);
+ Delete(cres);
}
}
- Append(w->def, ")");
- Append(declaration, ")");
- }
-
- Append(w->def, " {");
- Append(declaration, ";\n");
-
- /* declare method return value
- * if the return value is a reference or const reference, a specialized typemap must
- * handle it, including declaration of c_result ($result).
- */
- if (!is_void) {
- if (!(ignored_method && !pure_virtual)) {
- String *cres = SwigType_lstr(return_type, "c_result");
- Printf(w->code, "%s;\n", cres);
- Delete(cres);
- }
- }
-
- if (ignored_method) {
- if (!pure_virtual) {
- if (!is_void)
- Printf(w->code, "return ");
- String *super_call = Swig_method_call(super, l);
- Printf(w->code, "%s;\n", super_call);
- Delete(super_call);
+ if (ignored_method) {
+ if (!pure_virtual) {
+ if (!is_void)
+ Printf(w->code, "return ");
+ String *super_call = Swig_method_call(super, l);
+ Printf(w->code, "%s;\n", super_call);
+ Delete(super_call);
+ } else {
+ Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
+ SwigType_namestr(name));
+ }
} else {
- Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
- SwigType_namestr(name));
- }
- } else {
- /* attach typemaps to arguments (C/C++ -> Python) */
- String *arglist = NewString("");
- String *parse_args = NewString("");
+ /* attach typemaps to arguments (C/C++ -> Python) */
+ String *arglist = NewString("");
+ String *parse_args = NewString("");
- /* remove the wrapper 'w' since it was producing spurious temps */
- Swig_typemap_attach_parms("in", l, 0);
- Swig_typemap_attach_parms("directorin", l, 0);
- Swig_typemap_attach_parms("directorargout", l, w);
+ /* remove the wrapper 'w' since it was producing spurious temps */
+ Swig_typemap_attach_parms("in", l, 0);
+ Swig_typemap_attach_parms("directorin", l, 0);
+ Swig_typemap_attach_parms("directorargout", l, w);
- Parm *p;
- char source[256];
+ Parm *p;
+ char source[256];
- int outputs = 0;
- if (!is_void)
- outputs++;
-
- /* build argument list and type conversion string */
- idx = 0;
- p = l;
- int use_parse = 0;
- while (p) {
- if (checkAttribute(p, "tmap:in:numinputs", "0")) {
- p = Getattr(p, "tmap:in:next");
- continue;
- }
-
- /* old style? caused segfaults without the p!=0 check
- in the for() condition, and seems dangerous in the
- while loop as well.
- while (Getattr(p, "tmap:ignore")) {
- p = Getattr(p, "tmap:ignore:next");
- }
- */
-
- if (Getattr(p, "tmap:directorargout") != 0)
+ int outputs = 0;
+ if (!is_void)
outputs++;
- String *pname = Getattr(p, "name");
- String *ptype = Getattr(p, "type");
-
- Putc(',', arglist);
- if ((tm = Getattr(p, "tmap:directorin")) != 0) {
- String *parse = Getattr(p, "tmap:directorin:parse");
- if (!parse) {
- sprintf(source, "obj%d", idx++);
- String *input = NewString(source);
- Replaceall(tm, "$input", input);
- Delete(input);
- Replaceall(tm, "$owner", "0");
- /* Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); */
- Printv(wrap_args, "swig::SwigVar_PyObject ", source, ";\n", NIL);
-
- Printv(wrap_args, tm, "\n", NIL);
- Printv(arglist, "(PyObject *)", source, NIL);
- Putc('O', parse_args);
- } else {
- use_parse = 1;
- Append(parse_args, parse);
- Replaceall(tm, "$input", pname);
- Replaceall(tm, "$owner", "0");
- if (Len(tm) == 0)
- Append(tm, pname);
- Append(arglist, tm);
+ /* build argument list and type conversion string */
+ idx = 0;
+ p = l;
+ int use_parse = 0;
+ while (p) {
+ if (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ p = Getattr(p, "tmap:in:next");
+ continue;
}
- p = Getattr(p, "tmap:directorin:next");
- continue;
- } else if (Cmp(ptype, "void")) {
- /* special handling for pointers to other C++ director classes.
- * ideally this would be left to a typemap, but there is currently no
- * way to selectively apply the dynamic_cast<> to classes that have
- * directors. in other words, the type "SwigDirector_$1_lname" only exists
- * for classes with directors. we avoid the problem here by checking
- * module.wrap::directormap, but it's not clear how to get a typemap to
- * do something similar. perhaps a new default typemap (in addition
- * to SWIGTYPE) called DIRECTORTYPE?
- */
- if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) {
- Node *module = Getattr(parent, "module");
- Node *target = Swig_directormap(module, ptype);
- sprintf(source, "obj%d", idx++);
- String *nonconst = 0;
- /* strip pointer/reference --- should move to Swig/stype.c */
- String *nptype = NewString(Char(ptype) + 2);
- /* name as pointer */
- String *ppname = Copy(pname);
- if (SwigType_isreference(ptype)) {
- Insert(ppname, 0, "&");
- }
- /* if necessary, cast away const since Python doesn't support it! */
- if (SwigType_isconst(nptype)) {
- nonconst = NewStringf("nc_tmp_%s", pname);
- String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
- Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
- Delete(nonconst_i);
- Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
- "Target language argument '%s' discards const in director method %s::%s.\n",
- SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name));
+
+ /* old style? caused segfaults without the p!=0 check
+ in the for() condition, and seems dangerous in the
+ while loop as well.
+ while (Getattr(p, "tmap:ignore")) {
+ p = Getattr(p, "tmap:ignore:next");
+ }
+ */
+
+ if (Getattr(p, "tmap:directorargout") != 0)
+ outputs++;
+
+ String *pname = Getattr(p, "name");
+ String *ptype = Getattr(p, "type");
+
+ Putc(',', arglist);
+ if ((tm = Getattr(p, "tmap:directorin")) != 0) {
+ String *parse = Getattr(p, "tmap:directorin:parse");
+ if (!parse) {
+ sprintf(source, "obj%d", idx++);
+ String *input = NewString(source);
+ Replaceall(tm, "$input", input);
+ Delete(input);
+ Replaceall(tm, "$owner", "0");
+ /* Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); */
+ Printv(wrap_args, "swig::SwigVar_PyObject ", source, ";\n", NIL);
+
+ Printv(wrap_args, tm, "\n", NIL);
+ Printv(arglist, "(PyObject *)", source, NIL);
+ Putc('O', parse_args);
} else {
- nonconst = Copy(ppname);
+ use_parse = 1;
+ Append(parse_args, parse);
+ Replaceall(tm, "$input", pname);
+ Replaceall(tm, "$owner", "0");
+ if (Len(tm) == 0)
+ Append(tm, pname);
+ Append(arglist, tm);
}
- Delete(nptype);
- Delete(ppname);
- String *mangle = SwigType_manglestr(ptype);
- if (target) {
- String *director = NewStringf("director_%s", mangle);
- Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
- Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL);
- Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
- Printf(wrap_args, "if (!%s) {\n", director);
- Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
- Append(wrap_args, "} else {\n");
- Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
- Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source);
- Append(wrap_args, "}\n");
- Delete(director);
- Printv(arglist, source, NIL);
+ p = Getattr(p, "tmap:directorin:next");
+ continue;
+ } else if (Cmp(ptype, "void")) {
+ /* special handling for pointers to other C++ director classes.
+ * ideally this would be left to a typemap, but there is currently no
+ * way to selectively apply the dynamic_cast<> to classes that have
+ * directors. in other words, the type "SwigDirector_$1_lname" only exists
+ * for classes with directors. we avoid the problem here by checking
+ * module.wrap::directormap, but it's not clear how to get a typemap to
+ * do something similar. perhaps a new default typemap (in addition
+ * to SWIGTYPE) called DIRECTORTYPE?
+ */
+ if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) {
+ Node *module = Getattr(parent, "module");
+ Node *target = Swig_directormap(module, ptype);
+ sprintf(source, "obj%d", idx++);
+ String *nonconst = 0;
+ /* strip pointer/reference --- should move to Swig/stype.c */
+ String *nptype = NewString(Char(ptype) + 2);
+ /* name as pointer */
+ String *ppname = Copy(pname);
+ if (SwigType_isreference(ptype)) {
+ Insert(ppname, 0, "&");
+ }
+ /* if necessary, cast away const since Python doesn't support it! */
+ if (SwigType_isconst(nptype)) {
+ nonconst = NewStringf("nc_tmp_%s", pname);
+ String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
+ Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
+ Delete(nonconst_i);
+ Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
+ "Target language argument '%s' discards const in director method %s::%s.\n",
+ SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name));
+ } else {
+ nonconst = Copy(ppname);
+ }
+ Delete(nptype);
+ Delete(ppname);
+ String *mangle = SwigType_manglestr(ptype);
+ if (target) {
+ String *director = NewStringf("director_%s", mangle);
+ Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
+ Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL);
+ Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
+ Printf(wrap_args, "if (!%s) {\n", director);
+ Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
+ Append(wrap_args, "} else {\n");
+ Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
+ Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source);
+ Append(wrap_args, "}\n");
+ Delete(director);
+ Printv(arglist, source, NIL);
+ } else {
+ Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL);
+ Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
+ //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n",
+ // source, nonconst, base);
+ Printv(arglist, source, NIL);
+ }
+ Putc('O', parse_args);
+ Delete(mangle);
+ Delete(nonconst);
} else {
- Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL);
- Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
- //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n",
- // source, nonconst, base);
- Printv(arglist, source, NIL);
+ Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
+ "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0),
+ SwigType_namestr(c_classname), SwigType_namestr(name));
+ status = SWIG_NOWRAP;
+ break;
}
- Putc('O', parse_args);
- Delete(mangle);
- Delete(nonconst);
- } else {
- Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
- "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0),
- SwigType_namestr(c_classname), SwigType_namestr(name));
- status = SWIG_NOWRAP;
- break;
}
- }
- p = nextSibling(p);
- }
-
- /* add the method name as a PyString */
- String *pyname = Getattr(n, "sym:name");
-
- int allow_thread = threads_enable(n);
-
- if (allow_thread) {
- thread_begin_block(n, w->code);
- Append(w->code, "{\n");
- }
-
- /* wrap complex arguments to PyObjects */
- Printv(w->code, wrap_args, NIL);
-
- /* pass the method call on to the Python object */
- if (dirprot_mode() && !is_public(n)) {
- Printf(w->code, "swig_set_inner(\"%s\", true);\n", name);
- }
-
-
- Append(w->code, "if (!swig_get_self()) {\n");
- Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname);
- Append(w->code, "}\n");
- Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n");
- Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++);
- Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname);
-
- Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n");
- if (Len(parse_args) > 0) {
- if (use_parse || !modernargs) {
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist);
- } else {
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist);
- }
- } else {
- if (modernargs) {
- Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n");
- Append(w->code, "swig::SwigVar_PyObject result = PyObject_Call(method, (PyObject*) args, NULL);\n");
- } else {
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, NULL, NULL);\n");
- }
- }
- Append(w->code, "#else\n");
- if (Len(parse_args) > 0) {
- if (use_parse || !modernargs) {
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n",
- pyname, parse_args, arglist);
- } else {
- Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", arglist);
- }
- } else {
- if (!modernargs) {
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname);
- } else {
- Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
- Append(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n");
- }
- }
- Append(w->code, "#endif\n");
-
- if (dirprot_mode() && !is_public(n))
- Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
-
- /* exception handling */
- tm = Swig_typemap_lookup("director:except", n, "result", 0);
- if (!tm) {
- tm = Getattr(n, "feature:director:except");
- if (tm)
- tm = Copy(tm);
- }
- Append(w->code, "if (!result) {\n");
- Append(w->code, " PyObject *error = PyErr_Occurred();\n");
- if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
- Replaceall(tm, "$error", "error");
- Printv(w->code, Str(tm), "\n", NIL);
- } else {
- Append(w->code, " if (error) {\n");
- Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname);
- Append(w->code, " }\n");
- }
- Append(w->code, "}\n");
- Delete(tm);
-
- /*
- * Python method may return a simple object, or a tuple.
- * for in/out aruments, we have to extract the appropriate PyObjects from the tuple,
- * then marshal everything back to C/C++ (return value and output arguments).
- *
- */
-
- /* marshal return value and other outputs (if any) from PyObject to C/C++ type */
-
- String *cleanup = NewString("");
- String *outarg = NewString("");
-
- if (outputs > 1) {
- Wrapper_add_local(w, "output", "PyObject *output");
- Append(w->code, "if (!PyTuple_Check(result)) {\n");
- Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname);
- Append(w->code, "}\n");
- }
-
- idx = 0;
-
- /* marshal return value */
- if (!is_void) {
- /* this seems really silly. the node's type excludes
- * qualifier/pointer/reference markers, which have to be retrieved
- * from the decl field to construct return_type. but the typemap
- * lookup routine uses the node's type, so we have to swap in and
- * out the correct type. it's not just me, similar silliness also
- * occurs in Language::cDeclaration().
- */
- Setattr(n, "type", return_type);
- tm = Swig_typemap_lookup("directorout", n, "result", w);
- Setattr(n, "type", type);
- if (tm != 0) {
- if (outputs > 1) {
- Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);
- Replaceall(tm, "$input", "output");
- } else {
- Replaceall(tm, "$input", "result");
- }
- char temp[24];
- sprintf(temp, "%d", idx);
- Replaceall(tm, "$argnum", temp);
-
- /* TODO check this */
- if (Getattr(n, "wrap:disown")) {
- Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
- } else {
- Replaceall(tm, "$disown", "0");
- }
- if (Getattr(n, "tmap:directorout:implicitconv")) {
- Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
- }
- Replaceall(tm, "$result", "c_result");
- Printv(w->code, tm, "\n", NIL);
- Delete(tm);
- } else {
- Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
- "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname),
- SwigType_namestr(name));
- status = SWIG_ERROR;
- }
- }
-
- /* marshal outputs */
- for (p = l; p;) {
- if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
- if (outputs > 1) {
- Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);
- Replaceall(tm, "$input", "output");
- } else {
- Replaceall(tm, "$input", "result");
- }
- Replaceall(tm, "$result", Getattr(p, "name"));
- Printv(w->code, tm, "\n", NIL);
- p = Getattr(p, "tmap:directorargout:next");
- } else {
p = nextSibling(p);
}
- }
- /* any existing helper functions to handle this? */
- if (allow_thread) {
- Append(w->code, "}\n");
- thread_end_block(n, w->code);
- }
+ /* add the method name as a PyString */
+ String *pyname = Getattr(n, "sym:name");
- Delete(parse_args);
- Delete(arglist);
- Delete(cleanup);
- Delete(outarg);
- }
+ int allow_thread = threads_enable(n);
- if (!is_void) {
- if (!(ignored_method && !pure_virtual)) {
- String *rettype = SwigType_str(return_type, 0);
- if (!SwigType_isreference(return_type)) {
- Printf(w->code, "return (%s) c_result;\n", rettype);
- } else {
- Printf(w->code, "return (%s) *c_result;\n", rettype);
+ if (allow_thread) {
+ thread_begin_block(n, w->code);
+ Append(w->code, "{\n");
}
- Delete(rettype);
+
+ /* wrap complex arguments to PyObjects */
+ Printv(w->code, wrap_args, NIL);
+
+ /* pass the method call on to the Python object */
+ if (dirprot_mode() && !is_public(n)) {
+ Printf(w->code, "swig_set_inner(\"%s\", true);\n", name);
+ }
+
+
+ Append(w->code, "if (!swig_get_self()) {\n");
+ Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname);
+ Append(w->code, "}\n");
+ Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n");
+ Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++);
+ Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname);
+
+ Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n");
+ if (Len(parse_args) > 0) {
+ if (use_parse || !modernargs) {
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist);
+ } else {
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist);
+ }
+ } else {
+ if (modernargs) {
+ Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n");
+ Append(w->code, "swig::SwigVar_PyObject result = PyObject_Call(method, (PyObject*) args, NULL);\n");
+ } else {
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, NULL, NULL);\n");
+ }
+ }
+ Append(w->code, "#else\n");
+ if (Len(parse_args) > 0) {
+ if (use_parse || !modernargs) {
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n",
+ pyname, parse_args, arglist);
+ } else {
+ Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", arglist);
+ }
+ } else {
+ if (!modernargs) {
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname);
+ } else {
+ Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
+ Append(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n");
+ }
+ }
+ Append(w->code, "#endif\n");
+
+ if (dirprot_mode() && !is_public(n))
+ Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
+
+ /* exception handling */
+ tm = Swig_typemap_lookup("director:except", n, "result", 0);
+ if (!tm) {
+ tm = Getattr(n, "feature:director:except");
+ if (tm)
+ tm = Copy(tm);
+ }
+ Append(w->code, "if (!result) {\n");
+ Append(w->code, " PyObject *error = PyErr_Occurred();\n");
+ if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
+ Replaceall(tm, "$error", "error");
+ Printv(w->code, Str(tm), "\n", NIL);
+ } else {
+ Append(w->code, " if (error) {\n");
+ Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname);
+ Append(w->code, " }\n");
+ }
+ Append(w->code, "}\n");
+ Delete(tm);
+
+ /*
+ * Python method may return a simple object, or a tuple.
+ * for in/out aruments, we have to extract the appropriate PyObjects from the tuple,
+ * then marshal everything back to C/C++ (return value and output arguments).
+ *
+ */
+
+ /* marshal return value and other outputs (if any) from PyObject to C/C++ type */
+
+ String *cleanup = NewString("");
+ String *outarg = NewString("");
+
+ if (outputs > 1) {
+ Wrapper_add_local(w, "output", "PyObject *output");
+ Append(w->code, "if (!PyTuple_Check(result)) {\n");
+ Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname);
+ Append(w->code, "}\n");
+ }
+
+ idx = 0;
+
+ /* marshal return value */
+ if (!is_void) {
+ /* this seems really silly. the node's type excludes
+ * qualifier/pointer/reference markers, which have to be retrieved
+ * from the decl field to construct return_type. but the typemap
+ * lookup routine uses the node's type, so we have to swap in and
+ * out the correct type. it's not just me, similar silliness also
+ * occurs in Language::cDeclaration().
+ */
+ Setattr(n, "type", return_type);
+ tm = Swig_typemap_lookup("directorout", n, "result", w);
+ Setattr(n, "type", type);
+ if (tm != 0) {
+ if (outputs > 1) {
+ Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);
+ Replaceall(tm, "$input", "output");
+ } else {
+ Replaceall(tm, "$input", "result");
+ }
+ char temp[24];
+ sprintf(temp, "%d", idx);
+ Replaceall(tm, "$argnum", temp);
+
+ /* TODO check this */
+ if (Getattr(n, "wrap:disown")) {
+ Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
+ } else {
+ Replaceall(tm, "$disown", "0");
+ }
+ if (Getattr(n, "tmap:directorout:implicitconv")) {
+ Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
+ }
+ Replaceall(tm, "$result", "c_result");
+ Printv(w->code, tm, "\n", NIL);
+ Delete(tm);
+ } else {
+ Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
+ "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname),
+ SwigType_namestr(name));
+ status = SWIG_ERROR;
+ }
+ }
+
+ /* marshal outputs */
+ for (p = l; p;) {
+ if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
+ if (outputs > 1) {
+ Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);
+ Replaceall(tm, "$input", "output");
+ } else {
+ Replaceall(tm, "$input", "result");
+ }
+ Replaceall(tm, "$result", Getattr(p, "name"));
+ Printv(w->code, tm, "\n", NIL);
+ p = Getattr(p, "tmap:directorargout:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+
+ /* any existing helper functions to handle this? */
+ if (allow_thread) {
+ Append(w->code, "}\n");
+ thread_end_block(n, w->code);
+ }
+
+ Delete(parse_args);
+ Delete(arglist);
+ Delete(cleanup);
+ Delete(outarg);
}
- }
- Append(w->code, "}\n");
-
- // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
- String *inline_extra_method = NewString("");
- if (dirprot_mode() && !is_public(n) && !pure_virtual) {
- Printv(inline_extra_method, declaration, NIL);
- String *extra_method_name = NewStringf("%sSwigPublic", name);
- Replaceall(inline_extra_method, name, extra_method_name);
- Replaceall(inline_extra_method, ";\n", " {\n ");
- if (!is_void)
- Printf(inline_extra_method, "return ");
- String *methodcall = Swig_method_call(super, l);
- Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
- Delete(methodcall);
- Delete(extra_method_name);
- }
-
- /* emit the director method */
- if (status == SWIG_OK) {
- if (!Getattr(n, "defaultargs")) {
- Wrapper_print(w, f_directors);
- Printv(f_directors_h, declaration, NIL);
- Printv(f_directors_h, inline_extra_method, NIL);
+ if (!is_void) {
+ if (!(ignored_method && !pure_virtual)) {
+ String *rettype = SwigType_str(return_type, 0);
+ if (!SwigType_isreference(return_type)) {
+ Printf(w->code, "return (%s) c_result;\n", rettype);
+ } else {
+ Printf(w->code, "return (%s) *c_result;\n", rettype);
+ }
+ Delete(rettype);
+ }
}
- }
- /* clean up */
- Delete(wrap_args);
- Delete(return_type);
- Delete(pclassname);
- DelWrapper(w);
- return status;
+ Append(w->code, "}\n");
+
+ // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
+ String *inline_extra_method = NewString("");
+ if (dirprot_mode() && !is_public(n) && !pure_virtual) {
+ Printv(inline_extra_method, declaration, NIL);
+ String *extra_method_name = NewStringf("%sSwigPublic", name);
+ Replaceall(inline_extra_method, name, extra_method_name);
+ Replaceall(inline_extra_method, ";\n", " {\n ");
+ if (!is_void)
+ Printf(inline_extra_method, "return ");
+ String *methodcall = Swig_method_call(super, l);
+ Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
+ Delete(methodcall);
+ Delete(extra_method_name);
+ }
+
+ /* emit the director method */
+ if (status == SWIG_OK) {
+ if (!Getattr(n, "defaultargs")) {
+ Wrapper_print(w, f_directors);
+ Printv(f_directors_h, declaration, NIL);
+ Printv(f_directors_h, inline_extra_method, NIL);
+ }
+ }
+
+ /* clean up */
+ Delete(wrap_args);
+ Delete(return_type);
+ Delete(pclassname);
+ DelWrapper(w);
+ return status;
}
/* -----------------------------------------------------------------------------
From 8a7ad756d087681304f567b66c1c2df31704ceeb Mon Sep 17 00:00:00 2001
From: Stefan Zager
Date: Tue, 14 Dec 2010 21:11:02 +0000
Subject: [PATCH 050/317] Added sequence and mapping support for builtin types.
Fixed object ownership in %pyswigbinoperator.
Test suite now fails on li_std_vector_extra.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12346 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/python/builtin.swg | 135 ++++++++++++++++++++++++++++---------
Lib/python/pycontainer.swg | 19 +++++-
Lib/python/pyopers.swg | 58 ++++++++--------
Source/Modules/python.cxx | 82 ++++++++++++++++------
4 files changed, 212 insertions(+), 82 deletions(-)
diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg
index fde5339d5..f99e25890 100644
--- a/Lib/python/builtin.swg
+++ b/Lib/python/builtin.swg
@@ -1,16 +1,97 @@
-extern int
-pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure)
-{
- if (!closure)
- return -1;
- PyObject *tuple = PyTuple_New(1);
- assert(tuple);
- PyTuple_SET_ITEM(tuple, 0, val);
- Py_XINCREF(val);
- PyObject *result = ((PyCFunction) closure)(obj, tuple);
- Py_DECREF(tuple);
- Py_XDECREF(result);
- return result ? 0 : -1;
+#define PYSWIG_BINARYFUNC_CLOSURE(wrapper) \
+SWIGINTERN PyObject* \
+wrapper##_closure (PyObject *a, PyObject *b) \
+{ \
+ PyObject *tuple = PyTuple_New(1); \
+ assert(tuple); \
+ PyTuple_SET_ITEM(tuple, 0, b); \
+ Py_XINCREF(b); \
+ PyObject *result = wrapper(a, tuple); \
+ Py_DECREF(tuple); \
+ return result; \
+}
+
+#define PYSWIG_TERNARYFUNC_CLOSURE(wrapper) \
+SWIGINTERN PyObject* \
+wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \
+{ \
+ PyObject *tuple = PyTuple_New(2); \
+ assert(tuple); \
+ PyTuple_SET_ITEM(tuple, 0, b); \
+ PyTuple_SET_ITEM(tuple, 1, c); \
+ Py_XINCREF(b); \
+ Py_XINCREF(c); \
+ PyObject *result = wrapper(a, tuple); \
+ Py_DECREF(tuple); \
+ return result; \
+}
+
+#define PYSWIG_LENFUNC_CLOSURE(wrapper) \
+SWIGINTERN Py_ssize_t \
+wrapper##_closure (PyObject *a) \
+{ \
+ PyObject *resultobj = wrapper(a, NULL); \
+ Py_ssize_t result = _PyLong_AsSsize_t(resultobj); \
+ Py_DECREF(resultobj); \
+ return result; \
+}
+
+#define PYSWIG_SSIZESSIZEARGFUNC_CLOSURE(wrapper) \
+SWIGINTERN PyObject* \
+wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c) \
+{ \
+ PyObject *tuple = PyTuple_New(2); \
+ assert(tuple); \
+ PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
+ PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \
+ PyObject *result = wrapper(a, tuple); \
+ Py_DECREF(tuple); \
+ return result; \
+}
+
+#define PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE(wrapper) \
+SWIGINTERN int \
+wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) \
+{ \
+ PyObject *tuple = PyTuple_New(3); \
+ assert(tuple); \
+ PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
+ PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \
+ PyTuple_SET_ITEM(tuple, 2, d); \
+ Py_XINCREF(d); \
+ PyObject *resultobj = wrapper(a, tuple); \
+ int result = resultobj ? 0 : -1; \
+ Py_DECREF(tuple); \
+ Py_XDECREF(resultobj); \
+ return result; \
+}
+
+#define PYSWIG_SSIZEARGFUNC_CLOSURE(wrapper) \
+SWIGINTERN PyObject* \
+wrapper##_closure (PyObject *a, Py_ssize_t b) \
+{ \
+ PyObject *tuple = PyTuple_New(1); \
+ assert(tuple); \
+ PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
+ PyObject *result = wrapper(a, tuple); \
+ Py_DECREF(tuple); \
+ return result; \
+}
+
+#define PYSWIG_SSIZEOBJARGPROC_CLOSURE(wrapper) \
+SWIGINTERN int \
+wrapper##_closure (PyObject *a, Py_ssize_t b, PyObject *c) \
+{ \
+ PyObject *tuple = PyTuple_New(2); \
+ assert(tuple); \
+ PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
+ PyTuple_SET_ITEM(tuple, 1, c); \
+ Py_XINCREF(c); \
+ PyObject *resultobj = wrapper(a, tuple); \
+ int result = resultobj ? 0 : -1; \
+ Py_XDECREF(resultobj); \
+ Py_DECREF(tuple); \
+ return result; \
}
#ifdef __cplusplus
@@ -27,6 +108,8 @@ template struct PySwigBuiltin : public SwigPyObject {
static PyMethodDef methods[];
static PyGetSetDef getset[];
static PyNumberMethods number_methods;
+ static PySequenceMethods sequence_methods;
+ static PyMappingMethods mapping_methods;
static PyTypeObject pytype;
static SwigPyClientData clientdata;
};
@@ -40,27 +123,19 @@ template void py_builtin_dealloc (PyObject *pyobj)
(*pyobj->ob_type->tp_free)(pyobj);
}
-template PyObject*
-pyswig_binaryfunc_closure (PyObject *a, PyObject *b)
+SWIGINTERN int
+pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure)
{
+ if (!closure)
+ return -1;
PyObject *tuple = PyTuple_New(1);
assert(tuple);
- PyTuple_SET_ITEM(tuple, 0, b);
- PyObject *result = func(a, tuple);
+ PyTuple_SET_ITEM(tuple, 0, val);
+ Py_XINCREF(val);
+ PyObject *result = ((PyCFunction) closure)(obj, tuple);
Py_DECREF(tuple);
- return result;
-}
-
-template PyObject*
-pyswig_ternaryfunc_closure (PyObject *a, PyObject *b, PyObject *c)
-{
- PyObject *tuple = PyTuple_New(2);
- assert(tuple);
- PyTuple_SET_ITEM(tuple, 0, b);
- PyTuple_SET_ITEM(tuple, 1, c);
- PyObject *result = func(a, tuple);
- Py_DECREF(tuple);
- return result;
+ Py_XDECREF(result);
+ return result ? 0 : -1;
}
} // namespace {
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index 27e145362..5578f1af9 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -599,7 +599,6 @@ namespace swig
/**** The python container methods ****/
-
%define %swig_container_methods(Container...)
%newobject __getslice__;
@@ -618,8 +617,16 @@ namespace swig
return self->size();
}
}
+
+#if defined(SWIGPYTHON_BUILTIN)
+%pybinoperator(__nonzero__, __nonzero__, unaryfunc, nb_nonzero);
+%pybinoperator(__len__, __len__, lenfunc, sq_length);
+#endif // SWIGPYTHON_BUILTIN
+
%enddef
+
+
%define %swig_sequence_methods_common(Sequence...)
%swig_sequence_iterator(%arg(Sequence))
%swig_container_methods(%arg(Sequence))
@@ -697,6 +704,14 @@ namespace swig
}
}
+
+#if defined(SWIGPYTHON_BUILTIN)
+%pybinoperator(__getitem__, __getitem__, ssizeargfunc, sq_item);
+%pybinoperator(__getslice__, __getslice__, ssizessizeargfunc, sq_slice);
+%pybinoperator(__setitem__, __setitem__, ssizeobjargproc, sq_ass_item);
+%pybinoperator(__setslice__, __setslice__, ssizessizeobjargproc, sq_ass_slice);
+#endif // SWIGPYTHON_BUILTIN
+
%enddef
%define %swig_sequence_methods(Sequence...)
@@ -714,6 +729,7 @@ namespace swig
self->push_back(x);
}
}
+
%enddef
%define %swig_sequence_methods_val(Sequence...)
@@ -731,6 +747,7 @@ namespace swig
self->push_back(x);
}
}
+
%enddef
diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg
index 3074eaa9e..851524219 100644
--- a/Lib/python/pyopers.swg
+++ b/Lib/python/pyopers.swg
@@ -13,20 +13,20 @@
#define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype)
#endif
-%pybinoperator(__add__, *::operator+, binary_func, nb_add);
-%pybinoperator(__pos__, *::operator+(), unary_func, nb_positive);
-%pybinoperator(__pos__, *::operator+() const, unary_func, nb_positive);
-%pybinoperator(__sub__, *::operator-, binary_func, nb_subtract);
-%pybinoperator(__neg__, *::operator-(), unary_func, nb_negative);
-%pybinoperator(__neg__, *::operator-() const, unary_func, nb_negative);
-%pybinoperator(__mul__, *::operator*, binary_func, nb_multiply);
-%pybinoperator(__div__, *::operator/, binary_func, nb_div);
-%pybinoperator(__mod__, *::operator%, binary_func, nb_remainder);
-%pybinoperator(__lshift__, *::operator<<, binary_func, nb_lshift);
-%pybinoperator(__rshift__, *::operator>>, binary_func, nb_rshift);
-%pybinoperator(__and__, *::operator&, binary_func, nb_and);
-%pybinoperator(__or__, *::operator|, binary_func, nb_or);
-%pybinoperator(__xor__, *::operator^, binary_func, nb_xor);
+%pybinoperator(__add__, *::operator+, binaryfunc, nb_add);
+%pybinoperator(__pos__, *::operator+(), unaryfunc, nb_positive);
+%pybinoperator(__pos__, *::operator+() const, unaryfunc, nb_positive);
+%pybinoperator(__sub__, *::operator-, binaryfunc, nb_subtract);
+%pybinoperator(__neg__, *::operator-(), unaryfunc, nb_negative);
+%pybinoperator(__neg__, *::operator-() const, unaryfunc, nb_negative);
+%pybinoperator(__mul__, *::operator*, binaryfunc, nb_multiply);
+%pybinoperator(__div__, *::operator/, binaryfunc, nb_div);
+%pybinoperator(__mod__, *::operator%, binaryfunc, nb_remainder);
+%pybinoperator(__lshift__, *::operator<<, binaryfunc, nb_lshift);
+%pybinoperator(__rshift__, *::operator>>, binaryfunc, nb_rshift);
+%pybinoperator(__and__, *::operator&, binaryfunc, nb_and);
+%pybinoperator(__or__, *::operator|, binaryfunc, nb_or);
+%pybinoperator(__xor__, *::operator^, binaryfunc, nb_xor);
%pycompare(__lt__, *::operator<, Py_LT);
%pycompare(__le__, *::operator<=, Py_LE);
%pycompare(__gt__, *::operator>, Py_GT);
@@ -34,16 +34,16 @@
%pycompare(__eq__, *::operator==, Py_EQ);
%pycompare(__ne__, *::operator!=, Py_NE);
-%feature("pyslot", "nb_truediv", functype="binary_func") *::operator/;
+%feature("pyslot", "nb_truediv", functype="binaryfunc") *::operator/;
/* Special cases */
%rename(__invert__) *::operator~;
-%feature("pyslot", "nb_invert", functype="unary_func") *::operator~;
+%feature("pyslot", "nb_invert", functype="unaryfunc") *::operator~;
%rename(__call__) *::operator();
-%feature("pyslot", "tp_call", functype="ternary_func") *::operator();
+%feature("pyslot", "tp_call", functype="ternaryfunc") *::operator();
#if defined(SWIGPYTHON_BUILTIN)
-%pybinoperator(__nonzero__, *::operator bool, unary_func, nb_nonzero);
+%pybinoperator(__nonzero__, *::operator bool, unaryfunc, nb_nonzero);
#else
%feature("shadow") *::operator bool %{
def __nonzero__(self):
@@ -103,21 +103,21 @@ __bool__ = __nonzero__
*/
#if defined(SWIGPYTHON_BUILTIN)
-#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %rename(SwigPyOper) Oper; %feature("pyslot", #slot, functype=#functp) Oper;
+#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %delobject Oper; %newobject Oper; %feature("pyslot", #slot, functype=#functp) Oper; %rename(SwigPyOper) Oper
#else
#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
#endif
-%pyinplaceoper(__iadd__ , *::operator +=, binary_func, nb_inplace_add);
-%pyinplaceoper(__isub__ , *::operator -=, binary_func, nb_inplace_subtract);
-%pyinplaceoper(__imul__ , *::operator *=, binary_func, nb_inplace_multiply);
-%pyinplaceoper(__idiv__ , *::operator /=, binary_func, nb_inplace_divide);
-%pyinplaceoper(__imod__ , *::operator %=, binary_func, nb_inplace_remainder);
-%pyinplaceoper(__iand__ , *::operator &=, binary_func, nb_inplace_and);
-%pyinplaceoper(__ior__ , *::operator |=, binary_func, nb_inplace_or);
-%pyinplaceoper(__ixor__ , *::operator ^=, binary_func, nb_inplace_xor);
-%pyinplaceoper(__ilshift__, *::operator <<=, binary_func, nb_inplace_lshift);
-%pyinplaceoper(__irshift__, *::operator >>=, binary_func, nb_inplace_rshift);
+%pyinplaceoper(__iadd__ , *::operator +=, binaryfunc, nb_inplace_add);
+%pyinplaceoper(__isub__ , *::operator -=, binaryfunc, nb_inplace_subtract);
+%pyinplaceoper(__imul__ , *::operator *=, binaryfunc, nb_inplace_multiply);
+%pyinplaceoper(__idiv__ , *::operator /=, binaryfunc, nb_inplace_divide);
+%pyinplaceoper(__imod__ , *::operator %=, binaryfunc, nb_inplace_remainder);
+%pyinplaceoper(__iand__ , *::operator &=, binaryfunc, nb_inplace_and);
+%pyinplaceoper(__ior__ , *::operator |=, binaryfunc, nb_inplace_or);
+%pyinplaceoper(__ixor__ , *::operator ^=, binaryfunc, nb_inplace_xor);
+%pyinplaceoper(__ilshift__, *::operator <<=, binaryfunc, nb_inplace_lshift);
+%pyinplaceoper(__irshift__, *::operator >>=, binaryfunc, nb_inplace_rshift);
/* Finally, in python we need to mark the binary operations to fail as
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 55bfd8815..6dbaf0ea0 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -172,6 +172,30 @@ getSlot (Node *n, const char *key)
return val ? val : slot_default;
}
+static String*
+getClosure (String *functype, String *wrapper)
+{
+ static const char *functypes[] = {
+ "binaryfunc", "PYSWIG_BINARYFUNC_CLOSURE",
+ "ternaryfunc", "PYSWIG_TERNARYFUNC_CLOSURE",
+ "lenfunc", "PYSWIG_LENFUNC_CLOSURE",
+ "ssizeargfunc", "PYSWIG_SSIZEARGFUNC_CLOSURE",
+ "ssizessizeargfunc", "PYSWIG_SSIZESSIZEARGFUNC_CLOSURE",
+ "ssizeobjargproc", "PYSWIG_SSIZEOBJARGPROC_CLOSURE",
+ "ssizessizeobjargproc", "PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE",
+ NULL
+ };
+
+ if (!functype)
+ return NULL;
+ char *c = Char(functype);
+ int i;
+ for (i = 0; functypes[i] != NULL; i += 2) {
+ if (!strcmp(c, functypes[i]))
+ return NewStringf("%s(%s)", functypes[i+1], wrapper);
+ }
+ return NULL;
+}
class PYTHON:public Language {
public:
@@ -1947,18 +1971,18 @@ public:
char const *self_param = builtin_self ? "self" : "SWIGUNUSEDPARM(self)";
char const *wrap_return = builtin_ctor ? "int " : "PyObject *";
String *linkage = NewString("SWIGINTERN ");
+ String *wrapper_name = Swig_name_wrapper(iname);
String *slot = Getattr(n, "feature:pyslot");
+ String *closure_decl = NULL;
+ if (slot)
+ closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name);
+
+ /*
if (builtin_setter || builtin_getter) {
Clear(linkage);
Printv(linkage, "extern ", NIL);
}
- if (slot) {
- String *functype = Getattr(n, "feature:pyslot:functype");
- if (!strcmp(Char(functype), "binary_func") || !strcmp(Char(functype), "ternary_func")) {
- Clear(linkage);
- Printv(linkage, "extern ", NIL);
- }
- }
+ */
if (Getattr(n, "sym:overloaded")) {
overname = Getattr(n, "sym:overname");
@@ -2000,7 +2024,7 @@ public:
allow_kwargs = 0;
varargs = emit_isvarargs(l);
- String *wname = Swig_name_wrapper(iname);
+ String *wname = Copy(wrapper_name);
if (overname) {
Append(wname, overname);
}
@@ -2510,8 +2534,6 @@ public:
}
}
- String *wrapper_name = Swig_name_wrapper(iname);
-
/* If this is a builtin type, create a PyGetSetDef entry for this member variable. */
if (builtin_getter) {
Hash *h = Getattr(builtin_getset, name);
@@ -2534,15 +2556,12 @@ public:
/* Handle builtin operator overloads */
if (slot) {
- String *functype = Getattr(n, "feature:pyslot:functype");
String *feature_name = NewStringf("feature:%s", slot);
- String *closure_name = NewString("");
- if (!strcmp(Char(functype), "binary_func")) {
- Printf(closure_name, "pyswig_binaryfunc_closure< %s >", wrapper_name);
- } else if (!strcmp(Char(functype), "ternary_func")) {
- Printf(closure_name, "pyswig_ternaryfunc_closure< %s >", wrapper_name);
- } else {
- Append(closure_name, wrapper_name);
+ String *closure_name = Copy(wrapper_name);
+ if (closure_decl) {
+ if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling"))
+ Printv(f_wrappers, closure_decl, "\n\n", NIL);
+ Append(closure_name, "_closure");
}
Node *parent = Swig_methodclass(n);
Setattr(parent, feature_name, closure_name);
@@ -2561,6 +2580,8 @@ public:
Delete(wname);
DelWrapper(f);
Delete(wrapper_name);
+ if (closure_decl)
+ Delete(closure_decl);
return SWIG_OK;
}
@@ -3123,6 +3144,25 @@ public:
Printf(f, " (unaryfunc) %s, // nb_index;\n", getSlot(n, "feature:nb_index"));
Printf(f, "};\n\n");
+ Printf(f, "template <> PySequenceMethods PySwigBuiltin< %s >::sequence_methods = {\n", rname);
+ Printf(f, " (lenfunc) %s, // sq_length\n", getSlot(n, "sq_length"));
+ Printf(f, " (binaryfunc) %s, // sq_concat\n", getSlot(n, "sq_concat"));
+ Printf(f, " (ssizeargfunc) %s, // sq_repeat\n", getSlot(n, "sq_repeat"));
+ Printf(f, " (ssizeargfunc) %s, // sq_item\n", getSlot(n, "sq_item"));
+ Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "sq_slice"));
+ Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "sq_ass_item"));
+ Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "sq_ass_slice"));
+ Printf(f, " (objobjproc) %s, // sq_contains\n", getSlot(n, "sq_contains"));
+ Printf(f, " (binaryfunc) %s, // sq_inplace_concat\n", getSlot(n, "sq_inplace_concat"));
+ Printf(f, " (ssizeargfunc) %s, // sq_inplace_repeat\n", getSlot(n, "sq_inplace_repeat"));
+ Printf(f, "};\n\n");
+
+ Printf(f, "template <> PyMappingMethods PySwigBuiltin< %s >::mapping_methods = {\n", rname);
+ Printf(f, " (lenfunc) %s, // mp_length;\n", getSlot(n, "mp_length"));
+ Printf(f, " (binaryfunc) %s, // mp_subscript;\n", getSlot(n, "mp_subscript"));
+ Printf(f, " (objobjargproc) %s, // mp_ass_subscript;\n", getSlot(n, "mp_ass_subscript"));
+ Printf(f, "};\n\n");
+
String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES");
// TODO: Add more flags based on slots
Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname);
@@ -3138,8 +3178,8 @@ public:
Printf(f, " %s, /*tp_compare*/\n", getSlot(n, "feature:tp_compare"));
Printf(f, " %s, /*tp_repr*/\n", getSlot(n, "feature:tp_repr"));
Printf(f, " &%s::number_methods, /*tp_as_number*/\n", templ);
- Printf(f, " %s, /*tp_as_sequence*/\n", getSlot(n, "feature:tp_as_sequence"));
- Printf(f, " %s, /*tp_as_mapping*/\n", getSlot(n, "feature:tp_as_mapping"));
+ Printf(f, " &%s::sequence_methods, /*tp_as_sequence*/\n", templ);
+ Printf(f, " &%s::mapping_methods, /*tp_as_mapping*/\n", templ);
Printf(f, " %s, /*tp_hash */\n", getSlot(n, "feature:tp_hash"));
Printf(f, " %s, /*tp_call*/\n", getSlot(n, "feature:tp_call"));
Printf(f, " %s, /*tp_str*/\n", getSlot(n, "feature:tp_str"));
@@ -3519,8 +3559,6 @@ public:
String *fullname = Swig_name_member(NULL, class_name, symname);
String *wname = Swig_name_wrapper(fullname);
Setattr(class_members, name, name);
- ParmList *parms = Getattr(n, "parms");
- bool noArgs = !parms || Len(parms) == 0;
String *pyflags = NewString("METH_VARARGS");
Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags));
Delete(name);
From 8f1bde9d81c84bd3f761803eec6c5ab456633cf0 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Tue, 14 Dec 2010 21:38:36 +0000
Subject: [PATCH 051/317] Fix expansion in array typemaps
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12347 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 4 +++
Examples/test-suite/common.mk | 1 +
.../test-suite/java/typemap_arrays_runme.java | 19 ++++++++++++
.../test-suite/python/typemap_arrays_runme.py | 5 ++++
Examples/test-suite/typemap_arrays.i | 30 +++++++++++++++++++
Source/Swig/typemap.c | 16 +++++-----
6 files changed, 67 insertions(+), 8 deletions(-)
create mode 100644 Examples/test-suite/java/typemap_arrays_runme.java
create mode 100644 Examples/test-suite/python/typemap_arrays_runme.py
create mode 100644 Examples/test-suite/typemap_arrays.i
diff --git a/CHANGES.current b/CHANGES.current
index e42223da0..9449c2f4c 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (in progress)
===========================
+2010-12-14: wsfulton
+ Fix $basemangle expansion in array typemaps. For example if type is int *[3],
+ $basemangle expands to _p_int.
+
2010-12-07: iant
Check that we are using a sufficiently new version of the
6g or 8g Go compiler during configure time. If not, disable Go.
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 833e1532b..2f061cd88 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -397,6 +397,7 @@ CPP_TEST_CASES += \
typedef_scope \
typedef_sizet \
typedef_struct \
+ typemap_arrays \
typemap_delete \
typemap_global_scope \
typemap_namespace \
diff --git a/Examples/test-suite/java/typemap_arrays_runme.java b/Examples/test-suite/java/typemap_arrays_runme.java
new file mode 100644
index 000000000..1ca062f78
--- /dev/null
+++ b/Examples/test-suite/java/typemap_arrays_runme.java
@@ -0,0 +1,19 @@
+import typemap_arrays.*;
+
+public class typemap_arrays_runme {
+
+ static {
+ try {
+ System.loadLibrary("typemap_arrays");
+ } catch (UnsatisfiedLinkError e) {
+ System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
+ System.exit(1);
+ }
+ }
+
+ public static void main(String argv[]) {
+ if (typemap_arrays.sumA(null) != 60)
+ throw new RuntimeException("Sum is wrong");
+ }
+}
+
diff --git a/Examples/test-suite/python/typemap_arrays_runme.py b/Examples/test-suite/python/typemap_arrays_runme.py
new file mode 100644
index 000000000..c23222c63
--- /dev/null
+++ b/Examples/test-suite/python/typemap_arrays_runme.py
@@ -0,0 +1,5 @@
+from typemap_arrays import *
+
+if sumA(None) != 60:
+ raise RuntimeError, "Sum is wrong"
+
diff --git a/Examples/test-suite/typemap_arrays.i b/Examples/test-suite/typemap_arrays.i
new file mode 100644
index 000000000..dd7994405
--- /dev/null
+++ b/Examples/test-suite/typemap_arrays.i
@@ -0,0 +1,30 @@
+%module typemap_arrays
+
+// Test that previously non-working array typemaps special variables are working
+
+%typemap(in) SWIGTYPE[ANY] {
+ _should_not_be_used_and_will_not_compile_
+}
+
+// Check $basemangle expands to _p_int and $basetype expands to int *
+%typemap(in) int *nums[3] (int *temp[3]) {
+ $basetype var1$basemangle = new int(10);
+ $basetype var2$basemangle = new int(20);
+ $basetype var3$basemangle = new int(30);
+ temp[0] = var1_p_int;
+ temp[1] = var2_p_int;
+ temp[2] = var3_p_int;
+ $1 = temp;
+}
+
+%inline %{
+int sumA(int *nums[3]) {
+ int sum = 0;
+ for (int i=0; i<3; ++i) {
+ int *p = nums[i];
+ if (p)
+ sum += *p;
+ }
+ return sum;
+}
+%}
diff --git a/Source/Swig/typemap.c b/Source/Swig/typemap.c
index 607ab6d10..1062e0969 100644
--- a/Source/Swig/typemap.c
+++ b/Source/Swig/typemap.c
@@ -963,7 +963,7 @@ static int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, Swi
{
SwigType *star_type, *amp_type, *base_type, *lex_type;
SwigType *ltype, *star_ltype, *amp_ltype;
- String *mangle, *star_mangle, *amp_mangle, *base_mangle, *base_name;
+ String *mangle, *star_mangle, *amp_mangle, *base_mangle, *base_name, *base_type_str;
String *descriptor, *star_descriptor, *amp_descriptor;
String *ts;
char *sc;
@@ -1132,21 +1132,20 @@ static int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, Swi
/* Base type */
if (SwigType_isarray(type)) {
- SwigType *bt = Copy(type);
- Delete(SwigType_pop_arrays(bt));
- base_type = SwigType_str(bt, 0);
- Delete(bt);
+ base_type = Copy(type);
+ Delete(SwigType_pop_arrays(base_type));
} else {
base_type = SwigType_base(type);
}
- base_name = SwigType_namestr(base_type);
+ base_type_str = SwigType_str(base_type, 0);
+ base_name = SwigType_namestr(base_type_str);
if (index == 1) {
Replace(s, "$basetype", base_name, DOH_REPLACE_ANY);
replace_local_types(locals, "$basetype", base_name);
}
strcpy(varname, "basetype");
- Replace(s, var, base_type, DOH_REPLACE_ANY);
+ Replace(s, var, base_type_str, DOH_REPLACE_ANY);
replace_local_types(locals, var, base_name);
base_mangle = SwigType_manglestr(base_type);
@@ -1155,8 +1154,9 @@ static int typemap_replace_vars(String *s, ParmList *locals, SwigType *type, Swi
strcpy(varname, "basemangle");
Replace(s, var, base_mangle, DOH_REPLACE_ANY);
Delete(base_mangle);
- Delete(base_type);
Delete(base_name);
+ Delete(base_type_str);
+ Delete(base_type);
lex_type = SwigType_base(rtype);
if (index == 1)
From bb2d75892074cf87f12b5706958f63d1eb6f0980 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Wed, 15 Dec 2010 20:37:40 +0000
Subject: [PATCH 052/317] Use a SwigType instead of String where expected
including call to SwigType_manglestr
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12348 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/Modules/ocaml.cxx | 45 ++++++++++++++++------------------------
1 file changed, 18 insertions(+), 27 deletions(-)
diff --git a/Source/Modules/ocaml.cxx b/Source/Modules/ocaml.cxx
index 82e3f846a..6021cf276 100644
--- a/Source/Modules/ocaml.cxx
+++ b/Source/Modules/ocaml.cxx
@@ -35,7 +35,7 @@ static String *classname = 0;
static String *module = 0;
static String *init_func_def = 0;
static String *f_classtemplate = 0;
-static String *name_qualifier = 0;
+static SwigType *name_qualifier_type = 0;
static Hash *seen_enums = 0;
static Hash *seen_enumvalues = 0;
@@ -898,12 +898,12 @@ public:
String *name = Getattr(n, "feature:symname");
SwigType *type = Getattr(n, "type");
String *value = Getattr(n, "value");
- String *qvalue = Getattr(n, "qualified:value");
+ SwigType *qname = Getattr(n, "qualified:name");
String *rvalue = NewString("");
String *temp = 0;
- if (qvalue)
- value = qvalue;
+ if (qname)
+ value = qname;
if (!name) {
name = mangleNameForCaml(Getattr(n, "name"));
@@ -1228,20 +1228,18 @@ public:
return out;
}
- String *fully_qualify_enum_name(Node *n, String *name) {
+ SwigType *fully_qualified_enum_type(Node *n) {
Node *parent = 0;
- String *qualification = NewString("");
String *fully_qualified_name = NewString("");
String *parent_type = 0;
- String *normalized_name;
parent = parentNode(n);
while (parent) {
parent_type = nodeType(parent);
if (Getattr(parent, "name")) {
String *parent_copy = NewStringf("%s::", Getattr(parent, "name"));
- if (!Cmp(parent_type, "class") || !Cmp(parent_type, "namespace"))
- Insert(qualification, 0, parent_copy);
+ if (Cmp(parent_type, "class") == 0 || Cmp(parent_type, "namespace") == 0)
+ Insert(fully_qualified_name, 0, parent_copy);
Delete(parent_copy);
}
if (!Cmp(parent_type, "class"))
@@ -1249,25 +1247,18 @@ public:
parent = parentNode(parent);
}
- Printf(fully_qualified_name, "%s%s", qualification, name);
-
- normalized_name = normalizeTemplatedClassName(fully_qualified_name);
- if (!strncmp(Char(normalized_name), "enum ", 5)) {
- Insert(normalized_name, 5, qualification);
- }
-
- return normalized_name;
+ return fully_qualified_name;
}
/* Benedikt Grundmann inspired --> Enum wrap styles */
int enumvalueDeclaration(Node *n) {
String *name = Getattr(n, "name");
- String *qvalue = 0;
+ SwigType *qtype = 0;
- if (name_qualifier) {
- qvalue = Copy(name_qualifier);
- Printv(qvalue, name, NIL);
+ if (name_qualifier_type) {
+ qtype = Copy(name_qualifier_type);
+ Printv(qtype, name, NIL);
}
if (const_enum && name && !Getattr(seen_enumvalues, name)) {
@@ -1275,10 +1266,10 @@ public:
SetFlag(n, "feature:immutable");
Setattr(n, "feature:enumvalue", "1"); // this does not appear to be used
- if (qvalue)
- Setattr(n, "qualified:value", qvalue);
+ if (qtype)
+ Setattr(n, "qualified:name", SwigType_namestr(qtype));
- String *evname = SwigType_manglestr(qvalue);
+ String *evname = SwigType_manglestr(qtype);
Insert(evname, 0, "SWIG_ENUM_");
Setattr(n, "feature:enumvname", name);
@@ -1309,10 +1300,10 @@ public:
/* name is now fully qualified */
String *fully_qualified_name = NewString(name);
bool seen_enum = false;
- if (name_qualifier)
- Delete(name_qualifier);
+ if (name_qualifier_type)
+ Delete(name_qualifier_type);
char *strip_position;
- name_qualifier = fully_qualify_enum_name(n, NewString(""));
+ name_qualifier_type = fully_qualified_enum_type(n);
strip_position = strstr(Char(oname), "::");
From 1adc50e73032eb80e2f77cac15205112e422cdf5 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Wed, 15 Dec 2010 21:55:08 +0000
Subject: [PATCH 053/317] constify SwigType * in many places
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12349 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 22 ++++++++++
Source/Modules/lang.cxx | 2 +-
Source/Modules/php.cxx | 4 +-
Source/Modules/swigmod.h | 2 +-
Source/Swig/stype.c | 48 +++++++++++-----------
Source/Swig/swig.h | 87 ++++++++++++++++++++--------------------
Source/Swig/symbol.c | 2 +-
Source/Swig/typeobj.c | 30 +++++++-------
Source/Swig/typesys.c | 30 +++++++-------
9 files changed, 123 insertions(+), 104 deletions(-)
diff --git a/CHANGES.current b/CHANGES.current
index 9449c2f4c..633745a6f 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,28 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (in progress)
===========================
+2010-12-08: wsfulton
+ The name mangling for some complex types was incorrect. This is now fixed and results
+ in types being more interchangeable when there are typedefs involved.
+ namespace foo {
+ template class bar {};
+ typedef int Integer;
+ void test2(bar *x) { return x; }
+ }
+ The typewrapper class for x changes from
+ SWIGTYPE_p_foo__barT_int_p_t to
+ SWIGTYPE_p_foo__barT_p_int_t.
+
+ The name mangling involving qualifiers was not consistent, for example with the const qualifier in
+ MyTemplate< const ::DD * > the type wrapper class changes from
+ SWIGTYPE_p_MyTemplateT_DD_const_p_t to
+ SWIGTYPE_p_MyTemplateT_p_q_const__DD_t
+
+ There a number of other subtle name mangling changes not listed. The runtime version
+ has hence been changed from 4 to 5.
+
+TODO: write a testcase in Java showing reference_type working or whatever I fixed in STL.
+
2010-12-14: wsfulton
Fix $basemangle expansion in array typemaps. For example if type is int *[3],
$basemangle expands to _p_int.
diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx
index 0110b6ea1..7f96007e3 100644
--- a/Source/Modules/lang.cxx
+++ b/Source/Modules/lang.cxx
@@ -3011,7 +3011,7 @@ Node *Language::symbolLookup(String *s, const_String_or_char_ptr scope) {
* Tries to locate a class from a type definition
* ----------------------------------------------------------------------------- */
-Node *Language::classLookup(SwigType *s) {
+Node *Language::classLookup(const SwigType *s) {
Node *n = 0;
/* Look in hash of cached values */
diff --git a/Source/Modules/php.cxx b/Source/Modules/php.cxx
index b95eaa7cd..43eee9ae6 100644
--- a/Source/Modules/php.cxx
+++ b/Source/Modules/php.cxx
@@ -126,7 +126,7 @@ static enum {
} wrapperType = standard;
extern "C" {
- static void (*r_prevtracefunc) (SwigType *t, String *mangled, String *clientdata) = 0;
+ static void (*r_prevtracefunc) (const SwigType *t, String *mangled, String *clientdata) = 0;
}
static void SwigPHP_emit_resource_registrations() {
@@ -2710,7 +2710,7 @@ static PHP *maininstance = 0;
// We use this function to be able to write out zend_register_list_destructor_ex
// lines for most things in the type table
// NOTE: it's a function NOT A PHP::METHOD
-extern "C" void typetrace(SwigType *ty, String *mangled, String *clientdata) {
+extern "C" void typetrace(const SwigType *ty, String *mangled, String *clientdata) {
Node *class_node;
if (!zend_types) {
zend_types = NewHash();
diff --git a/Source/Modules/swigmod.h b/Source/Modules/swigmod.h
index d3074105f..208a7b026 100644
--- a/Source/Modules/swigmod.h
+++ b/Source/Modules/swigmod.h
@@ -213,7 +213,7 @@ public:
virtual int addSymbol(const String *s, const Node *n, const_String_or_char_ptr scope = ""); /* Add symbol */
virtual void dumpSymbols();
virtual Node *symbolLookup(String *s, const_String_or_char_ptr scope = ""); /* Symbol lookup */
- virtual Node *classLookup(SwigType *s); /* Class lookup */
+ virtual Node *classLookup(const SwigType *s); /* Class lookup */
virtual Node *enumLookup(SwigType *s); /* Enum lookup */
virtual int abstractClassTest(Node *n); /* Is class really abstract? */
virtual int is_assignable(Node *n); /* Is variable assignable? */
diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c
index 742b6232a..f3a1dc8ca 100644
--- a/Source/Swig/stype.c
+++ b/Source/Swig/stype.c
@@ -177,7 +177,7 @@ void SwigType_push(SwigType *t, String *cons) {
* Testing functions for querying a raw datatype
* ----------------------------------------------------------------------------- */
-int SwigType_ispointer_return(SwigType *t) {
+int SwigType_ispointer_return(const SwigType *t) {
char *c;
int idx;
if (!t)
@@ -190,7 +190,7 @@ int SwigType_ispointer_return(SwigType *t) {
return 0;
}
-int SwigType_isreference_return(SwigType *t) {
+int SwigType_isreference_return(const SwigType *t) {
char *c;
int idx;
if (!t)
@@ -203,7 +203,7 @@ int SwigType_isreference_return(SwigType *t) {
return 0;
}
-int SwigType_isconst(SwigType *t) {
+int SwigType_isconst(const SwigType *t) {
char *c;
if (!t)
return 0;
@@ -229,7 +229,7 @@ int SwigType_isconst(SwigType *t) {
return 0;
}
-int SwigType_ismutable(SwigType *t) {
+int SwigType_ismutable(const SwigType *t) {
int r;
SwigType *qt = SwigType_typedef_resolve_all(t);
if (SwigType_isreference(qt) || SwigType_isarray(qt)) {
@@ -240,7 +240,7 @@ int SwigType_ismutable(SwigType *t) {
return r ? 0 : 1;
}
-int SwigType_isenum(SwigType *t) {
+int SwigType_isenum(const SwigType *t) {
char *c = Char(t);
if (!t)
return 0;
@@ -250,7 +250,7 @@ int SwigType_isenum(SwigType *t) {
return 0;
}
-int SwigType_issimple(SwigType *t) {
+int SwigType_issimple(const SwigType *t) {
char *c = Char(t);
if (!t)
return 0;
@@ -308,7 +308,7 @@ int SwigType_issimple(SwigType *t) {
* r.q(const).enum SWIGTYPE
* ----------------------------------------------------------------------------- */
-SwigType *SwigType_default_create(SwigType *ty) {
+SwigType *SwigType_default_create(const SwigType *ty) {
SwigType *r = 0;
List *l;
Iterator it;
@@ -387,7 +387,7 @@ SwigType *SwigType_default_create(SwigType *ty) {
* SWIGTYPE
* ----------------------------------------------------------------------------- */
-SwigType *SwigType_default_deduce(SwigType *t) {
+SwigType *SwigType_default_deduce(const SwigType *t) {
SwigType *r = NewStringEmpty();
List *l;
Iterator it;
@@ -511,7 +511,7 @@ String *SwigType_namestr(const SwigType *t) {
* Create a C string representation of a datatype.
* ----------------------------------------------------------------------------- */
-String *SwigType_str(SwigType *s, const_String_or_char_ptr id) {
+String *SwigType_str(const SwigType *s, const_String_or_char_ptr id) {
String *result;
String *element = 0, *nextelement;
List *elements;
@@ -606,12 +606,12 @@ String *SwigType_str(SwigType *s, const_String_or_char_ptr id) {
}
/* -----------------------------------------------------------------------------
- * SwigType_ltype(SwigType *ty)
+ * SwigType_ltype(const SwigType *ty)
*
* Create a locally assignable type
* ----------------------------------------------------------------------------- */
-SwigType *SwigType_ltype(SwigType *s) {
+SwigType *SwigType_ltype(const SwigType *s) {
String *result;
String *element;
SwigType *td, *tc = 0;
@@ -709,7 +709,7 @@ SwigType *SwigType_ltype(SwigType *s) {
* with an equivalent assignable version.
* -------------------------------------------------------------------- */
-String *SwigType_lstr(SwigType *s, const_String_or_char_ptr id) {
+String *SwigType_lstr(const SwigType *s, const_String_or_char_ptr id) {
String *result;
SwigType *tc;
@@ -726,10 +726,11 @@ String *SwigType_lstr(SwigType *s, const_String_or_char_ptr id) {
* datatype printed by str().
* ----------------------------------------------------------------------------- */
-String *SwigType_rcaststr(SwigType *s, const_String_or_char_ptr name) {
+String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr name) {
String *result, *cast;
String *element = 0, *nextelement;
- SwigType *td, *rs, *tc = 0;
+ SwigType *td, *tc = 0;
+ const SwigType *rs;
List *elements;
int nelements, i;
int clear = 1;
@@ -873,7 +874,7 @@ String *SwigType_rcaststr(SwigType *s, const_String_or_char_ptr name) {
* Casts a variable from the real type to the local datatype.
* ----------------------------------------------------------------------------- */
-String *SwigType_lcaststr(SwigType *s, const_String_or_char_ptr name) {
+String *SwigType_lcaststr(const SwigType *s, const_String_or_char_ptr name) {
String *result;
result = NewStringEmpty();
@@ -899,9 +900,7 @@ String *SwigType_lcaststr(SwigType *s, const_String_or_char_ptr name) {
return result;
}
-
-/* keep old mangling since Java codes need it */
-String *SwigType_manglestr_default(SwigType *s) {
+static String *manglestr_default(const SwigType *s) {
char *c;
String *result = 0;
String *base = 0;
@@ -909,17 +908,16 @@ String *SwigType_manglestr_default(SwigType *s) {
SwigType *sr = SwigType_typedef_resolve_all(s);
SwigType *sq = SwigType_typedef_qualified(sr);
SwigType *ss = SwigType_remove_global_scope_prefix(sq);
-
- s = ss;
+ SwigType *type = ss;
if (SwigType_istemplate(ss)) {
SwigType *ty = Swig_symbol_template_deftype(ss, 0);
Delete(ss);
ss = ty;
- s = ss;
+ type = ss;
}
- lt = SwigType_ltype(s);
+ lt = SwigType_ltype(type);
result = SwigType_prefix(lt);
base = SwigType_base(lt);
@@ -972,8 +970,8 @@ String *SwigType_manglestr_default(SwigType *s) {
return result;
}
-String *SwigType_manglestr(SwigType *s) {
- return SwigType_manglestr_default(s);
+String *SwigType_manglestr(const SwigType *s) {
+ return manglestr_default(s);
}
/* -----------------------------------------------------------------------------
@@ -1092,7 +1090,7 @@ SwigType *SwigType_remove_global_scope_prefix(const SwigType *t) {
* Checks type declarators for a match
* ----------------------------------------------------------------------------- */
-int SwigType_check_decl(SwigType *ty, const SwigType *decl) {
+int SwigType_check_decl(const SwigType *ty, const SwigType *decl) {
SwigType *t, *t1, *t2;
int r;
t = SwigType_typedef_resolve_all(ty);
diff --git a/Source/Swig/swig.h b/Source/Swig/swig.h
index 8058216c3..6607c333d 100644
--- a/Source/Swig/swig.h
+++ b/Source/Swig/swig.h
@@ -129,37 +129,37 @@ extern "C" {
extern SwigType *SwigType_add_function(SwigType *t, ParmList *parms);
extern SwigType *SwigType_add_template(SwigType *t, ParmList *parms);
extern SwigType *SwigType_pop_function(SwigType *t);
- extern ParmList *SwigType_function_parms(SwigType *t, Node *file_line_node);
+ extern ParmList *SwigType_function_parms(const SwigType *t, Node *file_line_node);
extern List *SwigType_split(const SwigType *t);
extern String *SwigType_pop(SwigType *t);
- extern void SwigType_push(SwigType *t, SwigType *s);
+ extern void SwigType_push(SwigType *t, String *s);
extern List *SwigType_parmlist(const SwigType *p);
- extern String *SwigType_parm(String *p);
- extern String *SwigType_str(SwigType *s, const_String_or_char_ptr id);
- extern String *SwigType_lstr(SwigType *s, const_String_or_char_ptr id);
- extern String *SwigType_rcaststr(SwigType *s, const_String_or_char_ptr id);
- extern String *SwigType_lcaststr(SwigType *s, const_String_or_char_ptr id);
- extern String *SwigType_manglestr(SwigType *t);
- extern SwigType *SwigType_ltype(SwigType *t);
- extern int SwigType_ispointer(SwigType *t);
- extern int SwigType_ispointer_return(SwigType *t);
- extern int SwigType_isfunctionpointer(SwigType *t);
- extern int SwigType_ismemberpointer(SwigType *t);
- extern int SwigType_isreference(SwigType *t);
- extern int SwigType_isreference_return(SwigType *t);
- extern int SwigType_isarray(SwigType *t);
- extern int SwigType_prefix_is_simple_1D_array(SwigType *t);
- extern int SwigType_isfunction(SwigType *t);
- extern int SwigType_isqualifier(SwigType *t);
- extern int SwigType_isconst(SwigType *t);
- extern int SwigType_issimple(SwigType *t);
- extern int SwigType_ismutable(SwigType *t);
+ extern String *SwigType_parm(const SwigType *p);
+ extern String *SwigType_str(const SwigType *s, const_String_or_char_ptr id);
+ extern String *SwigType_lstr(const SwigType *s, const_String_or_char_ptr id);
+ extern String *SwigType_rcaststr(const SwigType *s, const_String_or_char_ptr id);
+ extern String *SwigType_lcaststr(const SwigType *s, const_String_or_char_ptr id);
+ extern String *SwigType_manglestr(const SwigType *t);
+ extern SwigType *SwigType_ltype(const SwigType *t);
+ extern int SwigType_ispointer(const SwigType *t);
+ extern int SwigType_ispointer_return(const SwigType *t);
+ extern int SwigType_isfunctionpointer(const SwigType *t);
+ extern int SwigType_ismemberpointer(const SwigType *t);
+ extern int SwigType_isreference(const SwigType *t);
+ extern int SwigType_isreference_return(const SwigType *t);
+ extern int SwigType_isarray(const SwigType *t);
+ extern int SwigType_prefix_is_simple_1D_array(const SwigType *t);
+ extern int SwigType_isfunction(const SwigType *t);
+ extern int SwigType_isqualifier(const SwigType *t);
+ extern int SwigType_isconst(const SwigType *t);
+ extern int SwigType_issimple(const SwigType *t);
+ extern int SwigType_ismutable(const SwigType *t);
extern int SwigType_isvarargs(const SwigType *t);
extern int SwigType_istemplate(const SwigType *t);
- extern int SwigType_isenum(SwigType *t);
- extern int SwigType_check_decl(SwigType *t, const_String_or_char_ptr decl);
- extern SwigType *SwigType_strip_qualifiers(SwigType *t);
- extern SwigType *SwigType_strip_single_qualifier(SwigType *t);
+ extern int SwigType_isenum(const SwigType *t);
+ extern int SwigType_check_decl(const SwigType *t, const_String_or_char_ptr decl);
+ extern SwigType *SwigType_strip_qualifiers(const SwigType *t);
+ extern SwigType *SwigType_strip_single_qualifier(const SwigType *t);
extern SwigType *SwigType_functionpointer_decompose(SwigType *t);
extern String *SwigType_base(const SwigType *t);
extern String *SwigType_namestr(const SwigType *t);
@@ -168,27 +168,26 @@ extern "C" {
extern String *SwigType_istemplate_templateprefix(const SwigType *t);
extern String *SwigType_templateargs(const SwigType *t);
extern String *SwigType_prefix(const SwigType *t);
- extern int SwigType_array_ndim(SwigType *t);
- extern String *SwigType_array_getdim(SwigType *t, int n);
+ extern int SwigType_array_ndim(const SwigType *t);
+ extern String *SwigType_array_getdim(const SwigType *t, int n);
extern void SwigType_array_setdim(SwigType *t, int n, const_String_or_char_ptr rep);
- extern SwigType *SwigType_array_type(SwigType *t);
- extern String *SwigType_default(SwigType *t);
- extern SwigType *SwigType_default_create(SwigType *ty);
- extern SwigType *SwigType_default_deduce(SwigType *t);
+ extern SwigType *SwigType_array_type(const SwigType *t);
+ extern SwigType *SwigType_default_create(const SwigType *ty);
+ extern SwigType *SwigType_default_deduce(const SwigType *t);
extern void SwigType_typename_replace(SwigType *t, String *pat, String *rep);
extern SwigType *SwigType_remove_global_scope_prefix(const SwigType *t);
- extern SwigType *SwigType_alttype(SwigType *t, int ltmap);
+ extern SwigType *SwigType_alttype(const SwigType *t, int ltmap);
extern void SwigType_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl);
extern SwigType *SwigType_template_deftype(const SwigType *type, Symtab *tscope);
/* --- Type-system managment --- */
extern void SwigType_typesystem_init(void);
- extern int SwigType_typedef(SwigType *type, const_String_or_char_ptr name);
+ extern int SwigType_typedef(const SwigType *type, const_String_or_char_ptr name);
extern int SwigType_typedef_class(const_String_or_char_ptr name);
extern int SwigType_typedef_using(const_String_or_char_ptr qname);
extern void SwigType_inherit(String *subclass, String *baseclass, String *cast, String *conversioncode);
- extern int SwigType_issubtype(SwigType *subtype, SwigType *basetype);
+ extern int SwigType_issubtype(const SwigType *subtype, const SwigType *basetype);
extern void SwigType_scope_alias(String *aliasname, Typetab *t);
extern void SwigType_using_scope(Typetab *t);
extern void SwigType_new_scope(const_String_or_char_ptr name);
@@ -197,17 +196,17 @@ extern "C" {
extern Typetab *SwigType_set_scope(Typetab *h);
extern void SwigType_print_scope(Typetab *t);
extern SwigType *SwigType_typedef_resolve(const SwigType *t);
- extern SwigType *SwigType_typedef_resolve_all(SwigType *t);
- extern SwigType *SwigType_typedef_qualified(SwigType *t);
- extern int SwigType_istypedef(SwigType *t);
- extern int SwigType_isclass(SwigType *t);
+ extern SwigType *SwigType_typedef_resolve_all(const SwigType *t);
+ extern SwigType *SwigType_typedef_qualified(const SwigType *t);
+ extern int SwigType_istypedef(const SwigType *t);
+ extern int SwigType_isclass(const SwigType *t);
extern void SwigType_attach_symtab(Symtab *syms);
- extern void SwigType_remember(SwigType *t);
- extern void SwigType_remember_clientdata(SwigType *t, const_String_or_char_ptr clientdata);
+ extern void SwigType_remember(const SwigType *t);
+ extern void SwigType_remember_clientdata(const SwigType *t, const_String_or_char_ptr clientdata);
extern void SwigType_remember_mangleddata(String *mangled, const_String_or_char_ptr clientdata);
- extern void (*SwigType_remember_trace(void (*tf) (SwigType *, String *, String *))) (SwigType *, String *, String *);
+ extern void (*SwigType_remember_trace(void (*tf) (const SwigType *, String *, String *))) (const SwigType *, String *, String *);
extern void SwigType_emit_type_table(File *f_headers, File *f_table);
- extern int SwigType_type(SwigType *t);
+ extern int SwigType_type(const SwigType *t);
/* --- Symbol table module --- */
@@ -240,7 +239,7 @@ extern "C" {
extern void Swig_symbol_inherit(Symtab *tab);
extern SwigType *Swig_symbol_type_qualify(const SwigType *ty, Symtab *tab);
extern String *Swig_symbol_string_qualify(String *s, Symtab *tab);
- extern SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab);
+ extern SwigType *Swig_symbol_typedef_reduce(const SwigType *ty, Symtab *tab);
extern ParmList *Swig_symbol_template_defargs(Parm *parms, Parm *targs, Symtab *tscope, Symtab *tsdecl);
extern SwigType *Swig_symbol_template_deftype(const SwigType *type, Symtab *tscope);
diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c
index b5e114683..4ec18e8c7 100644
--- a/Source/Swig/symbol.c
+++ b/Source/Swig/symbol.c
@@ -1642,7 +1642,7 @@ SwigType *Swig_symbol_template_reduce(SwigType *qt, Symtab *ntab) {
* Chase a typedef through symbol tables looking for a match.
* ----------------------------------------------------------------------------- */
-SwigType *Swig_symbol_typedef_reduce(SwigType *ty, Symtab *tab) {
+SwigType *Swig_symbol_typedef_reduce(const SwigType *ty, Symtab *tab) {
SwigType *prefix, *base;
Node *n;
String *nt;
diff --git a/Source/Swig/typeobj.c b/Source/Swig/typeobj.c
index 074bbf904..dd8d901e0 100644
--- a/Source/Swig/typeobj.c
+++ b/Source/Swig/typeobj.c
@@ -210,7 +210,7 @@ SwigType *SwigType_pop(SwigType *t) {
* Returns the parameter of an operator as a string
* ----------------------------------------------------------------------------- */
-String *SwigType_parm(SwigType *t) {
+String *SwigType_parm(const SwigType *t) {
char *start, *c;
int nparens = 0;
@@ -362,7 +362,7 @@ SwigType *SwigType_del_pointer(SwigType *t) {
return t;
}
-int SwigType_ispointer(SwigType *t) {
+int SwigType_ispointer(const SwigType *t) {
char *c;
if (!t)
return 0;
@@ -404,7 +404,7 @@ SwigType *SwigType_del_reference(SwigType *t) {
return t;
}
-int SwigType_isreference(SwigType *t) {
+int SwigType_isreference(const SwigType *t) {
char *c;
if (!t)
return 0;
@@ -494,7 +494,7 @@ SwigType *SwigType_del_qualifier(SwigType *t) {
return t;
}
-int SwigType_isqualifier(SwigType *t) {
+int SwigType_isqualifier(const SwigType *t) {
char *c;
if (!t)
return 0;
@@ -509,7 +509,7 @@ int SwigType_isqualifier(SwigType *t) {
* Function Pointers
* ----------------------------------------------------------------------------- */
-int SwigType_isfunctionpointer(SwigType *t) {
+int SwigType_isfunctionpointer(const SwigType *t) {
char *c;
if (!t)
return 0;
@@ -562,7 +562,7 @@ SwigType *SwigType_del_memberpointer(SwigType *t) {
return t;
}
-int SwigType_ismemberpointer(SwigType *t) {
+int SwigType_ismemberpointer(const SwigType *t) {
char *c;
if (!t)
return 0;
@@ -606,7 +606,7 @@ SwigType *SwigType_del_array(SwigType *t) {
return t;
}
-int SwigType_isarray(SwigType *t) {
+int SwigType_isarray(const SwigType *t) {
char *c;
if (!t)
return 0;
@@ -622,7 +622,7 @@ int SwigType_isarray(SwigType *t) {
* Determine if the type is a 1D array type that is treated as a pointer within SWIG
* eg Foo[], Foo[3] return true, but Foo[3][3], Foo*[], Foo*[3], Foo**[] return false
*/
-int SwigType_prefix_is_simple_1D_array(SwigType *t) {
+int SwigType_prefix_is_simple_1D_array(const SwigType *t) {
char *c = Char(t);
if (c && (strncmp(c, "a(", 2) == 0)) {
@@ -648,7 +648,7 @@ SwigType *SwigType_pop_arrays(SwigType *t) {
}
/* Return number of array dimensions */
-int SwigType_array_ndim(SwigType *t) {
+int SwigType_array_ndim(const SwigType *t) {
int ndim = 0;
char *c = Char(t);
@@ -661,7 +661,7 @@ int SwigType_array_ndim(SwigType *t) {
}
/* Get nth array dimension */
-String *SwigType_array_getdim(SwigType *t, int n) {
+String *SwigType_array_getdim(const SwigType *t, int n) {
char *c = Char(t);
while (c && (strncmp(c, "a(", 2) == 0) && (n > 0)) {
c = strchr(c, '.');
@@ -713,7 +713,7 @@ void SwigType_array_setdim(SwigType *t, int n, const_String_or_char_ptr rep) {
}
/* Return base type of an array */
-SwigType *SwigType_array_type(SwigType *ty) {
+SwigType *SwigType_array_type(const SwigType *ty) {
SwigType *t;
t = Copy(ty);
while (SwigType_isarray(t)) {
@@ -771,7 +771,7 @@ SwigType *SwigType_pop_function(SwigType *t) {
return g;
}
-int SwigType_isfunction(SwigType *t) {
+int SwigType_isfunction(const SwigType *t) {
char *c;
if (!t) {
return 0;
@@ -793,7 +793,7 @@ int SwigType_isfunction(SwigType *t) {
/* Create a list of parameters from the type t, using the file_line_node Node for
* file and line numbering for the parameters */
-ParmList *SwigType_function_parms(SwigType *t, Node *file_line_node) {
+ParmList *SwigType_function_parms(const SwigType *t, Node *file_line_node) {
List *l = SwigType_parmlist(t);
Hash *p, *pp = 0, *firstp = 0;
Iterator o;
@@ -1094,7 +1094,7 @@ String *SwigType_prefix(const SwigType *t) {
* Strip all qualifiers from a type and return a new type
* ----------------------------------------------------------------------------- */
-SwigType *SwigType_strip_qualifiers(SwigType *t) {
+SwigType *SwigType_strip_qualifiers(const SwigType *t) {
static Hash *memoize_stripped = 0;
SwigType *r;
List *l;
@@ -1138,7 +1138,7 @@ SwigType *SwigType_strip_qualifiers(SwigType *t) {
* r.p.int => r.p.int
* ----------------------------------------------------------------------------- */
-SwigType *SwigType_strip_single_qualifier(SwigType *t) {
+SwigType *SwigType_strip_single_qualifier(const SwigType *t) {
static Hash *memoize_stripped = 0;
SwigType *r = 0;
List *l;
diff --git a/Source/Swig/typesys.c b/Source/Swig/typesys.c
index 2436e005c..ec4376af4 100644
--- a/Source/Swig/typesys.c
+++ b/Source/Swig/typesys.c
@@ -112,7 +112,7 @@ static Hash *typedef_resolve_cache = 0;
static Hash *typedef_all_cache = 0;
static Hash *typedef_qualified_cache = 0;
-static Typetab *SwigType_find_scope(Typetab *s, String *nameprefix);
+static Typetab *SwigType_find_scope(Typetab *s, const SwigType *nameprefix);
/* common attribute keys, to avoid calling find_key all the times */
@@ -167,7 +167,7 @@ void SwigType_typesystem_init() {
* already defined.
* ----------------------------------------------------------------------------- */
-int SwigType_typedef(SwigType *type, const_String_or_char_ptr name) {
+int SwigType_typedef(const SwigType *type, const_String_or_char_ptr name) {
if (Getattr(current_typetab, name))
return -1; /* Already defined */
if (Strcmp(type, name) == 0) { /* Can't typedef a name to itself */
@@ -414,7 +414,7 @@ void SwigType_print_scope(Typetab *t) {
}
}
-static Typetab *SwigType_find_scope(Typetab *s, String *nameprefix) {
+static Typetab *SwigType_find_scope(Typetab *s, const SwigType *nameprefix) {
Typetab *ss;
String *nnameprefix = 0;
static int check_parent = 1;
@@ -806,7 +806,7 @@ return_result:
* Fully resolve a type down to its most basic datatype
* ----------------------------------------------------------------------------- */
-SwigType *SwigType_typedef_resolve_all(SwigType *t) {
+SwigType *SwigType_typedef_resolve_all(const SwigType *t) {
SwigType *n;
SwigType *r;
@@ -848,7 +848,7 @@ SwigType *SwigType_typedef_resolve_all(SwigType *t) {
* scope, it is left in place.
* ----------------------------------------------------------------------------- */
-SwigType *SwigType_typedef_qualified(SwigType *t) {
+SwigType *SwigType_typedef_qualified(const SwigType *t) {
List *elements;
String *result;
int i, len;
@@ -1049,7 +1049,7 @@ SwigType *SwigType_typedef_qualified(SwigType *t) {
* Checks a typename to see if it is a typedef.
* ----------------------------------------------------------------------------- */
-int SwigType_istypedef(SwigType *t) {
+int SwigType_istypedef(const SwigType *t) {
String *type;
type = SwigType_typedef_resolve(t);
@@ -1150,7 +1150,7 @@ int SwigType_typedef_using(const_String_or_char_ptr name) {
* a class.
* ----------------------------------------------------------------------------- */
-int SwigType_isclass(SwigType *t) {
+int SwigType_isclass(const SwigType *t) {
SwigType *qty, *qtys;
int isclass = 0;
@@ -1186,7 +1186,7 @@ int SwigType_isclass(SwigType *t) {
* everything is based on typemaps.
* ----------------------------------------------------------------------------- */
-int SwigType_type(SwigType *t) {
+int SwigType_type(const SwigType *t) {
char *c;
/* Check for the obvious stuff */
c = Char(t);
@@ -1295,7 +1295,7 @@ int SwigType_type(SwigType *t) {
* %feature("valuewrapper").
* ----------------------------------------------------------------------------- */
-SwigType *SwigType_alttype(SwigType *t, int local_tmap) {
+SwigType *SwigType_alttype(const SwigType *t, int local_tmap) {
Node *n;
SwigType *w = 0;
int use_wrapper = 0;
@@ -1413,7 +1413,7 @@ static Hash *r_clientdata = 0; /* Hash mapping resolved types to client data
static Hash *r_mangleddata = 0; /* Hash mapping mangled types to client data */
static Hash *r_remembered = 0; /* Hash of types we remembered already */
-static void (*r_tracefunc) (SwigType *t, String *mangled, String *clientdata) = 0;
+static void (*r_tracefunc) (const SwigType *t, String *mangled, String *clientdata) = 0;
void SwigType_remember_mangleddata(String *mangled, const_String_or_char_ptr clientdata) {
if (!r_mangleddata) {
@@ -1423,7 +1423,7 @@ void SwigType_remember_mangleddata(String *mangled, const_String_or_char_ptr cli
}
-void SwigType_remember_clientdata(SwigType *t, const_String_or_char_ptr clientdata) {
+void SwigType_remember_clientdata(const SwigType *t, const_String_or_char_ptr clientdata) {
String *mt;
SwigType *lt;
Hash *h;
@@ -1536,12 +1536,12 @@ void SwigType_remember_clientdata(SwigType *t, const_String_or_char_ptr clientda
}
}
-void SwigType_remember(SwigType *ty) {
+void SwigType_remember(const SwigType *ty) {
SwigType_remember_clientdata(ty, 0);
}
-void (*SwigType_remember_trace(void (*tf) (SwigType *, String *, String *))) (SwigType *, String *, String *) {
- void (*o) (SwigType *, String *, String *) = r_tracefunc;
+void (*SwigType_remember_trace(void (*tf) (const SwigType *, String *, String *))) (const SwigType *, String *, String *) {
+ void (*o) (const SwigType *, String *, String *) = r_tracefunc;
r_tracefunc = tf;
return o;
}
@@ -1713,7 +1713,7 @@ void SwigType_inherit(String *derived, String *base, String *cast, String *conve
* Determines if a t1 is a subtype of t2, ie, is t1 derived from t2
* ----------------------------------------------------------------------------- */
-int SwigType_issubtype(SwigType *t1, SwigType *t2) {
+int SwigType_issubtype(const SwigType *t1, const SwigType *t2) {
SwigType *ft1, *ft2;
String *b1, *b2;
Hash *h;
From babfccc072f3222929fbe7be11fad06e4e4786b6 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Wed, 15 Dec 2010 22:00:23 +0000
Subject: [PATCH 054/317] Remove accidental commit of CHANGES.current
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12350 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 22 -------
Source/Swig/stype.c | 148 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 148 insertions(+), 22 deletions(-)
diff --git a/CHANGES.current b/CHANGES.current
index 633745a6f..9449c2f4c 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,28 +5,6 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (in progress)
===========================
-2010-12-08: wsfulton
- The name mangling for some complex types was incorrect. This is now fixed and results
- in types being more interchangeable when there are typedefs involved.
- namespace foo {
- template class bar {};
- typedef int Integer;
- void test2(bar *x) { return x; }
- }
- The typewrapper class for x changes from
- SWIGTYPE_p_foo__barT_int_p_t to
- SWIGTYPE_p_foo__barT_p_int_t.
-
- The name mangling involving qualifiers was not consistent, for example with the const qualifier in
- MyTemplate< const ::DD * > the type wrapper class changes from
- SWIGTYPE_p_MyTemplateT_DD_const_p_t to
- SWIGTYPE_p_MyTemplateT_p_q_const__DD_t
-
- There a number of other subtle name mangling changes not listed. The runtime version
- has hence been changed from 4 to 5.
-
-TODO: write a testcase in Java showing reference_type working or whatever I fixed in STL.
-
2010-12-14: wsfulton
Fix $basemangle expansion in array typemaps. For example if type is int *[3],
$basemangle expands to _p_int.
diff --git a/Source/Swig/stype.c b/Source/Swig/stype.c
index f3a1dc8ca..c2c17e515 100644
--- a/Source/Swig/stype.c
+++ b/Source/Swig/stype.c
@@ -900,6 +900,145 @@ String *SwigType_lcaststr(const SwigType *s, const_String_or_char_ptr name) {
return result;
}
+#if 0
+/* Alternative implementation for manglestr_default. Mangling is similar to the original
+ except for a few subtle differences for example in templates:
+ namespace foo {
+ template class bar {};
+ typedef int Integer;
+ void test2(bar *x);
+ }
+ Mangling is more consistent and changes from
+ _p_foo__barT_int_p_t to
+ _p_foo__barT_p_int_t.
+*/
+static void mangle_stringcopy(String *destination, const char *source, int count) {
+ while (count-- > 0) {
+ char newc = '_';
+ if (!(*source == '.' || *source == ':' || *source == ' '))
+ newc = *source;
+ /* TODO: occasionally '*' or numerics need converting to '_', eg in array dimensions and template expressions */
+ Putc(newc, destination);
+ source++;
+ }
+}
+
+static void mangle_subtype(String *mangled, SwigType *s);
+
+/* -----------------------------------------------------------------------------
+ * mangle_namestr()
+ *
+ * Mangles a type taking care of template expansions. Similar to SwigType_namestr().
+ * The type may include a trailing '.', for example "p."
+ * ----------------------------------------------------------------------------- */
+
+static void mangle_namestr(String *mangled, SwigType *t) {
+ int length = Len(t);
+ if (SwigType_isqualifier(t)) {
+ Append(mangled, "q_");
+ mangle_stringcopy(mangled, Char(t)+2, length-4);
+ Append(mangled, "__");
+ } else if (SwigType_ismemberpointer(t)) {
+ Append(mangled, "m_");
+ mangle_stringcopy(mangled, Char(t)+2, length-4);
+ Append(mangled, "__");
+ } else if (SwigType_isarray(t)) {
+ Append(mangled, "a_");
+ mangle_stringcopy(mangled, Char(t)+2, length-4);
+ Append(mangled, "__");
+ } else if (SwigType_isfunction(t)) {
+ List *p = SwigType_parmlist(t);
+ int sz = Len(p);
+ int i;
+ Append(mangled, "f_");
+ for (i = 0; i < sz; i++) {
+ mangle_subtype(mangled, Getitem(p, i));
+ Putc('_', mangled);
+ }
+ Append(mangled, (sz > 0) ? "_" : "__");
+ } else if (SwigType_isvarargs(t)) {
+ Append(mangled, "___");
+ } else {
+ char *d = Char(t);
+ char *c = strstr(d, "<(");
+ if (!c || !strstr(c + 2, ")>")) {
+ /* not a template type */
+ mangle_stringcopy(mangled, Char(t), Len(t));
+ } else {
+ /* a template type */
+ String *suffix;
+ List *p;
+ int i, sz;
+ mangle_stringcopy(mangled, d, c-d);
+ Putc('T', mangled);
+ Putc('_', mangled);
+
+ p = SwigType_parmlist(c + 1);
+ sz = Len(p);
+ for (i = 0; i < sz; i++) {
+ mangle_subtype(mangled, Getitem(p, i));
+ Putc('_', mangled);
+ }
+ Putc('t', mangled);
+ suffix = SwigType_templatesuffix(t);
+ if (Len(suffix) > 0) {
+ mangle_namestr(mangled, suffix);
+ } else {
+ Append(mangled, suffix);
+ }
+ Delete(suffix);
+ Delete(p);
+ }
+ }
+}
+
+static void mangle_subtype(String *mangled, SwigType *s) {
+ List *elements;
+ int nelements, i;
+
+ assert(s);
+ elements = SwigType_split(s);
+ nelements = Len(elements);
+ for (i = 0; i < nelements; i++) {
+ SwigType *element = Getitem(elements, i);
+ mangle_namestr(mangled, element);
+ }
+ Delete(elements);
+}
+
+static String *manglestr_default(const SwigType *s) {
+ String *mangled = NewString("_");
+ SwigType *sr = SwigType_typedef_resolve_all(s);
+ SwigType *sq = SwigType_typedef_qualified(sr);
+ SwigType *ss = SwigType_remove_global_scope_prefix(sq);
+ SwigType *type = ss;
+ SwigType *lt;
+
+ if (SwigType_istemplate(ss)) {
+ SwigType *ty = Swig_symbol_template_deftype(ss, 0);
+ Delete(ss);
+ ss = ty;
+ type = ss;
+ }
+
+ lt = SwigType_ltype(type);
+
+ Replace(lt, "struct ", "", DOH_REPLACE_ANY);
+ Replace(lt, "class ", "", DOH_REPLACE_ANY);
+ Replace(lt, "union ", "", DOH_REPLACE_ANY);
+ Replace(lt, "enum ", "", DOH_REPLACE_ANY);
+
+ mangle_subtype(mangled, lt);
+
+ Delete(ss);
+ Delete(sq);
+ Delete(sr);
+
+ return mangled;
+}
+
+#else
+
static String *manglestr_default(const SwigType *s) {
char *c;
String *result = 0;
@@ -969,8 +1108,17 @@ static String *manglestr_default(const SwigType *s) {
Delete(sr);
return result;
}
+#endif
String *SwigType_manglestr(const SwigType *s) {
+#if 0
+ /* Debugging checks to ensure a proper SwigType is passed in and not a stringified type */
+ String *angle = Strstr(s, "<");
+ if (angle && Strncmp(angle, "<(", 2) != 0)
+ Printf(stderr, "SwigType_manglestr error: %s\n", s);
+ else if (Strstr(s, "*") || Strstr(s, "&") || Strstr(s, "["))
+ Printf(stderr, "SwigType_manglestr error: %s\n", s);
+#endif
return manglestr_default(s);
}
From dd465f9588ed9575470b0cc08fd3b605e3ba240d Mon Sep 17 00:00:00 2001
From: Stefan Zager
Date: Wed, 15 Dec 2010 23:04:20 +0000
Subject: [PATCH 055/317] Finished std::pair and std::map support.
li_std_pair_extra test fails, because the _runme.py uses the
secret 'this' member variable, which doesn't exist when the
-builtin option is used. Seems like a flaw in the test.
Test suite now fails on li_std_string_extra, because static
member variables are not fully implemented.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12351 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/python/builtin.swg | 31 +-
Lib/python/pycontainer.swg | 38 +-
Lib/python/pyiterators.swg | 2 +-
Lib/python/pyrun.swg | 9 +
Lib/python/std_map.i | 63 +-
Lib/python/std_pair.i | 50 ++
Source/Modules/python.cxx | 1324 ++++++++++++++++++------------------
7 files changed, 827 insertions(+), 690 deletions(-)
diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg
index f99e25890..7a5ad8664 100644
--- a/Lib/python/builtin.swg
+++ b/Lib/python/builtin.swg
@@ -31,7 +31,7 @@ SWIGINTERN Py_ssize_t \
wrapper##_closure (PyObject *a) \
{ \
PyObject *resultobj = wrapper(a, NULL); \
- Py_ssize_t result = _PyLong_AsSsize_t(resultobj); \
+ Py_ssize_t result = PyNumber_AsSsize_t(resultobj, NULL); \
Py_DECREF(resultobj); \
return result; \
}
@@ -53,12 +53,14 @@ wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c) \
SWIGINTERN int \
wrapper##_closure (PyObject *a, Py_ssize_t b, Py_ssize_t c, PyObject *d) \
{ \
- PyObject *tuple = PyTuple_New(3); \
+ PyObject *tuple = PyTuple_New(d ? 3 : 2); \
assert(tuple); \
PyTuple_SET_ITEM(tuple, 0, _PyLong_FromSsize_t(b)); \
PyTuple_SET_ITEM(tuple, 1, _PyLong_FromSsize_t(c)); \
- PyTuple_SET_ITEM(tuple, 2, d); \
- Py_XINCREF(d); \
+ if (d) { \
+ PyTuple_SET_ITEM(tuple, 2, d); \
+ Py_INCREF(d); \
+ } \
PyObject *resultobj = wrapper(a, tuple); \
int result = resultobj ? 0 : -1; \
Py_DECREF(tuple); \
@@ -94,6 +96,25 @@ wrapper##_closure (PyObject *a, Py_ssize_t b, PyObject *c) \
return result; \
}
+#define PYSWIG_OBJOBJARGPROC_CLOSURE(wrapper) \
+SWIGINTERN int \
+wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \
+{ \
+ PyObject *tuple = PyTuple_New(c ? 2 : 1); \
+ assert(tuple); \
+ PyTuple_SET_ITEM(tuple, 0, b); \
+ Py_XINCREF(b); \
+ if (c) { \
+ PyTuple_SET_ITEM(tuple, 1, c); \
+ Py_XINCREF(c); \
+ } \
+ PyObject *resultobj = wrapper(a, tuple); \
+ int result = resultobj ? 0 : -1; \
+ Py_XDECREF(resultobj); \
+ Py_DECREF(tuple); \
+ return result; \
+}
+
#ifdef __cplusplus
namespace {
@@ -105,6 +126,8 @@ template struct PySwigBuiltin : public SwigPyObject {
typedef obj_type* pointer;
typedef obj_type& reference;
+ static PyObject* richcompare (PyObject *self, PyObject *other, int op);
+
static PyMethodDef methods[];
static PyGetSetDef getset[];
static PyNumberMethods number_methods;
diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg
index 5578f1af9..cd38eeee1 100644
--- a/Lib/python/pycontainer.swg
+++ b/Lib/python/pycontainer.swg
@@ -245,7 +245,7 @@ namespace swig {
template
inline void
- setslice(Sequence* self, Difference i, Difference j, const InputSeq& v) {
+ setslice(Sequence* self, Difference i, Difference j, const InputSeq& v = InputSeq()) {
typename Sequence::size_type size = self->size();
typename Sequence::size_type ii = swig::check_index(i, size, true);
typename Sequence::size_type jj = swig::slice_index(j, size);
@@ -580,18 +580,18 @@ namespace swig
%fragment("SwigPySequence_Cont");
-# if defined(SWIGPYTHON_BUILTIN)
- %feature("tp_iter") Sequence "&swig::make_output_iterator_builtin< Sequence >";
-# else
%newobject iterator(PyObject **PYTHON_SELF);
%extend {
swig::SwigPyIterator* iterator(PyObject **PYTHON_SELF) {
return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
- %pythoncode {def __iter__(self): return self.iterator()}
+#if defined(SWIGPYTHON_BUILTIN)
+ %feature("pyslot", "tp_iter", functype="getiterfunc") iterator;
+#else
+ %pythoncode {def __iter__(self): return self.iterator()}
+#endif
}
-# endif // SWIGPYTHON_BUILTIN
#endif //SWIG_EXPORT_ITERATOR_METHODS
%enddef
@@ -603,6 +603,11 @@ namespace swig
%newobject __getslice__;
+#if defined(SWIGPYTHON_BUILTIN)
+ %feature("pyslot", "nb_nonzero", functype="unaryfunc") __nonzero__;
+ %feature("pyslot", "sq_length", functype="lenfunc") __len__;
+#endif // SWIGPYTHON_BUILTIN
+
%extend {
bool __nonzero__() const {
return !(self->empty());
@@ -618,11 +623,6 @@ namespace swig
}
}
-#if defined(SWIGPYTHON_BUILTIN)
-%pybinoperator(__nonzero__, __nonzero__, unaryfunc, nb_nonzero);
-%pybinoperator(__len__, __len__, lenfunc, sq_length);
-#endif // SWIGPYTHON_BUILTIN
-
%enddef
@@ -633,6 +633,13 @@ namespace swig
%fragment("SwigPySequence_Base");
+#if defined(SWIGPYTHON_BUILTIN)
+ %feature("pyslot", "sq_item", functype="ssizeargfunc") __getitem__;
+ %feature("pyslot", "sq_slice", functype="ssizessizeargfunc") __getslice__;
+ %feature("pyslot", "sq_ass_item", functype="ssizeobjargproc") __setitem__;
+ %feature("pyslot", "sq_ass_slice", functype="ssizessizeobjargproc") __setslice__;
+#endif // SWIGPYTHON_BUILTIN
+
%extend {
value_type pop() throw (std::out_of_range) {
if (self->size() == 0)
@@ -654,7 +661,7 @@ namespace swig
return swig::getslice(self, i, j);
}
- void __setslice__(difference_type i, difference_type j, const Sequence& v)
+ void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence())
throw (std::out_of_range, std::invalid_argument) {
swig::setslice(self, i, j, v);
}
@@ -705,13 +712,6 @@ namespace swig
}
-#if defined(SWIGPYTHON_BUILTIN)
-%pybinoperator(__getitem__, __getitem__, ssizeargfunc, sq_item);
-%pybinoperator(__getslice__, __getslice__, ssizessizeargfunc, sq_slice);
-%pybinoperator(__setitem__, __setitem__, ssizeobjargproc, sq_ass_item);
-%pybinoperator(__setslice__, __setslice__, ssizessizeobjargproc, sq_ass_slice);
-#endif // SWIGPYTHON_BUILTIN
-
%enddef
%define %swig_sequence_methods(Sequence...)
diff --git a/Lib/python/pyiterators.swg b/Lib/python/pyiterators.swg
index ecbc54270..d5ca73ec8 100644
--- a/Lib/python/pyiterators.swg
+++ b/Lib/python/pyiterators.swg
@@ -350,6 +350,7 @@ namespace swig
#if defined(SWIGPYTHON_BUILTIN)
%feature("tp_iter") SwigPyIterator "&swig::make_output_iterator_builtin";
+ %feature("pyslot", "tp_iternext", functype="iternextfunc") SwigPyIterator::__next__;
#else
%extend SwigPyIterator {
%pythoncode {def __iter__(self): return self}
@@ -370,7 +371,6 @@ namespace swig
%catches(swig::stop_iteration) SwigPyIterator::operator + (ptrdiff_t n) const;
%catches(swig::stop_iteration) SwigPyIterator::operator - (ptrdiff_t n) const;
-
struct SwigPyIterator
{
protected:
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index 3f93c4575..96fdcf085 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -465,8 +465,17 @@ SwigPyObject_type(void) {
SWIGRUNTIMEINLINE int
SwigPyObject_Check(PyObject *op) {
+#ifdef SWIGPYTHON_BUILTIN
+ PyTypeObject *target_tp = SwigPyObject_type();
+ PyTypeObject *obj_tp;
+ for (obj_tp = op->ob_type; obj_tp; obj_tp = obj_tp->tp_base)
+ if (obj_tp == target_tp)
+ return 1;
+ return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0);
+#else
return (Py_TYPE(op) == SwigPyObject_type())
|| (strcmp(Py_TYPE(op)->tp_name,"SwigPyObject") == 0);
+#endif
}
SWIGRUNTIME PyObject *
diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i
index 074c43180..8f06a97d9 100644
--- a/Lib/python/std_map.i
+++ b/Lib/python/std_map.i
@@ -119,6 +119,17 @@
return new SwigPyMapKeyIterator_T(current, begin, end, seq);
}
+ template
+ inline PyObject* make_output_key_iterator_builtin (PyObject *pyself)
+ {
+ SwigPyObject *builtin_obj = (SwigPyObject*) pyself;
+ Sequence *seq = reinterpret_cast< Sequence * >(builtin_obj->ptr);
+ if (!seq)
+ return SWIG_Py_Void();
+ SwigPyIterator *iter = make_output_key_iterator(seq->begin(), seq->begin(), seq->end(), pyself);
+ return SWIG_NewPointerObj(iter, SWIGTYPE_p_swig__SwigPyIterator, SWIG_POINTER_OWN);
+ }
+
template >
struct SwigPyMapValueITerator_T : SwigPyMapIterator_T
@@ -136,6 +147,7 @@
{
return new SwigPyMapValueITerator_T(current, begin, end, seq);
}
+
}
}
@@ -143,6 +155,37 @@
%swig_sequence_iterator(Map);
%swig_container_methods(Map)
+#if defined(SWIGPYTHON_BUILTIN)
+ %feature("pyslot", "mp_length", functype="lenfunc") __len__;
+ %feature("pyslot", "mp_subscript", functype="binaryfunc") __getitem__;
+ %feature("tp_iter") Map "&swig::make_output_key_iterator_builtin< Map >";
+
+ %extend {
+ %newobject iterkeys(PyObject **PYTHON_SELF);
+ swig::SwigPyIterator* iterkeys(PyObject **PYTHON_SELF) {
+ return swig::make_output_key_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
+ }
+
+ %newobject itervalues(PyObject **PYTHON_SELF);
+ swig::SwigPyIterator* itervalues(PyObject **PYTHON_SELF) {
+ return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
+ }
+
+ %newobject iteritems(PyObject **PYTHON_SELF);
+ swig::SwigPyIterator* iteritems(PyObject **PYTHON_SELF) {
+ return swig::make_output_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
+ }
+ }
+
+#else
+ %extend {
+ %pythoncode {def __iter__(self): return self.key_iterator()}
+ %pythoncode {def iterkeys(self): return self.key_iterator()}
+ %pythoncode {def itervalues(self): return self.value_iterator()}
+ %pythoncode {def iteritems(self): return self.iterator()}
+ }
+#endif
+
%extend {
mapped_type __getitem__(const key_type& key) const throw (std::out_of_range) {
Map::const_iterator i = self->find(key);
@@ -151,7 +194,7 @@
else
throw std::out_of_range("key not found");
}
-
+
void __delitem__(const key_type& key) throw (std::out_of_range) {
Map::iterator i = self->find(key);
if (i != self->end())
@@ -236,16 +279,24 @@
swig::SwigPyIterator* value_iterator(PyObject **PYTHON_SELF) {
return swig::make_output_value_iterator(self->begin(), self->begin(), self->end(), *PYTHON_SELF);
}
-
- %pythoncode {def __iter__(self): return self.key_iterator()}
- %pythoncode {def iterkeys(self): return self.key_iterator()}
- %pythoncode {def itervalues(self): return self.value_iterator()}
- %pythoncode {def iteritems(self): return self.iterator()}
}
+
%enddef
%define %swig_map_methods(Map...)
%swig_map_common(Map)
+
+#if defined(SWIGPYTHON_BUILTIN)
+ %feature("pyslot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
+
+ %extend {
+ // This will be called through the mp_ass_subscript slot to delete an entry.
+ void __setitem__(const key_type& key) {
+ self->erase(key);
+ }
+ }
+#endif
+
%extend {
void __setitem__(const key_type& key, const mapped_type& x) throw (std::out_of_range) {
(*self)[key] = x;
diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i
index bc8ccaade..4cc8fe5c2 100644
--- a/Lib/python/std_pair.i
+++ b/Lib/python/std_pair.i
@@ -116,9 +116,58 @@
}
};
}
+
+#if defined(SWIGPYTHON_BUILTIN)
+SWIGINTERN Py_ssize_t
+SwigPython_std_pair_len (PyObject *a)
+{
+ return 2;
+}
+
+SWIGINTERN PyObject*
+SwigPython_std_pair_repr (PyObject *o)
+{
+ static PyObject *first = PyString_FromString("first");
+ static PyObject *second = PyString_FromString("second");
+ PyObject *tuple = PyTuple_New(2);
+ assert(tuple);
+ PyTuple_SET_ITEM(tuple, 0, PyObject_GetAttr(o, first));
+ PyTuple_SET_ITEM(tuple, 1, PyObject_GetAttr(o, second));
+ PyObject *result = PyObject_Repr(tuple);
+ Py_DECREF(tuple);
+ return result;
+}
+
+SWIGINTERN PyObject*
+SwigPython_std_pair_getitem (PyObject *a, Py_ssize_t b)
+{
+ static PyObject *first = PyString_FromString("first");
+ static PyObject *second = PyString_FromString("second");
+ PyObject *attr_name = b % 2 ? second : first;
+ PyObject *result = PyObject_GetAttr(a, attr_name);
+ return result;
+}
+
+SWIGINTERN int
+SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c)
+{
+ static PyObject *first = PyString_FromString("first");
+ static PyObject *second = PyString_FromString("second");
+ PyObject *attr_name = b % 2 ? second : first;
+ int result = PyObject_SetAttr(a, attr_name, c);
+ return result;
+}
+#endif
+
}
%define %swig_pair_methods(pair...)
+#if defined(SWIGPYTHON_BUILTIN)
+%feature("sq_length") pair "SwigPython_std_pair_len";
+%feature("tp_repr") pair "SwigPython_std_pair_repr";
+%feature("sq_item") pair "SwigPython_std_pair_getitem";
+%feature("sq_ass_item") pair "SwigPython_std_pair_setitem";
+#else
%extend {
%pythoncode {def __len__(self): return 2
def __repr__(self): return str((self.first, self.second))
@@ -133,6 +182,7 @@ def __setitem__(self, index, val):
else:
self.second = val}
}
+#endif
%enddef
%include
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 6dbaf0ea0..1a4209092 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -48,6 +48,7 @@ static String *f_shadow_imports = 0;
static String *f_shadow_import_stmts = 0;
static String *f_shadow_stubs = 0;
static Hash *builtin_getset = 0;
+static String *builtin_richcompare = 0;
static String *methods;
static String *class_name;
@@ -164,37 +165,34 @@ static const char *usage3 = (char *) "\
Function annotation \n\
\n";
-static String*
-getSlot (Node *n, const char *key)
-{
+static String *getSlot(Node *n, const char *key) {
static String *slot_default = NewString("0");
String *val = Getattr(n, key);
return val ? val : slot_default;
}
-static String*
-getClosure (String *functype, String *wrapper)
-{
- static const char *functypes[] = {
- "binaryfunc", "PYSWIG_BINARYFUNC_CLOSURE",
- "ternaryfunc", "PYSWIG_TERNARYFUNC_CLOSURE",
- "lenfunc", "PYSWIG_LENFUNC_CLOSURE",
- "ssizeargfunc", "PYSWIG_SSIZEARGFUNC_CLOSURE",
- "ssizessizeargfunc", "PYSWIG_SSIZESSIZEARGFUNC_CLOSURE",
- "ssizeobjargproc", "PYSWIG_SSIZEOBJARGPROC_CLOSURE",
- "ssizessizeobjargproc", "PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE",
- NULL
- };
+static String *getClosure(String *functype, String *wrapper) {
+ static const char *functypes[] = {
+ "binaryfunc", "PYSWIG_BINARYFUNC_CLOSURE",
+ "ternaryfunc", "PYSWIG_TERNARYFUNC_CLOSURE",
+ "lenfunc", "PYSWIG_LENFUNC_CLOSURE",
+ "ssizeargfunc", "PYSWIG_SSIZEARGFUNC_CLOSURE",
+ "ssizessizeargfunc", "PYSWIG_SSIZESSIZEARGFUNC_CLOSURE",
+ "ssizeobjargproc", "PYSWIG_SSIZEOBJARGPROC_CLOSURE",
+ "ssizessizeobjargproc", "PYSWIG_SSIZESSIZEOBJARGPROC_CLOSURE",
+ "objobjargproc", "PYSWIG_OBJOBJARGPROC_CLOSURE",
+ NULL
+ };
- if (!functype)
- return NULL;
- char *c = Char(functype);
- int i;
- for (i = 0; functypes[i] != NULL; i += 2) {
- if (!strcmp(c, functypes[i]))
- return NewStringf("%s(%s)", functypes[i+1], wrapper);
- }
+ if (!functype)
return NULL;
+ char *c = Char(functype);
+ int i;
+ for (i = 0; functypes[i] != NULL; i += 2) {
+ if (!strcmp(c, functypes[i]))
+ return NewStringf("%s(%s)", functypes[i + 1], wrapper);
+ }
+ return NULL;
}
class PYTHON:public Language {
@@ -209,16 +207,11 @@ public:
director_multiple_inheritance = 1;
director_language = 1;
}
-
/* ------------------------------------------------------------
* Thread Implementation
- * ------------------------------------------------------------ */
-
- int threads_enable(Node *n) const {
+ * ------------------------------------------------------------ */ int threads_enable(Node *n) const {
return threads && !GetFlagAttr(n, "feature:nothread");
- }
-
- int initialize_threads(String *f_init) {
+ } int initialize_threads(String *f_init) {
if (!threads) {
return SWIG_OK;
}
@@ -480,9 +473,9 @@ public:
Preprocessor_define("SWIGPYTHON_BUILTIN", 0);
Swig_mark_arg(i);
}
-
+
}
- } /* for */
+ } /* for */
if (py3) {
/* force disable features that not compatible with Python 3.x */
@@ -579,6 +572,7 @@ public:
f_directors_h = NewString("");
f_directors = NewString("");
builtin_getset = NewHash();
+ builtin_richcompare = NewString("");
if (builtin) {
f_builtins = NewString("");
@@ -812,7 +806,7 @@ public:
}
if (modern || !classic) {
Printv(f_shadow, "try:\n", tab4, "_swig_property = property\n", "except NameError:\n", tab4, "pass # Python < 2.2 doesn't have 'property'.\n", NULL);
- }
+ }
/* if (!modern) */
/* always needed, a class can be forced to be no-modern, such as an exception */
{
@@ -851,11 +845,10 @@ public:
* But don't sure wether this would broken old Python?
*/
Printv(f_shadow,
- // "import types\n",
+ // "import types\n",
"try:\n",
- // " _object = types.ObjectType\n",
- " _object = object\n",
- " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
+ // " _object = types.ObjectType\n",
+ " _object = object\n", " _newclass = 1\n", "except AttributeError:\n", " class _object : pass\n", " _newclass = 0\n",
// "del types\n",
"\n\n", NIL);
}
@@ -878,7 +871,6 @@ public:
"try:\n", tab4, "import weakref\n", tab4, "weakref_proxy = weakref.proxy\n", "except:\n", tab4, "weakref_proxy = lambda x: x\n", "\n\n", NIL);
}
}
-
// Include some information in the code
Printf(f_header, "\n/*-----------------------------------------------\n @(target):= %s.so\n\
------------------------------------------------*/\n", module);
@@ -974,15 +966,14 @@ public:
return SWIG_OK;
}
-
+
/* ------------------------------------------------------------
* Emit the wrapper for PyInstanceMethod_New to MethodDef array.
* This wrapper is used to implement -fastproxy,
* as a replacement of new.instancemethod in Python 3.
* ------------------------------------------------------------ */
- int add_pyinstancemethod_new()
- {
- String* name = NewString("SWIG_PyInstanceMethod_New");
+ int add_pyinstancemethod_new() {
+ String *name = NewString("SWIG_PyInstanceMethod_New");
Printf(methods, "\t { (char *)\"%s\", (PyCFunction)%s, METH_O, NULL},\n", name, name);
Delete(name);
return 0;
@@ -1243,12 +1234,12 @@ public:
String *pn = Swig_name_make(p, 0, Getattr(p, "name"), 0, 0);
// Use C parameter name unless it is a duplicate or an empty parameter name
int count = 0;
- if ( SwigType_isvarargs(Getattr(p, "type")) ) {
+ if (SwigType_isvarargs(Getattr(p, "type"))) {
return NewString("*args");
}
while (plist) {
if ((Cmp(pn, Getattr(plist, "name")) == 0))
- count++;
+ count++;
plist = nextSibling(plist);
}
arg = (!pn || !Len(pn) || (count > 1)) ? NewStringf("arg%d", arg_num) : Copy(pn);
@@ -1263,43 +1254,43 @@ public:
* func_annotation: Function annotation support
* ------------------------------------------------------------ */
- String *make_autodocParmList(Node *n, bool showTypes, bool calling=false, bool func_annotation=false) {
+ String *make_autodocParmList(Node *n, bool showTypes, bool calling = false, bool func_annotation = false) {
+
-
String *doc = NewString("");
String *pdocs = Copy(Getattr(n, "feature:pdocs"));
ParmList *plist = CopyParmList(Getattr(n, "parms"));
Parm *p;
Parm *pnext;
- Node *lookup;
+ Node *lookup;
int lines = 0;
int arg_num = 0;
const int maxwidth = 50;
- if(calling)
+ if (calling)
func_annotation = false;
-
+
if (pdocs)
Append(pdocs, "\n");
Swig_typemap_attach_parms("in", plist, 0);
Swig_typemap_attach_parms("doc", plist, 0);
-
- if (Strcmp(ParmList_protostr(plist), "void")==0) {
+
+ if (Strcmp(ParmList_protostr(plist), "void") == 0) {
//No parameters actually
return doc;
}
-
+
for (p = plist; p; p = pnext) {
String *tm = Getattr(p, "tmap:in");
if (tm) {
pnext = Getattr(p, "tmap:in:next");
- if (checkAttribute(p, "tmap:in:numinputs", "0")) {
- continue;
- }
+ if (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ continue;
+ }
} else {
pnext = nextSibling(p);
}
@@ -1339,40 +1330,39 @@ public:
lines += 1;
}
}
-
+
type = SwigType_base(type);
lookup = Swig_symbol_clookup(type, 0);
if (lookup)
- type = Getattr(lookup, "sym:name");
-
+ type = Getattr(lookup, "sym:name");
+
// Do the param type too?
if (showTypes)
- Printf(doc, "%s ", type);
+ Printf(doc, "%s ", type);
+
-
Append(doc, name);
if (pdoc) {
- if (!pdocs)
- pdocs = NewString("Parameters:\n");
- Printf(pdocs, " %s\n", pdoc);
+ if (!pdocs)
+ pdocs = NewString("Parameters:\n");
+ Printf(pdocs, " %s\n", pdoc);
}
-
// Write the function annoation
if (func_annotation)
- Printf(doc, " : '%s'", type);
+ Printf(doc, " : '%s'", type);
// Write default value
if (value && !calling) {
- String* pv = pyvalue(value, Getattr(p, "type"));
- if (pv)
- value = pv;
+ String *pv = pyvalue(value, Getattr(p, "type"));
+ if (pv)
+ value = pv;
else {
lookup = Swig_symbol_clookup(value, 0);
if (lookup) {
value = Getattr(lookup, "sym:name");
- }
+ }
}
- Printf(doc, " = %s", value);
+ Printf(doc, " = %s", value);
}
}
if (pdocs)
@@ -1501,7 +1491,6 @@ public:
Printv(doc, "\n", pdocs, NULL);
}
}
-
// if it's overloaded then get the next decl and loop around again
n = Getattr(n, "sym:nextSibling");
if (n)
@@ -1510,29 +1499,28 @@ public:
return doc;
}
-
+
/* ------------------------------------------------------------
* pyvalue()
* Check if string v can be a Python value literal,
* (eg. number or string), or translate it to a Python literal.
* ------------------------------------------------------------ */
- String* pyvalue(String *v, SwigType *t)
- {
- if (v && Len(v)>0) {
+ String *pyvalue(String *v, SwigType *t) {
+ if (v && Len(v) > 0) {
char fc = (Char(v))[0];
- if (('0'<=fc && fc<='9') || '\''==fc || '"'==fc) {
- /* number or string (or maybe NULL pointer)*/
- if (SwigType_ispointer(t) && Strcmp(v, "0")==0)
- return NewString("None");
- else
- return v;
+ if (('0' <= fc && fc <= '9') || '\'' == fc || '"' == fc) {
+ /* number or string (or maybe NULL pointer) */
+ if (SwigType_ispointer(t) && Strcmp(v, "0") == 0)
+ return NewString("None");
+ else
+ return v;
}
- if (Strcmp(v, "true")==0 || Strcmp(v, "FALSE")==0)
- return NewString("True");
- if (Strcmp(v, "false")==0 || Strcmp(v, "FALSE")==0)
- return NewString("False");
- if (Strcmp(v, "NULL")==0)
- return NewString("None");
+ if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0)
+ return NewString("True");
+ if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
+ return NewString("False");
+ if (Strcmp(v, "NULL") == 0)
+ return NewString("None");
}
return 0;
}
@@ -1542,8 +1530,7 @@ public:
* (So we can generate proper parameter list with default
* values..)
* ------------------------------------------------------------ */
- bool is_primitive_defaultargs(Node *n)
- {
+ bool is_primitive_defaultargs(Node *n) {
ParmList *plist = CopyParmList(Getattr(n, "parms"));
Parm *p;
Parm *pnext;
@@ -1552,17 +1539,17 @@ public:
for (p = plist; p; p = pnext) {
String *tm = Getattr(p, "tmap:in");
if (tm) {
- pnext = Getattr(p, "tmap:in:next");
- if (checkAttribute(p, "tmap:in:numinputs", "0")) {
- continue;
- }
+ pnext = Getattr(p, "tmap:in:next");
+ if (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ continue;
+ }
} else {
- pnext = nextSibling(p);
+ pnext = nextSibling(p);
}
String *type = Getattr(p, "type");
String *value = Getattr(p, "value");
if (!pyvalue(value, type))
- return false;
+ return false;
}
return true;
}
@@ -1574,20 +1561,19 @@ public:
* siblings generated due to the original function have
* default arguments.
* ------------------------------------------------------------ */
- bool is_real_overloaded(Node *n)
- {
+ bool is_real_overloaded(Node *n) {
Node *h = Getattr(n, "sym:overloaded");
Node *i;
if (!h)
return false;
-
+
i = Getattr(h, "sym:nextSibling");
while (i) {
Node *nn = Getattr(i, "defaultargs");
if (nn != h) {
- /* Check if overloaded function has defaultargs and
- * pointed to the first overloaded. */
- return true;
+ /* Check if overloaded function has defaultargs and
+ * pointed to the first overloaded. */
+ return true;
}
i = Getattr(i, "sym:nextSibling");
}
@@ -1600,37 +1586,33 @@ public:
* Generate parameter list for Python functions or methods,
* reuse make_autodocParmList() to do so.
* ------------------------------------------------------------ */
- String* make_pyParmList(Node *n, bool in_class, bool is_calling, int kw)
- {
+ String *make_pyParmList(Node *n, bool in_class, bool is_calling, int kw) {
/* Get the original function for a defaultargs copy,
* see default_arguments() in parser.y. */
Node *nn = Getattr(n, "defaultargs");
- if (nn) n = nn;
+ if (nn)
+ n = nn;
/* For overloaded function, just use *args */
- if (is_real_overloaded(n) ||
- GetFlag(n, "feature:compactdefaultargs") ||
- !is_primitive_defaultargs(n))
- {
- String *parms = NewString("");
- if(in_class)
- Printf(parms, "self, ");
- Printf(parms, "*args");
- if (kw)
- Printf(parms, ", **kwargs");
- return parms;
- }
+ if (is_real_overloaded(n) || GetFlag(n, "feature:compactdefaultargs") || !is_primitive_defaultargs(n)) {
+ String *parms = NewString("");
+ if (in_class)
+ Printf(parms, "self, ");
+ Printf(parms, "*args");
+ if (kw)
+ Printf(parms, ", **kwargs");
+ return parms;
+ }
bool funcanno = py3 ? true : false;
String *params = NewString("");
String *_params = make_autodocParmList(n, false, is_calling, funcanno);
- if (in_class)
- {
- Printf(params, "self");
- if(Len(_params) > 0)
- Printf(params, ", ");
- }
+ if (in_class) {
+ Printf(params, "self");
+ if (Len(_params) > 0)
+ Printf(params, ", ");
+ }
Printv(params, _params, NULL);
@@ -1701,27 +1683,26 @@ public:
return have_pythonappend(n) || have_pythonprepend(n) || have_docstring(n);
}
-
+
/* ------------------------------------------------------------
* returnTypeAnnotation()
* Helper function for constructing the function annotation
* of the returning type, return a empty string for Python 2.x
* ------------------------------------------------------------ */
- String* returnTypeAnnotation(Node *n)
- {
- String *ret=0;
+ String *returnTypeAnnotation(Node *n) {
+ String *ret = 0;
Parm *p = Getattr(n, "parms");
String *tm;
/* Try to guess the returning type by argout typemap,
* however the result may not accurate. */
while (p) {
- if ((tm=Getattr(p, "tmap:argout:match_type"))) {
- tm = SwigType_str(tm, 0);
+ if ((tm = Getattr(p, "tmap:argout:match_type"))) {
+ tm = SwigType_str(tm, 0);
if (ret)
- Printv(ret, ", ", tm, NULL);
- else
- ret = tm;
- p = Getattr(p, "tmap:argout:next");
+ Printv(ret, ", ", tm, NULL);
+ else
+ ret = tm;
+ p = Getattr(p, "tmap:argout:next");
} else {
p = nextSibling(p);
}
@@ -1730,10 +1711,11 @@ public:
* the function prototype. */
if (!ret) {
ret = Getattr(n, "type");
- if (ret) ret = SwigType_str(ret, 0);
+ if (ret)
+ ret = SwigType_str(ret, 0);
}
return (ret && py3) ? NewStringf(" -> \"%s\" ", ret)
- : NewString("");
+ : NewString("");
}
/* ------------------------------------------------------------
@@ -1763,7 +1745,7 @@ public:
if (Getattr(n, "feature:python:callback") || !have_addtofunc(n)) {
/* If there is no addtofunc directive then just assign from the extension module (for speed up) */
Printv(f_dest, name, " = ", module, ".", name, "\n", NIL);
- }
+ }
}
@@ -1774,7 +1756,7 @@ public:
int check_kwargs(Node *n) {
return (use_kw || GetFlag(n, "feature:kwargs"))
- && !GetFlag(n, "memberset") && !GetFlag(n, "memberget");
+ && !GetFlag(n, "memberset") && !GetFlag(n, "memberget");
}
@@ -1855,7 +1837,7 @@ public:
Append(f->code, "argc = args ? (int)PyObject_Length(args) : 0;\n");
if (add_self)
Append(f->code, "argv[0] = self;\n");
- Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs-1 : maxargs);
+ Printf(f->code, "for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n", add_self ? maxargs - 1 : maxargs);
Printf(f->code, "argv[ii%s] = PyTuple_GET_ITEM(args,ii);\n", add_self ? " + 1" : "");
Append(f->code, "}\n");
if (add_self)
@@ -1975,14 +1957,14 @@ public:
String *slot = Getattr(n, "feature:pyslot");
String *closure_decl = NULL;
if (slot)
- closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name);
+ closure_decl = getClosure(Getattr(n, "feature:pyslot:functype"), wrapper_name);
/*
- if (builtin_setter || builtin_getter) {
- Clear(linkage);
- Printv(linkage, "extern ", NIL);
- }
- */
+ if (builtin_setter || builtin_getter) {
+ Clear(linkage);
+ Printv(linkage, "extern ", NIL);
+ }
+ */
if (Getattr(n, "sym:overloaded")) {
overname = Getattr(n, "sym:overname");
@@ -2006,7 +1988,7 @@ public:
Wrapper_add_local(f, "resultobj", "int resultobj = 0");
else
Wrapper_add_local(f, "resultobj", "PyObject *resultobj = 0");
-
+
// Emit all of the local variables for holding arguments.
emit_parameter_variables(l, f);
@@ -2119,7 +2101,7 @@ public:
if (Len(pn)) {
String *tmp = 0;
String *name = pn;
- if (!Getattr(p,"hidden")) {
+ if (!Getattr(p, "hidden")) {
name = tmp = Swig_name_make(p, 0, pn, 0, 0);
}
Printf(kwargs, "(char *) \"%s\",", name);
@@ -2152,7 +2134,7 @@ public:
if (Getattr(p, "tmap:in:implicitconv")) {
const char *convflag = "0";
- if (!Getattr(p,"hidden")) {
+ if (!Getattr(p, "hidden")) {
SwigType *ptype = Getattr(p, "type");
convflag = get_implicitconv_flag(classLookup(ptype));
}
@@ -2259,7 +2241,7 @@ public:
if (!Getattr(p, "tmap:in:parse") && (tm = Getattr(p, "tmap:freearg"))) {
if (Getattr(p, "tmap:freearg:implicitconv")) {
const char *convflag = "0";
- if (!Getattr(p,"hidden")) {
+ if (!Getattr(p, "hidden")) {
SwigType *ptype = Getattr(p, "type");
convflag = get_implicitconv_flag(classLookup(ptype));
}
@@ -2336,11 +2318,11 @@ public:
if (allow_thread) {
String *preaction = NewString("");
thread_begin_allow(n, preaction);
- Setattr(n,"wrap:preaction", preaction);
+ Setattr(n, "wrap:preaction", preaction);
String *postaction = NewString("");
thread_end_allow(n, postaction);
- Setattr(n,"wrap:postaction", postaction);
+ Setattr(n, "wrap:postaction", postaction);
}
}
@@ -2468,7 +2450,7 @@ public:
Printv(f->code, cleanup, NIL);
}
if (builtin_ctor)
- Printv(f->code, " return 0;\n", NIL);
+ Printv(f->code, " return -1;\n", NIL);
else
Printv(f->code, " return NULL;\n", NIL);
@@ -2559,9 +2541,9 @@ public:
String *feature_name = NewStringf("feature:%s", slot);
String *closure_name = Copy(wrapper_name);
if (closure_decl) {
- if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling"))
- Printv(f_wrappers, closure_decl, "\n\n", NIL);
- Append(closure_name, "_closure");
+ if (!Getattr(n, "sym:overloaded") || !Getattr(n, "sym:nextSibling"))
+ Printv(f_wrappers, closure_decl, "\n\n", NIL);
+ Append(closure_name, "_closure");
}
Node *parent = Swig_methodclass(n);
Setattr(parent, feature_name, closure_name);
@@ -2569,6 +2551,11 @@ public:
Delete(closure_name);
}
+ /* Handle comparison operators for builtin types */
+ String *compare = Getattr(n, "feature:pycompare");
+ if (compare)
+ Printf(builtin_richcompare, " case %s : result = %s(self, tuple); break;\n", compare, wrapper_name);
+
Delete(self_parse);
Delete(parse_args);
Delete(linkage);
@@ -2581,7 +2568,7 @@ public:
DelWrapper(f);
Delete(wrapper_name);
if (closure_decl)
- Delete(closure_decl);
+ Delete(closure_decl);
return SWIG_OK;
}
@@ -2904,13 +2891,13 @@ public:
if (dirprot_mode()) {
/*
- This implementation uses a std::map.
+ This implementation uses a std::map.
- It should be possible to rewrite it using a more elegant way,
- like copying the Java approach for the 'override' array.
+ It should be possible to rewrite it using a more elegant way,
+ like copying the Java approach for the 'override' array.
- But for now, this seems to be the least intrusive way.
- */
+ But for now, this seems to be the least intrusive way.
+ */
Printf(f_directors_h, "\n\n");
Printf(f_directors_h, "/* Internal Director utilities */\n");
Printf(f_directors_h, "public:\n");
@@ -2993,9 +2980,8 @@ public:
/* ------------------------------------------------------------
* classDeclaration()
* ------------------------------------------------------------ */
-
- virtual bool get_single_base (Node *n, Node **base = NULL)
- {
+
+ virtual bool get_single_base(Node *n, Node **base = NULL) {
if (base)
*base = NULL;
if (Getattr(n, "single_inh"))
@@ -3044,8 +3030,7 @@ public:
* classHandler()
* ------------------------------------------------------------ */
- void builtin_pre_decl (Node *n, Node *base_node)
- {
+ void builtin_pre_decl(Node *n, Node *base_node) {
String *name = Getattr(n, "name");
String *rname = SwigType_namestr(name);
Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname);
@@ -3061,15 +3046,14 @@ public:
Delete(base_mname);
Delete(base_name);
} else {
- //Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL);
- Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL);
+ Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL);
+ //Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL);
}
Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n");
Delete(rname);
}
- void builtin_post_decl (File *f, Node *n)
- {
+ void builtin_post_decl(File *f, Node *n) {
String *name = Getattr(n, "name");
String *pname = Copy(name);
SwigType_add_pointer(pname);
@@ -3081,13 +3065,13 @@ public:
char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : "0";
// Check for non-public destructor, in which case tp_dealloc should be "0"
+ // Any class that doesn't explicitly have a private/protected destructor
+ // has an implicit public destructor.
String *tp_dealloc = NewString("");
- String *dtor_name = NewString("delete");
- if (Getattr(class_members, "delete"))
- Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname);
- else
+ if (GetFlag(n, "private_dtor"))
Printv(tp_dealloc, "0", NIL);
- Delete(dtor_name);
+ else
+ Printf(tp_dealloc, "py_builtin_dealloc< %s >", rname);
Printf(f, "template <> PyGetSetDef PySwigBuiltin< %s >::getset[] = {\n", rname);
for (DohIterator member_iter = First(builtin_getset); member_iter.item; member_iter = Next(member_iter)) {
@@ -3095,13 +3079,14 @@ public:
Hash *mgetset = member_iter.item;
String *getter = Getattr(mgetset, "getter");
String *setter = Getattr(mgetset, "setter");
- Printf(f, tab4 "{ const_cast(\"%s\"), (getter) %s, (setter) pyswig_setter_closure, const_cast(\"%s.%s\"), (void*) &%s },\n",
- mname, getter ? getter : "0", name, mname, setter ? setter : "0");
+ Printf(f, tab4 "{ const_cast(\"%s\"), (getter) %s, (setter) %s, const_cast(\"%s.%s\"), (void*) %s },\n",
+ mname, getter ? getter : "0", setter ? "pyswig_setter_closure" : "0", name, mname, setter ? setter : "0");
}
Printv(f, " {NULL} // Sentinel\n", NIL);
Printv(f, "};\n\n", NIL);
Clear(builtin_getset);
+ // Number methods
Printf(f, "template <> PyNumberMethods PySwigBuiltin< %s >::number_methods = {\n", rname);
Printf(f, " (binaryfunc) %s, // nb_add;\n", getSlot(n, "feature:nb_add"));
Printf(f, " (binaryfunc) %s, // nb_subtract;\n", getSlot(n, "feature:nb_subtract"));
@@ -3143,26 +3128,47 @@ public:
Printf(f, " (binaryfunc) %s, // nb_inplace_true_divide;\n", getSlot(n, "feature:nb_inplace_true_divide"));
Printf(f, " (unaryfunc) %s, // nb_index;\n", getSlot(n, "feature:nb_index"));
Printf(f, "};\n\n");
-
+
+ // Sequence methods
Printf(f, "template <> PySequenceMethods PySwigBuiltin< %s >::sequence_methods = {\n", rname);
- Printf(f, " (lenfunc) %s, // sq_length\n", getSlot(n, "sq_length"));
- Printf(f, " (binaryfunc) %s, // sq_concat\n", getSlot(n, "sq_concat"));
- Printf(f, " (ssizeargfunc) %s, // sq_repeat\n", getSlot(n, "sq_repeat"));
- Printf(f, " (ssizeargfunc) %s, // sq_item\n", getSlot(n, "sq_item"));
- Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "sq_slice"));
- Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "sq_ass_item"));
- Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "sq_ass_slice"));
- Printf(f, " (objobjproc) %s, // sq_contains\n", getSlot(n, "sq_contains"));
- Printf(f, " (binaryfunc) %s, // sq_inplace_concat\n", getSlot(n, "sq_inplace_concat"));
- Printf(f, " (ssizeargfunc) %s, // sq_inplace_repeat\n", getSlot(n, "sq_inplace_repeat"));
+ Printf(f, " (lenfunc) %s, // sq_length\n", getSlot(n, "feature:sq_length"));
+ Printf(f, " (binaryfunc) %s, // sq_concat\n", getSlot(n, "feature:sq_concat"));
+ Printf(f, " (ssizeargfunc) %s, // sq_repeat\n", getSlot(n, "feature:sq_repeat"));
+ Printf(f, " (ssizeargfunc) %s, // sq_item\n", getSlot(n, "feature:sq_item"));
+ Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "feature:sq_slice"));
+ Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "feature:sq_ass_item"));
+ Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "feature:sq_ass_slice"));
+ Printf(f, " (objobjproc) %s, // sq_contains\n", getSlot(n, "feature:sq_contains"));
+ Printf(f, " (binaryfunc) %s, // sq_inplace_concat\n", getSlot(n, "feature:sq_inplace_concat"));
+ Printf(f, " (ssizeargfunc) %s, // sq_inplace_repeat\n", getSlot(n, "feature:sq_inplace_repeat"));
Printf(f, "};\n\n");
+ // Mapping methods
Printf(f, "template <> PyMappingMethods PySwigBuiltin< %s >::mapping_methods = {\n", rname);
- Printf(f, " (lenfunc) %s, // mp_length;\n", getSlot(n, "mp_length"));
- Printf(f, " (binaryfunc) %s, // mp_subscript;\n", getSlot(n, "mp_subscript"));
- Printf(f, " (objobjargproc) %s, // mp_ass_subscript;\n", getSlot(n, "mp_ass_subscript"));
+ Printf(f, " (lenfunc) %s, // mp_length;\n", getSlot(n, "feature:mp_length"));
+ Printf(f, " (binaryfunc) %s, // mp_subscript;\n", getSlot(n, "feature:mp_subscript"));
+ Printf(f, " (objobjargproc) %s, // mp_ass_subscript;\n", getSlot(n, "feature:mp_ass_subscript"));
Printf(f, "};\n\n");
+ // Rich compare function
+ Printf(f, "template <> PyObject*\n");
+ Printf(f, "%s::richcompare (PyObject *self, PyObject *other, int op)\n", templ);
+ Printf(f, "{\n");
+ Printf(f, " PyObject *result = NULL;\n");
+ Printf(f, " PyObject *tuple = PyTuple_New(1);\n");
+ Printf(f, " assert(tuple);\n");
+ Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n");
+ Printf(f, " Py_XINCREF(other);\n");
+ Printf(f, " switch (op) {\n");
+ Printv(f, builtin_richcompare, NIL);
+ Printf(f, " default : PyErr_Format(PyExc_TypeError, \"Cannot compare a(n) '%%s' to a(n) '%%s'\", self->ob_type->tp_name, other ? other->ob_type->tp_name : \"NIL\");\n");
+ Printf(f, " }\n");
+ Printf(f, " Py_DECREF(tuple);\n");
+ Printf(f, " return result;\n");
+ Printf(f, "}\n\n");
+ Clear(builtin_richcompare);
+
+ // Type object
String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES");
// TODO: Add more flags based on slots
Printf(f, "template <> PyTypeObject PySwigBuiltin< %s >::pytype = {\n", rname);
@@ -3190,10 +3196,10 @@ public:
Printf(f, " \"%s\", /* tp_doc */\n", rname);
Printf(f, " %s, /* tp_traverse */\n", getSlot(n, "feature:tp_traverse"));
Printf(f, " %s, /* tp_clear */\n", getSlot(n, "feature:tp_clear"));
- Printf(f, " %s, /* tp_richcompare */\n", getSlot(n, "feature:tp_richcompare"));
+ Printf(f, " %s::richcompare, /* tp_richcompare */\n", templ);
Printf(f, " %s, /* tp_weaklistoffset */\n", getSlot(n, "feature:tp_weaklistoffset"));
- Printf(f, " %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter"));
- Printf(f, " %s, /* tp_iternext */\n", getSlot(n, "feature:tp_iternext"));
+ Printf(f, " (getiterfunc) %s, /* tp_iter */\n", getSlot(n, "feature:tp_iter"));
+ Printf(f, " (iternextfunc) %s, /* tp_iternext */\n", getSlot(n, "feature:tp_iternext"));
Printf(f, " %s::methods, /* tp_methods */\n", templ);
Printf(f, " %s, /* tp_members */\n", getSlot(n, "feature:tp_members"));
Printf(f, " %s::getset, /* tp_getset */\n", templ);
@@ -3226,7 +3232,7 @@ public:
Delete(templ);
Delete(mname);
Delete(rname);
- Delete(pname);
+ Delete(pname);
Delete(tp_dealloc);
Delete(tp_flags);
}
@@ -3284,7 +3290,8 @@ public:
if (!bname || ignore) {
if (!bname && !ignore) {
Swig_warning(WARN_TYPE_UNDEFINED_CLASS, Getfile(n), Getline(n),
- "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n", SwigType_namestr(Getattr(b.item, "name")));
+ "Base class '%s' ignored - unknown module name for base. Either import the appropriate module interface file or specify the name of the module in the %%import directive.\n",
+ SwigType_namestr(Getattr(b.item, "name")));
}
b = Next(b);
continue;
@@ -3305,7 +3312,7 @@ public:
}
Printv(base_class, abcs, NIL);
}
-
+
if (!single_inh) {
Printv(f_shadow, "class ", class_name, NIL);
@@ -3315,7 +3322,7 @@ public:
if (!classic) {
Printf(f_shadow, modern ? "(object)" : "(_object)");
}
- if (GetFlag(n, "feature:exceptionclass") ) {
+ if (GetFlag(n, "feature:exceptionclass")) {
Printf(f_shadow, "(Exception)");
}
}
@@ -3391,7 +3398,7 @@ public:
if (shadow) {
/* Generate a class registration function */
if (!single_inh) {
- String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers)
+ String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers)
SwigType *smart = 0;
if (smartptr) {
SwigType *cpt = Swig_cparse_type(smartptr);
@@ -3421,8 +3428,7 @@ public:
}
Printv(f_wrappers,
- " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n",
- " return SWIG_Py_Void();\n", "}\n\n", NIL);
+ " SWIG_TypeNewClientData(SWIGTYPE", SwigType_manglestr(ct), ", SWIG_NewClientData(obj));\n", " return SWIG_Py_Void();\n", "}\n\n", NIL);
String *cname = NewStringf("%s_swigregister", class_name);
add_method(cname, cname, 0);
Delete(smart);
@@ -3432,7 +3438,8 @@ public:
}
if (!have_constructor) {
if (!single_inh)
- Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined", (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
+ Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined",
+ (Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
} else if (fastinit && !single_inh) {
Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
@@ -3487,7 +3494,8 @@ public:
List *shadow_list = Getattr(n, "shadow_methods");
for (int i = 0; i < Len(shadow_list); ++i) {
String *symname = Getitem(shadow_list, i);
- Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module, Swig_name_member(NSPACE_TODO, class_name, symname), class_name);
+ Printf(f_shadow_file, "%s.%s = new_instancemethod(%s.%s,None,%s)\n", class_name, symname, module,
+ Swig_name_member(NSPACE_TODO, class_name, symname), class_name);
}
}
Printf(f_shadow_file, "%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name);
@@ -3555,7 +3563,13 @@ public:
if (!Getattr(n, "sym:nextSibling")) {
if (builtin && in_class) {
String *name = Getattr(n, "name");
- if (checkAttribute(n, "access", "public") && strncmp(Char(name), "operator ", 9) && !Getattr(class_members, name)) {
+
+ // Can't use checkAttribute(n, "access", "public") because
+ // "access" attr isn't set on %extend methods
+ if (!checkAttribute(n, "access", "private") &&
+ !checkAttribute(n, "access", "protected") &&
+ strncmp(Char(name), "operator ", 9) &&
+ !Getattr(class_members, name)) {
String *fullname = Swig_name_member(NULL, class_name, symname);
String *wname = Swig_name_wrapper(fullname);
Setattr(class_members, name, name);
@@ -3589,7 +3603,7 @@ public:
Printv(f_shadow, " return ", funcCall(Swig_name_member(NSPACE_TODO, class_name, symname), callParms), "\n", NIL);
}
} else {
- Printv(f_shadow, tab4, "def ", symname, "(",parms , ")", returnTypeAnnotation(n), ":", NIL);
+ Printv(f_shadow, tab4, "def ", symname, "(", parms, ")", returnTypeAnnotation(n), ":", NIL);
Printv(f_shadow, "\n", NIL);
if (have_docstring(n))
Printv(f_shadow, tab8, docstring(n, AUTODOC_METHOD, tab8), "\n", NIL);
@@ -3653,7 +3667,7 @@ public:
Delete(wname);
Delete(pyflags);
}
- } else if (shadow ) {
+ } else if (shadow) {
if (!classic && !Getattr(n, "feature:python:callback") && have_addtofunc(n)) {
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
String *parms = make_pyParmList(n, false, false, kw);
@@ -3678,10 +3692,12 @@ public:
} else {
if (!modern) {
- Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n", NIL);
+ Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = lambda x: ", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), "\n",
+ NIL);
}
if (!classic) {
- Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname), ")\n", NIL);
+ Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = staticmethod(", module, ".", Swig_name_member(NSPACE_TODO, class_name, symname),
+ ")\n", NIL);
}
}
}
@@ -3732,18 +3748,18 @@ public:
if (!Getattr(n, "sym:nextSibling")) {
if (builtin && in_class) {
String *name = NewString("new");
- if ((use_director || checkAttribute(n, "access", "public")) && !Getattr(class_members, name)) {
+ // Can't use checkAttribute(n, "access", "public") because
+ // "access" attr isn't set on %extend methods
+ if ((use_director ||
+ (!checkAttribute(n, "access", "protected") &&
+ !checkAttribute(n, "access", "private"))) &&
+ !Getattr(class_members, name)) {
Setattr(class_members, name, name);
String *fullname = Swig_name_member(NULL, name, class_name);
if (!builtin_tp_init)
builtin_tp_init = Swig_name_wrapper(fullname);
- /*
- ParmList *parms = Getattr(n, "parms");
- char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS";
- Printf(f_shadow, " { \"__init__\", (PyCFunction) %s, %s, \"\" },\n", builtin_tp_init, Char(pyflags));
- */
Delete(fullname);
- }
+ }
Delete(name);
} else if (shadow) {
int allow_kwargs = (check_kwargs(n) && (!Getattr(n, "sym:overloaded"))) ? 1 : 0;
@@ -3755,7 +3771,7 @@ public:
handled_as_init = (Strcmp(nname, sname) == 0) || (Strcmp(nname, cname) == 0);
Delete(cname);
}
-
+
if (!have_constructor && handled_as_init) {
if (Getattr(n, "feature:shadow")) {
String *pycode = pythoncode(Getattr(n, "feature:shadow"), tab4);
@@ -3770,7 +3786,7 @@ public:
String *classname = Swig_class_name(parent);
String *rclassname = Swig_class_name(getCurrentClass());
assert(rclassname);
-
+
String *parms = make_pyParmList(n, true, false, allow_kwargs);
/* Pass 'self' only if using director */
@@ -3842,20 +3858,8 @@ public:
virtual int destructorHandler(Node *n) {
if (builtin && in_class) {
- String *name = NewString("delete");
- if (checkAttribute(n, "access", "public") && !Getattr(class_members, name)) {
- Setattr(class_members, name, name);
- /*
- String *fullname = Swig_name_member(NULL, name, class_name);
- String *wname = Swig_name_wrapper(fullname);
- ParmList *parms = Getattr(n, "parms");
- char const *pyflags = (!parms || Len(parms) == 0) ? "METH_NOARGS" : (Len(parms) == 1) ? "METH_0" : "METH_VARARGS";
- Printf(f_shadow, " { \"__del__\", (PyCFunction) %s, %s, \"\" },\n", wname, Char(pyflags));
- Delete(fullname);
- Delete(wname);
- */
- }
- Delete(name);
+ if (checkAttribute(n, "access", "private") || checkAttribute(n, "access", "protected"))
+ SetFlag(Swig_methodclass(n), "private_dtor");
return SWIG_OK;
}
@@ -4119,489 +4123,489 @@ public:
* ** Moved it here due to internal error on gcc-2.96 **
* --------------------------------------------------------------- */
int PYTHON::classDirectorMethods(Node *n) {
- director_method_index = 0;
- return Language::classDirectorMethods(n);
+ director_method_index = 0;
+ return Language::classDirectorMethods(n);
}
int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
- int is_void = 0;
- int is_pointer = 0;
- String *decl;
- String *type;
- String *name;
- String *classname;
- String *c_classname = Getattr(parent, "name");
- String *declaration;
- ParmList *l;
- Wrapper *w;
- String *tm;
- String *wrap_args = NewString("");
- String *return_type;
- String *value = Getattr(n, "value");
- String *storage = Getattr(n, "storage");
- bool pure_virtual = false;
- int status = SWIG_OK;
- int idx;
- bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
+ int is_void = 0;
+ int is_pointer = 0;
+ String *decl;
+ String *type;
+ String *name;
+ String *classname;
+ String *c_classname = Getattr(parent, "name");
+ String *declaration;
+ ParmList *l;
+ Wrapper *w;
+ String *tm;
+ String *wrap_args = NewString("");
+ String *return_type;
+ String *value = Getattr(n, "value");
+ String *storage = Getattr(n, "storage");
+ bool pure_virtual = false;
+ int status = SWIG_OK;
+ int idx;
+ bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
- if (Cmp(storage, "virtual") == 0) {
- if (Cmp(value, "0") == 0) {
- pure_virtual = true;
- }
+ if (Cmp(storage, "virtual") == 0) {
+ if (Cmp(value, "0") == 0) {
+ pure_virtual = true;
}
+ }
- classname = Getattr(parent, "sym:name");
- type = Getattr(n, "type");
- name = Getattr(n, "name");
+ classname = Getattr(parent, "sym:name");
+ type = Getattr(n, "type");
+ name = Getattr(n, "name");
- w = NewWrapper();
- declaration = NewString("");
+ w = NewWrapper();
+ declaration = NewString("");
- /* determine if the method returns a pointer */
- decl = Getattr(n, "decl");
- is_pointer = SwigType_ispointer_return(decl);
- is_void = (!Cmp(type, "void") && !is_pointer);
+ /* determine if the method returns a pointer */
+ decl = Getattr(n, "decl");
+ is_pointer = SwigType_ispointer_return(decl);
+ is_void = (!Cmp(type, "void") && !is_pointer);
- /* form complete return type */
- return_type = Copy(type);
- {
- SwigType *t = Copy(decl);
- SwigType *f = 0;
- f = SwigType_pop_function(t);
- SwigType_push(return_type, t);
- Delete(f);
- Delete(t);
- }
+ /* form complete return type */
+ return_type = Copy(type);
+ {
+ SwigType *t = Copy(decl);
+ SwigType *f = 0;
+ f = SwigType_pop_function(t);
+ SwigType_push(return_type, t);
+ Delete(f);
+ Delete(t);
+ }
- /* virtual method definition */
- l = Getattr(n, "parms");
- String *target;
- String *pclassname = NewStringf("SwigDirector_%s", classname);
- String *qualified_name = NewStringf("%s::%s", pclassname, name);
- SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
- target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
- Printf(w->def, "%s", target);
- Delete(qualified_name);
- Delete(target);
- /* header declaration */
- target = Swig_method_decl(rtype, decl, name, l, 0, 1);
- Printf(declaration, " virtual %s", target);
- Delete(target);
+ /* virtual method definition */
+ l = Getattr(n, "parms");
+ String *target;
+ String *pclassname = NewStringf("SwigDirector_%s", classname);
+ String *qualified_name = NewStringf("%s::%s", pclassname, name);
+ SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
+ target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
+ Printf(w->def, "%s", target);
+ Delete(qualified_name);
+ Delete(target);
+ /* header declaration */
+ target = Swig_method_decl(rtype, decl, name, l, 0, 1);
+ Printf(declaration, " virtual %s", target);
+ Delete(target);
- // Get any exception classes in the throws typemap
- ParmList *throw_parm_list = 0;
+ // Get any exception classes in the throws typemap
+ ParmList *throw_parm_list = 0;
- if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
- Parm *p;
- int gencomma = 0;
+ if ((throw_parm_list = Getattr(n, "throws")) || Getattr(n, "throw")) {
+ Parm *p;
+ int gencomma = 0;
- Append(w->def, " throw(");
- Append(declaration, " throw(");
+ Append(w->def, " throw(");
+ Append(declaration, " throw(");
- if (throw_parm_list)
- Swig_typemap_attach_parms("throws", throw_parm_list, 0);
- for (p = throw_parm_list; p; p = nextSibling(p)) {
- if ((tm = Getattr(p, "tmap:throws"))) {
- if (gencomma++) {
- Append(w->def, ", ");
- Append(declaration, ", ");
- }
- String *str = SwigType_str(Getattr(p, "type"), 0);
- Append(w->def, str);
- Append(declaration, str);
- Delete(str);
+ if (throw_parm_list)
+ Swig_typemap_attach_parms("throws", throw_parm_list, 0);
+ for (p = throw_parm_list; p; p = nextSibling(p)) {
+ if ((tm = Getattr(p, "tmap:throws"))) {
+ if (gencomma++) {
+ Append(w->def, ", ");
+ Append(declaration, ", ");
}
- }
-
- Append(w->def, ")");
- Append(declaration, ")");
- }
-
- Append(w->def, " {");
- Append(declaration, ";\n");
-
- /* declare method return value
- * if the return value is a reference or const reference, a specialized typemap must
- * handle it, including declaration of c_result ($result).
- */
- if (!is_void) {
- if (!(ignored_method && !pure_virtual)) {
- String *cres = SwigType_lstr(return_type, "c_result");
- Printf(w->code, "%s;\n", cres);
- Delete(cres);
+ String *str = SwigType_str(Getattr(p, "type"), 0);
+ Append(w->def, str);
+ Append(declaration, str);
+ Delete(str);
}
}
- if (ignored_method) {
- if (!pure_virtual) {
- if (!is_void)
- Printf(w->code, "return ");
- String *super_call = Swig_method_call(super, l);
- Printf(w->code, "%s;\n", super_call);
- Delete(super_call);
- } else {
- Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
- SwigType_namestr(name));
- }
- } else {
- /* attach typemaps to arguments (C/C++ -> Python) */
- String *arglist = NewString("");
- String *parse_args = NewString("");
+ Append(w->def, ")");
+ Append(declaration, ")");
+ }
- /* remove the wrapper 'w' since it was producing spurious temps */
- Swig_typemap_attach_parms("in", l, 0);
- Swig_typemap_attach_parms("directorin", l, 0);
- Swig_typemap_attach_parms("directorargout", l, w);
+ Append(w->def, " {");
+ Append(declaration, ";\n");
- Parm *p;
- char source[256];
+ /* declare method return value
+ * if the return value is a reference or const reference, a specialized typemap must
+ * handle it, including declaration of c_result ($result).
+ */
+ if (!is_void) {
+ if (!(ignored_method && !pure_virtual)) {
+ String *cres = SwigType_lstr(return_type, "c_result");
+ Printf(w->code, "%s;\n", cres);
+ Delete(cres);
+ }
+ }
- int outputs = 0;
+ if (ignored_method) {
+ if (!pure_virtual) {
if (!is_void)
- outputs++;
+ Printf(w->code, "return ");
+ String *super_call = Swig_method_call(super, l);
+ Printf(w->code, "%s;\n", super_call);
+ Delete(super_call);
+ } else {
+ Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
+ SwigType_namestr(name));
+ }
+ } else {
+ /* attach typemaps to arguments (C/C++ -> Python) */
+ String *arglist = NewString("");
+ String *parse_args = NewString("");
- /* build argument list and type conversion string */
- idx = 0;
- p = l;
- int use_parse = 0;
- while (p) {
- if (checkAttribute(p, "tmap:in:numinputs", "0")) {
- p = Getattr(p, "tmap:in:next");
- continue;
- }
+ /* remove the wrapper 'w' since it was producing spurious temps */
+ Swig_typemap_attach_parms("in", l, 0);
+ Swig_typemap_attach_parms("directorin", l, 0);
+ Swig_typemap_attach_parms("directorargout", l, w);
- /* old style? caused segfaults without the p!=0 check
- in the for() condition, and seems dangerous in the
- while loop as well.
- while (Getattr(p, "tmap:ignore")) {
- p = Getattr(p, "tmap:ignore:next");
- }
- */
+ Parm *p;
+ char source[256];
- if (Getattr(p, "tmap:directorargout") != 0)
- outputs++;
+ int outputs = 0;
+ if (!is_void)
+ outputs++;
- String *pname = Getattr(p, "name");
- String *ptype = Getattr(p, "type");
-
- Putc(',', arglist);
- if ((tm = Getattr(p, "tmap:directorin")) != 0) {
- String *parse = Getattr(p, "tmap:directorin:parse");
- if (!parse) {
- sprintf(source, "obj%d", idx++);
- String *input = NewString(source);
- Replaceall(tm, "$input", input);
- Delete(input);
- Replaceall(tm, "$owner", "0");
- /* Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); */
- Printv(wrap_args, "swig::SwigVar_PyObject ", source, ";\n", NIL);
-
- Printv(wrap_args, tm, "\n", NIL);
- Printv(arglist, "(PyObject *)", source, NIL);
- Putc('O', parse_args);
- } else {
- use_parse = 1;
- Append(parse_args, parse);
- Replaceall(tm, "$input", pname);
- Replaceall(tm, "$owner", "0");
- if (Len(tm) == 0)
- Append(tm, pname);
- Append(arglist, tm);
- }
- p = Getattr(p, "tmap:directorin:next");
- continue;
- } else if (Cmp(ptype, "void")) {
- /* special handling for pointers to other C++ director classes.
- * ideally this would be left to a typemap, but there is currently no
- * way to selectively apply the dynamic_cast<> to classes that have
- * directors. in other words, the type "SwigDirector_$1_lname" only exists
- * for classes with directors. we avoid the problem here by checking
- * module.wrap::directormap, but it's not clear how to get a typemap to
- * do something similar. perhaps a new default typemap (in addition
- * to SWIGTYPE) called DIRECTORTYPE?
- */
- if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) {
- Node *module = Getattr(parent, "module");
- Node *target = Swig_directormap(module, ptype);
- sprintf(source, "obj%d", idx++);
- String *nonconst = 0;
- /* strip pointer/reference --- should move to Swig/stype.c */
- String *nptype = NewString(Char(ptype) + 2);
- /* name as pointer */
- String *ppname = Copy(pname);
- if (SwigType_isreference(ptype)) {
- Insert(ppname, 0, "&");
- }
- /* if necessary, cast away const since Python doesn't support it! */
- if (SwigType_isconst(nptype)) {
- nonconst = NewStringf("nc_tmp_%s", pname);
- String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
- Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
- Delete(nonconst_i);
- Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
- "Target language argument '%s' discards const in director method %s::%s.\n",
- SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name));
- } else {
- nonconst = Copy(ppname);
- }
- Delete(nptype);
- Delete(ppname);
- String *mangle = SwigType_manglestr(ptype);
- if (target) {
- String *director = NewStringf("director_%s", mangle);
- Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
- Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL);
- Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
- Printf(wrap_args, "if (!%s) {\n", director);
- Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
- Append(wrap_args, "} else {\n");
- Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
- Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source);
- Append(wrap_args, "}\n");
- Delete(director);
- Printv(arglist, source, NIL);
- } else {
- Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL);
- Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
- //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n",
- // source, nonconst, base);
- Printv(arglist, source, NIL);
- }
- Putc('O', parse_args);
- Delete(mangle);
- Delete(nonconst);
- } else {
- Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
- "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0),
- SwigType_namestr(c_classname), SwigType_namestr(name));
- status = SWIG_NOWRAP;
- break;
- }
- }
- p = nextSibling(p);
+ /* build argument list and type conversion string */
+ idx = 0;
+ p = l;
+ int use_parse = 0;
+ while (p) {
+ if (checkAttribute(p, "tmap:in:numinputs", "0")) {
+ p = Getattr(p, "tmap:in:next");
+ continue;
}
- /* add the method name as a PyString */
- String *pyname = Getattr(n, "sym:name");
-
- int allow_thread = threads_enable(n);
-
- if (allow_thread) {
- thread_begin_block(n, w->code);
- Append(w->code, "{\n");
- }
-
- /* wrap complex arguments to PyObjects */
- Printv(w->code, wrap_args, NIL);
-
- /* pass the method call on to the Python object */
- if (dirprot_mode() && !is_public(n)) {
- Printf(w->code, "swig_set_inner(\"%s\", true);\n", name);
- }
-
-
- Append(w->code, "if (!swig_get_self()) {\n");
- Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname);
- Append(w->code, "}\n");
- Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n");
- Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++);
- Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname);
-
- Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n");
- if (Len(parse_args) > 0) {
- if (use_parse || !modernargs) {
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist);
- } else {
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist);
- }
- } else {
- if (modernargs) {
- Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n");
- Append(w->code, "swig::SwigVar_PyObject result = PyObject_Call(method, (PyObject*) args, NULL);\n");
- } else {
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, NULL, NULL);\n");
- }
- }
- Append(w->code, "#else\n");
- if (Len(parse_args) > 0) {
- if (use_parse || !modernargs) {
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n",
- pyname, parse_args, arglist);
- } else {
- Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", arglist);
- }
- } else {
- if (!modernargs) {
- Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname);
- } else {
- Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
- Append(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n");
- }
- }
- Append(w->code, "#endif\n");
-
- if (dirprot_mode() && !is_public(n))
- Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
-
- /* exception handling */
- tm = Swig_typemap_lookup("director:except", n, "result", 0);
- if (!tm) {
- tm = Getattr(n, "feature:director:except");
- if (tm)
- tm = Copy(tm);
- }
- Append(w->code, "if (!result) {\n");
- Append(w->code, " PyObject *error = PyErr_Occurred();\n");
- if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
- Replaceall(tm, "$error", "error");
- Printv(w->code, Str(tm), "\n", NIL);
- } else {
- Append(w->code, " if (error) {\n");
- Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname);
- Append(w->code, " }\n");
- }
- Append(w->code, "}\n");
- Delete(tm);
-
- /*
- * Python method may return a simple object, or a tuple.
- * for in/out aruments, we have to extract the appropriate PyObjects from the tuple,
- * then marshal everything back to C/C++ (return value and output arguments).
- *
+ /* old style? caused segfaults without the p!=0 check
+ in the for() condition, and seems dangerous in the
+ while loop as well.
+ while (Getattr(p, "tmap:ignore")) {
+ p = Getattr(p, "tmap:ignore:next");
+ }
*/
- /* marshal return value and other outputs (if any) from PyObject to C/C++ type */
+ if (Getattr(p, "tmap:directorargout") != 0)
+ outputs++;
- String *cleanup = NewString("");
- String *outarg = NewString("");
+ String *pname = Getattr(p, "name");
+ String *ptype = Getattr(p, "type");
- if (outputs > 1) {
- Wrapper_add_local(w, "output", "PyObject *output");
- Append(w->code, "if (!PyTuple_Check(result)) {\n");
- Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname);
- Append(w->code, "}\n");
- }
+ Putc(',', arglist);
+ if ((tm = Getattr(p, "tmap:directorin")) != 0) {
+ String *parse = Getattr(p, "tmap:directorin:parse");
+ if (!parse) {
+ sprintf(source, "obj%d", idx++);
+ String *input = NewString(source);
+ Replaceall(tm, "$input", input);
+ Delete(input);
+ Replaceall(tm, "$owner", "0");
+ /* Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL); */
+ Printv(wrap_args, "swig::SwigVar_PyObject ", source, ";\n", NIL);
- idx = 0;
-
- /* marshal return value */
- if (!is_void) {
- /* this seems really silly. the node's type excludes
- * qualifier/pointer/reference markers, which have to be retrieved
- * from the decl field to construct return_type. but the typemap
- * lookup routine uses the node's type, so we have to swap in and
- * out the correct type. it's not just me, similar silliness also
- * occurs in Language::cDeclaration().
+ Printv(wrap_args, tm, "\n", NIL);
+ Printv(arglist, "(PyObject *)", source, NIL);
+ Putc('O', parse_args);
+ } else {
+ use_parse = 1;
+ Append(parse_args, parse);
+ Replaceall(tm, "$input", pname);
+ Replaceall(tm, "$owner", "0");
+ if (Len(tm) == 0)
+ Append(tm, pname);
+ Append(arglist, tm);
+ }
+ p = Getattr(p, "tmap:directorin:next");
+ continue;
+ } else if (Cmp(ptype, "void")) {
+ /* special handling for pointers to other C++ director classes.
+ * ideally this would be left to a typemap, but there is currently no
+ * way to selectively apply the dynamic_cast<> to classes that have
+ * directors. in other words, the type "SwigDirector_$1_lname" only exists
+ * for classes with directors. we avoid the problem here by checking
+ * module.wrap::directormap, but it's not clear how to get a typemap to
+ * do something similar. perhaps a new default typemap (in addition
+ * to SWIGTYPE) called DIRECTORTYPE?
*/
- Setattr(n, "type", return_type);
- tm = Swig_typemap_lookup("directorout", n, "result", w);
- Setattr(n, "type", type);
- if (tm != 0) {
- if (outputs > 1) {
- Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);
- Replaceall(tm, "$input", "output");
+ if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) {
+ Node *module = Getattr(parent, "module");
+ Node *target = Swig_directormap(module, ptype);
+ sprintf(source, "obj%d", idx++);
+ String *nonconst = 0;
+ /* strip pointer/reference --- should move to Swig/stype.c */
+ String *nptype = NewString(Char(ptype) + 2);
+ /* name as pointer */
+ String *ppname = Copy(pname);
+ if (SwigType_isreference(ptype)) {
+ Insert(ppname, 0, "&");
+ }
+ /* if necessary, cast away const since Python doesn't support it! */
+ if (SwigType_isconst(nptype)) {
+ nonconst = NewStringf("nc_tmp_%s", pname);
+ String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
+ Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
+ Delete(nonconst_i);
+ Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
+ "Target language argument '%s' discards const in director method %s::%s.\n",
+ SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name));
} else {
- Replaceall(tm, "$input", "result");
+ nonconst = Copy(ppname);
}
- char temp[24];
- sprintf(temp, "%d", idx);
- Replaceall(tm, "$argnum", temp);
-
- /* TODO check this */
- if (Getattr(n, "wrap:disown")) {
- Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
+ Delete(nptype);
+ Delete(ppname);
+ String *mangle = SwigType_manglestr(ptype);
+ if (target) {
+ String *director = NewStringf("director_%s", mangle);
+ Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
+ Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL);
+ Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
+ Printf(wrap_args, "if (!%s) {\n", director);
+ Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
+ Append(wrap_args, "} else {\n");
+ Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
+ Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source);
+ Append(wrap_args, "}\n");
+ Delete(director);
+ Printv(arglist, source, NIL);
} else {
- Replaceall(tm, "$disown", "0");
+ Wrapper_add_localv(w, source, "swig::SwigVar_PyObject", source, "= 0", NIL);
+ Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
+ //Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE_p_%s, 0);\n",
+ // source, nonconst, base);
+ Printv(arglist, source, NIL);
}
- if (Getattr(n, "tmap:directorout:implicitconv")) {
- Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
- }
- Replaceall(tm, "$result", "c_result");
- Printv(w->code, tm, "\n", NIL);
- Delete(tm);
+ Putc('O', parse_args);
+ Delete(mangle);
+ Delete(nonconst);
} else {
- Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
- "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname),
- SwigType_namestr(name));
- status = SWIG_ERROR;
+ Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
+ "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0),
+ SwigType_namestr(c_classname), SwigType_namestr(name));
+ status = SWIG_NOWRAP;
+ break;
}
}
-
- /* marshal outputs */
- for (p = l; p;) {
- if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
- if (outputs > 1) {
- Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);
- Replaceall(tm, "$input", "output");
- } else {
- Replaceall(tm, "$input", "result");
- }
- Replaceall(tm, "$result", Getattr(p, "name"));
- Printv(w->code, tm, "\n", NIL);
- p = Getattr(p, "tmap:directorargout:next");
- } else {
- p = nextSibling(p);
- }
- }
-
- /* any existing helper functions to handle this? */
- if (allow_thread) {
- Append(w->code, "}\n");
- thread_end_block(n, w->code);
- }
-
- Delete(parse_args);
- Delete(arglist);
- Delete(cleanup);
- Delete(outarg);
+ p = nextSibling(p);
}
- if (!is_void) {
- if (!(ignored_method && !pure_virtual)) {
- String *rettype = SwigType_str(return_type, 0);
- if (!SwigType_isreference(return_type)) {
- Printf(w->code, "return (%s) c_result;\n", rettype);
- } else {
- Printf(w->code, "return (%s) *c_result;\n", rettype);
- }
- Delete(rettype);
- }
+ /* add the method name as a PyString */
+ String *pyname = Getattr(n, "sym:name");
+
+ int allow_thread = threads_enable(n);
+
+ if (allow_thread) {
+ thread_begin_block(n, w->code);
+ Append(w->code, "{\n");
}
+ /* wrap complex arguments to PyObjects */
+ Printv(w->code, wrap_args, NIL);
+
+ /* pass the method call on to the Python object */
+ if (dirprot_mode() && !is_public(n)) {
+ Printf(w->code, "swig_set_inner(\"%s\", true);\n", name);
+ }
+
+
+ Append(w->code, "if (!swig_get_self()) {\n");
+ Printf(w->code, " Swig::DirectorException::raise(\"'self' uninitialized, maybe you forgot to call %s.__init__.\");\n", classname);
Append(w->code, "}\n");
+ Append(w->code, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n");
+ Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++);
+ Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname);
- // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
- String *inline_extra_method = NewString("");
- if (dirprot_mode() && !is_public(n) && !pure_virtual) {
- Printv(inline_extra_method, declaration, NIL);
- String *extra_method_name = NewStringf("%sSwigPublic", name);
- Replaceall(inline_extra_method, name, extra_method_name);
- Replaceall(inline_extra_method, ";\n", " {\n ");
- if (!is_void)
- Printf(inline_extra_method, "return ");
- String *methodcall = Swig_method_call(super, l);
- Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
- Delete(methodcall);
- Delete(extra_method_name);
+ Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n");
+ if (Len(parse_args) > 0) {
+ if (use_parse || !modernargs) {
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist);
+ } else {
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist);
+ }
+ } else {
+ if (modernargs) {
+ Append(w->code, "swig::SwigVar_PyObject args = PyTuple_New(0);\n");
+ Append(w->code, "swig::SwigVar_PyObject result = PyObject_Call(method, (PyObject*) args, NULL);\n");
+ } else {
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallFunction(method, NULL, NULL);\n");
+ }
+ }
+ Append(w->code, "#else\n");
+ if (Len(parse_args) > 0) {
+ if (use_parse || !modernargs) {
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n",
+ pyname, parse_args, arglist);
+ } else {
+ Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name %s, NULL);\n", arglist);
+ }
+ } else {
+ if (!modernargs) {
+ Printf(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname);
+ } else {
+ Printf(w->code, "swig::SwigVar_PyObject swig_method_name = SWIG_Python_str_FromChar((char *)\"%s\");\n", pyname);
+ Append(w->code, "swig::SwigVar_PyObject result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n");
+ }
+ }
+ Append(w->code, "#endif\n");
+
+ if (dirprot_mode() && !is_public(n))
+ Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
+
+ /* exception handling */
+ tm = Swig_typemap_lookup("director:except", n, "result", 0);
+ if (!tm) {
+ tm = Getattr(n, "feature:director:except");
+ if (tm)
+ tm = Copy(tm);
+ }
+ Append(w->code, "if (!result) {\n");
+ Append(w->code, " PyObject *error = PyErr_Occurred();\n");
+ if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
+ Replaceall(tm, "$error", "error");
+ Printv(w->code, Str(tm), "\n", NIL);
+ } else {
+ Append(w->code, " if (error) {\n");
+ Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname);
+ Append(w->code, " }\n");
+ }
+ Append(w->code, "}\n");
+ Delete(tm);
+
+ /*
+ * Python method may return a simple object, or a tuple.
+ * for in/out aruments, we have to extract the appropriate PyObjects from the tuple,
+ * then marshal everything back to C/C++ (return value and output arguments).
+ *
+ */
+
+ /* marshal return value and other outputs (if any) from PyObject to C/C++ type */
+
+ String *cleanup = NewString("");
+ String *outarg = NewString("");
+
+ if (outputs > 1) {
+ Wrapper_add_local(w, "output", "PyObject *output");
+ Append(w->code, "if (!PyTuple_Check(result)) {\n");
+ Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", classname, pyname);
+ Append(w->code, "}\n");
}
- /* emit the director method */
- if (status == SWIG_OK) {
- if (!Getattr(n, "defaultargs")) {
- Wrapper_print(w, f_directors);
- Printv(f_directors_h, declaration, NIL);
- Printv(f_directors_h, inline_extra_method, NIL);
+ idx = 0;
+
+ /* marshal return value */
+ if (!is_void) {
+ /* this seems really silly. the node's type excludes
+ * qualifier/pointer/reference markers, which have to be retrieved
+ * from the decl field to construct return_type. but the typemap
+ * lookup routine uses the node's type, so we have to swap in and
+ * out the correct type. it's not just me, similar silliness also
+ * occurs in Language::cDeclaration().
+ */
+ Setattr(n, "type", return_type);
+ tm = Swig_typemap_lookup("directorout", n, "result", w);
+ Setattr(n, "type", type);
+ if (tm != 0) {
+ if (outputs > 1) {
+ Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);
+ Replaceall(tm, "$input", "output");
+ } else {
+ Replaceall(tm, "$input", "result");
+ }
+ char temp[24];
+ sprintf(temp, "%d", idx);
+ Replaceall(tm, "$argnum", temp);
+
+ /* TODO check this */
+ if (Getattr(n, "wrap:disown")) {
+ Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
+ } else {
+ Replaceall(tm, "$disown", "0");
+ }
+ if (Getattr(n, "tmap:directorout:implicitconv")) {
+ Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
+ }
+ Replaceall(tm, "$result", "c_result");
+ Printv(w->code, tm, "\n", NIL);
+ Delete(tm);
+ } else {
+ Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
+ "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname),
+ SwigType_namestr(name));
+ status = SWIG_ERROR;
}
}
- /* clean up */
- Delete(wrap_args);
- Delete(return_type);
- Delete(pclassname);
- DelWrapper(w);
- return status;
+ /* marshal outputs */
+ for (p = l; p;) {
+ if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
+ if (outputs > 1) {
+ Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);
+ Replaceall(tm, "$input", "output");
+ } else {
+ Replaceall(tm, "$input", "result");
+ }
+ Replaceall(tm, "$result", Getattr(p, "name"));
+ Printv(w->code, tm, "\n", NIL);
+ p = Getattr(p, "tmap:directorargout:next");
+ } else {
+ p = nextSibling(p);
+ }
+ }
+
+ /* any existing helper functions to handle this? */
+ if (allow_thread) {
+ Append(w->code, "}\n");
+ thread_end_block(n, w->code);
+ }
+
+ Delete(parse_args);
+ Delete(arglist);
+ Delete(cleanup);
+ Delete(outarg);
+ }
+
+ if (!is_void) {
+ if (!(ignored_method && !pure_virtual)) {
+ String *rettype = SwigType_str(return_type, 0);
+ if (!SwigType_isreference(return_type)) {
+ Printf(w->code, "return (%s) c_result;\n", rettype);
+ } else {
+ Printf(w->code, "return (%s) *c_result;\n", rettype);
+ }
+ Delete(rettype);
+ }
+ }
+
+ Append(w->code, "}\n");
+
+ // We expose protected methods via an extra public inline method which makes a straight call to the wrapped class' method
+ String *inline_extra_method = NewString("");
+ if (dirprot_mode() && !is_public(n) && !pure_virtual) {
+ Printv(inline_extra_method, declaration, NIL);
+ String *extra_method_name = NewStringf("%sSwigPublic", name);
+ Replaceall(inline_extra_method, name, extra_method_name);
+ Replaceall(inline_extra_method, ";\n", " {\n ");
+ if (!is_void)
+ Printf(inline_extra_method, "return ");
+ String *methodcall = Swig_method_call(super, l);
+ Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
+ Delete(methodcall);
+ Delete(extra_method_name);
+ }
+
+ /* emit the director method */
+ if (status == SWIG_OK) {
+ if (!Getattr(n, "defaultargs")) {
+ Wrapper_print(w, f_directors);
+ Printv(f_directors_h, declaration, NIL);
+ Printv(f_directors_h, inline_extra_method, NIL);
+ }
+ }
+
+ /* clean up */
+ Delete(wrap_args);
+ Delete(return_type);
+ Delete(pclassname);
+ DelWrapper(w);
+ return status;
}
/* -----------------------------------------------------------------------------
From c6f3ac542052528b128f45c8cb4ba046702117aa Mon Sep 17 00:00:00 2001
From: Olly Betts
Date: Thu, 16 Dec 2010 12:54:01 +0000
Subject: [PATCH 056/317] Fix typo in code (found by cppcheck)
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12352 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/test-suite/guilescm/ext_test_external.cxx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Examples/test-suite/guilescm/ext_test_external.cxx b/Examples/test-suite/guilescm/ext_test_external.cxx
index 4b65f4953..713e5d2d0 100644
--- a/Examples/test-suite/guilescm/ext_test_external.cxx
+++ b/Examples/test-suite/guilescm/ext_test_external.cxx
@@ -10,7 +10,7 @@ SCM test_create()
newobj = new A();
type = SWIG_TypeQuery("A *");
- result = SWIG_NewPointerObj(result, type, 1);
+ result = SWIG_NewPointerObj(newobj, type, 1);
return result;
#undef FUNC_NAME
From 3a86f2068ffca467f9aac0a06ac085cdb2af4e8d Mon Sep 17 00:00:00 2001
From: Stefan Zager
Date: Mon, 20 Dec 2010 23:35:18 +0000
Subject: [PATCH 057/317] Added support for multiple inheritance. Not as hard
as I feared.
Apply operator features to both the operator name, and the renamed
"__*__" method. That's the only way to hit all corners.
Added support for %pythonnondynamic. I believe this implementation
is more correct than the existing implementation, but I'm still
waiting for an adjudication on the behavior of the python_nondynamic
test.
Current list of unsupported features that require minor tweaks
to the test suite:
- 'this' member variable is obsolete.
- No support for reversible operator overloads (e.g., __radd__). You
can still support this:
a = MyString("foo")
b = "bar"
c = a + b
... but you can't do this:
a = "foo"
b = MyString("bar")
c = a + b
With the tweaks, the test suite now fails on python_nondynamic.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12353 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/python/builtin.swg | 30 ++++----
Lib/python/pyinit.swg | 6 ++
Lib/python/pyopers.swg | 4 +-
Lib/python/pyrun.swg | 49 +++++++++++++
Source/Modules/python.cxx | 148 ++++++++++++++++++++++++++++----------
5 files changed, 182 insertions(+), 55 deletions(-)
diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg
index 7a5ad8664..9b385ddfd 100644
--- a/Lib/python/builtin.swg
+++ b/Lib/python/builtin.swg
@@ -115,6 +115,21 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \
return result; \
}
+SWIGINTERN int
+pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure)
+{
+ if (!closure)
+ return -1;
+ PyObject *tuple = PyTuple_New(1);
+ assert(tuple);
+ PyTuple_SET_ITEM(tuple, 0, val);
+ Py_XINCREF(val);
+ PyObject *result = ((PyCFunction) closure)(obj, tuple);
+ Py_DECREF(tuple);
+ Py_XDECREF(result);
+ return result ? 0 : -1;
+}
+
#ifdef __cplusplus
namespace {
@@ -146,21 +161,6 @@ template void py_builtin_dealloc (PyObject *pyobj)
(*pyobj->ob_type->tp_free)(pyobj);
}
-SWIGINTERN int
-pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure)
-{
- if (!closure)
- return -1;
- PyObject *tuple = PyTuple_New(1);
- assert(tuple);
- PyTuple_SET_ITEM(tuple, 0, val);
- Py_XINCREF(val);
- PyObject *result = ((PyCFunction) closure)(obj, tuple);
- Py_DECREF(tuple);
- Py_XDECREF(result);
- return result ? 0 : -1;
-}
-
} // namespace {
#endif
diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg
index 5ee13f34b..f873e3968 100644
--- a/Lib/python/pyinit.swg
+++ b/Lib/python/pyinit.swg
@@ -7,6 +7,8 @@
%init %{
#ifdef __cplusplus
+#include
+
extern "C" {
#endif
@@ -338,7 +340,11 @@ SWIG_init(void) {
#if defined(SWIGPYTHON_BUILTIN)
PyTypeObject *builtin_pytype = 0;
+ PyObject *propargs = NULL, *propget = NULL, *propset = NULL, *propobj = NULL;
+ std::vector builtin_bases;
swig_type_info *builtin_basetype = 0;
+ PyObject *base_tuple = NULL;
+ int i;
SWIG_Python_builtin_imports();
#endif
diff --git a/Lib/python/pyopers.swg b/Lib/python/pyopers.swg
index 851524219..84058da96 100644
--- a/Lib/python/pyopers.swg
+++ b/Lib/python/pyopers.swg
@@ -6,8 +6,8 @@
#ifdef __cplusplus
#if defined(SWIGPYTHON_BUILTIN)
-#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper; %feature("pyslot", #slot, functype=#functp) oper;
-#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("pycompare", #comptype) oper;
+#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper; %feature("pyslot", #slot, functype=#functp) oper; %feature("pyslot", #slot, functype=#functp) pyname;
+#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("pycompare", #comptype) oper; %feature("pycompare", #comptype) pyname;
#else
#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper
#define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype)
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index 96fdcf085..503e42711 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -1628,6 +1628,55 @@ SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags)
return result;
}
+// Cribbed from Objects/object.c in the python source code and modified
+SWIGRUNTIME int
+SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value)
+{
+ PyTypeObject *tp = obj->ob_type;
+ PyObject *descr;
+ descrsetfunc f;
+ int res = -1;
+
+ if (!PyString_Check(name)) {
+#ifdef Py_USING_UNICODE
+ if (PyUnicode_Check(name)) {
+ name = PyUnicode_AsEncodedString(name, NULL, NULL);
+ if (name == NULL)
+ return -1;
+ }
+ else
+#endif
+ {
+ PyErr_Format(PyExc_TypeError,
+ "attribute name must be string, not '%.200s'",
+ name->ob_type->tp_name);
+ return -1;
+ }
+ }
+ else
+ Py_INCREF(name);
+
+ if (tp->tp_dict == NULL) {
+ if (PyType_Ready(tp) < 0)
+ goto done;
+ }
+
+ descr = _PyType_Lookup(tp, name);
+ f = NULL;
+ if (descr != NULL && PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS))
+ f = descr->ob_type->tp_descr_set;
+ if (f == NULL)
+ PyErr_Format(PyExc_AttributeError,
+ "'%.100s' object has no attribute '%.200s'",
+ tp->tp_name, PyString_AS_STRING(name));
+ else
+ res = f(descr, obj, value);
+
+done:
+ Py_DECREF(name);
+ return res;
+}
+
#ifdef __cplusplus
#if 0
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx
index 1a4209092..a10ba2179 100644
--- a/Source/Modules/python.cxx
+++ b/Source/Modules/python.cxx
@@ -48,7 +48,6 @@ static String *f_shadow_imports = 0;
static String *f_shadow_import_stmts = 0;
static String *f_shadow_stubs = 0;
static Hash *builtin_getset = 0;
-static String *builtin_richcompare = 0;
static String *methods;
static String *class_name;
@@ -572,7 +571,6 @@ public:
f_directors_h = NewString("");
f_directors = NewString("");
builtin_getset = NewHash();
- builtin_richcompare = NewString("");
if (builtin) {
f_builtins = NewString("");
@@ -1906,6 +1904,7 @@ public:
String *iname = Getattr(n, "sym:name");
SwigType *d = Getattr(n, "type");
ParmList *l = Getattr(n, "parms");
+ Node *parent = Swig_methodclass(n);
int director_method = 0;
@@ -2059,7 +2058,6 @@ public:
if (constructor && num_arguments == 1 && num_required == 1) {
if (Cmp(storage, "explicit") == 0) {
- Node *parent = Swig_methodclass(n);
if (GetFlag(parent, "feature:implicitconv")) {
String *desc = NewStringf("SWIGTYPE%s", SwigType_manglestr(Getattr(n, "type")));
Printf(f->code, "if (SWIG_CheckImplicit(%s)) SWIG_fail;\n", desc);
@@ -2097,7 +2095,7 @@ public:
}
/* Keyword argument handling */
- if (allow_kwargs) {
+ if (allow_kwargs && parse_from_tuple) {
if (Len(pn)) {
String *tmp = 0;
String *name = pn;
@@ -2380,7 +2378,6 @@ public:
String *type = Getattr(n, "type");
//Node *classNode = Swig_methodclass(n);
//Node *module = Getattr(classNode, "module");
- Node *parent = Swig_methodclass(n);
Node *module = Getattr(parent, "module");
Node *target = Swig_directormap(module, type);
if (target)
@@ -2545,7 +2542,6 @@ public:
Printv(f_wrappers, closure_decl, "\n\n", NIL);
Append(closure_name, "_closure");
}
- Node *parent = Swig_methodclass(n);
Setattr(parent, feature_name, closure_name);
Delete(feature_name);
Delete(closure_name);
@@ -2553,8 +2549,11 @@ public:
/* Handle comparison operators for builtin types */
String *compare = Getattr(n, "feature:pycompare");
- if (compare)
- Printf(builtin_richcompare, " case %s : result = %s(self, tuple); break;\n", compare, wrapper_name);
+ if (compare) {
+ Hash *richcompare = Getattr(parent, "richcompare");
+ assert(richcompare);
+ Setattr(richcompare, compare, wrapper_name);
+ }
Delete(self_parse);
Delete(parse_args);
@@ -2597,7 +2596,7 @@ public:
Python dictionary. */
if (!have_globals) {
- Printf(f_init, "\t PyDict_SetItemString(d,(char*)\"%s\", SWIG_globals());\n", global_name);
+ Printf(f_init, "\t PyDict_SetItemString(md,(char*)\"%s\", SWIG_globals());\n", global_name);
have_globals = 1;
if (!builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER))) {
Printf(f_shadow_stubs, "%s = %s.%s\n", global_name, module, global_name);
@@ -2605,8 +2604,8 @@ public:
}
int assignable = is_assignable(n);
- if (!builtin && (shadow) && !assignable && !in_class)
- Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname);
+ if (!builtin && shadow && !assignable && !in_class)
+ Printf(f_shadow_stubs, "%s = %s.%s\n", iname, global_name, iname);
String *getname = Swig_name_get(NSPACE_TODO, iname);
String *setname = Swig_name_set(NSPACE_TODO, iname);
@@ -2616,6 +2615,12 @@ public:
/* Create a function for setting the value of the variable */
if (assignable) {
Setattr(n, "wrap:name", varsetname);
+ if (builtin && in_class) {
+ String *method_def = NewStringf("%s_method_def", varsetname);
+ Printf(f_builtins, "static PyMethodDef %s = { const_cast(\"%s\"), (PyCFunction)%s, METH_VARARGS, \"\" };\n", method_def, name, varsetname);
+ Setattr(n, "builtin:setter", method_def);
+ Delete(method_def);
+ }
Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", varsetname);
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "_val");
@@ -2647,6 +2652,12 @@ public:
/* Create a function for getting the value of a variable */
Setattr(n, "wrap:name", vargetname);
+ if (builtin && in_class) {
+ String *method_def = NewStringf("%s_method_def", vargetname);
+ Printf(f_builtins, "static PyMethodDef %s = { const_cast(\"%s\"), (PyCFunction)%s, METH_NOARGS, \"\" };\n", method_def, name, vargetname);
+ Setattr(n, "builtin:getter", method_def);
+ Delete(method_def);
+ }
int addfail = 0;
Printf(getf->def, "SWIGINTERN PyObject *%s(void) {", vargetname);
Wrapper_add_local(getf, "pyobj", "PyObject *pyobj = 0");
@@ -2670,7 +2681,9 @@ public:
/* Now add this to the variable linking mechanism */
Printf(f_init, "\t SWIG_addvarlink(SWIG_globals(),(char*)\"%s\",%s, %s);\n", iname, vargetname, varsetname);
-
+ if (builtin && shadow && !assignable && !in_class)
+ Printf(f_init, "\t PyDict_SetItemString(md, (char*)\"%s\", PyObject_GetAttrString(SWIG_globals(), \"%s\"));\n",
+ iname, iname);
Delete(vargetname);
Delete(varsetname);
Delete(getname);
@@ -2991,7 +3004,7 @@ public:
Setattr(n, "single_inh", "1");
return true;
}
- if (baselist && Len(baselist) == 1) {
+ //if (baselist && Len(baselist) == 1) {
Iterator b = First(baselist);
if (this->get_single_base(b.item)) {
if (base)
@@ -2999,7 +3012,7 @@ public:
Setattr(n, "single_inh", "1");
return true;
}
- }
+ //}
return false;
}
@@ -3030,11 +3043,38 @@ public:
* classHandler()
* ------------------------------------------------------------ */
- void builtin_pre_decl(Node *n, Node *base_node) {
+ void builtin_pre_decl(Node *n, Node *) {
String *name = Getattr(n, "name");
String *rname = SwigType_namestr(name);
Printf(f_init, tab4 "builtin_pytype = &PySwigBuiltin< %s >::pytype;\n", rname);
Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n");
+ List *baselist = Getattr(n, "bases");
+ if (baselist) {
+ for (Iterator b = First(baselist); b.item; b = Next(b)) {
+ String *bname = Getattr(b.item, "name");
+ if (!bname || GetFlag(b.item, "feature:ignore"))
+ continue;
+ String *base_name = Copy(bname);
+ SwigType_add_pointer(base_name);
+ String *base_mname = SwigType_manglestr(base_name);
+ Printf(f_init, " builtin_basetype = SWIG_MangledTypeQuery(\"%s\");\n", base_mname);
+ Printv(f_init, " if (builtin_basetype && builtin_basetype->clientdata && ((SwigPyClientData*) builtin_basetype->clientdata)->pytype)\n", NIL);
+ Printv(f_init, " builtin_bases.push_back(((SwigPyClientData*) builtin_basetype->clientdata)->pytype);\n", NIL);
+ Delete(base_name);
+ Delete(base_mname);
+ }
+ }
+ Printv(f_init, " if (!builtin_bases.size())\n", NIL);
+ Printv(f_init, " builtin_bases.push_back(SwigPyObject_type());\n", NIL);
+ Printv(f_init, " builtin_pytype->tp_base = builtin_bases[0];\n", NIL);
+ Printv(f_init, " Py_INCREF((PyObject*) builtin_bases[0]);\n", NIL);
+ Printv(f_init, " base_tuple = PyTuple_New(builtin_bases.size());\n", NIL);
+ Printv(f_init, " for (i = 0; i < builtin_bases.size(); ++i) {\n", NIL);
+ Printv(f_init, " PyTuple_SET_ITEM(base_tuple, i, (PyObject*) builtin_bases[i]);\n", NIL);
+ Printv(f_init, " Py_INCREF((PyObject*) builtin_bases[i]);\n", NIL);
+ Printv(f_init, " }\n", NIL);
+ Printv(f_init, " builtin_bases.clear();\n", NIL);
+ /*
if (base_node) {
String *base_name = Copy(Getattr(base_node, "name"));
SwigType_add_pointer(base_name);
@@ -3047,8 +3087,8 @@ public:
Delete(base_name);
} else {
Printv(f_init, tab4, "builtin_pytype->tp_base = SwigPyObject_type();\n", NIL);
- //Printv(f_init, tab4, "builtin_pytype->tp_base = &PyBaseObject_Type;\n", NIL);
}
+ */
Printf(f_init, tab4 "builtin_pytype->tp_dict = d = PyDict_New();\n");
Delete(rname);
}
@@ -3160,13 +3200,20 @@ public:
Printf(f, " PyTuple_SET_ITEM(tuple, 0, other);\n");
Printf(f, " Py_XINCREF(other);\n");
Printf(f, " switch (op) {\n");
- Printv(f, builtin_richcompare, NIL);
+
+ Hash *richcompare = Getattr(n, "richcompare");
+ assert(richcompare);
+ for (Iterator i = First(richcompare); i.item; i = Next(i))
+ Printf(f, " case %s : result = %s(self, tuple); break;\n", i.key, i.item);
+
Printf(f, " default : PyErr_Format(PyExc_TypeError, \"Cannot compare a(n) '%%s' to a(n) '%%s'\", self->ob_type->tp_name, other ? other->ob_type->tp_name : \"NIL\");\n");
Printf(f, " }\n");
Printf(f, " Py_DECREF(tuple);\n");
Printf(f, " return result;\n");
Printf(f, "}\n\n");
- Clear(builtin_richcompare);
+
+ if (GetFlag(n, "feature:python:nondynamic"))
+ Setattr(n, "feature:tp_setattro", "SWIG_Python_NonDynamicSetAttr");
// Type object
String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES");
@@ -3241,7 +3288,6 @@ public:
int oldclassic = classic;
int oldmodern = modern;
File *f_shadow_file = f_shadow;
- bool single_inh = false;
Node *base_node = NULL;
if (shadow) {
@@ -3269,8 +3315,7 @@ public:
if (!addSymbol(class_name, n))
return SWIG_ERROR;
- single_inh = builtin && get_single_base(n, &base_node);
- if (builtin && !single_inh) {
+ if (builtin && !get_single_base(n, &base_node)) {
Swig_warning(WARN_PYTHON_MULTIPLE_INH, Getfile(n), Getline(n),
"Class '%s' ignored, because it has multiple inheritance, which is incompatible with the '-builtin' option.\n", real_classname);
return SWIG_OK;
@@ -3304,6 +3349,18 @@ public:
}
}
+ if (builtin) {
+ Hash *richcompare = NULL;
+ if (base_node) {
+ Hash *base_richcompare = Getattr(base_node, "richcompare");
+ assert(base_richcompare);
+ richcompare = Copy(base_richcompare);
+ } else {
+ richcompare = NewHash();
+ }
+ Setattr(n, "richcompare", richcompare);
+ }
+
/* dealing with abstract base class */
String *abcs = Getattr(n, "feature:python:abc");
if (py3 && abcs) {
@@ -3313,7 +3370,7 @@ public:
Printv(base_class, abcs, NIL);
}
- if (!single_inh) {
+ if (!builtin) {
Printv(f_shadow, "class ", class_name, NIL);
if (Len(base_class)) {
@@ -3367,7 +3424,7 @@ public:
/* Emit all of the members */
in_class = 1;
- if (single_inh) {
+ if (builtin) {
class_members = NewHash();
builtin_pre_decl(n, base_node);
}
@@ -3397,7 +3454,7 @@ public:
/* Complete the class */
if (shadow) {
/* Generate a class registration function */
- if (!single_inh) {
+ if (!builtin) {
String *smartptr = Getattr(n, "feature:smartptr"); // Replace storing a pointer to underlying class with a smart pointer (intended for use with non-intrusive smart pointers)
SwigType *smart = 0;
if (smartptr) {
@@ -3437,10 +3494,10 @@ public:
Delete(realct);
}
if (!have_constructor) {
- if (!single_inh)
+ if (!builtin)
Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined",
(Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
- } else if (fastinit && !single_inh) {
+ } else if (fastinit && !builtin) {
Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
Printv(f_wrappers, " return SWIG_Python_InitShadowInstance(args);\n", "}\n\n", NIL);
@@ -3448,7 +3505,7 @@ public:
add_method(cname, cname, 0);
Delete(cname);
}
- if (!have_repr && !single_inh) {
+ if (!have_repr && !builtin) {
/* Supply a repr method for this class */
String *rname = SwigType_namestr(real_classname);
if (new_repr) {
@@ -3459,7 +3516,7 @@ public:
Delete(rname);
}
- if (single_inh) {
+ if (builtin) {
builtin_post_decl(f_builtins, n);
String *rname = SwigType_namestr(real_classname);
Printf(f_builtins, "template <> PyMethodDef PySwigBuiltin< %s >::methods[] = {\n", rname);
@@ -3472,11 +3529,11 @@ public:
}
/* Now emit methods */
- if (!single_inh)
+ if (!builtin)
Printv(f_shadow_file, f_shadow, NIL);
/* Now the Ptr class */
- if (classptr && !single_inh) {
+ if (classptr && !builtin) {
Printv(f_shadow_file, "\nclass ", class_name, "Ptr(", class_name, "):\n", tab4, "def __init__(self, this):\n", NIL);
if (!modern) {
Printv(f_shadow_file,
@@ -3489,7 +3546,7 @@ public:
}
}
- if (!single_inh) {
+ if (!builtin) {
if (fastproxy) {
List *shadow_list = Getattr(n, "shadow_methods");
for (int i = 0; i < Len(shadow_list); ++i) {
@@ -3508,7 +3565,7 @@ public:
Clear(f_shadow_stubs);
}
- if (single_inh) {
+ if (builtin) {
Dump(f_shadow, f_builtins);
Printf(f_builtins, " {NULL} // Sentinel\n};\n\n");
Delete(class_members);
@@ -3573,15 +3630,14 @@ public:
String *fullname = Swig_name_member(NULL, class_name, symname);
String *wname = Swig_name_wrapper(fullname);
Setattr(class_members, name, name);
- String *pyflags = NewString("METH_VARARGS");
- Printf(f_shadow, " { \"%s\", (PyCFunction) %s, %s, \"\" },\n", Char(name), wname, Char(pyflags));
+ int allow_kwargs = check_kwargs(n);
+ Printf(f_shadow, " { \"%s\", (PyCFunction) %s, METH_VARARGS%s, \"\" },\n",
+ name, wname, allow_kwargs ? "|METH_KEYWORDS" : "");
Delete(name);
Delete(fullname);
Delete(wname);
- Delete(pyflags);
}
} else if (shadow) {
- int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
int fproxy = fastproxy;
if (Strcmp(symname, "__repr__") == 0) {
have_repr = 1;
@@ -3595,6 +3651,7 @@ public:
Delete(pycode);
fproxy = 0;
} else {
+ int allow_kwargs = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
String *parms = make_pyParmList(n, true, false, allow_kwargs);
String *callParms = make_pyParmList(n, true, true, allow_kwargs);
if (!have_addtofunc(n)) {
@@ -3996,19 +4053,34 @@ public:
add_method(setname, wrapsetname, 0);
DelWrapper(f);
}
- if (!modern) {
+ if (!modern && !builtin) {
if (assignable) {
Printv(f_shadow, tab4, "__swig_setmethods__[\"", symname, "\"] = ", module, ".", setname, "\n", NIL);
}
Printv(f_shadow, tab4, "__swig_getmethods__[\"", symname, "\"] = ", module, ".", getname, "\n", NIL);
}
- if (!classic) {
+ if (!classic && !builtin) {
if (!assignable) {
Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ")\n", NIL);
} else {
Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, " = _swig_property(", module, ".", getname, ", ", module, ".", setname, ")\n", NIL);
}
}
+ String *getter = Getattr(n, "builtin:getter");
+ String *setter = Getattr(n, "builtin:setter");
+ if (getter) {
+ Printf(f_init, " propargs = PyTuple_New(%d);\n", setter ? 2 : 1);
+ Printf(f_init, " propget = PyCFunction_New(&%s, NULL);\n", getter);
+ Printf(f_init, " PyTuple_SET_ITEM(propargs, 0, propget);\n");
+ if (setter) {
+ Printf(f_init, " propset = PyCFunction_New(&%s, NULL);\n", setter);
+ Printf(f_init, " PyTuple_SET_ITEM(propargs, 1, propset);\n");
+ }
+ Printf(f_init, " propobj = PyType_Type.tp_call((PyObject*) &PyProperty_Type, propargs, NULL);\n");
+ Printf(f_init, " Py_DECREF(propargs);\n");
+ Printf(f_init, " PyDict_SetItemString(d, \"%s\", propobj);\n", symname);
+ Printf(f_init, " Py_DECREF(propobj);\n");
+ }
Delete(mname);
Delete(getname);
Delete(wrapgetname);
From 7f4283f6843991f189b1b6ba4ad6f1d58c1ba4af Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 23 Dec 2010 20:27:34 +0000
Subject: [PATCH 058/317] Fix special variable not being expanded for csvarin
typemaps when used for global variables
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12354 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
.../test-suite/csharp/csharp_prepost_runme.cs | 37 +++++++++++++++++++
Examples/test-suite/csharp_prepost.i | 5 ++-
Source/Modules/csharp.cxx | 1 +
3 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/Examples/test-suite/csharp/csharp_prepost_runme.cs b/Examples/test-suite/csharp/csharp_prepost_runme.cs
index d0bacdaba..f76dae38e 100644
--- a/Examples/test-suite/csharp/csharp_prepost_runme.cs
+++ b/Examples/test-suite/csharp/csharp_prepost_runme.cs
@@ -55,6 +55,43 @@ public class csharp_prepost_runme {
throw new Exception("Expecting CustomInt attribute");
}
}
+ // Dates
+ {
+ // pre post typemap attributes example
+ System.DateTime dateIn = new System.DateTime(2011, 4, 13);
+ System.DateTime dateOut = new System.DateTime();
+
+ // Note in calls below, dateIn remains unchanged and dateOut
+ // is set to a new value by the C++ call
+ csharp_prepostNamespace.Action action = new csharp_prepostNamespace.Action(dateIn, out dateOut);
+ if (dateOut != dateIn)
+ throw new Exception("dates wrong");
+
+ dateIn = new System.DateTime(2012, 7, 14);
+ action.doSomething(dateIn, out dateOut);
+ if (dateOut != dateIn)
+ throw new Exception("dates wrong");
+
+ System.DateTime refDate = new System.DateTime(1999, 12, 31);
+ if (csharp_prepost.ImportantDate != refDate)
+ throw new Exception("dates wrong");
+
+ refDate = new System.DateTime(1999, 12, 31);
+ csharp_prepost.ImportantDate = refDate;
+ System.DateTime importantDate = csharp_prepost.ImportantDate;
+ if (importantDate != refDate)
+ throw new Exception("dates wrong");
+
+ System.DateTime christmasEve = new System.DateTime(2000, 12, 24);
+ csharp_prepost.addYears(ref christmasEve, 10);
+ if (christmasEve != new System.DateTime(2010, 12, 24))
+ throw new Exception("dates wrong");
+
+ Person person = new Person();
+ person.Birthday = christmasEve;
+ if (person.Birthday != christmasEve)
+ throw new Exception("dates wrong");
+ }
}
private static void Assert(double d1, double d2) {
if (d1 != d2)
diff --git a/Examples/test-suite/csharp_prepost.i b/Examples/test-suite/csharp_prepost.i
index 817f5b9b9..31e6ec753 100644
--- a/Examples/test-suite/csharp_prepost.i
+++ b/Examples/test-suite/csharp_prepost.i
@@ -79,7 +79,7 @@ struct PrePost2 {
// Check attributes in the typemaps
%typemap(cstype, inattributes="[CustomInt]") int val "int"
-%typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int "tmp_$csinput"
+%typemap(csin, pre=" int tmp_$csinput = $csinput * 100;") int val "tmp_$csinput"
%typemap(imtype, out="IntPtr/*overridden*/", outattributes="[CustomIntPtr]") CsinAttributes * "HandleRef/*overridden*/"
%inline %{
@@ -188,5 +188,8 @@ void subtractYears(CDate *pDate, int years) {
%inline %{
CDate ImportantDate = CDate(1999, 12, 31);
+struct Person {
+ CDate Birthday;
+};
%}
diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
index 6ecd18aed..d93891795 100644
--- a/Source/Modules/csharp.cxx
+++ b/Source/Modules/csharp.cxx
@@ -2343,6 +2343,7 @@ public:
SwigType *pt = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:csvarin"))) {
substituteClassname(pt, tm);
+ Replaceall(tm, "$csinput", "value");
Replaceall(tm, "$imcall", imcall);
excodeSubstitute(n, tm, "csvarin", p);
Printf(proxy_class_code, "%s", tm);
From 4f99df61c52a4085a474ec761a74833a4e75bf07 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 23 Dec 2010 20:28:17 +0000
Subject: [PATCH 059/317] Fix special variable not being expanded for csvarin
typemaps when used for global variables
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12355 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/CHANGES.current b/CHANGES.current
index 9449c2f4c..7cedad228 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (in progress)
===========================
+2010-12-23: wsfulton
+ [C#] Fix $csinput special variable not being expanded for csvarin typemaps
+ when used for global variables. Reported by Vadim Zeitlin.
+
2010-12-14: wsfulton
Fix $basemangle expansion in array typemaps. For example if type is int *[3],
$basemangle expands to _p_int.
From 9a0f7ed06ccd4afbdf56e3828ceaa11020ed1005 Mon Sep 17 00:00:00 2001
From: William S Fulton
Date: Thu, 23 Dec 2010 20:30:41 +0000
Subject: [PATCH 060/317] Some more constness added to DOH and code comment
consistency changes
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12356 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Source/DOH/doh.h | 6 ++--
Source/DOH/dohint.h | 2 +-
Source/DOH/hash.c | 2 +-
Source/DOH/string.c | 68 ++++++++++++++++++++++-----------------------
4 files changed, 39 insertions(+), 39 deletions(-)
diff --git a/Source/DOH/doh.h b/Source/DOH/doh.h
index 6fa352547..bca5f0f0f 100644
--- a/Source/DOH/doh.h
+++ b/Source/DOH/doh.h
@@ -277,9 +277,9 @@ extern int DohGetmark(DOH *obj);
* ----------------------------------------------------------------------------- */
extern DOHString *DohNewStringEmpty(void);
-extern DOHString *DohNewString(const DOH *c);
-extern DOHString *DohNewStringWithSize(const DOH *c, int len);
-extern DOHString *DohNewStringf(const DOH *fmt, ...);
+extern DOHString *DohNewString(const DOHString_or_char *c);
+extern DOHString *DohNewStringWithSize(const DOHString_or_char *c, int len);
+extern DOHString *DohNewStringf(const DOHString_or_char *fmt, ...);
extern int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2);
extern int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n);
diff --git a/Source/DOH/dohint.h b/Source/DOH/dohint.h
index 3d812b849..9f5c06272 100644
--- a/Source/DOH/dohint.h
+++ b/Source/DOH/dohint.h
@@ -54,7 +54,7 @@ typedef struct {
/* String methods */
typedef struct {
- int (*doh_replace) (DOH *obj, DOH *old, DOH *rep, int flags);
+ int (*doh_replace) (DOH *obj, const DOHString_or_char *old, const DOHString_or_char *rep, int flags);
void (*doh_chop) (DOH *obj);
} DohStringMethods;
diff --git a/Source/DOH/hash.c b/Source/DOH/hash.c
index 48afd2e54..241383327 100644
--- a/Source/DOH/hash.c
+++ b/Source/DOH/hash.c
@@ -363,7 +363,7 @@ static DohIterator Hash_nextiter(DohIterator iter) {
}
/* -----------------------------------------------------------------------------
- * Hash_keys(DOH *)
+ * Hash_keys()
*
* Return a list of keys
* ----------------------------------------------------------------------------- */
diff --git a/Source/DOH/string.c b/Source/DOH/string.c
index 142b88c4d..c326e9f40 100644
--- a/Source/DOH/string.c
+++ b/Source/DOH/string.c
@@ -29,7 +29,7 @@ typedef struct String {
} String;
/* -----------------------------------------------------------------------------
- * void *String_data() - Return as a 'void *'
+ * String_data() - Return as a 'void *'
* ----------------------------------------------------------------------------- */
static void *String_data(DOH *so) {
@@ -44,7 +44,7 @@ static void *String_data(DOH *so) {
*/
/* -----------------------------------------------------------------------------
- * int String_dump() - Serialize a string onto out
+ * String_dump() - Serialize a string onto out
* ----------------------------------------------------------------------------- */
static int String_dump(DOH *so, DOH *out) {
@@ -105,7 +105,7 @@ static int String_len(DOH *so) {
/* -----------------------------------------------------------------------------
- * int String_cmp() - Compare two strings
+ * String_cmp() - Compare two strings
* ----------------------------------------------------------------------------- */
static int String_cmp(DOH *so1, DOH *so2) {
@@ -137,7 +137,7 @@ static int String_cmp(DOH *so1, DOH *so2) {
}
/* -----------------------------------------------------------------------------
- * int String_equal() - Say if two string are equal
+ * String_equal() - Say if two string are equal
* ----------------------------------------------------------------------------- */
static int String_equal(DOH *so1, DOH *so2) {
@@ -174,7 +174,7 @@ static int String_equal(DOH *so1, DOH *so2) {
}
/* -----------------------------------------------------------------------------
- * int String_hash() - Compute string hash value
+ * String_hash() - Compute string hash value
* ----------------------------------------------------------------------------- */
static int String_hash(DOH *so) {
@@ -203,10 +203,10 @@ static int String_hash(DOH *so) {
}
/* -----------------------------------------------------------------------------
- * DohString_append(String *s, const char *newstr) - Append to s
+ * DohString_append() - Append to s
* ----------------------------------------------------------------------------- */
-void DohString_append(DOH *so, DOH *str) {
+static void DohString_append(DOH *so, const DOHString_or_char *str) {
int oldlen, newlen, newmaxsize, l, sp;
char *tc;
String *s = (String *) ObjData(so);
@@ -251,7 +251,7 @@ void DohString_append(DOH *so, DOH *str) {
/* -----------------------------------------------------------------------------
- * void String_clear() - Clear a string
+ * String_clear() - Clear a string
* ----------------------------------------------------------------------------- */
static void String_clear(DOH *so) {
@@ -264,7 +264,7 @@ static void String_clear(DOH *so) {
}
/* -----------------------------------------------------------------------------
- * void String_insert() - Insert a string
+ * String_insert() - Insert a string
* ----------------------------------------------------------------------------- */
static int String_insert(DOH *so, int pos, DOH *str) {
@@ -320,7 +320,7 @@ static int String_insert(DOH *so, int pos, DOH *str) {
}
/* -----------------------------------------------------------------------------
- * int String_delitem() - Delete a character
+ * String_delitem() - Delete a character
* ----------------------------------------------------------------------------- */
static int String_delitem(DOH *so, int pos) {
@@ -346,7 +346,7 @@ static int String_delitem(DOH *so, int pos) {
}
/* -----------------------------------------------------------------------------
- * int String_delslice() - Delete a range
+ * String_delslice() - Delete a range
* ----------------------------------------------------------------------------- */
static int String_delslice(DOH *so, int sindex, int eindex) {
@@ -384,7 +384,7 @@ static int String_delslice(DOH *so, int sindex, int eindex) {
}
/* -----------------------------------------------------------------------------
- * DOH *String_str() - Returns a string (used by printing commands)
+ * String_str() - Returns a string (used by printing commands)
* ----------------------------------------------------------------------------- */
static DOH *String_str(DOH *so) {
@@ -394,7 +394,7 @@ static DOH *String_str(DOH *so) {
}
/* -----------------------------------------------------------------------------
- * int String_read() - Read data from a string
+ * String_read() - Read data from a string
* ----------------------------------------------------------------------------- */
static int String_read(DOH *so, void *buffer, int len) {
@@ -417,7 +417,7 @@ static int String_read(DOH *so, void *buffer, int len) {
}
/* -----------------------------------------------------------------------------
- * int String_write() - Write data to a string
+ * String_write() - Write data to a string
* ----------------------------------------------------------------------------- */
static int String_write(DOH *so, const void *buffer, int len) {
int newlen;
@@ -441,7 +441,7 @@ static int String_write(DOH *so, const void *buffer, int len) {
}
/* -----------------------------------------------------------------------------
- * int String_seek() - Seek to a new position
+ * String_seek() - Seek to a new position
* ----------------------------------------------------------------------------- */
static int String_seek(DOH *so, long offset, int whence) {
@@ -498,7 +498,7 @@ static int String_seek(DOH *so, long offset, int whence) {
}
/* -----------------------------------------------------------------------------
- * long String_tell() - Return current position
+ * String_tell() - Return current position
* ----------------------------------------------------------------------------- */
static long String_tell(DOH *so) {
@@ -507,7 +507,7 @@ static long String_tell(DOH *so) {
}
/* -----------------------------------------------------------------------------
- * int String_putc()
+ * String_putc()
* ----------------------------------------------------------------------------- */
static int String_putc(DOH *so, int ch) {
@@ -538,7 +538,7 @@ static int String_putc(DOH *so, int ch) {
}
/* -----------------------------------------------------------------------------
- * int String_getc()
+ * String_getc()
* ----------------------------------------------------------------------------- */
static int String_getc(DOH *so) {
@@ -554,7 +554,7 @@ static int String_getc(DOH *so) {
}
/* -----------------------------------------------------------------------------
- * int String_ungetc()
+ * String_ungetc()
* ----------------------------------------------------------------------------- */
static int String_ungetc(DOH *so, int ch) {
@@ -569,12 +569,6 @@ static int String_ungetc(DOH *so, int ch) {
return ch;
}
-/* -----------------------------------------------------------------------------
- * replace_simple(String *str, char *token, char *rep, int flags, int count)
- *
- * Replaces count non-overlapping occurrences of token with rep in a string.
- * ----------------------------------------------------------------------------- */
-
static char *end_quote(char *s) {
char *qs;
char qc;
@@ -659,6 +653,12 @@ static char *match_identifier_end(char *base, char *s, char *token, int tokenlen
return 0;
}
+/* -----------------------------------------------------------------------------
+ * replace_simple()
+ *
+ * Replaces count non-overlapping occurrences of token with rep in a string.
+ * ----------------------------------------------------------------------------- */
+
static int replace_simple(String *str, char *token, char *rep, int flags, int count, char *(*match) (char *, char *, char *, int)) {
int tokenlen; /* Length of the token */
int replen; /* Length of the replacement */
@@ -885,10 +885,10 @@ static int replace_simple(String *str, char *token, char *rep, int flags, int co
}
/* -----------------------------------------------------------------------------
- * int String_replace()
+ * String_replace()
* ----------------------------------------------------------------------------- */
-static int String_replace(DOH *stro, DOH *token, DOH *rep, int flags) {
+static int String_replace(DOH *stro, const DOHString_or_char *token, const DOHString_or_char *rep, int flags) {
int count = -1;
String *str = (String *) ObjData(stro);
@@ -907,7 +907,7 @@ static int String_replace(DOH *stro, DOH *token, DOH *rep, int flags) {
}
/* -----------------------------------------------------------------------------
- * void String_chop(DOH *str)
+ * String_chop()
* ----------------------------------------------------------------------------- */
static void String_chop(DOH *so) {
@@ -1012,10 +1012,10 @@ DohObjInfo DohStringType = {
#define INIT_MAXSIZE 16
/* -----------------------------------------------------------------------------
- * NewString(const char *c) - Create a new string
+ * NewString() - Create a new string
* ----------------------------------------------------------------------------- */
-DOHString *DohNewString(const DOH *so) {
+DOHString *DohNewString(const DOHString_or_char *so) {
int l = 0, max;
String *str;
char *s;
@@ -1073,10 +1073,10 @@ DOHString *DohNewStringEmpty(void) {
}
/* -----------------------------------------------------------------------------
- * NewStringWithSize(const DOH *so, int len) - Create a new string
+ * NewStringWithSize() - Create a new string
* ----------------------------------------------------------------------------- */
-DOHString *DohNewStringWithSize(const DOH *so, int len) {
+DOHString *DohNewStringWithSize(const DOHString_or_char *so, int len) {
int l = 0, max;
String *str;
char *s;
@@ -1111,12 +1111,12 @@ DOHString *DohNewStringWithSize(const DOH *so, int len) {
}
/* -----------------------------------------------------------------------------
- * NewStringf(DOH *fmt, ...)
+ * NewStringf()
*
* Create a new string from a list of objects.
* ----------------------------------------------------------------------------- */
-DOHString *DohNewStringf(const DOH *fmt, ...) {
+DOHString *DohNewStringf(const DOHString_or_char *fmt, ...) {
va_list ap;
DOH *r;
va_start(ap, fmt);
From 38c88a0931c4cd759079a3492f60f47b3ec0fccb Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 30 Dec 2010 02:44:04 +0000
Subject: [PATCH 061/317] [D] Operator overloading support for D1 and D2.
As mentioned in the documentation, opIndexAssign and implicit casting are not supported yet.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12357 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Doc/Manual/D.html | 16 +-
.../test-suite/d/operator_overload_runme.1.d | 89 +++++++
.../test-suite/d/operator_overload_runme.2.d | 91 +++++++
Examples/test-suite/operator_overload.i | 6 +
Examples/test-suite/operator_overload_break.i | 2 +-
Lib/d/dclassgen.swg | 58 ++---
Lib/d/doperators.swg | 238 +++++++++++++++---
7 files changed, 425 insertions(+), 75 deletions(-)
create mode 100644 Examples/test-suite/d/operator_overload_runme.1.d
create mode 100644 Examples/test-suite/d/operator_overload_runme.2.d
diff --git a/Doc/Manual/D.html b/Doc/Manual/D.html
index 959a4f48f..47a8f0e6f 100644
--- a/Doc/Manual/D.html
+++ b/Doc/Manual/D.html
@@ -29,6 +29,7 @@
Other features
D Typemap examples
@@ -391,7 +392,19 @@ struct A {
To determine if a type should be considered primitive, the cprimitive attribute on its dtype attribute is used. For example, the dtype typemap for float has cprimitive="1" , so the code from the nativepointer attribute is taken into account e.g. for float ** or the function pointer float (*)(float *) .
- 20.8.2 Running the test-suite
+ 20.8.2 Operator overloading
+
+
+The D module comes with basic operator overloading support for both D1 and D2. There are, however, a few limitations arising from conceptual differences between C++ and D:
+
+The first key difference is that C++ supports free functions as operators (along with argument-dependent lookup), while D requires operators to be member functions of the class they are operating on. SWIG can only automatically generate wrapping code for member function operators; if you want to use operators defined as free functions in D, you need to handle them manually.
+
+Another set of differences between C++ and D concerns individual operators. For example, there are quite a few operators which are overloadable in C++, but not in D, for example && and || , but also ! , and prefix increment/decrement operators in D1 resp. their postfix pendants in D2 .
+
+There are also some cases where the operators can be translated to D, but the differences in the implementation details are big enough that a rather involved scheme would be required for automatic wrapping them, which has not been implemented yet. This affects, for example, the array subscript operator, [] , in combination with assignments – while operator [] in C++ simply returns a reference which is then written to, D resorts to a separate opIndexAssign method –, or implicit casting (which was introduced in D2 via alias this ). Despite the lack of automatic support, manually handling these cases should be perfectly possible.
+
+
+ 20.8.3 Running the test-suite
As with any other language, the SWIG test-suite can be built for D using the *-d-test-suite targets of the top-level Makefile. By default, D1 is targeted, to build it with D2, use the optional D_VERSION variable, e.g. make check-d-test-suite D_VERSION=2 .
@@ -414,7 +427,6 @@ struct A {
Static linking: Currently, the C wrapper code is compiled into a dynamic library, out of which the symbol addresses are looked up at runtime by the D part. If statically linking the different languages into one binary was supported, a tool-chain capable of performing IPO at link time could inline the wrapping code, effectively reducing the overhead for simple calls to zero.
C array handling: Many data structures in some C/C++ libraries contain array containing of a pointer to the first element and the element count. Currently, one must manually writing wrapper code to be able to access these from D. It should be possible to add a set of SWIG macros to semi-automatically generate conversion code.
- Operator overloading: Currently, operator overloading is supported only to a very limited extent – many C++ operators are just ignored with a warning. The problem here is that the way D handles operator overloading differs quite a lot from the way C++ does it, both syntactically and semantically, and even more so since the advent of template-based operator overloading in D2.
Some generated code might also be a bit rough around the edges, particularly in the following areas:
diff --git a/Examples/test-suite/d/operator_overload_runme.1.d b/Examples/test-suite/d/operator_overload_runme.1.d
new file mode 100644
index 000000000..18a24b91f
--- /dev/null
+++ b/Examples/test-suite/d/operator_overload_runme.1.d
@@ -0,0 +1,89 @@
+module operator_overload_runme;
+
+import operator_overload.Op;
+
+void main() {
+ // Invoke the C++ sanity check first.
+ Op.sanity_check();
+
+ auto a = new Op();
+ auto b = new Op(5);
+ auto c = b;
+ auto d = new Op(2);
+ auto dd = d;
+
+ // test equality
+ assert(a != b);
+ assert(b == c);
+ assert(a != d);
+ assert(d == dd);
+
+ // test <
+ assert(a < b);
+ assert(a <= b);
+ assert(b <= c);
+ assert(b >= c);
+ assert(b > d);
+ assert(b >= d);
+
+ // test +=
+ auto e = new Op(3);
+ e += d;
+ assert(e == b);
+ e -= c;
+ assert(e == a);
+ e = new Op(1);
+ e *= b;
+ assert(e == c);
+ e /= d;
+ assert(e == d);
+ e %= c;
+ assert(e == d);
+
+ // test +
+ auto f = new Op(1);
+ auto g = new Op(1);
+ assert(f + g == new Op(2));
+ assert(f - g == new Op(0));
+ assert(f * g == new Op(1));
+ assert(f / g == new Op(1));
+ assert(f % g == new Op(0));
+
+ // test unary operators
+ assert(-a == a);
+ assert(-b == new Op(-5));
+ // The unary ! operator is not overloadable in D1.
+
+ // test []
+ auto h = new Op(3);
+ assert(h[0]==3);
+ assert(h[1]==0);
+ // Generation of opIndexAssign is not supported yet.
+
+ // test ()
+ auto i = new Op(3);
+ assert(i()==3);
+ assert(i(1)==4);
+ assert(i(1,2)==6);
+
+ // test ++ and --
+ auto j = new Op(100);
+ int original = j.i;
+ {
+ Op newOp = j++;
+ int newInt = original++;
+ assert(j.i == original);
+ assert(newOp.i == newInt);
+ }
+ {
+ Op newOp = j--;
+ int newInt = original--;
+ assert(j.i == original);
+ assert(newOp.i == newInt);
+ }
+ // Prefix increment/decrement operators are lowered to (foo +=/-= 1) in D1,
+ // but the test case does not define an integer overload for operator +=
+ // respectively -=.
+
+ // Implicit casting is not overloadable in D1.
+}
\ No newline at end of file
diff --git a/Examples/test-suite/d/operator_overload_runme.2.d b/Examples/test-suite/d/operator_overload_runme.2.d
new file mode 100644
index 000000000..2ff61cd56
--- /dev/null
+++ b/Examples/test-suite/d/operator_overload_runme.2.d
@@ -0,0 +1,91 @@
+module operator_overload_runme;
+
+import operator_overload.Op;
+
+void main() {
+ // Invoke the C++ sanity check first.
+ Op.sanity_check();
+
+ auto a = new Op();
+ auto b = new Op(5);
+ auto c = b;
+ auto d = new Op(2);
+ auto dd = d;
+
+ // test equality
+ assert(a != b);
+ assert(b == c);
+ assert(a != d);
+ assert(d == dd);
+
+ // test <
+ assert(a < b);
+ assert(a <= b);
+ assert(b <= c);
+ assert(b >= c);
+ assert(b > d);
+ assert(b >= d);
+
+ // test +=
+ auto e = new Op(3);
+ e += d;
+ assert(e == b);
+ e -= c;
+ assert(e == a);
+ e = new Op(1);
+ e *= b;
+ assert(e == c);
+ e /= d;
+ assert(e == d);
+ e %= c;
+ assert(e == d);
+
+ // test +
+ auto f = new Op(1);
+ auto g = new Op(1);
+ assert(f + g == new Op(2));
+ assert(f - g == new Op(0));
+ assert(f * g == new Op(1));
+ assert(f / g == new Op(1));
+ assert(f % g == new Op(0));
+
+ // test unary operators
+ assert(-a == a);
+ assert(-b == new Op(-5));
+
+ // Unfortunaly, there is no way to override conversion to boolean for
+ // classes in D, opCast!("bool") is only used for structs.
+
+ // test []
+ auto h = new Op(3);
+ assert(h[0]==3);
+ assert(h[1]==0);
+ // Generation of opIndexAssign is not supported yet.
+
+ // test ()
+ auto i = new Op(3);
+ assert(i()==3);
+ assert(i(1)==4);
+ assert(i(1,2)==6);
+
+ // test ++ and --
+ auto j = new Op(100);
+ int original = j.i;
+ // The prefix increment/decrement operators are not directly overloadable in
+ // D2, and because the proxy classes are reference types, the lowering
+ // yields the same value as the postfix operators.
+ {
+ Op newOp = ++j;
+ int newInt = ++original;
+ assert(j.i == original);
+ assert(newOp.i == newInt);
+ }
+ {
+ Op newOp = --j;
+ int newInt = --original;
+ assert(j.i == original);
+ assert(newOp.i == newInt);
+ }
+
+ // Implicit casting via alias this is not supported yet.
+}
\ No newline at end of file
diff --git a/Examples/test-suite/operator_overload.i b/Examples/test-suite/operator_overload.i
index 80facff76..006662109 100644
--- a/Examples/test-suite/operator_overload.i
+++ b/Examples/test-suite/operator_overload.i
@@ -79,6 +79,12 @@ see bottom for a set of possible tests
%}
#endif
+#ifdef SWIGD
+// Due to the way operator overloading is implemented in D1 and D2, the prefix
+// increment/decrement operators (D1) resp. the postfix ones (D2) are ignored.
+%warnfilter(SWIGWARN_IGNORE_OPERATOR_PLUSPLUS, SWIGWARN_IGNORE_OPERATOR_MINUSMINUS);
+#endif
+
%rename(IntCast) operator int();
%rename(DoubleCast) operator double();
diff --git a/Examples/test-suite/operator_overload_break.i b/Examples/test-suite/operator_overload_break.i
index 9c6927bb0..f5f3c1a46 100644
--- a/Examples/test-suite/operator_overload_break.i
+++ b/Examples/test-suite/operator_overload_break.i
@@ -1,6 +1,6 @@
%module operator_overload_break
-#if defined(SWIGPYTHON)
+#if defined(SWIGPYTHON) || defined(SWIGD)
%warnfilter(SWIGWARN_IGNORE_OPERATOR_PLUSPLUS);
#endif
diff --git a/Lib/d/dclassgen.swg b/Lib/d/dclassgen.swg
index 8c08b9dc4..467621f4a 100644
--- a/Lib/d/dclassgen.swg
+++ b/Lib/d/dclassgen.swg
@@ -58,7 +58,7 @@
}
}
-%define SWIGD_CLASS_BODIES(OP_EQUALS_RETURN)
+
// Unfortunately, the »package« visibility attribute does not work in D when the
// module in question is in the root package (happens if no -package is specified
// at the SWIG command line), so we are stuck with public visibility for
@@ -72,18 +72,14 @@ public this(void* cObject, bool ownCObject) {
swigCMemOwn = ownCObject;
}
-public override OP_EQUALS_RETURN opEquals(Object rhs) {
- if (auto other = cast($dclassname)rhs) {
- return (swigCPtr == other.swigCPtr);
- }
- return super.opEquals(rhs);
-}
-
public static void* swigGetCPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
+
+mixin $imdmodule.SwigOperatorDefinitions;
%}
+
%typemap(dbody_derived) SWIGTYPE %{
private void* swigCPtr;
@@ -92,16 +88,11 @@ public this(void* cObject, bool ownCObject) {
swigCPtr = cObject;
}
-public override OP_EQUALS_RETURN opEquals(Object rhs) {
- if (auto other = cast($dclassname)rhs) {
- return (swigCPtr == other.swigCPtr);
- }
- return super.opEquals(rhs);
-}
-
public static void* swigGetCPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
+
+mixin $imdmodule.SwigOperatorDefinitions;
%}
@@ -120,16 +111,11 @@ protected this() {
swigCPtr = null;
}
-public override OP_EQUALS_RETURN opEquals(Object rhs) {
- if (auto other = cast($dclassname)rhs) {
- return (swigCPtr == other.swigCPtr);
- }
- return super.opEquals(rhs);
-}
-
public static void* swigGetCPtr($dclassname obj) {
return (obj is null) ? null : obj.swigCPtr;
}
+
+mixin $imdmodule.SwigOperatorDefinitions;
%}
@@ -138,35 +124,19 @@ public static void* swigGetCPtr($dclassname obj) {
*/
%typemap(dbody) SWIGTYPE (CLASS::*) %{
-private char* m_swigCMemberPtr;
+private char* swigCPtr;
public this(char* cMemberPtr, bool futureUse) {
- m_swigCMemberPtr = cMemberPtr;
+ swigCPtr = cMemberPtr;
}
protected this() {
- m_swigCMemberPtr = null;
+ swigCPtr = null;
}
-public override OP_EQUALS_RETURN opEquals(Object rhs) {
- if (auto other = cast($dclassname)rhs) {
- return (m_swigCMemberPtr == other.m_swigCMemberPtr);
- }
- return super.opEquals(rhs);
-}
-
-
package static char* swigGetCMemberPtr($dclassname obj) {
- return (obj is null) ? null : obj.m_swigCMemberPtr;
+ return (obj is null) ? null : obj.swigCPtr;
}
+
+mixin $imdmodule.SwigOperatorDefinitions;
%}
-%enddef
-
-
-#if SWIG_D_VERSION == 1
- SWIGD_CLASS_BODIES(int)
-#else
- SWIGD_CLASS_BODIES(bool)
-#endif
-
-#undef SWIGD_CLASS_BODIES
diff --git a/Lib/d/doperators.swg b/Lib/d/doperators.swg
index b3d8d7257..0cb63533c 100644
--- a/Lib/d/doperators.swg
+++ b/Lib/d/doperators.swg
@@ -4,15 +4,36 @@
* Mapping of C++ operator overloading methods to D.
* ----------------------------------------------------------------------------- */
-#ifdef __cplusplus
-
#if (SWIG_D_VERSION == 1)
-%rename(opAdd) *::operator+;
+%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(opNeg) *::operator-();
%rename(opSubAssign) *::operator-=;
%rename(opMul) *::operator*;
%rename(opMulAssign) *::operator*=;
@@ -20,8 +41,6 @@
%rename(opDivAssign) *::operator/=;
%rename(opMod) *::operator%;
%rename(opModAssign) *::operator%=;
-
-%rename(opCom) *::operator~();
%rename(opAnd) *::operator&;
%rename(opAndAssign) *::operator&=;
%rename(opOr) *::operator|;
@@ -34,44 +53,207 @@
%rename(opShrAssign) *::operator>>=;
%rename(opIndex) *::operator[](unsigned) const;
-%rename(opIndexAssign) *::operator[](unsigned);
-%rename(opCall) *::operator();
+// opIndexAssign is not currently generated, it needs more extensive support
+// mechanisms.
+%rename(opCall) *::operator();
+
// !a is not overrideable in D1.
%ignoreoperator(LNOT) operator!;
-// a != b is rewritten as !a.opEquals(b) in D.
-// For now, just ignore both of them, since there would be quite a bit of magic
-// needed to correctly generate a wrapper method for non-primitives types (there is
-// only one opEquals overload with an Object parameter in D).
-%ignoreoperator(EQ) operator==;
-%ignoreoperator(NOTEQUAL) operator!=;
-
// opCmp is used in D.
-%ignoreoperator(LT) operator<;
-%ignoreoperator(LTEQUAL) operator<=;
-%ignoreoperator(GT) operator>;
-%ignoreoperator(GTEQUAL) operator>=;
+%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 D.
-%ignoreoperator(PLUSPLUS) operator++();
-%ignoreoperator(MINUSMINUS) operator--();
-%ignoreoperator(PLUSPLUS) operator++(int);
-%ignoreoperator(MINUSMINUS) operator--(int);
+// ++/--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 custom types
-// have reference semantics.
+// 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) {
+ if (auto rhs = cast(typeof(this))o) {
+ if (swigCPtr == rhs.swigCPtr) return true;
+ static if (is(typeof(swigOpEquals(rhs)))) {
+ return swigOpEquals(rhs);
+ } else {
+ return false;
+ }
+ }
+ 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.
-// Operator overloading works completely different in D2, proper support will
-// probably need fairly extensive code generation support.
+#ifdef __cplusplus
+%rename(swigOpPos) *::operator+();
+%rename(swigOpPos) *::operator+() const;
+%rename(swigOpNeg) *::operator-();
+%rename(swigOpNeg) *::operator-() const;
+%rename(swigOpCom) *::operator~();
+%rename(swigOpCom) *::operator~() const;
+%rename(swigOpInc) *::operator++();
+%rename(swigOpDec) *::operator--();
+%ignoreoperator(PLUSPLUS) *::operator++(int);
+%ignoreoperator(MINUSMINUS) *::operator--(int);
+// The postfix increment/decrement operators are ignored because they are
+// rewritten to (auto t = e, ++e, t) in D2. The unary * operator (used for
+// pointer dereferencing in C/C++) isn't mapped to opUnary("*") by default,
+// despite this would be possible in D2 – the difference in member access
+// semantics would only lead to confusion in most cases.
+%rename(swigOpAdd) *::operator+;
+%rename(swigOpSub) *::operator-;
+%rename(swigOpMul) *::operator*;
+%rename(swigOpDiv) *::operator/;
+%rename(swigOpMod) *::operator%;
+%rename(swigOpAnd) *::operator&;
+%rename(swigOpOr) *::operator|;
+%rename(swigOpXor) *::operator^;
+%rename(swigOpShl) *::operator<<;
+%rename(swigOpShr) *::operator>>;
+
+%rename(swigOpAddAssign) *::operator+=;
+%rename(swigOpSubAssign) *::operator-=;
+%rename(swigOpMulAssign) *::operator*=;
+%rename(swigOpDivAssign) *::operator/=;
+%rename(swigOpModAssign) *::operator%=;
+%rename(swigOpAndAssign) *::operator&=;
+%rename(swigOpOrAssign) *::operator|=;
+%rename(swigOpXorAssign) *::operator^=;
+%rename(swigOpShlAssign) *::operator<<=;
+%rename(swigOpShrAssign) *::operator>>=;
+
+%rename(opIndex) *::operator[];
+// opIndexAssign is not currently generated, it needs more extensive support
+// mechanisms.
+
+%rename(opCall) *::operator();
+
+%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||;
+
+// 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 (__traits(compiles, 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);
+ }
+
+ private template swigOpBinary(string operator, string name) {
+ enum swigOpBinary = `public void opOpAssign(string op, T)(T rhs) if (op == "` ~ operator ~
+ `" && __traits(compiles, swigOp` ~ name ~ `Assign(rhs))) { swigOp` ~ name ~ `Assign(rhs);}` ~
+ `public auto opBinary(string op, T)(T rhs) if (op == "` ~ operator ~
+ `" && __traits(compiles, swigOp` ~ name ~ `(rhs))) { return swigOp` ~ name ~ `(rhs);}`;
+ }
+ mixin(swigOpBinary!("+", "Add"));
+ mixin(swigOpBinary!("-", "Sub"));
+ mixin(swigOpBinary!("*", "Mul"));
+ mixin(swigOpBinary!("/", "Div"));
+ mixin(swigOpBinary!("%", "Mod"));
+ mixin(swigOpBinary!("&", "And"));
+ mixin(swigOpBinary!("|", "Or"));
+ mixin(swigOpBinary!("^", "Xor"));
+ mixin(swigOpBinary!("<<", "Shl"));
+ mixin(swigOpBinary!(">>", "Shr"));
+
+ private template swigOpUnary(string operator, string name) {
+ enum swigOpUnary = `public auto opUnary(string op)() if (op == "` ~ operator ~
+ `" && __traits(compiles, swigOp` ~ name ~ `())) { return swigOp` ~ name ~ `();}`;
+ }
+ mixin(swigOpUnary!("+", "Pos"));
+ mixin(swigOpUnary!("-", "Neg"));
+ mixin(swigOpUnary!("~", "Com"));
+ mixin(swigOpUnary!("++", "Inc"));
+ mixin(swigOpUnary!("--", "Dec"));
+%}
#endif
+%pragma(d) imdmodulecode=%{
+}
+%}
+
#endif
From 91523f7510a248bd4d2fcc2e892b29f35cd33a04 Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 30 Dec 2010 15:40:17 +0000
Subject: [PATCH 062/317] [C#, D, Java] Check for collision of parameter names
with target language keywords when generating the director glue code.
The situation in which the generated could would previously be invalid is illustrated in the new 'director_keywords' test case.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12358 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
CHANGES.current | 7 +++++++
Examples/test-suite/common.mk | 1 +
Examples/test-suite/director_keywords.i | 13 +++++++++++++
Source/Modules/csharp.cxx | 13 ++++++-------
Source/Modules/d.cxx | 9 ++++-----
Source/Modules/java.cxx | 8 ++++----
6 files changed, 35 insertions(+), 16 deletions(-)
create mode 100644 Examples/test-suite/director_keywords.i
diff --git a/CHANGES.current b/CHANGES.current
index 7cedad228..2aa1e8d7b 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,13 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.2 (in progress)
===========================
+2010-12-30: klickverbot
+ [C#, D, Java] Check for collision of parameter names with target
+ language keywords when generating the director glue code.
+
+ The situation in which the generated could would previously be
+ invalid is illustrated in the new 'director_keywords' test case.
+
2010-12-23: wsfulton
[C#] Fix $csinput special variable not being expanded for csvarin typemaps
when used for global variables. Reported by Vadim Zeitlin.
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 2f061cd88..f25238382 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -166,6 +166,7 @@ CPP_TEST_CASES += \
director_finalizer \
director_frob \
director_ignore \
+ director_keywords \
director_namespace_clash \
director_nested \
director_overload \
diff --git a/Examples/test-suite/director_keywords.i b/Examples/test-suite/director_keywords.i
new file mode 100644
index 000000000..473786c00
--- /dev/null
+++ b/Examples/test-suite/director_keywords.i
@@ -0,0 +1,13 @@
+// Checks if collisions of argument names with target language keywords are
+// resolved properly when directors are used (currently only »abstract« for
+// C#, D and Java is checked).
+%module(directors="1") director_keywords
+
+%feature("director") Foo;
+
+%inline %{
+struct Foo {
+ virtual ~Foo() {}
+ virtual void bar(int abstract) {}
+};
+%}
diff --git a/Source/Modules/csharp.cxx b/Source/Modules/csharp.cxx
index d93891795..6d0896b16 100644
--- a/Source/Modules/csharp.cxx
+++ b/Source/Modules/csharp.cxx
@@ -3473,7 +3473,6 @@ public:
String *callback_def = NewString("");
String *callback_code = NewString("");
String *imcall_args = NewString("");
- int gencomma = 0;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
// Kludge Alert: functionWrapper sets sym:overload properly, but it
@@ -3617,14 +3616,14 @@ public:
Printf(w->code, "} else {\n");
/* Go through argument list, convert from native to Java */
- for (p = l; p; /* empty */ ) {
+ for (i = 0, p = l; p; ++i) {
/* Is this superfluous? */
while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
p = Getattr(p, "tmap:directorin:next");
}
SwigType *pt = Getattr(p, "type");
- String *ln = Copy(Getattr(p, "name"));
+ String *ln = makeParameterName(n, p, i, false);
String *c_param_type = NULL;
String *c_decl = NewString("");
String *arg = NewString("");
@@ -3632,7 +3631,7 @@ public:
Printf(arg, "j%s", ln);
/* And add to the upcall args */
- if (gencomma > 0)
+ if (i > 0)
Printf(jupcall_args, ", ");
Printf(jupcall_args, "%s", arg);
@@ -3660,7 +3659,7 @@ public:
Delete(tm);
/* Add C type to callback typedef */
- if (gencomma > 0)
+ if (i > 0)
Printf(callback_typedef_parms, ", ");
Printf(callback_typedef_parms, "%s", c_param_type);
@@ -3681,7 +3680,7 @@ public:
substituteClassname(pt, din);
Replaceall(din, "$iminput", ln);
- if (gencomma > 0) {
+ if (i > 0) {
Printf(delegate_parms, ", ");
Printf(proxy_method_types, ", ");
Printf(imcall_args, ", ");
@@ -3727,7 +3726,7 @@ public:
p = nextSibling(p);
}
- gencomma++;
+ Delete(ln);
Delete(arg);
Delete(c_decl);
Delete(c_param_type);
diff --git a/Source/Modules/d.cxx b/Source/Modules/d.cxx
index 986079d65..4fdc25fac 100644
--- a/Source/Modules/d.cxx
+++ b/Source/Modules/d.cxx
@@ -1867,7 +1867,6 @@ public:
String *callback_def = NewString("");
String *callback_code = NewString("");
String *imcall_args = NewString("");
- int gencomma = 0;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
// Kludge Alert: functionWrapper sets sym:overload properly, but it
@@ -2007,14 +2006,14 @@ public:
Printf(w->code, "} else {\n");
// Go through argument list.
- for (p = l; p; /* empty */) {
+ for (i = 0, p = l; p; ++i) {
/* Is this superfluous? */
while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
p = Getattr(p, "tmap:directorin:next");
}
SwigType *pt = Getattr(p, "type");
- String *ln = Copy(Getattr(p, "name"));
+ String *ln = makeParameterName(n, p, i, false);
String *c_param_type = NULL;
String *c_decl = NewString("");
String *arg = NewString("");
@@ -2071,7 +2070,7 @@ public:
Replaceall(din, "$winput", ln);
Printf(delegate_parms, ", ");
- if (gencomma > 0) {
+ if (i > 0) {
Printf(proxy_method_param_list, ", ");
Printf(imcall_args, ", ");
}
@@ -2123,10 +2122,10 @@ public:
p = nextSibling(p);
}
- gencomma++;
Delete(arg);
Delete(c_decl);
Delete(c_param_type);
+ Delete(ln);
}
/* header declaration, start wrapper definition */
diff --git a/Source/Modules/java.cxx b/Source/Modules/java.cxx
index 1d4e522c6..234a1e85b 100644
--- a/Source/Modules/java.cxx
+++ b/Source/Modules/java.cxx
@@ -3548,7 +3548,6 @@ public:
String *callback_def = NewString("");
String *callback_code = NewString("");
String *imcall_args = NewString("");
- int gencomma = 0;
int classmeth_off = curr_class_dmethod - first_class_dmethod;
bool ignored_method = GetFlag(n, "feature:ignore") ? true : false;
@@ -3767,14 +3766,14 @@ public:
Delete(tp);
/* Go through argument list, convert from native to Java */
- for (p = l; p; /* empty */ ) {
+ for (i = 0, p = l; p; ++i) {
/* Is this superfluous? */
while (checkAttribute(p, "tmap:directorin:numinputs", "0")) {
p = Getattr(p, "tmap:directorin:next");
}
SwigType *pt = Getattr(p, "type");
- String *ln = Copy(Getattr(p, "name"));
+ String *ln = makeParameterName(n, p, i, false);
String *c_param_type = NULL;
String *c_decl = NewString("");
String *arg = NewString("");
@@ -3833,7 +3832,7 @@ public:
substituteClassname(pt, din);
Replaceall(din, "$jniinput", ln);
- if (++gencomma > 1)
+ if (i > 0)
Printf(imcall_args, ", ");
Printf(callback_def, ", %s %s", tm, ln);
@@ -3896,6 +3895,7 @@ public:
Delete(arg);
Delete(c_decl);
Delete(c_param_type);
+ Delete(ln);
}
/* header declaration, start wrapper definition */
From ab2af5ebe2330a723b14f678e667e45c8554af8e Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Thu, 30 Dec 2010 17:37:48 +0000
Subject: [PATCH 063/317] [D] Removed leftover %dstripprefix definition.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12359 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/d/ddirectives.swg | 1 -
1 file changed, 1 deletion(-)
diff --git a/Lib/d/ddirectives.swg b/Lib/d/ddirectives.swg
index f3052cb87..6972a0c18 100644
--- a/Lib/d/ddirectives.swg
+++ b/Lib/d/ddirectives.swg
@@ -7,5 +7,4 @@
#define %dmanifestconst %feature("d:manifestconst")
#define %dconstvalue(value) %feature("d:constvalue",value)
#define %dmethodmodifiers %feature("d:methodmodifiers")
-#define %dstripprefix %feature("d:stripprefix")
#define %dnothrowexception %feature("except")
From 0c3f855cc9d13828505ee47d9db9fe0e2a494067 Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Sat, 1 Jan 2011 14:23:47 +0000
Subject: [PATCH 064/317] [D] Not only build, but also run the examples for the
'check' target.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12360 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/Makefile.in | 7 +++++++
Examples/d/callback/Makefile | 2 ++
Examples/d/class/Makefile | 2 ++
Examples/d/constants/Makefile | 2 ++
Examples/d/enum/Makefile | 2 ++
Examples/d/extend/Makefile | 2 ++
Examples/d/funcptr/Makefile | 2 ++
Examples/d/simple/Makefile | 2 ++
Examples/d/variables/Makefile | 2 ++
9 files changed, 23 insertions(+)
diff --git a/Examples/Makefile.in b/Examples/Makefile.in
index 1a02c4186..b23fccef8 100644
--- a/Examples/Makefile.in
+++ b/Examples/Makefile.in
@@ -1263,6 +1263,13 @@ d_cpp: $(SRCS)
d_compile: $(SRCS)
DFLAGS="" $(COMPILETOOL) $(DCOMPILER) $(DFLAGS) $(DSRCS)
+# -----------------------------------------------------------------
+# Run D example
+# -----------------------------------------------------------------
+
+d_run:
+ env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./runme
+
# -----------------------------------------------------------------
# Clean the D examples
# -----------------------------------------------------------------
diff --git a/Examples/d/callback/Makefile b/Examples/d/callback/Makefile
index bc16dd0fc..b5808cf0d 100644
--- a/Examples/d/callback/Makefile
+++ b/Examples/d/callback/Makefile
@@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_run
diff --git a/Examples/d/class/Makefile b/Examples/d/class/Makefile
index bc16dd0fc..b5808cf0d 100644
--- a/Examples/d/class/Makefile
+++ b/Examples/d/class/Makefile
@@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_run
diff --git a/Examples/d/constants/Makefile b/Examples/d/constants/Makefile
index ce17134ec..412055243 100644
--- a/Examples/d/constants/Makefile
+++ b/Examples/d/constants/Makefile
@@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_run
diff --git a/Examples/d/enum/Makefile b/Examples/d/enum/Makefile
index bc16dd0fc..b5808cf0d 100644
--- a/Examples/d/enum/Makefile
+++ b/Examples/d/enum/Makefile
@@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_run
diff --git a/Examples/d/extend/Makefile b/Examples/d/extend/Makefile
index bc16dd0fc..b5808cf0d 100644
--- a/Examples/d/extend/Makefile
+++ b/Examples/d/extend/Makefile
@@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_run
diff --git a/Examples/d/funcptr/Makefile b/Examples/d/funcptr/Makefile
index 616102926..09efa8d88 100644
--- a/Examples/d/funcptr/Makefile
+++ b/Examples/d/funcptr/Makefile
@@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_run
diff --git a/Examples/d/simple/Makefile b/Examples/d/simple/Makefile
index 312e6a9e9..ae173a566 100644
--- a/Examples/d/simple/Makefile
+++ b/Examples/d/simple/Makefile
@@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_run
diff --git a/Examples/d/variables/Makefile b/Examples/d/variables/Makefile
index 312e6a9e9..ae173a566 100644
--- a/Examples/d/variables/Makefile
+++ b/Examples/d/variables/Makefile
@@ -26,3 +26,5 @@ clean::
$(MAKE) -f $(TOP)/Makefile d_clean
check: all
+ cd $(WORKING_DIR); \
+ $(MAKE) -f $(TOP)/Makefile d_run
From a344899ed8854e21ee7b698b27950fe04aee0901 Mon Sep 17 00:00:00 2001
From: David Nadlinger
Date: Sat, 1 Jan 2011 14:34:51 +0000
Subject: [PATCH 065/317] [D] Added workaround for LDC to the D1 version of the
'funcptr' example.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12361 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Examples/d/funcptr/d1/runme.d | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/Examples/d/funcptr/d1/runme.d b/Examples/d/funcptr/d1/runme.d
index 2947602a5..1461c1546 100644
--- a/Examples/d/funcptr/d1/runme.d
+++ b/Examples/d/funcptr/d1/runme.d
@@ -27,8 +27,16 @@ void main() {
Stdout( " SUB(a,b) = " )( example.do_op( a, b, example.SUB ) ).newline;
Stdout( " MUL(a,b) = " )( example.do_op( a, b, example.MUL ) ).newline;
- Stdout( "Now the same with callback functions defined in D:" ).newline;
- Stdout( " add(a,b) = " )( example.do_op( a, b, &add ) ).newline;
- Stdout( " sub(a,b) = " )( example.do_op( a, b, &sub ) ).newline;
- Stdout( " mul(a,b) = " )( example.do_op( a, b, &mul ) ).newline;
+ version (LDC) {
+ // Currently, there is no way to specify the calling convention for
+ // function pointer parameters in D, but LDC does strict typechecking for
+ // them (which is reasonable, but not covered by the language spec yet).
+ // As a result, there is no way to make the code below compile with LDC at
+ // the moment, so just skip it.
+ } else {
+ Stdout( "Now the same with callback functions defined in D:" ).newline;
+ Stdout( " add(a,b) = " )( example.do_op( a, b, &add ) ).newline;
+ Stdout( " sub(a,b) = " )( example.do_op( a, b, &sub ) ).newline;
+ Stdout( " mul(a,b) = " )( example.do_op( a, b, &mul ) ).newline;
+ }
}
From b77b64944b6befc15b984b5f22187e13c288672e Mon Sep 17 00:00:00 2001
From: Stefan Zager
Date: Wed, 5 Jan 2011 08:35:28 +0000
Subject: [PATCH 066/317] Static member variables are working.
Fixed some corner cases with protected members of director classes.
Now dying in director_finalizer.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12371 626c5289-ae23-0410-ae9c-e8d60b6d4f22
---
Lib/python/builtin.swg | 241 ++++++++++++++++++--
Lib/python/pyinit.swg | 19 +-
Lib/python/pyrun.swg | 41 +++-
Lib/python/std_pair.i | 27 ++-
Source/Modules/python.cxx | 451 ++++++++++++++++++++------------------
5 files changed, 525 insertions(+), 254 deletions(-)
diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg
index 9b385ddfd..de72a558e 100644
--- a/Lib/python/builtin.swg
+++ b/Lib/python/builtin.swg
@@ -1,3 +1,10 @@
+#define PYSWIG_UNARYFUNC_CLOSURE(wrapper) \
+SWIGINTERN PyObject* \
+wrapper##_closure (PyObject *a) \
+{ \
+ return wrapper(a, NULL); \
+}
+
#define PYSWIG_BINARYFUNC_CLOSURE(wrapper) \
SWIGINTERN PyObject* \
wrapper##_closure (PyObject *a, PyObject *b) \
@@ -115,28 +122,13 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \
return result; \
}
-SWIGINTERN int
-pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure)
-{
- if (!closure)
- return -1;
- PyObject *tuple = PyTuple_New(1);
- assert(tuple);
- PyTuple_SET_ITEM(tuple, 0, val);
- Py_XINCREF(val);
- PyObject *result = ((PyCFunction) closure)(obj, tuple);
- Py_DECREF(tuple);
- Py_XDECREF(result);
- return result ? 0 : -1;
-}
-
#ifdef __cplusplus
namespace {
-template struct PySwigBuiltin : public SwigPyObject {
+template struct SwigPyBuiltin : public SwigPyObject {
- typedef PySwigBuiltin<_Tp> this_type;
+ typedef SwigPyBuiltin<_Tp> this_type;
typedef _Tp obj_type;
typedef obj_type* pointer;
typedef obj_type& reference;
@@ -154,7 +146,7 @@ template struct PySwigBuiltin : public SwigPyObject {
template void py_builtin_dealloc (PyObject *pyobj)
{
- typedef PySwigBuiltin<_Tp> builtin_type;
+ typedef SwigPyBuiltin<_Tp> builtin_type;
builtin_type *obj = (builtin_type*) pyobj;
if (obj->own)
delete reinterpret_cast<_Tp*>(obj->ptr);
@@ -164,3 +156,216 @@ template void py_builtin_dealloc (PyObject *pyobj)
} // namespace {
#endif
+
+SWIGRUNTIME int py_builtin_bad_init (PyObject *self, PyObject *args, PyObject *kwds)
+{
+ PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name);
+ return -1;
+}
+
+SWIGRUNTIME void py_builtin_bad_dealloc (PyObject *pyobj)
+{
+ SwigPyObject *sobj = (SwigPyObject*) pyobj;
+ if (sobj->own) {
+ PyErr_Format(PyExc_TypeError,
+ "Swig detected a memory leak in type '%s': no callable destructor found.",
+ pyobj->ob_type->tp_name);
+ }
+}
+
+typedef struct {
+ PyCFunction get;
+ PyCFunction set;
+} SwigPyGetSet;
+
+SWIGRUNTIME PyObject*
+pyswig_getter_closure (PyObject *obj, void *closure)
+{
+ if (!closure)
+ return SWIG_Py_Void();
+ SwigPyGetSet *getset = (SwigPyGetSet*) closure;
+ if (!getset->get)
+ return SWIG_Py_Void();
+ PyObject *tuple = PyTuple_New(0);
+ assert(tuple);
+ PyObject *result = (*getset->get)(obj, tuple);
+ Py_DECREF(tuple);
+ return result;
+}
+
+SWIGRUNTIME int
+pyswig_setter_closure (PyObject *obj, PyObject *val, void *closure)
+{
+ if (!closure)
+ return -1;
+ SwigPyGetSet *getset = (SwigPyGetSet*) closure;
+ if (!getset->set)
+ return -1;
+ PyObject *tuple = PyTuple_New(1);
+ assert(tuple);
+ PyTuple_SET_ITEM(tuple, 0, val);
+ Py_XINCREF(val);
+ PyObject *result = (*getset->set)(obj, tuple);
+ Py_DECREF(tuple);
+ Py_XDECREF(result);
+ return result ? 0 : -1;
+}
+
+SWIGRUNTIME PyObject*
+pyswig_static_getter_closure (PyObject *obj, void *closure)
+{
+ if (!closure)
+ return SWIG_Py_Void();
+ SwigPyGetSet *getset = (SwigPyGetSet*) closure;
+ if (!getset->get)
+ return SWIG_Py_Void();
+ PyObject *tuple = PyTuple_New(0);
+ assert(tuple);
+ PyObject *result = (*getset->get)(obj, tuple);
+ Py_DECREF(tuple);
+ return result;
+}
+
+SWIGRUNTIME int
+pyswig_static_setter_closure (PyObject *obj, PyObject *val, void *closure)
+{
+ if (!closure)
+ return -1;
+ SwigPyGetSet *getset = (SwigPyGetSet*) closure;
+ if (!getset->set)
+ return -1;
+ PyObject *tuple = PyTuple_New(1);
+ assert(tuple);
+ PyTuple_SET_ITEM(tuple, 0, val);
+ Py_XINCREF(val);
+ PyObject *result = (*getset->set)(obj, tuple);
+ Py_DECREF(tuple);
+ Py_XDECREF(result);
+ return result ? 0 : -1;
+}
+
+SWIGRUNTIME void
+SwigPyStaticVar_dealloc(PyDescrObject *descr)
+{
+ _PyObject_GC_UNTRACK(descr);
+ Py_XDECREF(descr->d_type);
+ Py_XDECREF(descr->d_name);
+ PyObject_GC_Del(descr);
+}
+
+SWIGRUNTIME PyObject *
+SwigPyStaticVar_repr(PyGetSetDescrObject *descr)
+{
+ return PyString_FromFormat("",
+ PyString_AsString(descr->d_name),
+ descr->d_type->tp_name);
+}
+
+SWIGRUNTIME int
+SwigPyStaticVar_traverse(PyObject *self, visitproc visit, void *arg)
+{
+ PyDescrObject *descr = (PyDescrObject *)self;
+ Py_VISIT(descr->d_type);
+ return 0;
+}
+
+SWIGRUNTIME PyObject *
+SwigPyStaticVar_get (PyGetSetDescrObject *descr, PyObject *obj, PyObject *type)
+{
+ if (descr->d_getset->get != NULL)
+ return descr->d_getset->get(obj, descr->d_getset->closure);
+ PyErr_Format(PyExc_AttributeError,
+ "attribute '%.300s' of '%.100s' objects is not readable",
+ PyString_AsString(descr->d_name),
+ descr->d_type->tp_name);
+ return NULL;
+}
+
+SWIGRUNTIME int
+SwigPyStaticVar_set (PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
+{
+ int res;
+
+ if (descr->d_getset->set != NULL)
+ return descr->d_getset->set(obj, value, descr->d_getset->closure);
+ PyErr_Format(PyExc_AttributeError,
+ "attribute '%.300s' of '%.100s' objects is not writable",
+ PyString_AsString(descr->d_name),
+ descr->d_type->tp_name);
+ return -1;
+}
+
+SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0,
+ "swig_static_var_getset_descriptor",
+ sizeof(PyGetSetDescrObject),
+ 0,
+ (destructor)SwigPyStaticVar_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr */
+ 0, /* tp_setattr */
+ 0, /* tp_compare */
+ (reprfunc)SwigPyStaticVar_repr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash */
+ 0, /* tp_call */
+ 0, /* tp_str */
+ PyObject_GenericGetAttr, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
+ 0, /* tp_doc */
+ SwigPyStaticVar_traverse, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ (descrgetfunc)SwigPyStaticVar_get, /* tp_descr_get */
+ (descrsetfunc)SwigPyStaticVar_set, /* tp_descr_set */
+};
+
+SWIGRUNTIME int
+SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
+{
+ PyObject *attribute = _PyType_Lookup(type, name);
+ if (attribute != NULL) {
+ /* Implement descriptor functionality, if any */
+ descrsetfunc local_set = attribute->ob_type->tp_descr_set;
+ if (local_set != NULL)
+ return local_set(attribute, (PyObject*) type, value);
+ PyErr_Format(PyExc_AttributeError,
+ "cannot modify read-only attribute '%.50s.%.400s'",
+ type->tp_name, PyString_AS_STRING(name));
+ } else {
+ PyErr_Format(PyExc_AttributeError,
+ "type '%.50s' has no attribute '%.400s'",
+ type->tp_name, PyString_AS_STRING(name));
+ }
+
+ return -1;
+}
+
+SWIGINTERN PyGetSetDescrObject*
+SwigPyStaticVar_new_getset (PyTypeObject *type, PyGetSetDef *getset)
+{
+ PyGetSetDescrObject *descr = (PyGetSetDescrObject*) PyType_GenericAlloc(&SwigPyStaticVar_Type, 0);
+ assert(descr);
+ Py_XINCREF(type);
+ descr->d_type = type;
+ descr->d_name = PyString_InternFromString(getset->name);
+ descr->d_getset = getset;
+ if (descr->d_name == NULL) {
+ Py_DECREF(descr);
+ descr = NULL;
+ }
+ return descr;
+}
diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg
index f873e3968..3faef3f76 100644
--- a/Lib/python/pyinit.swg
+++ b/Lib/python/pyinit.swg
@@ -340,12 +340,25 @@ SWIG_init(void) {
#if defined(SWIGPYTHON_BUILTIN)
PyTypeObject *builtin_pytype = 0;
- PyObject *propargs = NULL, *propget = NULL, *propset = NULL, *propobj = NULL;
+#ifdef __cplusplus
std::vector builtin_bases;
+#endif
swig_type_info *builtin_basetype = 0;
- PyObject *base_tuple = NULL;
+ PyObject *tuple = NULL;
+ PyGetSetDescrObject *static_getset = NULL;
+
int i;
+ // metatype is used to implement static member variables.
+
+ PyObject *metatype_args = Py_BuildValue("(s(O){})", "SwigPyObjectType", &PyType_Type);
+ assert(metatype_args);
+ PyTypeObject *metatype = (PyTypeObject*) PyType_Type.tp_call((PyObject*) &PyType_Type, metatype_args, NULL);
+ assert(metatype);
+ Py_DECREF(metatype_args);
+ metatype->tp_setattro = (setattrofunc) &SwigPyObjectType_setattro;
+ assert(PyType_Ready(metatype) >= 0);
+
SWIG_Python_builtin_imports();
#endif
@@ -361,6 +374,6 @@ SWIG_init(void) {
SWIG_InitializeModule(0);
SWIG_InstallConstants(d,swig_const_table);
-
+
%}
diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg
index 503e42711..acffffd01 100644
--- a/Lib/python/pyrun.swg
+++ b/Lib/python/pyrun.swg
@@ -332,6 +332,9 @@ typedef struct {
swig_type_info *ty;
int own;
PyObject *next;
+#ifdef SWIGPYTHON_BUILTIN
+ PyObject *dict;
+#endif
} SwigPyObject;
SWIGRUNTIME PyObject *
@@ -384,19 +387,19 @@ SwigPyObject_repr(SwigPyObject *v, PyObject *args)
const char *name = SWIG_TypePrettyName(v->ty);
PyObject *repr = SWIG_Python_str_FromFormat("", name, v);
if (v->next) {
-#ifdef METH_NOARGS
+# ifdef METH_NOARGS
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next);
-#else
+# else
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next, args);
-#endif
-#if PY_VERSION_HEX >= 0x03000000
+# endif
+# if PY_VERSION_HEX >= 0x03000000
PyObject *joined = PyUnicode_Concat(repr, nrep);
Py_DecRef(repr);
Py_DecRef(nrep);
repr = joined;
-#else
+# else
PyString_ConcatAndDel(&repr,nrep);
-#endif
+# endif
}
return repr;
}
@@ -468,9 +471,8 @@ SwigPyObject_Check(PyObject *op) {
#ifdef SWIGPYTHON_BUILTIN
PyTypeObject *target_tp = SwigPyObject_type();
PyTypeObject *obj_tp;
- for (obj_tp = op->ob_type; obj_tp; obj_tp = obj_tp->tp_base)
- if (obj_tp == target_tp)
- return 1;
+ if (PyType_IsSubtype(op->ob_type, target_tp))
+ return 1;
return (strcmp(op->ob_type->tp_name, "SwigPyObject") == 0);
#else
return (Py_TYPE(op) == SwigPyObject_type())
@@ -1080,6 +1082,7 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
if (ptr) *ptr = 0;
return SWIG_OK;
}
+
if (ty && ty->clientdata && ((SwigPyClientData*) ty->clientdata)->pytype) {
PyTypeObject *target_tp = ((SwigPyClientData*) ty->clientdata)->pytype;
PyTypeObject *obj_tp;
@@ -1096,6 +1099,9 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
}
}
}
+
+ int res = SWIG_ERROR;
+
SwigPyObject *sobj = SWIG_Python_GetSwigThis(obj);
if (own)
*own = 0;
@@ -1135,9 +1141,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
if (flags & SWIG_POINTER_DISOWN) {
sobj->own = 0;
}
- return SWIG_OK;
+ res = SWIG_OK;
} else {
- int res = SWIG_ERROR;
if (flags & SWIG_POINTER_IMPLICIT_CONV) {
SwigPyClientData *data = ty ? (SwigPyClientData *) ty->clientdata : 0;
if (data && !data->implicitconv) {
@@ -1173,8 +1178,8 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
}
}
}
- return res;
}
+ return res;
}
/* Convert a function ptr value */
@@ -1357,6 +1362,9 @@ SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
newobj->ty = type;
newobj->own = own;
newobj->next = 0;
+#ifdef SWIGPYTHON_BUILTIN
+ newobj->dict = 0;
+#endif
return (PyObject*) newobj;
}
return SWIG_Py_Void();
@@ -1388,10 +1396,19 @@ SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int f
assert(clientdata->pytype);
int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
SwigPyObject *newobj = (SwigPyObject*) self;
+ if (newobj->ptr) {
+ PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0);
+ while (newobj->next) newobj = (SwigPyObject*) newobj->next;
+ newobj->next = next_self;
+ newobj = (SwigPyObject*) next_self;
+ }
newobj->ptr = ptr;
newobj->own = own;
newobj->ty = type;
newobj->next = 0;
+#ifdef SWIGPYTHON_BUILTIN
+ newobj->dict = 0;
+#endif
return 0;
}
diff --git a/Lib/python/std_pair.i b/Lib/python/std_pair.i
index 4cc8fe5c2..49f381afb 100644
--- a/Lib/python/std_pair.i
+++ b/Lib/python/std_pair.i
@@ -161,13 +161,28 @@ SwigPython_std_pair_setitem (PyObject *a, Py_ssize_t b, PyObject *c)
}
+%feature("sq_length") std::pair "SwigPython_std_pair_len";
+%feature("sq_length") std::pair "SwigPython_std_pair_len";
+%feature("sq_length") std::pair "SwigPython_std_pair_len";
+%feature("sq_length") std::pair "SwigPython_std_pair_len";
+
+%feature("tp_repr") std::pair "SwigPython_std_pair_repr";
+%feature("tp_repr") std::pair "SwigPython_std_pair_repr";
+%feature("tp_repr") std::pair "SwigPython_std_pair_repr";
+%feature("tp_repr") std::pair "SwigPython_std_pair_repr";
+
+%feature("sq_item") std::pair "SwigPython_std_pair_getitem";
+%feature("sq_item") std::pair