diff --git a/compiler/pmodules.pas b/compiler/pmodules.pas index ea643db82b..e042780935 100644 --- a/compiler/pmodules.pas +++ b/compiler/pmodules.pas @@ -1209,7 +1209,7 @@ implementation if not current_module.interface_only and (token=_FINALIZATION) then begin { set module options } - current_module.flags:=current_module.flags or uf_finalize; + // current_module.flags:=current_module.flags or uf_finalize; { Compile the finalize } finalize_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,current_module.localsymtable); @@ -2138,7 +2138,7 @@ implementation if token=_FINALIZATION then begin { set module options } - current_module.flags:=current_module.flags or uf_finalize; + //current_module.flags:=current_module.flags or uf_finalize; { Parse the finalize } finalize_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,current_module.localsymtable); finalize_procinfo.procdef.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,'')); diff --git a/compiler/psub.pas b/compiler/psub.pas index 593044532e..f3ce252b35 100644 --- a/compiler/psub.pas +++ b/compiler/psub.pas @@ -207,21 +207,29 @@ implementation begin { The library init code is already called and does not need to be in the initfinal table (PFV) } - if not islibrary then - current_module.flags:=current_module.flags or uf_init; block:=statement_block(_INITIALIZATION); - end - else if (token=_FINALIZATION) then - begin - if (current_module.flags and uf_finalize)<>0 then - block:=statement_block(_FINALIZATION) + { optimize empty initialization block away } + if (tstatementnode(block).left=nil) then + FreeAndNil(block) else - begin - { can we allow no INITIALIZATION for DLL ?? - I think it should work PM } - block:=nil; - exit; - end; + if not islibrary then + current_module.flags:=current_module.flags or uf_init; + end + else if token=_FINALIZATION then + begin + { when a unit has only a finalization section, we can come to this + point when we try to read the nonh existing initalization section + so we've to check if we are really try to parse the finalization } + if current_procinfo.procdef.proctypeoption=potype_unitfinalize then + begin + block:=statement_block(_FINALIZATION); + { optimize empty finalization block away } + if (tstatementnode(block).left=nil) then + FreeAndNil(block) + else + if not islibrary then + current_module.flags:=current_module.flags or uf_finalize; + end; end else begin