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]

Re: [RFA] Change malloc to xmalloc


On Jan 23,  4:13pm, Rudy Folden wrote:

> Changed calls within gdb from malloc to xmalloc.  Of course, the file
> utils.c can not be changed since it implements xmalloc via a call to mmalloc
> which in turn calls the real malloc.

I'm wondering if the NEED_DECLARATION_MALLOC stuff from defs.h ought
to be left alone, but moved to utils.c (which is the only place from
which malloc() is actually called).

[...]
> --- 962,968 ----
>   #ifndef MALLOC_INCOMPATIBLE
> 
>   #ifdef NEED_DECLARATION_MALLOC
> ! extern PTR xmalloc ();
>   #endif
> 
>   #ifdef NEED_DECLARATION_REALLOC

Also, when you change something with PTR in it, just change the ``PTR''
to ``void *''.

[...]
> Index: stuff.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/stuff.c,v
> retrieving revision 1.2

I think you should leave stuff.c alone.  It's a stand-alone program
that doesn't link in utils.c.  (Actually, I think stuff.c ought
to be marked obsolete and eventually deleted.)

[...]
> *** valprint.c 2000/12/15 01:01:50 1.9
> --- valprint.c 2001/01/23 21:01:45
> *************** print_decimal_chars (struct ui_file *str
> *** 886,892 ****
>      * as the base 16 number, which is 2 digits per byte.
>      */
>     decimal_len = len * 2 * 2;
> !   digits = (unsigned char *) malloc (decimal_len);
>     if (digits == NULL)
>       error ("Can't allocate memory for conversion to decimal.");
> 
> --- 886,892 ----
>      * as the base 16 number, which is 2 digits per byte.
>      */
>     decimal_len = len * 2 * 2;
> !   digits = (unsigned char *) xmalloc (decimal_len);
>     if (digits == NULL)
>       error ("Can't allocate memory for conversion to decimal.");

Again, while you're at it, I think the typecast can go away.

> Index: config/pa/xm-hppah.h
> ===================================================================
> RCS file: /cvs/src/src/gdb/config/pa/xm-hppah.h,v
> retrieving revision 1.2
> diff -c -3 -p -r1.2 xm-hppah.h
> *** xm-hppah.h 2000/05/28 01:12:37 1.2
> --- xm-hppah.h 2001/01/23 21:01:47
> ***************
> *** 40,46 ****
> 
>   #define MALLOC_INCOMPATIBLE
> 
> ! extern void *malloc (size_t);
> 
>   extern void *realloc (void *, size_t);
> 
> --- 40,46 ----
> 
>   #define MALLOC_INCOMPATIBLE
> 
> ! extern void *xmalloc (size_t);
> 
>   extern void *realloc (void *, size_t);

We shouldn't need to declare xmalloc() here at all.  (Nor realloc()
either.)

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