[fpc-pascal] Sigsegv with refcounting interface

Joao Morais jcmoraisjr at gmail.com
Sat Mar 9 02:37:24 CET 2013


On Fri, Mar 8, 2013 at 4:09 PM, Flávio Etrusco <flavio.etrusco at gmail.com> wrote:
>
>> procedure addintf(const aintf: IUnknown);
>> (...)
>>     addintf(TInterfacedObject.Create);
>> (...)
>
> It's a pity, but I don't know whether it's fixable (or if needs to be
> "fixed") in the compiler.

Works in Delphi 7 with FastMM4.

> The TInterfacedObject has RefCount = 0 after construction, so you
> should always to assign it to a variable.
> In a sense a RefCounted object only exists while someone has a
> reference to it, so in that case the object non-existant ;-)

Correct. I am using an interface reference -- in the indexOf() method
in my sample -- before its "definitive persistence" as an intflist
member, and without a "real" variable that holds the instance alive
because of the const parameter.

You are suggesting that this unlikely coincidente which causes a
sigsegv should be the programmer's responsibility. No thanks, I much
more prefer the Delphi compatibility =)

Joao Morais



More information about the fpc-pascal mailing list