This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [rfc] Fix some nasty casts
- To: Andrew Cagney <ac131313 at cygnus dot com>
- Subject: Re: [rfc] Fix some nasty casts
- From: Michael Snyder <msnyder at cygnus dot com>
- Date: Thu, 01 Feb 2001 13:52:22 -0800
- CC: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Organization: Red Hat
- References: <3A79AB96.E255247C@cygnus.com>
Andrew Cagney wrote:
>
> Hello,
>
> The attatched eliminates some nasty and unnecessary casts that assumed
> sizeof(int) == sizeof(void*).
>
> I've run the testsuite and had a long hard stare at the changes but ....
> :-)
Looks right to me.
>
> ----------------------------------------------------------------------------------------------------
> Thu Feb 1 00:29:42 2001 Andrew Cagney <cagney@redhat.com>
>
> * sol-thread.c (restore_inferior_pid): Save the PID in a freshly
> allocated buffer.
> (save_inferior_pid): Restore the PID from that tempoary
> buffer. Delete the buffer.
> * utils.c (make_cleanup_close, do_close_cleanup): Ditto for FD.
>
> Index: sol-thread.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/sol-thread.c,v
> retrieving revision 1.20
> diff -p -r1.20 sol-thread.c
> *** sol-thread.c 2001/01/24 21:01:02 1.20
> --- sol-thread.c 2001/02/01 18:27:00
> *************** lwp_to_thread (int lwp)
> *** 424,436 ****
> static struct cleanup *
> save_inferior_pid (void)
> {
> ! return make_cleanup (restore_inferior_pid, (void *) inferior_pid);
> }
>
> static void
> ! restore_inferior_pid (void *pid)
> {
> ! inferior_pid = (int) pid;
> }
>
>
> --- 424,440 ----
> static struct cleanup *
> save_inferior_pid (void)
> {
> ! int *saved_pid = xmalloc (sizeof (int));
> ! *saved_pid = inferior_pid;
> ! return make_cleanup (restore_inferior_pid, saved_pid);
> }
>
> static void
> ! restore_inferior_pid (void *data)
> {
> ! int *saved_pid = data;
> ! inferior_pid = *saved_pid;
> ! xfree (saved_pid);
> }
>
>
> Index: utils.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/utils.c,v
> retrieving revision 1.27
> diff -p -r1.27 utils.c
> *** utils.c 2001/01/31 03:46:23 1.27
> --- utils.c 2001/02/01 18:27:03
> *************** make_cleanup_bfd_close (bfd *abfd)
> *** 215,228 ****
> static void
> do_close_cleanup (void *arg)
> {
> ! close ((int) arg);
> }
>
> struct cleanup *
> make_cleanup_close (int fd)
> {
> ! /* int into void*. Outch!! */
> ! return make_cleanup (do_close_cleanup, (void *) fd);
> }
>
> static void
> --- 215,231 ----
> static void
> do_close_cleanup (void *arg)
> {
> ! int *fd = arg;
> ! close (*fd);
> ! xfree (fd);
> }
>
> struct cleanup *
> make_cleanup_close (int fd)
> {
> ! int *saved_fd = xmalloc (sizeof (fd));
> ! *saved_fd = fd;
> ! return make_cleanup (do_close_cleanup, saved_fd);
> }
>
> static void