Some shadow fixes. (more comments)

Steven King sxking@uswest.net
Sat May 20 10:25:00 GMT 2000


On Sat, 20 May 2000, Nathan Myers wrote:
>
> 
> With 
> 
>   #include <time.h>
>   #include <stdio.h>
>   int main()
>   {
>     ::time_t t = time((::time_t*)0);
>     ::printf("%s\n", ::ctime(&t));
>     return 0;
>   }
>
> The idea for the using-declarations like those cited in your mail is 
> that only names actually defined in std:: need to be imported into
> namespace _C_legacy::_C_shadow, because if they're already defined 
> in _C_legacy, they're inherited by _C_shadow automatically.
> 
> What are you doing differently?

  try

#include <signal.h>
#include <time.h>

  I think its a manifestation of the order of inclusion problem I noted before
(and some other compilation problems also are due to this).  My analysis:

shadow/signal.h includes generic_shadow.h.  In generic_shadow.h, _IN_C_LEGACY
isnt defined so the #else is expanded which includes csignal which includes
std_csignal.h which defines _IN_C_LEGACY and then includes
/usr/include/signal.h.   /usr/include/signal.h includes time.h (shadow/time.h)
which includes generic_shadow.h.  In generic_shadow.h,  at this point
_IN_C_LEGACY is defined, so the #if is expanded, the namespaces are closed, 
_IN_C_LEGACY is undef'd and ctime is included, ctime includes std_ctime which
defines _IN_C_LEGACY and then at the end of std_ctime, _IN_C_LEGACY is undef'd.
Back in generic_shadow.h we are still in the #if, so we reopen the _C_legacy
namespace and #define _IN_C_LEGACY.  Back in time.h,  the #ifndef _IN_C_LEGACY
is not expanded because generic_shadow.h has just defined it (and we're back
in _C_legacy) and so the using declarations are not seen and so none of those 
symbols in std are imported into ::, thus only those names declared
_C_legacy::_C_shadow are visable in ::.

  What I believe is needed to fix this is the using declarations need to be seen
before diving back into the 'swamp' and defining _IN_C_LEGACY.  This would mean
splitting generic_shadow into a pre and post script, or rather, just wacking it
and pasting the chunks into the various name.h headers directly, which would be
more pedantically conforming with 17.4.4.1/3.   ie, my new, improved time.h
looks like

Index: time.h
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/shadow/time.h,v
retrieving revision 1.2
diff -r1.2 time.h
30d29
< 
32c31
< 
---
> # define _INCLUDED_CPP_TIME_H_ 1
36c35
< #undef __need_timespec))
---
> #undef __need_timespec
38,41c37
< # undef _SHADOW_NAME
< # define _SHADOW_NAME <ctime>
< # include <bits/generic_shadow.h>
< # undef _SHADOW_NAME
---
> #ifdef _IN_C_LEGACY_  /* sub-included by a C header */
43c39,51
< # ifndef _IN_C_LEGACY_
---
>       // get out of the "legacy"
>     } // close extern "C"
>   }   // close namespace _C_legacy::
> #define _NEED_C_LEGACY
> #endif
> 
> # include <ctime>
>  
>   // expose global C names, including non-standard ones, but shadow
>   //   some names and types with the std:: C++ version.
> 
>   using namespace ::_C_legacy::_C_shadow;
>   
57,58d64
< # define _INCLUDED_CPP_TIME_H_ 1
< # endif
59a66,72
> #ifdef _NEED_C_LEGACY
>   // dive back into the "swamp"
>   namespace _C_legacy {
>     extern "C" {
> #     define _IN_C_LEGACY_
> #		undef _NEED_C_LEGACY
> #endif /* _NEED_C__LEGACY_ */

  This would need to be done to all the other name.h's.  If you concur, I can
put together a patch in the next couple of days, or, if you'd rather, leave it
up to you.

> p.s. Eeek.  I just noticed that shadow/bits/std_cstdlib.h needs a lot 
> of work on the exit() functions.

  Yea, I had some other problems (and some patches) but at this point I think
this problem needs to be fixed before I try to 'fix' anything else.

-- 
Steven King
sxking@uswest.net


More information about the Libstdc++ mailing list