comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: "STORAGE_ERROR : s-intman.adb:139 explicit raise" from record containing a queue from Ada.Containers.Bounded_Synchronized_Queues in Gnat Ada 2014
Date: Sat, 28 Feb 2015 15:59:41 -0600
Date: 2015-02-28T15:59:41-06:00	[thread overview]
Message-ID: <85egp9bstu.fsf@stephe-leake.org> (raw)
In-Reply-To: afb441db-d190-422a-992f-7fd8eebeb56a@googlegroups.com

jocpaine@googlemail.com writes:

> with Ada.Containers.Synchronized_Queue_Interfaces;
> with Ada.Containers.Bounded_Synchronized_Queues;
>
> procedure Q11 is
>
>  package Job_Queues_Interface is
>     new Ada.Containers.Synchronized_Queue_Interfaces
>       ( Element_Type => Integer );
>
>   package Job_Queues_Package is
>     new Ada.Containers.Bounded_Synchronized_Queues
>       ( Queue_Interfaces => Job_Queues_Interface
>       , Default_Capacity => 100 
>       );
>
>   subtype My_Queue_Type is Job_Queues_Package.Queue; 
>       
>   type Job_Queue is record
>                       Queue: My_Queue_Type;
>                     end record;  
>
>   q : Job_Queue;
>   -- This is the line causing the error. If I give q
>   -- My_Queue_Type instead, the error doesn't happen.

The declaration of Queue in Ada.Containers.Bounded_Synchronized_Queues
includes:

   protected type Queue
     (Capacity : Count_Type := Default_Capacity;
      Ceiling  : System.Any_Priority := Default_Ceiling)
   with
     Priority => Ceiling
   is new Queue_Interfaces.Queue with
   ...
   private
      List : Implementation.List_Type (Capacity);
   end Queue;

List_Type is:

      type List_Type (Capacity : Count_Type) is tagged limited record
         First, Last : Count_Type := 0;
         Length      : Count_Type := 0;
         Max_Length  : Count_Type := 0;
         Elements    : Element_Array (1 .. Capacity) := (others => <>);
      end record;

So if Capacity is large enough, you'll get Storage_Error.

In type Queue, the discriminant Capacity has a default value, which
means it is allowed to be changed, in particular to Count_Type'last,
which is large enough to cause Storage_Error. 

If you change Default_Capacity to 2**31-1, you get Storage_Error for
either case.

So apparently GNAT allocates the largest allowed space when you use type
Job_Queue, but when you use the type My_Queu_Type, it allocates the
space needed for the current discriminant.

-- 
-- Stephe

  parent reply	other threads:[~2015-02-28 21:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-27 19:26 "STORAGE_ERROR : s-intman.adb:139 explicit raise" from record containing a queue from Ada.Containers.Bounded_Synchronized_Queues in Gnat Ada 2014 jocpaine
2015-02-28 10:08 ` Simon Wright
2015-02-28 21:59 ` Stephen Leake [this message]
2015-03-01 12:07   ` AdaMagica
2015-03-02  8:55 ` Egil H H
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox