Recent

Author Topic: FPC 3.2.2 - compilerproc problem with fpc_ansistr_unique  (Read 356 times)

paule32

  • Hero Member
  • *****
  • Posts: 565
  • One in all. But, not all in one.
FPC 3.2.2 - compilerproc problem with fpc_ansistr_unique
« on: May 18, 2025, 04:42:05 pm »
Hello,
I am faced with a problem that I can not solve:
when I use this source code (without SetLength), I get the message:
Code: Bash  [Select][+][-]
  1. StrUtils.pas(130,8) Fatal: Unknown compilerproc "fpc_ansistr_unique". Check if you use the correct run time library.
  2. Fatal: Compilation aborted

Code: Pascal  [Select][+][-]
  1. procedure fpc_ansistr_unique(var s: AnsiString); compilerproc;
  2. var
  3.   pSrc, pDst: PChar;
  4.   len: LongInt;
  5.   refCountPtr: PLongInt;
  6.   newMem: Pointer;
  7. begin
  8.   if Pointer(s) = nil then
  9.     Exit;
  10.  
  11.   // RefCount-Adresse berechnen
  12.   refCountPtr := PLongInt(Pointer(s) - 8);
  13.   len := PLongInt(Pointer(s) - 4)^;
  14.  
  15.   // Nur bei mehrfacher Referenz kopieren
  16.   if refCountPtr^ > 1 then
  17.   begin
  18.     // Neuen Speicherblock mit Header (8 Byte) + Inhalt + Nullterminierung
  19.     GetMem(newMem, 8 + len + 1);
  20.    
  21.     // RefCount = 1
  22.     PLongInt(newMem)^ := 1;
  23.     // Länge übernehmen
  24.     PLongInt(Pointer(newMem) + 4)^ := len;
  25.     // Daten kopieren
  26.     pSrc := PChar(s);
  27.     pDst := PChar(Pointer(newMem) + 8);
  28.     Move(pSrc^, pDst^, len);
  29.     pDst[len] := #0;
  30.  
  31.     // Alten RefCount dekrementieren
  32.     Dec(refCountPtr^);
  33.  
  34.     // neuen Zeiger setzen
  35.     Pointer(s) := PChar(Pointer(newMem) + 8);
  36.   end;
  37. end;
  38.  
  39. procedure fpc_ansistr_setlength(var s: AnsiString; newlen: SizeInt); compilerproc;
  40. var
  41.   tmp: AnsiString;
  42.   i: Integer;
  43. begin
  44.   tmp := StrPas('');
  45.   if Length(s) < newlen then
  46.   begin
  47.     for i := 1 to newlen do
  48.     tmp[i] := s[i];  // <-- in this line, the compiler need fpc_ansistr_unique
  49.   end else
  50.   begin
  51.     for i := Length(s) to newlen do
  52.     tmp[i] := s[i];
  53.   end;
  54.   s := tmp;
  55. end;
  56.  
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12312
  • FPC developer.
Re: FPC 3.2.2 - compilerproc problem with fpc_ansistr_unique
« Reply #1 on: May 18, 2025, 05:44:03 pm »
Do you also declare it in the interface of the system unit?

Thaddy

  • Hero Member
  • *****
  • Posts: 17405
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: FPC 3.2.2 - compilerproc problem with fpc_ansistr_unique
« Reply #2 on: May 18, 2025, 05:48:02 pm »
Hello,
I am faced with a problem that I can not solve:
when I use this source code (without SetLength), I get the message:
Strutils should not even touch that. (but you are always on the wrong side of the border of what is sensible)
It should use UniqueString instead,
« Last Edit: May 18, 2025, 05:50:23 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018