3

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).

Álex
  • 1,587
  • 11
  • 17
  • I expect `No_Standard_Storage_Pools` (which seems to be GNAT-specific) only applies to this program unit? though why wouldn’t it apply to the instantiation, which is in this program unit? puzzling. – Simon Wright Jul 11 '18 at 15:44
  • Your comment gave me idea to move these pragmas to the partition-wide gnat.adc file, but no difference – Álex Jul 11 '18 at 21:17

1 Answers1

4

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.

Jacob Sparre Andersen
  • 6,733
  • 17
  • 22
  • This certainly seems to do the business: `anon.adb:6:04: instantiation error at a-coinve.adb:2295`, `anon.adb:6:04: allocation from empty storage pool` – Simon Wright Jul 11 '18 at 18:36
  • Yup, I was so fixated on doing it through Restrictions that I missed this one. Still, it has some unforeseen side effects on some initializations; I will probably open a new question about those. – Álex Jul 11 '18 at 21:17
  • As an appetizer, if you check that line you'll see that there's no explicit memory allocation: `return It : constant Iterator := (Limited_Controlled with Container => V, Index => No_Index)` – Álex Jul 11 '18 at 21:21