You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Jeff Trawick <tr...@bellsouth.net> on 2001/02/08 01:35:23 UTC

[PATCH] a somewhat different approach to the iconv() issue

There are some ideas here previously described by Mo DeJong.
Additionally:

. there is a way to avoid a warning for a certain platform:
  set apr_iconv_inbuf_const to "1" in hints.m4 for platforms
  where the parm is "const char **" but the autoconf logic
  doesn't detect

. we *know* that versions of glibc < 2.2 have "const char **"
  instead of "char **" so make that work without any hints.m4
  stuff (which would have to look at the glibc version)
 
This should get RedHat 7.0 compiling cleanly, but I don't have such a
system to test with.  

My RedHat 6.0 system ("const char **") now compiles xlate.c cleanly
for the first time in a while.  

A Tru64 system ("char **") still compiles xlate.c cleanly.

To get AIX compiling xlate.c cleanly (it hasn't done so in a while)
I'd expect to have to add apr_iconv_inbuf_const=1 to the AIX stanza in
hints.m4.  I haven't tested that though.  The same is true for
Solaris, which is "const char **" like AIX.

Comments?

Index: apr_common.m4
===================================================================
RCS file: /home/cvspublic/apr/apr_common.m4,v
retrieving revision 1.11
diff -u -r1.11 apr_common.m4
--- apr_common.m4	2001/01/11 13:55:58	1.11
+++ apr_common.m4	2001/02/08 00:01:57
@@ -285,3 +285,36 @@
   $1="$$1 $2"; export $1
 ])
 
+dnl
+dnl APR_CHECK_ICONV_INBUF
+dnl
+dnl  Decide whether or not the inbuf parameter to iconv() is const.
+dnl
+dnl  We try to compile something without const.  If it fails to 
+dnl  compile, we assume that the system's iconv() has const.  
+dnl  Unfortunately, we won't realize when there was a compile
+dnl  warning, so we allow a variable -- apr_iconv_inbuf_const -- to
+dnl  be set in hints.m4 to specify whether or not iconv() has const
+dnl  on this parameter.
+dnl
+AC_DEFUN(APR_CHECK_ICONV_INBUF,[
+AC_MSG_CHECKING(for type of inbuf parameter to iconv)
+if test "x$apr_iconv_inbuf_const" = "x"; then
+    AC_TRY_COMPILE([
+    #include <stddef.h>
+    #include <iconv.h>
+    ],[
+    #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR < 2
+    #error We know this version of glibc has const char **, so fail this compile
+    #endif
+    iconv(0,(char **)0,(size_t *)0,(char **)0,(size_t *)0);
+    ], apr_iconv_inbuf_const="0", apr_iconv_inbuf_const="1")
+fi
+if test "$apr_iconv_inbuf_const" = "1"; then
+    AC_DEFINE(APR_ICONV_INBUF_CONST, 1, [Define if the inbuf parm to iconv() is const char **])
+    msg="const char **"
+else
+    msg="char **"
+fi
+AC_MSG_RESULT([$msg])
+])
Index: configure.in
===================================================================
RCS file: /home/cvspublic/apr/configure.in,v
retrieving revision 1.220
diff -u -r1.220 configure.in
--- configure.in	2001/01/28 12:18:38	1.220
+++ configure.in	2001/02/08 00:02:07
@@ -245,6 +245,9 @@
 AC_CHECK_FUNC(_getch)
 AC_CHECK_FUNCS(gmtime_r localtime_r)
 AC_CHECK_FUNCS(iconv, [ iconv="1" ], [ iconv="0" ])
+if test "$iconv" = "1"; then
+  APR_CHECK_ICONV_INBUF
+fi
 AC_CHECK_FUNCS(mmap, [ mmap="1" ], [ mmap="0" ])
 if test "$native_mmap_emul" = "1"; then
     mmap="1"
Index: i18n/unix/xlate.c
===================================================================
RCS file: /home/cvspublic/apr/i18n/unix/xlate.c,v
retrieving revision 1.18
diff -u -r1.18 xlate.c
--- i18n/unix/xlate.c	2001/01/28 11:33:52	1.18
+++ i18n/unix/xlate.c	2001/02/08 00:02:33
@@ -80,6 +80,12 @@
 #include <iconv.h>
 #endif
 
