Fix build with Clang for libpng versions 1.4.0 to 1.5.2
authorTor Arne Vestbø <tor.arne.vestbo@nokia.com>
Tue, 30 Aug 2011 14:25:54 +0000 (16:25 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 31 Aug 2011 14:25:34 +0000 (16:25 +0200)
Versions 1.4.0 to 1.5.2 of libpng declare png_longjmp_ptr to
have a noreturn attribute if PNG_PEDANTIC_WARNINGS_SUPPORTED
is enabled, but most declarations of longjmp in the wild do
not add this attribute. This causes problems when the png_jmpbuf
macro expands to calling png_set_longjmp_fn with a mismatched
longjmp, as compilers such as Clang will treat this as an error.

To work around this we override the png_jmpbuf macro to cast
longjmp to a png_longjmp_ptr.

See also http://llvm.org/bugs/show_bug.cgi?id=10338

Reviewed-by: Simon Hausmann <simon.hausmann@nokia.com>
Reviewed-by: Marius Storm-Olsen <marius.storm-olsen@nokia.com>
Change-Id: I197cfa12af76410310e409bc0fce7d4332ee66a6
Reviewed-on: http://codereview.qt.nokia.com/3929
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
src/gui/image/qpnghandler.cpp

index f7d07a5..1714442 100644 (file)
 #include <pngconf.h>
 #endif
 
+#if PNG_LIBPNG_VER >= 10400 && PNG_LIBPNG_VER <= 10502 \
+        && defined(PNG_PEDANTIC_WARNINGS_SUPPORTED)
+/*
+    Versions 1.4.0 to 1.5.2 of libpng declare png_longjmp_ptr to
+    have a noreturn attribute if PNG_PEDANTIC_WARNINGS_SUPPORTED
+    is enabled, but most declarations of longjmp in the wild do
+    not add this attribute. This causes problems when the png_jmpbuf
+    macro expands to calling png_set_longjmp_fn with a mismatched
+    longjmp, as compilers such as Clang will treat this as an error.
+
+    To work around this we override the png_jmpbuf macro to cast
+    longjmp to a png_longjmp_ptr.
+*/
+#   undef png_jmpbuf
+#   ifdef PNG_SETJMP_SUPPORTED
+#       define png_jmpbuf(png_ptr) \
+            (*png_set_longjmp_fn((png_ptr), (png_longjmp_ptr)longjmp, sizeof(jmp_buf)))
+#   else
+#       define png_jmpbuf(png_ptr) \
+            (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP)
+#   endif
+#endif
+
 #ifdef Q_OS_WINCE
 #define CALLBACK_CALL_TYPE        __cdecl
 #else