首页 > 解决方案 > 检测 GNAT 预定义库中的匿名分配

问题描述

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

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

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

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

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

标签: adadynamic-allocationrestrictions

解决方案


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

我发现的第一个选项是 LRM 中的 13.11.3。它看起来不像我记得的那样,但pragma Default_Storage_Pool (null);用作配置编译指示应该——据我所知——也涵盖运行时库。


推荐阅读