Recent

Author Topic: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)  (Read 885 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2384
    • UVviewsoft
Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« on: December 01, 2022, 11:15:18 am »
Free Pascal Compiler version 3.2.3-660-g9b2ba834a6 [2022/08/18] for x86_64
Linux

For Pos('/text', StrVar) Lazarus IDE thinks that it is overload Pos(WideString, AnsiString). This gives little slower code! Can be avoided?

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« Reply #1 on: December 01, 2022, 11:44:06 am »
You can Cast your desired type "string('data'), otherString" or make it a variable to insert.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« Reply #2 on: December 01, 2022, 12:10:58 pm »
For Pos('/text', StrVar) Lazarus IDE thinks that it is overload Pos(WideString, AnsiString). This gives little slower code! Can be avoided?
How did you verify it?
'/text' should be interpreted as UTF-8 string when the default Unicode support is in action.
 https://wiki.lazarus.freepascal.org/Unicode_Support_in_Lazarus
Then the overload should be Pos(AnsiString, AnsiString).
Actually it can be interpreted as any 8-bit codepage and AnsiString overload is used.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

AlexTP

  • Hero Member
  • *****
  • Posts: 2384
    • UVviewsoft
Re: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« Reply #3 on: December 01, 2022, 01:42:08 pm »
I verify it only by IDE - by floating tooltip, by 'go to definition' into FPC src.

Is it IDE bug that it thinks about wrong overload?

Lazarus 2.3.0 (rev main-2_3-1386-g23b2324f9f) FPC 3.2.3 x86_64-linux-gtk2
« Last Edit: December 01, 2022, 01:43:43 pm by AlexTP »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« Reply #4 on: December 01, 2022, 02:09:35 pm »
In attachment you see what the Lazarus IDE is using for me while just typing that:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$IFDEF MSWINDOWS}{$APPTYPE CONSOLE}{$ENDIF}
  4.  
  5. {$R *.res}
  6.  
  7. var
  8.   s: string;
  9. begin
  10.   Pos('...',
  11. end.
  12.  
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

AlexTP

  • Hero Member
  • *****
  • Posts: 2384
    • UVviewsoft
Re: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« Reply #5 on: December 01, 2022, 02:35:47 pm »
Yes, same for me, Pos(WideString, RawByteString, SizeInt)

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« Reply #6 on: December 01, 2022, 04:47:53 pm »
It's a Lazarus CodeTools thing, not an fpc thing.

Bart

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« Reply #7 on: December 01, 2022, 09:23:54 pm »
It's a Lazarus CodeTools thing, not an fpc thing.

Bart
I am no expert to judge between FPC <-> Lazarus, on my system it is using declaration inside wstringh.inc instead of systemh.inc,
for myself I can live with it since I could cast to the version that I want to use  O:-)
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« Reply #8 on: December 01, 2022, 09:39:53 pm »
Yes, same for me, Pos(WideString, RawByteString, SizeInt)

Check what the assembly code is using (use -al to look at it). Anything that the IDE shows might be wrong.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« Reply #9 on: December 01, 2022, 09:44:15 pm »
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. {$h+}
  3.  
  4. var
  5.   S: String;
  6. begin
  7.   Pos('Test',S);
  8. end.

Relevant part of the assembler output.
Code: ASM  [Select][+][-]
  1. # [7] Pos('Test',S);
  2.         movl    U_$P$PROGRAM_$$_S,%edx
  3.         movl    $1,%ecx
  4.         movl    $.Ld1,%eax
  5.         call    SYSTEM_$$_POS$RAWBYTESTRING$RAWBYTESTRING$LONGINT$$LONGINT
  6.  

No WideString anywhere...

Bart

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Pos('/text', S) thinks that it is Pos(WideString, AnsiString)
« Reply #10 on: December 02, 2022, 10:33:50 am »
Yes, FPC figures out the right overload. CodeTools in Lazarus somehow gets it wrong.
On Linux I get a slightly different hint but still wrong. See the screenshot.

Adding {$mode objfpc}{$h+} to the program made no difference. Neither did adding "uses Classes, SysUtils;"
« Last Edit: December 02, 2022, 10:43:42 am by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018