This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Ping: [PATCH] Simplify macros in string/bits/string2.h.


ping
On Sun, Feb 24, 2013 at 09:51:29AM +0100, OndÅej BÃlka wrote:
> Hello, 
> Header string/bits/string2.h contains several versions of quite long macros
> that differ only in calling builtin version instead normal.
> 
> To simplify future changes I unified them by adding macro
> __BUILTIN_SINCE_GCC_3_2 which selects builtin version when appropriate.
> 
> 2013-02-24  OndÅej BÃlka  <neleai@seznam.cz>
> 
> 	* string/bits/string2.h: Add __BUILTIN_SINCE_GCC_3_2 macro.
> 	(strchr) Unify pre and post gcc-3.2 versions.
> 	(strcmp) Likewise.
> 	(strcspn) Likewise.
> 	(strspn) Likewise.
> 	(strpbrk) Likewise.
> 
> ---
>  string/bits/string2.h |  130 +++++++++++--------------------------------------
>  1 files changed, 28 insertions(+), 102 deletions(-)
> 
> diff --git a/string/bits/string2.h b/string/bits/string2.h
> index 94f5ee9..a850649 100644
> --- a/string/bits/string2.h
> +++ b/string/bits/string2.h
> @@ -21,6 +21,13 @@
>  # error "Never use <bits/string2.h> directly; include <string.h> instead."
>  #endif
>  
> +
> +#if __GNUC_PREREQ (3, 2)
> +# define __BUILTIN_SINCE_GCC_3_2(fn) __builtin_##fn
> +#else
> +# define __BUILTIN_SINCE_GCC_3_2(fn) fn
> +#endif
> +
>  #ifndef __NO_STRING_INLINES
>  
>  /* Unlike the definitions in the header <bits/string.h> the
> @@ -197,6 +204,7 @@ __STRING2_COPY_TYPE (8);
>  #endif
>  
>  
> +
>  /* Copy N bytes from SRC to DEST, returning pointer to byte following the
>     last copied.  */
>  #ifdef __USE_GNU
> @@ -391,18 +399,10 @@ __mempcpy_small (void *__dest, char __src1,
>  /* Return pointer to C in S.  */
>  #ifndef _HAVE_STRING_ARCH_strchr
>  extern void *__rawmemchr (const void *__s, int __c);
> -# if __GNUC_PREREQ (3, 2)
> -#  define strchr(s, c) \
> -  (__extension__ (__builtin_constant_p (c) && !__builtin_constant_p (s)	      \
> -		  && (c) == '\0'					      \
> -		  ? (char *) __rawmemchr (s, c)				      \
> -		  : __builtin_strchr (s, c)))
> -# else
> -#  define strchr(s, c) \
> +# define strchr(s, c) \
>    (__extension__ (__builtin_constant_p (c) && (c) == '\0'		      \
>  		  ? (char *) __rawmemchr (s, c)				      \
> -		  : strchr (s, c)))
> -# endif
> +		  : __BUILTIN_SINCE_GCC_3_2 (strchr) (s, c)))
>  #endif
>  
>  
> @@ -795,48 +795,25 @@ __stpcpy_small (char *__dest,
>  
>  /* Compare characters of S1 and S2.  */
>  #ifndef _HAVE_STRING_ARCH_strcmp
> -# if __GNUC_PREREQ (3, 2)
> -#  define strcmp(s1, s2) \
> +# define strcmp(s1, s2) \
>    __extension__								      \
>    ({ size_t __s1_len, __s2_len;						      \
>       (__builtin_constant_p (s1) && __builtin_constant_p (s2)		      \
>        && (__s1_len = strlen (s1), __s2_len = strlen (s2),		      \
>  	  (!__string2_1bptr_p (s1) || __s1_len >= 4)			      \
>  	  && (!__string2_1bptr_p (s2) || __s2_len >= 4))		      \
> -      ? __builtin_strcmp (s1, s2)					      \
> +      ? __BUILTIN_SINCE_GCC_3_2 (strcmp) (s1, s2)			      \
>        : (__builtin_constant_p (s1) && __string2_1bptr_p (s1)		      \
>  	 && (__s1_len = strlen (s1), __s1_len < 4)			      \
>  	 ? (__builtin_constant_p (s2) && __string2_1bptr_p (s2)		      \
> -	    ? __builtin_strcmp (s1, s2)					      \
> +	    ? __BUILTIN_SINCE_GCC_3_2 (strcmp) (s1, s2)			      \
>  	    : __strcmp_cg (s1, s2, __s1_len))				      \
>  	 : (__builtin_constant_p (s2) && __string2_1bptr_p (s2)		      \
>  	    && (__s2_len = strlen (s2), __s2_len < 4)			      \
>  	    ? (__builtin_constant_p (s1) && __string2_1bptr_p (s1)	      \
> -	       ? __builtin_strcmp (s1, s2)				      \
> +	       ? __BUILTIN_SINCE_GCC_3_2 (strcmp) (s1, s2)		      \
>  	       : __strcmp_gc (s1, s2, __s2_len))			      \
> -	    : __builtin_strcmp (s1, s2)))); })
> -# else
> -#  define strcmp(s1, s2) \
> -  __extension__								      \
> -  ({ size_t __s1_len, __s2_len;						      \
> -     (__builtin_constant_p (s1) && __builtin_constant_p (s2)		      \
> -      && (__s1_len = strlen (s1), __s2_len = strlen (s2),		      \
> -	  (!__string2_1bptr_p (s1) || __s1_len >= 4)			      \
> -	  && (!__string2_1bptr_p (s2) || __s2_len >= 4))		      \
> -      ? memcmp ((const char *) (s1), (const char *) (s2),		      \
> -		(__s1_len < __s2_len ? __s1_len : __s2_len) + 1)	      \
> -      : (__builtin_constant_p (s1) && __string2_1bptr_p (s1)		      \
> -	 && (__s1_len = strlen (s1), __s1_len < 4)			      \
> -	 ? (__builtin_constant_p (s2) && __string2_1bptr_p (s2)		      \
> -	    ? __strcmp_cc (s1, s2, __s1_len)				      \
> -	    : __strcmp_cg (s1, s2, __s1_len))				      \
> -	 : (__builtin_constant_p (s2) && __string2_1bptr_p (s2)		      \
> -	    && (__s2_len = strlen (s2), __s2_len < 4)			      \
> -	    ? (__builtin_constant_p (s1) && __string2_1bptr_p (s1)	      \
> -	       ? __strcmp_cc (s1, s2, __s2_len)				      \
> -	       : __strcmp_gc (s1, s2, __s2_len))			      \
> -	    : strcmp (s1, s2)))); })
> -# endif
> +	    : __BUILTIN_SINCE_GCC_3_2 (strcmp) (s1, s2)))); })
>  
>  # define __strcmp_cc(s1, s2, l) \
>    (__extension__ ({ register int __result =				      \
> @@ -930,13 +907,12 @@ __stpcpy_small (char *__dest,
>     consists entirely of characters not in REJECT.  */
>  #if !defined _HAVE_STRING_ARCH_strcspn || defined _FORCE_INLINES
>  # ifndef _HAVE_STRING_ARCH_strcspn
> -#  if __GNUC_PREREQ (3, 2)
> -#   define strcspn(s, reject) \
> +#  define strcspn(s, reject) \
>    __extension__								      \
>    ({ char __r0, __r1, __r2;						      \
>       (__builtin_constant_p (reject) && __string2_1bptr_p (reject)	      \
>        ? ((__builtin_constant_p (s) && __string2_1bptr_p (s))		      \
> -	 ? __builtin_strcspn (s, reject)				      \
> +	 ? __BUILTIN_SINCE_GCC_3_2(strcspn) (s, reject)			      \
>  	 : ((__r0 = ((const char *) (reject))[0], __r0 == '\0')		      \
>  	    ? strlen (s)						      \
>  	    : ((__r1 = ((const char *) (reject))[1], __r1 == '\0')	      \
> @@ -945,24 +921,8 @@ __stpcpy_small (char *__dest,
>  		  ? __strcspn_c2 (s, __r0, __r1)			      \
>  		  : (((const char *) (reject))[3] == '\0'		      \
>  		     ? __strcspn_c3 (s, __r0, __r1, __r2)		      \
> -		     : __builtin_strcspn (s, reject))))))		      \
> -      : __builtin_strcspn (s, reject)); })
> -#  else
> -#   define strcspn(s, reject) \
> -  __extension__								      \
> -  ({ char __r0, __r1, __r2;						      \
> -     (__builtin_constant_p (reject) && __string2_1bptr_p (reject)	      \
> -      ? ((__r0 = ((const char *) (reject))[0], __r0 == '\0')		      \
> -	 ? strlen (s)							      \
> -	 : ((__r1 = ((const char *) (reject))[1], __r1 == '\0')		      \
> -	    ? __strcspn_c1 (s, __r0)					      \
> -	    : ((__r2 = ((const char *) (reject))[2], __r2 == '\0')	      \
> -	       ? __strcspn_c2 (s, __r0, __r1)				      \
> -	       : (((const char *) (reject))[3] == '\0'			      \
> -		  ? __strcspn_c3 (s, __r0, __r1, __r2)			      \
> -		  : strcspn (s, reject)))))				      \
> -      : strcspn (s, reject)); })
> -#  endif
> +		     : __BUILTIN_SINCE_GCC_3_2(strcspn) (s, reject))))))      \
> +      : __BUILTIN_SINCE_GCC_3_2(strcspn) (s, reject)); })
>  # endif
>  
>  __STRING_INLINE size_t __strcspn_c1 (const char *__s, int __reject);
> @@ -1006,13 +966,12 @@ __strcspn_c3 (const char *__s, int __reject1, int __reject2,
>     consists entirely of characters in ACCEPT.  */
>  #if !defined _HAVE_STRING_ARCH_strspn || defined _FORCE_INLINES
>  # ifndef _HAVE_STRING_ARCH_strspn
> -#  if __GNUC_PREREQ (3, 2)
> -#   define strspn(s, accept) \
> +#  define strspn(s, accept) \
>    __extension__								      \
>    ({ char __a0, __a1, __a2;						      \
>       (__builtin_constant_p (accept) && __string2_1bptr_p (accept)	      \
>        ? ((__builtin_constant_p (s) && __string2_1bptr_p (s))		      \
> -	 ? __builtin_strspn (s, accept)					      \
> +	 ? __BUILTIN_SINCE_GCC_3_2 (strspn) (s, accept)			      \
>  	 : ((__a0 = ((const char *) (accept))[0], __a0 == '\0')		      \
>  	    ? ((void) (s), (size_t) 0)					      \
>  	    : ((__a1 = ((const char *) (accept))[1], __a1 == '\0')	      \
> @@ -1021,24 +980,8 @@ __strcspn_c3 (const char *__s, int __reject1, int __reject2,
>  		  ? __strspn_c2 (s, __a0, __a1)				      \
>  		  : (((const char *) (accept))[3] == '\0'		      \
>  		     ? __strspn_c3 (s, __a0, __a1, __a2)		      \
> -		     : __builtin_strspn (s, accept))))))		      \
> -      : __builtin_strspn (s, accept)); })
> -#  else
> -#   define strspn(s, accept) \
> -  __extension__								      \
> -  ({ char __a0, __a1, __a2;						      \
> -     (__builtin_constant_p (accept) && __string2_1bptr_p (accept)	      \
> -      ? ((__a0 = ((const char *) (accept))[0], __a0 == '\0')		      \
> -	 ? ((void) (s), (size_t) 0)					      \
> -	 : ((__a1 = ((const char *) (accept))[1], __a1 == '\0')		      \
> -	    ? __strspn_c1 (s, __a0)					      \
> -	    : ((__a2 = ((const char *) (accept))[2], __a2 == '\0')	      \
> -	       ? __strspn_c2 (s, __a0, __a1)				      \
> -	       : (((const char *) (accept))[3] == '\0'			      \
> -		  ? __strspn_c3 (s, __a0, __a1, __a2)			      \
> -		  : strspn (s, accept)))))				      \
> -      : strspn (s, accept)); })
> -#  endif
> +		     :  __BUILTIN_SINCE_GCC_3_2 (strspn) (s, accept))))))     \
> +      :  __BUILTIN_SINCE_GCC_3_2 (strspn) (s, accept)); })
>  # endif
>  
>  __STRING_INLINE size_t __strspn_c1 (const char *__s, int __accept);
> @@ -1082,39 +1025,22 @@ __strspn_c3 (const char *__s, int __accept1, int __accept2, int __accept3)
>  /* Find the first occurrence in S of any character in ACCEPT.  */
>  #if !defined _HAVE_STRING_ARCH_strpbrk || defined _FORCE_INLINES
>  # ifndef _HAVE_STRING_ARCH_strpbrk
> -#  if __GNUC_PREREQ (3, 2)
> -#   define strpbrk(s, accept) \
> +#  define strpbrk(s, accept) \
>    __extension__								      \
>    ({ char __a0, __a1, __a2;						      \
>       (__builtin_constant_p (accept) && __string2_1bptr_p (accept)	      \
>        ? ((__builtin_constant_p (s) && __string2_1bptr_p (s))		      \
> -	 ? __builtin_strpbrk (s, accept)				      \
> +	 ? __BUILTIN_SINCE_GCC_3_2 (strpbrk) (s, accept)		      \
>  	 : ((__a0 = ((const char  *) (accept))[0], __a0 == '\0')	      \
>  	    ? ((void) (s), (char *) NULL)				      \
>  	    : ((__a1 = ((const char *) (accept))[1], __a1 == '\0')	      \
> -	       ? __builtin_strchr (s, __a0)				      \
> +	       ? __BUILTIN_SINCE_GCC_3_2 (strchr) (s, __a0)		      \
>  	       : ((__a2 = ((const char *) (accept))[2], __a2 == '\0')	      \
>  		  ? __strpbrk_c2 (s, __a0, __a1)			      \
>  		  : (((const char *) (accept))[3] == '\0'		      \
>  		     ? __strpbrk_c3 (s, __a0, __a1, __a2)		      \
> -		     : __builtin_strpbrk (s, accept))))))		      \
> -      : __builtin_strpbrk (s, accept)); })
> -#  else
> -#   define strpbrk(s, accept) \
> -  __extension__								      \
> -  ({ char __a0, __a1, __a2;						      \
> -     (__builtin_constant_p (accept) && __string2_1bptr_p (accept)	      \
> -      ? ((__a0 = ((const char  *) (accept))[0], __a0 == '\0')		      \
> -	 ? ((void) (s), (char *) NULL)					      \
> -	 : ((__a1 = ((const char *) (accept))[1], __a1 == '\0')		      \
> -	    ? strchr (s, __a0)						      \
> -	    : ((__a2 = ((const char *) (accept))[2], __a2 == '\0')	      \
> -	       ? __strpbrk_c2 (s, __a0, __a1)				      \
> -	       : (((const char *) (accept))[3] == '\0'			      \
> -		  ? __strpbrk_c3 (s, __a0, __a1, __a2)			      \
> -		  : strpbrk (s, accept)))))				      \
> -      : strpbrk (s, accept)); })
> -#  endif
> +		     : __BUILTIN_SINCE_GCC_3_2 (strpbrk) (s, accept))))))     \
> +      : __BUILTIN_SINCE_GCC_3_2 (strpbrk) (s, accept)); })
>  # endif
>  
>  __STRING_INLINE char *__strpbrk_c2 (const char *__s, int __accept1,
> -- 
> 1.7.4.4

-- 

temporary routing anomaly


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