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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed-00.mathworks.com!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Controlled types as interfaces Date: Fri, 29 Aug 2014 11:01:30 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <17zg1do470nci.15209dgoz3ktk.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls7.std.com 1409324471 31231 192.74.137.71 (29 Aug 2014 15:01:11 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 29 Aug 2014 15:01:11 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:uwU5UULJew3sn5YYfxKKv44AaXc= Xref: news.eternal-september.org comp.lang.ada:21985 Date: 2014-08-29T11:01:30-04:00 List-Id: "Randy Brukardt" writes: > The real problem is that some (many?) implementations include > implementation-defined components in types Controlled and > Limited_Controlled. (For instance, Janus/Ada includes chain components.) GNAT used to do that, but actually only heap objects need to be chained, and the current implementation does not declare the chain links as components. Controlled components and stack objects do not get chained. A heap object is allocated with some extra space at negative offsets, where the chain links are stored. > Interfaces of course don't have any components; thus making > Controlled/Limited_Controlled into interfaces would require the back-door > implementation of full MI (since it would require adding components to > existing types, meaning that the components could not be assumed at a fixed > offset). That is a leap too far. > > Note that in the OP's example, Janus/Ada does NOT treat the enclosing record > as controlled; each individual controlled object (including components) is > managed separately. I did it that way to make unwinding an object in the > face of exceptions during construction easier (each object is registered as > it is constructed, so all successfully constructed objects get finalized and > none that failed get finalized). GNAT, OTOH, does treat each object ^ not > individibly and has to go through some handstands so that objects that > aren't constructed aren't finalized. I think you're missing a "not" there. Yes, there are some "handstands", but it's not so bad. I think the only reason it was so hard to implement is that it was a re-implementation. Doing it that way from the start would not have been so bad (as is often the case). The compiler generates a "deep_initialize" procedure for each type, which either fully initializes everything, or else finalizes the parts that got initialized before an exception. Rational uses the same method as GNAT. - Bob