[fpc-devel] Initialize/Finalize management operators and Default intrinsic
Maciej Izak
hnb.code at gmail.com
Mon Apr 11 15:27:32 CEST 2016
2016-04-11 14:38 GMT+02:00 Sven Barth <pascaldragon at googlemail.com>:
> There is another problem that occurred to.me after my previous mail. Have
> you ever heard of the "static initialization order fiasco"? I've stumbled
> upon that a few weeks ago at work with C++ and was glad that we don't have
> that problem in Pascal, but with the new management operators and the need
> to have global variables be initialized correctly as well this would change
> - which would be very bad as this is a hard to debug problem.
>
Even worse, currently is possible to achieve some similar... I've
experienced from another side - "static finalization order fiasco" for
Generics.Collections (fixed 24 Dec 2015
https://github.com/dathox/generics.collections/commit/fda586932bd80ef58c08f8ebf5a24316ca4ccca5
).
I can confirm that "static initialization/finalization order fiasco" bugs
are really hard to debug. In my case for Generics.Collections was something
like this (maybe not the same but very similar):
=== X ===
program X;
uses
UnitA, ..., UnitZ, GC, Generics.Collections, Unit1;
...
=== GC ===
...
interface
var
G: Contnrs.TObjectList;
implementation
...
initialization
G := Contnrs.TObjectList.Create(True);
finalization
G.Free; // !!!
end.
=== Unit1 ===
... somewhere in code ...
var
d: TDictionary<string, string>;
begin
d := TDictionary<string, string>.Create;
G.Add(d);
=== END CODE ===
at line marked by "!!!" was memory corruption, because any of manual
interface used by dictionary was already destroyed in static/class
destructor in Generics.Defaults... Really hard to find that kind of bug.
What was funny the corruption was visible only on android... Anyway bug is
fixed :)
> I'll provide you with an example when I'm back home again in the evening.
>
> > Sven, could you look at topic "Management operators AddRef and Copy vs
> Copy" thread? New operators are ready for test in branch, anyway we can
> adjust the naming of AddRef and Copy. Florian proposed "Clone" (instead of
> Copy) and "Copy" (instead of AddRef).
>
> I've yet to find a quiet minute to digest that one :P
>
Ok! Thanks. I'm looking forward :P
--
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160411/f9ced169/attachment.html>
More information about the fpc-devel
mailing list