[net.micro.mac] TML Pascal ver 2.01 bug

mjmartin@watnot.UUCP (Marie-Josee Martin) (10/30/86)

Last night I was working with my newly received TML Pascal ver 2.01.  Well,
I managed to find what I think is a bug compiling some of my old programs.

Using the "Plain Vanilla" mode, TML doesn't pass variable text parameters
correctly, at least for input and output.  The following piece of code
compiles correctly but never runs correctly.  Actually, the program hangs
(and sometimes crashes.)


program main (input, output);

  procedure Sread (var f : text);
    begin
      writeln (SizeOf (f));
      get (f);
      while f^ <> 'q' do
        get (f)
    end;
    
  begin
    Sread (input)
  end.


By defining the procedure as:
  
  procedure Sread (f : text);

the program compiles correctly AND executes properly. (Try to figure
that out.)

Hope this saves someone some trouble.

-Marie-Josee.

bezanson@gumby.WISC.EDU (Brian Bezanson) (11/02/86)

In article <12125@watnot.UUCP>, mjmartin@watnot.UUCP (Marie-Josee Martin) writes:
> Using the "Plain Vanilla" mode, TML doesn't pass variable text parameters
> correctly, at least for input and output.  The following piece of code
> compiles correctly but never runs correctly.  Actually, the program hangs
> (and sometimes crashes.)
 
>   procedure Sread (var f : text);
>     begin
>       writeln (SizeOf (f));
>       get (f);
>       while f^ <> 'q' do
>         get (f)
>     end;
 
> By defining the procedure as:
>   procedure Sread (f : text);
> the program compiles correctly AND executes properly. (Try to figure
> that out.)

I tried a similiar procedure recently in a program running under Lightspeed
Pascal.  But when it tried to compile a procedure similiar to your second
one, WITHOUT the VARiable parameter, Lightspeed gave me an error.  What you
have to do is change it to a VAR parameter, no mater if you plan on changing
it or not.  The reason why (correct me somebody because this may not be perfect)
is that a file of type TEXT (or a file of char) is a pointer or start of
a buffer in memory for this file.  By passing it as a straight parameter,
the computer would try and pass a copy of the buffer onto the stack.  
By using a VAR parameter you are passing a pointer to this buffer, thus 
giving no memory problems at all.  Lightspeed is set up to watch for this
possible error, either TML misses this, or Leonard lets you try it and
when it gets pushed on the stack, the program either bombs or hangs.

I made the fix in my procedures and used VAR parameters and everything
worked fine, I would assume this should fix your problem with TML.

-- 
Brian Bezanson {seismo,ihnp4,allegra,topaz,harvard}!uwvax!gumby!bezanson
Manta Software Corp.				  bezanson@gumby.wisc.edu