[PATCH][STEP 2] ctype changes for removing locale structures

Jaap de Wolff info@jasoon.nl
Fri Feb 9 15:06:00 GMT 2018


modify ctype not to use __locale_ctype_ptr (== __CTYPE_PTR) or
__locale_ctype_ptr_l
To do this al inline functions are removed, and the source implementations
test hard coded values of the given characters


================================== PATCH =================
diff --git a/newlib/libc/ctype/isalnum.c b/newlib/libc/ctype/isalnum.c
index d926f97b7..6d3864114 100644
--- a/newlib/libc/ctype/isalnum.c
+++ b/newlib/libc/ctype/isalnum.c
@@ -46,5 +46,9 @@ No OS subroutines are required.
 int
 isalnum (int c)
 {
+#ifdef _REENT_SMALL
+	return (isdigit(c) | islower(c) | isupper(c));
+#else
 	return(__CTYPE_PTR[c+1] & (_U|_L|_N));
+#endif
 }
diff --git a/newlib/libc/ctype/isalnum_l.c b/newlib/libc/ctype/isalnum_l.c
index dcb7e3652..d924898a6 100644
--- a/newlib/libc/ctype/isalnum_l.c
+++ b/newlib/libc/ctype/isalnum_l.c
@@ -6,5 +6,9 @@
 int
 isalnum_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return isalnum(c);
+#else
   return __locale_ctype_ptr_l (locale)[c+1] & (_U|_L|_N);
+#endif
 }
diff --git a/newlib/libc/ctype/isalpha.c b/newlib/libc/ctype/isalpha.c
index 8b8e78a29..4b98d1d90 100644
--- a/newlib/libc/ctype/isalpha.c
+++ b/newlib/libc/ctype/isalpha.c
@@ -45,5 +45,9 @@ No supporting OS subroutines are required.
 int
 isalpha (int c)
 {
+#ifdef 	_REENT_SMALL
+	return (islower(c) | isupper(c));
+#else
 	return(__CTYPE_PTR[c+1] & (_U|_L));
+#endif
 }
diff --git a/newlib/libc/ctype/isalpha_l.c b/newlib/libc/ctype/isalpha_l.c
index dcae3ccb4..187d956b7 100644
--- a/newlib/libc/ctype/isalpha_l.c
+++ b/newlib/libc/ctype/isalpha_l.c
@@ -6,5 +6,9 @@
 int
 isalpha_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return isalpha(c);
+#else
   return __locale_ctype_ptr_l (locale)[c+1] & (_U|_L);
+#endif
 }
diff --git a/newlib/libc/ctype/isblank.c b/newlib/libc/ctype/isblank.c
index 0ebc2192c..4d8cceb6a 100644
--- a/newlib/libc/ctype/isblank.c
+++ b/newlib/libc/ctype/isblank.c
@@ -44,5 +44,9 @@ No supporting OS subroutines are required.
 int
 isblank (int c)
 {
+#ifdef _REENT_SMALL
+	return ((c == ' ') || (c == '\t'))?1:0;
+#else
 	return ((__CTYPE_PTR[c+1] & _B) || (c == '\t'));
+#endif
 }
diff --git a/newlib/libc/ctype/isblank_l.c b/newlib/libc/ctype/isblank_l.c
index 8bbb84e1f..b9b43fceb 100644
--- a/newlib/libc/ctype/isblank_l.c
+++ b/newlib/libc/ctype/isblank_l.c
@@ -6,5 +6,9 @@
 int
 isblank_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return isblank(c);
+#else
   return (__locale_ctype_ptr_l (locale)[c+1] & _B) || (c == '\t');
+#endif
 }
diff --git a/newlib/libc/ctype/iscntrl.c b/newlib/libc/ctype/iscntrl.c
index ebbdd7371..64abf7f07 100644
--- a/newlib/libc/ctype/iscntrl.c
+++ b/newlib/libc/ctype/iscntrl.c
@@ -48,5 +48,9 @@ No supporting OS subroutines are required.
 int
 iscntrl (int c)
 {
+#ifdef _REENT_SMALL
+	return ((c < 0x20) || (c == 0x7F))?1:0;
+#else
 	return(__CTYPE_PTR[c+1] & _C);
+#endif
 }
diff --git a/newlib/libc/ctype/iscntrl_l.c b/newlib/libc/ctype/iscntrl_l.c
index 0ae17c7f7..0186bfa4b 100644
--- a/newlib/libc/ctype/iscntrl_l.c
+++ b/newlib/libc/ctype/iscntrl_l.c
@@ -6,5 +6,9 @@
 int
 iscntrl_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return iscntrl(c);
+#else
   return __locale_ctype_ptr_l (locale)[c+1] & _C;
+#endif
 }
