View Issue Details

IDProjectCategoryView StatusLast Update
0035104FPCFCLpublic2019-07-12 21:04
ReporterSerge AnvarovAssigned ToJoost van der Sluis 
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Product VersionProduct Build 
Target VersionFixed in Version 
Summary0035104: TRegistry. Patch 5. Repeted code raising SInvalidRegType
DescriptionException SInvalidRegType raise in several places. Raising exception generates a lot of code, in addition, it also repeated.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files
  • registry5.diff (2,196 bytes)
    Index: packages/fcl-registry/src/registry.pp
    ===================================================================
    --- packages/fcl-registry/src/registry.pp	(revision 41343)
    +++ packages/fcl-registry/src/registry.pp	(working copy)
    @@ -235,6 +235,10 @@
         Generic, implementation-independent code.
       ---------------------------------------------------------------------}
     
    +procedure RaiseInvalidRegTypeException(const AName: string); noreturn;
    +begin
    +  raise ERegistryException.CreateFmt(SInvalidRegType, [AName]) at get_caller_addr(get_frame);
    +end;
     
     constructor TRegistry.Create;
     
    @@ -334,7 +338,7 @@
     begin
       Result := GetData(Name, @Buffer, BufSize, RegDataType);
       If not (RegDataType in [rdBinary, rdUnknown]) Then
    -    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
    +    RaiseInvalidRegTypeException(Name);
     end;
     
     function TRegistry.ReadInteger(const Name: string): Integer;
    @@ -345,7 +349,7 @@
     begin
       GetData(Name, @Result, SizeOf(Integer), RegDataType);
       If RegDataType<>rdInteger Then
    -    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
    +    RaiseInvalidRegTypeException(Name);
     end;
     
     function TRegistry.ReadInt64(const Name: string): Int64;
    @@ -356,7 +360,7 @@
     begin
       GetData(Name, @Result, SizeOf(Int64), RegDataType);
       If RegDataType<>rdInt64 Then
    -    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
    +    RaiseInvalidRegTypeException(Name);
     end;
     
     function TRegistry.ReadBool(const Name: string): Boolean;
    @@ -407,7 +411,7 @@
       if info.datasize>0 then
       begin
         if Not (Info.RegData in [rdString,rdExpandString]) then
    -      Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
    +      RaiseInvalidRegTypeException(Name);
         if Odd(Info.DataSize) then
           SetLength(u,round((Info.DataSize+1)/SizeOf(UnicodeChar)))
         else
    @@ -439,7 +443,7 @@
       if info.datasize>0 then
         begin
          If Not (Info.RegData in [rdMultiString]) then
    -       Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
    +       RaiseInvalidRegTypeException(Name);
          SetLength(Data,Info.DataSize);
          ReadDataSize := GetData(Name,PChar(Data),Info.DataSize,Info.RegData);
          if ReadDataSize > 0 then
    
    registry5.diff (2,196 bytes)
  • registry5.1.diff (2,180 bytes)
    Index: packages/fcl-registry/src/registry.pp
    ===================================================================
    --- packages/fcl-registry/src/registry.pp	(revision 42351)
    +++ packages/fcl-registry/src/registry.pp	(working copy)
    @@ -305,6 +305,11 @@
     end;
     {$endif}
     
    +procedure RaiseInvalidRegTypeException(const AName: UnicodeString); noreturn;
    +begin
    +  raise ERegistryException.CreateFmt(SInvalidRegType, [AName]) at get_caller_addr(get_frame);
    +end
    +
     constructor TRegistry.Create;
     
     begin
    @@ -478,7 +483,7 @@
     begin
       Result := GetData(Name, @Buffer, BufSize, RegDataType);
       If not (RegDataType in [rdBinary, rdUnknown]) Then
    -    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
    +    RaiseInvalidRegTypeException(Name);
     end;
     
     function TRegistry.ReadBinaryData(const Name: String; var Buffer;
    @@ -495,7 +500,7 @@
     begin
       GetData(Name, @Result, SizeOf(Integer), RegDataType);
       If RegDataType<>rdInteger Then
    -    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
    +    RaiseInvalidRegTypeException(Name);
     end;
     
     function TRegistry.ReadInteger(const Name: String): Integer;
    @@ -511,7 +516,7 @@
     begin
       GetData(Name, @Result, SizeOf(Int64), RegDataType);
       If RegDataType<>rdInt64 Then
    -    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
    +    RaiseInvalidRegTypeException(Name);
     end;
     
     function TRegistry.ReadInt64(const Name: String): Int64;
    @@ -592,7 +597,7 @@
       if info.datasize>0 then
       begin
         if Not (Info.RegData in [rdString,rdExpandString]) then
    -      Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
    +      RaiseInvalidRegTypeException(Name);
         if Odd(Info.DataSize) then
           SetLength(u,round((Info.DataSize+1)/SizeOf(UnicodeChar)))
         else
    @@ -709,7 +714,7 @@
       if info.datasize>0 then
         begin
          If Not (Info.RegData in [rdMultiString]) then
    -       Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
    +       RaiseInvalidRegTypeException(Name);
          SetLength(Data,Info.DataSize);
          ReadDataSize := GetData(Name,PWideChar(Data),Info.DataSize,Info.RegData) div SizeOf(WideChar);
          //writeln('TRegistry.ReadStringArray: ReadDataSize=',ReadDataSize);
    
    registry5.1.diff (2,180 bytes)

Activities

Serge Anvarov

2019-02-16 20:43

reporter  

registry5.diff (2,196 bytes)
Index: packages/fcl-registry/src/registry.pp
===================================================================
--- packages/fcl-registry/src/registry.pp	(revision 41343)
+++ packages/fcl-registry/src/registry.pp	(working copy)
@@ -235,6 +235,10 @@
     Generic, implementation-independent code.
   ---------------------------------------------------------------------}
 
