Patchwork [Ada] Make GNAT.AWK API compatible with Ada 2005.

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 3, 2011, 2:54 p.m.
Message ID <20110803145431.GA18376@adacore.com>
Download mbox | patch
Permalink /patch/108248/
State New
Headers show

Comments

Arnaud Charlet - Aug. 3, 2011, 2:54 p.m.
Ada 2005 does not allow returning limited objects from a function. As this
interface should be callable from Ada 95 and Ada 2005 we have changed
the API to return access type instead.

This minor upward compatibility issue is very easy to fix. A ".all" needs
to be added to calls to routines Current_Session and Default_Session.

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-03  Pascal Obry  <obry@adacore.com>

	* g-awk.adb, g-awk.ads: Make GNAT.AWK API compatible with Ada 2005.
	(Current_Session): Return a not null access to Session_Type.
	(Default_Session): Likewise.

Patch

Index: g-awk.adb
===================================================================
--- g-awk.adb	(revision 177274)
+++ g-awk.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---                     Copyright (C) 2000-2010, AdaCore                     --
+--                     Copyright (C) 2000-2011, AdaCore                     --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -29,11 +29,6 @@ 
 --                                                                          --
 ------------------------------------------------------------------------------
 
-pragma Ada_95;
---  This is needed because the pragmas Warnings (Off) in Current_Session and
---  Default_Session (see below) do not work when compiling clients of this
---  package that instantiate generic units herein.
-
 with Ada.Exceptions;
 with Ada.Text_IO;
 with Ada.Strings.Unbounded;
@@ -735,30 +730,18 @@ 
    -- Current_Session --
    ---------------------
 
-   function Current_Session return Session_Type is
+   function Current_Session return not null access Session_Type is
    begin
-      pragma Warnings (Off);
-      return Cur_Session;
-      --  ???The above return statement violates the Ada 2005 rule forbidding
-      --  copying of limited objects (see RM-7.5(2.8/2)). When compiled with
-      --  -gnatg, the compiler gives a warning instead of an error, so we can
-      --  turn it off.
-      pragma Warnings (On);
+      return Cur_Session.Self;
    end Current_Session;
 
    ---------------------
    -- Default_Session --
    ---------------------
 
-   function Default_Session return Session_Type is
+   function Default_Session return not null access Session_Type is
    begin
-      pragma Warnings (Off);
-      return Def_Session;
-      --  ???The above return statement violates the Ada 2005 rule forbidding
-      --  copying of limited objects (see RM-7.5(2.8/2)). When compiled with
-      --  -gnatg, the compiler gives a warning instead of an error, so we can
-      --  turn it off.
-      pragma Warnings (On);
+      return Def_Session.Self;
    end Default_Session;
 
    --------------------
Index: g-awk.ads
===================================================================
--- g-awk.ads	(revision 177281)
+++ g-awk.ads	(working copy)
@@ -229,12 +229,12 @@ 
    --  Set the session to be used by default. This file will be used when the
    --  Session parameter in following services is not specified.
 
-   function Current_Session return Session_Type;
+   function Current_Session return not null access Session_Type;
    --  Returns the session used by default by all services. This is the
    --  latest session specified by Set_Current service or the session
    --  provided by default with this implementation.
 
-   function Default_Session return Session_Type;
+   function Default_Session return not null access Session_Type;
    --  Returns the default session provided by this package. Note that this is
    --  the session return by Current_Session if Set_Current has not been used.
 
@@ -633,6 +633,7 @@ 
 
    type Session_Type is new Ada.Finalization.Limited_Controlled with record
       Data : Session_Data_Access;
+      Self : not null access Session_Type := Session_Type'Unchecked_Access;
    end record;
 
    procedure Initialize (Session : in out Session_Type);