https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124016

--- Comment #7 from Liam Powell <liam at liampwll dot com> ---
> Finalization on that type is also broken

I have a fix for this since I had to figure it out for my own types, it's a bit
of a hack but it works. The issue here is that finalization of Holder_Subpool
is nontrivial so the trick with setting the address in Create_Subpool does not
work. Feel free to disregard if this is already solved internally, but I figure
it may be useful if not:

Declare a package outside of the generic package like so:

package Dummy_Allocator is

   Next_Allocation_Address : System.Address with Thread_Local_Storage;

   type Dummy_Pool_Type is new Root_Storage_Pool with null record;

   overriding
   procedure Allocate
     (Pool                     : in out Dummy_Pool_Type;
      Storage_Address          : out System.Address;
      Size_In_Storage_Elements : Storage_Count;
      Alignment                : Storage_Count) is
   begin
      Storage_Address := Next_Allocation_Address;
   end Allocate;

   ...

end Dummy_Allocator;


Within the generic package create a dummy pool and a
Holder_Subpool_Access_Type:

Local_Dummy_Pool : Prunt.Dummy_Allocator.Dummy_Pool_Type;

type Pooled_Holder_Subpool_Handle is access Holder_Subpool
with Storage_Pool => Local_Dummy_Pool;


In Create_Subpool replace:

         Subpool : aliased Holder_Subpool :=
           (Root_Subpool with Start => Element_Start)
           with Address => Subpool_Start;

with something along the lines of:

Next_Allocation_Address := Subpool_Start;
Subpool : Pooled_Holder_Subpool_Handle :=
  new Holder_Subpool'(Root_Subpool with Start => Element_Start);


Lastly you of course need a Unchecked_Deallocation for the new access type.

Reply via email to