comp.lang.ada
 help / color / mirror / Atom feed
* access check failure in "adjust" of a controlled type in aggregate assignement but not with normal variable assignement
@ 2018-05-17 17:21 Mehdi Saada
  2018-05-17 18:48 ` Niklas Holsti
  0 siblings, 1 reply; 4+ messages in thread
From: Mehdi Saada @ 2018-05-17 17:21 UTC (permalink / 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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: access check failure in "adjust" of a controlled type in aggregate assignement but not with normal variable assignement
  2018-05-17 17:21 access check failure in "adjust" of a controlled type in aggregate assignement but not with normal variable assignement Mehdi Saada
@ 2018-05-17 18:48 ` Niklas Holsti
  2018-05-17 22:38   ` Mehdi Saada
  0 siblings, 1 reply; 4+ messages in thread
From: Niklas Holsti @ 2018-05-17 18:48 UTC (permalink / raw)


On 18-05-17 20:21 , Mehdi Saada wrote:
> 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;

Your Adjust never reassigns Matrice.First, so it continues to refer to 
the original list, not to the new deep copy.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: access check failure in "adjust" of a controlled type in aggregate assignement but not with normal variable assignement
  2018-05-17 18:48 ` Niklas Holsti
@ 2018-05-17 22:38   ` Mehdi Saada
  2018-05-18  0:13     ` Mehdi Saada
  0 siblings, 1 reply; 4+ messages in thread
From: Mehdi Saada @ 2018-05-17 22:38 UTC (permalink / raw)


Right, also I saw that the "+" operator merely adds the parameters numbers of elements, which is a ridiculous... Thanks !


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: access check failure in "adjust" of a controlled type in aggregate assignement but not with normal variable assignement
  2018-05-17 22:38   ` Mehdi Saada
@ 2018-05-18  0:13     ` Mehdi Saada
  0 siblings, 0 replies; 4+ messages in thread
From: Mehdi Saada @ 2018-05-18  0:13 UTC (permalink / raw)


It's corrected now.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-18  0:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-17 17:21 access check failure in "adjust" of a controlled type in aggregate assignement but not with normal variable assignement Mehdi Saada
2018-05-17 18:48 ` Niklas Holsti
2018-05-17 22:38   ` Mehdi Saada
2018-05-18  0:13     ` Mehdi Saada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox