std_cstring.h: #define away all global functions we will redeclare in namespace `std'.

* include/c_std/bin/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'.

From-SVN: r42555
This commit is contained in:
Mark Mitchell 2001-05-25 01:33:21 +00:00 committed by Mark Mitchell
parent f5aada2647
commit eeff8d2c06
5 changed files with 118 additions and 32 deletions

View File

@ -1,3 +1,14 @@
2001-05-24 Mark Mitchell <mark@codesourcery.com>
* include/c_std/bin/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'.
2001-05-24 Benjamin Kosnik <bkoz@redhat.com>
libstdc++/2832

View File

@ -41,11 +41,28 @@
// Need to mangle these "C" functions because C++ modifies their signature.
#define memchr __glibcpp_memchr
#define strchr __glibcpp_strchr
#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 strstr __glibcpp_strstr
#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,53 +93,111 @@
namespace std
{
extern "C" void* memcpy(void*, const void*, size_t);
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);
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*);
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*);
extern "C" int strncmp(const char*, const char*, size_t);
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));
}
extern "C" const char* strchr(const char*, int);
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*>(strchr(const_cast<const char*>(__s1), __n));
return
const_cast<char*>(__builtin_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 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*>(strpbrk(const_cast<const char*>(__s1), __s2));
return const_cast<char*>
(__builtin_strpbrk(const_cast<const char*>(__s1), __s2));
}
extern "C" const char* strrchr(const char*, int);
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 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*);
{ 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*>(strstr(const_cast<const char*>(__s1), __s2));
return (const_cast<char*>
(__builtin_strstr(const_cast<const char*>(__s1), __s2)));
}
extern "C" char* strtok(char*, const char*);
extern "C" void* memset(void*, int, size_t);
inline void*
memset(void* __p, int __c, size_t __n)
{ return __builtin_memset(__p, __c, __n); }
extern "C" char* strerror(int);
extern "C" size_t strlen(const char*);
inline size_t
strlen(const char* __s)
{ return __builtin_strlen(__s); }
}
#endif

View File

@ -133,7 +133,7 @@ __cxa_allocate_exception(std::size_t thrown_size)
std::terminate ();
}
memset (ret, 0, sizeof (__cxa_exception));
std::memset (ret, 0, sizeof (__cxa_exception));
return (void *)((char *)ret + sizeof (__cxa_exception));
}

View File

@ -38,7 +38,7 @@ void test01()
// 2
// std::logic_error obj((std::string)strlit);
VERIFY( strcmp(obj.what(), s.data()) == 0 );
VERIFY( std::strcmp(obj.what(), s.data()) == 0 );
}
void test02()
@ -47,7 +47,7 @@ void test02()
std::string s("lack of sunlight error");
std::domain_error x(s);
VERIFY( strcmp(x.what(), s.data()) == 0 );
VERIFY( std::strcmp(x.what(), s.data()) == 0 );
}
// libstdc++/2089
@ -64,7 +64,7 @@ void test03()
try
{ throw fuzzy_logic(); }
catch(const fuzzy_logic& obj)
{ VERIFY( strcmp("whoa", obj.what()) == 0 ); }
{ VERIFY( std::strcmp("whoa", obj.what()) == 0 ); }
catch(...)
{ VERIFY( false ); }
}
@ -93,7 +93,7 @@ void test04()
obj1 = obj2;
}
allocate_on_stack();
VERIFY( strcmp(strlit1, obj1.what()) == 0 );
VERIFY( std::strcmp(strlit1, obj1.what()) == 0 );
// block 02
{
@ -102,7 +102,7 @@ void test04()
obj1 = obj3;
}
allocate_on_stack();
VERIFY( strcmp(strlit2, obj1.what()) == 0 );
VERIFY( std::strcmp(strlit2, obj1.what()) == 0 );
}
int main(void)

View File

@ -34,7 +34,7 @@ void test01()
const char* ccarray1 = "san francisco roof garden inspectors";
const char* ccarray2 = "san francisco sunny-day park inspectors";
char carray[30];
strcpy(carray, ccarray1);
std::strcpy(carray, ccarray1);
void* v = carray;
const void* cv = ccarray1;