[fpc-devel] "Default" discussion for SmartPointers etc

Maciej Izak hnb.code at gmail.com
Tue Jul 26 14:51:12 CEST 2016


Hi,

Finally I have a working implementation (not published yet) of Smart
Pointers/ARC objects and Nullable (Nilable?) types. I think is worth to
discuss a little about new "default modifier" (which is strictly related to
mentioned structures). If needed I can correct details.

As you know (or not) all is based on new modifier - "default" for fields.
Overriding operators like "." or "^" is complicated and not obvious in
Pascal world.

The "default" modifier is inspired by "default" modifier for indexed
properties. All of my work is (I hope so) natural for Pascal language. All
FPC tests pass fine (phew!). The idea is quiet simple:

"If all fails - try to use default field".

Example implementation of SmartPointers and SmartObjects available at:

https://github.com/maciej-izak/PascalSmartPointers (see OUTPUT on the end
of each of file)

Tests (very good way to see how it works. NOTE: I need to add few other
tests for functions with var/const/out, "for in do" loop and for arrays and
indexed properties - help with additional tests is welcome):

https://github.com/maciej-izak/PascalSmartPointers/tree/master/tests

The way how to obtain pointer can be a little confusing for most of Pascal
programmers. Anyway nothing new for Pascal language. In Pascal we have
little known @@ operator to get pointer to variable which handle pointer to
procedure/function. For records with "default field" @ means "get pointer
to default field" and @@ means "get pointer to record".

Any questions and suggestions are welcome!

Side note: as side effect of new feature we can implement very compatible
ARC objects compatible with Delphi without breaking existing code base and
without ugly additions for TObject like:

    function __ObjAddRef: Integer; virtual;
    function __ObjRelease: Integer; virtual;
    property RefCount: Integer read FRefCount;
    procedure DisposeOf; // that can become also part of TObject

All can be delegated into record (record with default field works like
proxy, note: each of method/field/property/operator of record has higher
priority than "default field object"). We can omit easily TComponent
problem for ARC compiler like mentioned here (maybe we can add some hidden
field for TObject similar to hfMonitorOffset from Delphi to point proxy
record for destroy notification - maybe as part of TMonitor):

https://plus.google.com/+DalijaPrasnikar/posts/3CUnrZam6zp (see comments)

more info about DisposeOf:

https://plus.google.com/+HoracioJoseCavalcantiFilho/posts/Nhp7wbHX2hM (see
comments)

-- 
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160726/3e137b02/attachment.html>


More information about the fpc-devel mailing list