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.8 required=5.0 tests=BAYES_00,FREEMAIL_FROM, FROM_STARTS_WITH_NUMS,PDS_OTHER_BAD_TLD autolearn=no autolearn_force=no version=3.4.4 X-Received: by 10.36.89.142 with SMTP id p136mr1556328itb.19.1519257453603; Wed, 21 Feb 2018 15:57:33 -0800 (PST) X-Received: by 10.157.95.135 with SMTP id g7mr239519oti.14.1519257453326; Wed, 21 Feb 2018 15:57:33 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.unit0.net!peer03.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!w142no6727ita.0!news-out.google.com!s63ni21itb.0!nntp.google.com!w142no6723ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 21 Feb 2018 15:57:33 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.240.212.129; posting-account=rhqvKAoAAABpikMmPHJSZh4400BboHwT NNTP-Posting-Host: 85.240.212.129 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <503e3322-ee8e-4d6f-9aa5-e7b98f87e8f8@googlegroups.com> Subject: article on acces types and dynamic serialization in Ada (2003) From: Mehdi Saada <00120260a@gmail.com> Injection-Date: Wed, 21 Feb 2018 23:57:33 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Bytes: 4092 X-Received-Body-CRC: 974686306 Xref: reader02.eternal-september.org comp.lang.ada:50530 Date: 2018-02-21T15:57:33-08:00 List-Id: Hello everyone. I already mailed you Simon Wright about it, but I've more info and questions, so it put it here. First the context: I played with streams yesterday to learn more, and stumbled on something not really intuitive, at least. what means exactly Some_access_type'Write(Stream1, Some_Pointer) ? I could figure out it's implementation defined, so you can't guess. So that Some_access_type'Write(stream(Stream_File), Pointer1); ... Reset(Stream_File, IN_FILE); Some_access_type'Read(stream(Stream_file), Pointer2); doesn't work: reaching Pointer2.all raises "erroneous memory access", though Pointer2 isn't null. Strange, since in my exemple, all happen in the same, hum, "scope of declaration" (apropriate term ?). Any address or whatever information the pointer is made of, should still be valid. Any pool pointed at still exists. Doesn't feel like a "sane" legal behavior. I also saw a "normal" record object with a pool-specific pointer like this one type FOO is record ... BAR: access INTEGER := new INTEGER'(15); end record; serializes well, I can read Bar.all. Funny, but where the difference since (according to Ada wikibook) a priori the default 'Write is called for each record component ? Then I found today that https://infoscience.epfl.ch/record/54724/files/IC_TECH_REPORT_200363.pdf : Automatic Serialization of Dynamic Structures in Ada Technical Report I was surprised I could read and understand it all with some concentration. And a bit proud, to be honnest ! I would have thought it to be like Chinese at my level. It was 13 years ago, but I couldn't find a more recent papier on the subject of dynamic serialization, nor has new Dynamic_Stream aspects/attributes been added since then. I didn't read anything either in the stream or access types related sections. I tried more, but can't write well yet that more complicated exemple: with Ada.Streams.Stream_IO, Ada.Strings.Unbounded.Text_IO, Ada.Text_IO; use Ada.Streams.Stream_IO, Ada.Streams, Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO; procedure Main is subtype TSF is File_Type; FILE : TSF; type CHAMPS; type ACCESS_CHAMPS is access ALL CHAMPS; type CHAMPS (A: ACCESS_CHAMPS) is record NOTE : NATURAL range 0 .. 20 := 0; end record; C2, C1 , C3 : aliased CHAMPS := (A => null, note => 5); begin C1 := (C2'Access, 14); C2 := (A => C1'Access, Note => 5 ); Create (FILE, Append_File, Name => "tentative.stream"); CHAMPS'Write (Stream (FILE), C2); Reset (File => FILE, Mode => In_File ); CHAMPS'Read(Stream(FILE), C3); ada.Text_IO.Put_line (INTEGER'Image (C3.A.all.Note)); CLOSE(FILE); end; raises CONSTRAINT_ERROR : main.adb:15 discriminant check failed I read as I could about access discrimant aliasing and autoreferencing types, but visibly lack practice ;-) Could you help me finish that exemple ? I would be delighted to see what happens by myself, since the former exemple (Some_Access'Write and 'Read) proves interesting. Gosh, the pleasure these things give me...