[fpc-devel] Initialize/Finalize management operators and Default intrinsic

Sven Barth pascaldragon at googlemail.com
Tue Apr 12 14:33:56 CEST 2016


Am 12.04.2016 12:01 schrieb "Maciej Izak" <hnb.code at gmail.com>:
>
> another way is to introduce attributes for selected language elements in
Delphi compatible way. For example in Delphi we have:
>
>   TCustomAttribute = class(TObject)
>   end;
>   WeakAttribute = class(TCustomAttribute);
>   UnsafeAttribute = class(TCustomAttribute);
>   RefAttribute = class(TCustomAttribute);
>   VolatileAttribute = class(TCustomAttribute);

What I don't like about such a usage of attributes (aside from the syntax,
but that's an orthogonal problem) is that the compiler needs to be made
aware of each and every special attribute... (yes, it also needs to support
each keyword, but in the case of keywords it doesn't have to be somehow
defined in some units as well)
[Note: this is less a "I don't want it", but a "I don't like it"]

>
> Note: these attributes are on my TODO list.

Please don't do anything attribute related until I've merged Joost's class
attributes branch which lays the foundations for the attributes. I've
planned this for after the reintegration of my dynamic packages branch
which is currently WIP (the merge, not the branch ;) )

> To protect our management operators we should declare in System.pp:
>
>   FixedAttribute = class(TCustomAttribute); // or
SystemInitializedAttribute
>
> Now the gSomething from example is declared as:
>
> var
>   [Fixed] gSomething: TSomeType; // fixed can be used only for global
variables and for class var/{$J+} const (aka static var)

That together with your suggestion to force this attribute for records with
management operators might indeed be useful, but there are some problems...
(see below)

> ... that means "don't' [Initialize|Finalize|FillChar|Whatever] this
variable from module but from System.pp (in special table in initialization
section)". Any module may contain special hidden section (if [Fixed]
attribute is detected); that will register all global variables declared
with [Fixed] and any variable with [Fixed] will be excluded from standard
initialization/finalization process. That special all "Fixed Sections" from
all modules should be called before any other initialize/finalize to
register all variables (and before system initialize section ofc, where all
registered fixed variables shall be initialized, and after all ofc
finalized).

The system unit's initialization *must* be run first, otherwise you won't
have a heap or synchronisation primitives or whatever you might need. That
then also extends to units like heaptrc, cmem, cthreads, etc.

Maybe it would be better to initialize such records always *after* *all*
initialization sections have been run... :/ (and deinitialized first)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160412/55888948/attachment.html>


More information about the fpc-devel mailing list