代码之家  ›  专栏  ›  技术社区  ›  Álex

在gnat预定义库中检测匿名分配

  •  1
  • Álex  · 技术社区  · 7 年前

    因此,我正在开发一个不应该从默认池执行分配的ada 2012库;所有这些库都应该使用用户指定的存储池。

    我使用了一些预定义的包,其中一些显然不遵守规则:例如不确定的容器。我想确定我没有用我不该用的东西。

    我认为一些pragma限制可能会有帮助,但以下这些都没有抱怨:

    pragma Restrictions (No_Allocators);
    pragma Restrictions (No_Anonymous_Allocators);
    pragma Restrictions (No_Implicit_Heap_Allocations);
    pragma Restrictions (No_Standard_Allocators_After_Elaboration);
    pragma Restrictions (No_Standard_Storage_Pools);
    
    with Ada.Containers.Indefinite_Vectors;
    
    procedure Anon is
       package Vectors is new Ada.Containers.Indefinite_Vectors (Positive, String);
    
       V : Vectors.Vector;
    begin
       V.Append ("Mmm");
    end Anon;
    

    我不确定为什么没有或者应该检测到(即使是预编译的,编译器库也应该有包含此信息的.ali文件)。如果没有,有办法吗?

    这是在中声明的指针类型 a-coinve.ads 没有任何存储池: type Elements_Access is access all Elements_Type; 这是用在身体里的 new .

    (编辑以澄清我指的是来自默认池的分配,而不是匿名访问类型)。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Jacob Sparre Andersen    7 年前

    如果我没记错的话,您可以覆盖 全部的 访问类型(包括在标准库中声明的类型)。

    我找到的第一个选择是13.11.3。看起来不像我记得的,但是 pragma Default_Storage_Pool (null); 据我所见,用作配置的pragma也应该覆盖运行时库。