Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Avoid obstack_free in cp-namespace.c
@ 2004-02-09 21:10 Daniel Jacobowitz
  2004-02-09 21:20 ` David Carlton
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2004-02-09 21:10 UTC (permalink / raw)
  To: carlton, gdb-patches

Hi David,

What do you think of this change?  It makes the assumption that
lookup_block_symbol will not allocate anything on the objfile obstack, which
is no longer true in a patch I'm testing.  I really dislike obstack_free for
this exact reason.

[For the curious I've audited the remaining uses of obstack_free in GDB. 
The ones in jv-lang.c and stabsread.c are suspicious but seem to be OK, and
the rest are fine except for this one - they release whole obstacks.]

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2004-02-09  Daniel Jacobowitz  <drow@mvista.com>

	* cp-namespace.c (check_one_possible_namespace_symbol): Don't use
	obstack_free.

Index: cp-namespace.c
===================================================================
RCS file: /big/fsf/rsync/src-cvs/src/gdb/cp-namespace.c,v
retrieving revision 1.11
diff -u -p -r1.11 cp-namespace.c
--- cp-namespace.c	7 Feb 2004 23:13:47 -0000	1.11
+++ cp-namespace.c	9 Feb 2004 21:03:31 -0000
@@ -783,14 +783,20 @@ check_one_possible_namespace_symbol (con
 				     struct objfile *objfile)
 {
   struct block *block = get_possible_namespace_block (objfile);
-  char *name_copy = obsavestring (name, len, &objfile->objfile_obstack);
-  struct symbol *sym = lookup_block_symbol (block, name_copy, NULL,
-					    VAR_DOMAIN);
+  char *name_copy = alloca (len + 1);
+  struct symbol *sym;
+
+  memcpy (name_copy, name, len);
+  name_copy[len] = '\0';
+  sym = lookup_block_symbol (block, name_copy, NULL, VAR_DOMAIN);
 
   if (sym == NULL)
     {
-      struct type *type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
-				     name_copy, objfile);
+      struct type *type;
+      name_copy = obsavestring (name, len, &objfile->objfile_obstack);
+
+      type = init_type (TYPE_CODE_NAMESPACE, 0, 0, name_copy, objfile);
+
       TYPE_TAG_NAME (type) = TYPE_NAME (type);
 
       sym = obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
@@ -806,11 +812,7 @@ check_one_possible_namespace_symbol (con
       return 0;
     }
   else
-    {
-      obstack_free (&objfile->objfile_obstack, name_copy);
-
-      return 1;
-    }
+    return 1;
 }
 
 /* Look for a symbol named NAME in all the possible namespace blocks.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Avoid obstack_free in cp-namespace.c
  2004-02-09 21:10 Avoid obstack_free in cp-namespace.c Daniel Jacobowitz
@ 2004-02-09 21:20 ` David Carlton
  2004-02-09 22:25   ` Daniel Jacobowitz
  2004-02-09 22:42 ` Elena Zannoni
  2004-02-10  5:44 ` Eli Zaretskii
  2 siblings, 1 reply; 8+ messages in thread
From: David Carlton @ 2004-02-09 21:20 UTC (permalink / raw)
  To: gdb-patches

On Mon, 9 Feb 2004 16:10:10 -0500, Daniel Jacobowitz <drow@mvista.com> said:

> What do you think of this change?  It makes the assumption that
> lookup_block_symbol will not allocate anything on the objfile
> obstack, which is no longer true in a patch I'm testing.  I really
> dislike obstack_free for this exact reason.

Makes sense to me.

David Carlton
carlton@kealia.com


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Avoid obstack_free in cp-namespace.c
  2004-02-09 21:20 ` David Carlton
@ 2004-02-09 22:25   ` Daniel Jacobowitz
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2004-02-09 22:25 UTC (permalink / raw)
  To: gdb-patches

On Mon, Feb 09, 2004 at 01:15:28PM -0800, David Carlton wrote:
> On Mon, 9 Feb 2004 16:10:10 -0500, Daniel Jacobowitz <drow@mvista.com> said:
> 
> > What do you think of this change?  It makes the assumption that
> > lookup_block_symbol will not allocate anything on the objfile
> > obstack, which is no longer true in a patch I'm testing.  I really
> > dislike obstack_free for this exact reason.
> 
> Makes sense to me.

Checked in.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Avoid obstack_free in cp-namespace.c
  2004-02-09 21:10 Avoid obstack_free in cp-namespace.c Daniel Jacobowitz
  2004-02-09 21:20 ` David Carlton
