Skip to contentSkip to conversation

Silence iconv warnings on Leopard

PATCH In review Wincent Colaiuta 5 participants 12 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Silence iconv warnings on Leopard

Apple ships a newer version of iconv with Leopard (Mac OS X 10.5/Darwin 9). Ensure that OLD_ICONV is not set on any version of Darwin in the 9.x series; this should be good for at least a couple of years, when Darwin 10 comes out and we can invert the sense of the test to specifically check for Darwin 7 or 8.

A more sophisticated and robust check is possible for those who use autoconf, but not everybody does that.

---
 Makefile |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
Makefile +3 -1
index 999391e..4dda340 100644
@@ -406,7 +406,9 @@ endif
 ifeq ($(uname_S),Darwin)
 	NEEDS_SSL_WITH_CRYPTO = YesPlease
 	NEEDS_LIBICONV = YesPlease
-	OLD_ICONV = UnfortunatelyYes
+	ifneq ($(shell expr "$(uname_R)" : '9\.'),2)
+		OLD_ICONV = UnfortunatelyYes
+	endif
 	NO_STRLCPY = YesPlease
 	NO_MEMMEM = YesPlease
 endif
Signature · 1 line
1.5.3.7.1067.gaa51
#1 lore raw
Quoted 5 lines · Wincent Colaiuta

Apple ships a newer version of iconv with Leopard (Mac OS X 10.5/Darwin 9). Ensure that OLD_ICONV is not set on any version of Darwin in the 9.x series; this should be good for at least a couple of years, when Darwin 10 comes out and we can invert the sense of the test to specifically check for Darwin 7 or 8.

This approach seems fine to me, there was some concern about matching the OS type / version in the past, but I haven't really seen a better answer.

Quoted 2 lines

A more sophisticated and robust check is possible for those who use autoconf, but not everybody does that.

I did make a patch for configure.ac that does this. If it's interesting, I'll send it along.

Blake

Signature · 1 line
Blake Ramsdell | http://www.blakeramsdell.com
#2 lore raw
Quoted 8 lines · Blake Ramsdell
Quoted 5 lines · Wincent Colaiuta

Apple ships a newer version of iconv with Leopard (Mac OS X 10.5/Darwin 9). Ensure that OLD_ICONV is not set on any version of Darwin in the 9.x series; this should be good for at least a couple of years, when Darwin 10 comes out and we can invert the sense of the test to specifically check for Darwin 7 or 8.

Quoted 5 lines
Quoted 2 lines

A more sophisticated and robust check is possible for those who use autoconf, but not everybody does that.

I did make a patch for configure.ac that does this. If it's interesting, I'll send it along.

I would be interested, as I tried to make a patch to configure.ac which does that. The problem is that it should be check that tests for compile time _warnings_; my solution was to use '-Werror' flag to make warning into error, and AC_COMPILE_IFELSE, but this might be gcc only solution.

Message-ID: <[email protected]>
http://permalink.gmane.org/gmane.comp.version-control.git/67209

So please send it.

Thanks in advance

Signature · 2 lines
Jakub Narebski
Poland
#3 lore raw
Quoted 4 lines · Jakub Narebski

I would be interested, as I tried to make a patch to configure.ac which does that. The problem is that it should be check that tests for compile time _warnings_; my solution was to use '-Werror' flag to make warning into error, and AC_COMPILE_IFELSE, but this might be gcc only solution.

That's precisely what I did. If this isn't suitable, then bummer -- impossible ;).

Blake

Signature · 1 line
Blake Ramsdell | http://www.blakeramsdell.com
#4 lore raw
In reply to Jakub Narebski
Quoted 9 lines · Jakub Narebski

The problem is that it should be check that tests for compile time _warnings_; my solution was to use '-Werror' flag to make warning into error, and AC_COMPILE_IFELSE, but this might be gcc only solution.

Message-ID: <[email protected]>
http://permalink.gmane.org/gmane.comp.version-control.git/67209

So please send it.

Umm. Why not just make the test be whether the following compiles cleanly?

	#include <iconv.h>
	
	extern size_t iconv(iconv_t cd,
	  char **inbuf, size_t *inbytesleft,
	  char **outbuf, size_t *outbytesleft);

because if the compiler has seen a "const char **inbuf", then it should error out with a "conflicting types for ‘iconv’" style message..

Just do

$CC -c test-iconv.c

or something.

Totally untested. I don't do autoconf.

Linus

#5 lore raw
Quoted 10 lines · Linus Torvalds

Umm. Why not just make the test be whether the following compiles cleanly?

#include <iconv.h>

extern size_t iconv(iconv_t cd,
char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);

because if the compiler has seen a "const char **inbuf", then it should error out with a "conflicting types for 'iconv'" style message..

