Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2002-08-30 12:08:26

From: Carlo Wood <carlo_at_[hidden]>
> On Fri, Aug 30, 2002 at 12:00:58PM -0400, Rob Stewart wrote:
> > From: Douglas Gregor <gregod_at_[hidden]>
> > > On Friday 30 August 2002 11:12 am, Carlo Wood wrote:
> > > template<typename InputIterator, typename Allocator, typename OutputIterator>
> > > OutputIterator demangle_type(InputIterator first, InputIterator last,
> > > const Allocator& allocator, OutputIterator out);
> >
> > I consider this approach inspired. I would eliminate the
> > Allocator parameter, as I don't really think the library needs it
> However, the Allocator is needed as I will need to store
> things internally (substitutions, template parameter lists).

Let me see if I understand the problem you're dealing with.
Because of the possibility of demangle() being called from within
a call to malloc(), you can't rely on ordinary memory allocation
routines because of the possibility of a deadlock.

That leads me to the following questions:

- Under what scenario will demangle() be invoked from within a
  call to malloc()?

- Why would the demangle() client care how demangle() manages its

- If demangle() needs a separate memory scheme, couldn't it use
  OS-specific means for establishing a separate heap? I realize
  that implies portability issues, but it would work, wouldn't

- I don't suppose that the information demangle() needs to track
  could be preallocated, could it? (I'm gathering that you want
  to track information per symbol, so the data is unbounded.)

- Didn't you previously mention that there could be an interface
  to supply the (de)allocation functions? That's not unlike
  set_terminate(), but it leads to problems if you need
  demangle() to work before entering main(). So, why not create
  a parameterized class which can be given the required functions
  as part of specializing the type:

    template <typename Allocator, typename Deallocator>
    struct demangler
        static std::string type(std::string const & type_i);
        static std::string type(std::type_info const & type_i);
        static std::string symbol(std::string const & symbol_i);

  Usage then becomes:

    typedef demangler<?, ?> demangle;
    std::cout << demangle::type(mangled_type_name);
    std::cout << demangle::type(T.type_id());
    std::cout << demangle::symbol(mangled_symbol_name);

Rob Stewart                           stewart_at_[hidden]
Software Engineer           
Susquehanna International Group, LLP  using std::disclaimer;

Boost list run by bdawes at, gregod at, cpdaniel at, john at