comp.lang.ada
 help / color / mirror / Atom feed
* Reading from a saved stream
@ 2002-01-23  4:10 Paul Pukite
  2002-01-23 17:49 ` Stephen Leake
  2002-01-24  6:03 ` Greg Bek
  0 siblings, 2 replies; 3+ messages in thread
From: Paul Pukite @ 2002-01-23  4:10 UTC (permalink / raw)


Is the attached pattern legal & portable Ada? I believe
so but a compiler upgrade from Rational Apex 3.0.0b
to Rational Apex 4.0.0b resulted in the following
questionable output for the Stream_Save main procedure:

Received Move Command with Speed = 259
Speed should be = 999

The dispatching works OK but the transferred data looks odd.

I would like to know if this is more likely a regression 
bug or if Rational is following the standard leading to
an unexpected outcome. The results are independent of
the OS by the way. Also, the same behavior occurs if the
base class is not labelled abstract.

We have spent a lot of effort creating streamable classes and
to hit this issue has got me second-guessing this particular idiom.
Any comments are appreciated.

thanks,
Paul Pukite

::::::::::::::
base.1.ada
::::::::::::::
package Base is

    type Selection is (Zero, One, Two, Three);

    type Item is abstract tagged
	record
	    Menu : Integer := 1;
	    Enum : Selection := Three;
	end record;
    -- Primitive op
    procedure Input (Msg : in Item) is abstract;

end Base;
::::::::::::::
gizmo.1.ada
::::::::::::::
with Base;
package Gizmo is
    pragma Elaborate_Body;

    type Move is new Base.Item with
	record
	    Speed : Integer := 1;
	end record;
    procedure Input (Obj : in Move);

end Gizmo;
::::::::::::::
gizmo.2.ada
::::::::::::::
with Text_Io;

