BPCOMPAT v1.10 -released!_(re)

Mon, 27 Oct 1997 19:25:22 GMT



The African Chief wrote:

> I had a problem with it in TESTMEM.PAS in the new bpcompat.
> However, I have since discovered that the problem lies in mixing
> the use of "ExitProc", and "AddExitProc" in the same program. Use
> one or the other, and the problem disappears. Use both ==
> infinite loop.

I see. AddExitProc is the C function atexit which I don't know much about.
However, I like the simple way of adding an exit proc (rather than messing
with pointer as in BP's ExitProc), so I wrote a replacement for AddExitProc
in pure Pascal which is quite possible. It's included below, it can be used as
a separate unit or merged into the existing units. A demo programs follows.

BTW: Rather than an EP procedural parameter (as in sysutils.pas) I use a
BP procedural type. One difference is that for a procedural parameter, a local
procedure could be passed, which is unwanted here (since a local procedure
would rely on its outer procedures to be active which is not the case during
the finalization).

unit aep;

interface

type TProc = procedure;

procedure AddExitProc (Proc: TProc);

implementation

type
  PProcList = ^TProcList;
  TProcList = record
    Next: PProcList;
    Proc: TProc
  end;

var ProcList: PProcList = nil;

procedure AddExitProc (Proc: TProc);
var Temp: PProcList;
begin
  Temp := ProcList;
  New (ProcList);
  ProcList^.Next := Temp;
  ProcList^.Proc := Proc
end;

to end do
  while ProcList<>nil do
    begin
      {$W-}var Temp: PProcList;{$W+}
      Temp := ProcList;
      ProcList := ProcList^.Next;
      Temp^.Proc;
      Dispose (Temp)
    end;

end.

program x;
uses aep;

procedure world;
begin
  writeln('world!')
end;

procedure hello;
begin
  write('Hello ')
end;

begin
  AddExitProc(world);
  AddExitProc(hello)
end.

> > > > Assign is built-in now, so you can remove it from system.pas.
> 
> Actually, the CygWin32 version still does not have it

Strange. Actually, the built-in Assign in the RTS (rts/rts-assign.p) is
written in Pascal in just the same way as in system.pas, so I think it should
compile on any platform. Is this just an omission, or are there any hidden
problems? Or is the CygWin version an older binary distribution?
Peter, Jan-Jaap?

-- 
Frank Heckenbach, Erlangen, Germany
heckenb@mi.uni-erlangen.de
http://home.pages.de/~fjf/links.htm


Frank Heckenbach (heckenb@mi.uni-erlangen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es