This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH][STEP 2] ctype changes for removing locale structures
- From: Craig Howland <howland at LGSInnovations dot com>
- To: <newlib at sourceware dot org>
- Date: Fri, 9 Feb 2018 10:50:46 -0500
- Subject: Re: [PATCH][STEP 2] ctype changes for removing locale structures
- Authentication-results: sourceware.org; auth=none
- References: <003d01d3a1b7$925a12a0$b70e37e0$@jasoon.nl>
On 02/09/2018 10:06 AM, Jaap de Wolff wrote:
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
}
I would think that we should be able to do better than this, as this method is
taking a half step backwards for some of the functions, such as isalnum(). That
is, it potentially loses the efficiency of doing one table lookup plus one OR,
as it needs to do N table lookups and N+N-1 ORs (where N appears to be from
1-3). I say "potentially" because maybe the compiler would end up reducing it
to the 1+1 case, but maybe not, too (depending on compiler, compiler settings).
Before locale was added, isalnum(), for example, was
return(__ctype_ptr__[c+1] & (_U|_L));
I'm not sure what the right thing is now (still __ctype_ptr__?), but the same
basic thing ought to work, knowing the right thing to put in. But for that
matter, why not in the REENT_SMALL case simply redefine __CTYPE_PTR to point to
the right thing? Then all these other source file changes become unnecessary.
It seems reasonable to expect this to work, and it would be a cleaner solution
(since the is*.c files remain untouched, without #ifs). The stated purpose of
the patch is to stop ctype from using __locale_ctype_ptr, but ctype.h is where
it is defined to be __CTYPE_PTR--so just define it differently.
Craig