This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch/rfc] Cleanup XMALLOCs


Hello,

The attached patch rationalizes all the XMALLOC() that are defined 
through out the GDB source.  It moves the definition to defs.h.

Assuming no issues are raised, I'll commit it in the next few days.

Andrew
2002-03-15  Andrew Cagney  <ac131313@redhat.com>

	* defs.h (XMALLOC): Define.
	* gdb-events.sh (XMALLOC): Delete macro.
	* gdbarch.sh (XMALLOC): Delete macro.
	* gdbarch.c: Regenerate.
	* serial.c (XMALLOC): Delete macro.
	* ui-file.c (XMALLOC): Ditto.
	* ser-unix.h (XMALLOC): Ditto.
	* sh-tdep.c (XMALLOC): Ditto.
	* ui-out.c (XMALLOC): Ditto.
	* utils.c (XMALLOC): Ditto.
	* i386-tdep.c (XMALLOC): Ditto.
	* gdb-events.c (XMALLOC): Ditto.
	* d10v-tdep.c (XMALLOC): Ditto.
	* cli-out.c (XMALLOC): Ditto.

Index: mi/ChangeLog
2002-03-15  Andrew Cagney  <ac131313@redhat.com>

	* mi-main.c (XMALLOC): Delete macro.
	* mi-out.c (XMALLOC): Ditto.
	* mi-parse.c (XMALLOC): Ditto.
	* mi-console.c (XMALLOC): Ditto.
	* mi-cmd-var.c (XMALLOC): Ditto.
	* mi-cmd-break.c (XMALLOC): Ditto.

Index: tui/ChangeLog
2002-03-15  Andrew Cagney  <ac131313@redhat.com>

	* tui-out.c (XMALLOC): Delete macro.

Index: cli-out.c
===================================================================
RCS file: /cvs/src/src/gdb/cli-out.c,v
retrieving revision 1.13
diff -u -r1.13 cli-out.c
--- cli-out.c	2001/07/06 03:53:11	1.13
+++ cli-out.c	2002/03/16 03:28:01
@@ -26,12 +26,6 @@
 #include "gdb_string.h"
 #include "gdb_assert.h"
 
