* [PATCH] use memset to zero the fields of a new frame_info
@ 2001-05-17 13:08 Michael Snyder
2001-05-17 13:24 ` Stan Shebs
0 siblings, 1 reply; 4+ messages in thread
From: Michael Snyder @ 2001-05-17 13:08 UTC (permalink / raw)
To: gdb-patches
One call to memset does a better job than some number of individual assigns,
esp. since it's guaranteed to get new fields that would be missed otherwise
(and were being).
2001-05-17 Michael Snyder <msnyder@redhat.com>
* blockframe.c (create_new_frame): Zero all the fields via memset,
rather than zeroing them one by one.
Index: blockframe.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/blockframe.c,v
retrieving revision 1.111
diff -c -3 -p -r1.111 blockframe.c
*** blockframe.c 2001/05/09 00:19:04 1.111
--- blockframe.c 2001/05/17 19:59:08
*************** create_new_frame (CORE_ADDR addr, CORE_A
*** 219,228 ****
obstack_alloc (&frame_cache_obstack,
sizeof (struct frame_info));
/* Arbitrary frame */
- fi->saved_regs = NULL;
- fi->next = NULL;
- fi->prev = NULL;
fi->frame = addr;
fi->pc = pc;
find_pc_partial_function (pc, &name, (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
--- 219,227 ----
obstack_alloc (&frame_cache_obstack,
sizeof (struct frame_info));
+ /* Zero all fields by default. */
+ memset (fi, 0, sizeof (struct frame_info));
/* Arbitrary frame */
fi->frame = addr;
fi->pc = pc;
find_pc_partial_function (pc, &name, (CORE_ADDR *) NULL, (CORE_ADDR *) NULL);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] use memset to zero the fields of a new frame_info
2001-05-17 13:08 [PATCH] use memset to zero the fields of a new frame_info Michael Snyder
@ 2001-05-17 13:24 ` Stan Shebs
2001-05-17 21:04 ` Andrew Cagney
0 siblings, 1 reply; 4+ messages in thread
From: Stan Shebs @ 2001-05-17 13:24 UTC (permalink / raw)
To: Michael Snyder; +Cc: gdb-patches
Michael Snyder wrote:
>
> One call to memset does a better job than some number of individual assigns,
> esp. since it's guaranteed to get new fields that would be missed otherwise
> (and were being).
>
> 2001-05-17 Michael Snyder <msnyder@redhat.com>
>
> * blockframe.c (create_new_frame): Zero all the fields via memset,
> rather than zeroing them one by one.
Ah, the end of an era. Gilmore originally objected to this kind of
thing, on the theory that it was "machine-gunning" memory and wasn't
necessary - only set fields that you know need to be zeroed. I'm on
the fence, because it can save bugs and random scattered init code
if you can assume that newly-allocated data all has known values, and
clearing small-to-medium-size structs isn't expensive usually.
In any case, the policy ought to be clarified one way or the other.
Stan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] use memset to zero the fields of a new frame_info
2001-05-17 13:24 ` Stan Shebs
@ 2001-05-17 21:04 ` Andrew Cagney
2001-05-20 13:06 ` Jim Blandy
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Cagney @ 2001-05-17 21:04 UTC (permalink / raw)
To: Stan Shebs; +Cc: Michael Snyder, gdb-patches
> Ah, the end of an era. Gilmore originally objected to this kind of
> thing, on the theory that it was "machine-gunning" memory and wasn't
> necessary - only set fields that you know need to be zeroed. I'm on
> the fence, because it can save bugs and random scattered init code
> if you can assume that newly-allocated data all has known values, and
> clearing small-to-medium-size structs isn't expensive usually.
I remember that, I got my wrist slapped for sending such a patch to BFD.
> In any case, the policy ought to be clarified one way or the other.
If you look at PSIM which uses ZALLOC(TYPE) (allocate sizeof(TYPE) bytes
of zero initialized memory) you'll see where I sit.
When it comes down to it, I'm more concerned with ensuring that all
memory is initialized to a well defined, machine independant, value then
what the value actually is. Zero happens to be convenient.
Andrew
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] use memset to zero the fields of a new frame_info
2001-05-17 21:04 ` Andrew Cagney
@ 2001-05-20 13:06 ` Jim Blandy
0 siblings, 0 replies; 4+ messages in thread
From: Jim Blandy @ 2001-05-20 13:06 UTC (permalink / raw)
To: Andrew Cagney; +Cc: Stan Shebs, Michael Snyder, gdb-patches
Andrew Cagney <ac131313@cygnus.com> writes:
> When it comes down to it, I'm more concerned with ensuring that all
> memory is initialized to a well defined, machine independant, value then
> what the value actually is. Zero happens to be convenient.
Using memset(addr, 0, size) to clear a structure is certainly not
machine-independent. You have no idea whether the compiler represents
integer zero, null pointers, floating-point zeros, etc. as a series of
zero bytes or not. Using memset this way is not typesafe.
(No, I don't think this ``concern'' has any practical consequence. I
have no opinion on the actual issue. I just want to be a smarty
pants.)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-05-20 13:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-17 13:08 [PATCH] use memset to zero the fields of a new frame_info Michael Snyder
2001-05-17 13:24 ` Stan Shebs
2001-05-17 21:04 ` Andrew Cagney
2001-05-20 13:06 ` Jim Blandy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox