You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Roy T. Fielding" <fi...@kiwi.ics.uci.edu> on 1998/07/07 19:55:27 UTC

Re: PR 2553 and 2282

Shouldn't (unsigned) be (unsigned char), as in

#define ap_isalnum(c) (isalnum(((unsigned char)(c)))
#define ap_isalpha(c) (isalpha(((unsigned char)(c)))
#define ap_iscntrl(c) (iscntrl(((unsigned char)(c)))
#define ap_isdigit(c) (isdigit(((unsigned char)(c)))
#define ap_isgraph(c) (isgraph(((unsigned char)(c)))
#define ap_islower(c) (islower(((unsigned char)(c)))
#define ap_isprint(c) (isprint(((unsigned char)(c)))
#define ap_ispunct(c) (ispunct(((unsigned char)(c)))
#define ap_isspace(c) (isspace(((unsigned char)(c)))
#define ap_isupper(c) (isupper(((unsigned char)(c)))

or is the potential lack of (unsigned char) the problem?
Color me confused.

....Roy [resisting the temptation to comment on casts, almost]

Re: PR 2553 and 2282

Posted by Dean Gaudet <dg...@arctic.org>.

On Tue, 7 Jul 1998, Dirk-Willem van Gulik wrote:

> On Tue, 7 Jul 1998, Roy T. Fielding wrote:
> 
> > Shouldn't (unsigned) be (unsigned char), as in
> > 
> > #define ap_isalnum(c) (isalnum(((unsigned char)(c)))
> > 
> > or is the potential lack of (unsigned char) the problem?
> 
> Hmm, certainly in the area the lack of proper testing and debugging. 
> 
> From personal experience with porting things such as Tcl/Tk to machines on
> which signed vs. unsigned matter; I fear that this opens up a whole can of
> worms. Whereas a normal char (or signed int), though arguably wrong,
> gives expetable behavour. Given the boxes most of us have access to I
> would have trouble seeing how to debug and test that. 

I don't understand what you're saying... are you saying you disagree with
the: 

#define ap_isalpha(c) (isalpha(((unsigned)(c))) 

approach? 

On machines that don't accept unsigned char in those macros we're already
broken -- this approach just trades one form of brokenness for another... 
and given that it's all wrapped in our own macros we could provide the
(isascii(c) && isalpha(c)) approach where needed.  But that approach is
wrong on anything modern (it means we can't support 8-bit even on things
that support 8-bit). 

Dean



Re: PR 2553 and 2282

Posted by Dirk-Willem van Gulik <di...@jrc.it>.

On Tue, 7 Jul 1998, Roy T. Fielding wrote:

> Shouldn't (unsigned) be (unsigned char), as in
> 
> #define ap_isalnum(c) (isalnum(((unsigned char)(c)))
> 
> or is the potential lack of (unsigned char) the problem?

Hmm, certainly in the area the lack of proper testing and debugging. 

>From personal experience with porting things such as Tcl/Tk to machines on
which signed vs. unsigned matter; I fear that this opens up a whole can of
worms. Whereas a normal char (or signed int), though arguably wrong,
gives expetable behavour. Given the boxes most of us have access to I
would have trouble seeing how to debug and test that. 

dw.


Re: PR 2553 and 2282

Posted by Dean Gaudet <dg...@arctic.org>.

On Tue, 7 Jul 1998, Roy T. Fielding wrote:

> Shouldn't (unsigned) be (unsigned char), as in

Both work, but (unsigned char)c can introduce an extra (c & 0xff) when c
is actually an int (because the cast to char has to loose the high bits,
and the compiler can't prove that they're already zero in general)...
whereas (unsigned)(c) does nothing for ints (we assume they're already in
0..0xff), and zero extends chars (which is what we want -- rather than
sign extend). 

Dean, performance freak


> 
> #define ap_isalnum(c) (isalnum(((unsigned char)(c)))
> #define ap_isalpha(c) (isalpha(((unsigned char)(c)))
> #define ap_iscntrl(c) (iscntrl(((unsigned char)(c)))
> #define ap_isdigit(c) (isdigit(((unsigned char)(c)))
> #define ap_isgraph(c) (isgraph(((unsigned char)(c)))
> #define ap_islower(c) (islower(((unsigned char)(c)))
> #define ap_isprint(c) (isprint(((unsigned char)(c)))
> #define ap_ispunct(c) (ispunct(((unsigned char)(c)))
> #define ap_isspace(c) (isspace(((unsigned char)(c)))
> #define ap_isupper(c) (isupper(((unsigned char)(c)))
> 
> or is the potential lack of (unsigned char) the problem?
> Color me confused.
> 
> ....Roy [resisting the temptation to comment on casts, almost]
>