View Issue Details

IDProjectCategoryView StatusLast Update
0038967FPCDocumentationpublic2021-06-06 08:00
ReporterSerge Anvarov Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.2.1 
Fixed in Version3.3.1 
Summary0038967: The example in the managed types documentation can be simplified, since the FPC already contains the desired function
DescriptionThere is no need to describe the SRefCount function and cast the parameter to a pointer everywhere, because there is a built-in StringRefCount function.
Additional InformationReference guide for Free Pascal, version 3.2.2
TagsNo tags attached.
Fixed in Revision1857
FPCOldBugId
FPCTarget4.0.0
Attached Files

Activities

Serge Anvarov

2021-06-06 02:34

reporter  

ref.tex.diff (2,110 bytes)   
Index: ref.tex
===================================================================
--- ref.tex	(revision 1856)
+++ ref.tex	(working copy)
@@ -11202,53 +11202,29 @@
 {$mode objfpc}
 {$H+}
 
-// Auxiliary function to extract reference count.
-function SRefCount(P : Pointer) : integer;
-
-Type
-  PAnsiRec = ^TAnsiRec;
-  TAnsiRec = Record
-    CodePage    : TSystemCodePage;
-    ElementSize : Word;
-  {$ifdef CPU64}
-  { align fields  }
-    Dummy       : DWord;
-  {$endif CPU64}
-    Ref         : SizeInt;
-    Len         : SizeInt;
-  end;
-
-
-begin
-  if P=Nil then
-    Result:=0
-  else
-    Result:=PAnsiRec(P-SizeOf(TAnsiRec))^.Ref;
-end;
-
 Procedure ByVar(Var S : string);
 
 begin
-  Writeln('By var, ref count : ',SRefCount(Pointer(S)));
+  Writeln('By var, ref count : ',StringRefCount(S));
 end;
 
 Procedure ByConst(Const S : string);
 
 begin
-  Writeln('Const, ref count : ',SRefCount(Pointer(S)));
+  Writeln('Const, ref count : ',StringRefCount(S));
 end;
 
 Procedure ByVal(S : string);
 
 begin
-  Writeln('Value, ref count : ',SRefCount(Pointer(S)));
+  Writeln('Value, ref count : ',StringRefCount(S));
 end;
 
 Function FunctionResult(Var S : String) : String;
 
 begin
-  Writeln('Function argument, ref count : ',SRefCount(Pointer(S)));
-  Writeln('Function result, ref count : ',SRefCount(Pointer(Result)));
+  Writeln('Function argument, ref count : ',StringRefCount(S));
+  Writeln('Function result, ref count : ',StringRefCount(Result));
 end;
 
 Var
@@ -11256,17 +11232,17 @@
 
 begin
   S:='Some string';
-  Writeln('Constant       : ',SrefCount(Pointer(S)));
+  Writeln('Constant       : ',StringRefCount(S));
   UniqueString(S);
-  Writeln('Unique         : ',SRefCount(Pointer(S)));
+  Writeln('Unique         : ',StringRefCount(S));
   T:=S;
-  Writeln('After Assign   : ',SRefCount(Pointer(S)));
+  Writeln('After Assign   : ',StringRefCount(S));
   ByVar(S);
   ByConst(S);
   ByVal(S);
   UniqueString(S);
   T:=FunctionResult(S);
-  Writeln('After function : ',SRefCount(Pointer(S)));
+  Writeln('After function : ',StringRefCount(S));
 end.
 \end{verbatim}
 
ref.tex.diff (2,110 bytes)   

Michael Van Canneyt

2021-06-06 08:00

administrator   ~0131175

Last edited: 2021-06-06 08:00

View 2 revisions

Thanks, applied.
When the example was written, the function StringRefCount did not yet exist. Later, I forgot to adapt the example.

Issue History

Date Modified Username Field Change
2021-06-06 02:34 Serge Anvarov New Issue
2021-06-06 02:34 Serge Anvarov Status new => assigned
2021-06-06 02:34 Serge Anvarov Assigned To => Michael Van Canneyt
2021-06-06 02:34 Serge Anvarov File Added: ref.tex.diff
2021-06-06 08:00 Michael Van Canneyt Status assigned => resolved
2021-06-06 08:00 Michael Van Canneyt Resolution open => fixed
2021-06-06 08:00 Michael Van Canneyt Fixed in Version => 3.3.1
2021-06-06 08:00 Michael Van Canneyt Fixed in Revision => 1857
2021-06-06 08:00 Michael Van Canneyt FPCTarget => 4.0.0
2021-06-06 08:00 Michael Van Canneyt Note Added: 0131175
2021-06-06 08:00 Michael Van Canneyt Note Edited: 0131175 View Revisions