Recent

Author Topic: commctrl.pp bug ?  (Read 1118 times)

440bx

  • Hero Member
  • *****
  • Posts: 3944
commctrl.pp bug ?
« on: May 07, 2022, 07:23:46 pm »
Hello,

I came across this definition of an inline macro that seems "suspicious", it is:
Code: Pascal  [Select][+][-]
  1. // Macro 160
  2. // #define TreeView_GetItemRect(hwnd, hitem, prc, code) \
  3. //     (*(HTREEITEM *)prc = (hitem), (BOOL)SNDMSG((hwnd), TVM_GETITEMRECT, (WPARAM)(code), (LPARAM)(RECT *)(prc)))
  4.  
  5. Function TreeView_GetItemRect( hwnd : hwnd; hitem: HTREEITEM; code : WPARAM; prc : pRECT):BOOL;inline;
  6. Begin
  7.  HTREEITEM(prc):=HITEM;
  8.  Result:=Bool(SendMessage((hwnd), TVM_GETITEMRECT, code, LPARAM(prc)));
  9. end;
  10.  
  11. Function TreeView_GetItemRect( hwnd : hwnd; hitem: HTREEITEM; var prc : TRECT;code : Bool):BOOL;inline;
  12. Begin
  13.  HTREEITEM(Pointer(@prc)^):=HITEM;
  14.  Result:=Bool(SendMessage((hwnd), TVM_GETITEMRECT, WPARAM(code), LPARAM(@prc)));
  15. end;
  16.  
  17.  
Note that "code" (in line 2) is the last parameter in the macro but, in the definition in line 5, the last parameter is "prc" instead of "code".

Also, on line 7, the parameter "prc" is being assigned the value of "hitem" (typed in capitals instead of in lowercase, which can cause confusion.) "prc" should not be set to "hitem" the _contents_ of "prc" should be set to "hitem".  IOW, in like 7, "prc" should be dereferenced to set the _value_ of the rectangle to "hitem" (as is done in line 13)


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: commctrl.pp bug ?
« Reply #1 on: May 07, 2022, 10:16:30 pm »
Ouch, that is long ago, 2003 or so, with FPC 1.1, maybe 1.9. It was done by some heuristic based header translation tool specifically for this header that tried to propagate types back into the macro/inline procedure definition parameter line based on the casts in the sendmessage. Biggest header translation I've ever (manually) done.

I think you are right on both counts, fixed it to follow the original code.

Code: Pascal  [Select][+][-]
  1. Function TreeView_GetItemRect( hwnd : hwnd; hitem: HTREEITEM;  prc : pRECT; code : WPARAM):BOOL;inline;
  2. Begin
  3.  PHTREEITEM(prc)^:=HITEM;
  4.  Result:=Bool(SendMessage((hwnd), TVM_GETITEMRECT, code, LPARAM(prc)));
  5. end;
  6.  

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: commctrl.pp bug ?
« Reply #2 on: May 07, 2022, 11:28:58 pm »
fixed it to follow the original code.
Another bug bites the dust :)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: commctrl.pp bug ?
« Reply #3 on: May 08, 2022, 01:33:20 pm »
Yeah, thanks. It probably will not be the last in that unit, that was quite an involved translation

 

TinyPortal © 2005-2018