Recent

Author Topic: Free Pascal produces runtime error 107  (Read 6414 times)

mggm

  • Newbie
  • Posts: 2
Free Pascal produces runtime error 107
« on: June 25, 2014, 04:01:44 pm »
...which is not listed here: http://www.freepascal.org/docs-html/user/userap4.html . I thought this document was meant to be exhaustive, or was I wrong?

Here is what I did:
a) Compiled a simple http://pastebin.com/Qf4pRNN6 piece of code with no compiler options - simply fpc wont.pas
b) Used the compiled code to produce file wont.dat (inserted a 0 on standard input)
c) Screwed up the produced file
d) Tried to use the compiled code to open the screwed up file wont.dat (inserted a 1 on standard input).
e) Received:
Runtime error 107 at $00000000004002CD
  $00000000004002CD
  $0000000000400180

EDIT: I've run into a yet another thingy I can't understand while playing with the sample.

I slighlty modified the code: http://pastebin.com/vpq0QeEz Running the code (it does not crash with the {$I-} switch now) and commenting the writelns in and out showed that IOResult is set to 0! But removing the {$I-} switch immediately produces the above runtime error. I find this weird, becouse if I understand the documentation of the switch http://www.freepascal.org/docs-html/prog/progsu38.html#x45-440001.2.38 , the program with {$I-} should have IOResult set to something other then 0 if and only if the same program in the same conditions, but with {$I+} would crash. Yet there happenes the opposite: the program with {$I+} crashes, but with {$I-} reports no errors with IOResult. Why so?
« Last Edit: June 25, 2014, 04:36:24 pm by mggm »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Free Pascal produces runtime error 107
« Reply #1 on: June 25, 2014, 04:33:52 pm »
Yes, it's meant to be exhaustive for current stable FPC (i.e. 2.6.4).

In any case, you could go grep through the source code to find the exact error number... (but if 107 exists on FPC 2.6.4 then it is a bug in the documentation, yes)

Please always specify what FPC/Lazarus version you are using, and operating system (see first link in my signature). Thanks.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11990
  • FPC developer.
Re: Free Pascal produces runtime error 107
« Reply #2 on: June 25, 2014, 04:56:18 pm »
It seems to be the write(enum) functionality. If the conversion fails then this runtime error is raised.


mggm

  • Newbie
  • Posts: 2
Re: Free Pascal produces runtime error 107
« Reply #3 on: June 25, 2014, 05:09:45 pm »
Sorry.

So, I'm on Linux Mint 16, Cinnamon. Well, it's FPC 2.6.2 , so maybe that's the reason...

Anyway, I found something with grep. It's file /rtl/inc/sstrings.inc, lines 536-543. They read:

procedure fpc_shortstr_enum(ordinal,len:sizeint;typinfo,ord2strindex:pointer;out s:shortstring);[public,alias:'FPC_SHORTSTR_ENUM'];compilerproc;
var
  res: longint;
begin
  res:=fpc_shortstr_enum_intern(ordinal,len,typinfo,ord2strindex,s);
  if (res<>0) then
    runerror(107);
end;

Edit: @marcov, it seems it is how you say. But if so, why {$I-} prevents the program from crashing?

Well, the program crashes because it can't handle the enum correctly. But {$I-} should prevent it from crashing only if it couldn't read the data correctly. But no errors araised there, since IOResult continues to be set to 0!

Edit2: Ahh, I get it. http://pastebin.com/DLxVpyfs Now the program prints out nicely 107. The error araises on an attempt to write g, not to read the file . Anyway, IOResult code 107 again is not documented: http://www.freepascal.org/docs-html/rtl/system/ioresult.html

Seems I'll have to compile & run the program on an up-to-date fpc version.
« Last Edit: June 25, 2014, 05:20:11 pm by mggm »

 

TinyPortal © 2005-2018