From db430f6a2a5997bed3109eff088c4e86020378d0 Mon Sep 17 00:00:00 2001 From: Janne Blomqvist Date: Tue, 3 Jul 2007 19:50:05 +0300 Subject: [PATCH] Fortran frontend: 2007-07-03 Janne Blomqvist * trans-decl.c (gfc_build_builtin_function_decls): Mark internal_realloc as a malloc function. libgfortran: 2007-07-03 Janne Blomqvist * libgfortran.h: Mark internal_malloc_size as a malloc function. * runtime/memory.c (internal_realloc_size): Remove. (internal_realloc): Call realloc directly instead of internal_realloc_size. (allocate_size): Remove. (allocate): Call malloc directly instead of allocate_size, mark as malloc function. From-SVN: r126264 --- gcc/fortran/ChangeLog | 5 +++ gcc/fortran/trans-decl.c | 1 + libgfortran/ChangeLog | 10 +++++ libgfortran/libgfortran.h | 2 +- libgfortran/runtime/memory.c | 76 ++++++++++++++---------------------- 5 files changed, 46 insertions(+), 48 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 80f1e3c5384f..1ee186203bf7 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2007-07-03 Janne Blomqvist + + * trans-decl.c (gfc_build_builtin_function_decls): Mark + internal_realloc as a malloc function. + 2007-07-03 Tobias Burnus PR fortran/20888 diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 1a949826cf1c..06842f30af82 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -2276,6 +2276,7 @@ gfc_build_builtin_function_decls (void) (PREFIX("internal_realloc")), pvoid_type_node, 2, pvoid_type_node, gfc_index_int_type_node); + DECL_IS_MALLOC (gfor_fndecl_internal_realloc) = 1; gfor_fndecl_allocate = gfc_build_library_function_decl (get_identifier (PREFIX("allocate")), diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index dc0e2468ef99..631e2a5da642 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,13 @@ +2007-07-03 Janne Blomqvist + + * libgfortran.h: Mark internal_malloc_size as a malloc function. + * runtime/memory.c (internal_realloc_size): Remove. + (internal_realloc): Call realloc directly instead of + internal_realloc_size. + (allocate_size): Remove. + (allocate): Call malloc directly instead of allocate_size, mark as + malloc function. + 2007-07-02 Steven G. Kargl Restore collateral damage from ISO C Binding merge. diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index f73594dc4d75..8a86f41785d6 100644 --- a/libgfortran/libgfortran.h +++ b/libgfortran/libgfortran.h @@ -634,7 +634,7 @@ internal_proto(get_mem); extern void free_mem (void *); internal_proto(free_mem); -extern void *internal_malloc_size (size_t); +extern void *internal_malloc_size (size_t) __attribute__ ((malloc)); internal_proto(internal_malloc_size); /* environ.c */ diff --git a/libgfortran/runtime/memory.c b/libgfortran/runtime/memory.c index 7d8937169783..f1991cda324a 100644 --- a/libgfortran/runtime/memory.c +++ b/libgfortran/runtime/memory.c @@ -82,26 +82,6 @@ internal_malloc_size (size_t size) Allocate a new block if MEM is zero, and free the block if SIZE is 0. */ -static void * -internal_realloc_size (void *mem, size_t size) -{ - if (size == 0) - { - if (mem) - free (mem); - return NULL; - } - - if (mem == 0) - return get_mem (size); - - mem = realloc (mem, size); - if (!mem) - os_error ("Out of memory."); - - return mem; -} - extern void *internal_realloc (void *, index_type); export_proto(internal_realloc); @@ -113,17 +93,43 @@ internal_realloc (void *mem, index_type size) if (size < 0) runtime_error ("Attempt to allocate a negative amount of memory."); #endif - return internal_realloc_size (mem, (size_t) size); + mem = realloc (mem, size); + if (!mem && size != 0) + os_error ("Out of memory."); + + if (size == 0) + return NULL; + + return mem; } + /* User-allocate, one call for each member of the alloc-list of an ALLOCATE statement. */ -static void * -allocate_size (size_t size, GFC_INTEGER_4 * stat) +extern void *allocate (index_type, GFC_INTEGER_4 *) __attribute__ ((malloc)); +export_proto(allocate); + +void * +allocate (index_type size, GFC_INTEGER_4 * stat) { void *newmem; +#ifdef GFC_CHECK_MEMORY + /* The only time this can happen is the size computed by the + frontend wraps around. */ + if (size < 0) + { + if (stat) + { + *stat = ERROR_ALLOCATION; + return NULL; + } + else + runtime_error ("Attempt to allocate negative amount of memory. " + "Possible integer overflow"); + } +#endif newmem = malloc (size ? size : 1); if (!newmem) { @@ -142,30 +148,6 @@ allocate_size (size_t size, GFC_INTEGER_4 * stat) return newmem; } -extern void *allocate (index_type, GFC_INTEGER_4 *); -export_proto(allocate); - -void * -allocate (index_type size, GFC_INTEGER_4 * stat) -{ -#ifdef GFC_CHECK_MEMORY - /* The only time this can happen is the size computed by the - frontend wraps around. */ - if (size < 0) - { - if (stat) - { - *stat = ERROR_ALLOCATION; - return NULL; - } - else - runtime_error ("Attempt to allocate negative amount of memory. " - "Possible integer overflow"); - } -#endif - return allocate_size ((size_t) size, stat); -} - /* 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. */