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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,43127f177a55dc41 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.42.131.137 with SMTP id z9mr15753567ics.1.1320360641191; Thu, 03 Nov 2011 15:50:41 -0700 (PDT) Path: p6ni67982pbn.0!nntp.google.com!news1.google.com!postnews.google.com!h5g2000yqk.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: limited allocated classwide types Date: Thu, 3 Nov 2011 15:50:40 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <0ed43f83-40e7-46d3-8cc4-e1c41f500d28@c1g2000vbw.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 X-Trace: posting.google.com 1320360641 5355 127.0.0.1 (3 Nov 2011 22:50:41 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 3 Nov 2011 22:50:41 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h5g2000yqk.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ARLUEHNKC X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: news1.google.com comp.lang.ada:18815 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2011-11-03T15:50:40-07:00 List-Id: On Nov 3, 3:01=A0pm, Simon Belmont wrote: > I am attempting to create a limited, private, controlled type that > extends an interface type via an allocator (i think that's the right > termonology) with GNAT (GNATMAKE GPL 2011 20110428), but not having > much luck. =A0To summarize, when the access type is that of the concrete > type, or if the type is made non-limited, everything works as it > should. =A0However, when the access type is of the classwide variety and > the type is limited, things go bananas in a way that I cannot just > wrap my head around. > > I'm not sure if I'm misusing the limited nature, the extended return > syntax, or the classwide type, but I have had no success unravelling > the mystery. =A0If anybody can point out where I've gone off the rails, > and also the appropriate part of the RM that i've missed, I would be > eternally grateful. With an earlier version of GNAT (4.5.2), I don't get a Program_Error but I also don't seem to get the same output you get with "Output A" with either declaration of Foo_Ptr. Using "access all P.Foo_Type", the last "Entered Finalize" doesn't appear. Using "access all I.LI'Class", a second "Entered Initialize" appears instead of "Entered Doo!", and no "Entered Finalize" appears. But no Program_Error is raised. With our compiler (Irvine Compiler), the output is what you say is expected, in both cases. I haven't studied the program carefully to make sure the output really should be what you say it should be. But my initial impression is that this is a GNAT error. What happens if you remove the "limited" (and change Limited_Controlled to Controlled)? Does it work correctly in both cases? Since there's nothing tricky in your program, it really should have the same behavior except possibly for some additional Adjust and Finalize calls (since build-in-place is required for function calls returning limited types). If it works correctly without "limited" but not with it, that would be an additional reason to suspect a GNAT bug. -- Adam > > The entire sample program is at the bottom, but here is the basic > jist: > > When the access type is defined as: > > type Foo_Ptr is access all P.Foo_Type; > > the execution performs as expected: > > Entered Create > Entered Initialize > Entered Extended Return > Leaving Extended Return > Starting... > Entered Doo! > Ending... > Entered Finalize > [2011-11-03 17:38:57] process terminated successfully (elapsed time: > 00.12s) > > When the access type is changed to: > > type Foo_Ptr is access all I.LI'Class; > > the output crashes to some strange function that indicates it should > be impossible to ever get to (hence my confusion): > > Entered Create > Entered Initialize > Entered Extended Return > Leaving Extended Return > Starting... > Entered Finalize > > raised PROGRAM_ERROR : s-finroo.adb:42 explicit raise > [2011-11-03 17:40:27] process exited with status 1 (elapsed time: > 00.13s) > > The sample code is as follows: > > with Ada.Text_IO; > with Ada.Finalization; > > procedure Test_Init is > > =A0 =A0-- An interface with one function Doo > =A0 =A0package I is > =A0 =A0 =A0 type LI is limited interface; > =A0 =A0 =A0 procedure Doo (This : LI) is abstract; > =A0 =A0end I; > > =A0 =A0-- Concrete, limited, controlled implementation > =A0 =A0package P is > =A0 =A0 =A0 type Foo_Type is limited new Ada.Finalization.Limited_Control= led > and I.LI with > =A0 =A0 =A0 =A0 =A0record > =A0 =A0 =A0 =A0 =A0 =A0 o : Integer; > =A0 =A0 =A0 =A0 =A0end record; > > =A0 =A0 =A0 function Create (Arg : in Integer) return Foo_Type; > =A0 =A0 =A0 overriding procedure Initialize (This : in out Foo_Type); > =A0 =A0 =A0 overriding procedure Finalize =A0 (This : in out Foo_Type); > =A0 =A0 =A0 overriding procedure Doo (This : =A0Foo_Type); > =A0 =A0 end P; > > =A0 =A0package body P is > > =A0 =A0 =A0 function Create (Arg : in Integer) return Foo_Type is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0Ada.Text_IO.Put_Line("Entered Create"); > =A0 =A0 =A0 =A0 =A0return Object : Foo_Type do > =A0 =A0 =A0 =A0 =A0 =A0 Ada.Text_IO.Put_Line("Entered Extended Return"); > =A0 =A0 =A0 =A0 =A0 =A0 Object.o :=3D Arg; > =A0 =A0 =A0 =A0 =A0 =A0 Ada.Text_IO.Put_Line("Leaving Extended Return"); > =A0 =A0 =A0 =A0 =A0end return; > =A0 =A0 =A0 end Create; > > =A0 =A0 =A0 overriding procedure Initialize (This : in out Foo_Type) is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0Ada.Text_IO.Put_Line("Entered Initialize"); > =A0 =A0 =A0 end Initialize; > > =A0 =A0 =A0 overriding procedure Finalize =A0 (This : in out Foo_Type) is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0Ada.Text_IO.Put_Line("Entered Finalize"); > =A0 =A0 =A0 end Finalize; > > =A0 =A0 =A0 overriding procedure Doo (This : Foo_Type) is > =A0 =A0 =A0 begin > =A0 =A0 =A0 =A0 =A0Ada.Text_IO.Put_Line("Entered Doo!"); > =A0 =A0 =A0 end Doo; > > =A0 =A0end P; > > -- =A0 =A0 =A0type Foo_Ptr is access P.Foo_Type; =A0-- Output A > -- =A0 =A0 =A0type Foo_Ptr is access I.LI'Class; =A0-- Output B > > =A0 =A0Bar : Foo_Ptr :=3D new P.Foo_Type'(P.Create(42)); > > begin > > =A0 =A0Ada.Text_IO.Put_Line("Starting..."); > =A0 =A0Bar.all.Doo; > =A0 =A0Ada.Text_IO.Put_Line("Ending..."); > > end Test_Init; > > Thank you in advance to anyone who can explain what exactly is going > on here. > > -sb