From: Richard Earnshaw <Richard.Earnshaw@foss.arm.com>
To: Mike Frysinger <vapier@gentoo.org>, newlib@sourceware.org
Subject: Re: [PATCH 2/2] ctype: use less short names in public header
Date: Tue, 23 Nov 2021 15:09:20 +0000 [thread overview]
Message-ID: <43a8b21c-ac4e-fd33-d7ad-ae7738329d16@foss.arm.com> (raw)
In-Reply-To: <20211109012459.30826-1-vapier@gentoo.org>
This is wrong and breaks all old versions of C++.
The GNU sim code should not be using reserved names (those starting _)
in normal source code. Such names are reserved to the implementation.
R.
On 09/11/2021 01:24, Mike Frysinger wrote:
> We're seeing a build failure in GNU sim code which is using _P locally
> but the ctype.h define clashes with it. Rename these to use the same
> symbols that glibc does. They're a bit more verbose, but seems likely
> that we'll have fewer conflicts if glibc isn't seeing them.
>
> However, these shortnames are still used internally by ctype modules
> to produce pretty concise source code, so use _COMPILING_NEWLIB to
> keep them around when compiling newlib itself where we have better
> control over short name conflicts.
> ---
> newlib/libc/include/ctype.h | 77 ++++++++++++++++++++++---------------
> 1 file changed, 45 insertions(+), 32 deletions(-)
>
> diff --git a/newlib/libc/include/ctype.h b/newlib/libc/include/ctype.h
> index 932a567e25db..f2a4368da5d2 100644
> --- a/newlib/libc/include/ctype.h
> +++ b/newlib/libc/include/ctype.h
> @@ -57,14 +57,27 @@ extern int isascii_l (int __c, locale_t __l);
> extern int toascii_l (int __c, locale_t __l);
> #endif
>
> -#define _U 01
> -#define _L 02
> -#define _N 04
> -#define _S 010
> -#define _P 020
> -#define _C 040
> -#define _X 0100
> -#define _B 0200
> +enum
> +{
> + _ISupper = 01,
> + _ISlower = 02,
> + _ISdigit = 04,
> + _ISspace = 010,
> + _ISpunct = 020,
> + _IScntrl = 040,
> + _ISxdigit = 0100,
> + _ISblank = 0200,
> +};
> +#ifdef _COMPILING_NEWLIB
> +# define _U _ISupper
> +# define _L _ISlower
> +# define _N _ISdigit
> +# define _S _ISspace
> +# define _P _ISpunct
> +# define _C _IScntrl
> +# define _X _ISxdigit
> +# define _B _ISblank
> +#endif
>
> /* For C++ backward-compatibility only. */
> extern __IMPORT const char _ctype_[];
> @@ -89,22 +102,22 @@ const char *__locale_ctype_ptr (void);
> an out-of-bounds reference on a 64-bit machine. */
> #define __ctype_lookup(__c) ((__CTYPE_PTR+sizeof(""[__c]))[(int)(__c)])
>
> -#define isalpha(__c) (__ctype_lookup(__c)&(_U|_L))
> -#define isupper(__c) ((__ctype_lookup(__c)&(_U|_L))==_U)
> -#define islower(__c) ((__ctype_lookup(__c)&(_U|_L))==_L)
> -#define isdigit(__c) (__ctype_lookup(__c)&_N)
> -#define isxdigit(__c) (__ctype_lookup(__c)&(_X|_N))
> -#define isspace(__c) (__ctype_lookup(__c)&_S)
> -#define ispunct(__c) (__ctype_lookup(__c)&_P)
> -#define isalnum(__c) (__ctype_lookup(__c)&(_U|_L|_N))
> -#define isprint(__c) (__ctype_lookup(__c)&(_P|_U|_L|_N|_B))
> -#define isgraph(__c) (__ctype_lookup(__c)&(_P|_U|_L|_N))
> -#define iscntrl(__c) (__ctype_lookup(__c)&_C)
> +#define isalpha(__c) (__ctype_lookup(__c) & (_ISupper|_ISlower))
> +#define isupper(__c) ((__ctype_lookup(__c) & (_ISupper|_ISlower)) == _ISupper)
> +#define islower(__c) ((__ctype_lookup(__c) & (_ISupper|_ISlower)) == _ISlower)
> +#define isdigit(__c) (__ctype_lookup(__c) & _ISdigit)
> +#define isxdigit(__c) (__ctype_lookup(__c) & (_ISxdigit|_ISdigit))
> +#define isspace(__c) (__ctype_lookup(__c) & _ISspace)
> +#define ispunct(__c) (__ctype_lookup(__c) & _ISpunct)
> +#define isalnum(__c) (__ctype_lookup(__c) & (_ISupper|_ISlower|_ISdigit))
> +#define isprint(__c) (__ctype_lookup(__c) & (_ISpunct|_ISupper|_ISlower|_ISdigit|_ISblank))
> +#define isgraph(__c) (__ctype_lookup(__c) & (_ISpunct|_ISupper|_ISlower|_ISdigit))
> +#define iscntrl(__c) (__ctype_lookup(__c) & _IScntrl)
>
> #if defined(__GNUC__) && __ISO_C_VISIBLE >= 1999
> #define isblank(__c) \
> __extension__ ({ __typeof__ (__c) __x = (__c); \
> - (__ctype_lookup(__x)&_B) || (int) (__x) == '\t';})
> + (__ctype_lookup(__x)&_ISblank) || (int) (__x) == '\t';})
> #endif
>
> #if __POSIX_VISIBLE >= 200809
> @@ -120,22 +133,22 @@ __locale_ctype_ptr_l(locale_t _l)
> #endif
> #define __ctype_lookup_l(__c,__l) ((__locale_ctype_ptr_l(__l)+sizeof(""[__c]))[(int)(__c)])
>
> -#define isalpha_l(__c,__l) (__ctype_lookup_l(__c,__l)&(_U|_L))
> -#define isupper_l(__c,__l) ((__ctype_lookup_l(__c,__l)&(_U|_L))==_U)
> -#define islower_l(__c,__l) ((__ctype_lookup_l(__c,__l)&(_U|_L))==_L)
> -#define isdigit_l(__c,__l) (__ctype_lookup_l(__c,__l)&_N)
> -#define isxdigit_l(__c,__l) (__ctype_lookup_l(__c,__l)&(_X|_N))
> -#define isspace_l(__c,__l) (__ctype_lookup_l(__c,__l)&_S)
> -#define ispunct_l(__c,__l) (__ctype_lookup_l(__c,__l)&_P)
> -#define isalnum_l(__c,__l) (__ctype_lookup_l(__c,__l)&(_U|_L|_N))
> -#define isprint_l(__c,__l) (__ctype_lookup_l(__c,__l)&(_P|_U|_L|_N|_B))
> -#define isgraph_l(__c,__l) (__ctype_lookup_l(__c,__l)&(_P|_U|_L|_N))
> -#define iscntrl_l(__c,__l) (__ctype_lookup_l(__c,__l)&_C)
> +#define isalpha_l(__c,__l) (__ctype_lookup_l(__c,__l) & (_ISupper|_ISlower))
> +#define isupper_l(__c,__l) ((__ctype_lookup_l(__c,__l) & (_ISupper|_ISlower)) == _ISupper)
> +#define islower_l(__c,__l) ((__ctype_lookup_l(__c,__l) & (_ISupper|_ISlower)) == _ISlower)
> +#define isdigit_l(__c,__l) (__ctype_lookup_l(__c,__l) & _ISdigit)
> +#define isxdigit_l(__c,__l) (__ctype_lookup_l(__c,__l) & (_ISxdigit|_ISdigit))
> +#define isspace_l(__c,__l) (__ctype_lookup_l(__c,__l) & _ISspace)
> +#define ispunct_l(__c,__l) (__ctype_lookup_l(__c,__l) & _ISpunct)
> +#define isalnum_l(__c,__l) (__ctype_lookup_l(__c,__l) & (_ISupper|_ISlower|_ISdigit))
> +#define isprint_l(__c,__l) (__ctype_lookup_l(__c,__l) & (_ISpunct|_ISupper|_ISlower|_ISdigit|_ISblank))
> +#define isgraph_l(__c,__l) (__ctype_lookup_l(__c,__l) & (_ISpunct|_ISupper|_ISlower|_ISdigit))
> +#define iscntrl_l(__c,__l) (__ctype_lookup_l(__c,__l) & _IScntrl)
>
> #if defined(__GNUC__)
> #define isblank_l(__c, __l) \
> __extension__ ({ __typeof__ (__c) __x = (__c); \
> - (__ctype_lookup_l(__x,__l)&_B) || (int) (__x) == '\t';})
> + (__ctype_lookup_l(__x,__l)&_ISblank) || (int) (__x) == '\t';})
> #endif
>
> #endif /* __POSIX_VISIBLE >= 200809 */
>
next prev parent reply other threads:[~2021-11-23 15:09 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-07 0:21 what's up with _COMPILING_NEWLIB Mike Frysinger
2021-11-08 10:05 ` Corinna Vinschen
2021-11-08 11:46 ` Mike Frysinger
2021-11-08 15:05 ` Corinna Vinschen
2021-11-08 18:14 ` Mike Frysinger
2021-11-09 1:24 ` [PATCH 1/2] define _COMPILING_NEWLIB for all targets when compiling Mike Frysinger
2021-11-09 1:24 ` [PATCH 2/2] ctype: use less short names in public header Mike Frysinger
2021-11-09 11:38 ` Corinna Vinschen
2021-11-10 0:18 ` Mike Frysinger
2021-11-10 10:56 ` Corinna Vinschen
2021-11-30 12:18 ` Jonathan Wakely
2021-11-11 1:37 ` [PATCH v2] " Mike Frysinger
2021-11-11 10:35 ` Corinna Vinschen
2021-11-11 22:28 ` Mike Frysinger
2021-11-12 10:27 ` Corinna Vinschen
2021-11-20 20:08 ` Brian Inglis
2021-11-23 15:09 ` Richard Earnshaw [this message]
2021-11-24 4:15 ` [PATCH 2/2] " Mike Frysinger
2021-11-24 10:58 ` Richard Earnshaw
2021-11-24 11:01 ` Richard Earnshaw
2021-11-30 12:01 ` Jonathan Wakely
2021-11-30 15:14 ` Corinna Vinschen
2021-11-30 17:12 ` Jonathan Wakely
2021-11-30 17:15 ` Jonathan Wakely
2021-11-30 17:52 ` Richard Earnshaw
2021-12-02 10:27 ` Corinna Vinschen
2021-12-03 9:56 ` Corinna Vinschen
2021-12-05 9:42 ` Mike Frysinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=43a8b21c-ac4e-fd33-d7ad-ae7738329d16@foss.arm.com \
--to=richard.earnshaw@foss.arm.com \
--cc=newlib@sourceware.org \
--cc=vapier@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).