[fpc-pascal] run pascal programs as scripts

Darius Blaszyk dhkblaszyk at zeelandnet.nl
Thu Mar 31 01:49:08 CEST 2011


I created a patch to make instantFPC run on win32. To make the app run I implemented TProcess as windows does not understands fpexecv. Even better would be to use TProcess for all platforms, thus removing the need of defines and we could drop the unix and windows units.

The only script that did not work for me was exitcode.pas. I will have to look more in detail how to support this.

Regards, Darius

-------------- next part --------------
A non-text attachment was scrubbed...
Name: instantfpc_win32.zip
Type: application/zip
Size: 1394 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20110331/6e262bd6/attachment.zip>
-------------- next part --------------

On Mar 28, 2011, at 12:14 AM, Mattias Gaertner wrote:

> On Sun, 27 Mar 2011 23:59:11 +0200 (CEST)
> Michael Van Canneyt <michael at freepascal.org> wrote:
> 
>> 
>> 
>> On Sun, 27 Mar 2011, Mattias Gaertner wrote:
>> 
>>> On Sun, 27 Mar 2011 21:16:58 +0200 (CEST)
>>> Michael Van Canneyt <michael at freepascal.org> wrote:
>>> 
>>>> 
>>>> 
>>>> On Sun, 27 Mar 2011, Mattias Gaertner wrote:
>>>> 
>>>>> On Sun, 27 Mar 2011 19:05:12 +0200 (CEST)
>>>>> Michael Van Canneyt <michael at freepascal.org> wrote:
>>>>> 
>>>>>> 
>>>>>> 
>>>>>> On Sun, 27 Mar 2011, Mattias Gaertner wrote:
>>>>>> 
>>>>>>> I wrote a little tool:
>>>>>>> 
>>>>>>> http://wiki.lazarus.freepascal.org/InstantFPC
>>>>>> 
>>>>>> Nice job. OK to include in FPC as one of the utils ?
>>>>> 
>>>>> Yes.
>>>> 
>>>> Thank you. But please, fix a couple of bugs first:
>>>> 
>>>> 1. I get a stream read error each time I execute a script the first time (i.e. it's not yet in the cache) :
>>>> home: >./helloworld.pas
>>>> An unhandled exception occurred at $0000000000425556 :
>>>> EReadError : Stream read error
>>>>   $0000000000425556
>>>>   $00000000004256FA
>>>>   $0000000000469E8A
>>>>   $0000000000400A25
>>> 
>>> It works here.
>> 
>> I assume you use FPC 2.4.x. In FPC 2.5.1 your code
>> 
>>   repeat
>>     Count:=ss.CopyFrom(Proc.Output,4096);
>>   until Count=0;
>> 
>> Fails.
>> 
>> This is because CopyFrom assumes that at least 4096 bytes are present. 
>> If it doesn't get 4096 bytes, an exception is thrown.
>> 
>> (see recent change in trunk:
>> r16992 | sergei | 2011-02-24 04:25:40 +0100 (Thu, 24 Feb 2011) | 5 lines
>> 
>> * Rework TStream.CopyFrom (see Mantis #17980):
>> a) Use significantly larger buffer (128k instead of 1k)
>> b) When Count=0, do not try to determine the source size. Just copy until the source can be read. This should improve performance with limited seek capability sources (e.g. a decompression stream will be decompressed once rather than twice).
>> c) Use ReadBuffer/WriteBuffer, so an exception is raised when something goes wrong. This conforms to Delphi behavior.
>> )
>> 
>> My FPC outputs nothing, so CopyFrom does not get 4096 bytes and therefor 
>> raises an exception:
>> 
>> Breakpoint 1, 0x000000000041396c in fpc_raiseexception ()
>> (gdb) bt
>> #0  0x000000000041396c in fpc_raiseexception ()
>> #1  0x0000000000425565 in CLASSES_TSTREAM_$__READBUFFER$formal$LONGINT ()
>> #2  0x00000000004256fa in CLASSES_TSTREAM_$__COPYFROM$TSTREAM$INT64$$INT64 ()
>> #3  0x0000000000469e8a in INSTANTFPTOOLS_COMPILE$ANSISTRING$ANSISTRING ()
>> #4  0x0000000000400a25 in main ()
>> 
>> since the compilation is already done, the binary is in the cache, and the second run works.
>> 
>> Changing the code to
>> 
>>   buf : Array[1..4096] of byte;
>> 
>> begin
>>   // snip
>>   ss:=TStringStream.Create('');
>>   repeat
>>     Count:=Proc.Output.Read(Buf,4096);
>>     if Count>0 then
>>       ss.write(buf,count);
>>   until Count=0;
>> 
>> it works always. Will you change it, or do I change it once it is in FPC ?
> 
> I changed it on sf.
> 
> 
>> This change may affect other things in Lazarus. 
>> Sergei (hope you are reading this), I think you should put this in the user_changes wiki page.
> 
> 
> Mattias
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list