[fpc-devel] FreeInstance
Sven Barth
pascaldragon at googlemail.com
Wed Aug 1 23:28:12 CEST 2018
Ryan Joseph <ryan at thealchemistguild.com> schrieb am Mi., 1. Aug. 2018,
17:28:
>
>
> > On Aug 1, 2018, at 9:17 AM, Sven Barth via fpc-devel <
> fpc-devel at lists.freepascal.org> wrote:
> >
> > Search the compiler's source for the string 'FREEINSTANCE'; you'll find
> two locations, one in ngenutil and one in psub. The latter is the one you
> want.
> >
>
> Yeah, this is the first place I looked but current_structdef is always nil
> so it never progresses past that point.
>
> Is this test program not enough to get FreeInstance called?
>
> program test;
> var
> obj1: TObject;
> begin
> obj1 := TObject.Create;
> obj1.Free;
> end.
>
>
> ===========
>
> function generate_bodyexit_block:tnode;
> var
> srsym : tsym;
> para : tcallparanode;
> newstatement : tstatementnode;
> oldlocalswitches: tlocalswitches;
> begin
> result:=internalstatements(newstatement);
>
> if assigned(current_structdef) then
> begin
> { Don't test self and the vmt here. The reason is that }
> { a constructor already checks whether these are valid }
> { before. Further, in case of TThread the thread may }
> { free the class instance right after AfterConstruction }
> { has been called, so it may no longer be valid (JM) }
> oldlocalswitches:=current_settings.localswitches;
>
> current_settings.localswitches:=oldlocalswitches-[cs_check_object,cs_check_range];
>
> { a destructor needs a help procedure }
> if (current_procinfo.procdef.proctypeoption=potype_destructor)
> then
> begin
> if is_class(current_structdef) then
> begin
>
> srsym:=search_struct_member(current_structdef,'FREEINSTANCE');
>
If you'd look at the code you quoted you'd see that this is only inserted
*inside* a destructor (the check for potype_destructor; current_procinfo is
the currently compiled routine). So, no, your code is not enough. You need
to declare a class with a destructor, then the code would be entered.
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180801/f846bf0e/attachment.html>
More information about the fpc-devel
mailing list