[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: atexit from libc causes unexpected program termination
From: |
Gaius Mulley |
Subject: |
Re: atexit from libc causes unexpected program termination |
Date: |
Fri, 01 Mar 2024 22:22:27 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
Rudolf Schubert <rudolf@muc.de> writes:
> Hi,
>
> I'm trying to register a PROCEDURE with atexit from libc but
> it does not work. Please see example code appended. Did I
> miss something?
>
>
> Thanks
>
> Rudolf
Hi Rudolf,
ah interesting - I think it better to use the
InstallTerminationProcedure procedure function from M2RTS. In the
original code the procedure P2 is called but at this point all the m2 io
libraries have executed their finalisation sections (and the call to
WriteString causes an exception), whereas the module M2RTS alternative
will insert its own cleanup calls prior to the finialisation calls of
each module. So the code could be modified slightly to:
module glibc_test2;
from IOChan import
ChanId;
from StdChans import
StdOutChan;
from TextIO import
WriteLn, WriteString;
from M2RTS import
InstallTerminationProcedure ;
var
cid_out: ChanId;
procedure P1();
begin (* procedure P1 *)
WriteString(cid_out, 'This is P1');
WriteLn(cid_out);
end P1;
procedure P2();
begin (* procedure P2 *)
WriteString(cid_out, 'This is P2');
WriteLn(cid_out);
end P2;
begin (* module glibc_test *)
cid_out:=StdOutChan();
if InstallTerminationProcedure (P2)
then
P1();
end
end glibc_test2.
(*
01.03.2024
*)
$ gm2 glibc_test2.mod
$ ./a.out
This is P1
This is P2
hope this helps,
regards,
Gaius
- Re: atexit from libc causes unexpected program termination,
Gaius Mulley <=