[fpc-devel] ref count issue with out param

Florian Klämpfl florian at freepascal.org
Sat Jun 13 16:18:49 CEST 2015


Am 13.06.2015 um 15:09 schrieb Martin Frb:
> On 13/06/2015 09:31, Florian Klämpfl wrote:
>> The only way to prevent this (of course, such a simple case could be detected by the compiler but
>> one can always construct an example which works around this detection), is to turn off the const
>> optimization that const allows the compiler to pass only a reference, but I am pretty sure, people
>> will not be happy about this :)
> 
> Out of curiosity, how would you disguise it from the compiler?

Adding an additional indirection e.g. by a pointer, a class or an array.

> Actually, how would you do that in the example I posted. In your example it is not that hard to
> discuise (but then in your example there is nothing unexpected)
> 
> But in my example it is about refcounting (and pointing to unallocated mem)
> 
>   //procedure Foo2(out a: AnsiString; b: AnsiString);
>   Foo2(s1,s1);
> 
> Foo2 is called with
> 1) the same string for both param
> 2) That string has a ref count of 1 before the call
> 
> How to you disguise it, without incrementing the ref count)

Foo2(a1[i],a2[j])

a1, a2 being dyn. arrays, but sharing data, i and j having the same value.

var p1, p2 : pansistring

Foo2(p1^,p2^);

p1 and p2 pointing to the same data

etc.






More information about the fpc-devel mailing list