diff --git a/newlib/libc/ctype/isdigit.c b/newlib/libc/ctype/isdigit.c
index a5c511964..e5d033326 100644
--- a/newlib/libc/ctype/isdigit.c
+++ b/newlib/libc/ctype/isdigit.c
@@ -47,5 +47,9 @@ No supporting OS subroutines are required.
 int
 isdigit (int c)
 {
+#ifdef _REENT_SMALL
+	return ((c > 0x2F) && (c < 0x3A))?1:0;
+#else
 	return(__CTYPE_PTR[c+1] & _N);
+#endif
 }
diff --git a/newlib/libc/ctype/isdigit_l.c b/newlib/libc/ctype/isdigit_l.c
index 1fb79e000..6ca875d36 100644
--- a/newlib/libc/ctype/isdigit_l.c
+++ b/newlib/libc/ctype/isdigit_l.c
@@ -6,5 +6,9 @@
 int
 isdigit_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return isdigit(c);
+#else
   return __locale_ctype_ptr_l (locale)[c+1] & _N;
+#endif
 }
diff --git a/newlib/libc/ctype/islower.c b/newlib/libc/ctype/islower.c
index 2b3440489..d67cf8f3c 100644
--- a/newlib/libc/ctype/islower.c
+++ b/newlib/libc/ctype/islower.c
@@ -45,5 +45,9 @@ No supporting OS subroutines are required.
 int
 islower (int c)
 {
+#ifdef _REENT_SMALL
+	return ((c > 0x60) && (c < 0x7B))?1:0;
+#else
 	return ((__CTYPE_PTR[c+1] & (_U|_L)) == _L);
+#endif
 }
diff --git a/newlib/libc/ctype/islower_l.c b/newlib/libc/ctype/islower_l.c
index d1f3a82d8..2469ba453 100644
--- a/newlib/libc/ctype/islower_l.c
+++ b/newlib/libc/ctype/islower_l.c
@@ -6,5 +6,9 @@
 int
 islower_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return islower(c);
+#else
   return (__locale_ctype_ptr_l (locale)[c+1] & (_U|_L)) == _L;
+#endif
 }
diff --git a/newlib/libc/ctype/isprint.c b/newlib/libc/ctype/isprint.c
index e34fbe28a..7b5c4bb1f 100644
--- a/newlib/libc/ctype/isprint.c
+++ b/newlib/libc/ctype/isprint.c
@@ -59,7 +59,11 @@ No supporting OS subroutines are required.
 int
 isgraph (int c)
 {
+#ifdef _REENT_SMALL
+	return ((c > 0x20) && (c < 0x7F))?1:0;
+#else
 	return(__CTYPE_PTR[c+1] & (_P|_U|_L|_N));
+#endif
 }
 
 
@@ -67,5 +71,9 @@ isgraph (int c)
 int
 isprint (int c)
 {
+#ifdef _REENT_SMALL
+	return ((c > 0x1F) && (c < 0x7F))?1:0;
+#else
 	return(__CTYPE_PTR[c+1] & (_P|_U|_L|_N|_B));
+#endif
 }
diff --git a/newlib/libc/ctype/isprint_l.c b/newlib/libc/ctype/isprint_l.c
index 535504f14..297c83498 100644
--- a/newlib/libc/ctype/isprint_l.c
+++ b/newlib/libc/ctype/isprint_l.c
@@ -6,7 +6,11 @@
 int
 isgraph_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return isgraph(c);
+#else
   return __locale_ctype_ptr_l (locale)[c+1] & (_P|_U|_L|_N);
+#endif
 }
 
 #undef isprint_l
@@ -14,5 +18,9 @@ isgraph_l (int c, struct __locale_t *locale)
 int
 isprint_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return isprint(c);
+#else
   return __locale_ctype_ptr_l (locale)[c+1] & (_P|_U|_L|_N|_B);
+#endif
 }
diff --git a/newlib/libc/ctype/ispunct.c b/newlib/libc/ctype/ispunct.c
index 9c5a3fcca..d28172e3a 100644
--- a/newlib/libc/ctype/ispunct.c
+++ b/newlib/libc/ctype/ispunct.c
@@ -47,5 +47,11 @@ No supporting OS subroutines are required.
 int
 ispunct (int c)
 {
+#ifdef _REENT_SMALL
+	return ( ((c > 0x20) && (c < 0x30)) ||
+	         ((c > 0x5A) && (c < 0x60)) ||
+	         ((c > 0x7A) && (c < 0x7F)) )?1:0;
+#else
 	return(__CTYPE_PTR[c+1] & _P);
+#endif
 }
