From: Mehdi Saada <00120260a@gmail.com>
Subject: access check failure in "adjust" of a controlled type in aggregate assignement but not with normal variable assignement
Date: Thu, 17 May 2018 10:21:11 -0700 (PDT)
Date: 2018-05-17T10:21:11-07:00 [thread overview]
Message-ID: <3c1a0e9a-6238-4cf3-b978-f08fd7dd420d@googlegroups.com> (raw)
I used controlled type to implement deep copy of lists, but I get
raised PROGRAM_ERROR : adjust/finalize raised CONSTRAINT_ERROR: essai2.adb:61 access check failed
The definitions:
type Matrice_Creuse is new Ada.Finalization.Controlled with record
First : Node_Access;
Number : Natural := 0;
Max_Indices : T_INDICE := (0, 0);
end record;
type t_indice is record
Column, Line : natural ;
end record;
procedure Adjust (Matrice : in out Matrice_Creuse) is
begin
if Matrice.First = null then return;
else
declare
Iter : Node_Access := Matrice.First;
Iter_R : Node_Access := new Node'(Iter.all);
begin
for I in 2 .. Matrice.Number loop
pragma Assert (Iter /= null); -- useless
Iter_R.Next := new Node'(Iter.Next.all);
Iter := Iter.Next; -- LINE 61 HEEEEREEE
Iter_R := Iter_R.Next;
end loop;
end;
end if;
end Adjust;
As you can see it SEEMS to work:
the code below:
Put_Line ("M1");
Put_Line (M1);
Put_Line ("M3 initialized to M1 ");
Put_Line (M3);
M1 := Create_Matrice ((1 => MN ((5, 6), 1)));
Put_Line ("M1 modified");
Put_Line(M1);
Put_Line ("M3 after modification of M1");
Put_Line (M3);
gives:
M1
0 0 0
0 0 0
0 0 0
0 0 0
0 8 9
M3 initialized to M1
0 0 0
0 0 0
0 0 0
0 0 0
0 8 9
M1 modified
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 1
M3 after modification of M1
0 0 0
0 0 0
0 0 0
0 0 0
0 8 9
I verified the figures, the right values are set where they are meant to be. "Adjust" did work in making a deep copy of M1 into M3. So what's wrong ?
It's the "+" function that errs, and exactly this line:
R := (Controlled with Number => NumBer_R, MAx_Indices => (Natural'Max(M1.Max_Indices.Column, M2.Max_Indices.Column), Natural'Max(M1.Max_Indices.Line, M2.Max_Indices.Line)), FIrst => R.First);
Is there something obviously wrong here I don't see ?
The entire code is here, if needed:
http://depositfiles.com/files/dmizq837v
This is the version that fails.
next reply other threads:[~2018-05-17 17:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-17 17:21 Mehdi Saada [this message]
2018-05-17 18:48 ` access check failure in "adjust" of a controlled type in aggregate assignement but not with normal variable assignement Niklas Holsti
2018-05-17 22:38 ` Mehdi Saada
2018-05-18 0:13 ` Mehdi Saada
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox