TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
"Beard, Frank" <[log in to unmask]>
Thu, 27 Apr 2000 14:32:38 -0400
text/plain; charset="iso-8859-1"
"Beard, Frank" <[log in to unmask]>
text/plain (104 lines)
Thanks to everyone for their input.  It was very helpful.
Sorry it took so long to respond, but I was torn between
system delivery items and tracking down a new problem
related to this issue.

I'm using the Aonix ObjectAda compiler, version 7.1.2a.
From my cursory reading of the LRM and the fact that
the compiler didn't flag the code, led me to believe I
misunderstood the LRM.  But, as Daniel suggested, if
I change the anonymous declaration to a type, the
compiler properly flags the errors.

I changed the functions to procedures which led to a
new problem for which I need input.  I'm now getting a
Constraint_Error returned during runtime.  I have a
Configuration_Class with an internal protected type
that calls a List_Class which calls the protected
Garbage_Collection code that started this thread.

So my situation is as follows:

package body Configuration_Class is

     --+ Protected method
     procedure Initialize is
          --+ Read items form "config.ini"
          --+ and add the item to the list.
     end Initialize;

end Configuration_Class;

package body List_Class is

     procedure Add_Item() is
          --+ Call to protected procedure New_Item.
          Garbage_Collection.New_Item(the_List.head);  -- Constraint_Error
is raised.
     end Add_Item;

end List_Class;

If I change New_Item back to a function, the problem goes away.
Is Constraint_Error being raised because of what Section 9.5 (8-21)
of the LRM says.  The LRM says that Program_Error will be raised
if a bounded error is detected (9.5(17)).  But 9.5 (22) says:

     "From within a protected action, an internal call on a protected
     subprogram, or an external call on a protected subprogram with
     a different target object is not considered a potentially blocking

So, can the protected procedure Initialize, inside Configuration_Class,
call the protected procedure New_Item inside Garbage_Collection?


> -----Original Message-----
> From: C. Daniel Cooper [SMTP:[log in to unmask]]
> Sent: Saturday, April 22, 2000 9:05 AM
> To:   [log in to unmask]
> Subject:      Re: Protected Type question.
> > The next paragraph (9.5.1(2)) says that it
> > is illegal to write components of a protected object in a protected
> > function.
> >
> > His code does so in four places. Thus it is out and out illegal. It
> doesn't
> > compile with GNAT, but it does compile with at least one other compiler
> I
> > tried. (And presumably the one he is using as well).
> The Rational Apex compiler also correctly flags the four violations. But
> if he's using the compiler I think he is, the solution is to stay away
> from "single_protected_declarations", ie, use only a protected type for
> declaring a protected object; for some reason this avoids the bug. Thus,
> after making the following changes, the compiler should correctly flag
> the illegal assignments (the added word TYPE is capitalized below):
>     protected TYPE Protected_Collection_TYPE is --> make into type
>         function Destroy return natural;
>         procedure Dispose_Item(the_Pointer : in out Pointer);
>         function New_Item return Pointer;
>         function Size return natural;
>     private
>         garbage_Collector       : Pointer := null;
>         garbage_Collector_Count : natural := 0;
>     end Protected_Collection;
>     Protected_Collection : Protected_Collection_TYPE; --> use the type
> --
> C. Daniel Cooper ==========v=================v=======================v
> Adv Computing Technologist | processes       | All opinions are mine |
> 206-655-3519               | + architectures | and may not represent |
> [log in to unmask]  |   = systems     | those of my employer. |
> ===========================^=================^=======================^