Skip to content

Commit

Permalink
Try to use safer reference
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Feb 14, 2024
1 parent f1f7cb8 commit 359d475
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 26 deletions.
2 changes: 1 addition & 1 deletion deps/diskflags
Submodule diskflags updated 1 files
+1 −1 src/diskflags.ads
2 changes: 1 addition & 1 deletion src/alire/alire-dependencies-states.adb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ package body Alire.Dependencies.States is
Workspace : Any_Path)
return Stored_Release
is
Opt_Root : constant Roots.Optional.Root :=
Opt_Root : Roots.Optional.Root :=
Roots.Optional.Detect_Root (Workspace);
begin
if Opt_Root.Is_Valid then
Expand Down
12 changes: 6 additions & 6 deletions src/alire/alire-publish.adb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ package body Alire.Publish is
return +This.Path;
else
declare
Root : constant Roots.Optional.Root := Alire.Root.Current;
Root : Roots.Optional.Root := Alire.Root.Current;
begin
Check_Root_Status (+This.Path, Root, This.Options);
return Root.Value.Path;
Expand Down Expand Up @@ -155,7 +155,7 @@ package body Alire.Publish is
-- Generated_Filename --
------------------------

function Generated_Filename (This : Data) return String
function Generated_Filename (This : in out Data) return String
is (TOML_Index.Manifest_File
(This.Root.Value.Name,
This.Root.Value.Release.Version));
Expand All @@ -164,7 +164,7 @@ package body Alire.Publish is
-- Generated_Manifest --
------------------------

function Generated_Manifest (This : Data) return Absolute_Path
function Generated_Manifest (This : in out Data) return Absolute_Path
is (This.Root.Value.Working_Folder
/ Paths.Release_Folder_Inside_Working_Folder
/ This.Generated_Filename);
Expand Down Expand Up @@ -395,7 +395,7 @@ package body Alire.Publish is
-- Will have raised if the release is not loadable or incomplete
else
declare
Root : constant Roots.Optional.Root := Alire.Root.Current;
Root : Roots.Optional.Root := Alire.Root.Current;
begin
case Root.Status is
when Outside =>
Expand Down Expand Up @@ -495,7 +495,7 @@ package body Alire.Publish is

procedure Generate_Index_Manifest (Context : in out Data) is
User_Manifest : constant Any_Path := Packaged_Manifest (Context);
Workspace : constant Roots.Optional.Root := Root.Current;
Workspace : Roots.Optional.Root := Root.Current;
begin
if not GNAT.OS_Lib.Is_Read_Accessible_File (User_Manifest) then
Raise_Checked_Error
Expand Down Expand Up @@ -1039,7 +1039,7 @@ package body Alire.Publish is
Revision : String := "HEAD";
Options : All_Options := New_Options)
is
Root : constant Roots.Optional.Root := Roots.Optional.Search_Root (Path);
Root : Roots.Optional.Root := Roots.Optional.Search_Root (Path);
Git : constant VCSs.Git.VCS := VCSs.Git.Handler;

Subdir : Unbounded_Relative_Path;
Expand Down
8 changes: 4 additions & 4 deletions src/alire/alire-publish.ads
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,27 @@ private
-- Branch_Name --
-----------------

function Branch_Name (This : Data) return String
function Branch_Name (This : in out Data) return String
is (Branch_Name (This.Root.Value.Release.Milestone));

-------------
-- PR_Name --
-------------

function PR_Name (This : Data) return String
function PR_Name (This : in out Data) return String
is (This.Root.Value.Name.As_String & " "
& This.Root.Value.Release.Version.Image);

------------------------
-- Generated_Filename --
------------------------

function Generated_Filename (This : Data) return String;
function Generated_Filename (This : in out Data) return String;

------------------------
-- Generated_Manifest --
------------------------

function Generated_Manifest (This : Data) return Absolute_Path;
function Generated_Manifest (This : in out Data) return Absolute_Path;

end Alire.Publish;
7 changes: 6 additions & 1 deletion src/alire/alire-root.adb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ package body Alire.Root is
-------------

function Current return Roots.Root
is (Roots.Optional.Detect_Root (Directories.Detect_Root_Path).Value);
is
Optional_Root : Roots.Optional.Root :=
Roots.Optional.Detect_Root (Directories.Detect_Root_Path);
begin
return Optional_Root.Value;
end Current;

end Alire.Root;
2 changes: 1 addition & 1 deletion src/alire/alire-roots-editable.adb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ package body Alire.Roots.Editable is
Path : Any_Path)
return Crate_Name
is
Pin_Root : constant Optional.Root := Optional.Detect_Root (Path);
Pin_Root : Optional.Root := Optional.Detect_Root (Path);