package body Gizmo is

    procedure Input (Obj : in Move) is
    begin
	Text_Io.Put_Line ("Received Move Command with Speed =" &
			  Integer'Image (Obj.Speed));
    end Input;

end Gizmo;
::::::::::::::
stream_save.2.ada
::::::::::::::
with Ada.Streams.Stream_Io;
with Text_Io;
with Base;
with Gizmo;

procedure Stream_Save is
    Stream_File_Name : constant String := "stream.out";

    procedure Save (Cmd : in Base.Item'Class) is
	File : Ada.Streams.Stream_Io.File_Type;
	S : Ada.Streams.Stream_Io.Stream_Access;
    begin
	Ada.Streams.Stream_Io.Create (File, Name => Stream_File_Name);
	S := Ada.Streams.Stream_Io.Stream (File);
	Base.Item'Class'Output (S, Cmd);
	Ada.Streams.Stream_Io.Close (File);
    end Save;

    procedure Play_Back is
	File : Ada.Streams.Stream_Io.File_Type;
	S : Ada.Streams.Stream_Io.Stream_Access;
    begin
	Ada.Streams.Stream_Io.Open
	   (File, Ada.Streams.Stream_Io.In_File, Stream_File_Name);
	S := Ada.Streams.Stream_Io.Stream (File);
	Base.Input (Base.Item'Class'Input (S));
	Ada.Streams.Stream_Io.Close (File);
    end Play_Back;

    Obj : Gizmo.Move;
    Speed : constant Integer := 999;
begin
    Obj.Speed := Speed;
    Save (Obj);  -- Save the command
    Play_Back;   -- Play back (and dispatch) the command
    Text_Io.Put_Line ("Speed should be =" & Integer'Image (Speed));
end Stream_Save;

pragma Main (Posix_Compliant => False); -- needed for Text_IO.Create




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Reading from a saved stream
  2002-01-23  4:10 Reading from a saved stream Paul Pukite
@ 2002-01-23 17:49 ` Stephen Leake
  2002-01-24  6:03 ` Greg Bek
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Leake @ 2002-01-23 17:49 UTC (permalink / raw)


puk @ umn._edu_ (Paul Pukite) writes:

> Is the attached pattern legal & portable Ada? I believe
> so but a compiler upgrade from Rational Apex 3.0.0b
> to Rational Apex 4.0.0b resulted in the following
> questionable output for the Stream_Save main procedure:
> 
> Received Move Command with Speed = 259
> Speed should be = 999
> 

gnat 3.14a1 under Windows NT gives:

Received Move Command with Speed = 999
Speed should be = 999

Which is what you were expecting?

Looks like a compiler bug to me.

Did you try it without the dispatching? Maybe it is just a stream
problem.

You should submit a support request to Rational, whether this is legal
Ada 95 or not. It's their job to help you use their tool to get your
job done, not just to make their compiler match the Ada spec. And if
they _don't_ agree that is their job, change support vendors!

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Reading from a saved stream
  2002-01-23  4:10 Reading from a saved stream Paul Pukite
  2002-01-23 17:49 ` Stephen Leake
@ 2002-01-24  6:03 ` Greg Bek
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Bek @ 2002-01-24  6:03 UTC (permalink / raw)


Paul,
The code looks right and as far as I can tell this is an Apex bug (I tested
on more than
one platform) and the bug appears to be on the reading side of the code.

I tested on our current internal build and the program works correctly.

I suggest you contact Rational support so that they open a case log and
correctly
track the issue.

Greg Bek
gab@rational.com



<puk @ umn._edu_ (Paul Pukite)> wrote in message
news:3c4e2839.2139458@news.tc.umn.edu...
> Is the attached pattern legal & portable Ada? I believe
> so but a compiler upgrade from Rational Apex 3.0.0b
> to Rational Apex 4.0.0b resulted in the following
> questionable output for the Stream_Save main procedure:
>
> Received Move Command with Speed = 259
> Speed should be = 999
>
> The dispatching works OK but the transferred data looks odd.
>
> I would like to know if this is more likely a regression
> bug or if Rational is following the standard leading to
> an unexpected outcome. The results are independent of
> the OS by the way. Also, the same behavior occurs if the
> base class is not labelled abstract.
>
> We have spent a lot of effort creating streamable classes and
> to hit this issue has got me second-guessing this particular idiom.
> Any comments are appreciated.
>
> thanks,
> Paul Pukite
>
> ::::::::::::::
> base.1.ada
> ::::::::::::::
> package Base is
>
>     type Selection is (Zero, One, Two, Three);
>
>     type Item is abstract tagged
> record
>     Menu : Integer := 1;
>     Enum : Selection := Three;
> end record;
>     -- Primitive op
>     procedure Input (Msg : in Item) is abstract;
>
> end Base;
> ::::::::::::::
> gizmo.1.ada
> ::::::::::::::
> with Base;
> package Gizmo is
>     pragma Elaborate_Body;
>
>     type Move is new Base.Item with
> record
>     Speed : Integer := 1;
> end record;
>     procedure Input (Obj : in Move);
>
> end Gizmo;
> ::::::::::::::
> gizmo.2.ada
> ::::::::::::::
> with Text_Io;
>
> package body Gizmo is
>
>     procedure Input (Obj : in Move) is
>     begin
> Text_Io.Put_Line ("Received Move Command with Speed =" &
>   Integer'Image (Obj.Speed));
>     end Input;
>
> end Gizmo;
> ::::::::::::::
> stream_save.2.ada
> ::::::::::::::
> with Ada.Streams.Stream_Io;
> with Text_Io;
> with Base;
> with Gizmo;
>
> procedure Stream_Save is
>     Stream_File_Name : constant String := "stream.out";
>
>     procedure Save (Cmd : in Base.Item'Class) is
> File : Ada.Streams.Stream_Io.File_Type;
> S : Ada.Streams.Stream_Io.Stream_Access;
>     begin
> Ada.Streams.Stream_Io.Create (File, Name => Stream_File_Name);
> S := Ada.Streams.Stream_Io.Stream (File);
> Base.Item'Class'Output (S, Cmd);
> Ada.Streams.Stream_Io.Close (File);
>     end Save;
>
>     procedure Play_Back is
> File : Ada.Streams.Stream_Io.File_Type;
> S : Ada.Streams.Stream_Io.Stream_Access;
>     begin
> Ada.Streams.Stream_Io.Open
>    (File, Ada.Streams.Stream_Io.In_File, Stream_File_Name);
> S := Ada.Streams.Stream_Io.Stream (File);
> Base.Input (Base.Item'Class'Input (S));
> Ada.Streams.Stream_Io.Close (File);
>     end Play_Back;
>
>     Obj : Gizmo.Move;
>     Speed : constant Integer := 999;
> begin
>     Obj.Speed := Speed;
>     Save (Obj);  -- Save the command
>     Play_Back;   -- Play back (and dispatch) the command
>     Text_Io.Put_Line ("Speed should be =" & Integer'Image (Speed));
> end Stream_Save;
>
> pragma Main (Posix_Compliant => False); -- needed for Text_IO.Create
>





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-01-24  6:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-23  4:10 Reading from a saved stream Paul Pukite
2002-01-23 17:49 ` Stephen Leake
2002-01-24  6:03 ` Greg Bek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox