aboutsummaryrefslogtreecommitdiffstats
path: root/main/swig/swig-3.0.12-Fix-generated-code-for-constant-expressions-containi.patch
blob: 7198c215f2fb1acce01187f68a3df3172dd4062d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
From 90ba174fcea1618af57aa594199541d47a89b7f6 Mon Sep 17 00:00:00 2001
From: William S Fulton <wsf@fultondesigns.co.uk>
Date: Sun, 17 Sep 2017 19:02:55 +0100
Subject: [PATCH 1/2] Fix generated code for constant expressions containing
 wchar_t L literals.

Such as:
  # define __WCHAR_MAX    (0x7fffffff + L'\0')

Reported on swig-user mailing list.
---
 CHANGES.current                                         | 5 +++++
 Examples/test-suite/csharp/preproc_constants_c_runme.cs | 3 ++-
 Examples/test-suite/csharp/preproc_constants_runme.cs   | 2 ++
 Examples/test-suite/d/preproc_constants_c_runme.1.d     | 2 ++
 Examples/test-suite/d/preproc_constants_c_runme.2.d     | 2 ++
 Examples/test-suite/d/preproc_constants_runme.1.d       | 2 ++
 Examples/test-suite/d/preproc_constants_runme.2.d       | 2 ++
 Examples/test-suite/php/preproc_constants_c_runme.php   | 2 ++
 Examples/test-suite/php/preproc_constants_runme.php     | 2 ++
 Examples/test-suite/php5/preproc_constants_c_runme.php  | 2 ++
 Examples/test-suite/php5/preproc_constants_runme.php    | 2 ++
 Examples/test-suite/preproc_constants.i                 | 3 +++
 Source/CParse/parser.y                                  | 2 +-
 13 files changed, 29 insertions(+), 2 deletions(-)