-------------------------
-- Pin_Is_Parent_Crate --
Expand Down
7 changes: 4 additions & 3 deletions src/alire/alire-roots-optional.adb
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ package body Alire.Roots.Optional is
-- Value --
-----------

function Value (This : Root) return Reference
function Value (This : in out Root) return Reference
is
begin
This.Assert;
-- The following Unrestricted_Access cannot fail as we just asserted
-- the value is stored.
return Reference'(Ptr => This.Data.Value'Unrestricted_Access);
return Ref : constant Reference :=
Reference'(Ptr => This.Data.Value'Unrestricted_Access);
end Value;

---------------------
Expand Down Expand Up @@ -166,7 +167,7 @@ package body Alire.Roots.Optional is
-- Updatable_Dependency --
--------------------------

function Updatable_Dependency (This : Root)
function Updatable_Dependency (This : in out Root)
return Dependencies.Dependency
is (Dependencies.New_Dependency
(This.Value.Release.Element.Name,
Expand Down
4 changes: 2 additions & 2 deletions src/alire/alire-roots-optional.ads
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ package Alire.Roots.Optional is
function Outside (This : Root) return Boolean;
-- True when there is no root at all, broken or valid

function Value (This : Root) return Reference with
function Value (This : in out Root) return Reference with
Pre => This.Is_Valid;

function Brokenness (This : Root) return String with
Expand All @@ -55,7 +55,7 @@ package Alire.Roots.Optional is

-- UTILITIES

function Updatable_Dependency (This : Root)
function Updatable_Dependency (This : in out Root)
return Dependencies.Dependency
with Pre => This.Is_Valid;
-- If This.Is_Valid, get the corresponding updatable
Expand Down
10 changes: 7 additions & 3 deletions src/alire/alire-roots.adb
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ package body Alire.Roots is
declare
use Containers.Crate_Name_Sets;
use Semver.Extended;
Target : constant Optional.Root :=
Target : Optional.Root :=
Optional.Detect_Root (Pin.Path);
begin

Expand Down Expand Up @@ -1139,7 +1139,11 @@ package body Alire.Roots is
---------------

function Load_Root (Path : Any_Path) return Root
is (Roots.Optional.Detect_Root (Path).Value);
is
Optional_Root : Optional.Root := Optional.Detect_Root (Path);
begin
return Optional_Root.Value;
end Load_Root;

------------------------------
-- Export_Build_Environment --
Expand Down Expand Up @@ -1187,7 +1191,7 @@ package body Alire.Roots is
-- Try to detect a root in this folder

declare
Opt : constant Optional.Root :=
Opt : Optional.Root :=
Optional.Detect_Root (Full_Name (Item));
begin
if Opt.Is_Valid then
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-user_pins.adb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ package body Alire.User_Pins is
-- At this point, we have the sources at Destination. Last checks ensue.

declare
Root : constant Roots.Optional.Root :=
Root : Roots.Optional.Root :=
Roots.Optional.Detect_Root (Destination);
begin

Expand Down
2 changes: 1 addition & 1 deletion src/alr/alr-commands-init.adb
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ package body Alr.Commands.Init is
---------------------

procedure Generate_Config is
Root : constant Alire.Roots.Optional.Root :=
Root : Alire.Roots.Optional.Root :=
Alire.Roots.Optional.Detect_Root (+Directory.Full_Name);
begin
Root.Value.Build_Prepare (Saved_Profiles => False,
Expand Down
2 changes: 1 addition & 1 deletion src/alr/alr-commands-version.adb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ package body Alr.Commands.Version is
Indexes : constant Alire.Index_On_Disk.Loading.Set :=
Alire.Index_On_Disk.Loading.Find_All
(Alire.Config.Edit.Indexes_Directory, Index_Outcome);
Root : constant Alire.Roots.Optional.Root :=
Root : Alire.Roots.Optional.Root :=
Alire.Roots.Optional.Search_Root (Alire.Directories.Current);

Build_Path : constant String :=
Expand Down
6 changes: 5 additions & 1 deletion src/alr/alr-commands.adb
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,11 @@ package body Alr.Commands is
Cmd.Requires_Workspace;
end if;

return Cmd.Optional_Root.Value;
return R : constant Alire.Roots.Optional.Reference :=
(Ptr => Cmd.Optional_Root.Value.Ptr.all'Unchecked_Access);
-- Workaround for bug (?) in GNAT 11 about dangling pointers. It should
-- simply be:
-- return Cmd.Optional_Root.Value;
end Root;

---------
Expand Down

0 comments on commit 359d475

Please sign in to comment.