View Issue Details

IDProjectCategoryView StatusLast Update
0029059LazarusLazUtilspublic2016-06-12 06:53
ReporterStephanoAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformOSWinCEOS Version
Product Version1.5 (SVN)Product Build 
Target Version1.6Fixed in Version1.6 
Summary0029059: WinCE projects fail to compile
DescriptionThe forcing of UTF8 RTL by default (can be disabled through the conditional directive DisableUTF8RTL) makes compilation of WinCE projects fail.

The compilation errors are mainly in winlazutf8.inc:

line 195: GetMem(argv,SizeOf(Pointer)*length(ArgsW));
line 199: argv[i]:=PChar(ArgsUTF8[i]);
line 523: argv:=OldArgV;
Error: Can't take the address of constant expressions / argv is a function and can't be assigned to

line 354: if (GetLocaleInfoA(aLocaleID, aLCType, Buf, sizeof(buf)) > 0)
Error: Identifier not found "GetLocaleInfoA"

line 497: GetFormatSettingsUTF8(GetThreadLocale,FormatSettings);
Error: Identifier not found "GetThreadLocale"


There are 2 workarounds:

1- For each and every project: Project options / Additions and Overrides / Use System Encoding

2- Apply the attached patch. If then one wants to test the UTF8 RTL, do the same as in (1) above and change -dDisableUTF8RTL to -dWinCEEnableUTF8RTL
TagsNo tags attached.
Fixed in Revisionr50470, r50475
LazTarget1.6
WidgetsetWinCE
Attached Files
  • WinCE EnableUTF8RTL patch.diff (6,589 bytes)
    Index: lcl/interfaces/win32/interfaces.pp
    ===================================================================
    --- lcl/interfaces/win32/interfaces.pp	(revision 50454)
    +++ lcl/interfaces/win32/interfaces.pp	(working copy)
    @@ -24,7 +24,9 @@
     
     uses
       {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
       LazUTF8,
    +    {$IFEND}
       {$IFEND}
       InterfaceBase;
     
    Index: components/lazutils/winlazutf8.inc
    ===================================================================
    --- components/lazutils/winlazutf8.inc	(revision 50454)
    +++ components/lazutils/winlazutf8.inc	(working copy)
    @@ -8,8 +8,10 @@
       ArgsW: Array of WideString;
       ArgsWCount: Integer; // length(ArgsW)+1
       {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
       ArgsUTF8: Array of String; // the ArgsW array as UTF8
       OldArgV: PPChar = nil;
    +    {$IFEND}
       {$IFEND}
     
     //************ START "Stubs" that just call Ansi or Wide implementation
    @@ -189,6 +191,7 @@
       Dec(ArgsWCount);
     
       {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
       if DefaultSystemCodePage=CP_UTF8 then begin
         SetLength(ArgsUTF8,length(ArgsW));
         OldArgV:=argv;
    @@ -199,6 +202,7 @@
           argv[i]:=PChar(ArgsUTF8[i]);
         end;
       end;
    +    {$IFEND}
       {$IFEND}
     end;
     
    @@ -332,6 +336,7 @@
     {$endif}
     
     {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +  {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
     function GetLocaleStr(aLocaleID, aLCType: Longint; const Def: string): String;
     var
       L: Integer;
    @@ -465,6 +470,7 @@
       end else
         Result:=0;
     end;
    +  {$IFEND}
     {$IFEND}
     
     procedure InitLazUtf8;
    @@ -494,6 +500,7 @@
         end;
       end;
       {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
       GetFormatSettingsUTF8(GetThreadLocale,FormatSettings);
       widestringmanager.UpperAnsiStringProc:=@UTF8UpperString;
       widestringmanager.LowerAnsiStringProc:=@UTF8LowerString;
    @@ -506,16 +513,20 @@
       // Does anyone need these two?
       //widestringmanager.StrLowerAnsiStringProc;
       //widestringmanager.StrUpperAnsiStringProc;
    +    {$IFEND}
       {$IFEND}
     end;
     
     procedure FinalizeLazUTF8;
     {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +  {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
     var
       p: PPChar;
    +  {$IFEND}
     {$IFEND}
     begin
       {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
       // restore argv and free memory
       if OldArgV<>nil then
       begin
    @@ -523,5 +534,6 @@
         argv:=OldArgV;
         Freemem(p);
       end;
    +    {$IFEND}
       {$IFEND}
     end;
    Index: components/lazutils/winlazfileutils.inc
    ===================================================================
    --- components/lazutils/winlazfileutils.inc	(revision 50454)
    +++ components/lazutils/winlazfileutils.inc	(working copy)
    @@ -539,7 +539,9 @@
       {$define FindData_W}
     {$IFEND}
     {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    -  {$DEFINE ReallyUseUTF8RTL}
    +  {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
    +    {$DEFINE ReallyUseUTF8RTL}
    +  {$IFEND}
     {$IFEND}
     
     function FindMatch(var f: TSearchRec) : Longint;
    Index: components/lazutils/paswstring.pas
    ===================================================================
    --- components/lazutils/paswstring.pas	(revision 50454)
    +++ components/lazutils/paswstring.pas	(working copy)
    @@ -23,9 +23,11 @@
     // sanity checks for defines
     {$IF FPC_FULLVERSION >= 30000}
       {$IFnDEF DisableUTF8RTL}
    -    {$IFDEF PASWSTRING_SUPPORT_NONUTF8_ANSISTRING}
    -      {$error UTF8 or not UTF8}
    -    {$ENDIF}
    +    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
    +      {$IFDEF PASWSTRING_SUPPORT_NONUTF8_ANSISTRING}
    +        {$error UTF8 or not UTF8}
    +      {$ENDIF}
    +    {$IFEND}
       {$ENDIF}
       {$DEFINE DisablePasWString}
     {$ENDIF}
    Index: components/lazutils/lconvencoding.pas
    ===================================================================
    --- components/lazutils/lconvencoding.pas	(revision 50454)
    +++ components/lazutils/lconvencoding.pas	(working copy)
    @@ -19,9 +19,11 @@
     {$if FPC_FULLVERSION >= 30000}
       {$Define HasCP} // AnsiString has codepage
       {$IFnDEF DisableUTF8RTL}
    -    // Windows provides conversion functions.
    -    // Unix: unit cwstring provides conversion functions which are used by default UTF-8 encoding system.
    -    {$Define UseSystemCPConv} // use system conversions
    +    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
    +      // Windows provides conversion functions.
    +      // Unix: unit cwstring provides conversion functions which are used by default UTF-8 encoding system.
    +      {$Define UseSystemCPConv} // use system conversions
    +    {$IFEND}
       {$ENDIF}
     {$IFEND}
     {$ifdef UseLCPConv}{$undef UseSystemCPConv}{$endif}
    Index: components/lazutils/lazutf8.pas
    ===================================================================
    --- components/lazutils/lazutf8.pas	(revision 50454)
    +++ components/lazutils/lazutf8.pas	(working copy)
    @@ -19,7 +19,9 @@
     {$mode objfpc}{$H+}{$inline on}
     
     {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    -  {$DEFINE ReallyUseUTF8RTL}
    +  {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
    +    {$DEFINE ReallyUseUTF8RTL}
    +  {$IFEND}
     {$IFEND}
     interface
     
    Index: components/lazutils/fpcadds.pas
    ===================================================================
    --- components/lazutils/fpcadds.pas	(revision 50454)
    +++ components/lazutils/fpcadds.pas	(working copy)
    @@ -65,10 +65,12 @@
     end;
     
     {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +  {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
     initialization
       SetMultiByteConversionCodePage(CP_UTF8);
       // SetMultiByteFileSystemCodePage(CP_UTF8); not needed, this is the default under Windows
       SetMultiByteRTLFileSystemCodePage(CP_UTF8);
    +  {$IFEND}
     {$IFEND}
     
     end.
    
  • lazutf8.diff (3,732 bytes)
    Index: components/lazutils/winlazutf8.inc
    ===================================================================
    --- components/lazutils/winlazutf8.inc	(revision 50401)
    +++ components/lazutils/winlazutf8.inc	(working copy)
    @@ -51,6 +51,21 @@
     end;
     {$endif}
     
    +{$ifndef wince}
    +procedure SetupArgvAsUtf8;
    +var
    +  i: Integer;
    +begin
    +  SetLength(ArgsUTF8,length(ArgsW));
    +  OldArgV:=argv;
    +  GetMem(argv,SizeOf(Pointer)*length(ArgsW));
    +  for i:=0 to length(ArgsW)-1 do
    +  begin
    +    ArgsUTF8[i]:=ArgsW{%H-}[i];
    +    argv[i]:=PChar(ArgsUTF8[i]);
    +  end;
    +end;
    +{$endif}
     
     procedure SetupCommandlineParametersWide;
     var
    @@ -188,17 +203,9 @@
       end;
       Dec(ArgsWCount);
     
    -  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    -  if DefaultSystemCodePage=CP_UTF8 then begin
    -    SetLength(ArgsUTF8,length(ArgsW));
    -    OldArgV:=argv;
    -    GetMem(argv,SizeOf(Pointer)*length(ArgsW));
    -    for i:=0 to length(ArgsW)-1 do
    -    begin
    -      ArgsUTF8[i]:=ArgsW{%H-}[i];
    -      argv[i]:=PChar(ArgsUTF8[i]);
    -    end;
    -  end;
    +  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL) AND NOT DEFINED(WINCE)}
    +  if DefaultSystemCodePage=CP_UTF8 then
    +    SetupArgvAsUtf8;
       {$IFEND}
     end;
     
    @@ -349,13 +356,15 @@
     
     function GetLocaleCharUTF8(aLocaleID, aLCType: Longint; Def: Char): Char;
     var
    -  Buf: array[0..3] of Char; // sdate allows 4 chars.
    +  Buf: array[0..3] of WChar; // sdate allows 4 chars.
     begin
    -  if (GetLocaleInfoA(aLocaleID, aLCType, Buf, sizeof(buf)) > 0)
    +  //Use Widestring Api so it works on WinCE as well
    +  if (GetLocaleInfoW(aLocaleID, aLCType, Buf, sizeof(buf)) > 0)
       and (ord(Buf[0])<128) then
         Result := Buf[0]
       else begin
         Result := Def;
    +    {
         case Buf[0] of
         #$C2:
           case Buf[1] of
    @@ -383,6 +392,33 @@
           #$8E: if Buf[2]=#$96 then Result := ''''; // codepoint 9110 decimal separator
           end;
         end;
    +    }
    +    case Word(Buf[0]) of
    +      $00A0: Result := ' ';   // non breakable space
    +      $00B7: Result := '.';   // middle stop
    +      $02D9: Result := '''';  // dot above, italian handwriting
    +      $066B: Result := ',';   // arabic decimal separator, persian thousand separator
    +      $066C: Result := '''';  // arabic thousand separator
    +      $2002: Result := ' ';   // long space
    +      $2003: Result := ' ';   // long space
    +      $2009: Result := ' ';   // thin space
    +      $202F: Result := ' ';   // narrow non breakable space
    +      $2014: Result := '-';   // persian decimal mark
    +      $2396: Result := '''';  // codepoint 9110 decimal separator
    +      { Utf8     Utf16
    +        C2 A0 -> 00A0
    +        C2 B7 -> 00B7
    +        CB 99 -> 02D9
    +        D9 AB -> 066B
    +        D9 AC -> 066C
    +        E2 80 82 -> 2002
    +        E2 80 83 -> 2003
    +        E2 80 89 -> 2009
    +        E2 80 AF -> 202F
    +        E2 80 94 -> 2014
    +        E2 8E 96 -> 2396
    +      }
    +    end;
       end;
     end;
     
    @@ -494,7 +530,11 @@
         end;
       end;
       {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +  {$ifndef wince}
       GetFormatSettingsUTF8(GetThreadLocale,FormatSettings);
    +  {$else}
    +  GetFormatSettingsUTF8(GetUserDefaultLCID ,FormatSettings);
    +  {$endif}
       widestringmanager.UpperAnsiStringProc:=@UTF8UpperString;
       widestringmanager.LowerAnsiStringProc:=@UTF8LowerString;
       widestringmanager.CompareStrAnsiStringProc:=@UTF8CompareStr;
    @@ -515,13 +555,15 @@
       p: PPChar;
     {$IFEND}
     begin
    -  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL) AND NOT DEFINED(WINCE)}
       // restore argv and free memory
       if OldArgV<>nil then
       begin
         p:=argv;
    +    {$ifndef wince}
         argv:=OldArgV;
         Freemem(p);
    +    {$endif wince}
       end;
       {$IFEND}
     end;
    
    lazutf8.diff (3,732 bytes)
  • lazutf8-2.diff (3,612 bytes)
    Index: components/lazutils/winlazutf8.inc
    ===================================================================
    --- components/lazutils/winlazutf8.inc	(revision 50401)
    +++ components/lazutils/winlazutf8.inc	(working copy)
    @@ -51,6 +51,21 @@
     end;
     {$endif}
     
    +{$ifndef wince}
    +procedure SetupArgvAsUtf8;
    +var
    +  i: Integer;
    +begin
    +  SetLength(ArgsUTF8,length(ArgsW));
    +  OldArgV:=argv;
    +  GetMem(argv,SizeOf(Pointer)*length(ArgsW));
    +  for i:=0 to length(ArgsW)-1 do
    +  begin
    +    ArgsUTF8[i]:=ArgsW{%H-}[i];
    +    argv[i]:=PChar(ArgsUTF8[i]);
    +  end;
    +end;
    +{$endif}
     
     procedure SetupCommandlineParametersWide;
     var
    @@ -188,17 +203,9 @@
       end;
       Dec(ArgsWCount);
     
    -  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    -  if DefaultSystemCodePage=CP_UTF8 then begin
    -    SetLength(ArgsUTF8,length(ArgsW));
    -    OldArgV:=argv;
    -    GetMem(argv,SizeOf(Pointer)*length(ArgsW));
    -    for i:=0 to length(ArgsW)-1 do
    -    begin
    -      ArgsUTF8[i]:=ArgsW{%H-}[i];
    -      argv[i]:=PChar(ArgsUTF8[i]);
    -    end;
    -  end;
    +  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL) AND NOT DEFINED(WINCE)}
    +  if DefaultSystemCodePage=CP_UTF8 then
    +    SetupArgvAsUtf8;
       {$IFEND}
     end;
     
    @@ -349,13 +356,15 @@
     
     function GetLocaleCharUTF8(aLocaleID, aLCType: Longint; Def: Char): Char;
     var
    -  Buf: array[0..3] of Char; // sdate allows 4 chars.
    +  Buf: array[0..3] of WChar; // sdate allows 4 chars.
     begin
    -  if (GetLocaleInfoA(aLocaleID, aLCType, Buf, sizeof(buf)) > 0)
    +  //Use Widestring Api so it works on WinCE as well
    +  if (GetLocaleInfoW(aLocaleID, aLCType, Buf, sizeof(buf)) > 0)
       and (ord(Buf[0])<128) then
         Result := Buf[0]
       else begin
         Result := Def;
    +    {
         case Buf[0] of
         #$C2:
           case Buf[1] of
    @@ -383,6 +392,33 @@
           #$8E: if Buf[2]=#$96 then Result := ''''; // codepoint 9110 decimal separator
           end;
         end;
    +    }
    +    case Word(Buf[0]) of
    +      $00A0: Result := ' ';   // non breakable space
    +      $00B7: Result := '.';   // middle stop
    +      $02D9: Result := '''';  // dot above, italian handwriting
    +      $066B: Result := ',';   // arabic decimal separator, persian thousand separator
    +      $066C: Result := '''';  // arabic thousand separator
    +      $2002: Result := ' ';   // long space
    +      $2003: Result := ' ';   // long space
    +      $2009: Result := ' ';   // thin space
    +      $202F: Result := ' ';   // narrow non breakable space
    +      $2014: Result := '-';   // persian decimal mark
    +      $2396: Result := '''';  // codepoint 9110 decimal separator
    +      { Utf8     Utf16
    +        C2 A0 -> 00A0
    +        C2 B7 -> 00B7
    +        CB 99 -> 02D9
    +        D9 AB -> 066B
    +        D9 AC -> 066C
    +        E2 80 82 -> 2002
    +        E2 80 83 -> 2003
    +        E2 80 89 -> 2009
    +        E2 80 AF -> 202F
    +        E2 80 94 -> 2014
    +        E2 8E 96 -> 2396
    +      }
    +    end;
       end;
     end;
     
    @@ -494,7 +530,11 @@
         end;
       end;
       {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +  {$ifndef wince}
       GetFormatSettingsUTF8(GetThreadLocale,FormatSettings);
    +  {$else}
    +  GetFormatSettingsUTF8(GetUserDefaultLCID ,FormatSettings);
    +  {$endif}
       widestringmanager.UpperAnsiStringProc:=@UTF8UpperString;
       widestringmanager.LowerAnsiStringProc:=@UTF8LowerString;
       widestringmanager.CompareStrAnsiStringProc:=@UTF8CompareStr;
    @@ -515,7 +555,7 @@
       p: PPChar;
     {$IFEND}
     begin
    -  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
    +  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL) AND NOT DEFINED(WINCE)}
       // restore argv and free memory
       if OldArgV<>nil then
       begin
    
    lazutf8-2.diff (3,612 bytes)

Relationships

related to 0030253 resolvedOndrej Pokorny FormatFloat('#,'...); Become working incorrect after changing screen resolution 

Activities

Stephano

2015-11-21 10:55

developer  

WinCE EnableUTF8RTL patch.diff (6,589 bytes)
Index: lcl/interfaces/win32/interfaces.pp
===================================================================
--- lcl/interfaces/win32/interfaces.pp	(revision 50454)
+++ lcl/interfaces/win32/interfaces.pp	(working copy)
@@ -24,7 +24,9 @@
 
 uses
   {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
   LazUTF8,
+    {$IFEND}
   {$IFEND}
   InterfaceBase;
 
Index: components/lazutils/winlazutf8.inc
===================================================================
--- components/lazutils/winlazutf8.inc	(revision 50454)
+++ components/lazutils/winlazutf8.inc	(working copy)
@@ -8,8 +8,10 @@
   ArgsW: Array of WideString;
   ArgsWCount: Integer; // length(ArgsW)+1
   {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
   ArgsUTF8: Array of String; // the ArgsW array as UTF8
   OldArgV: PPChar = nil;
+    {$IFEND}
   {$IFEND}
 
 //************ START "Stubs" that just call Ansi or Wide implementation
@@ -189,6 +191,7 @@
   Dec(ArgsWCount);
 
   {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
   if DefaultSystemCodePage=CP_UTF8 then begin
     SetLength(ArgsUTF8,length(ArgsW));
     OldArgV:=argv;
@@ -199,6 +202,7 @@
       argv[i]:=PChar(ArgsUTF8[i]);
     end;
   end;
+    {$IFEND}
   {$IFEND}
 end;
 
@@ -332,6 +336,7 @@
 {$endif}
 
 {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+  {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
 function GetLocaleStr(aLocaleID, aLCType: Longint; const Def: string): String;
 var
   L: Integer;
@@ -465,6 +470,7 @@
   end else
     Result:=0;
 end;
+  {$IFEND}
 {$IFEND}
 
 procedure InitLazUtf8;
@@ -494,6 +500,7 @@
     end;
   end;
   {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
   GetFormatSettingsUTF8(GetThreadLocale,FormatSettings);
   widestringmanager.UpperAnsiStringProc:=@UTF8UpperString;
   widestringmanager.LowerAnsiStringProc:=@UTF8LowerString;
@@ -506,16 +513,20 @@
   // Does anyone need these two?
   //widestringmanager.StrLowerAnsiStringProc;
   //widestringmanager.StrUpperAnsiStringProc;
+    {$IFEND}
   {$IFEND}
 end;
 
 procedure FinalizeLazUTF8;
 {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+  {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
 var
   p: PPChar;
+  {$IFEND}
 {$IFEND}
 begin
   {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
   // restore argv and free memory
   if OldArgV<>nil then
   begin
@@ -523,5 +534,6 @@
     argv:=OldArgV;
     Freemem(p);
   end;
+    {$IFEND}
   {$IFEND}
 end;
Index: components/lazutils/winlazfileutils.inc
===================================================================
--- components/lazutils/winlazfileutils.inc	(revision 50454)
+++ components/lazutils/winlazfileutils.inc	(working copy)
@@ -539,7 +539,9 @@
   {$define FindData_W}
 {$IFEND}
 {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
-  {$DEFINE ReallyUseUTF8RTL}
+  {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
+    {$DEFINE ReallyUseUTF8RTL}
+  {$IFEND}
 {$IFEND}
 
 function FindMatch(var f: TSearchRec) : Longint;
Index: components/lazutils/paswstring.pas
===================================================================
--- components/lazutils/paswstring.pas	(revision 50454)
+++ components/lazutils/paswstring.pas	(working copy)
@@ -23,9 +23,11 @@
 // sanity checks for defines
 {$IF FPC_FULLVERSION >= 30000}
   {$IFnDEF DisableUTF8RTL}
-    {$IFDEF PASWSTRING_SUPPORT_NONUTF8_ANSISTRING}
-      {$error UTF8 or not UTF8}
-    {$ENDIF}
+    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
+      {$IFDEF PASWSTRING_SUPPORT_NONUTF8_ANSISTRING}
+        {$error UTF8 or not UTF8}
+      {$ENDIF}
+    {$IFEND}
   {$ENDIF}
   {$DEFINE DisablePasWString}
 {$ENDIF}
Index: components/lazutils/lconvencoding.pas
===================================================================
--- components/lazutils/lconvencoding.pas	(revision 50454)
+++ components/lazutils/lconvencoding.pas	(working copy)
@@ -19,9 +19,11 @@
 {$if FPC_FULLVERSION >= 30000}
   {$Define HasCP} // AnsiString has codepage
   {$IFnDEF DisableUTF8RTL}
-    // Windows provides conversion functions.
-    // Unix: unit cwstring provides conversion functions which are used by default UTF-8 encoding system.
-    {$Define UseSystemCPConv} // use system conversions
+    {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
+      // Windows provides conversion functions.
+      // Unix: unit cwstring provides conversion functions which are used by default UTF-8 encoding system.
+      {$Define UseSystemCPConv} // use system conversions
+    {$IFEND}
   {$ENDIF}
 {$IFEND}
 {$ifdef UseLCPConv}{$undef UseSystemCPConv}{$endif}
Index: components/lazutils/lazutf8.pas
===================================================================
--- components/lazutils/lazutf8.pas	(revision 50454)
+++ components/lazutils/lazutf8.pas	(working copy)
@@ -19,7 +19,9 @@
 {$mode objfpc}{$H+}{$inline on}
 
 {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
-  {$DEFINE ReallyUseUTF8RTL}
+  {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
+    {$DEFINE ReallyUseUTF8RTL}
+  {$IFEND}
 {$IFEND}
 interface
 
Index: components/lazutils/fpcadds.pas
===================================================================
--- components/lazutils/fpcadds.pas	(revision 50454)
+++ components/lazutils/fpcadds.pas	(working copy)
@@ -65,10 +65,12 @@
 end;
 
 {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+  {$IF NOT DEFINED(WINCE) OR DEFINED(WinCEEnableUTF8RTL)} // temporary workaround for WinCE bug #29059
 initialization
   SetMultiByteConversionCodePage(CP_UTF8);
   // SetMultiByteFileSystemCodePage(CP_UTF8); not needed, this is the default under Windows
   SetMultiByteRTLFileSystemCodePage(CP_UTF8);
+  {$IFEND}
 {$IFEND}
 
 end.

Bart Broersma

2015-11-21 14:08

developer   ~0087446

> argv is a function and can't be assigned to
This is actually different from win32/win64??

Juha Manninen

2015-11-21 14:36

developer   ~0087448

I don't know why you use energy for a workaround patch instead of fixing the actual problem.

If you need help, please ask the WinCE users who answered your "call" in Lazarus mailing list.

Stephano

2015-11-21 15:25

developer   ~0087450

wince/system.pp defines argv as a function, whereas for win32:
argv : ppchar; public name 'operatingsystem_parameter_argv';

GetLocaleInfoA: I guess GetLocaleInfo can be used instead (but Buf has to adjusted for).

GetThreadLocale: I am not sure how much GetUserDefaultLCID is of a susbstitute in this case.

Bart Broersma

2015-11-21 16:27

developer   ~0087455

Last edited: 2015-11-21 16:58

View 3 revisions

GetLocaleCharUTF8 can probably be rewritten to use GetLocaleInfoW

ArgsUTF8: Array of String; // the ArgsW array as UTF8
IIUC the purpose of this is to have ParamStr() return strings in Utf8 encoding (but without it setting StringCodePage to CP_UTF8).

To me it is unclear why this is needed at all.
ParamStr() in the past never returned strings that were UTF8 encoded.
That said, it could be done for WinCE as well I think (by setting argv to a local function that return the proper value).

ParamStringUtf8() will always convert from WideString to Utf8 encoded AnsiString (as designed), and this should work also on Wince if the tampering with argv is disable for that widgetset.

Bart Broersma

2015-11-21 18:06

developer   ~0087457

Attached a possible patch.
Currently I have no 3.0 wince crosscompiler installed, so someone else has to test if it compiles.

- it now uses GetLocaleInfoW
- it tries to setup a ppchar variable holding the correct values ad then assigns argv function to a function that returns the ppchar variable. Not sure if the @ operator should be in argv:=@WinCeArgvFunc;

Bart Broersma

2015-11-21 18:43

developer  

lazutf8.diff (3,732 bytes)
Index: components/lazutils/winlazutf8.inc
===================================================================
--- components/lazutils/winlazutf8.inc	(revision 50401)
+++ components/lazutils/winlazutf8.inc	(working copy)
@@ -51,6 +51,21 @@
 end;
 {$endif}
 
+{$ifndef wince}
+procedure SetupArgvAsUtf8;
+var
+  i: Integer;
+begin
+  SetLength(ArgsUTF8,length(ArgsW));
+  OldArgV:=argv;
+  GetMem(argv,SizeOf(Pointer)*length(ArgsW));
+  for i:=0 to length(ArgsW)-1 do
+  begin
+    ArgsUTF8[i]:=ArgsW{%H-}[i];
+    argv[i]:=PChar(ArgsUTF8[i]);
+  end;
+end;
+{$endif}
 
 procedure SetupCommandlineParametersWide;
 var
@@ -188,17 +203,9 @@
   end;
   Dec(ArgsWCount);
 
-  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
-  if DefaultSystemCodePage=CP_UTF8 then begin
-    SetLength(ArgsUTF8,length(ArgsW));
-    OldArgV:=argv;
-    GetMem(argv,SizeOf(Pointer)*length(ArgsW));
-    for i:=0 to length(ArgsW)-1 do
-    begin
-      ArgsUTF8[i]:=ArgsW{%H-}[i];
-      argv[i]:=PChar(ArgsUTF8[i]);
-    end;
-  end;
+  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL) AND NOT DEFINED(WINCE)}
+  if DefaultSystemCodePage=CP_UTF8 then
+    SetupArgvAsUtf8;
   {$IFEND}
 end;
 
@@ -349,13 +356,15 @@
 
 function GetLocaleCharUTF8(aLocaleID, aLCType: Longint; Def: Char): Char;
 var
-  Buf: array[0..3] of Char; // sdate allows 4 chars.
+  Buf: array[0..3] of WChar; // sdate allows 4 chars.
 begin
-  if (GetLocaleInfoA(aLocaleID, aLCType, Buf, sizeof(buf)) > 0)
+  //Use Widestring Api so it works on WinCE as well
+  if (GetLocaleInfoW(aLocaleID, aLCType, Buf, sizeof(buf)) > 0)
   and (ord(Buf[0])<128) then
     Result := Buf[0]
   else begin
     Result := Def;
+    {
     case Buf[0] of
     #$C2:
       case Buf[1] of
@@ -383,6 +392,33 @@
       #$8E: if Buf[2]=#$96 then Result := ''''; // codepoint 9110 decimal separator
       end;
     end;
+    }
+    case Word(Buf[0]) of
+      $00A0: Result := ' ';   // non breakable space
+      $00B7: Result := '.';   // middle stop
+      $02D9: Result := '''';  // dot above, italian handwriting
+      $066B: Result := ',';   // arabic decimal separator, persian thousand separator
+      $066C: Result := '''';  // arabic thousand separator
+      $2002: Result := ' ';   // long space
+      $2003: Result := ' ';   // long space
+      $2009: Result := ' ';   // thin space
+      $202F: Result := ' ';   // narrow non breakable space
+      $2014: Result := '-';   // persian decimal mark
+      $2396: Result := '''';  // codepoint 9110 decimal separator
+      { Utf8     Utf16
+        C2 A0 -> 00A0
+        C2 B7 -> 00B7
+        CB 99 -> 02D9
+        D9 AB -> 066B
+        D9 AC -> 066C
+        E2 80 82 -> 2002
+        E2 80 83 -> 2003
+        E2 80 89 -> 2009
+        E2 80 AF -> 202F
+        E2 80 94 -> 2014
+        E2 8E 96 -> 2396
+      }
+    end;
   end;
 end;
 
@@ -494,7 +530,11 @@
     end;
   end;
   {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+  {$ifndef wince}
   GetFormatSettingsUTF8(GetThreadLocale,FormatSettings);
+  {$else}
+  GetFormatSettingsUTF8(GetUserDefaultLCID ,FormatSettings);
+  {$endif}
   widestringmanager.UpperAnsiStringProc:=@UTF8UpperString;
   widestringmanager.LowerAnsiStringProc:=@UTF8LowerString;
   widestringmanager.CompareStrAnsiStringProc:=@UTF8CompareStr;
@@ -515,13 +555,15 @@
   p: PPChar;
 {$IFEND}
 begin
-  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL) AND NOT DEFINED(WINCE)}
   // restore argv and free memory
   if OldArgV<>nil then
   begin
     p:=argv;
+    {$ifndef wince}
     argv:=OldArgV;
     Freemem(p);
+    {$endif wince}
   end;
   {$IFEND}
 end;
lazutf8.diff (3,732 bytes)

Bart Broersma

2015-11-21 18:46

developer   ~0087459

Last edited: 2015-11-21 18:46

View 2 revisions

Finally installed crosscompiler.

> - it tries to setup a ppchar variable holding the correct values ad then
> assigns argv function to a function that returns the ppchar variable.

Well that doesn't compile ;-)

Uploaded new patch.
It compiles.
It builds.
The WinCE executable at least does not crash.

Please review.

(I don't know how to setup commandline parameters on WinCE)

Bart Broersma

2015-11-21 18:48

developer   ~0087460

Maybe we could file a feature request for fpc to make argv a function variable in WinCE?

Sven Barth

2015-11-21 20:16

manager   ~0087461

This wouldn't solve your problem at hand. Even if we'd change that right now then you'd need to wait at least till 3.0.2 as 3.0.0 is nearly out of the door already.

Regards,
Sven

Bart Broersma

2015-11-21 21:26

developer   ~0087467

> Even if we'd change that right now then you'd need to wait at least till 3.0.2
That's allright.
But if it is changed, at least we can fix this issue in the future.
When using the Utf8InRtl feature, ParamStrUtf8 will give the correct value with proposed patch. There is no need to use ParamStr() in that case.

> 3.0.0 is nearly out of the door already.
Yeah!

Stephano

2015-11-21 21:37

developer   ~0087468

@Bart,

In your patch, procedure FinalizeLazUTF8 has a {$ifndef wince} which is never used due to the preceding AND NOT DEFINED(WINCE). Pls double check.

The patch seems to be good (though I don't know how to setup commandline parameters on WinCE as well), but remains incomplete as long as argv is a function.


@Sven,

Is it possible to have argv changed for WinCE even if it follows in a later fpc version?

Bart Broersma

2015-11-21 23:21

developer   ~0087470

> In your patch, procedure FinalizeLazUTF8 has a {$ifndef wince} which is never
> used due to the preceding AND NOT DEFINED(WINCE)

You're right, I overlooked that.
Attached new patch.

I can commit if you think it's allright (for now).

Bart Broersma

2015-11-21 23:21

developer  

lazutf8-2.diff (3,612 bytes)
Index: components/lazutils/winlazutf8.inc
===================================================================
--- components/lazutils/winlazutf8.inc	(revision 50401)
+++ components/lazutils/winlazutf8.inc	(working copy)
@@ -51,6 +51,21 @@
 end;
 {$endif}
 
+{$ifndef wince}
+procedure SetupArgvAsUtf8;
+var
+  i: Integer;
+begin
+  SetLength(ArgsUTF8,length(ArgsW));
+  OldArgV:=argv;
+  GetMem(argv,SizeOf(Pointer)*length(ArgsW));
+  for i:=0 to length(ArgsW)-1 do
+  begin
+    ArgsUTF8[i]:=ArgsW{%H-}[i];
+    argv[i]:=PChar(ArgsUTF8[i]);
+  end;
+end;
+{$endif}
 
 procedure SetupCommandlineParametersWide;
 var
@@ -188,17 +203,9 @@
   end;
   Dec(ArgsWCount);
 
-  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
-  if DefaultSystemCodePage=CP_UTF8 then begin
-    SetLength(ArgsUTF8,length(ArgsW));
-    OldArgV:=argv;
-    GetMem(argv,SizeOf(Pointer)*length(ArgsW));
-    for i:=0 to length(ArgsW)-1 do
-    begin
-      ArgsUTF8[i]:=ArgsW{%H-}[i];
-      argv[i]:=PChar(ArgsUTF8[i]);
-    end;
-  end;
+  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL) AND NOT DEFINED(WINCE)}
+  if DefaultSystemCodePage=CP_UTF8 then
+    SetupArgvAsUtf8;
   {$IFEND}
 end;
 
@@ -349,13 +356,15 @@
 
 function GetLocaleCharUTF8(aLocaleID, aLCType: Longint; Def: Char): Char;
 var
-  Buf: array[0..3] of Char; // sdate allows 4 chars.
+  Buf: array[0..3] of WChar; // sdate allows 4 chars.
 begin
-  if (GetLocaleInfoA(aLocaleID, aLCType, Buf, sizeof(buf)) > 0)
+  //Use Widestring Api so it works on WinCE as well
+  if (GetLocaleInfoW(aLocaleID, aLCType, Buf, sizeof(buf)) > 0)
   and (ord(Buf[0])<128) then
     Result := Buf[0]
   else begin
     Result := Def;
+    {
     case Buf[0] of
     #$C2:
       case Buf[1] of
@@ -383,6 +392,33 @@
       #$8E: if Buf[2]=#$96 then Result := ''''; // codepoint 9110 decimal separator
       end;
     end;
+    }
+    case Word(Buf[0]) of
+      $00A0: Result := ' ';   // non breakable space
+      $00B7: Result := '.';   // middle stop
+      $02D9: Result := '''';  // dot above, italian handwriting
+      $066B: Result := ',';   // arabic decimal separator, persian thousand separator
+      $066C: Result := '''';  // arabic thousand separator
+      $2002: Result := ' ';   // long space
+      $2003: Result := ' ';   // long space
+      $2009: Result := ' ';   // thin space
+      $202F: Result := ' ';   // narrow non breakable space
+      $2014: Result := '-';   // persian decimal mark
+      $2396: Result := '''';  // codepoint 9110 decimal separator
+      { Utf8     Utf16
+        C2 A0 -> 00A0
+        C2 B7 -> 00B7
+        CB 99 -> 02D9
+        D9 AB -> 066B
+        D9 AC -> 066C
+        E2 80 82 -> 2002
+        E2 80 83 -> 2003
+        E2 80 89 -> 2009
+        E2 80 AF -> 202F
+        E2 80 94 -> 2014
+        E2 8E 96 -> 2396
+      }
+    end;
   end;
 end;
 
@@ -494,7 +530,11 @@
     end;
   end;
   {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+  {$ifndef wince}
   GetFormatSettingsUTF8(GetThreadLocale,FormatSettings);
+  {$else}
+  GetFormatSettingsUTF8(GetUserDefaultLCID ,FormatSettings);
+  {$endif}
   widestringmanager.UpperAnsiStringProc:=@UTF8UpperString;
   widestringmanager.LowerAnsiStringProc:=@UTF8LowerString;
   widestringmanager.CompareStrAnsiStringProc:=@UTF8CompareStr;
@@ -515,7 +555,7 @@
   p: PPChar;
 {$IFEND}
 begin
-  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL)}
+  {$IF (FPC_FULLVERSION >= 30000) AND NOT DEFINED(DisableUTF8RTL) AND NOT DEFINED(WINCE)}
   // restore argv and free memory
   if OldArgV<>nil then
   begin
lazutf8-2.diff (3,612 bytes)

Stephano

2015-11-22 09:13

developer   ~0087475

Pls commit it especially that we can't do more until argv is changed.

Bart Broersma

2015-11-22 13:34

developer   ~0087492

Please test and close if OK.

Issue History

Date Modified Username Field Change
2015-11-21 10:50 Stephano New Issue
2015-11-21 10:50 Stephano Status new => assigned
2015-11-21 10:50 Stephano Assigned To => Stephano
2015-11-21 10:55 Stephano File Added: WinCE EnableUTF8RTL patch.diff
2015-11-21 14:08 Bart Broersma Note Added: 0087446
2015-11-21 14:36 Juha Manninen Note Added: 0087448
2015-11-21 15:25 Stephano Note Added: 0087450
2015-11-21 16:27 Bart Broersma Note Added: 0087455
2015-11-21 16:28 Bart Broersma Note Edited: 0087455 View Revisions
2015-11-21 16:58 Bart Broersma Note Edited: 0087455 View Revisions
2015-11-21 18:01 Bart Broersma File Added: lazutf8.diff
2015-11-21 18:06 Bart Broersma Note Added: 0087457
2015-11-21 18:43 Bart Broersma File Deleted: lazutf8.diff
2015-11-21 18:43 Bart Broersma File Added: lazutf8.diff
2015-11-21 18:46 Bart Broersma Note Added: 0087459
2015-11-21 18:46 Bart Broersma Note Edited: 0087459 View Revisions
2015-11-21 18:48 Bart Broersma Note Added: 0087460
2015-11-21 20:16 Sven Barth Note Added: 0087461
2015-11-21 21:26 Bart Broersma Note Added: 0087467
2015-11-21 21:37 Stephano Note Added: 0087468
2015-11-21 23:21 Bart Broersma Note Added: 0087470
2015-11-21 23:21 Bart Broersma File Added: lazutf8-2.diff
2015-11-22 09:13 Stephano Note Added: 0087475
2015-11-22 12:37 Bart Broersma Assigned To Stephano => Bart Broersma
2015-11-22 13:34 Bart Broersma Fixed in Revision => r50470
2015-11-22 13:34 Bart Broersma LazTarget - => 1.6
2015-11-22 13:34 Bart Broersma Note Added: 0087492
2015-11-22 13:34 Bart Broersma Status assigned => resolved
2015-11-22 13:34 Bart Broersma Fixed in Version => 1.6
2015-11-22 13:34 Bart Broersma Resolution open => fixed
2015-11-22 13:34 Bart Broersma Target Version => 1.6
2015-11-22 14:26 Stephano Status resolved => closed
2015-11-23 10:59 Bart Broersma Status closed => assigned
2015-11-23 10:59 Bart Broersma Resolution fixed => reopened
2015-11-23 10:59 Bart Broersma Fixed in Revision r50470 => r50470, r50475
2015-11-23 10:59 Bart Broersma Status assigned => resolved
2015-11-23 10:59 Bart Broersma Resolution reopened => fixed
2015-11-23 10:59 Bart Broersma Status resolved => closed
2016-06-12 06:53 Ondrej Pokorny Relationship added related to 0030253