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]

[v3] "C" string/wchar fixes



Found while working on libstdc++/2767

With this, two more errors are activated, so you'll see a jump in
unexpected failures.

-benjamin

2001-05-08  Benjamin Kosnik  <bkoz@fillmore.constant.com>

	* include/c_std/bits/std_cstring.h (memchr): Correct definitions.
	(strchr): Same.
	(strpbrk): Same.
	(strrchr): Same.
	(strstr): Same.
	* include/c_std/bits/std_cwchar.h (wcschr): Same.
	(wcsbrk): Same.
	(wcsrchr): Same.
	(wcsstr): Same.
	(wmemchr): Same.
	* testsuite/21_strings/c_strings.cc: Add tests.

Index: 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.6
diff -c -p -r1.6 std_cstring.h
*** std_cstring.h	2001/04/02 22:51:25	1.6
--- std_cstring.h	2001/05/08 23:50:55
*************** namespace std 
*** 79,116 ****
    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); 
--- 79,129 ----
    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); 
! 
!   inline const void*
!   memchr(const void* __p, int __c, size_t __n)
!   { return const_cast<const void*>(::memchr(__p, __c, __n)); }
! 
    inline void*
    memchr(void* __p, int __c, size_t __n)
!   { return ::memchr(const_cast<const void*>(__p), __c, __n); }
! 
!   inline const char*
!   strchr(const char* __s1, int __n)
!   { return const_cast<const char*>(::strchr(__s1, __n)); }
! 
    inline char*
    strchr(char* __s1, int __n)
!   { return ::strchr(const_cast<const char*>(__s1), __n); }
! 
    extern "C" size_t strcspn(const char*, const char*); 
! 
!   inline const char*
!   strpbrk(const char* __s1, const char* __s2)
!   { return const_cast<char*>(::strpbrk(__s1, __s2)); }
! 
    inline char*
    strpbrk(char* __s1, const char* __s2)
!   { return ::strpbrk(const_cast<const char*>(__s1), __s2); }
! 
!   inline const char*
!   strrchr(const char* __s1, int __n)
!   { return const_cast<char*>(::strrchr(__s1, __n)); }
! 
    inline char*
    strrchr(char* __s1, int __n)
!   { return ::strrchr(const_cast<const char*>(__s1), __n); }
! 
    extern "C" size_t strspn(const char*, const char*); 
! 
!   inline const char*
!   strstr(const char* __s1, const char* __s2)
!   { return const_cast<char*>(::strstr(__s1, __s2)); }
! 
    inline char*
    strstr(char* __s1, const char* __s2)
!   { return ::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); 
Index: include/c_std/bits/std_cwchar.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/c_std/bits/std_cwchar.h,v
retrieving revision 1.8
diff -c -p -r1.8 std_cwchar.h
*** std_cwchar.h	2001/04/26 02:23:51	1.8
--- std_cwchar.h	2001/05/08 23:50:56
*************** namespace std
*** 156,195 ****
    extern "C" int wcscoll(const wchar_t*, const wchar_t*); 
    extern "C" int wcsncmp(const wchar_t*, const wchar_t*, size_t); 
    extern "C" size_t wcsxfrm(wchar_t*, const wchar_t*, size_t); 
!   extern "C" const wchar_t* wcschr(const wchar_t*, wchar_t); 
    inline wchar_t*
    wcschr(wchar_t* __p, wchar_t __c)
!   {
!     return const_cast<wchar_t*>(wcschr(const_cast<const wchar_t*>(__p), __c));
!   }
    extern "C" size_t wcscspn(const wchar_t*, const wchar_t*); 
    extern "C" size_t wcslen(const wchar_t*); 
!   extern "C" const wchar_t* wcspbrk(const wchar_t*, const wchar_t*); 
    inline wchar_t*
    wcspbrk(wchar_t* __s1, wchar_t* __s2)
!   {
!     return const_cast<wchar_t*>(wcspbrk(const_cast<const wchar_t*>(__s1), __s2));
!   }
!   extern "C" const wchar_t* wcsrchr(const wchar_t*, wchar_t); 
    inline wchar_t*
    wcsrchr(wchar_t* __p, wchar_t __c)
!   {
!     return const_cast<wchar_t*>(wcsrchr(const_cast<const wchar_t*>(__p), __c));
!   }
    extern "C" size_t wcsspn(const wchar_t*, const wchar_t*); 
!   extern "C" const wchar_t* wcsstr(const wchar_t*, const wchar_t*); 
    inline wchar_t*
    wcsstr(wchar_t* __s1, wchar_t* __s2)
!   {
!     return const_cast<wchar_t*>(wcsstr(const_cast<const wchar_t*>(__s1), __s2));
!   }
    extern "C" wchar_t* wcstok(wchar_t*, const wchar_t*, wchar_t**); 
