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]

C++ PATCH: Builtins (2 of 3)



This patch implements the V3 changes required now that g++ no longer
treats `std::foo' as a builtin for all of the functions in <cstring>.

Note that this also fixes some V3 testcases that should not have
compiled (they assumed names in global scope that should not have
been) and a use of `memset' in libsupc++ that should have been
`std::memset'.  Also, we get better code in some cases where the
V3 implementation of one variant of a function thunked back to
`::foo', which was not a builtin in C++.

Tested on i686-pc-linux-gnu, installed on the mainline and on the
branch.

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

2001-05-24  Mark Mitchell  <mark@codesourcery.com>

	* include/c_std/bits/std_cstring.h: #define away all global
	functions we will redeclare in namespace `std'.
	* libsupc++/eh_alloc.cc (__cxa_allocate_exception): Use
	std::memset, instead of memset.
	* testsuite/19_diagnostics/stdexceptions.cc: Use `std::strcmp',
	not plain `strcmp'.
	* testsuite/21_strings/c_strings.cc: Use `std::strcpy' instead of
	plain `strcpy'.
	
Index: libstdc++-v3/include/c_std/bits/std_cstring.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/c_std/bits/std_cstring.h,v
retrieving revision 1.5.2.2
diff -c -p -r1.5.2.2 std_cstring.h
*** std_cstring.h	2001/05/22 05:02:58	1.5.2.2
--- std_cstring.h	2001/05/25 00:56:15
***************
*** 41,51 ****
  
  
  // Need to mangle these "C" functions because C++ modifies their signature.
! #define memchr  __glibcpp_memchr
! #define strchr  __glibcpp_strchr
  #define strpbrk __glibcpp_strpbrk
  #define strrchr __glibcpp_strrchr
! #define strstr  __glibcpp_strstr
  
  #pragma GCC system_header
  #include <string.h>
--- 41,68 ----
  
  
  // Need to mangle these "C" functions because C++ modifies their signature.
! #define memcpy __glibcpp_memcpy
! #define memmove __glibcpp_memmove
! #define strcpy __glibcpp_strcpy
! #define strncpy __glibcpp_strncpy
! #define strcat __glibcpp_strcat
! #define strncat __glibcpp_strncat
! #define memcmp __glibcpp_memcmp
! #define strcmp __glibcpp_strcmp
! #define strcoll __glibcpp_strcoll
! #define strncmp __glibcpp_strncmp
! #define strxfrm __glibcpp_strxfrm
! #define memchr __glibcpp_memchr
! #define strchr __glibcpp_strchr
! #define strcspn __glibcpp_strcspn
  #define strpbrk __glibcpp_strpbrk
  #define strrchr __glibcpp_strrchr
! #define strspn __glibcpp_strspn
! #define strstr __glibcpp_strstr
! #define strtok __glibcpp_strtok
! #define memset __glibcpp_memset
! #define strerror __glibcpp_strerror
! #define strlen __glibcpp_strlen
  
  #pragma GCC system_header
  #include <string.h>
***************
*** 76,128 ****
  
  namespace std 
  {
!   extern "C" void* memcpy(void*, const void*, size_t); 
    extern "C" void* memmove(void*, const void*, size_t); 
!   extern "C" char* strcpy(char*, const char*); 
!   extern "C" char* strncpy(char*, const char*, size_t); 
!   extern "C" char* strcat(char*, const char*); 
!   extern "C" char* strncat(char*, const char*, size_t); 
!   extern "C" int memcmp(const void*, const void*, size_t); 
!   extern "C" int strcmp(const char*, const char*); 
    extern "C" int strcoll(const char*, const char*); 
!   extern "C" int strncmp(const char*, const char*, size_t); 
    extern "C" size_t strxfrm(char*, const char*, size_t); 
    extern "C" const void* memchr(const void*, int, size_t); 
    inline void*
    memchr(void* __p, int __c, size_t __n)
    {
      return const_cast<void*>(memchr(const_cast<const void*>(__p), __c, __n));
    }
!   extern "C" const char* strchr(const char*, int); 
    inline char*
    strchr(char* __s1, int __n)
    {
!     return const_cast<char*>(strchr(const_cast<const char*>(__s1), __n));
    }
!   extern "C" size_t strcspn(const char*, const char*); 
!   extern "C" const char* strpbrk(const char*, const char*); 
    inline char*
    strpbrk(char* __s1, const char* __s2)
    {
!     return const_cast<char*>(strpbrk(const_cast<const char*>(__s1), __s2));
    }
!   extern "C" const char* strrchr(const char*, int); 
    inline char*
    strrchr(char* __s1, int __n)
!   {
!     return const_cast<char*>(strrchr(const_cast<const char*>(__s1), __n));
!   }
!   extern "C" size_t strspn(const char*, const char*); 
!   extern "C" const char* strstr(const char*, const char*); 
    inline char*
    strstr(char* __s1, const char* __s2)
    {
!     return const_cast<char*>(strstr(const_cast<const char*>(__s1), __s2));
    }
    extern "C" char* strtok(char*, const char*); 
!   extern "C" void* memset(void*, int, size_t); 
    extern "C" char* strerror(int); 
!   extern "C" size_t strlen(const char*);
  }
  
  #endif
--- 93,203 ----
  
  namespace std 
  {
!   inline void*
!   memcpy(void* __p1, const void* __p2, size_t __n)
!   { return __builtin_memcpy(__p1, __p2, __n); }
! 
    extern "C" void* memmove(void*, const void*, size_t); 
! 
!   inline char*
!   strcpy(char* __s1, const char* __s2)
!   { return __builtin_strcpy(__s1, __s2); }
! 
!   inline char*
!   strncpy(char* __s1, const char* __s2, size_t __n)
!   { return __builtin_strncpy(__s1, __s2, __n); }
! 
!   inline char*
!   strcat(char* __s1, const char* __s2)
!   { return __builtin_strcat(__s1, __s2); }
! 
!   inline char*
!   strncat(char* __s1, const char* __s2, size_t __n)
!   { return __builtin_strncat(__s1, __s2, __n); }
! 
!   inline int
!   memcmp(const void* __p1, const void* __p2, size_t __n)
!   { return __builtin_memcmp(__p1, __p2, __n); }
! 
!   inline int
!   strcmp(const char* __s1, const char* __s2)
!   { return __builtin_strcmp(__s1, __s2); }
! 
    extern "C" int strcoll(const char*, const char*); 
! 
!   inline int
!   strncmp(const char* __s1, const char* __s2, size_t __n)
!   { return __builtin_strncmp(__s1, __s2, __n); }
! 
    extern "C" size_t strxfrm(char*, const char*, size_t); 
    extern "C" const void* memchr(const void*, int, size_t); 
+ 
    inline void*
    memchr(void* __p, int __c, size_t __n)
    {
      return const_cast<void*>(memchr(const_cast<const void*>(__p), __c, __n));
    }
! 
!   inline const char*
!   strchr(const char* __s1, int __n)
!   { return const_cast<const char*>(__builtin_strchr(__s1, __n)); }
! 
    inline char*
    strchr(char* __s1, int __n)
    {
!     return 
!       const_cast<char*>(__builtin_strchr(const_cast<const char*>(__s1), __n));
    }
! 
!   inline size_t
!   strcspn(const char* __s1, const char* __s2)
!   { return __builtin_strcspn(__s1, __s2); }
! 
!   inline const char*
!   strpbrk(const char* __s1, const char* __s2)
!   { return const_cast<char*>(__builtin_strpbrk(__s1, __s2)); }
! 
    inline char*
    strpbrk(char* __s1, const char* __s2)
    {
!     return const_cast<char*>
!       (__builtin_strpbrk(const_cast<const char*>(__s1), __s2));
    }
! 
!   inline const char*
!   strrchr(const char* __s1, int __n)
!   { return const_cast<char*>(__builtin_strrchr(__s1, __n)); }
! 
    inline char*
    strrchr(char* __s1, int __n)
!   { return __builtin_strrchr(const_cast<const char*>(__s1), __n); }
! 
!   inline size_t
!   strspn(const char* __s1, const char* __s2)
!   { return __builtin_strspn(__s1, __s2); }
! 
!   inline const char*
!   strstr(const char* __s1, const char* __s2)
!   { return const_cast<char*>(__builtin_strstr (__s1, __s2)); }
! 
    inline char*
    strstr(char* __s1, const char* __s2)
    {
!     return (const_cast<char*>
! 	    (__builtin_strstr(const_cast<const char*>(__s1), __s2)));
    }
+ 
    extern "C" char* strtok(char*, const char*); 
! 
!   inline void*
!   memset(void* __p, int __c, size_t __n)
!   { return __builtin_memset(__p, __c, __n); }
! 
    extern "C" char* strerror(int); 
! 
!   inline size_t
!   strlen(const char* __s)
!   { return __builtin_strlen(__s); }
  }
  
  #endif
Index: libstdc++-v3/libsupc++/eh_alloc.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/eh_alloc.cc,v
retrieving revision 1.2.2.1
diff -c -p -r1.2.2.1 eh_alloc.cc
*** eh_alloc.cc	2001/05/13 07:10:26	1.2.2.1
--- eh_alloc.cc	2001/05/25 00:56:15
*************** __cxa_allocate_exception(std::size_t thr
*** 133,139 ****
  	std::terminate ();
      }
  
!   memset (ret, 0, sizeof (__cxa_exception));
  
    return (void *)((char *)ret + sizeof (__cxa_exception));
  }
--- 133,139 ----
  	std::terminate ();
      }
  
!   std::memset (ret, 0, sizeof (__cxa_exception));
  
    return (void *)((char *)ret + sizeof (__cxa_exception));
  }
Index: libstdc++-v3/testsuite/19_diagnostics/stdexceptions.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/19_diagnostics/stdexceptions.cc,v
retrieving revision 1.1.2.4
diff -c -p -r1.1.2.4 stdexceptions.cc
*** stdexceptions.cc	2001/02/27 23:03:59	1.1.2.4
--- stdexceptions.cc	2001/05/25 00:56:15
*************** void test01()
*** 38,44 ****
    // 2
    // std::logic_error obj((std::string)strlit);
  
!   VERIFY( strcmp(obj.what(), s.data()) == 0 );
  }
  
  void test02()
--- 38,44 ----
    // 2
    // std::logic_error obj((std::string)strlit);
  
!   VERIFY( std::strcmp(obj.what(), s.data()) == 0 );
  }
  
  void test02()
*************** void test02()
*** 47,53 ****
    std::string s("lack of sunlight error");
    std::domain_error x(s);
    
!   VERIFY( strcmp(x.what(), s.data()) == 0 );
  }
  
  // libstdc++/2089
--- 47,53 ----
    std::string s("lack of sunlight error");
    std::domain_error x(s);
    
!   VERIFY( std::strcmp(x.what(), s.data()) == 0 );
  }
  
  // libstdc++/2089
*************** void test03()
*** 64,70 ****
    try
      { throw fuzzy_logic(); }
    catch(const fuzzy_logic& obj)
!     { VERIFY( strcmp("whoa", obj.what()) == 0 ); }
    catch(...)
      { VERIFY( false ); }
  }
--- 64,70 ----
    try
      { throw fuzzy_logic(); }
    catch(const fuzzy_logic& obj)
!     { VERIFY( std::strcmp("whoa", obj.what()) == 0 ); }
    catch(...)
      { VERIFY( false ); }
  }
*************** void test04()
*** 93,99 ****
      obj1 = obj2;
    }
    allocate_on_stack();
!   VERIFY( strcmp(strlit1, obj1.what()) == 0 ); 
  
    // block 02
    {
--- 93,99 ----
      obj1 = obj2;
    }
    allocate_on_stack();
!   VERIFY( std::strcmp(strlit1, obj1.what()) == 0 ); 
  
    // block 02
    {
*************** void test04()
*** 102,108 ****
      obj1 = obj3;
    }
    allocate_on_stack();     
!   VERIFY( strcmp(strlit2, obj1.what()) == 0 ); 
  }
  
  int main(void)
--- 102,108 ----
      obj1 = obj3;
    }
    allocate_on_stack();     
!   VERIFY( std::strcmp(strlit2, obj1.what()) == 0 ); 
  }
  
  int main(void)
Index: libstdc++-v3/testsuite/21_strings/c_strings.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/21_strings/c_strings.cc,v
retrieving revision 1.3.2.2
diff -c -p -r1.3.2.2 c_strings.cc
*** c_strings.cc	2001/05/22 05:02:58	1.3.2.2
--- c_strings.cc	2001/05/25 00:56:15
*************** void test01()
*** 34,40 ****
    const char* ccarray1 = "san francisco roof garden inspectors";
    const char* ccarray2 = "san francisco sunny-day park inspectors";
    char carray[30];
!   strcpy(carray, ccarray1);
    void* v = carray;
    const void* cv = ccarray1;
    
--- 34,40 ----
    const char* ccarray1 = "san francisco roof garden inspectors";
    const char* ccarray2 = "san francisco sunny-day park inspectors";
    char carray[30];
!   std::strcpy(carray, ccarray1);
    void* v = carray;
    const void* cv = ccarray1;
    


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