This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[commit] use TYPE_ZALLOC and XZALLOC in gdbtypes.c instead of memset
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 26 Jan 2009 19:00:38 +0000
- Subject: [commit] use TYPE_ZALLOC and XZALLOC in gdbtypes.c instead of memset
I had done this a while back, prompted by some other discussion related to this.
Tested on x86_64-linux, and checked in.
--
Pedro Alves
2009-01-26 Pedro Alves <pedro@codesourcery.com>
* gdbtypes.c (alloc_type, alloc_type_instance, create_range_type)
(create_array_type, create_set_type, init_flags_type)
(copy_type_recursive): Replace pairs of calls to XALLOC and memset
with a call to XZALLOC or XCALLOC, and pairs of calls to
obstack_alloc and memset with a call to OBSTACK_ZALLOC.
---
gdb/gdbtypes.c | 53 +++++++++++++++++------------------------------------
1 file changed, 17 insertions(+), 36 deletions(-)
Index: src/gdb/gdbtypes.c
===================================================================
--- src.orig/gdb/gdbtypes.c 2009-01-26 18:30:07.000000000 +0000
+++ src/gdb/gdbtypes.c 2009-01-26 18:30:49.000000000 +0000
@@ -162,20 +162,16 @@ alloc_type (struct objfile *objfile)
if (objfile == NULL)
{
- type = xmalloc (sizeof (struct type));
- memset (type, 0, sizeof (struct type));
- TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
+ type = XZALLOC (struct type);
+ TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
}
else
{
- type = obstack_alloc (&objfile->objfile_obstack,
- sizeof (struct type));
- memset (type, 0, sizeof (struct type));
- TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
- sizeof (struct main_type));
+ type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
+ TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
+ struct main_type);
OBJSTAT (objfile, n_types++);
}
- memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
/* Initialize the fields that might not be zero. */
@@ -199,16 +195,11 @@ alloc_type_instance (struct type *oldtyp
/* Allocate the structure. */
if (TYPE_OBJFILE (oldtype) == NULL)
- {
- type = xmalloc (sizeof (struct type));
- memset (type, 0, sizeof (struct type));
- }
+ type = XZALLOC (struct type);
else
- {
- type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
- sizeof (struct type));
- memset (type, 0, sizeof (struct type));
- }
+ type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
+ struct type);
+
TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
TYPE_CHAIN (type) = type; /* Chain back to itself for now. */
@@ -705,9 +696,7 @@ create_range_type (struct type *result_t
int low_bound, int high_bound)
{
if (result_type == NULL)
- {
- result_type = alloc_type (TYPE_OBJFILE (index_type));
- }
+ result_type = alloc_type (TYPE_OBJFILE (index_type));
TYPE_CODE (result_type) = TYPE_CODE_RANGE;
TYPE_TARGET_TYPE (result_type) = index_type;
if (TYPE_STUB (index_type))
@@ -715,11 +704,9 @@ create_range_type (struct type *result_t
else
TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
TYPE_NFIELDS (result_type) = 2;
- TYPE_FIELDS (result_type) = TYPE_ALLOC (result_type,
- TYPE_NFIELDS (result_type)
- * sizeof (struct field));
- memset (TYPE_FIELDS (result_type), 0,
- TYPE_NFIELDS (result_type) * sizeof (struct field));
+ TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type,
+ TYPE_NFIELDS (result_type)
+ * sizeof (struct field));
TYPE_LOW_BOUND (result_type) = low_bound;
TYPE_HIGH_BOUND (result_type) = high_bound;
@@ -835,8 +822,7 @@ create_array_type (struct type *result_t
TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
TYPE_NFIELDS (result_type) = 1;
TYPE_FIELDS (result_type) =
- (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
- memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
+ (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
TYPE_INDEX_TYPE (result_type) = range_type;
TYPE_VPTR_FIELDNO (result_type) = -1;
@@ -883,9 +869,7 @@ create_set_type (struct type *result_typ
}
TYPE_CODE (result_type) = TYPE_CODE_SET;
TYPE_NFIELDS (result_type) = 1;
- TYPE_FIELDS (result_type) = (struct field *)
- TYPE_ALLOC (result_type, 1 * sizeof (struct field));
- memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
+ TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field));
if (!TYPE_STUB (domain_type))
{
@@ -931,9 +915,7 @@ init_flags_type (char *name, int length)
type = init_type (TYPE_CODE_FLAGS, length,
TYPE_FLAG_UNSIGNED, name, NULL);
TYPE_NFIELDS (type) = nfields;
- TYPE_FIELDS (type) = TYPE_ALLOC (type,
- nfields * sizeof (struct field));
- memset (TYPE_FIELDS (type), 0, nfields * sizeof (struct field));
+ TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field));
return type;
}
@@ -2981,8 +2963,7 @@ copy_type_recursive (struct objfile *obj
int i, nfields;
nfields = TYPE_NFIELDS (type);
- TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields);
- memset (TYPE_FIELDS (new_type), 0, sizeof (struct field) * nfields);
+ TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
for (i = 0; i < nfields; i++)
{
TYPE_FIELD_ARTIFICIAL (new_type, i) =