Demangler interfacd

Matt Austern austern at sgi.com
Thu Apr 27 19:17:45 UTC 2000


This was a small meeting!  We ended up quitting early.

One thing I promised to do and didn't, though, was to come up with a
revised demangler interface.  Here it is.  It's more complicated than
I like, but the complexity does serve a real purpose.  Motivation:
 - allow returning an error code
 - interface callable from C
 - allow reusing a buffer between multiple invocations
 - allow resizing a buffer, since there is no way, even in principle,
   to know how large a buffer to provide.

namespace abi {

  char* __cxa_demangle(const char* mangled_name,
                       char* buf,
                       size_t* n,
                       int* status);

}

mangled-name is a pointer to a null-terminated array of characters

buf may be null.  If it is nonnull, then n must also be nonnull,
and buf is a pointer to an array, of at least *n characters, that
was allocated using malloc.

status points to an int that's used as an error indicator.  It is 
permitted to be null, in which case the user just doesn't get any
detailed error information.

Behavior: the return value is a pointer to a null-character array 
of characters, the demangled name.  If there is an error in
demangling, the return value is a null pointer.  The user can examine
*status to find out what kind of error it is.  Meaning of error 
indications:
     0:  success
     -1: memory allocation failure
     -2: invalid mangled name
     -3: invalid arguments (e.g. buf nonnull and n null)

Memory management: 
 - if buf is a null pointer, __cxa_demangle allocates a new buffer 
   with malloc.  It stoes the size of the buffer in *n, if n is
   nonnull.
 - if buf is not a null pointer, it must have been allocated with
   malloc.  If the array turns out to be too small, __cxa_demangle
   may use realloc to increase its size.  The new size will be stored
   in *n.


    








More information about the cxx-abi-dev mailing list