From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10578 invoked by alias); 30 Jan 2009 16:13:08 -0000 Received: (qmail 10445 invoked by uid 22791); 30 Jan 2009 16:13:08 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,SARE_SUB_6CONS_WORD X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 30 Jan 2009 16:13:02 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id n0UGGLg8029329; Fri, 30 Jan 2009 17:16:21 +0100 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id n0UGGLd8029328; Fri, 30 Jan 2009 17:16:21 +0100 Date: Fri, 30 Jan 2009 16:13:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fixes for C++ strchr etc. overloads Message-ID: <20090130161620.GA16681@sunsite.ms.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2009-01/txt/msg00013.txt.bz2 Hi! This patch fixes two problems with the patch from yesterday. 1) #include #include no longer compiles in C++, the same overloads for index/rindex need to be present in both. 2) When the functions are extern "C++", they are no longer considered builtins, so little help (inline wrappers) is needed to tell G++ that they can be optimized if possible. Tested with the testcases posted to gcc-patches today. 2009-01-30 Jakub Jelinek * string/string.h (memchr, strchr, strrchr, strpbrk, strstr, index, rindex): For C++ add inlines so that they can be recognized as builtins. * string/strings.h: Define correct C++ prototypes for gcc 4.4. --- libc/string/string.h.jj 2009-01-30 13:26:22.000000000 +0100 +++ libc/string/string.h 2009-01-30 14:21:47.000000000 +0100 @@ -69,10 +69,27 @@ extern int memcmp (__const void *__s1, _ /* Search N bytes of S for C. */ #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO -extern "C++" void *memchr (void *__s, int __c, size_t __n) +extern "C++" +{ +extern void *memchr (void *__s, int __c, size_t __n) __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1)); -extern "C++" __const void *memchr (__const void *__s, int __c, size_t __n) +extern __const void *memchr (__const void *__s, int __c, size_t __n) __THROW __asm ("memchr") __attribute_pure__ __nonnull ((1)); + +# ifdef __OPTIMIZE__ +__extern_always_inline void * +memchr (void *__s, int __c, size_t __n) __THROW +{ + return __builtin_memchr (__s, __c, __n); +} + +__extern_always_inline __const void * +memchr (__const void *__s, int __c, size_t __n) __THROW +{ + return __builtin_memchr (__s, __c, __n); +} +# endif +} #else extern void *memchr (__const void *__s, int __c, size_t __n) __THROW __attribute_pure__ __nonnull ((1)); @@ -191,20 +208,54 @@ extern char *strndup (__const char *__st __BEGIN_NAMESPACE_STD /* Find the first occurrence of C in S. */ #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO -extern "C++" char *strchr (char *__s, int __c) +extern "C++" +{ +extern char *strchr (char *__s, int __c) __THROW __asm ("strchr") __attribute_pure__ __nonnull ((1)); -extern "C++" __const char *strchr (__const char *__s, int __c) +extern __const char *strchr (__const char *__s, int __c) __THROW __asm ("strchr") __attribute_pure__ __nonnull ((1)); + +# ifdef __OPTIMIZE__ +__extern_always_inline char * +strchr (char *__s, int __c) __THROW +{ + return __builtin_strchr (__s, __c); +} + +__extern_always_inline __const char * +strchr (__const char *__s, int __c) __THROW +{ + return __builtin_strchr (__s, __c); +} +# endif +} #else extern char *strchr (__const char *__s, int __c) __THROW __attribute_pure__ __nonnull ((1)); #endif /* Find the last occurrence of C in S. */ #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO -extern "C++" char *strrchr (char *__s, int __c) +extern "C++" +{ +extern char *strrchr (char *__s, int __c) __THROW __asm ("strrchr") __attribute_pure__ __nonnull ((1)); -extern "C++" __const char *strrchr (__const char *__s, int __c) +extern __const char *strrchr (__const char *__s, int __c) __THROW __asm ("strrchr") __attribute_pure__ __nonnull ((1)); + +# ifdef __OPTIMIZE__ +__extern_always_inline char * +strrchr (char *__s, int __c) __THROW +{ + return __builtin_strrchr (__s, __c); +} + +__extern_always_inline __const char * +strrchr (__const char *__s, int __c) __THROW +{ + return __builtin_strrchr (__s, __c); +} +# endif +} #else extern char *strrchr (__const char *__s, int __c) __THROW __attribute_pure__ __nonnull ((1)); @@ -236,21 +287,55 @@ extern size_t strspn (__const char *__s, __THROW __attribute_pure__ __nonnull ((1, 2)); /* Find the first occurrence in S of any character in ACCEPT. */ #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO -extern "C++" char *strpbrk (char *__s, __const char *__accept) +extern "C++" +{ +extern char *strpbrk (char *__s, __const char *__accept) __THROW __asm ("strpbrk") __attribute_pure__ __nonnull ((1, 2)); -extern "C++" __const char *strpbrk (__const char *__s, __const char *__accept) +extern __const char *strpbrk (__const char *__s, __const char *__accept) __THROW __asm ("strpbrk") __attribute_pure__ __nonnull ((1, 2)); + +# ifdef __OPTIMIZE__ +__extern_always_inline char * +strpbrk (char *__s, __const char *__accept) __THROW +{ + return __builtin_strpbrk (__s, __accept); +} + +__extern_always_inline __const char * +strpbrk (__const char *__s, __const char *__accept) __THROW +{ + return __builtin_strpbrk (__s, __accept); +} +# endif +} #else extern char *strpbrk (__const char *__s, __const char *__accept) __THROW __attribute_pure__ __nonnull ((1, 2)); #endif /* Find the first occurrence of NEEDLE in HAYSTACK. */ #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO -extern "C++" char *strstr (char *__haystack, __const char *__needle) +extern "C++" +{ +extern char *strstr (char *__haystack, __const char *__needle) __THROW __asm ("strstr") __attribute_pure__ __nonnull ((1, 2)); -extern "C++" __const char *strstr (__const char *__haystack, - __const char *__needle) +extern __const char *strstr (__const char *__haystack, + __const char *__needle) __THROW __asm ("strstr") __attribute_pure__ __nonnull ((1, 2)); + +# ifdef __OPTIMIZE__ +__extern_always_inline char * +strstr (char *__haystack, __const char *__needle) __THROW +{ + return __builtin_strstr (__haystack, __needle); +} + +__extern_always_inline __const char * +strstr (__const char *__haystack, __const char *__needle) __THROW +{ + return __builtin_strstr (__haystack, __needle); +} +# endif +} #else extern char *strstr (__const char *__haystack, __const char *__needle) __THROW __attribute_pure__ __nonnull ((1, 2)); @@ -377,10 +462,27 @@ extern int bcmp (__const void *__s1, __c /* Find the first occurrence of C in S (same as strchr). */ # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO -extern "C++" char *index (char *__s, int __c) +extern "C++" +{ +extern char *index (char *__s, int __c) __THROW __asm ("index") __attribute_pure__ __nonnull ((1)); -extern "C++" __const char *index (__const char *__s, int __c) +extern __const char *index (__const char *__s, int __c) __THROW __asm ("index") __attribute_pure__ __nonnull ((1)); + +# if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRINGS_H_PROTO +__extern_always_inline char * +index (char *__s, int __c) __THROW +{ + return __builtin_index (__s, __c); +} + +__extern_always_inline __const char * +index (__const char *__s, int __c) __THROW +{ + return __builtin_index (__s, __c); +} +# endif +} # else extern char *index (__const char *__s, int __c) __THROW __attribute_pure__ __nonnull ((1)); @@ -388,10 +490,27 @@ extern char *index (__const char *__s, i /* Find the last occurrence of C in S (same as strrchr). */ # ifdef __CORRECT_ISO_CPP_STRING_H_PROTO -extern "C++" char *rindex (char *__s, int __c) +extern "C++" +{ +extern char *rindex (char *__s, int __c) __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1)); -extern "C++" __const char *rindex (__const char *__s, int __c) +extern __const char *rindex (__const char *__s, int __c) __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1)); + +# if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRINGS_H_PROTO +__extern_always_inline char * +rindex (char *__s, int __c) __THROW +{ + return __builtin_rindex (__s, __c); +} + +__extern_always_inline __const char * +rindex (__const char *__s, int __c) __THROW +{ + return __builtin_rindex (__s, __c); +} +#endif +} # else extern char *rindex (__const char *__s, int __c) __THROW __attribute_pure__ __nonnull ((1)); --- libc/string/strings.h.jj 2001-07-06 06:55:41.000000000 +0200 +++ libc/string/strings.h 2009-01-30 14:22:40.000000000 +0100 @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,92,96,97,99,2000,2001 Free Software Foundation, Inc. +/* Copyright (C) 1991,92,96,97,99,2000,2001,2009 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -28,6 +28,11 @@ # define __need_size_t # include +/* Tell the caller that we provide correct C++ prototypes. */ +# if defined __cplusplus && __GNUC_PREREQ (4, 4) +# define __CORRECT_ISO_CPP_STRINGS_H_PROTO +# endif + __BEGIN_DECLS /* Compare N bytes of S1 and S2 (same as memcmp). */ @@ -45,10 +50,60 @@ extern void bzero (void *__s, size_t __n extern int ffs (int __i) __THROW __attribute__ ((const)); /* Find the first occurrence of C in S (same as strchr). */ -extern char *index (__const char *__s, int __c) __THROW __attribute_pure__; +# ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO +extern "C++" +{ +extern char *index (char *__s, int __c) + __THROW __asm ("index") __attribute_pure__ __nonnull ((1)); +extern __const char *index (__const char *__s, int __c) + __THROW __asm ("index") __attribute_pure__ __nonnull ((1)); + +# if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO +__extern_always_inline char * +index (char *__s, int __c) __THROW +{ + return __builtin_index (__s, __c); +} + +__extern_always_inline __const char * +index (__const char *__s, int __c) __THROW +{ + return __builtin_index (__s, __c); +} +# endif +} +# else +extern char *index (__const char *__s, int __c) + __THROW __attribute_pure__ __nonnull ((1)); +# endif /* Find the last occurrence of C in S (same as strrchr). */ -extern char *rindex (__const char *__s, int __c) __THROW __attribute_pure__; +# ifdef __CORRECT_ISO_CPP_STRINGS_H_PROTO +extern "C++" +{ +extern char *rindex (char *__s, int __c) + __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1)); +extern __const char *rindex (__const char *__s, int __c) + __THROW __asm ("rindex") __attribute_pure__ __nonnull ((1)); + +# if defined __OPTIMIZE__ && !defined __CORRECT_ISO_CPP_STRING_H_PROTO +__extern_always_inline char * +rindex (char *__s, int __c) __THROW +{ + return __builtin_rindex (__s, __c); +} + +__extern_always_inline __const char * +rindex (__const char *__s, int __c) __THROW +{ + return __builtin_rindex (__s, __c); +} +#endif +} +# else +extern char *rindex (__const char *__s, int __c) + __THROW __attribute_pure__ __nonnull ((1)); +# endif /* Compare S1 and S2, ignoring case. */ extern int strcasecmp (__const char *__s1, __const char *__s2) Jakub