View Issue Details

IDProjectCategoryView StatusLast Update
0035305FPCRTLpublic2019-04-01 19:37
ReporterOndrej PokornyAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1Product Build 
Target Version3.2.0Fixed in Version3.3.1 
Summary0035305: Lazy initialization of ClassAliasList within classes.inc
DescriptionCurrently ClassAliasList is initialized at every FPC program start.

This unfortunately means that also TEncoding.Default is initialized - that means that TEncoding.Default cannot be changed afterwards in user-code (see 0032961).

The solution is to initialize it when it is needed - and so allow TEncoding.Default to be set after DefaultSystemCodePage.
Additional InformationPatch is attached.

(The patch includes the change from 0035304 as well because they are in the same function. You should apply 0035304 first, if you decide so.)
TagsNo tags attached.
Fixed in Revision41819
FPCOldBugId
FPCTarget
Attached Files
  • Lazy-ClassAliasList-01.patch (1,839 bytes)
    Index: rtl/objpas/classes/classes.inc
    ===================================================================
    --- rtl/objpas/classes/classes.inc	(revision 41802)
    +++ rtl/objpas/classes/classes.inc	(working copy)
    @@ -2496,7 +2496,7 @@
       FindGlobalComponentList:=nil;
       IntConstList := TThreadList.Create;
       ClassList := TThreadList.Create;
    -  ClassAliasList := TStringList.Create;
    +  ClassAliasList := nil;
       { on unix this maps to a simple rw synchornizer }
       GlobalNameSpace := TMultiReadExclusiveWriteSynchronizer.Create;
       RegisterInitComponentHandler(TComponent,@DefaultInitHandler);
    Index: rtl/objpas/classes/cregist.inc
    ===================================================================
    --- rtl/objpas/classes/cregist.inc	(revision 41802)
    +++ rtl/objpas/classes/cregist.inc	(working copy)
    @@ -44,9 +44,16 @@
       var
         I : integer;
       begin
    -    i := ClassAliasList.IndexOf(Alias);
    -    if I = -1 then
    -      ClassAliasList.AddObject( Alias, TObject(AClass) );
    +    ClassList.LockList;
    +    try
    +      if ClassAliasList=nil then
    +        ClassAliasList := TStringList.Create;
    +      i := ClassAliasList.IndexOf(Alias);
    +      if I = -1 then
    +        ClassAliasList.AddObject( Alias, TObject(AClass) );
    +    finally
    +      ClassList.UnlockList;
    +    end;
       end;
     
     
    @@ -96,6 +103,8 @@
             Result := TPersistentClass(Items[I]);
             if Result.ClassNameIs(AClassName) then Exit;
            end;
    +    if Assigned(ClassAliasList) then
    +       begin
            I := ClassAliasList.Indexof(AClassName);
            if I >= 0 then  //found
               Begin
    @@ -102,10 +111,11 @@
               Result := TPersistentClass(ClassAliasList.Objects[i]);
               exit;
               end;
    +       end;
            Result := nil;
    -    finally
    -      ClassList.Unlocklist;
    -    end;
    +   finally
    +     ClassList.Unlocklist;
    +   end;
     end;
     
     
    

Activities

Ondrej Pokorny

2019-04-01 16:50

reporter  

Lazy-ClassAliasList-01.patch (1,839 bytes)
Index: rtl/objpas/classes/classes.inc
===================================================================
--- rtl/objpas/classes/classes.inc	(revision 41802)
+++ rtl/objpas/classes/classes.inc	(working copy)
@@ -2496,7 +2496,7 @@
   FindGlobalComponentList:=nil;
   IntConstList := TThreadList.Create;
   ClassList := TThreadList.Create;
-  ClassAliasList := TStringList.Create;
+  ClassAliasList := nil;
   { on unix this maps to a simple rw synchornizer }
   GlobalNameSpace := TMultiReadExclusiveWriteSynchronizer.Create;
   RegisterInitComponentHandler(TComponent,@DefaultInitHandler);
Index: rtl/objpas/classes/cregist.inc
===================================================================
--- rtl/objpas/classes/cregist.inc	(revision 41802)
+++ rtl/objpas/classes/cregist.inc	(working copy)
@@ -44,9 +44,16 @@
   var
     I : integer;
   begin
-    i := ClassAliasList.IndexOf(Alias);
-    if I = -1 then
-      ClassAliasList.AddObject( Alias, TObject(AClass) );
+    ClassList.LockList;
+    try
+      if ClassAliasList=nil then
+        ClassAliasList := TStringList.Create;
+      i := ClassAliasList.IndexOf(Alias);
+      if I = -1 then
+        ClassAliasList.AddObject( Alias, TObject(AClass) );
+    finally
+      ClassList.UnlockList;
+    end;
   end;
 
 
@@ -96,6 +103,8 @@
         Result := TPersistentClass(Items[I]);
         if Result.ClassNameIs(AClassName) then Exit;
        end;
+    if Assigned(ClassAliasList) then
+       begin
        I := ClassAliasList.Indexof(AClassName);
        if I >= 0 then  //found
           Begin
@@ -102,10 +111,11 @@
           Result := TPersistentClass(ClassAliasList.Objects[i]);
           exit;
           end;
+       end;
        Result := nil;
-    finally
-      ClassList.Unlocklist;
-    end;
+   finally
+     ClassList.Unlocklist;
+   end;
 end;
 
 

Michael Van Canneyt

2019-04-01 19:31

administrator   ~0115172

Applied, thank you very much !

Ondrej Pokorny

2019-04-01 19:37

reporter   ~0115173

Thank you!

Issue History

Date Modified Username Field Change
2019-04-01 16:50 Ondrej Pokorny New Issue
2019-04-01 16:50 Ondrej Pokorny File Added: Lazy-ClassAliasList-01.patch
2019-04-01 17:01 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-04-01 17:01 Michael Van Canneyt Status new => assigned
2019-04-01 19:31 Michael Van Canneyt Fixed in Revision => 41819
2019-04-01 19:31 Michael Van Canneyt Note Added: 0115172
2019-04-01 19:31 Michael Van Canneyt Status assigned => resolved
2019-04-01 19:31 Michael Van Canneyt Fixed in Version => 3.3.1
2019-04-01 19:31 Michael Van Canneyt Resolution open => fixed
2019-04-01 19:31 Michael Van Canneyt Target Version => 3.2.0
2019-04-01 19:37 Ondrej Pokorny Note Added: 0115173
2019-04-01 19:37 Ondrej Pokorny Status resolved => closed