Search code examples
adadynamic-allocationrestrictions

Detect anonymous allocations in GNAT predefined libraries


So I'm developing an Ada 2012 library that should not perform allocations from default pools; all of those should use a user-specified storage pool.

I'm using some predefined packages and some of them obviously do not honor the rule: indefinite containers for example. I'd like to be sure I'm not using something that I should not.

I thought that some pragma Restrictions could help, but none of the following complain:

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;

I'm unsure why this is not, or if it should be, detected (even if precompiled, the compiler libraries should have their .ali files containing this info). If not, is there a way to do this?

This is the pointer type declared in a-coinve.ads without any storage pool: type Elements_Access is access all Elements_Type; This is used in the body with regular new.

(Edited to clarify that I mean allocations from default pools, not anonymous access types).


Solution

  • If I recall correctly you can override the default storage pool for all access types (including those declared inside the standard library).

    The first option I found was 13.11.3 in the LRM. It doesn't look quite like what I remember, but pragma Default_Storage_Pool (null); used as a configuration pragma should - as far as I can see - cover the run-time library as well.