summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Nadlinger <code@klickverbot.at>2011-12-03 19:48:01 +0000
committerDavid Nadlinger <code@klickverbot.at>2011-12-03 19:48:01 +0000
commite2b2f26bf6a6c01c95b9106bda9a4b59dfd4e2bd (patch)
tree09bee0c517d0c1955f054cf1c62d81de928d5f3d
parent5e5d1e2775935648c853388773f42eb26f89fbfd (diff)
downloadswig-e2b2f26bf6a6c01c95b9106bda9a4b59dfd4e2bd.tar.gz
[D] Use stdc.config.c_long/c_ulong to represent C long types.
Previously, C's long/ulong types would always be mapped to 32 bit integers in D, which is wrong on D_LP64, but was not really a problem in practice since DMD used to be 32 bit only. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12861 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--CHANGES.current1
-rw-r--r--Examples/test-suite/d/li_boost_shared_ptr_runme.2.d2
-rw-r--r--Examples/test-suite/d/preproc_constants_c_runme.1.d13
-rw-r--r--Examples/test-suite/d/preproc_constants_c_runme.2.d13
-rw-r--r--Examples/test-suite/d/preproc_constants_runme.1.d13
-rw-r--r--Examples/test-suite/d/preproc_constants_runme.2.d13
-rw-r--r--Lib/d/dprimitives.swg17
-rw-r--r--Lib/d/typemaps.i12
8 files changed, 51 insertions, 33 deletions
diff --git a/CHANGES.current b/CHANGES.current
index 60858a4ba..8105a0fe6 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -8,6 +8,7 @@ Version 2.0.5 (in progress)
2011-12-03: klickvebrot
[D] Fix exception glue code for newer DMD 2 versions.
[D] Do not default to 32 bit glue code for DMD anymore.
+ [D] Use stdc.config.c_long/c_ulong to represent C long types.
2011-12-01: szager
[python] Fixed bug 3447426: memory leak in vector.__getitem__.
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
index 773ae74d5..0027aad05 100644
--- a/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d
+++ b/Examples/test-suite/d/li_boost_shared_ptr_runme.2.d
@@ -583,7 +583,7 @@ 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);
+ auto got = use_count(k);
if (expected != got)
throw new Exception("verify use_count failed. Expected: " ~ to!string(expected) ~ " Got: " ~ to!string(got));
}
diff --git a/Examples/test-suite/d/preproc_constants_c_runme.1.d b/Examples/test-suite/d/preproc_constants_c_runme.1.d
index f25bbfdee..d846c71ac 100644
--- a/Examples/test-suite/d/preproc_constants_c_runme.1.d
+++ b/Examples/test-suite/d/preproc_constants_c_runme.1.d
@@ -1,5 +1,6 @@
module preproc_constants_c_runme;
+import tango.stdc.config;
import preproc_constants_c.preproc_constants_c;
// Same as preproc_constants.i testcase, but bool types are int instead.
@@ -10,10 +11,10 @@ void main() {
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(c_long == typeof(CONST_LONG1())));
+ static assert(is(c_long == typeof(CONST_LONG2())));
+ static assert(is(c_long == typeof(CONST_LONG3())));
+ static assert(is(c_long == typeof(CONST_LONG4())));
static assert(is(long == typeof(CONST_LLONG1())));
static assert(is(long == typeof(CONST_LLONG2())));
static assert(is(long == typeof(CONST_LLONG3())));
@@ -38,8 +39,8 @@ void main() {
// 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(c_long == typeof(INT_AND_LONG())));
+ static assert(is(c_ulong == 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())));
diff --git a/Examples/test-suite/d/preproc_constants_c_runme.2.d b/Examples/test-suite/d/preproc_constants_c_runme.2.d
index 07d6ac53d..9bdbb9372 100644
--- a/Examples/test-suite/d/preproc_constants_c_runme.2.d
+++ b/Examples/test-suite/d/preproc_constants_c_runme.2.d
@@ -1,5 +1,6 @@
module preproc_constants_c_runme;
+import core.stdc.config;
import preproc_constants_c.preproc_constants_c;
// Same as preproc_constants.i testcase, but bool types are int instead.
@@ -10,10 +11,10 @@ void main() {
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(c_long == typeof(CONST_LONG1())));
+ static assert(is(c_long == typeof(CONST_LONG2())));
+ static assert(is(c_long == typeof(CONST_LONG3())));
+ static assert(is(c_long == typeof(CONST_LONG4())));
static assert(is(long == typeof(CONST_LLONG1())));
static assert(is(long == typeof(CONST_LLONG2())));
static assert(is(long == typeof(CONST_LLONG3())));
@@ -38,8 +39,8 @@ void main() {
// 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(c_long == typeof(INT_AND_LONG())));
+ static assert(is(c_ulong == 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())));
diff --git a/Examples/test-suite/d/preproc_constants_runme.1.d b/Examples/test-suite/d/preproc_constants_runme.1.d
index a2aaa8fcd..009405fc7 100644
--- a/Examples/test-suite/d/preproc_constants_runme.1.d
+++ b/Examples/test-suite/d/preproc_constants_runme.1.d
@@ -1,5 +1,6 @@
module preproc_constants_runme;
+import tango.stdc.config;
import preproc_constants.preproc_constants;
void main() {
@@ -9,10 +10,10 @@ void main() {
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(c_long == typeof(CONST_LONG1())));
+ static assert(is(c_long == typeof(CONST_LONG2())));
+ static assert(is(c_long == typeof(CONST_LONG3())));
+ static assert(is(c_long == typeof(CONST_LONG4())));
static assert(is(long == typeof(CONST_LLONG1())));
static assert(is(long == typeof(CONST_LLONG2())));
static assert(is(long == typeof(CONST_LLONG3())));
@@ -37,8 +38,8 @@ void main() {
// 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(c_long == typeof(INT_AND_LONG())));
+ static assert(is(c_ulong == 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())));
diff --git a/Examples/test-suite/d/preproc_constants_runme.2.d b/Examples/test-suite/d/preproc_constants_runme.2.d
index e2eab2c46..2d92ef052 100644
--- a/Examples/test-suite/d/preproc_constants_runme.2.d
+++ b/Examples/test-suite/d/preproc_constants_runme.2.d
@@ -1,5 +1,6 @@
module preproc_constants_runme;
+import core.stdc.config;
import preproc_constants.preproc_constants;
void main() {
@@ -9,10 +10,10 @@ void main() {
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(c_long == typeof(CONST_LONG1())));
+ static assert(is(c_long == typeof(CONST_LONG2())));
+ static assert(is(c_long == typeof(CONST_LONG3())));
+ static assert(is(c_long == typeof(CONST_LONG4())));
static assert(is(long == typeof(CONST_LLONG1())));
static assert(is(long == typeof(CONST_LLONG2())));
static assert(is(long == typeof(CONST_LLONG3())));
@@ -37,8 +38,8 @@ void main() {
// 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(c_long == typeof(INT_AND_LONG())));
+ static assert(is(c_ulong == 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())));
diff --git a/Lib/d/dprimitives.swg b/Lib/d/dprimitives.swg
index 53a4b89da..24ac8c9a0 100644
--- a/Lib/d/dprimitives.swg
+++ b/Lib/d/dprimitives.swg
@@ -4,6 +4,19 @@
* Typemaps for primitive types.
* ----------------------------------------------------------------------------- */
+// C long/ulong width depends on the target arch, use stdlib aliases for them.
+#if (SWIG_D_VERSION == 1)
+%pragma(d) imdmoduleimports = "static import tango.stdc.config;"
+%pragma(d) globalproxyimports = "static import tango.stdc.config;"
+#define SWIG_LONG_DTYPE tango.stdc.config.c_long
+#define SWIG_ULONG_DTYPE tango.stdc.config.c_ulong
+#else
+%pragma(d) imdmoduleimports = "static import core.stdc.config;"
+%pragma(d) globalproxyimports = "static import core.stdc.config;"
+#define SWIG_LONG_DTYPE core.stdc.config.c_long
+#define SWIG_ULONG_DTYPE core.stdc.config.c_ulong
+#endif
+
/*
* The SWIG_D_PRIMITIVE macro is used to define the typemaps for the primitive
* types, because are more or less the same for all of them. The few special
@@ -49,8 +62,8 @@ 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(long, SWIG_LONG_DTYPE)
+SWIG_D_PRIMITIVE(unsigned long, SWIG_ULONG_DTYPE)
SWIG_D_PRIMITIVE(size_t, size_t)
SWIG_D_PRIMITIVE(long long, long)
SWIG_D_PRIMITIVE(unsigned long long, ulong)
diff --git a/Lib/d/typemaps.i b/Lib/d/typemaps.i
index 143c736f5..4f1b5997c 100644
--- a/Lib/d/typemaps.i
+++ b/Lib/d/typemaps.i
@@ -74,8 +74,8 @@ 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, SWIG_LONG_DTYPE)
+INPUT_TYPEMAP(unsigned long, unsigned long, SWIG_ULONG_DTYPE)
INPUT_TYPEMAP(long long, long long, long)
INPUT_TYPEMAP(unsigned long long, unsigned long long, ulong)
INPUT_TYPEMAP(float, float, float)
@@ -157,8 +157,8 @@ 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, SWIG_LONG_DTYPE,INT32_PTR)
+OUTPUT_TYPEMAP(unsigned long, unsigned long, SWIG_ULONG_DTYPE,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)
@@ -248,8 +248,8 @@ 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, SWIG_LONG_DTYPE,INT32_PTR)
+INOUT_TYPEMAP(unsigned long, unsigned long, SWIG_ULONG_DTYPE,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)