This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

C++ PATCH: Adjust <typeinfo>



On platforms that do not use weak symbols, we must resort to strcmp to
do typeinfo::operator==, even under the new ABI.

Tested on i686-pc-linux-gnu.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2001-02-04  Mark Mitchell  <mark@codesourcery.com>

	* libsupc++/typeinfo (__GXX_MERGED_TYPEINFO_NAMES): New macro.
	* libsupc++/tinfo.cc (std::typeinfo::operator==): Use strcmp
	whenever !__GXX_MERGED_TYPEINFO_NAMES.
	* libsupc++/tinfo2.cc (std::typeinfo::before): Likewise.

Index: libstdc++-v3/libsupc++/tinfo.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/tinfo.cc,v
retrieving revision 1.2
diff -c -p -r1.2 tinfo.cc
*** tinfo.cc	2000/10/21 16:50:29	1.2
--- tinfo.cc	2001/02/04 08:25:05
*************** std::type_info::
*** 41,46 ****
--- 41,57 ----
  ~type_info ()
  { }
  
+ #if !__GXX_MERGED_TYPEINFO_NAMES
+ 
+ // We can't rely on common symbols being shared between shared objects.
+ bool std::type_info::
+ operator== (const std::type_info& arg) const
+ {
+   return (&arg == this) || (__builtin_strcmp (name (), arg.name ()) == 0);
+ }
+ 
+ #endif
+ 
  #if !defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100
  // original (old) abi
  
*************** convert_to_base (void *addr, bool is_vir
*** 62,74 ****
    return *((void **) ((char *) addr + offset));
  }
  
- }
- 
- // We can't rely on common symbols being shared between shared objects.
- bool std::type_info::
- operator== (const std::type_info& arg) const
- {
-   return (&arg == this) || (__builtin_strcmp (name (), arg.name ()) == 0);
  }
  
  extern "C" void
--- 73,78 ----
Index: libstdc++-v3/libsupc++/tinfo2.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/tinfo2.cc,v
retrieving revision 1.2
diff -c -p -r1.2 tinfo2.cc
*** tinfo2.cc	2000/10/31 01:26:06	1.2
--- tinfo2.cc	2001/02/04 08:25:05
***************
*** 1,5 ****
  // Methods for type_info for -*- C++ -*- Run Time Type Identification.
! // Copyright (C) 1994, 1996, 1997, 1998, 1999, 2000 Free Software Foundation
  
  // This file is part of GNU CC.
  
--- 1,5 ----
  // Methods for type_info for -*- C++ -*- Run Time Type Identification.
! // Copyright (C) 1994, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation
  
  // This file is part of GNU CC.
  
*************** extern "C" void abort ();
*** 36,47 ****
  
  using std::type_info;
  
! #if !defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100
  bool
  type_info::before (const type_info &arg) const
  {
    return __builtin_strcmp (name (), arg.name ()) < 0;
  }
  
  // type info for pointer type.
  
--- 36,52 ----
  
  using std::type_info;
  
! #if !__GXX_MERGED_TYPEINFO_NAMES
! 
  bool
  type_info::before (const type_info &arg) const
  {
    return __builtin_strcmp (name (), arg.name ()) < 0;
  }
+ 
+ #endif
+ 
+ #if !defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100
  
  // type info for pointer type.
  
Index: libstdc++-v3/libsupc++/typeinfo
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/typeinfo,v
retrieving revision 1.2
diff -c -p -r1.2 typeinfo
*** typeinfo	2001/01/17 07:44:56	1.2
--- typeinfo	2001/02/04 08:25:05
*************** namespace __cxxabiv1
*** 48,53 ****
--- 48,66 ----
  } // namespace __cxxabiv1
  #endif
  
+ 
+ #if !defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100
+   // In the old ABI, typeinfo name strings were not merged.
+   #define __GXX_MERGED_TYPEINFO_NAMES 0
+ #elif !__GXX_WEAK__
+   // If weak symbols are not supported, they are still not merged.
+   #define __GXX_MERGED_TYPEINFO_NAMES 0
+ #else
+   // In the new ABI, on platforms that support weak symbols, they are
+   // merged.
+   #define __GXX_MERGED_TYPEINFO_NAMES 1
+ #endif
+ 
  namespace std 
  {
    class type_info 
*************** namespace std 
*** 73,100 ****
    public:
      // the public interface
  #if !defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100
-     // In old abi, there can be multiple instances of a type_info
-     // object for one type. Uniqueness must use the _name value, not
-     // object address.
-     bool before(const type_info& arg) const;
      const char* name() const
      { return __name; }
!     bool operator==(const type_info& __arg) const;
!     bool operator!=(const type_info& __arg) const
!     { return !operator==(__arg); }
  
  #else
      // In new abi we can rely on type_info's NTBS being unique,
      // and therefore address comparisons are sufficient.
      bool before(const type_info& __arg) const
      { return __name < __arg.__name; }
-     const char* name() const
-     { return __name; }
      bool operator==(const type_info& __arg) const
      { return __name == __arg.__name; }
      bool operator!=(const type_info& __arg) const
      { return !operator==(__arg); }
- #endif
      
      // the internal interface
  #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
--- 86,114 ----
    public:
      // the public interface
  #if !defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100
      const char* name() const
      { return __name; }
! #else
!     const char* name() const
!     { return __name; }
! #endif
  
+ #if !__GXX_MERGED_TYPEINFO_NAMES
+     bool before(const type_info& arg) const;
+     // In old abi, or when weak symbols are not supported, there can
+     // be multiple instances of a type_info object for one
+     // type. Uniqueness must use the _name value, not object address.
+     bool operator==(const type_info& __arg) const;
  #else
      // In new abi we can rely on type_info's NTBS being unique,
      // and therefore address comparisons are sufficient.
      bool before(const type_info& __arg) const
      { return __name < __arg.__name; }
      bool operator==(const type_info& __arg) const
      { return __name == __arg.__name; }
+ #endif
      bool operator!=(const type_info& __arg) const
      { return !operator==(__arg); }
      
      // the internal interface
  #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100

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