OSDN Git Service

2009-12-01 Thomas Quinot <quinot@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / s-memory.ads
index 524bd30..4af6002 100644 (file)
@@ -6,33 +6,26 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---                                                                          --
---             Copyright (C) 2001 Free Software Foundation, Inc.            --
---                                                                          --
--- This specification is derived from the Ada Reference Manual for use with --
--- GNAT. The copyright notice above, and the license provisions that follow --
--- apply solely to the  contents of the part following the private keyword. --
+--          Copyright (C) 2001-2009, Free Software Foundation, Inc.         --
 --                                                                          --
 -- 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- --
--- ware  Foundation;  either version 2,  or (at your option) any later ver- --
+-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
--- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
--- for  more details.  You should have  received  a copy of the GNU General --
--- Public License  distributed with GNAT;  see file COPYING.  If not, write --
--- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
--- MA 02111-1307, USA.                                                      --
+-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
+--                                                                          --
+-- As a special exception under Section 7 of GPL version 3, you are granted --
+-- additional permissions described in the GCC Runtime Library Exception,   --
+-- version 3.1, as published by the Free Software Foundation.               --
 --                                                                          --
--- As a special exception,  if other files  instantiate  generics from this --
--- unit, or you link  this unit with other files  to produce an executable, --
--- this  unit  does not  by itself cause  the resulting  executable  to  be --
--- covered  by the  GNU  General  Public  License.  This exception does not --
--- however invalidate  any other reasons why  the executable file  might be --
--- covered by the  GNU Public License.                                      --
+-- You should have received a copy of the GNU General Public License and    --
+-- a copy of the GCC Runtime Library Exception along with this program;     --
+-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
+-- <http://www.gnu.org/licenses/>.                                          --
 --                                                                          --
 -- GNAT was originally developed  by the GNAT team at  New York University. --
--- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
+-- Extensive contributions were provided by Ada Core Technologies Inc.      --
 --                                                                          --
 ------------------------------------------------------------------------------
 
 --  that the ali and object files for this unit are found in the object
 --  search path.
 
+--  This unit may be used directly from an application program by providing
+--  an appropriate WITH, and the interface can be expected to remain stable.
+
+pragma Compiler_Unit;
+
 package System.Memory is
    pragma Elaborate_Body;
 
    type size_t is mod 2 ** Standard'Address_Size;
+   --  Note: the reason we redefine this here instead of using the
+   --  definition in Interfaces.C is that we do not want to drag in
+   --  all of Interfaces.C just because System.Memory is used.
 
    function Alloc (Size : size_t) return System.Address;
-   --  malloc for use by GNAT, with error checking and task lockout,
-   --  as well as allocation tracking.
+   --  This is the low level allocation routine. Given a size in storage
+   --  units, it returns the address of a maximally aligned block of
+   --  memory. The implementation of this routine is guaranteed to be
+   --  task safe, and also aborts are deferred if necessary.
+   --
+   --  If size_t is set to size_t'Last on entry, then a Storage_Error
+   --  exception is raised with a message "object too large".
+   --
+   --  If size_t is set to zero on entry, then a minimal (but non-zero)
+   --  size block is allocated.
+   --
+   --  Note: this is roughly equivalent to the standard C malloc call
+   --  with the additional semantics as described above.
 
    procedure Free (Ptr : System.Address);
-   --  free for use by GNAT, with task lockout and allocation tracking.
+   --  This is the low level free routine. It frees a block previously
+   --  allocated with a call to Alloc. As in the case of Alloc, this
+   --  call is guaranteed task safe, and aborts are deferred.
+   --
+   --  Note: this is roughly equivalent to the standard C free call
+   --  with the additional semantics as described above.
 
    function Realloc
      (Ptr  : System.Address;
-      Size : size_t)
-      return System.Address;
-   --  realloc for use by GNAT, with error checking and task lockout.
+      Size : size_t) return System.Address;
+   --  This is the low level reallocation routine. It takes an existing
+   --  block address returned by a previous call to Alloc or Realloc,
+   --  and reallocates the block. The size can either be increased or
+   --  decreased. If possible the reallocation is done in place, so that
+   --  the returned result is the same as the value of Ptr on entry.
+   --  However, it may be necessary to relocate the block to another
+   --  address, in which case the information is copied to the new
+   --  block, and the old block is freed. The implementation of this
+   --  routine is guaranteed to be task safe, and also aborts are
+   --  deferred as necessary.
+   --
+   --  If size_t is set to size_t'Last on entry, then a Storage_Error
+   --  exception is raised with a message "object too large".
+   --
+   --  If size_t is set to zero on entry, then a minimal (but non-zero)
+   --  size block is allocated.
+   --
+   --  Note: this is roughly equivalent to the standard C realloc call
+   --  with the additional semantics as described above.
 
 private
 
-   pragma Export (C, Alloc, "__gnat_malloc");
-   pragma Export (C, Free, "__gnat_free");
+   --  The following names are used from the generated compiler code
+
+   pragma Export (C, Alloc,   "__gnat_malloc");
+   pragma Export (C, Free,    "__gnat_free");
    pragma Export (C, Realloc, "__gnat_realloc");
 
 end System.Memory;