Forum > FPC development

[CLOSED] Code cleanup at function GetInterfaceProp

(1/2) > >>

lagprogramming:
rtl/objpas/typinfo.pp has function GetInterfaceProp(Instance: TObject; PropInfo: PPropInfo): IInterface;

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function GetInterfaceProp(Instance: TObject; PropInfo: PPropInfo): IInterface;type  TGetInterfaceProc=function:IInterface of object;  TGetInterfaceProcIndex=function(index:longint):IInterface of object;var  AMethod : TMethod;begin  Result:=nil;  case (PropInfo^.PropProcs) and 3 of    ptField:      Result:=IInterface(PPointer(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^);    ptStatic,    ptVirtual:      begin        if (PropInfo^.PropProcs and 3)=ptStatic then          AMethod.Code:=PropInfo^.GetProc        else          AMethod.Code:=PCodePointer(Pointer(Instance.ClassType)+PtrUInt(PropInfo^.GetProc))^;        AMethod.Data:=Instance;        if ((PropInfo^.PropProcs shr 6) and 1)<>0 then          Result:=TGetInterfaceProcIndex(AMethod)(PropInfo^.Index)        else          Result:=TGetInterfaceProc(AMethod)();      end;  else    raise EPropertyError.CreateFmt(SErrCannotReadProperty, [PropInfo^.Name]);  end;end;The following patch removes the initial "Result:=nil;" line. If the patch is accepted, regarding result assignments, the patch will make the function look closer to other functions in the same file like Function IsStoredProp(Instance : TObject;PropInfo : PPropInfo) : Boolean; or Function GetPointerProp(Instance: TObject; PropInfo : PPropInfo): Pointer;.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---diff --git a/rtl/objpas/typinfo.pp b/rtl/objpas/typinfo.ppindex da6a889b08..7ffaefc081 100644--- a/rtl/objpas/typinfo.pp+++ b/rtl/objpas/typinfo.pp@@ -2302,7 +2302,6 @@ function GetInterfaceProp(Instance: TObject; PropInfo: PPropInfo): IInterface; var   AMethod : TMethod; begin-  Result:=nil;   case (PropInfo^.PropProcs) and 3 of     ptField:       Result:=IInterface(PPointer(Pointer(Instance)+PtrUInt(PropInfo^.GetProc))^);

AlexTP:
Posted on bugtracker
https://gitlab.com/freepascal.org/fpc/source/-/issues/40249

lagprogramming:
https://gitlab.com/freepascal.org/fpc/source/-/commit/f6a8b045c2f52740186feca3d50c3211c74c775c
https://gitlab.com/freepascal.org/fpc/source/-/commit/abb7aebaba5721512c3d16857c78781c60259e66
https://gitlab.com/freepascal.org/fpc/source/-/commit/d7d65fe0d7b62c61f4751b896eb6ab9271d03a0c
::) :-X  :-\   :-[
https://gitlab.com/freepascal.org/fpc/source/-/issues/40249

wp:
What's wrong with clearly assigning a result to a function? Even if the assignment is unnecessary it improves readability of the code. I agree with Michael's decision not to apply this.

PascalDragon:

--- Quote from: lagprogramming on April 25, 2023, 10:23:49 am ---https://gitlab.com/freepascal.org/fpc/source/-/commit/f6a8b045c2f52740186feca3d50c3211c74c775c
https://gitlab.com/freepascal.org/fpc/source/-/commit/abb7aebaba5721512c3d16857c78781c60259e66
https://gitlab.com/freepascal.org/fpc/source/-/commit/d7d65fe0d7b62c61f4751b896eb6ab9271d03a0c
--- End quote ---
Is there a reason you mention these commits in relation to that issue?

Navigation

[0] Message Index

[#] Next page

Go to full version