[fpc-pascal] Interfaces again (patch for refcount)

ml ml at brainwashers.org
Mon Mar 28 21:37:24 CEST 2005


RefCount isn't handled correctly if guid <> 0, obviously tests were for
guid 0 only (either when I create guid with md5 or specify in interface
type as {C35224FA-ED88-0D1C-A4D2-FCF91AC4C8C6})

// always using same two variables, and notice all possible calls 
// do the same error with counting one too much

  obj := TSomeClass.Create;
  Writeln('ref:', (obj as TInterfacedObject).RefCount); //count=0
  a := obj; aa := (a as IA);
  Writeln('ref:', (obj as TInterfacedObject).RefCount); //count=3
  a := obj; 
  Supports(a, IA, aa);
  obj.GetInterface(IA, aa);
  obj.GetInterface(IA, aa);
  obj.GetInterface(IA, aa);
  Writeln('ref:', (obj as TInterfacedObject).RefCount); //count=7

OUTPUT:
TSomeClass.Create
ref:0
ref:3
ref:7

Just as soon as you apply simple patch (included), everything works like
it should

OUTPUT (after patch):
TSomeClass.Create
ref:0
ref:2
ref:2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: interface_refcount_error.patch
Type: text/x-patch
Size: 1093 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20050328/084bc226/attachment.bin>


More information about the fpc-pascal mailing list