blob: f4ed782a82f709d5f3cb875ebb43be38261b5c4d [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From 90ba174fcea1618af57aa594199541d47a89b7f6 Mon Sep 17 00:00:00 2001
2From: William S Fulton <wsf@fultondesigns.co.uk>
3Date: Sun, 17 Sep 2017 19:02:55 +0100
4Subject: [PATCH 1/2] Fix generated code for constant expressions containing
5 wchar_t L literals.
6
7Such as:
8 # define __WCHAR_MAX (0x7fffffff + L'\0')
9
10Reported on swig-user mailing list.
11---
12 CHANGES.current | 5 +++++
13 Examples/test-suite/csharp/preproc_constants_c_runme.cs | 3 ++-
14 Examples/test-suite/csharp/preproc_constants_runme.cs | 2 ++
15 Examples/test-suite/d/preproc_constants_c_runme.1.d | 2 ++
16 Examples/test-suite/d/preproc_constants_c_runme.2.d | 2 ++
17 Examples/test-suite/d/preproc_constants_runme.1.d | 2 ++
18 Examples/test-suite/d/preproc_constants_runme.2.d | 2 ++
19 Examples/test-suite/php/preproc_constants_c_runme.php | 2 ++
20 Examples/test-suite/php/preproc_constants_runme.php | 2 ++
21 Examples/test-suite/php5/preproc_constants_c_runme.php | 2 ++
22 Examples/test-suite/php5/preproc_constants_runme.php | 2 ++
23 Examples/test-suite/preproc_constants.i | 3 +++
24 Source/CParse/parser.y | 2 +-
25 13 files changed, 29 insertions(+), 2 deletions(-)
26
27Upstream-Status: Backport
28[https://github.com/swig/swig/commit/90ba174fcea1618af57aa594199541d47a89b7f6]
29Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
30
31diff --git a/Examples/test-suite/csharp/preproc_constants_c_runme.cs b/Examples/test-suite/csharp/preproc_constants_c_runme.cs
32index 76c684d..1c28e49 100644
33--- a/Examples/test-suite/csharp/preproc_constants_c_runme.cs
34+++ b/Examples/test-suite/csharp/preproc_constants_c_runme.cs
35@@ -61,7 +61,8 @@ public class runme {
36 assert( typeof(int) == preproc_constants_c.EXPR_LAND.GetType() );
37 assert( typeof(int) == preproc_constants_c.EXPR_LOR.GetType() );
38 assert( typeof(double) == preproc_constants_c.EXPR_CONDITIONAL.GetType() );
39-
40+ assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MAX.GetType() );
41+ assert( typeof(int) == preproc_constants_c.EXPR_WCHAR_MIN.GetType() );
42 }
43 static void assert(bool assertion) {
44 if (!assertion)
45diff --git a/Examples/test-suite/csharp/preproc_constants_runme.cs b/Examples/test-suite/csharp/preproc_constants_runme.cs
46index 9fae591..6b02e30 100644
47--- a/Examples/test-suite/csharp/preproc_constants_runme.cs
48+++ b/Examples/test-suite/csharp/preproc_constants_runme.cs
49@@ -60,6 +60,8 @@ public class runme {
50 assert( typeof(bool) == preproc_constants.EXPR_LAND.GetType() );
51 assert( typeof(bool) == preproc_constants.EXPR_LOR.GetType() );
52 assert( typeof(double) == preproc_constants.EXPR_CONDITIONAL.GetType() );
53+ assert( typeof(int) == preproc_constants.EXPR_WCHAR_MAX.GetType() );
54+ assert( typeof(int) == preproc_constants.EXPR_WCHAR_MIN.GetType() );
55
56 }
57 static void assert(bool assertion) {
58diff --git a/Examples/test-suite/d/preproc_constants_c_runme.1.d b/Examples/test-suite/d/preproc_constants_c_runme.1.d
59index d846c71..2b349af 100644
60--- a/Examples/test-suite/d/preproc_constants_c_runme.1.d
61+++ b/Examples/test-suite/d/preproc_constants_c_runme.1.d
62@@ -61,4 +61,6 @@ void main() {
63 static assert(is(int == typeof(EXPR_LAND())));
64 static assert(is(int == typeof(EXPR_LOR())));
65 static assert(is(double == typeof(EXPR_CONDITIONAL())));
66+ static assert(is(int == typeof(EXPR_WCHAR_MAX())));
67+ static assert(is(int == typeof(EXPR_WCHAR_MIN())));
68 }
69diff --git a/Examples/test-suite/d/preproc_constants_c_runme.2.d b/Examples/test-suite/d/preproc_constants_c_runme.2.d
70index 9bdbb93..1bac525 100644
71--- a/Examples/test-suite/d/preproc_constants_c_runme.2.d
72+++ b/Examples/test-suite/d/preproc_constants_c_runme.2.d
73@@ -61,4 +61,6 @@ void main() {
74 static assert(is(int == typeof(EXPR_LAND())));
75 static assert(is(int == typeof(EXPR_LOR())));
76 static assert(is(double == typeof(EXPR_CONDITIONAL())));
77+ static assert(is(int == typeof(EXPR_WCHAR_MAX())));
78+ static assert(is(int == typeof(EXPR_WCHAR_MIN())));
79 }
80diff --git a/Examples/test-suite/d/preproc_constants_runme.1.d b/Examples/test-suite/d/preproc_constants_runme.1.d
81index 009405f..f743f48 100644
82--- a/Examples/test-suite/d/preproc_constants_runme.1.d
83+++ b/Examples/test-suite/d/preproc_constants_runme.1.d
84@@ -60,4 +60,6 @@ void main() {
85 static assert(is(bool == typeof(EXPR_LAND())));
86 static assert(is(bool == typeof(EXPR_LOR())));
87 static assert(is(double == typeof(EXPR_CONDITIONAL())));
88+ static assert(is(int == typeof(EXPR_WCHAR_MAX())));
89+ static assert(is(int == typeof(EXPR_WCHAR_MIN())));
90 }
91diff --git a/Examples/test-suite/d/preproc_constants_runme.2.d b/Examples/test-suite/d/preproc_constants_runme.2.d
92index 2d92ef0..0d96c37 100644
93--- a/Examples/test-suite/d/preproc_constants_runme.2.d
94+++ b/Examples/test-suite/d/preproc_constants_runme.2.d
95@@ -60,4 +60,6 @@ void main() {
96 static assert(is(bool == typeof(EXPR_LAND())));
97 static assert(is(bool == typeof(EXPR_LOR())));
98 static assert(is(double == typeof(EXPR_CONDITIONAL())));
99+ static assert(is(int == typeof(EXPR_WCHAR_MAX())));
100+ static assert(is(int == typeof(EXPR_WCHAR_MIN())));
101 }
102diff --git a/Examples/test-suite/php/preproc_constants_c_runme.php b/Examples/test-suite/php/preproc_constants_c_runme.php
103index af9b76e..e59fe18 100644
104--- a/Examples/test-suite/php/preproc_constants_c_runme.php
105+++ b/Examples/test-suite/php/preproc_constants_c_runme.php
106@@ -62,5 +62,7 @@ check::equal(gettype(preproc_constants_c::EXPR_OR), "integer", "preproc_constant
107 check::equal(gettype(preproc_constants_c::EXPR_LAND), "integer", "preproc_constants.EXPR_LAND has unexpected type");
108 check::equal(gettype(preproc_constants_c::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
109 check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
110+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
111+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
112
113 ?>
114diff --git a/Examples/test-suite/php/preproc_constants_runme.php b/Examples/test-suite/php/preproc_constants_runme.php
115index 5c9119b..8e117ea 100644
116--- a/Examples/test-suite/php/preproc_constants_runme.php
117+++ b/Examples/test-suite/php/preproc_constants_runme.php
118@@ -61,5 +61,7 @@ check::equal(gettype(preproc_constants::EXPR_OR), "integer", "preproc_constants.
119 check::equal(gettype(preproc_constants::EXPR_LAND), "boolean", "preproc_constants.EXPR_LAND has unexpected type");
120 check::equal(gettype(preproc_constants::EXPR_LOR), "boolean", "preproc_constants.EXPR_LOR has unexpected type");
121 check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
122+check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
123+check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
124
125 ?>
126diff --git a/Examples/test-suite/php5/preproc_constants_c_runme.php b/Examples/test-suite/php5/preproc_constants_c_runme.php
127index 1ea0195..d978fab 100644
128--- a/Examples/test-suite/php5/preproc_constants_c_runme.php
129+++ b/Examples/test-suite/php5/preproc_constants_c_runme.php
130@@ -62,5 +62,7 @@ check::equal(gettype(preproc_constants_c::EXPR_OR), "integer", "preproc_constant
131 check::equal(gettype(preproc_constants_c::EXPR_LAND), "integer", "preproc_constants.EXPR_LAND has unexpected type");
132 check::equal(gettype(preproc_constants_c::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
133 check::equal(gettype(preproc_constants_c::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
134+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
135+check::equal(gettype(preproc_constants_c::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
136
137 ?>
138diff --git a/Examples/test-suite/php5/preproc_constants_runme.php b/Examples/test-suite/php5/preproc_constants_runme.php
139index fb9ee4f..7527026 100644
140--- a/Examples/test-suite/php5/preproc_constants_runme.php
141+++ b/Examples/test-suite/php5/preproc_constants_runme.php
142@@ -70,5 +70,7 @@ check::equal(gettype(preproc_constants::EXPR_LAND), "integer", "preproc_constant
143 check::equal(gettype(preproc_constants::EXPR_LOR), "integer", "preproc_constants.EXPR_LOR has unexpected type");
144
145 check::equal(gettype(preproc_constants::EXPR_CONDITIONAL), "double", "preproc_constants.EXPR_CONDITIONAL has unexpected type");
146+check::equal(gettype(preproc_constants::EXPR_WCHAR_MAX), "integer", "preproc_constants.EXPR_WCHAR_MAX has unexpected type");
147+check::equal(gettype(preproc_constants::EXPR_WCHAR_MIN), "integer", "preproc_constants.EXPR_WCHAR_MIN has unexpected type");
148
149 ?>
150diff --git a/Examples/test-suite/preproc_constants.i b/Examples/test-suite/preproc_constants.i
151index 3a999ad..16b44c9 100644
152--- a/Examples/test-suite/preproc_constants.i
153+++ b/Examples/test-suite/preproc_constants.i
154@@ -87,6 +87,9 @@
155 #define EXPR_LOR 0xFF || 1
156 #define EXPR_CONDITIONAL true ? 2 : 2.2
157
158+#define EXPR_WCHAR_MAX (0x7fffffff + L'\0')
159+#define EXPR_WCHAR_MIN (-EXPR_WCHAR_MAX - 1)
160+
161 #define EXPR_CHAR_COMPOUND_ADD 'A' + 12
162 #define EXPR_CHAR_COMPOUND_LSHIFT 'B' << 6
163 #define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p')
164diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y
165index 2e92cd0..273dadb 100644
166--- a/Source/CParse/parser.y
167+++ b/Source/CParse/parser.y
168@@ -194,7 +194,7 @@ int SWIG_cparse_template_reduce(int treduce) {
169 * ----------------------------------------------------------------------------- */
170
171 static int promote_type(int t) {
172- if (t <= T_UCHAR || t == T_CHAR) return T_INT;
173+ if (t <= T_UCHAR || t == T_CHAR || t == T_WCHAR) return T_INT;
174 return t;
175 }
176
177--
1782.9.5
179