Re: [fpc-pascal] Using Supports() I got an AV... bug?
I only added {$mode objfpc} to be able compile, so I test this code: program Project1; {$mode objfpc} uses SysUtils; type IBar = interface ['{C22FB8F4-1EC6-42C4-81E4-F2A52CC52258}'] function Name: string; end; TBar = class(TInterfacedObject, IBar) public function Name: string; end; { TBar } function TBar.Name: string; begin Result := ClassName; end; var Bar: TBar; begin Bar := TBar.Create; try if Supports(Bar, IBar) then Writeln('Bar supports...'); finally //FreeAndNil(Bar); end; end. My FPC is also 3.0.4, on 64-bit Linux. Compiled with -gh I have no memory leak since this demo is about COM interfaces. V. __ Od: "Marcos Douglas B. Santos" Komu: FPC-Pascal users discussions Datum: 11.03.2018 16:17 Předmět: Re: [fpc-pascal] Using Supports() I got an AV... bug? On Sun, Mar 11, 2018 at 11:51 AM, Vojtěch Čihák wrote: > With this modification and -gh it is alright: > Only if you declare `Bar` as `IBar` instead of `TBar`. Please, check your code again. Regards, Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal <http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal> ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Using Supports() I got an AV... bug?
On Sun, Mar 11, 2018 at 11:51 AM, Vojtěch Čihák wrote: > With this modification and -gh it is alright: > Only if you declare `Bar` as `IBar` instead of `TBar`. Please, check your code again. Regards, Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Using Supports() I got an AV... bug?
Not here. I'm using FPC 3.0.4. I've took a look at EMB documentation: http://docwiki.embarcadero.com/Libraries/XE2/en/System.SysUtils.Supports Take a look at "Warning" section. That's the problem. Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Using Supports() I got an AV... bug?
With this modification and -gh it is alright: [v1@nb-msi Interface]$ ./test Bar supports... Heap dump by heaptrc unit 7 memory blocks allocated : 875/880 7 memory blocks freed : 875/880 0 unfreed memory blocks : 0 True heap size : 360448 True free heap : 360448 [v1@nb-msi Interface]$ V. __ > Od: "Marcos Douglas B. Santos" > Komu: FPC-Pascal users discussions > Datum: 11.03.2018 15:36 > Předmět: Re: [fpc-pascal] Using Supports() I got an AV... bug? > ===begin=== Bar := TBar.Create; try if Supports(Bar, IBar) then Writeln(Bar.Name + ' supports...'); finally Bar.Free; << no Free end; ===end=== Are you still seeing an AV? Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal <http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal> ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Using Supports() I got an AV... bug?
On Sun, Mar 11, 2018 at 11:17 AM, Vojtěch Čihák wrote: > Yes, TBar is TInterfacedObject and is reference counted therefore Free is > not needed. > > Just comment the line //Bar.Free; compile with -gh and you will see no > memory leak. You think this is the problem... All right, try to change your copy like this: ===begin=== Bar := TBar.Create; try if Supports(Bar, IBar) then Writeln(Bar.Name + ' supports...'); finally Bar.Free; << no Free end; ===end=== Are you still seeing an AV? Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Using Supports() I got an AV... bug?
Yes, TBar is TInterfacedObject and is reference counted therefore Free is not needed. Just comment the line //Bar.Free; compile with -gh and you will see no memory leak. V. __ Od: "Marcos Douglas B. Santos" Komu: FPC-Pascal users discussions Datum: 11.03.2018 14:57 Předmět: Re: [fpc-pascal] Using Supports() I got an AV... bug? On Sun, Mar 11, 2018 at 10:52 AM, Vojtěch Čihák wrote: > > Hi, > > Bar shoud be released by Interface, no need to call Free. I'm sorry, but `Bar` was defined as `Bar: TBar` so, it's a class not an interface. Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal <http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal> ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Using Supports() I got an AV... bug?
On Sun, Mar 11, 2018 at 10:52 AM, Vojtěch Čihák wrote: > > Hi, > > Bar shoud be released by Interface, no need to call Free. I'm sorry, but `Bar` was defined as `Bar: TBar` so, it's a class not an interface. Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Using Supports() I got an AV... bug?
Hi, Bar shoud be released by Interface, no need to call Free. V. __ Od: "Marcos Douglas B. Santos" Komu: FPC-Pascal users discussions Datum: 11.03.2018 14:23 Předmět: [fpc-pascal] Using Supports() I got an AV... bug? The code below should work but I get an AV when the program calls `Bar.Free`.Do you know why?Lazarus 1.8.1 r57299 FPC 3.0.4 i386-win32-win32/win64...Regards,Marcos Douglas -- ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal <http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal> ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Using Supports() I got an AV... bug?
The code below should work but I get an AV when the program calls `Bar.Free`. Do you know why? Lazarus 1.8.1 r57299 FPC 3.0.4 i386-win32-win32/win64 ===begin=== program Project1; uses SysUtils; type IBar = interface ['{C22FB8F4-1EC6-42C4-81E4-F2A52CC52258}'] function Name: string; end; TBar = class(TInterfacedObject, IBar) public function Name: string; end; { TBar } function TBar.Name: string; begin Result := ClassName; end; var Bar: TBar; begin Bar := TBar.Create; try if Supports(Bar, IBar) then Writeln('Bar supports...'); finally Bar.Free; end; end. ===end=== Regards, Marcos Douglas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal