summaryrefslogtreecommitdiff
path: root/libgfortran/runtime/memory.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgfortran/runtime/memory.c')
-rw-r--r--libgfortran/runtime/memory.c74
1 files changed, 28 insertions, 46 deletions
diff --git a/libgfortran/runtime/memory.c b/libgfortran/runtime/memory.c
index 7d893716978..f1991cda324 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,41 +93,28 @@ 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)
-{
- void *newmem;
-
- newmem = malloc (size ? size : 1);
- if (!newmem)
- {
- if (stat)
- {
- *stat = ERROR_ALLOCATION;
- return newmem;
- }
- else
- runtime_error ("ALLOCATE: Out of memory.");
- }
-
- if (stat)
- *stat = 0;
-
- return newmem;
-}
-
-extern void *allocate (index_type, GFC_INTEGER_4 *);
+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. */
@@ -163,7 +130,22 @@ allocate (index_type size, GFC_INTEGER_4 * stat)
"Possible integer overflow");
}
#endif
- return allocate_size ((size_t) size, stat);
+ newmem = malloc (size ? size : 1);
+ if (!newmem)
+ {
+ if (stat)
+ {
+ *stat = ERROR_ALLOCATION;
+ return newmem;
+ }
+ else
+ runtime_error ("ALLOCATE: Out of memory.");
+ }
+
+ if (stat)
+ *stat = 0;
+
+ return newmem;
}
/* Function to call in an ALLOCATE statement when the argument is an