!   extern "C" const wchar_t* wmemchr(const wchar_t*, wchar_t, size_t);
    inline wchar_t*
    wmemchr(wchar_t* __p, wchar_t __c, size_t __n)
!   {
!     return const_cast<wchar_t*>(wmemchr(const_cast<const wchar_t*>(__p), __c, __n));
!   }
    extern "C" int wmemcmp(const wchar_t*, const wchar_t*, size_t); 
    extern "C" wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t); 
    extern "C" wchar_t* wmemmove(wchar_t*, const wchar_t*, size_t); 
--- 156,209 ----
    extern "C" int wcscoll(const wchar_t*, const wchar_t*); 
    extern "C" int wcsncmp(const wchar_t*, const wchar_t*, size_t); 
    extern "C" size_t wcsxfrm(wchar_t*, const wchar_t*, size_t); 
! 
!   inline const wchar_t*
!   wcschr(const wchar_t* __p, wchar_t __c)
!   { return const_cast<const wchar_t*>(::wcschr(__p, __c)); }
! 
    inline wchar_t*
    wcschr(wchar_t* __p, wchar_t __c)
!   { return ::wcschr(const_cast<const wchar_t*>(__p), __c); }
! 
    extern "C" size_t wcscspn(const wchar_t*, const wchar_t*); 
    extern "C" size_t wcslen(const wchar_t*); 
! 
!   inline const wchar_t*
!   wcspbrk(const wchar_t* __s1, wchar_t* __s2)
!   { return const_cast<const wchar_t*>(::wcspbrk(__s1, __s2)); }
! 
    inline wchar_t*
    wcspbrk(wchar_t* __s1, wchar_t* __s2)
!   { return ::wcspbrk(const_cast<const wchar_t*>(__s1), __s2); }
! 
!   inline const wchar_t*
!   wcsrchr(const wchar_t* __p, wchar_t __c)
!   { return const_cast<const wchar_t*>(::wcsrchr(__p, __c)); }
! 
    inline wchar_t*
    wcsrchr(wchar_t* __p, wchar_t __c)
!   { return ::wcsrchr(const_cast<const wchar_t*>(__p), __c); }
! 
    extern "C" size_t wcsspn(const wchar_t*, const wchar_t*); 
! 
!   inline const wchar_t*
!   wcsstr(const wchar_t* __s1, wchar_t* __s2)
!   { return const_cast<const wchar_t*>(::wcsstr(__s1, __s2)); }
! 
    inline wchar_t*
    wcsstr(wchar_t* __s1, wchar_t* __s2)
!   { return ::wcsstr(const_cast<const wchar_t*>(__s1), __s2); }
! 
    extern "C" wchar_t* wcstok(wchar_t*, const wchar_t*, wchar_t**); 
! 
!   inline const wchar_t*
!   wmemchr(const wchar_t* __p, wchar_t __c, size_t __n)
!   { return const_cast<wchar_t*>(::wmemchr(__p, __c, __n)); }
! 
    inline wchar_t*
    wmemchr(wchar_t* __p, wchar_t __c, size_t __n)
!   { return ::wmemchr(const_cast<const wchar_t*>(__p), __c, __n); }
! 
    extern "C" int wmemcmp(const wchar_t*, const wchar_t*, size_t); 
    extern "C" wchar_t* wmemcpy(wchar_t*, const wchar_t*, size_t); 
    extern "C" wchar_t* wmemmove(wchar_t*, const wchar_t*, size_t); 
Index: testsuite/21_strings/c_strings.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/21_strings/c_strings.cc,v
retrieving revision 1.1
diff -c -p -r1.1 c_strings.cc
*** c_strings.cc	2001/04/02 22:01:52	1.1
--- c_strings.cc	2001/05/08 23:50:57
***************
*** 24,30 ****
  #include <cstring>
  #include <cwchar>
  
! int main()
  {
    bool test = true;
    char c = 'a';
--- 24,30 ----
  #include <cstring>
  #include <cwchar>
  
! void test01()
  {
    bool test = true;
    char c = 'a';
*************** int main()
*** 62,67 ****
--- 62,95 ----
    // void* memchr(      void* s, int c, size_t n);
    cv = std::memchr(cv, 'a', 3);
    v = std::memchr(v, 'a', 3);
+ }
  
+ void test02()
+ {
+   using namespace std;
+ 
+   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;
+   const void* cv;
+  
+   memchr(cv, '/', 3);
+   strchr(ccarray1, '/');
+   strpbrk(ccarray1, ccarray2);
+   strrchr(ccarray1, 'c');
+   strstr(carray, carray);
+ }
+ 
+ int main()
+ {
+   test01();
+   test02();
+ 
    return 0;
  }
+ 
+ 
+ 
+ 


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