Commit ae3a2b54 by Bob Duff Committed by Pierre-Marie de Rodat

[Ada] Strengthen Locked flag

This patch strengthens the Locked flag, by Asserting that it is False on
operations that might cause reallocation.

No change in behavior (except in the presence of compiler bugs), so no
test.

2019-08-14  Bob Duff  <duff@adacore.com>

gcc/ada/

	* table.adb: Assert that the table is not locked when increasing
	Last, even if it doesn't cause reallocation.  In other words,
	assert that on operations that MIGHT cause reallocation.
	* table.ads: Fix comment accordingly.

From-SVN: r274463
parent 27af94e7
2019-08-14 Bob Duff <duff@adacore.com>
* table.adb: Assert that the table is not locked when increasing
Last, even if it doesn't cause reallocation. In other words,
assert that on operations that MIGHT cause reallocation.
* table.ads: Fix comment accordingly.
2019-08-14 Arnaud Charlet <charlet@adacore.com> 2019-08-14 Arnaud Charlet <charlet@adacore.com>
* doc/gnat_ugn/gnat_and_program_execution.rst: Remove * doc/gnat_ugn/gnat_and_program_execution.rst: Remove
......
...@@ -80,6 +80,7 @@ package body Table is ...@@ -80,6 +80,7 @@ package body Table is
procedure Append (New_Val : Table_Component_Type) is procedure Append (New_Val : Table_Component_Type) is
begin begin
pragma Assert (not Locked);
Set_Item (Table_Index_Type (Last_Val + 1), New_Val); Set_Item (Table_Index_Type (Last_Val + 1), New_Val);
end Append; end Append;
...@@ -120,6 +121,7 @@ package body Table is ...@@ -120,6 +121,7 @@ package body Table is
procedure Increment_Last is procedure Increment_Last is
begin begin
pragma Assert (not Locked);
Last_Val := Last_Val + 1; Last_Val := Last_Val + 1;
if Last_Val > Max then if Last_Val > Max then
...@@ -384,6 +386,8 @@ package body Table is ...@@ -384,6 +386,8 @@ package body Table is
procedure Set_Last (New_Val : Table_Index_Type) is procedure Set_Last (New_Val : Table_Index_Type) is
begin begin
pragma Assert (Int (New_Val) <= Last_Val or else not Locked);
if Int (New_Val) < Last_Val then if Int (New_Val) < Last_Val then
Last_Val := Int (New_Val); Last_Val := Int (New_Val);
......
...@@ -130,14 +130,15 @@ package Table is ...@@ -130,14 +130,15 @@ package Table is
-- First .. Last. -- First .. Last.
Locked : Boolean := False; Locked : Boolean := False;
-- Table expansion is permitted only if this switch is set to False. A -- Increasing the value of Last is permitted only if this switch is set
-- client may set Locked to True, in which case any attempt to expand -- to False. A client may set Locked to True, in which case any attempt
-- the table will cause an assertion failure. Note that while a table -- to increase the value of Last (which might expand the table) will
-- is locked, its address in memory remains fixed and unchanging. This -- cause an assertion failure. Note that while a table is locked, its
-- feature is used to control table expansion during Gigi processing. -- address in memory remains fixed and unchanging. This feature is used
-- Gigi assumes that tables other than the Uint and Ureal tables do -- to control table expansion during Gigi processing. Gigi assumes that
-- not move during processing, which means that they cannot be expanded. -- tables other than the Uint and Ureal tables do not move during
-- The Locked flag is used to enforce this restriction. -- processing, which means that they cannot be expanded. The Locked
-- flag is used to enforce this restriction.
procedure Init; procedure Init;
-- This procedure allocates a new table of size Initial (freeing any -- This procedure allocates a new table of size Initial (freeing any
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment