From 092a0af0ecaacb713d208a2e9708a9a0a9d56e2e Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 11 Dec 2015 15:33:28 +0000 Subject: [PATCH] * removed special-purpose code for constant chars while parsing typed string constants: it did not properly handle ansistring code pages, and was just a hack to speed things up a bit (mantis #29153) git-svn-id: trunk@32636 - --- .gitattributes | 1 + compiler/ngtcon.pas | 12 ++---------- tests/webtbs/tw29153.pp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 tests/webtbs/tw29153.pp diff --git a/.gitattributes b/.gitattributes index d8cefd9a97..2be46933b0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14894,6 +14894,7 @@ tests/webtbs/tw29096.pp svneol=native#text/plain tests/webtbs/tw2911.pp svneol=native#text/plain tests/webtbs/tw2912.pp svneol=native#text/plain tests/webtbs/tw2913.pp svneol=native#text/plain +tests/webtbs/tw29153.pp svneol=native#text/plain tests/webtbs/tw2916.pp svneol=native#text/plain tests/webtbs/tw2920.pp svneol=native#text/plain tests/webtbs/tw2923.pp svneol=native#text/plain diff --git a/compiler/ngtcon.pas b/compiler/ngtcon.pas index 8b4b544c0d..b6eb9ebcb9 100644 --- a/compiler/ngtcon.pas +++ b/compiler/ngtcon.pas @@ -461,7 +461,6 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis var strlength : aint; strval : pchar; - strch : char; ll : tasmlabofs; ca : pchar; winlike : boolean; @@ -470,7 +469,8 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis strval:=''; { load strval and strlength of the constant tree } if (node.nodetype=stringconstn) or is_wide_or_unicode_string(def) or is_constwidecharnode(node) or - ((node.nodetype=typen) and is_interfacecorba(ttypenode(node).typedef)) then + ((node.nodetype=typen) and is_interfacecorba(ttypenode(node).typedef)) or + is_constcharnode(node) then begin { convert to the expected string type so that for widestrings strval is a pcompilerwidestring } @@ -497,14 +497,6 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis CGMessage(parser_e_widestring_to_ansi_compile_time); end; end - else if is_constcharnode(node) then - begin - { strval:=pchar(@tordconstnode(node).value); - THIS FAIL on BIG_ENDIAN MACHINES PM } - strch:=chr(tordconstnode(node).value.svalue and $ff); - strval:=@strch; - strlength:=1 - end else if is_constresourcestringnode(node) then begin hsym:=tconstsym(tloadnode(node).symtableentry); diff --git a/tests/webtbs/tw29153.pp b/tests/webtbs/tw29153.pp new file mode 100644 index 0000000000..944b053dcf --- /dev/null +++ b/tests/webtbs/tw29153.pp @@ -0,0 +1,32 @@ +program bug; +{$IFDEF FPC} +{$CODEPAGE UTF8} +{$ENDIF} +const + c1: RawByteString = 'a'; + c2: RawByteString = 'aa'; + c3: RawByteString = 'aaa'; +begin + writeln(StringCodePage(c1)); + writeln(StringCodePage(c2)); + writeln(StringCodePage(c3)); + if stringcodepage(c1)<>CP_UTF8 then + halt(1); + if stringcodepage(c2)<>CP_UTF8 then + halt(2); + if stringcodepage(c3)<>CP_UTF8 then + halt(3); + + c1:='a'; + c2:='aa'; + c3:='aaa'; + writeln(StringCodePage(c1)); + writeln(StringCodePage(c2)); + writeln(StringCodePage(c3)); + if stringcodepage(c1)<>CP_UTF8 then + halt(4); + if stringcodepage(c2)<>CP_UTF8 then + halt(5); + if stringcodepage(c3)<>CP_UTF8 then + halt(6); +end.