[PATCH v2] ctype: use less short names in public header
Mike Frysinger
vapier@gentoo.org
Thu Nov 11 01:37:00 GMT 2021
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 move the short names to the
internal ctype_.h where short name conflicts shouldn't show up.
---
newlib/libc/ctype/ctype_.h | 10 +++++
newlib/libc/ctype/isalnum.c | 2 +-
newlib/libc/ctype/isalnum_l.c | 2 +-
newlib/libc/ctype/isalpha.c | 2 +-
newlib/libc/ctype/isalpha_l.c | 2 +-
newlib/libc/ctype/isblank.c | 2 +-
newlib/libc/ctype/isblank_l.c | 2 +-
newlib/libc/ctype/iscntrl.c | 2 +-
newlib/libc/ctype/iscntrl_l.c | 2 +-
newlib/libc/ctype/isdigit.c | 2 +-
newlib/libc/ctype/isdigit_l.c | 2 +-
newlib/libc/ctype/islower.c | 2 +-
newlib/libc/ctype/islower_l.c | 2 +-
newlib/libc/ctype/isprint.c | 4 +-
newlib/libc/ctype/isprint_l.c | 4 +-
newlib/libc/ctype/ispunct.c | 2 +-
newlib/libc/ctype/ispunct_l.c | 2 +-
newlib/libc/ctype/isspace.c | 2 +-
newlib/libc/ctype/isspace_l.c | 2 +-
newlib/libc/ctype/isupper.c | 2 +-
newlib/libc/ctype/isupper_l.c | 2 +-
newlib/libc/ctype/isxdigit.c | 2 +-
newlib/libc/ctype/isxdigit_l.c | 2 +-
newlib/libc/include/ctype.h | 67 ++++++++++++++++++----------------
24 files changed, 69 insertions(+), 56 deletions(-)
diff --git a/newlib/libc/ctype/ctype_.h b/newlib/libc/ctype/ctype_.h
index a73870b3e4ad..42ad2c87024d 100644
--- a/newlib/libc/ctype/ctype_.h
+++ b/newlib/libc/ctype/ctype_.h
@@ -1,5 +1,15 @@
#include <ctype.h>
+/* Define some short names to keep internal files shorter. */
+#define _U _ISupper
+#define _L _ISlower
+#define _N _ISdigit
+#define _S _ISspace
+#define _P _ISpunct
+#define _C _IScntrl
+#define _X _ISxdigit
+#define _B _ISblank
+
#if (defined(__GNUC__) && !defined(__CHAR_UNSIGNED__) && !defined(COMPACT_CTYPE)) || defined (__CYGWIN__)
#define ALLOW_NEGATIVE_CTYPE_INDEX
#endif
diff --git a/newlib/libc/ctype/isalnum.c b/newlib/libc/ctype/isalnum.c
index d926f97b7c3f..3ddf0d2e1f18 100644
--- a/newlib/libc/ctype/isalnum.c
+++ b/newlib/libc/ctype/isalnum.c
@@ -46,5 +46,5 @@ No OS subroutines are required.
int
isalnum (int c)
{
- return(__CTYPE_PTR[c+1] & (_U|_L|_N));
+ return(__CTYPE_PTR[c+1] & (_ISupper|_ISlower|_ISdigit));
}
diff --git a/newlib/libc/ctype/isalnum_l.c b/newlib/libc/ctype/isalnum_l.c
index dcb7e3652313..e3587f1b2995 100644
--- a/newlib/libc/ctype/isalnum_l.c
+++ b/newlib/libc/ctype/isalnum_l.c
@@ -6,5 +6,5 @@
int
isalnum_l (int c, struct __locale_t *locale)
{
- return __locale_ctype_ptr_l (locale)[c+1] & (_U|_L|_N);
+ return __locale_ctype_ptr_l (locale)[c+1] & (_ISupper|_ISlower|_ISdigit);
}
diff --git a/newlib/libc/ctype/isalpha.c b/newlib/libc/ctype/isalpha.c
index 8b8e78a29635..c8de62cea3c2 100644
--- a/newlib/libc/ctype/isalpha.c
+++ b/newlib/libc/ctype/isalpha.c
@@ -45,5 +45,5 @@ No supporting OS subroutines are required.
int
isalpha (int c)
{
- return(__CTYPE_PTR[c+1] & (_U|_L));
+ return(__CTYPE_PTR[c+1] & (_ISupper|_ISlower));
}
diff --git a/newlib/libc/ctype/isalpha_l.c b/newlib/libc/ctype/isalpha_l.c
index dcae3ccb4408..6ff1e3b686ac 100644
--- a/newlib/libc/ctype/isalpha_l.c
+++ b/newlib/libc/ctype/isalpha_l.c
@@ -6,5 +6,5 @@
int
isalpha_l (int c, struct __locale_t *locale)
{
- return __locale_ctype_ptr_l (locale)[c+1] & (_U|_L);
+ return __locale_ctype_ptr_l (locale)[c+1] & (_ISupper|_ISlower);
}
diff --git a/newlib/libc/ctype/isblank.c b/newlib/libc/ctype/isblank.c
index 0ebc2192c5c9..2fa29f33fb6f 100644
--- a/newlib/libc/ctype/isblank.c
+++ b/newlib/libc/ctype/isblank.c
@@ -44,5 +44,5 @@ No supporting OS subroutines are required.
int
isblank (int c)
{
- return ((__CTYPE_PTR[c+1] & _B) || (c == '\t'));
+ return ((__CTYPE_PTR[c+1] & _ISblank) || (c == '\t'));
}
diff --git a/newlib/libc/ctype/isblank_l.c b/newlib/libc/ctype/isblank_l.c
index 8bbb84e1f6a8..6aff2f7fc354 100644
--- a/newlib/libc/ctype/isblank_l.c
+++ b/newlib/libc/ctype/isblank_l.c
@@ -6,5 +6,5 @@
int
isblank_l (int c, struct __locale_t *locale)
{
- return (__locale_ctype_ptr_l (locale)[c+1] & _B) || (c == '\t');
+ return (__locale_ctype_ptr_l (locale)[c+1] & _ISblank) || (c == '\t');
}
diff --git a/newlib/libc/ctype/iscntrl.c b/newlib/libc/ctype/iscntrl.c
index ebbdd7371d73..bd99ebafb511 100644
--- a/newlib/libc/ctype/iscntrl.c
+++ b/newlib/libc/ctype/iscntrl.c
@@ -48,5 +48,5 @@ No supporting OS subroutines are required.
int
iscntrl (int c)
{
- return(__CTYPE_PTR[c+1] & _C);
+ return(__CTYPE_PTR[c+1] & _IScntrl);
}
diff --git a/newlib/libc/ctype/iscntrl_l.c b/newlib/libc/ctype/iscntrl_l.c
index 0ae17c7f7414..85f4d6900022 100644
--- a/newlib/libc/ctype/iscntrl_l.c
+++ b/newlib/libc/ctype/iscntrl_l.c
@@ -6,5 +6,5 @@
int
iscntrl_l (int c, struct __locale_t *locale)
{
- return __locale_ctype_ptr_l (locale)[c+1] & _C;
+ return __locale_ctype_ptr_l (locale)[c+1] & _IScntrl;
}
diff --git a/newlib/libc/ctype/isdigit.c b/newlib/libc/ctype/isdigit.c
index a5c511964f21..911781df3c5a 100644
--- a/newlib/libc/ctype/isdigit.c
+++ b/newlib/libc/ctype/isdigit.c
@@ -47,5 +47,5 @@ No supporting OS subroutines are required.
int
isdigit (int c)
{
- return(__CTYPE_PTR[c+1] & _N);
+ return(__CTYPE_PTR[c+1] & _ISdigit);
}
diff --git a/newlib/libc/ctype/isdigit_l.c b/newlib/libc/ctype/isdigit_l.c
index 1fb79e0001a0..6e24c100ce2e 100644
--- a/newlib/libc/ctype/isdigit_l.c
+++ b/newlib/libc/ctype/isdigit_l.c
@@ -6,5 +6,5 @@
int
isdigit_l (int c, struct __locale_t *locale)
{
- return __locale_ctype_ptr_l (locale)[c+1] & _N;
+ return __locale_ctype_ptr_l (locale)[c+1] & _ISdigit;
}
diff --git a/newlib/libc/ctype/islower.c b/newlib/libc/ctype/islower.c
index 2b344048957a..c45c6c8ad6f5 100644
--- a/newlib/libc/ctype/islower.c
+++ b/newlib/libc/ctype/islower.c
@@ -45,5 +45,5 @@ No supporting OS subroutines are required.
int
islower (int c)
{
- return ((__CTYPE_PTR[c+1] & (_U|_L)) == _L);
+ return ((__CTYPE_PTR[c+1] & (_ISupper|_ISlower)) == _ISlower);
}
diff --git a/newlib/libc/ctype/islower_l.c b/newlib/libc/ctype/islower_l.c
index d1f3a82d8239..1c66ab48b931 100644
--- a/newlib/libc/ctype/islower_l.c
+++ b/newlib/libc/ctype/islower_l.c
@@ -6,5 +6,5 @@
int
islower_l (int c, struct __locale_t *locale)
{
- return (__locale_ctype_ptr_l (locale)[c+1] & (_U|_L)) == _L;
+ return (__locale_ctype_ptr_l (locale)[c+1] & (_ISupper|_ISlower)) == _ISlower;
}
diff --git a/newlib/libc/ctype/isprint.c b/newlib/libc/ctype/isprint.c
index e34fbe28a2ac..7206047fb36b 100644
--- a/newlib/libc/ctype/isprint.c
+++ b/newlib/libc/ctype/isprint.c
@@ -59,7 +59,7 @@ No supporting OS subroutines are required.
int
isgraph (int c)
{
- return(__CTYPE_PTR[c+1] & (_P|_U|_L|_N));
+ return(__CTYPE_PTR[c+1] & (_ISpunct|_ISupper|_ISlower|_ISdigit));
}
@@ -67,5 +67,5 @@ isgraph (int c)
int
isprint (int c)
{
- return(__CTYPE_PTR[c+1] & (_P|_U|_L|_N|_B));
+ return(__CTYPE_PTR[c+1] & (_ISpunct|_ISupper|_ISlower|_ISdigit|_ISblank));
}
diff --git a/newlib/libc/ctype/isprint_l.c b/newlib/libc/ctype/isprint_l.c
index 535504f1406f..3efaa2f90e01 100644
--- a/newlib/libc/ctype/isprint_l.c
+++ b/newlib/libc/ctype/isprint_l.c
@@ -6,7 +6,7 @@
int
isgraph_l (int c, struct __locale_t *locale)
{
- return __locale_ctype_ptr_l (locale)[c+1] & (_P|_U|_L|_N);
+ return __locale_ctype_ptr_l (locale)[c+1] & (_ISpunct|_ISupper|_ISlower|_ISdigit);
}
#undef isprint_l
@@ -14,5 +14,5 @@ isgraph_l (int c, struct __locale_t *locale)
int
isprint_l (int c, struct __locale_t *locale)
{
- return __locale_ctype_ptr_l (locale)[c+1] & (_P|_U|_L|_N|_B);
+ return __locale_ctype_ptr_l (locale)[c+1] & (_ISpunct|_ISupper|_ISlower|_ISdigit|_ISblank);
}
diff --git a/newlib/libc/ctype/ispunct.c b/newlib/libc/ctype/ispunct.c
index 9c5a3fcca762..35f7cc2d421b 100644
--- a/newlib/libc/ctype/ispunct.c
+++ b/newlib/libc/ctype/ispunct.c
@@ -47,5 +47,5 @@ No supporting OS subroutines are required.
int
ispunct (int c)
{
- return(__CTYPE_PTR[c+1] & _P);
+ return(__CTYPE_PTR[c+1] & _ISpunct);
}
diff --git a/newlib/libc/ctype/ispunct_l.c b/newlib/libc/ctype/ispunct_l.c
index eeba1f5ae110..30c2b48d65ca 100644
--- a/newlib/libc/ctype/ispunct_l.c
+++ b/newlib/libc/ctype/ispunct_l.c
@@ -6,6 +6,6 @@
int
ispunct_l (int c, struct __locale_t *locale)
{
- return __locale_ctype_ptr_l (locale)[c+1] & _P;
+ return __locale_ctype_ptr_l (locale)[c+1] & _ISpunct;
}
diff --git a/newlib/libc/ctype/isspace.c b/newlib/libc/ctype/isspace.c
index 0def2c0ce47f..8834d1901c6e 100644
--- a/newlib/libc/ctype/isspace.c
+++ b/newlib/libc/ctype/isspace.c
@@ -46,5 +46,5 @@ No supporting OS subroutines are required.
int
isspace (int c)
{
- return(__CTYPE_PTR[c+1] & _S);
+ return(__CTYPE_PTR[c+1] & _ISspace);
}
diff --git a/newlib/libc/ctype/isspace_l.c b/newlib/libc/ctype/isspace_l.c
index bf4a36c3e90a..06227c87a052 100644
--- a/newlib/libc/ctype/isspace_l.c
+++ b/newlib/libc/ctype/isspace_l.c
@@ -6,6 +6,6 @@
int
isspace_l (int c, struct __locale_t *locale)
{
- return __locale_ctype_ptr_l (locale)[c+1] & _S;
+ return __locale_ctype_ptr_l (locale)[c+1] & _ISspace;
}
diff --git a/newlib/libc/ctype/isupper.c b/newlib/libc/ctype/isupper.c
index aeed383ecdea..7d916d9f3c49 100644
--- a/newlib/libc/ctype/isupper.c
+++ b/newlib/libc/ctype/isupper.c
@@ -43,5 +43,5 @@ No supporting OS subroutines are required.
int
isupper (int c)
{
- return ((__CTYPE_PTR[c+1] & (_U|_L)) == _U);
+ return ((__CTYPE_PTR[c+1] & (_ISupper|_ISlower)) == _ISupper);
}
diff --git a/newlib/libc/ctype/isupper_l.c b/newlib/libc/ctype/isupper_l.c
index eb473a7a1d54..1fdcf107277e 100644
--- a/newlib/libc/ctype/isupper_l.c
+++ b/newlib/libc/ctype/isupper_l.c
@@ -6,6 +6,6 @@
int
isupper_l (int c, struct __locale_t *locale)
{
- return (__locale_ctype_ptr_l (locale)[c+1] & (_U|_L)) == _U;
+ return (__locale_ctype_ptr_l (locale)[c+1] & (_ISupper|_ISlower)) == _ISupper;
}
diff --git a/newlib/libc/ctype/isxdigit.c b/newlib/libc/ctype/isxdigit.c
index 2bfe18dbfab7..fb2a59ea801a 100644
--- a/newlib/libc/ctype/isxdigit.c
+++ b/newlib/libc/ctype/isxdigit.c
@@ -46,5 +46,5 @@ No supporting OS subroutines are required.
int
isxdigit (int c)
{
- return(__CTYPE_PTR[c+1] & ((_X)|(_N)));
+ return(__CTYPE_PTR[c+1] & ((_ISxdigit)|(_ISdigit)));
}
diff --git a/newlib/libc/ctype/isxdigit_l.c b/newlib/libc/ctype/isxdigit_l.c
index 726db31903fb..bbae410c6cd8 100644
--- a/newlib/libc/ctype/isxdigit_l.c
+++ b/newlib/libc/ctype/isxdigit_l.c
@@ -6,6 +6,6 @@
int
isxdigit_l (int c, struct __locale_t *locale)
{
- return __locale_ctype_ptr_l (locale)[c+1] & ((_X)|(_N));
+ return __locale_ctype_ptr_l (locale)[c+1] & ((_ISxdigit)|(_ISdigit));
}
diff --git a/newlib/libc/include/ctype.h b/newlib/libc/include/ctype.h
index 932a567e25db..366b35dc9f9d 100644
--- a/newlib/libc/include/ctype.h
+++ b/newlib/libc/include/ctype.h
@@ -57,14 +57,17 @@ 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,
+};
/* For C++ backward-compatibility only. */
extern __IMPORT const char _ctype_[];
@@ -89,22 +92,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 +123,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 */
--
2.33.0
More information about the Newlib
mailing list