This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][RFC] Change interface of allocate{,64}_array


This is a prototype for conversion of the allocator library interface
to return a pointer to the allocated memory and to not pass the old
pointer per reference.

Prototype because it only changes allocate{,64}_array and because it
doesn't address the fact that this changes the library ABI (we might
sneak this into 4.2 where we bump the library version, for a
symbol-versioning compatible change we'd need to change the symbol
name and continue to provide the old interface).

Bootstrapped and tested on x86_64-unknown-linux-gnu.  I put this
change on the Polyhedron tester together with the sincos patches
for tonight.

Thanks,
Richard.

2006-12-10  Richard Guenther  <rguenther@suse.de>

	PR fortran/30115
	* runtime/memory.c (allocate_array): Change interface to return
	the pointer to the allocated memory and to receive the old
	pointer by value.
	(allocate64_array): Likewise.

	* trans-array.c (gfc_array_allocate): Adjust for the change
	in the interface to allocate{,64}_array.
	* trans-decl.c (gfc_build_builtin_function_decls): Likewise.
	Mark allocate{,64}_array as following malloc semantics.  Add
	pointer to stat argument to the function decls.

Index: libgfortran/runtime/memory.c
===================================================================
*** libgfortran/runtime/memory.c	(revision 119706)
--- libgfortran/runtime/memory.c	(working copy)
*************** allocate64 (void **mem, GFC_INTEGER_8 si
*** 237,292 ****
     allocatable array.  If the array is currently allocated, it is
     an error to allocate it again.  32-bit version.  */
  
! extern void allocate_array (void **, GFC_INTEGER_4, GFC_INTEGER_4 *);
  export_proto(allocate_array);
  
! void
! allocate_array (void **mem, GFC_INTEGER_4 size, GFC_INTEGER_4 * stat)
  {
!   if (*mem == NULL)
      {
!       allocate (mem, size, stat);
!       return;
      }
    if (stat)
      {
!       free (*mem);
!       allocate (mem, size, stat);
        *stat = ERROR_ALLOCATION;
!       return;
      }
    else
      runtime_error ("Attempting to allocate already allocated array.");
  
!   return;
  }
  
  /* Function to call in an ALLOCATE statement when the argument is an
     allocatable array.  If the array is currently allocated, it is
     an error to allocate it again.  64-bit version.  */
  
! extern void allocate64_array (void **, GFC_INTEGER_8, GFC_INTEGER_4 *);
  export_proto(allocate64_array);
  
! void
! allocate64_array (void **mem, GFC_INTEGER_8 size, GFC_INTEGER_4 * stat)
  {
!   if (*mem == NULL)
      {
!       allocate64 (mem, size, stat);
!       return;
      }
    if (stat)
      {
!       free (*mem);
!       allocate (mem, size, stat);
        *stat = ERROR_ALLOCATION;
!       return;
      }
    else
      runtime_error ("Attempting to allocate already allocated array.");
  
!   return;
  }
  
  /* User-deallocate; pointer is NULLified. */
--- 237,296 ----
     allocatable array.  If the array is currently allocated, it is
     an error to allocate it again.  32-bit version.  */
  
! extern void *allocate_array (void *, GFC_INTEGER_4, GFC_INTEGER_4 *);
  export_proto(allocate_array);
  
! void *
! allocate_array (void *mem, GFC_INTEGER_4 size, GFC_INTEGER_4 * stat)
  {
!   if (mem == NULL)
      {
!       allocate (&mem, size, stat);
!       return mem;
      }
    if (stat)
      {
!       free (mem);
!       mem = NULL;
!       allocate (&mem, size, stat);
        *stat = ERROR_ALLOCATION;
!       return mem;
      }
    else
      runtime_error ("Attempting to allocate already allocated array.");
  
!   /* Unreachable.  */
!   return mem;
  }
  
  /* Function to call in an ALLOCATE statement when the argument is an
     allocatable array.  If the array is currently allocated, it is
     an error to allocate it again.  64-bit version.  */
  
! extern void *allocate64_array (void *, GFC_INTEGER_8, GFC_INTEGER_4 *);
  export_proto(allocate64_array);
  
! void *
! allocate64_array (void *mem, GFC_INTEGER_8 size, GFC_INTEGER_4 * stat)
  {
!   if (mem == NULL)
      {
!       allocate64 (&mem, size, stat);
!       return mem;
      }
    if (stat)
      {
!       free (mem);
!       mem = NULL;
!       allocate (&mem, size, stat);
        *stat = ERROR_ALLOCATION;
!       return mem;
      }
    else
      runtime_error ("Attempting to allocate already allocated array.");
  
!   /* Unreachable.  */
!   return mem;
  }
  
  /* User-deallocate; pointer is NULLified. */
Index: gcc/fortran/trans-array.c
===================================================================
*** gcc/fortran/trans-array.c	(revision 119706)
--- gcc/fortran/trans-array.c	(working copy)
*************** gfc_array_allocate (gfc_se * se, gfc_exp
*** 3355,3362 ****
  			      lower, upper, &se->pre);
  
    /* Allocate memory to store the data.  */
!   tmp = gfc_conv_descriptor_data_addr (se->expr);
!   pointer = gfc_evaluate_now (tmp, &se->pre);
  
    if (TYPE_PRECISION (gfc_array_index_type) == 32)
      {
--- 3355,3370 ----
  			      lower, upper, &se->pre);
  
    /* Allocate memory to store the data.  */
!   if (allocatable_array)
!     {
!       pointer = gfc_conv_descriptor_data_get (se->expr);
!       STRIP_NOPS (pointer);
!     }
!   else
!     {
!       tmp = gfc_conv_descriptor_data_addr (se->expr);
!       pointer = gfc_evaluate_now (tmp, &se->pre);
!     }
  
    if (TYPE_PRECISION (gfc_array_index_type) == 32)
      {
*************** gfc_array_allocate (gfc_se * se, gfc_exp
*** 3379,3384 ****
--- 3387,3394 ----
    tmp = gfc_chainon_list (tmp, size);
    tmp = gfc_chainon_list (tmp, pstat);
    tmp = build_function_call_expr (allocate, tmp);
+   if (allocatable_array)
+     tmp = build2 (MODIFY_EXPR, void_type_node, pointer, tmp);
    gfc_add_expr_to_block (&se->pre, tmp);
  
    tmp = gfc_conv_descriptor_offset (se->expr);
Index: gcc/fortran/trans-decl.c
===================================================================
*** gcc/fortran/trans-decl.c	(revision 119706)
--- gcc/fortran/trans-decl.c	(working copy)
*************** gfc_build_builtin_function_decls (void)
*** 2314,2326 ****
  
    gfor_fndecl_allocate_array =
      gfc_build_library_function_decl (get_identifier (PREFIX("allocate_array")),
! 				     void_type_node, 2, ppvoid_type_node,
! 				     gfc_int4_type_node);
  
    gfor_fndecl_allocate64_array =
      gfc_build_library_function_decl (get_identifier (PREFIX("allocate64_array")),
! 				     void_type_node, 2, ppvoid_type_node,
! 				     gfc_int8_type_node);
  
    gfor_fndecl_deallocate =
      gfc_build_library_function_decl (get_identifier (PREFIX("deallocate")),
--- 2314,2328 ----
  
    gfor_fndecl_allocate_array =
      gfc_build_library_function_decl (get_identifier (PREFIX("allocate_array")),
! 				     pvoid_type_node, 3, pvoid_type_node,
! 				     gfc_int4_type_node, gfc_pint4_type_node);
!   DECL_IS_MALLOC (gfor_fndecl_allocate_array) = 1;
  
    gfor_fndecl_allocate64_array =
      gfc_build_library_function_decl (get_identifier (PREFIX("allocate64_array")),
! 				     pvoid_type_node, 3, pvoid_type_node,
! 				     gfc_int8_type_node, gfc_pint4_type_node);
!   DECL_IS_MALLOC (gfor_fndecl_allocate64_array) = 1;
  
    gfor_fndecl_deallocate =
      gfc_build_library_function_decl (get_identifier (PREFIX("deallocate")),


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]