+#ifdef APR_ICONV_INBUF_CONST
+#define ICONV_INBUF_TYPE const char **
+#else
+#define ICONV_INBUF_TYPE char **
+#endif
+
 #ifndef min
 #define min(x,y) ((x) <= (y) ? (x) : (y))
 #endif
@@ -194,7 +200,7 @@
     }
 
     inbytes_left = outbytes_left = sizeof(inbuf);
-    translated = iconv(convset->ich, &inbufptr, 
+    translated = iconv(convset->ich, (ICONV_INBUF_TYPE)&inbufptr, 
                        &inbytes_left, &outbufptr, &outbytes_left);
     if (translated != (size_t) -1 &&
         inbytes_left == 0 &&
@@ -288,7 +294,7 @@
         char *inbufptr = (char *)inbuf;
         char *outbufptr = outbuf;
         
-        translated = iconv(convset->ich, &inbufptr, 
+        translated = iconv(convset->ich, (ICONV_INBUF_TYPE)&inbufptr, 
                            inbytes_left, &outbufptr, outbytes_left);
         /* If everything went fine but we ran out of buffer, don't
          * report it as an error.  Caller needs to look at the two

-- 
Jeff Trawick | trawickj@bellsouth.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Re: [PATCH] a somewhat different approach to the iconv() issue

Posted by "Roy T. Fielding" <fi...@ebuilt.com>.
> >   1) The #ifdef APR_ in xlate.c must be a #if
> 
> Why is that?  We generally use #ifdef FOO if FOO is sometimes defined
> and sometimes not (e.g., APR_ICONV_INBUF_CONST).  We generally use #if
> FOO if FOO is always defined but sometimes to 1 and sometimes to 0
> (e.g., APR_HAS_XLATE).

Sorry, I just misread the code -- it is setting the internal variable
to 1 or 0, but only does the define if it is 1.  My goof.

> >   2) The test is looking at the versions and triggering #error
> > 
> > I don't know why the version test is giving a false-positive, nor
> > do I particularly care -- I don't think this can be fixed by assuming
> > the version numbers mean anything.  The fix I am working on is a
> > replacement for AC_TRY_COMPILE, but m4 isn't one of my strong
> > points.
> 
> I don't follow your comment about "assuming the version numbers mean
> anything".  Maybe if I saw the version numbers in glibc 2.2's
> <features.h> it would be easy to follow what you are saying.
> 
> If you can get -Werror working for gcc, obviously we don't need the
> glibc version check since we can expect to use gcc on a platform which
> uses glibc 99.99% of the time, but I can't help but be curious about
> why it generated the #error on RH 7.0 which has glibc 2.2 (and I guess
> __GLIBC_MINOR__ == 2).

Oh, that's probably the problem -- it is __GLIBC_MINOR in the macro.

Anyway, I've coded up the tester as APR_TRY_GCC_WARNING and will commit.
Please give it a try on your platform and fix where needed.  I think
it will fail-safe, but I'm still too sane to be able to follow all
of the possible m4 paths.

No worries about the license -- the m4 include files have effectively
the same license as the autoconf library, and since they don't get
added to the object file they cannot cause our code to be considered
"derived from GPL code".

....Roy

Re: [PATCH] a somewhat different approach to the iconv() issue

Posted by Jeff Trawick <tr...@bellsouth.net>.
"Roy T. Fielding" <fi...@ebuilt.com> writes:

> > > What was checked in doesn't work -- I now get warnings again on
> > > my platform, and mine is the one with the correct prototypes.
> > 
> > Hmmm...  I get no warnings on a system of each flavor (Tru64 and
> > RedHat 6) and got no warnings.  What warnings do you get?  Did the
> > configure output display the right message?
> > 
> > checking for type of inbuf parameter to iconv... char **
> 
> RedHat 7 with the latest glibc compiled from source.  There are
> two problems, one easy and one not yet figured out:
> 
>   1) The #ifdef APR_ in xlate.c must be a #if

Why is that?  We generally use #ifdef FOO if FOO is sometimes defined
and sometimes not (e.g., APR_ICONV_INBUF_CONST).  We generally use #if
FOO if FOO is always defined but sometimes to 1 and sometimes to 0
(e.g., APR_HAS_XLATE).

>   2) The test is looking at the versions and triggering #error
> 
> I don't know why the version test is giving a false-positive, nor
> do I particularly care -- I don't think this can be fixed by assuming
> the version numbers mean anything.  The fix I am working on is a
> replacement for AC_TRY_COMPILE, but m4 isn't one of my strong
> points.

I don't follow your comment about "assuming the version numbers mean
anything".  Maybe if I saw the version numbers in glibc 2.2's
<features.h> it would be easy to follow what you are saying.

If you can get -Werror working for gcc, obviously we don't need the
glibc version check since we can expect to use gcc on a platform which
uses glibc 99.99% of the time, but I can't help but be curious about
why it generated the #error on RH 7.0 which has glibc 2.2 (and I guess
__GLIBC_MINOR__ == 2).

(I wasn't too eager to write the compile macro either.  When I
considered a different flavor of AC_TRY_COMPILE it was obvious that I
would have to start by cutting and pasting AC_TRY_COMPILE.  A quick
look at the license reminded me that I am not a lawyer :) )

-- 
Jeff Trawick | trawickj@bellsouth.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Re: [PATCH] a somewhat different approach to the iconv() issue

Posted by Jeff Trawick <tr...@bellsouth.net>.
"Roy T. Fielding" <fi...@ebuilt.com> writes:

> What was checked in doesn't work -- I now get warnings again on
> my platform, and mine is the one with the correct prototypes.

Hmmm...  I get no warnings on a system of each flavor (Tru64 and
RedHat 6) and got no warnings.  What warnings do you get?  Did the
configure output display the right message?

checking for type of inbuf parameter to iconv... char **

-- 
Jeff Trawick | trawickj@bellsouth.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Re: [PATCH] a somewhat different approach to the iconv() issue

Posted by "Roy T. Fielding" <fi...@ebuilt.com>.
> well, in practice it isn't so excellent :(  the template for
> AC_TRY_COMPILE() doesn't even compile without warnings
> 
> int main() {  
> configure:4111: warning: function declaration isn't a prototype

So we write our own macro that does compile without warnings.

What was checked in doesn't work -- I now get warnings again on
my platform, and mine is the one with the correct prototypes.

I'll try to fix it.

....Roy

Re: [PATCH] a somewhat different approach to the iconv() issue

Posted by Jeff Trawick <tr...@bellsouth.net>.
Sascha Schumann <sa...@schumann.cx> writes:

> On 7 Feb 2001, Jeff Trawick wrote:
> 
> > Jeff Trawick <tr...@bellsouth.net> writes:
> >
> > > "Roy T. Fielding" <fi...@ebuilt.com> writes:
> > >
> > > > > . we *know* that versions of glibc < 2.2 have "const char **"
> > > > >   instead of "char **" so make that work without any hints.m4
> > > > >   stuff (which would have to look at the glibc version)
> > > >
> > > > Why not check for GCC and simply add -Werror to the compile?
> > >
> > > excellent...
> >
> > well, in practice it isn't so excellent :(  the template for
> > AC_TRY_COMPILE() doesn't even compile without warnings
> 
>     <Insert reiterating about pre-ANSI C systems>
> 
>     Does anyone around here remember the -Werror thread?

Well now I remember :)  (off to pluck some gray hairs)

-- 
Jeff Trawick | trawickj@bellsouth.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Re: [PATCH] a somewhat different approach to the iconv() issue

Posted by Sascha Schumann <sa...@schumann.cx>.
On 7 Feb 2001, Jeff Trawick wrote:

> Jeff Trawick <tr...@bellsouth.net> writes:
>
> > "Roy T. Fielding" <fi...@ebuilt.com> writes:
> >
> > > > . we *know* that versions of glibc < 2.2 have "const char **"
> > > >   instead of "char **" so make that work without any hints.m4
> > > >   stuff (which would have to look at the glibc version)
> > >
> > > Why not check for GCC and simply add -Werror to the compile?
> >
> > excellent...
>
> well, in practice it isn't so excellent :(  the template for
> AC_TRY_COMPILE() doesn't even compile without warnings

    <Insert reiterating about pre-ANSI C systems>

    Does anyone around here remember the -Werror thread?

    - Sascha


Re: [PATCH] a somewhat different approach to the iconv() issue

Posted by Jeff Trawick <tr...@bellsouth.net>.
Jeff Trawick <tr...@bellsouth.net> writes:

> "Roy T. Fielding" <fi...@ebuilt.com> writes:
> 
> > > . we *know* that versions of glibc < 2.2 have "const char **"
> > >   instead of "char **" so make that work without any hints.m4
> > >   stuff (which would have to look at the glibc version)
> > 
> > Why not check for GCC and simply add -Werror to the compile?
> 
> excellent...

well, in practice it isn't so excellent :(  the template for
AC_TRY_COMPILE() doesn't even compile without warnings

int main() {  
configure:4111: warning: function declaration isn't a prototype

-- 
Jeff Trawick | trawickj@bellsouth.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Re: [PATCH] a somewhat different approach to the iconv() issue

Posted by Jeff Trawick <tr...@bellsouth.net>.
"Roy T. Fielding" <fi...@ebuilt.com> writes:

> > . we *know* that versions of glibc < 2.2 have "const char **"
> >   instead of "char **" so make that work without any hints.m4
> >   stuff (which would have to look at the glibc version)
> 
> Why not check for GCC and simply add -Werror to the compile?

excellent...

...
> I think the final patch should remove the first cast of inbufptr
> that I added in my initial "fix".

You're talking about this I presume...

  @@ -285,7 +285,7 @@
       size_t translated;
   
       if (convset->ich != (iconv_t)-1) {
  -        char *inbufptr = inbuf;
  +        char *inbufptr = (char *)inbuf;
           char *outbufptr = outbuf;
           
           translated = iconv(convset->ich, &inbufptr, 
  
Thanks,

-- 
Jeff Trawick | trawickj@bellsouth.net | PGP public key at web site:
       http://www.geocities.com/SiliconValley/Park/9289/
             Born in Roswell... married an alien...

Re: [PATCH] a somewhat different approach to the iconv() issue

Posted by "Roy T. Fielding" <fi...@ebuilt.com>.
> . we *know* that versions of glibc < 2.2 have "const char **"
>   instead of "char **" so make that work without any hints.m4
>   stuff (which would have to look at the glibc version)

Why not check for GCC and simply add -Werror to the compile?

> This should get RedHat 7.0 compiling cleanly, but I don't have such a
> system to test with.  

I do, but my glibc has already been updated.  One warning: the
glibc update RPM distributed by RedHat is completely broken -- among
other things, it installs a timezone for EST and breaks ld.conf.

I think the final patch should remove the first cast of inbufptr
that I added in my initial "fix".

....Roy

Re: [PATCH] a somewhat different approach to the iconv() issue

Posted by Greg Stein <gs...@lyra.org>.
Awesome.

+1

On Wed, Feb 07, 2001 at 07:35:23PM -0500, Jeff Trawick wrote:
> There are some ideas here previously described by Mo DeJong.
> Additionally:
> 
> . there is a way to avoid a warning for a certain platform:
>   set apr_iconv_inbuf_const to "1" in hints.m4 for platforms
>   where the parm is "const char **" but the autoconf logic
>   doesn't detect
> 
> . we *know* that versions of glibc < 2.2 have "const char **"
>   instead of "char **" so make that work without any hints.m4
>   stuff (which would have to look at the glibc version)
>  
> This should get RedHat 7.0 compiling cleanly, but I don't have such a
> system to test with.  
> 
> My RedHat 6.0 system ("const char **") now compiles xlate.c cleanly
> for the first time in a while.  
> 
> A Tru64 system ("char **") still compiles xlate.c cleanly.
> 
> To get AIX compiling xlate.c cleanly (it hasn't done so in a while)
> I'd expect to have to add apr_iconv_inbuf_const=1 to the AIX stanza in
> hints.m4.  I haven't tested that though.  The same is true for
> Solaris, which is "const char **" like AIX.
> 
> Comments?
>...

-- 
Greg Stein, http://www.lyra.org/