diff --git a/newlib/libc/ctype/ispunct_l.c b/newlib/libc/ctype/ispunct_l.c
index eeba1f5ae..aef30f057 100644
--- a/newlib/libc/ctype/ispunct_l.c
+++ b/newlib/libc/ctype/ispunct_l.c
@@ -6,6 +6,10 @@
 int
 ispunct_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return ispunct(c);
+#else
   return __locale_ctype_ptr_l (locale)[c+1] & _P;
+#endif
 }
 
diff --git a/newlib/libc/ctype/isspace.c b/newlib/libc/ctype/isspace.c
index 0def2c0ce..ad36a2ac9 100644
--- a/newlib/libc/ctype/isspace.c
+++ b/newlib/libc/ctype/isspace.c
@@ -46,5 +46,9 @@ No supporting OS subroutines are required.
 int
 isspace (int c)
 {
+#ifdef _REENT_SMALL
+	return (((c > 0x7) && (c < 0x0E)) || (c == ' '))?1:0;
+#else
 	return(__CTYPE_PTR[c+1] & _S);
+#endif
 }
diff --git a/newlib/libc/ctype/isspace_l.c b/newlib/libc/ctype/isspace_l.c
index bf4a36c3e..d83cd1658 100644
--- a/newlib/libc/ctype/isspace_l.c
+++ b/newlib/libc/ctype/isspace_l.c
@@ -6,6 +6,10 @@
 int
 isspace_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return isspace(c);
+#else
   return __locale_ctype_ptr_l (locale)[c+1] & _S;
+#endif
 }
 
diff --git a/newlib/libc/ctype/isupper.c b/newlib/libc/ctype/isupper.c
index aeed383ec..e7f121d0e 100644
--- a/newlib/libc/ctype/isupper.c
+++ b/newlib/libc/ctype/isupper.c
@@ -43,5 +43,9 @@ No supporting OS subroutines are required.
 int
 isupper (int c)
 {
+#ifdef _REENT_SMALL
+	return ((c > 0x40) && (c < 0x4B));
+#else
 	return ((__CTYPE_PTR[c+1] & (_U|_L)) == _U);
+#endif
 }
diff --git a/newlib/libc/ctype/isupper_l.c b/newlib/libc/ctype/isupper_l.c
index eb473a7a1..1d7068431 100644
--- a/newlib/libc/ctype/isupper_l.c
+++ b/newlib/libc/ctype/isupper_l.c
@@ -6,6 +6,10 @@
 int
 isupper_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return isupper(c);
+#else
   return (__locale_ctype_ptr_l (locale)[c+1] & (_U|_L)) == _U;
+#endif
 }
 
diff --git a/newlib/libc/ctype/isxdigit.c b/newlib/libc/ctype/isxdigit.c
index 2bfe18dbf..ff5248122 100644
--- a/newlib/libc/ctype/isxdigit.c
+++ b/newlib/libc/ctype/isxdigit.c
@@ -46,5 +46,11 @@ No supporting OS subroutines are required.
 int
 isxdigit (int c)
 {
+#ifdef _REENT_SMALL
+	return ( ((c > 0x2F) && (c < 0x3A)) ||
+                 ((c > 0x40) && (c < 0x48)) ||
+	         ((c > 0x60) && (c < 0x68)) )?1:0;
+#else
 	return(__CTYPE_PTR[c+1] & ((_X)|(_N)));
+#endif
 }
diff --git a/newlib/libc/ctype/isxdigit_l.c b/newlib/libc/ctype/isxdigit_l.c
index 726db3190..17d278070 100644
--- a/newlib/libc/ctype/isxdigit_l.c
+++ b/newlib/libc/ctype/isxdigit_l.c
@@ -6,6 +6,10 @@
 int
 isxdigit_l (int c, struct __locale_t *locale)
 {
+#ifdef _REENT_SMALL
+  return isxdigit(c);
+#else
   return __locale_ctype_ptr_l (locale)[c+1] & ((_X)|(_N));
+#endif
 }
 
diff --git a/newlib/libc/include/ctype.h b/newlib/libc/include/ctype.h
index f74b3499b..c21ad94da 100644
--- a/newlib/libc/include/ctype.h
+++ b/newlib/libc/include/ctype.h
@@ -66,10 +66,13 @@ extern int toascii_l (int __c, locale_t __l);
 #define _X	0100
 #define	_B	0200
 
+#ifndef _REENT_SMALL
 const char *__locale_ctype_ptr (void);
 # define __CTYPE_PTR	(__locale_ctype_ptr ())
 
-#ifndef __cplusplus
+#endif /* !_REENT_SMALL */
+
+#if !defined (__cplusplus) && !defined(_REENT_SMALL)
 /* These macros are intentionally written in a manner that will trigger
    a gcc -Wall warning if the user mistakenly passes a 'char' instead
    of an int containing an 'unsigned char'.  Note that the sizeof will



More information about the Newlib mailing list