+procedure RaiseInvalidRegTypeException(const AName: string); noreturn;
+begin
+  raise ERegistryException.CreateFmt(SInvalidRegType, [AName]) at get_caller_addr(get_frame);
+end;
 
 constructor TRegistry.Create;
 
@@ -334,7 +338,7 @@
 begin
   Result := GetData(Name, @Buffer, BufSize, RegDataType);
   If not (RegDataType in [rdBinary, rdUnknown]) Then
-    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
+    RaiseInvalidRegTypeException(Name);
 end;
 
 function TRegistry.ReadInteger(const Name: string): Integer;
@@ -345,7 +349,7 @@
 begin
   GetData(Name, @Result, SizeOf(Integer), RegDataType);
   If RegDataType<>rdInteger Then
-    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
+    RaiseInvalidRegTypeException(Name);
 end;
 
 function TRegistry.ReadInt64(const Name: string): Int64;
@@ -356,7 +360,7 @@
 begin
   GetData(Name, @Result, SizeOf(Int64), RegDataType);
   If RegDataType<>rdInt64 Then
-    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
+    RaiseInvalidRegTypeException(Name);
 end;
 
 function TRegistry.ReadBool(const Name: string): Boolean;
@@ -407,7 +411,7 @@
   if info.datasize>0 then
   begin
     if Not (Info.RegData in [rdString,rdExpandString]) then
-      Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
+      RaiseInvalidRegTypeException(Name);
     if Odd(Info.DataSize) then
       SetLength(u,round((Info.DataSize+1)/SizeOf(UnicodeChar)))
     else
@@ -439,7 +443,7 @@
   if info.datasize>0 then
     begin
      If Not (Info.RegData in [rdMultiString]) then
-       Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
+       RaiseInvalidRegTypeException(Name);
      SetLength(Data,Info.DataSize);
      ReadDataSize := GetData(Name,PChar(Data),Info.DataSize,Info.RegData);
      if ReadDataSize > 0 then
registry5.diff (2,196 bytes)

Serge Anvarov

2019-04-10 07:13

reporter   ~0115371

Revision 60900. The patch is still actual.

Bart Broersma

2019-07-12 11:39

reporter   ~0117213

@Serge: shouldn't this be in implemented the methods with UnicodeString parameters?

Serge Anvarov

2019-07-12 21:04

reporter   ~0117230

Here you are

registry5.1.diff (2,180 bytes)
Index: packages/fcl-registry/src/registry.pp
===================================================================
--- packages/fcl-registry/src/registry.pp	(revision 42351)
+++ packages/fcl-registry/src/registry.pp	(working copy)
@@ -305,6 +305,11 @@
 end;
 {$endif}
 
+procedure RaiseInvalidRegTypeException(const AName: UnicodeString); noreturn;
+begin
+  raise ERegistryException.CreateFmt(SInvalidRegType, [AName]) at get_caller_addr(get_frame);
+end
+
 constructor TRegistry.Create;
 
 begin
@@ -478,7 +483,7 @@
 begin
   Result := GetData(Name, @Buffer, BufSize, RegDataType);
   If not (RegDataType in [rdBinary, rdUnknown]) Then
-    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
+    RaiseInvalidRegTypeException(Name);
 end;
 
 function TRegistry.ReadBinaryData(const Name: String; var Buffer;
@@ -495,7 +500,7 @@
 begin
   GetData(Name, @Result, SizeOf(Integer), RegDataType);
   If RegDataType<>rdInteger Then
-    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
+    RaiseInvalidRegTypeException(Name);
 end;
 
 function TRegistry.ReadInteger(const Name: String): Integer;
@@ -511,7 +516,7 @@
 begin
   GetData(Name, @Result, SizeOf(Int64), RegDataType);
   If RegDataType<>rdInt64 Then
-    Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
+    RaiseInvalidRegTypeException(Name);
 end;
 
 function TRegistry.ReadInt64(const Name: String): Int64;
@@ -592,7 +597,7 @@
   if info.datasize>0 then
   begin
     if Not (Info.RegData in [rdString,rdExpandString]) then
-      Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
+      RaiseInvalidRegTypeException(Name);
     if Odd(Info.DataSize) then
       SetLength(u,round((Info.DataSize+1)/SizeOf(UnicodeChar)))
     else
@@ -709,7 +714,7 @@
   if info.datasize>0 then
     begin
      If Not (Info.RegData in [rdMultiString]) then
-       Raise ERegistryException.CreateFmt(SInvalidRegType, [Name]);
+       RaiseInvalidRegTypeException(Name);
      SetLength(Data,Info.DataSize);
      ReadDataSize := GetData(Name,PWideChar(Data),Info.DataSize,Info.RegData) div SizeOf(WideChar);
      //writeln('TRegistry.ReadStringArray: ReadDataSize=',ReadDataSize);
registry5.1.diff (2,180 bytes)

Issue History

Date Modified Username Field Change
2019-02-16 20:43 Serge Anvarov New Issue
2019-02-16 20:43 Serge Anvarov File Added: registry5.diff
2019-02-17 22:10 Joost van der Sluis Assigned To => Joost van der Sluis
2019-02-17 22:10 Joost van der Sluis Status new => assigned
2019-04-10 07:13 Serge Anvarov Note Added: 0115371
2019-07-12 11:39 Bart Broersma Note Added: 0117213
2019-07-12 21:04 Serge Anvarov File Added: registry5.1.diff
2019-07-12 21:04 Serge Anvarov Note Added: 0117230