summaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2006-12-13 09:57:56 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2006-12-13 09:57:56 +0000
commitdac9919dff0a85f3455e168341969940e059c2db (patch)
tree7999ad0c5cf8c4027a341ed6f21ea1817f74f26f /libgfortran
parent2eb5c889f514f9d1856e97bb1ad81ee56a50b491 (diff)
downloadgcc-dac9919dff0a85f3455e168341969940e059c2db.tar.gz
2006-12-13 Richard Guenther <rguenther@suse.de>
PR fortran/30115 * runtime/memory.c (allocate_size): Change interface to void *()(size_t, GFC_INTEGER_4 *). (allocate): Likewise. (allocate64): Likewise. (allocate_array): Change interface to void *()(void *, size_t, GFC_INTEGER_4 *). (allocate64_array): Likewise. (deallocate): Change interface to void ()(void *, GFC_INTEGER_4 *). * trans-array.c (gfc_array_allocate): Adjust for changed library interface. (gfc_array_deallocate): Likewise. (gfc_trans_dealloc_allocated): Likewise. * trans-stmt.c (gfc_trans_allocate): Likewise. (gfc_trans_deallocate): Likewise. * trans-decl.c (gfc_build_builtin_function_decls): Adjust function declarations to match the library changes. Mark allocation functions with DECL_IS_MALLOC. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@119822 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog13
-rw-r--r--libgfortran/runtime/memory.c106
2 files changed, 52 insertions, 67 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 6d9739a6f8c..d80cf70f170 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,16 @@
+2006-12-13 Richard Guenther <rguenther@suse.de>
+
+ PR fortran/30115
+ * runtime/memory.c (allocate_size): Change interface to
+ void *()(size_t, GFC_INTEGER_4 *).
+ (allocate): Likewise.
+ (allocate64): Likewise.
+ (allocate_array): Change interface to
+ void *()(void *, size_t, GFC_INTEGER_4 *).
+ (allocate64_array): Likewise.
+ (deallocate): Change interface to
+ void ()(void *, GFC_INTEGER_4 *).
+
2006-12-06 Francois-Xavier Coudert <coudert@clipper.ens.fr>
PR libfortran/29810
diff --git a/libgfortran/runtime/memory.c b/libgfortran/runtime/memory.c
index 43a72e3f1b2..b38d062669f 100644
--- a/libgfortran/runtime/memory.c
+++ b/libgfortran/runtime/memory.c
@@ -174,133 +174,110 @@ internal_realloc64 (void *mem, GFC_INTEGER_8 size)
/* User-allocate, one call for each member of the alloc-list of an
ALLOCATE statement. */
-static void
-allocate_size (void **mem, size_t size, GFC_INTEGER_4 * stat)
+static void *
+allocate_size (size_t size, GFC_INTEGER_4 * stat)
{
void *newmem;
- if (!mem)
- runtime_error ("Internal: NULL mem pointer in ALLOCATE.");
-
newmem = malloc (size ? size : 1);
if (!newmem)
{
if (stat)
{
*stat = 1;
- return;
+ return newmem;
}
else
runtime_error ("ALLOCATE: Out of memory.");
}
- (*mem) = newmem;
-
if (stat)
*stat = 0;
+
+ return newmem;
}
-extern void allocate (void **, GFC_INTEGER_4, GFC_INTEGER_4 *);
+extern void *allocate (GFC_INTEGER_4, GFC_INTEGER_4 *);
export_proto(allocate);
-void
-allocate (void **mem, GFC_INTEGER_4 size, GFC_INTEGER_4 * stat)
+void *
+allocate (GFC_INTEGER_4 size, GFC_INTEGER_4 * stat)
{
if (size < 0)
- {
- runtime_error ("Attempt to allocate negative amount of memory. "
- "Possible integer overflow");
- abort ();
- }
+ runtime_error ("Attempt to allocate negative amount of memory. "
+ "Possible integer overflow");
- allocate_size (mem, (size_t) size, stat);
+ return allocate_size ((size_t) size, stat);
}
-extern void allocate64 (void **, GFC_INTEGER_8, GFC_INTEGER_4 *);
+extern void *allocate64 (GFC_INTEGER_8, GFC_INTEGER_4 *);
export_proto(allocate64);
-void
-allocate64 (void **mem, GFC_INTEGER_8 size, GFC_INTEGER_4 * stat)
+void *
+allocate64 (GFC_INTEGER_8 size, GFC_INTEGER_4 * stat)
{
if (size < 0)
- {
- runtime_error
- ("ALLOCATE64: Attempt to allocate negative amount of memory. "
- "Possible integer overflow");
- abort ();
- }
+ runtime_error ("ALLOCATE64: Attempt to allocate negative amount of "
+ "memory. Possible integer overflow");
- allocate_size (mem, (size_t) size, stat);
+ 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. 32-bit version. */
-extern void allocate_array (void **, GFC_INTEGER_4, GFC_INTEGER_4 *);
+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)
+void *
+allocate_array (void *mem, GFC_INTEGER_4 size, GFC_INTEGER_4 * stat)
{
- if (*mem == NULL)
- {
- allocate (mem, size, stat);
- return;
- }
+ if (mem == NULL)
+ return allocate (size, stat);
if (stat)
{
- free (*mem);
- allocate (mem, size, stat);
+ free (mem);
+ mem = allocate (size, stat);
*stat = ERROR_ALLOCATION;
- return;
+ return mem;
}
- else
- runtime_error ("Attempting to allocate already allocated array.");
- return;
+ runtime_error ("Attempting to allocate already allocated array.");
}
/* 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 *);
+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)
+void *
+allocate64_array (void *mem, GFC_INTEGER_8 size, GFC_INTEGER_4 * stat)
{
- if (*mem == NULL)
- {
- allocate64 (mem, size, stat);
- return;
- }
+ if (mem == NULL)
+ return allocate64 (size, stat);
if (stat)
{
- free (*mem);
- allocate (mem, size, stat);
+ free (mem);
+ mem = allocate (size, stat);
*stat = ERROR_ALLOCATION;
- return;
+ return mem;
}
- else
- runtime_error ("Attempting to allocate already allocated array.");
- return;
+ runtime_error ("Attempting to allocate already allocated array.");
}
/* User-deallocate; pointer is NULLified. */
-extern void deallocate (void **, GFC_INTEGER_4 *);
+extern void deallocate (void *, GFC_INTEGER_4 *);
export_proto(deallocate);
void
-deallocate (void **mem, GFC_INTEGER_4 * stat)
+deallocate (void *mem, GFC_INTEGER_4 * stat)
{
if (!mem)
- runtime_error ("Internal: NULL mem pointer in DEALLOCATE.");
-
- if (!*mem)
{
if (stat)
{
@@ -308,15 +285,10 @@ deallocate (void **mem, GFC_INTEGER_4 * stat)
return;
}
else
- {
- runtime_error
- ("Internal: Attempt to DEALLOCATE unallocated memory.");
- abort ();
- }
+ runtime_error ("Internal: Attempt to DEALLOCATE unallocated memory.");
}
- free (*mem);
- *mem = NULL;
+ free (mem);
if (stat)
*stat = 0;