[fpc-pascal] Disk Full

Bernd Kreuss prof7bit at googlemail.com
Sun Oct 10 23:42:22 CEST 2010


The following code (Msg is just outputting to the debug monitor) will
produce something strange:

// replace all line endings with space
for Pos1 := 1 to Len do begin
  try
    Msg(2, 'GetVector', Format('  %d %d',[Pos1, Len]));
    if Line[Pos1] = #13 then Line[Pos1] := ' ';
    if Line[Pos1] = #10 then Line[Pos1] := ' ';
  except
    on e: Exception do
      Msg(2, 'GetVector', Format('e %d %d %s',[Pos1, Len, e.message]));
  end;
end;

> [1428] <2> TRConsole.GetVector:   1 84
> [1428] <2> TRConsole.GetVector:   2 84
> [1428] <2> TRConsole.GetVector:   3 84
> [1428] <2> TRConsole.GetVector: e 3 84 Disk Full
> [1428] <2> TRConsole.GetVector:   4 84
> [1428] <2> TRConsole.GetVector:   5 84
> [1428] <2> TRConsole.GetVector:   6 84
> [1428] <2> TRConsole.GetVector:   7 84
> [1428] <2> TRConsole.GetVector:   8 84
> [1428] <2> TRConsole.GetVector:   9 84
> [1428] <2> TRConsole.GetVector: e 9 84 Disk Full
> [1428] <2> TRConsole.GetVector:   10 84
> [1428] <2> TRConsole.GetVector:   11 84
> [1428] <2> TRConsole.GetVector:   12 84
> [1428] <2> TRConsole.GetVector:   13 84
> [1428] <2> TRConsole.GetVector:   14 84
> [1428] <2> TRConsole.GetVector:   15 84
> [1428] <2> TRConsole.GetVector: e 15 84 Disk Full
> [1428] <2> TRConsole.GetVector:   16 84
> [1428] <2> TRConsole.GetVector:   17 84
> [1428] <2> TRConsole.GetVector:   18 84
> [1428] <2> TRConsole.GetVector:   19 84
> [1428] <2> TRConsole.GetVector:   20 84
and so on.

This is not the only code that fails in strange ways! I wondered all the
time why I got random non-deterministic crashes all the time and only
when I inserted these debug message outputs into this loop the nature of
the problem became more clear.

The code in question is running in a dll that is loaded by a the
proprietary software Metatrader 4 (through their proprietary scripting
language) and it does not much more than having a TProcess in which
Rterm.exe (the R-Project) is running (and idle) and there are two pipes
for the stdio of this process but they are empty and idle when this
happens. I have no other threads started when this happens (of course
Metatrader has a few) but not my dll and nothing calls into my dll when
this happens.

FPC is 2.5.1 trunk.

There are no OS exceptions happening because I have another dll with an
exception handler hooked into AddVectoredExceptionHandler() as the very
forst handler that does reliable log all these windows exceptions (AV,
FPU, etc).

What could cause this strange effect? What kind of outside force can
make this thread raise an FPC native exception although it does not come
anywhere near a raise statement? Maybe there is something wrong in the
DLLMain when the attach_thread event happens? does it mess up this
thread ID (or however the raise mechanism works) with something else?

Maybe something else is permanently calling raise and random other
threads are catching it?

confused,
Bernd



More information about the fpc-pascal mailing list