View Issue Details

IDProjectCategoryView StatusLast Update
0029436LazarusLazUtilspublic2019-05-06 20:18
ReporterBart BroersmaAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionduplicate 
Platformi386OSWindowOS VersionWin7
Product VersionProduct Build 
Target VersionFixed in Version 
Summary0029436: LazUtils FileXXXUtf8() functions: maybe conditionally rewrite to call WideString fpc functions
DescriptionThe FileXXXUtf8 implementatiosn could be rewritten to use the WideString/Unicode string variant for fpc > 3.0.0.
This would reduce code duplication (and potential bugs) and would simplify things a lot when the 2.6 series compiler will not be supported anymore.
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetWin32/Win64, WinCE
Attached Files

Relationships

duplicate of 0035512 resolvedJuha Manninen winlazfileutils.inc patch 

Activities

Alexey Tor.

2017-03-31 15:42

reporter   ~0099297

The FPC 3.0.2 released; maybe consider this issue for it?

Juha Manninen

2017-03-31 18:42

developer   ~0099306

Last edited: 2017-03-31 18:59

View 2 revisions

I think those functions can be first deprecated and later removed.
Or does it need special treatment without the UTF-8 mode, when using -dDisableUTF8RTL?
My understanding is that RTL already calls the wide unicode WinAPI for those file functions.

Alexey Tor.

2017-03-31 19:41

reporter   ~0099314

Last edited: 2017-03-31 19:49

View 2 revisions

I see what man means:

SysUtils (FPC 3.x) has
Function FileExists (Const FileName : UnicodeString) : Boolean;
Function DirectoryExists (Const Directory : UnicodeString) : Boolean;
Function FileSetDate (Const FileName : UnicodeString;Age : Longint) : Longint;
Function FileGetAttr (Const FileName : UnicodeString) : Longint;
Function FileSetAttr (Const Filename : UnicodeString; Attr: longint) : Longint;

+
Function FileExists (Const FileName : RawByteString) : Boolean;
Function DirectoryExists (Const Directory : RawByteString) : Boolean;
Function FileSetDate (Const FileName : RawByteString;Age : Longint) : Longint;
Function FileGetAttr (Const FileName : RawByteString) : Longint;
Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;

man suggests to use 1st funcs. (on Win32). Now used 2nd funcs.

Juha Manninen

2017-04-01 08:57

developer   ~0099323

Last edited: 2017-04-01 09:00

View 2 revisions

> man suggests to use 1st funcs. (on Win32). Now used 2nd funcs.

Yes but how is that useful? LCL still uses AnsiStrings either with UTF-8 or with system codepage.
The actual WinAPI call inside those functions is the wide version, isn't it?

Bart, maybe I misunderstood your idea. How would it simplify things?

Alexey Tor.

2017-04-01 09:03

reporter   ~0099324

Juha,
you're right. This suggestion if wrong IMO.

Bart Broersma

2019-01-09 23:07

developer   ~0113294

Last edited: 2019-01-09 23:09

View 2 revisions

@Juha: e.g.
function FileOpenUtf8(Const FileName : string; Mode : Integer) : THandle;
begin
  Result := CreateFileW(PWideChar(UTF8Decode(FileName)), dword(AccessModes[Mode and 3]),
                         dword(ShareModes[(Mode and $F0) shr 4]), nil, OPEN_EXISTING,
                         FILE_ATTRIBUTE_NORMAL, 0);
  //if fail api return feInvalidHandle (INVALIDE_HANDLE=feInvalidHandle=-1)
end;

Change that to
function FileOpenUtf8(Const FileName : string; Mode : Integer) : THandle;
begin
  Result := FileOpen(WideString(FileName), Mode);
end;

(Only for fpc >= 3.0)
LazUTF8 unit will make Utf8ToUtf16 the default AnsiToWideString conversion procedure for the WideStringManager.
(Might need a check for DisableUtf8RTL)

Issue History

Date Modified Username Field Change
2016-01-17 18:38 Bart Broersma New Issue
2016-01-17 18:38 Bart Broersma Status new => assigned
2016-01-17 18:38 Bart Broersma Assigned To => Bart Broersma
2017-03-31 15:42 Alexey Tor. Note Added: 0099297
2017-03-31 18:42 Juha Manninen Note Added: 0099306
2017-03-31 18:59 Juha Manninen Note Edited: 0099306 View Revisions
2017-03-31 19:41 Alexey Tor. Note Added: 0099314
2017-03-31 19:49 Alexey Tor. Note Edited: 0099314 View Revisions
2017-04-01 08:57 Juha Manninen Note Added: 0099323
2017-04-01 09:00 Juha Manninen Note Edited: 0099323 View Revisions
2017-04-01 09:03 Alexey Tor. Note Added: 0099324
2019-01-09 23:07 Bart Broersma Note Added: 0113294
2019-01-09 23:09 Bart Broersma Note Edited: 0113294 View Revisions
2019-05-04 23:27 Bart Broersma Relationship added related to 0035512
2019-05-06 20:18 Bart Broersma Status assigned => resolved
2019-05-06 20:18 Bart Broersma Resolution open => duplicate
2019-05-06 20:18 Bart Broersma Widgetset Win32/Win64, WinCE => Win32/Win64, WinCE
2019-05-06 20:18 Bart Broersma Relationship replaced duplicate of 0035512
2019-05-06 20:18 Bart Broersma Status resolved => closed