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]

Re: PR 2767, V3 regression failure on strstr et al



This gets rid of the ambiguity for the "C" functions that have
different C++ signatures, ie strchr et. al.

Stephen this is slightly different than your patch here:
http://gcc.gnu.org/ml/libstdc++/2001-05/msg00168.html

As Fergus Henderson noted, glibcpp pollutes the global namespace...not
a biggie. Also, I'd like to keep the signatures pedantically correct,
and not punt to the extern "C" version for the non-const versions even
though return types are not part of overload resolution. Hopefully
this will clue people in that neither of the std:: signatures for the
afflicted functions exactly match "C".

Comments?

2001-05-21  Stephen M. Webb  <stephen@bregmasoft.com>
	    Benjamin Kosnik  <bkoz@redhat.com>

	* include/c_std/bits/std_cstring.h (memchr): Define "C" functions to
	__glibcpp_memchr.
	(strchr): Same, but to __glibcpp_strchr.
	(strpbrk): Same.
	(strrchr): Same.
	(strstr): Same.  
	* include/c_std/bits/std_cwchar.h (wcschr): Same.
	(wcsbrk): Same.
	(wcsrchr): Same.
	(wcsstr): Same.
	(wmemchr): Same.

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.7
diff -c -p -r1.7 std_cstring.h
*** std_cstring.h	2001/05/08 23:53:55	1.7
--- std_cstring.h	2001/05/22 01:40:27
***************
*** 39,44 ****
--- 39,51 ----
  #include <bits/c++config.h>
  #include <bits/std_cstddef.h>
  
+ // 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>
  
*************** namespace std 
*** 82,128 ****
  
    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); 
--- 89,135 ----
  
    inline const void*
    memchr(const void* __p, int __c, size_t __n)
!   { return const_cast<const void*>(__glibcpp_memchr(__p, __c, __n)); }
  
    inline void*
    memchr(void* __p, int __c, size_t __n)
!   { return __glibcpp_memchr(const_cast<const void*>(__p), __c, __n); }
  
    inline const char*
    strchr(const char* __s1, int __n)
!   { return const_cast<const char*>(__glibcpp_strchr(__s1, __n)); }
  
    inline char*
    strchr(char* __s1, int __n)
!   { return __glibcpp_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*>(__glibcpp_strpbrk(__s1, __s2)); }
  
    inline char*
    strpbrk(char* __s1, const char* __s2)
!   { return __glibcpp_strpbrk(const_cast<const char*>(__s1), __s2); }
  
    inline const char*
    strrchr(const char* __s1, int __n)
!   { return const_cast<char*>(__glibcpp_strrchr(__s1, __n)); }
  
    inline char*
    strrchr(char* __s1, int __n)
!   { return __glibcpp_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*>(__glibcpp_strstr(__s1, __s2)); }
  
    inline char*
    strstr(char* __s1, const char* __s2)
!   { return __glibcpp_strstr(const_cast<const char*>(__s1), __s2); }
  
    extern "C" char* strtok(char*, const char*); 
    extern "C" void* memset(void*, int, size_t); 
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.9
diff -c -p -r1.9 std_cwchar.h
*** std_cwchar.h	2001/05/08 23:53:55	1.9
--- std_cwchar.h	2001/05/22 01:40:28
***************
*** 42,47 ****
--- 42,54 ----
  #include <bits/std_cstdarg.h>
  
  #if _GLIBCPP_HAVE_WCHAR_H
+ // Need to mangle these "C" functions because C++ modifies their signature.
+ #define wcschr  __glibcpp_wcschr
+ #define wcsbrk  __glibcpp_wcsbrk
+ #define wcsrchr  __glibcpp_wcsrchr
+ #define wcsstr  __glibcpp_wcsstr
+ #define wmemchr  __glibcpp_wmemchr
+ 
  #pragma GCC system_header
  #include <wchar.h>
  #endif
*************** namespace std
*** 159,208 ****
  
    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); 
--- 166,215 ----
  
    inline const wchar_t*
    wcschr(const wchar_t* __p, wchar_t __c)
!   { return const_cast<const wchar_t*>(__glibcpp_wcschr(__p, __c)); }
  
    inline wchar_t*
    wcschr(wchar_t* __p, wchar_t __c)
!   { return __glibcpp_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*>(__glibcpp_wcspbrk(__s1, __s2)); }
  
    inline wchar_t*
    wcspbrk(wchar_t* __s1, wchar_t* __s2)
!   { return __glibcpp_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*>(__glibcpp_wcsrchr(__p, __c)); }
  
    inline wchar_t*
    wcsrchr(wchar_t* __p, wchar_t __c)
!   { return __glibcpp_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*>(__glibcpp_wcsstr(__s1, __s2)); }
  
    inline wchar_t*
    wcsstr(wchar_t* __s1, wchar_t* __s2)
!   { return __glibcpp_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*>(__glibcpp_wmemchr(__p, __c, __n)); }
  
    inline wchar_t*
    wmemchr(wchar_t* __p, wchar_t __c, size_t __n)
!   { return __glibcpp_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); 


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