-/* Convenience macro for allocting typesafe memory. */
-
-#ifndef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-#endif
-
 struct ui_out_data
   {
     struct ui_file *stream;
Index: d10v-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/d10v-tdep.c,v
retrieving revision 1.33
diff -u -r1.33 d10v-tdep.c
--- d10v-tdep.c	2002/01/31 04:10:51	1.33
+++ d10v-tdep.c	2002/03/16 03:28:08
@@ -41,9 +41,6 @@
 #include "floatformat.h"
 #include "sim-d10v.h"
 
-#undef XMALLOC
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
-
 struct frame_extra_info
   {
     CORE_ADDR return_pc;
Index: defs.h
===================================================================
RCS file: /cvs/src/src/gdb/defs.h,v
retrieving revision 1.82
diff -u -r1.82 defs.h
--- defs.h	2002/03/11 00:01:08	1.82
+++ defs.h	2002/03/16 03:28:15
@@ -840,6 +840,11 @@
    "libiberty.h". */
 extern void xfree (void *);
 
+/* Utility macro to allocate typed memory.  Avoids errors like
+   ``struct foo *foo = xmalloc (sizeof bar)'' and ``struct foo *foo =
+   (struct foo *) xmalloc (sizeof bar)''.  */
+#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
+
 /* Like asprintf/vasprintf but get an internal_error if the call
    fails. */
 extern void xasprintf (char **ret, const char *format, ...) ATTR_FORMAT (printf, 2, 3);
Index: gdb-events.c
===================================================================
RCS file: /cvs/src/src/gdb/gdb-events.c,v
retrieving revision 1.8
diff -u -r1.8 gdb-events.c
--- gdb-events.c	2001/08/11 00:41:02	1.8
+++ gdb-events.c	2002/03/16 03:28:15
@@ -38,9 +38,6 @@
 #include "gdb-events.h"
 #include "gdbcmd.h"
 
-#undef XMALLOC
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
-
 #if WITH_GDB_EVENTS
 static struct gdb_events null_event_hooks;
 static struct gdb_events queue_event_hooks;
Index: gdb-events.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdb-events.sh,v
retrieving revision 1.11
diff -u -r1.11 gdb-events.sh
--- gdb-events.sh	2001/08/11 00:41:02	1.11
+++ gdb-events.sh	2002/03/16 03:28:16
@@ -303,9 +303,6 @@
 #include "gdb-events.h"
 #include "gdbcmd.h"
 
-#undef XMALLOC
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
-
 #if WITH_GDB_EVENTS
 static struct gdb_events null_event_hooks;
 static struct gdb_events queue_event_hooks;
Index: gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.110
diff -u -r1.110 gdbarch.c
--- gdbarch.c	2002/02/18 15:59:13	1.110
+++ gdbarch.c	2002/03/16 03:29:20
@@ -74,13 +74,6 @@
 static void swapout_gdbarch_swap (struct gdbarch *);
 static void swapin_gdbarch_swap (struct gdbarch *);
 
-/* Convenience macro for allocting typesafe memory. */
-
-#ifndef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-#endif
-
-
 /* Non-zero if we want to trace architecture code.  */
 
 #ifndef GDBARCH_DEBUG
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.118
diff -u -r1.118 gdbarch.sh
--- gdbarch.sh	2002/02/18 15:59:14	1.118
+++ gdbarch.sh	2002/03/16 03:29:51
@@ -1212,13 +1212,6 @@
 static void swapout_gdbarch_swap (struct gdbarch *);
 static void swapin_gdbarch_swap (struct gdbarch *);
 
-/* Convenience macro for allocting typesafe memory. */
-
-#ifndef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-#endif
-
-
 /* Non-zero if we want to trace architecture code.  */
 
 #ifndef GDBARCH_DEBUG
Index: i386-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-tdep.c,v
retrieving revision 1.52
diff -u -r1.52 i386-tdep.c
--- i386-tdep.c	2002/02/19 18:42:27	1.52
+++ i386-tdep.c	2002/03/16 03:30:02
@@ -40,9 +40,6 @@
 
 #include "i386-tdep.h"
 
-#undef XMALLOC
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
-
 /* Names of the registers.  The first 10 registers match the register
    numbering scheme used by GCC for stabs and DWARF.  */
 static char *i386_register_names[] =
Index: ser-unix.h
===================================================================
RCS file: /cvs/src/src/gdb/ser-unix.h,v
retrieving revision 1.2
diff -u -r1.2 ser-unix.h
--- ser-unix.h	2001/07/11 17:52:32	1.2
+++ ser-unix.h	2002/03/16 03:30:11
@@ -21,9 +21,6 @@
 #ifndef SER_UNIX_H
 #define SER_UNIX_H
 
-#undef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-
 /* Generic UNIX/FD functions */
 
 extern int ser_unix_nop_flush_output (struct serial *scb);
Index: serial.c
===================================================================
RCS file: /cvs/src/src/gdb/serial.c,v
retrieving revision 1.14
diff -u -r1.14 serial.c
--- serial.c	2002/02/24 03:59:50	1.14
+++ serial.c	2002/03/16 03:30:13
@@ -58,9 +58,6 @@
 static const char *logbase_enums[] =
 {logbase_hex, logbase_octal, logbase_ascii, NULL};
 static const char *serial_logbase = logbase_ascii;
-
-#undef XMALLOC
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
 
 
 static int serial_current_type = 0;
Index: sh-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sh-tdep.c,v
retrieving revision 1.48
diff -u -r1.48 sh-tdep.c
--- sh-tdep.c	2002/02/08 03:01:11	1.48
+++ sh-tdep.c	2002/03/16 03:30:24
@@ -43,9 +43,6 @@
 
 #include "solib-svr4.h"
 
-#undef XMALLOC
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
-
 void (*sh_show_regs) (void);
 CORE_ADDR (*skip_prologue_hard_way) (CORE_ADDR);
 void (*do_pseudo_register) (int);
Index: ui-file.c
===================================================================
RCS file: /cvs/src/src/gdb/ui-file.c,v
retrieving revision 1.7
diff -u -r1.7 ui-file.c
--- ui-file.c	2001/03/06 08:21:17	1.7
+++ ui-file.c	2002/03/16 03:30:24
@@ -24,9 +24,6 @@
 #include "ui-file.h"
 #include "gdb_string.h"
 
-#undef XMALLOC
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
-
 static ui_file_isatty_ftype null_file_isatty;
 static ui_file_write_ftype null_file_write;
 static ui_file_fputs_ftype null_file_fputs;
Index: ui-out.c
===================================================================
RCS file: /cvs/src/src/gdb/ui-out.c,v
retrieving revision 1.20
diff -u -r1.20 ui-out.c
--- ui-out.c	2001/12/15 05:18:42	1.20
+++ ui-out.c	2002/03/16 03:30:25
@@ -27,11 +27,6 @@
 #include "ui-out.h"
 #include "gdb_assert.h"
 
-/* Convenience macro for allocting typesafe memory. */
-
-#undef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-
 /* table header structures */
 
 struct ui_out_hdr
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.69
diff -u -r1.69 utils.c
--- utils.c	2002/03/15 00:44:49	1.69
+++ utils.c	2002/03/16 03:35:49
@@ -87,9 +87,6 @@
 extern char *canonicalize_file_name (const char *);
 #endif
 
-#undef XMALLOC
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
-
 /* readline defines this.  */
 #undef savestring
 
Index: mi/mi-cmd-break.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-break.c,v
retrieving revision 1.7
diff -u -r1.7 mi-cmd-break.c
--- mi-cmd-break.c	2002/01/17 22:15:18	1.7
+++ mi-cmd-break.c	2002/03/16 03:39:07
@@ -29,11 +29,6 @@
 #include "gdb-events.h"
 #include "gdb.h"
 
-/* Convenience macro for allocting typesafe memory. */
-
-#undef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-
 enum
   {
     FROM_TTY = 0
Index: mi/mi-cmd-var.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-cmd-var.c,v
retrieving revision 1.10
diff -u -r1.10 mi-cmd-var.c
--- mi-cmd-var.c	2001/08/17 19:01:22	1.10
+++ mi-cmd-var.c	2002/03/16 03:39:07
@@ -27,11 +27,6 @@
 #include "value.h"
 #include <ctype.h>
 
-/* Convenience macro for allocting typesafe memory. */
-
-#undef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-
 extern int varobjdebug;		/* defined in varobj.c */
 
 static int varobj_update_one (struct varobj *var);
Index: mi/mi-console.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-console.c,v
retrieving revision 1.7
diff -u -r1.7 mi-console.c
--- mi-console.c	2001/03/06 08:21:45	1.7
+++ mi-console.c	2002/03/16 03:39:07
@@ -23,11 +23,6 @@
 #include "mi-console.h"
 #include "gdb_string.h"
 
-/* Convenience macro for allocting typesafe memory. */
-
-#undef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-
 /* MI-console: send output to std-out but correcty encapsulated */
 
 static ui_file_fputs_ftype mi_console_file_fputs;
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.26
diff -u -r1.26 mi-main.c
--- mi-main.c	2002/01/17 22:15:18	1.26
+++ mi-main.c	2002/03/16 03:40:14
@@ -42,11 +42,6 @@
 #include <ctype.h>
 #include <sys/time.h>
 
-/* Convenience macro for allocting typesafe memory. */
-
-#undef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-
 enum
   {
     FROM_TTY = 0
Index: mi/mi-out.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-out.c,v
retrieving revision 1.22
diff -u -r1.22 mi-out.c
--- mi-out.c	2001/07/09 22:19:50	1.22
+++ mi-out.c	2002/03/16 03:40:14
@@ -23,12 +23,6 @@
 #include "ui-out.h"
 #include "mi-out.h"
 
-/* Convenience macro for allocting typesafe memory. */
-
-#ifndef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-#endif
-
 struct ui_out_data
   {
     int suppress_field_separator;
Index: mi/mi-parse.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-parse.c,v
retrieving revision 1.7
diff -u -r1.7 mi-parse.c
--- mi-parse.c	2001/03/06 08:21:45	1.7
+++ mi-parse.c	2002/03/16 03:43:42
@@ -26,9 +26,6 @@
 #include <ctype.h>
 #include "gdb_string.h"
 
-#undef XMALLOC
-#define XMALLOC(TYPE) ((TYPE*) xmalloc (sizeof (TYPE)))
-
 static void
 mi_parse_argv (char *args, struct mi_parse *parse)
 {
Index: tui/tui-out.c
===================================================================
RCS file: /cvs/src/src/gdb/tui/tui-out.c,v
retrieving revision 1.1
diff -u -r1.1 tui-out.c
--- tui-out.c	2001/07/24 20:40:39	1.1
+++ tui-out.c	2002/03/16 03:45:24
@@ -26,12 +26,6 @@
 #include "gdb_string.h"
 #include "gdb_assert.h"
 
-/* Convenience macro for allocting typesafe memory. */
-
-#ifndef XMALLOC
-#define XMALLOC(TYPE) (TYPE*) xmalloc (sizeof (TYPE))
-#endif
-
 struct ui_out_data
   {
     struct ui_file *stream;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]