[PATCH][RFC] Malloc-less demangler interface

Mark Mitchell mark@codesourcery.com
Tue Jan 23 17:17:00 GMT 2007


Simon Baldwin wrote:
> Attached is a proposed patch to libiberty's demangler.  It allows a careful
> caller to demangle a name without using any heap allocation functions.
> This makes it useful for functions such as __verbose_terminate_handler in
> libstdc++, which might need to operate in conditions where the heap or the
> malloc arena have been corrupted by a problem in user code.

This is an interesting idea.  However, I have two concerns:

1. Do you have a copyright assignment on file?  (I know Google completed
some copyright paperwork, but I don't know if Google has a blanket
assignment or not.)

2. The reliance alloca means that on some systems you may exceed stack
limits.  Some systems may have rather small stacks and some mangled
names are big.  So, while you're reducing reliance on malloc, you're
increasing reliance on alloca.

What I think might be a better interface would be to allow the caller to
provide "alloc" and "dealloc" functions (ala C++ allocators).  Then, the
standard __cxa_demangle function would pass "malloc" and "free" for
those parameters, while more sophisticated callers could pass functions
that allocate out of a static buffer.  Or, a variant of cxa_demangle
where we never try to "realloc" the buffer.

In other words, it seems to me we should focus on the allocation
interface, rather than creating a "stream" interface, which is what your
approach does.  The only argument I can see in favor of the stream
interface is that it would allow you to print a demangled name via
write(2) even when you had no space (dynamic or otherwise) to hold the
mangled name.

But, perhaps I'm missing some key aspects of your design and/or goals;
feel free to argue.

Thanks,

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713



More information about the Gcc-patches mailing list