Yeah, this is what I did:

configure.ac +23 -0
index 5f8a15b..675d3e0 100644
@@ -182,6 +182,29 @@ AC_SUBST(NEEDS_LIBICONV)
 AC_SUBST(NO_ICONV)
 test -n "$NEEDS_LIBICONV" && LIBS="$LIBS -liconv"
 #
+# Define OLD_ICONV if the iconv function prototype uses const** (Darwin and
+# some FreeBSD installations).
+AC_DEFUN([OLDICONVTEST_SRC], [
+#include <iconv.h>
+
+int main(void)
+{
+    char* value = "test";
+
+    (void) iconv (NULL, &value, NULL, NULL, NULL);
+}
+])
+AC_MSG_CHECKING([for old iconv])
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Werror"
+AC_COMPILE_IFELSE(OLDICONVTEST_SRC,
+	[AC_MSG_RESULT([no])
+	OLD_ICONV=],
+	[AC_MSG_RESULT([yes])
+	OLD_ICONV=UnfortunatelyYes])
+CFLAGS="$old_CFLAGS"
+AC_SUBST(OLD_ICONV)
+#
 # Define NO_DEFLATE_BOUND if deflateBound is missing from zlib.
 AC_DEFUN([ZLIBTEST_SRC], [
 #include <zlib.h>

The problem is that AC_COMPILE_IFELSE doesn't barf on warnings, so I had to put in the CFLAGS hack to do -Werror (this is what Jakub did also, I think).

So if this isn't rude to use -Werror (which is probably gcc-specific in one or more ways), then fine. If it is rude to use -Werror, then yeah, there needs to be some check for the warning, which I confess in my five minutes of learning autoconf I don't understand well enough to say if it's possible.

Blake

Signature · 1 line
Blake Ramsdell | http://www.blakeramsdell.com
#6 lore raw
Quoted 5 lines · Blake Ramsdell
Quoted 4 lines · Linus Torvalds

Umm. Why not just make the test be whether the following compiles cleanly?

        #include <iconv.h>
Quoted 8 lines
Quoted 6 lines

extern size_t iconv(iconv_t cd,
char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);

because if the compiler has seen a "const char **inbuf", then it should error out with a "conflicting types for 'iconv'" style message..

Yeah, this is what I did:

My apologies. Your suggestion is completely different, and should work without -Werror. Let me try that.

Blake

Signature · 1 line
Blake Ramsdell | http://www.blakeramsdell.com
#7 lore raw

[PATCH/RFC (take 3)] autoconf: Add test for OLD_ICONV (squelching compiler warning)

In reply to Linus Torvalds

Update configure.ac (and config.mak.in) to keep up with git development by adding [compile] test whether your library has an old iconv(), where the second (input buffer pointer) parameter is declared with type (const char **) (OLD_ICONV).

---
CC-ed to all parties (in this and previous thread).

I should probably used AC_LANG_PROGRAM like for NO_C99_FORMAT instead of generating whole programlet^W test program by hand (I hope that for example I haven't missed some header file which needs to be included); I have followed example for NO_ICONV / NEEDS_LIBICONV and NO_DEFLATE_BOUND test. I'm also not sure if I have put this test in the correct autoconf section, but that is probably matter of taste.

Quoted 22 lines · Linus Torvalds
Quoted 9 lines · Jakub Narebski

The problem is that it should be check that tests for compile time _warnings_; my solution was to use '-Werror' flag to make warning into error, and AC_COMPILE_IFELSE, but this might be gcc only solution.

Message-ID: <[email protected]>
http://permalink.gmane.org/gmane.comp.version-control.git/67209

So please send it.

Umm. Why not just make the test be whether the following compiles cleanly?

	#include <iconv.h>
	
	extern size_t iconv(iconv_t cd,
	  char **inbuf, size_t *inbytesleft,
	  char **outbuf, size_t *outbytesleft);

because if the compiler has seen a "const char **inbuf", then it should error out with a "conflicting types for ?iconv?" style message..

[...]

Quoted 1 line

Totally untested. I don't do autoconf.

Thanks for a suggestion. Implemented in the patch below. It should work correctly, but could those who have old iconv(), or used to have old iconv() please check if works correctly for them?

By the way, perhaps the previous idea would work using AC_LANG_WERROR instead of passing adding [temporarily] GCC -Werror' option to CFLAGS', or use parts of its implementation.

- Macro: AC_LANG_WERROR
Normally Autoconf ignores warnings generated by the compiler, linker, and preprocessor. If this macro is used, warnings will be treated as fatal errors instead for the current language. This macro is useful when the results of configuration will be used where warnings are unacceptable; for instance, if parts of a program are built with the GCC -Werror' option. If the whole program will be built using -Werror' it is often simpler to put -Werror' in the compiler flags (CFLAGS' etc.).

Quoted 10 lines · Blake Ramsdell
Quoted 9 lines · Blake Ramsdell
Quoted 8 lines · Linus Torvalds

Umm. Why not just make the test be whether the following compiles cleanly?

#include <iconv.h>

extern size_t iconv(iconv_t cd,
char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

because if the compiler has seen a "const char **inbuf", then it should error out with a "conflicting types for 'iconv'" style message..

Yeah, this is what I did:

My apologies. Your suggestion is completely different, and should work without -Werror. Let me try that.

Is something like the patch below what you wanted to try?

 config.mak.in |    1 +
 configure.ac  |   22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)
config.mak.in +1 -0
index 11d256e..7d5df9b 100644
@@ -41,4 +41,5 @@ NO_STRTOUMAX=@NO_STRTOUMAX@
 NO_SETENV=@NO_SETENV@
 NO_MKDTEMP=@NO_MKDTEMP@
 NO_ICONV=@NO_ICONV@
+OLD_ICONV=@OLD_ICONV@
 NO_DEFLATE_BOUND=@NO_DEFLATE_BOUND@
configure.ac +22 -0
index 5f8a15b..86be19a 100644
@@ -212,6 +212,28 @@ test -n "$NEEDS_SOCKET" && LIBS="$LIBS -lsocket"
 
 
 ## Checks for header files.
+AC_MSG_NOTICE([CHECKS for header files])
+#
+# Define OLD_ICONV if your library has an old iconv(), where the second
+# (input buffer pointer) parameter is declared with type (const char **).
+AC_DEFUN([OLDICONVTEST_SRC], [[
+#include <iconv.h>
+
+extern size_t iconv(iconv_t cd,
+                    char **inbuf, size_t *inbytesleft,
+                    char **outbuf, size_t *outbytesleft);
+
+int main(void)
+{
+	return 0;
+}
+]])
+AC_MSG_CHECKING([for old iconv()])
+AC_COMPILE_IFELSE(OLDICONVTEST_SRC,
+	[AC_MSG_RESULT([no])],
+	[AC_MSG_RESULT([yes])
+	OLD_ICONV=UnfortunatelyYes])
+AC_SUBST(OLD_ICONV)
 
 
 ## Checks for typedefs, structures, and compiler characteristics.
Signature · 1 line
1.5.3.7
#8 lore raw

Re: [PATCH/RFC (take 3)] autoconf: Add test for OLD_ICONV (squelching compiler warning)

Quoted 7 lines · Jakub Narebski

Update configure.ac (and config.mak.in) to keep up with git development by adding [compile] test whether your library has an old iconv(), where the second (input buffer pointer) parameter is declared with type (const char **) (OLD_ICONV).

Tested and working here on Mac OS X 10.5.1/Darwin 9.1.0 (where we no longer have an old iconv):

configure: CHECKS for header files
checking for old iconv()... no

Cheers,
Wincent

#9 lore raw

Re: [PATCH/RFC (take 3)] autoconf: Add test for OLD_ICONV (squelching compiler warning)

In reply to Jakub Narebski
Quoted 14 lines · Jakub Narebski
Quoted 13 lines · Blake Ramsdell
Quoted 12 lines · Blake Ramsdell
Quoted 10 lines · Linus Torvalds

Umm. Why not just make the test be whether the following compiles cleanly?

#include <iconv.h>

extern size_t iconv(iconv_t cd,
char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);

because if the compiler has seen a "const char **inbuf", then it should error out with a "conflicting types for 'iconv'" style message..

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Yeah, this is what I did:

My apologies. Your suggestion is completely different, and should work without -Werror. Let me try that.

Is something like the patch below what you wanted to try?

This looks sensible. Will apply.

#10 lore raw

Re: [PATCH/RFC (take 3)] autoconf: Add test for OLD_ICONV (squelching compiler warning)

Quoted 5 lines · Junio C Hamano
Quoted 1 line · Jakub Narebski

Is something like the patch below what you wanted to try?

This looks sensible. Will apply.

This works for those using autoconf. Junio, did you get a chance to look at the patch I posted for people who don't use autoconf?

Cheers,
Wincent

#11 lore raw

Re: [PATCH/RFC (take 3)] autoconf: Add test for OLD_ICONV (squelching compiler warning)

In reply to Jakub Narebski
Quoted 1 line · Jakub Narebski

Is something like the patch below what you wanted to try?

Yes. Not sure if main() is required, so it might be shorter if that's removed, but not really relevant as long as it works.

And CHECKS for header files might be considered chatty.

Blake

Signature · 1 line
Blake Ramsdell | http://www.blakeramsdell.com