You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Ron Egyed <ro...@verizon.net> on 2007/07/03 15:20:49 UTC

mod_jk pointer error for i5/OS V5R4

FYI,

The following code in the sc_for_req_header function in module jk_ajp_common was getting a pointer error on version V5R4 of i5/OS (AS400).

while (*p)
      header[i++] = toupper((unsigned char)*p++);

IBM provided two solutions to this problem.
I tried the 2nd solution of wrapping the toupper in parenthesis and the code works correctly when compiled with LOCALE(*LOCALEUTF).

IBM's explanation. . . 
The reason for the different behavior is that the toupper() routine is implemented as a macro within the header file and the parameter is evaluated twice for the *LOCALEUTF version of the routine. 

The standard indicates that the routines within <ctype.h> may be implemented as macros - http://www.opengroup.org/onlinepubs/007908799/xsh/ctype.h.html 

Any routine which may be implemented as a macro is allowed to evaluate the parameter any number of times and thus using code like xxx(*p++) where xxx is a runtime routine is not portable.  The standard does not state this for every routine which may be a macro, but it is true in all macro cases.  Here is an example within the standard which explicitly states this fact for the getc() routine - http://www.opengroup.org/onlinepubs/007908799/xsh/getc.html .  Here is an excerpt from that web page: 

Because it may be implemented as a macro, getc() may treat incorrectly a stream argument with side effects. In particular, getc(*f++) will not necessarily work as expected. Therefore, use of this function should be preceded by "#undef getc" in such situations; fgetc() could also be used. 

This yields the following solutions for such code: 

1) use #undef toupper after <ctype.h> is included. 
2) a second solution is to wrap the toupper call in parenthesis - e.g. (toupper)((unsigned char)*p++) 

Either of these solutions can be used to 'disable' the macro version and allow both methods to work correctly. 


Re: mod_jk pointer error for i5/OS V5R4

Posted by Henri Gomez <he...@gmail.com>.
What about doing ?

----

unsigned char ch;

while (*p)
{
     ch =  (unsigned char)*p++;
     header[i++] = toupper(ch);
}


2007/7/3, Ron Egyed <ro...@verizon.net>:
> FYI,
>
> The following code in the sc_for_req_header function in module jk_ajp_common was getting a pointer error on version V5R4 of i5/OS (AS400).
>
> while (*p)
>       header[i++] = toupper((unsigned char)*p++);
>
> IBM provided two solutions to this problem.
> I tried the 2nd solution of wrapping the toupper in parenthesis and the code works correctly when compiled with LOCALE(*LOCALEUTF).
>
> IBM's explanation. . .
> The reason for the different behavior is that the toupper() routine is implemented as a macro within the header file and the parameter is evaluated twice for the *LOCALEUTF version of the routine.
>
> The standard indicates that the routines within <ctype.h> may be implemented as macros - http://www.opengroup.org/onlinepubs/007908799/xsh/ctype.h.html
>
> Any routine which may be implemented as a macro is allowed to evaluate the parameter any number of times and thus using code like xxx(*p++) where xxx is a runtime routine is not portable.  The standard does not state this for every routine which may be a macro, but it is true in all macro cases.  Here is an example within the standard which explicitly states this fact for the getc() routine - http://www.opengroup.org/onlinepubs/007908799/xsh/getc.html .  Here is an excerpt from that web page:
>
> Because it may be implemented as a macro, getc() may treat incorrectly a stream argument with side effects. In particular, getc(*f++) will not necessarily work as expected. Therefore, use of this function should be preceded by "#undef getc" in such situations; fgetc() could also be used.
>
> This yields the following solutions for such code:
>
> 1) use #undef toupper after <ctype.h> is included.
> 2) a second solution is to wrap the toupper call in parenthesis - e.g. (toupper)((unsigned char)*p++)
>
> Either of these solutions can be used to 'disable' the macro version and allow both methods to work correctly.
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org