@ 2004-02-09 22:42 ` Elena Zannoni
  2004-02-10  5:44   ` Eli Zaretskii
  2004-02-10  5:44 ` Eli Zaretskii
  2 siblings, 1 reply; 8+ messages in thread
From: Elena Zannoni @ 2004-02-09 22:42 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: carlton, gdb-patches

Daniel Jacobowitz writes:
 > 
 > [For the curious I've audited the remaining uses of obstack_free in GDB. 
 > The ones in jv-lang.c and stabsread.c are suspicious but seem to be OK, and
 > the rest are fine except for this one - they release whole obstacks.]

I already did this in my cleanups. For the curious, you might as well
explain the whole story. The obstack_free function takes a pointer to
where in the stack it must start the deletion from (much like the
cleanup chains have a pointer to where to start the cleanups). The
obstack_free's in jv-lang.c and stabsread.c are done after some local
stuff is allocated to the obstack. Only the local stuff is deleted
from the obstack. Of course this assumes that nothing between the
obstack_alloc and the obstack_free allocates anything else on the same
obstack. For this reason other files use temporary obstacks. Maybe
jv-lang.c and stabsread.c could do the same. This one had the same
assumption.

Releasing the whole obstack is not safe per se. It is safe only under
the condition that we know the obstacks memory is no longer
needed. In GDB we blow away the obstacks only when we get rid of the
whole objfile(s). 

elena


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Avoid obstack_free in cp-namespace.c
  2004-02-09 22:42 ` Elena Zannoni
@ 2004-02-10  5:44   ` Eli Zaretskii
  2004-02-10 17:28     ` Elena Zannoni
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2004-02-10  5:44 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: drow, carlton, gdb-patches

> From: Elena Zannoni <ezannoni@redhat.com>
> Date: Mon, 9 Feb 2004 17:39:19 -0500
> 
> For the curious, you might as well explain the whole story.

Thanks.  It would be nice if this could find its way into
gdbint.texinfo, sigh...



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Avoid obstack_free in cp-namespace.c
  2004-02-09 21:10 Avoid obstack_free in cp-namespace.c Daniel Jacobowitz
  2004-02-09 21:20 ` David Carlton
  2004-02-09 22:42 ` Elena Zannoni
@ 2004-02-10  5:44 ` Eli Zaretskii
  2 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2004-02-10  5:44 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: carlton, gdb-patches

> Date: Mon, 9 Feb 2004 16:10:10 -0500
> From: Daniel Jacobowitz <drow@mvista.com>
> 
> -  char *name_copy = obsavestring (name, len, &objfile->objfile_obstack);
> -  struct symbol *sym = lookup_block_symbol (block, name_copy, NULL,
> -					    VAR_DOMAIN);
> +  char *name_copy = alloca (len + 1);
> +  struct symbol *sym;
> +
> +  memcpy (name_copy, name, len);
> +  name_copy[len] = '\0';

How large can the value of `len' be?  I believe we have some coding
guidelines against using alloca for allocations that are too large.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Avoid obstack_free in cp-namespace.c
  2004-02-10  5:44   ` Eli Zaretskii
@ 2004-02-10 17:28     ` Elena Zannoni
  2004-02-10 18:55       ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Elena Zannoni @ 2004-02-10 17:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Elena Zannoni, drow, carlton, gdb-patches

Eli Zaretskii writes:
 > > From: Elena Zannoni <ezannoni@redhat.com>
 > > Date: Mon, 9 Feb 2004 17:39:19 -0500
 > > 
 > > For the curious, you might as well explain the whole story.
 > 
 > Thanks.  It would be nice if this could find its way into
 > gdbint.texinfo, sigh...
 > 

your wish is my command.....


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Avoid obstack_free in cp-namespace.c
  2004-02-10 17:28     ` Elena Zannoni
@ 2004-02-10 18:55       ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2004-02-10 18:55 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: drow, carlton, gdb-patches

> From: Elena Zannoni <ezannoni@redhat.com>
> Date: Tue, 10 Feb 2004 12:25:04 -0500
>  > 
>  > Thanks.  It would be nice if this could find its way into
>  > gdbint.texinfo, sigh...
>  > 
> 
> your wish is my command.....

Please, never a command: a request.

Thanks.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-02-10 18:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-09 21:10 Avoid obstack_free in cp-namespace.c Daniel Jacobowitz
2004-02-09 21:20 ` David Carlton
2004-02-09 22:25   ` Daniel Jacobowitz
2004-02-09 22:42 ` Elena Zannoni
2004-02-10  5:44   ` Eli Zaretskii
2004-02-10 17:28     ` Elena Zannoni
2004-02-10 18:55       ` Eli Zaretskii
2004-02-10  5:44 ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox