From 9d81148986e2c9cab0e69adbf133520cabba02c9 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sat, 24 Jan 2009 12:45:03 +0000 Subject: [PATCH] * only convert character constants into widechar/widestring when assigned to a widechar/widestring (compatible with constant string handling, mantis #13036) git-svn-id: trunk@12588 - --- .gitattributes | 1 + compiler/ncnv.pas | 11 ------ tests/webtbs/tw12933.pp | 31 ++++++++-------- tests/webtbs/tw13019.pp | 81 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 26 deletions(-) create mode 100644 tests/webtbs/tw13019.pp diff --git a/.gitattributes b/.gitattributes index 78a7e40edc..26cf41fd8a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8736,6 +8736,7 @@ tests/webtbs/tw12933.pp svneol=native#text/plain tests/webtbs/tw12942.pp svneol=native#text/plain tests/webtbs/tw1295.pp svneol=native#text/plain tests/webtbs/tw1299.pp svneol=native#text/plain +tests/webtbs/tw13019.pp svneol=native#text/plain tests/webtbs/tw1310.pp svneol=native#text/plain tests/webtbs/tw1318.pp svneol=native#text/plain tests/webtbs/tw1323.pp svneol=native#text/plain diff --git a/compiler/ncnv.pas b/compiler/ncnv.pas index d02a4c5e7f..458e266c56 100644 --- a/compiler/ncnv.pas +++ b/compiler/ncnv.pas @@ -917,17 +917,6 @@ implementation { we can't do widechar to ansichar conversions at compile time, since } { this maps all non-ascii chars to '?' -> loses information } - { one thing we have to do in advance: "constant ansichar" -> ansistring } - { conversions with ord(ansichar) >= 128, have to be done by converting } - { the ansichar to a widechar at compile time (using the source's code } - { page), and then by converting the widechar to an ansistring at run } - { time (using the run time code page) } - if (left.nodetype=ordconstn) and - not(tstringdef(resultdef).stringtype in [st_widestring,st_unicodestring]) and - (torddef(left.resultdef).ordtype=uchar) and - not(tordconstnode(left).value.uvalue<128) then - inserttypeconv(left,cwidechartype); - if (left.nodetype=ordconstn) and ((tstringdef(resultdef).stringtype in [st_widestring,st_unicodestring]) or (torddef(left.resultdef).ordtype=uchar) or diff --git a/tests/webtbs/tw12933.pp b/tests/webtbs/tw12933.pp index 67d8e939a2..05869feb17 100644 --- a/tests/webtbs/tw12933.pp +++ b/tests/webtbs/tw12933.pp @@ -11,28 +11,29 @@ uses cwstring; {$endif} var - s, s2: ansistring; - ws, ws2, ws3: widestring; + s: ansistring; + ws, ws3: widestring; begin + // must not be converted s := '£'; - writeln(s); + if (length(s)<>1) or + (s[1]<> #163) then + halt(1); - ws := s; + ws := '££'; writeln(ws); - - ws2 := '££'; - writeln(ws2); - s2:=ws2; - ws2:=s2; + s:=ws; + ws:=s; ws3 := '£'; + if ws3[1]<>ws[1] then + halt(2); writeln(ws3); - s2:=ws3; - ws3:=s2; + s:=ws3; + ws3:=s; - delete(ws2,1,1); + delete(ws,1,1); - if (ws<>ws2) or - (ws<>ws3) then - halt(1); + if (ws<>ws3) then + halt(3); end. diff --git a/tests/webtbs/tw13019.pp b/tests/webtbs/tw13019.pp new file mode 100644 index 0000000000..897fd364dc --- /dev/null +++ b/tests/webtbs/tw13019.pp @@ -0,0 +1,81 @@ +program bug13019; + +{$mode objfpc}{$H+} + +const expected : array[1..411] of byte = ( +62, 143, 158, 162, 176, 227, 28, 124, 207, 207 +, 12, 92, 26, 173, 164, 90, 1, 83, 2, 192 +, 135, 21, 118, 9, 252, 191, 12, 28, 240, 51 +, 254, 129, 199, 107, 15, 82, 56, 43, 82, 72 +, 216, 56, 88, 92, 105, 2, 17, 36, 73, 132 +, 224, 252, 173, 179, 106, 38, 224, 46, 70, 121 +, 245, 37, 122, 114, 61, 10, 48, 74, 75, 83 +, 24, 200, 13, 1, 128, 3, 45, 17, 196, 36 +, 238, 12, 235, 57, 3, 50, 106, 192, 196, 184 +, 112, 102, 0, 70, 24, 196, 4, 18, 130, 97 +, 131, 55, 209, 12, 238, 127, 185, 135, 161, 222 +, 139, 48, 181, 39, 215, 122, 167, 8, 123, 58 +, 191, 227, 179, 37, 77, 16, 35, 32, 195, 72 +, 200, 96, 37, 90, 65, 194, 198, 193, 128, 135 +, 254, 195, 135, 80, 142, 222, 225, 201, 226, 35 +, 244, 180, 0, 76, 4, 86, 96, 87, 235, 42 +, 218, 119, 47, 163, 177, 225, 55, 170, 105, 2 +, 34, 70, 204, 9, 66, 191, 73, 177, 6, 248 +, 90, 36, 132, 183, 51, 101, 252, 250, 182, 129 +, 225, 163, 131, 48, 75, 211, 105, 223, 46, 193 +, 218, 74, 3, 132, 58, 16, 39, 149, 218, 24 +, 201, 16, 166, 30, 78, 35, 77, 194, 148, 142 +, 50, 7, 18, 198, 250, 215, 42, 70, 142, 141 +, 166, 147, 112, 81, 133, 12, 68, 1, 54, 6 +, 203, 113, 0, 136, 168, 65, 130, 224, 197, 216 +, 43, 55, 171, 98, 177, 104, 11, 133, 2, 238 +, 206, 77, 34, 82, 231, 203, 39, 175, 102, 187 +, 64, 38, 170, 189, 3, 50, 90, 177, 222, 5 +, 202, 139, 155, 78, 182, 7, 68, 228, 254, 108 +, 217, 98, 244, 196, 149, 186, 101, 74, 212, 208 +, 193, 170, 98, 18, 189, 19, 88, 251, 15, 131 +, 225, 227, 151, 82, 173, 51, 48, 166, 214, 66 +, 75, 219, 94, 167, 20, 111, 2, 182, 2, 102 +, 66, 48, 49, 49, 97, 231, 231, 231, 157, 65 +, 169, 84, 218, 218, 255, 58, 29, 60, 176, 137 +, 185, 215, 207, 208, 212, 220, 138, 176, 185, 5 +, 141, 97, 147, 75, 32, 194, 248, 175, 207, 249 +, 246, 200, 190, 46, 102, 234, 101, 54, 253, 170 +, 7, 21, 204, 251, 65, 56, 168, 45, 173, 255 +, 1, 156, 162, 177, 64, 134, 27, 179, 141, 0 +, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96 +, 130); + + +var + i: Integer; + s: string; + +begin + s := + '>'#143#158#162#176#227#28'|'#207#207#12'\'#26#173#164'Z'#1'S'#2#192#135#21 + +'v'#9#252#191#12#28#240'3'#254#129#199'k'#15'R8+RH'#216'8X\i'#2#17'$I'#132 + +#224#252#173#179'j&'#224'.Fy'#245'%zr='#10'0JKS'#24#200#13#1#128#3'-'#17#196 + +'$'#238#12#235'9'#3'2j'#192#196#184'pf'#0'F'#24#196#4#18#130'a'#131'7'#209#12 + +#238''#185#135#161#222#139'0'#181''''#215'z'#167#8'{:'#191#227#179'%M'#16'#' + +' '#195'H'#200'`%ZA'#194#198#193#128#135#254#195#135'P'#142#222#225#201#226 + +'#'#244#180#0'L'#4'V`W'#235'*'#218'w/'#163#177#225'7'#170'i'#2'"F'#204#9'B' + +#191'I'#177#6#248'Z$'#132#183'3e'#252#250#182#129#225#163#131'0K'#211'i'#223 + +'.'#193#218'J'#3#132':'#16''''#149#218#24#201#16#166#30'N#M'#194#148#142'2'#7 + +#18#198#250#215'*F'#142#141#166#147'pQ'#133#12'D'#1'6'#6#203'q'#0#136#168'A' + +#130#224#197#216'+7'#171'b'#177'h'#11#133#2#238#206'M"R'#231#203''''#175'f' + +#187'@&'#170#189#3'2Z'#177#222#5#202#139#155'N'#182#7'D'#228#254'l'#217'b' + +#244#196#149#186'eJ'#212#208#193#170'b'#18#189#19'X'#251#15#131#225#227#151 + +'R'#173'30'#166#214'BK'#219'^'#167#20'o'#2#182#2'fB011a'#231#231#231#157'A' + +#169'T'#218#218#255':'#29'<'#176#137#185#215#207#208#212#220#138#176#185#5 + +#141'a'#147'K '#194#248#175#207#249#246#200#190'.f'#234'e6'#253#170#7#21#204 + +#251'A8'#168'-'#173#255#1#156#162#177'@'#134#27#179#141#0#0#0#0'IEND'#174'B`' + +#130; + for i := 1 to length(s) do + if (ord(s[i])<>expected[i]) then + begin + writeln('Different at index ',i, ', expected #', expected[i],', got #', ord(s[i])); + halt(1); + end; +end. +