From d3ded54ae076ca09e8c264311e16e7fcf808f024 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sat, 23 Dec 2006 14:03:43 +0000 Subject: [PATCH] * temporarily turn off self and vmt checking after calling AfterConstruction, since self may no longer be valid afterwards (the instance may already have freed itself, e.g. in case of a TThread with FreeOnTerminate=true) git-svn-id: trunk@5689 - --- compiler/psub.pas | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/compiler/psub.pas b/compiler/psub.pas index dc6e98b93d..3ad93511f4 100644 --- a/compiler/psub.pas +++ b/compiler/psub.pas @@ -362,11 +362,19 @@ implementation srsym : tsym; para : tcallparanode; newstatement : tstatementnode; + oldlocalswitches: tlocalswitches; begin result:=internalstatements(newstatement); if assigned(current_procinfo.procdef._class) 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]; { maybe call AfterConstruction for classes } if (current_procinfo.procdef.proctypeoption=potype_constructor) and is_class(current_procinfo.procdef._class) then @@ -444,6 +452,7 @@ implementation else internalerror(200305105); end; + current_settings.localswitches:=oldlocalswitches; end; end; @@ -452,6 +461,7 @@ implementation var pd : tprocdef; newstatement : tstatementnode; + oldlocalswitches: tlocalswitches; begin generate_except_block:=internalstatements(newstatement); @@ -460,6 +470,10 @@ implementation if assigned(current_procinfo.procdef._class) and (current_procinfo.procdef.proctypeoption=potype_constructor) then begin + { Don't test self and the vmt here. See generate_bodyexit_block } + { why (JM) } + oldlocalswitches:=current_settings.localswitches; + current_settings.localswitches:=oldlocalswitches-[cs_check_object,cs_check_range]; pd:=current_procinfo.procdef._class.Finddestructor; if assigned(pd) then begin @@ -471,6 +485,7 @@ implementation ccallnode.create(nil,tprocsym(pd.procsym),pd.procsym.owner,load_self_node,[]), nil)); end; + current_settings.localswitches:=oldlocalswitches; end else begin