* Obtaining access to protected object @ 2008-07-08 20:41 Maciej Sobczak 2008-07-09 15:03 ` Adam Beneschan 2008-07-09 15:33 ` george.priv 0 siblings, 2 replies; 10+ messages in thread From: Maciej Sobczak @ 2008-07-08 20:41 UTC (permalink / raw) Consider 9.4-21/2: "Within the declaration or body of a protected unit other than in an access_definition, the name of the protected unit denotes the current instance of the unit" I understand that this allows me to obtain the access to the current object (the "this" access) of the protected object. Let's try: protected type P is procedure Foo; end P; protected body P is procedure Foo is Ptr : access P; -- P denotes the type P begin Ptr := P'Access; -- here P denotes the "this" instance of P end; end P; This is what GNAT has to say about it: ""Access" attribute cannot be applied to type". As far as I understand, this is in conflict with the AARM paragraph mentioned above. Am I doing something wrong or is it a compiler bug? -- Maciej Sobczak * www.msobczak.com * www.inspirel.com ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Obtaining access to protected object 2008-07-08 20:41 Obtaining access to protected object Maciej Sobczak @ 2008-07-09 15:03 ` Adam Beneschan 2008-07-09 21:21 ` Maciej Sobczak 2008-07-09 15:33 ` george.priv 1 sibling, 1 reply; 10+ messages in thread From: Adam Beneschan @ 2008-07-09 15:03 UTC (permalink / raw) On Jul 8, 1:41 pm, Maciej Sobczak <see.my.homep...@gmail.com> wrote: > Consider 9.4-21/2: > > "Within the declaration or body of a protected unit other than in an > access_definition, the name of the protected unit denotes the current > instance of the unit" > > I understand that this allows me to obtain the access to the current > object (the "this" access) of the protected object. > Let's try: > > protected type P is > procedure Foo; > end P; > > protected body P is > procedure Foo is > Ptr : access P; -- P denotes the type P > begin > Ptr := P'Access; -- here P denotes the "this" instance of > P > end; > end P; > > This is what GNAT has to say about it: ""Access" attribute cannot be > applied to type". > As far as I understand, this is in conflict with the AARM paragraph > mentioned above. > > Am I doing something wrong or is it a compiler bug? It's a compiler bug. -- Adam ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Obtaining access to protected object 2008-07-09 15:03 ` Adam Beneschan @ 2008-07-09 21:21 ` Maciej Sobczak 2008-07-09 21:57 ` Adam Beneschan ` (2 more replies) 0 siblings, 3 replies; 10+ messages in thread From: Maciej Sobczak @ 2008-07-09 21:21 UTC (permalink / raw) On 9 Lip, 17:03, Adam Beneschan <a...@irvine.com> wrote: > It's a compiler bug. Reported to bugzilla. I cannot believe nobody [*] tried it before. [*] What about ACATS? My code example looks like a unit test derived directly from AARM. -- Maciej Sobczak * www.msobczak.com * www.inspirel.com ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Obtaining access to protected object 2008-07-09 21:21 ` Maciej Sobczak @ 2008-07-09 21:57 ` Adam Beneschan 2008-07-09 22:01 ` Georg Bauhaus 2008-07-10 0:39 ` Randy Brukardt 2 siblings, 0 replies; 10+ messages in thread From: Adam Beneschan @ 2008-07-09 21:57 UTC (permalink / raw) On Jul 9, 2:21 pm, Maciej Sobczak <see.my.homep...@gmail.com> wrote: > On 9 Lip, 17:03, Adam Beneschan <a...@irvine.com> wrote: > > > It's a compiler bug. > > Reported to bugzilla. > I cannot believe nobody [*] tried it before. > > [*] What about ACATS? My code example looks like a unit test derived > directly from AARM. There's plenty that ACATS can't test. The ACATS tries to test every rule in the RM, but it doesn't try to test every possible combination of rules that could interact---that would be impossibly hard. In fact, I just tried this on a *task* type, rather than a protected type, and it works fine. So if ACATS has a test that tests the "current instance" rule, that would be considered good enough; if a compiler handles current instances correctly in some cases but not others, the ACATS isn't designed to catch all of those problems. -- Adam ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Obtaining access to protected object 2008-07-09 21:21 ` Maciej Sobczak 2008-07-09 21:57 ` Adam Beneschan @ 2008-07-09 22:01 ` Georg Bauhaus 2008-07-10 0:39 ` Randy Brukardt 2 siblings, 0 replies; 10+ messages in thread From: Georg Bauhaus @ 2008-07-09 22:01 UTC (permalink / raw) Maciej Sobczak wrote: > On 9 Lip, 17:03, Adam Beneschan <a...@irvine.com> wrote: > >> It's a compiler bug. > > Reported to bugzilla. > I cannot believe nobody [*] tried it before. > Maybe Ada programmer have not tried creating a "this" pointer inside a shared variable's procedure because they are much less used to passing references around using pointers. ;-) -- Georg Bauhaus Y A Time Drain http://www.9toX.de ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Obtaining access to protected object 2008-07-09 21:21 ` Maciej Sobczak 2008-07-09 21:57 ` Adam Beneschan 2008-07-09 22:01 ` Georg Bauhaus @ 2008-07-10 0:39 ` Randy Brukardt 2 siblings, 0 replies; 10+ messages in thread From: Randy Brukardt @ 2008-07-10 0:39 UTC (permalink / raw) "Maciej Sobczak" <see.my.homepage@gmail.com> wrote in message news:d234e827-c3e6-481a-a15e-94382c2fbf6c@d77g2000hsb.googlegroups.com... ... > [*] What about ACATS? My code example looks like a unit test derived > directly from AARM. The Ada 95 ACATS writers made a rather fundamental mistake, in that they made no attempt to look at whether rules inherited from Ada 83 were tested properly. One result of that is that kinds of types added in Ada 95 (modular, decimal, protected) types are not tested much with the basic rules of the language in the ACATS. (Another error that they made was to consider a paragraph covered if any rule in the paragraph is tested -- but there are a lot of paragraphs with multiple rules.) The current ACATS work includes going back and restarting the coverage analysis from first principles. I'm finding that the coverage of the Standard in the ACATS is around 60% (far less than the Ada 95 contractors claimed). I doubt that given the current ACATS budget that this situation is going to change much -- I'm primarily emphasizing Ada 2005 changes for new tests. Anyone can help, however, by submitting candidate ACATS tests. (I recommend doing so to complete untested test objectives where those have already been created for the full language, as that would increase the chances of a test being used in the ACATS.) Information on how to create tests can be found in the ACATS documentation - look at http://www.ada-auth.org/acats.html to find that. (I'm too busy at the moment to look up the exact link.) Feel free to contact me if you are interested and/or have questions. (Also, you can ask me for the most recent test objectives for a section of interest, as the ones available with the ACATS distribution are pretty stale.) Randy. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Obtaining access to protected object 2008-07-08 20:41 Obtaining access to protected object Maciej Sobczak 2008-07-09 15:03 ` Adam Beneschan @ 2008-07-09 15:33 ` george.priv 2008-07-09 19:27 ` Adam Beneschan 1 sibling, 1 reply; 10+ messages in thread From: george.priv @ 2008-07-09 15:33 UTC (permalink / raw) On Jul 8, 4:41 pm, Maciej Sobczak <see.my.homep...@gmail.com> wrote: > Consider 9.4-21/2: > > "Within the declaration or body of a protected unit other than in an > access_definition, the name of the protected unit denotes the current > instance of the unit" > > I understand that this allows me to obtain the access to the current > object (the "this" access) of the protected object. > Let's try: > > protected type P is > procedure Foo; > end P; > > protected body P is > procedure Foo is > Ptr : access P; -- P denotes the type P > begin > Ptr := P'Access; -- here P denotes the "this" instance of > P > end; > end P; > > This is what GNAT has to say about it: ""Access" attribute cannot be > applied to type". > As far as I understand, this is in conflict with the AARM paragraph > mentioned above. > > Am I doing something wrong or is it a compiler bug? > > -- > Maciej Sobczak *www.msobczak.com*www.inspirel.com The instance may not be aliased, and type itself is not enough to determine that at compile time. You can reference the protected type "this" instance though: protected type Xt is procedure Foo; end Xt; procedure Call_Foo (A : in out Xt); protected body Xt is procedure Foo is begin Call_Foo (Xt); end; end Xt; ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Obtaining access to protected object 2008-07-09 15:33 ` george.priv @ 2008-07-09 19:27 ` Adam Beneschan 2008-07-10 2:10 ` george.priv 0 siblings, 1 reply; 10+ messages in thread From: Adam Beneschan @ 2008-07-09 19:27 UTC (permalink / raw) On Jul 9, 8:33 am, george.p...@gmail.com wrote: > The instance may not be aliased, and type itself is not enough to > determine that at compile time. Wrong. The current instance of a protected type is always considered aliased, and 'Access is allowed. 3.10(9/2). -- Adam ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Obtaining access to protected object 2008-07-09 19:27 ` Adam Beneschan @ 2008-07-10 2:10 ` george.priv 2008-07-10 14:46 ` Adam Beneschan 0 siblings, 1 reply; 10+ messages in thread From: george.priv @ 2008-07-10 2:10 UTC (permalink / raw) On Jul 9, 3:27 pm, Adam Beneschan <a...@irvine.com> wrote: > On Jul 9, 8:33 am, george.p...@gmail.com wrote: > > > The instance may not be aliased, and type itself is not enough to > > determine that at compile time. > > Wrong. The current instance of a protected type is always considered > aliased, and 'Access is allowed. 3.10(9/2). > > -- Adam I may be wrong, but it seems that Aliaseness is guaranteed only within the protected body. So taking pointer and spilling it outside of the scope (even if allowed) is bad idea IMHO. If used inside the protected body then what's advantage of using pointer vs. referring directly? George ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Obtaining access to protected object 2008-07-10 2:10 ` george.priv @ 2008-07-10 14:46 ` Adam Beneschan 0 siblings, 0 replies; 10+ messages in thread From: Adam Beneschan @ 2008-07-10 14:46 UTC (permalink / raw) On Jul 9, 7:10 pm, george.p...@gmail.com wrote: > On Jul 9, 3:27 pm, Adam Beneschan <a...@irvine.com> wrote: > > > On Jul 9, 8:33 am, george.p...@gmail.com wrote: > > > > The instance may not be aliased, and type itself is not enough to > > > determine that at compile time. > > > Wrong. The current instance of a protected type is always considered > > aliased, and 'Access is allowed. 3.10(9/2). > > > -- Adam > > I may be wrong, You're definitely wrong about the rules. If there's a possibility that the rules can allow a programmer to write a legal program that creates a dangling reference (without involving certain dangerous features), then the ARG needs to hear about it. But I don't think that's the case here. The biggest problem, as far as I know, with allowing something to access an unaliased object, is that the compiler may not realize that something could point to it, and therefore could optimize certain calculations so that the object doesn't necessarily hold the right value when expected, which will then be a problem if the program does a dereference of the access. However, none of this reasoning applies to protected types, or task types. In fact, there would probably be no accessing problem at all if *all* protected and task objects were considered aliased, even without an explicit "aliased" keyword. See AARM 3.10(9.l/2) [that's "nine" "dot" "the lower-case letter L"]; the ARG actually considered doing this for all by-reference types (which would include task and protected types, as well as all tagged types and all limited record types). They decided not to do so because of some problems involving private parts. > but it seems that Aliaseness is guaranteed only within > the protected body. So taking pointer and spilling it outside of the > scope (even if allowed) is bad idea IMHO. See above; there's no danger in letting such pointers outside, even if the object is not explicitly declared as "aliased". Were it not for some problems involving privacy breakage, the ARG saw no danger in simply decreeing that all protected types, etc., are automatically aliased. > If used inside the > protected body then what's advantage of using pointer vs. referring > directly? Because you could have an object of an access-to-protected type that could, in some instances, be set to the same protected type, or could be set to point to some other protected type. Of course there's little point in setting up a pointer that always refers to the same object; the idea is that you could modify it to point to something else. -- Adam ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2008-07-10 14:46 UTC | newest] Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2008-07-08 20:41 Obtaining access to protected object Maciej Sobczak 2008-07-09 15:03 ` Adam Beneschan 2008-07-09 21:21 ` Maciej Sobczak 2008-07-09 21:57 ` Adam Beneschan 2008-07-09 22:01 ` Georg Bauhaus 2008-07-10 0:39 ` Randy Brukardt 2008-07-09 15:33 ` george.priv 2008-07-09 19:27 ` Adam Beneschan 2008-07-10 2:10 ` george.priv 2008-07-10 14:46 ` Adam Beneschan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox