Ada - 无约束对象的队列数组导致Storage_Error - 如何解决?

问题描述 投票:2回答:1

所以,免责声明,我现在只使用Ada几个星期......我希望有一个noob错误导致这个。

所以(匿名)代码我有......

with Ada.Text_IO; use Ada.Text_IO;

with Ada.Containers.Synchronized_Queue_Interfaces;
with Ada.Containers.Bounded_Synchronized_Queues;

procedure Hello is
  type ID_Type is ( Invalid_Id,
                    Config_Id);

  for ID_Type use ( Invalid_Id => 16#00#,
                    Config_Id => 16#11#  );
  for ID_Type'Size use 8;                  

  type Config_Type is 
    record
      data : Integer;
    end record;

  type Data_Type (i : ID_Type := Invalid_Id) is 
    record
      Id : ID_Type := i;

      case i is
        when Invalid_Id => null;
        when Config_Id => config : Config_Type;
        when others => null;
      end case; 
    end record with Unchecked_Union, Convention => C;

  package Queue_Interface is
    new Ada.Containers.Synchronized_Queue_Interfaces(Data_Type);

  package Data_Queue is 
    new Ada.Containers.Bounded_Synchronized_Queues
      ( Queue_Interfaces => Queue_Interface,
        Default_Capacity => 1);

  Queue_Array : array(1..1) of Data_Queue.Queue;

begin

  Put_Line("Queue_Array(1)'Size = " & Integer'Image(Queue_Array(1)'Size));

end Hello;

在在线编译器(GNAT 7.1.1)上,这会触发:引发STORAGE_ERROR:s-intman.adb:136显式引发

预期用途是与从串行端口提取数据的C级驱动程序连接。 (因此unchecked_union和其他表示条款)

尝试使用Indefinite_Holder进行包装,假设无限期问题来自Unconstrained类型......并且得到了相同的错误。以为我不需要它,因为虽然它是一个不受约束的变体,但它的大小是确定的。同样的事情,无论如何。

另外值得注意的是:test1:array(ID_Type)Data_Type; - 工作test2:Data_Queue.Queue; - 工作test3:array(1 .. 2)Data_Queue.Queue; - Storage_Error

我究竟做错了什么?

arrays generics containers ada variant
1个回答
2
投票

Bounded_Synchronized_Queue的定义是

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

看起来GNAT正在尝试为数组大小的所有潜在排列分配大小,从而导致类型非常大的类型。由于这是一种有限的类型,我不确定它是否仍然必须这样做(所以可能是一个错误)。

您可以通过将声明的discriminant更改为具有特定的constraint来修复它:

-- create an array of queues
Queue_Array : array(ID_Type) of ID_Holder_Queue.Queue
    (Capacity => 16,
     Ceiling  => System.Priority'Last);

在系统内;

这应该会删除您的存储错误。如果您使用GNAT编译器,This可能是相关的。

© www.soinside.com 2019 - 2024. All rights reserved.