From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,FROM_ADDR_WS, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,64ebc6f079364493,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-22 20:08:21 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!hardy.tc.umn.edu!laurel.tc.umn.edu!not-for-mail From: puk @ umn._edu_ (Paul Pukite) Newsgroups: comp.lang.ada Subject: Reading from a saved stream Date: Wed, 23 Jan 2002 04:10:58 GMT Organization: University of Minnesota (umn . edu) Message-ID: <3c4e2839.2139458@news.tc.umn.edu> Reply-To: pukite@mr.net X-Trace: laurel.tc.umn.edu 1011758900 2722 128.101.252.233 (23 Jan 2002 04:08:20 GMT) X-Complaints-To: usenet@laurel.tc.umn.edu X-Newsreader: Forte Free Agent 1.11/32.235 Xref: archiver1.google.com comp.lang.ada:19215 Date: 2002-01-23T04:10:58+00:00 List-Id: 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