[fpc-pascal] Double finalize

Michael Van Canneyt michael at freepascal.org
Wed Dec 20 19:53:55 CET 2023



On Wed, 20 Dec 2023, Hairy Pixels via fpc-pascal wrote:

> I feel like this was addressed but I couldn't find any references. The program below prints the following:
>
>  Initialize
>  Create
>  Finalize
>  Finalize
>
> Why is Finalize called twice? I thought those were supposed to be called in pairs with initialize?

If you look at the generated code, you see that there is an implicit try/finally block
and the  finally block does a finalize.

         call    fpc_pushexceptaddr
         movq    %rax,%rdi
         call    fpc_setjmp
         movl    %eax,-92(%rbp)
         cmpl    $0,%eax
         jne     .Lj10
         leaq    -96(%rbp),%rdi
         call    P$TEST$_$TMANAGEDOBJECT_$__$$_CREATE$$TMANAGEDOBJECT
         movq    $INIT_$P$TEST_$$_TMANAGEDOBJECT,%rsi
         leaq    -96(%rbp),%rdi
         call    fpc_finalize
.Lj10:
         call    fpc_popaddrstack
         movq    $INIT_$P$TEST_$$_TMANAGEDOBJECT,%rsi
         leaq    -96(%rbp),%rdi
         call    fpc_finalize
         movl    -92(%rbp),%eax


Michael.


More information about the fpc-pascal mailing list