+2012-03-25 Janne Blomqvist <jb@gcc.gnu.org>
+
+ * runtime/memory.c (xcalloc): New function.
+ * libgfortran.h (xcalloc): New prototype.
+ * io/list_read.c (push_char): Use xcalloc instead of get_mem and
+ memset.
+ (l_push_char): Likewise.
+ * io/unit.c (insert_unit): Likewise.
+ (get_internal_unit): Likewise.
+ * io/unix.c (open_internal): Likewise.
+ (open_internal4): Likewise.
+ (fd_to_stream): Likewise.
+
2012-03-17 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/52608
-/* Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+/* Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
Contributed by Andy Vaught
Namelist input contributed by Paul Thomas
if (dtp->u.p.saved_string == NULL)
{
- dtp->u.p.saved_string = get_mem (SCRATCH_SIZE);
- // memset below should be commented out.
- memset (dtp->u.p.saved_string, 0, SCRATCH_SIZE);
+ // Plain malloc should suffice here, zeroing not needed?
+ dtp->u.p.saved_string = xcalloc (SCRATCH_SIZE, 1);
dtp->u.p.saved_length = SCRATCH_SIZE;
dtp->u.p.saved_used = 0;
}
l_push_char (st_parameter_dt *dtp, char c)
{
if (dtp->u.p.line_buffer == NULL)
- {
- dtp->u.p.line_buffer = get_mem (SCRATCH_SIZE);
- memset (dtp->u.p.line_buffer, 0, SCRATCH_SIZE);
- }
+ dtp->u.p.line_buffer = xcalloc (SCRATCH_SIZE, 1);
dtp->u.p.line_buffer[dtp->u.p.item_count++] = c;
}
-/* Copyright (C) 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011
+/* Copyright (C) 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
Contributed by Andy Vaught
F2003 I/O support contributed by Jerry DeLisle
static gfc_unit *
insert_unit (int n)
{
- gfc_unit *u = get_mem (sizeof (gfc_unit));
- memset (u, '\0', sizeof (gfc_unit));
+ gfc_unit *u = xcalloc (1, sizeof (gfc_unit));
u->unit_number = n;
#ifdef __GTHREAD_MUTEX_INIT
{
/* Allocate memory for a unit structure. */
- iunit = get_mem (sizeof (gfc_unit));
- if (iunit == NULL)
- {
- generate_error (&dtp->common, LIBERROR_INTERNAL_UNIT, NULL);
- return NULL;
- }
+ iunit = xcalloc (1, sizeof (gfc_unit));
- memset (iunit, '\0', sizeof (gfc_unit));
#ifdef __GTHREAD_MUTEX_INIT
{
__gthread_mutex_t tmp = __GTHREAD_MUTEX_INIT;
/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
- 2011
+ 2011, 2012
Free Software Foundation, Inc.
Contributed by Andy Vaught
F2003 I/O support contributed by Jerry DeLisle
{
unix_stream *s;
- s = get_mem (sizeof (unix_stream));
- memset (s, '\0', sizeof (unix_stream));
+ s = xcalloc (1, sizeof (unix_stream));
s->buffer = base;
s->buffer_offset = offset;
- s->logical_offset = 0;
s->active = s->file_length = length;
s->st.vptr = &mem_vtable;
{
unix_stream *s;
- s = get_mem (sizeof (unix_stream));
- memset (s, '\0', sizeof (unix_stream));
+ s = xcalloc (1, sizeof (unix_stream));
s->buffer = base;
s->buffer_offset = offset;
- s->logical_offset = 0;
s->active = s->file_length = length;
s->st.vptr = &mem4_vtable;
struct stat statbuf;
unix_stream *s;
- s = get_mem (sizeof (unix_stream));
- memset (s, '\0', sizeof (unix_stream));
+ s = xcalloc (1, sizeof (unix_stream));
s->fd = fd;
- s->buffer_offset = 0;
- s->physical_offset = 0;
- s->logical_offset = 0;
/* Get the current length of the file. */
extern void *internal_malloc_size (size_t) __attribute__ ((malloc));
internal_proto(internal_malloc_size);
+extern void *xcalloc (size_t, size_t) __attribute__ ((malloc));
+internal_proto(xcalloc);
+
+
/* environ.c */
extern int check_buffered (int);
/* Memory management routines.
- Copyright 2002, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+ Copyright 2002, 2005, 2006, 2007, 2009, 2010, 2012
+ Free Software Foundation, Inc.
Contributed by Paul Brook <paul@nowt.org>
This file is part of the GNU Fortran runtime library (libgfortran).
return get_mem (size);
}
+
+
+/* calloc wrapper that aborts on error. */
+
+void *
+xcalloc (size_t nmemb, size_t size)
+{
+ if (nmemb * size == 0)
+ nmemb = size = 1;
+
+ void *p = calloc (nmemb, size);
+ if (!p)
+ os_error ("Allocating cleared memory failed");
+
+ return p;
+}