tolower() implementation question + patch

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

tolower() implementation question + patch

Steffen Wendzel-2
hi,

I just ask me why tolower() is implemented with an EOF array element
in lib/libc/gen/tolower_.c. How about this patch?

--steffen

Index: tolower_.c
===================================================================
RCS file: /cvs/src/lib/libc/gen/tolower_.c,v
retrieving revision 1.9
diff -u -p -r1.9 tolower_.c
--- tolower_.c 8 Aug 2005 08:05:34 -0000 1.9
+++ tolower_.c 11 Sep 2006 20:01:13 -0000
@@ -9,8 +9,7 @@
 #include <stdio.h>
 #include "ctype_private.h"
 
-const short _C_tolower_[1 + CTYPE_NUM_CHARS] = {
- EOF,
+const short _C_tolower_[CTYPE_NUM_CHARS] = {
  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -53,5 +52,7 @@ tolower(int c)
 {
  if ((unsigned int)c > 255)
  return(c);
- return((_tolower_tab_ + 1)[c]);
+ return(_C_tolower_[c]);
 }
+
+

Reply | Threaded
Open this post in threaded view
|

Re: tolower() implementation question + patch

Miod Vallat
> I just ask me why tolower() is implemented with an EOF array element
> in lib/libc/gen/tolower_.c. How about this patch?
>
> --steffen
>
> Index: tolower_.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/gen/tolower_.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 tolower_.c
> --- tolower_.c 8 Aug 2005 08:05:34 -0000 1.9
> +++ tolower_.c 11 Sep 2006 20:01:13 -0000
> @@ -9,8 +9,7 @@
>  #include <stdio.h>
>  #include "ctype_private.h"
>  
> -const short _C_tolower_[1 + CTYPE_NUM_CHARS] = {
> - EOF,
> +const short _C_tolower_[CTYPE_NUM_CHARS] = {

This breaks tolower(EOF) being EOF.

> @@ -53,5 +52,7 @@ tolower(int c)
>  {
>   if ((unsigned int)c > 255)
>   return(c);
> - return((_tolower_tab_ + 1)[c]);
> + return(_C_tolower_[c]);

This breaks locale.

Miod

Reply | Threaded
Open this post in threaded view
|

Re: tolower() implementation question + patch

Otto Moerbeek
On Mon, 11 Sep 2006, Miod Vallat wrote:

> > I just ask me why tolower() is implemented with an EOF array element
> > in lib/libc/gen/tolower_.c. How about this patch?
> >
> > --steffen
> >
> > Index: tolower_.c
> > ===================================================================
> > RCS file: /cvs/src/lib/libc/gen/tolower_.c,v
> > retrieving revision 1.9
> > diff -u -p -r1.9 tolower_.c
> > --- tolower_.c 8 Aug 2005 08:05:34 -0000 1.9
> > +++ tolower_.c 11 Sep 2006 20:01:13 -0000
> > @@ -9,8 +9,7 @@
> >  #include <stdio.h>
> >  #include "ctype_private.h"
> >  
> > -const short _C_tolower_[1 + CTYPE_NUM_CHARS] = {
> > - EOF,
> > +const short _C_tolower_[CTYPE_NUM_CHARS] = {
>
> This breaks tolower(EOF) being EOF.

Actually that case is handled by the if (... > 255) statement. But the
diff is totally wrong, not only for breaking locale handling, but also
for creating inconsistency between the inline and out-of-line versions
of tolower().

        -Otto

>
> > @@ -53,5 +52,7 @@ tolower(int c)
> >  {
> >   if ((unsigned int)c > 255)
> >   return(c);
> > - return((_tolower_tab_ + 1)[c]);
> > + return(_C_tolower_[c]);
>
> This breaks locale.
>
> Miod

Reply | Threaded
Open this post in threaded view
|

Re: tolower() implementation question + patch

Joerg Sonnenberger
On Mon, Sep 11, 2006 at 10:45:00PM +0200, Otto Moerbeek wrote:
> Actually that case is handled by the if (... > 255) statement. But the
> diff is totally wrong, not only for breaking locale handling, but also
> for creating inconsistency between the inline and out-of-line versions
> of tolower().

The argument for tolower is either EOF (-1) or an unsigned char, so this
is necessary as it is.

Joerg