#diff --git a/CHANGES.current b/CHANGES.current
#index 1e4a244..b455a9f 100644
#--- a/CHANGES.current
#+++ b/CHANGES.current
#@@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
# Version 4.0.0 (in progress)
# ===========================
# 
#+2017-09-17: wsfulton
#+            Fix generated code for constant expressions containing wchar_t L literals such as:
#+              # define __WCHAR_MAX    (0x7fffffff + L'\0')
#+              # define __WCHAR_MIN    (-__WCHAR_MAX - 1)
#+
# 2017-09-10: mlamarre
#             [Python] Patch #1083. Define_DEBUG to 1 to do exactly like Visual Studio
#             /LDd, /MDd or /MTd compiler options.
diff --git a/Examples/test-suite/csharp/preproc_constants_c_runme.cs b/Examples/test-suite/csharp/preproc_constants_c_runme.cs
index 76c684d..1c28e49 100644
--- a/Examples/test-suite/csharp/preproc_constants_c_runme.cs
+++ b/Examples/test-suite/csharp/preproc_constants_c_runme.cs
@@ -61,7 +61,8 @@ public class runme {
     assert( typeof(int) == preproc_constants_c.EXPR_LAND.GetType() );
     assert( typeof(int) == preproc_constants_c.EXPR_LOR.GetType() );
     assert( typeof(double) == preproc_constants_c.EXPR_CONDITIONAL.GetType() );
-
+    assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MAX.GetType() );
+    assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MIN.GetType() );
   }
   static void assert(bool assertion) {
     if (!assertion)
diff --git a/Examples/test-suite/csharp/preproc_constants_runme.cs b/Examples/test-suite/csharp/preproc_constants_runme.cs
index 9fae591..6b02e30 100644
--- a/Examples/test-suite/csharp/preproc_constants_runme.cs
+++ b/Examples/test-suite/csharp/preproc_constants_runme.cs
@@ -60,6 +60,8 @@ public class runme {
     assert( typeof(bool) == preproc_constants.EXPR_LAND.GetType() );
     assert( typeof(bool) == preproc_constants.EXPR_LOR.GetType() );
     assert( typeof(double) == preproc_constants.EXPR_CONDITIONAL.GetType() );
+    assert( typeof(int) == preproc_constants.EXPR_WCHAR_MAX.GetType() );
+    assert( typeof(int) == preproc_constants.EXPR_WCHAR_MIN.GetType() );
 
   }
   static void assert(bool assertion) {
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 d846c71..2b349af 100644
--- a/Examples/test-suite/d/preproc_constants_c_runme.1.d
+++ b/Examples/test-suite/d/preproc_constants_c_runme.1.d
@@ -61,4 +61,6 @@ void main() {
   static assert(is(int == typeof(EXPR_LAND())));
   static assert(is(int == typeof(EXPR_LOR())));
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
+  static assert(is(int == typeof(EXPR_WCHAR_MAX())));
+  static assert(is(int == typeof(EXPR_WCHAR_MIN())));
 }
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 9bdbb93..1bac525 100644
--- a/Examples/test-suite/d/preproc_constants_c_runme.2.d
+++ b/Examples/test-suite/d/preproc_constants_c_runme.2.d
@@ -61,4 +61,6 @@ void main() {
   static assert(is(int == typeof(EXPR_LAND())));
   static assert(is(int == typeof(EXPR_LOR())));
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
+  static assert(is(int == typeof(EXPR_WCHAR_MAX())));
+  static assert(is(int == typeof(EXPR_WCHAR_MIN())));
 }
diff --git a/Examples/test-suite/d/preproc_constants_runme.1.d b/Examples/test-suite/d/preproc_constants_runme.1.d
index 009405f..f743f48 100644
--- a/Examples/test-suite/d/preproc_constants_runme.1.d
+++ b/Examples/test-suite/d/preproc_constants_runme.1.d
@@ -60,4 +60,6 @@ void main() {
   static assert(is(bool == typeof(EXPR_LAND())));
   static assert(is(bool == typeof(EXPR_LOR())));
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
+  static assert(is(int == typeof(EXPR_WCHAR_MAX())));
+  static assert(is(int == typeof(EXPR_WCHAR_MIN())));
 }
diff --git a/Examples/test-suite/d/preproc_constants_runme.2.d b/Examples/test-suite/d/preproc_constants_runme.2.d
index 2d92ef0..0d96c37 100644
--- a/Examples/test-suite/d/preproc_constants_runme.2.d
+++ b/Examples/test-suite/d/preproc_constants_runme.2.d
@@ -60,4 +60,6 @@ void main() {
   static assert(is(bool == typeof(EXPR_LAND())));
   static assert(is(bool == typeof(EXPR_LOR())));
   static assert(is(double == typeof(EXPR_CONDITIONAL())));
+  static assert(is(int == typeof(EXPR_WCHAR_MAX())));
+  static assert(is(int == typeof(EXPR_WCHAR_MIN())));
 }
diff --git a/Examples/test-suite/php/preproc_constants_c_runme.php b/Examples/test-suite/php/preproc_constants_c_runme.php
index af9b76e..e59fe18 100644
--- a/Examples/test-suite/php/preproc_constants_c_runme.php
+++ b/Examples/test-suite/php/preproc_constants_c_runme.php
@@ -62,5 +62,7 @@ check::equal(gettype(preproc_constants_c::EXPR_OR), "integer", "preproc_constant
 check::equal(gettype(preproc_constants_c::EXPR_LAND), "integer", "preproc_constants.EXPR_LAND has unexpected type");
 check::equal(gettype(preproc_constants_c::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
 check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
 
 ?>
diff --git a/Examples/test-suite/php/preproc_constants_runme.php b/Examples/test-suite/php/preproc_constants_runme.php
index 5c9119b..8e117ea 100644
--- a/Examples/test-suite/php/preproc_constants_runme.php
+++ b/Examples/test-suite/php/preproc_constants_runme.php
@@ -61,5 +61,7 @@ check::equal(gettype(preproc_constants::EXPR_OR), "integer", "preproc_constants.
 check::equal(gettype(preproc_constants::EXPR_LAND), "boolean", "preproc_constants.EXPR_LAND has unexpected type");
 check::equal(gettype(preproc_constants::EXPR_LOR), "boolean", "preproc_constants.EXPR_LOR has unexpected type");
 check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
 
 ?>
diff --git a/Examples/test-suite/php5/preproc_constants_c_runme.php b/Examples/test-suite/php5/preproc_constants_c_runme.php
index 1ea0195..d978fab 100644
--- a/Examples/test-suite/php5/preproc_constants_c_runme.php
+++ b/Examples/test-suite/php5/preproc_constants_c_runme.php
@@ -62,5 +62,7 @@ check::equal(gettype(preproc_constants_c::EXPR_OR), "integer", "preproc_constant
 check::equal(gettype(preproc_constants_c::EXPR_LAND), "integer", "preproc_constants.EXPR_LAND has unexpected type");
 check::equal(gettype(preproc_constants_c::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
 check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
 
 ?>
diff --git a/Examples/test-suite/php5/preproc_constants_runme.php b/Examples/test-suite/php5/preproc_constants_runme.php
index fb9ee4f..7527026 100644
--- a/Examples/test-suite/php5/preproc_constants_runme.php
+++ b/Examples/test-suite/php5/preproc_constants_runme.php
@@ -70,5 +70,7 @@ check::equal(gettype(preproc_constants::EXPR_LAND), "integer", "preproc_constant
 check::equal(gettype(preproc_constants::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
 
 check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
+check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
 
 ?>
diff --git a/Examples/test-suite/preproc_constants.i b/Examples/test-suite/preproc_constants.i
index 3a999ad..16b44c9 100644
--- a/Examples/test-suite/preproc_constants.i
+++ b/Examples/test-suite/preproc_constants.i
@@ -87,6 +87,9 @@
 #define EXPR_LOR         0xFF || 1
 #define EXPR_CONDITIONAL true ? 2 : 2.2
 
+#define EXPR_WCHAR_MAX   (0x7fffffff + L'\0')
+#define EXPR_WCHAR_MIN   (-EXPR_WCHAR_MAX - 1)
+
 #define EXPR_CHAR_COMPOUND_ADD 'A' + 12
 #define EXPR_CHAR_COMPOUND_LSHIFT 'B' << 6
 #define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p')
diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
index 2e92cd0..273dadb 100644
--- a/Source/CParse/parser.y
+++ b/Source/CParse/parser.y
@@ -194,7 +194,7 @@ int SWIG_cparse_template_reduce(int treduce) {
  * ----------------------------------------------------------------------------- */
 
 static int promote_type(int t) {
-  if (t <= T_UCHAR || t == T_CHAR) return T_INT;
+  if (t <= T_UCHAR || t == T_CHAR || t == T_WCHAR) return T_INT;
   return t;
 }
 
-- 
2.9.5