This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: __cxa_demangle


On Fri, Dec 06, 2002 at 12:20:30PM -0600, Benjamin Kosnik wrote:
> > Ambiguities are possible between extern
> >"C" object names and internal built-in type names, e.g. "i" may be either
> >an object named "i" or the built-in "int" type. Such ambiguities should
> >be resolved to user names over built-in names. 
> 
> extern "C" 
> {
>   struct i
>   {
>     int j;
>   };
>   
>   i obj;
> }
> 
> void foo(i my, char* c) { }
> 
> void foo(int m, char* c) { }
> 
> 00000000 T _Z3foo1iPc
> 00000006 T _Z3fooiPc
> 
> Maybe I don't understand the ambiguity? These are distinct. For
> non-function arguments, the extern "C" structs won't be mangled, so
> there is no need to demangle.
> 
> A C object that is unfortunately named "i" would be mangled as
> 
> i
> 
> without the preceeding _Z, so it wouldn't need to be demangled (see
> below). I'm assuming you are talking about this as a function argument,
> right? Can't you just check for an int before the "i"?  

But if you pass "i" to __cxa_demangle(), then would should it return?
I think it should return 'int'.  It can't know that there is an object
called 'i' because it doesn't have the symbol table.

> ie:
> 
> #if 0
> class i
> {
> public:
>   i();
> };
> 
> i::i(){};
> #else
> extern "C" 
> {
>   struct obj
>   {
>     int j;
>   };
>   
>   obj i;
> }
> 
> #endif
>   i();
> };
> 
> i::i(){};
> 
> ie:
> 
> 00000006 T _ZN1iC1Ev
> 
> vs.
> 
> 00000000 B i

This is why I explicitely seperated demangle::type and
demangle::symbol, and never return an error for objcts,
but simply assume that it was an extern "C" object
when demangling fails.  That seems to be the only
reasonable thing to do.  However, the abi demands that
we mix these two in __cxa_demangle: When the input passed
starts with _Z it is a symbol, when it doesn't, it is
a type OR a C symbol - that is ridiculous, especially
when you have to give the latter precedence over the
types - that means you'd NEVER demangle a (builtin) type.
Passing "i" would then return "i".

Is that is what is intended??
In other words, I still don't understand it.

-- 
Carlo Wood <carlo@alinoe.com>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]