检测 GNAT 预定义库中的匿名分配

Detect anonymous allocations in GNAT predefined libraries

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

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

我认为一些 pragma Restrictions 会有所帮助,但是 none 以下抱怨:

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

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

如果我没记错的话,您可以覆盖所有 访问类型(包括在标准库中声明的那些)的默认存储池。

我找到的第一个选项是 LRM 中的 13.11.3。它看起来不像我记忆中的那样,但是 pragma Default_Storage_Pool (null); 用作配置 pragma 应该 - 据我所知 - 也涵盖 运行-time 库。