Skip to content

Commit 8c762ad

Browse files
authored
Fix #14423: Add support for Cairo, GLib, GTK and ATK version check macros (danmar#8147)
Without those known to cppcheck, it now bails out with something like this: ``` test/cfg/gtk.c:16:2: error: failed to evaluate #if condition, undefined function-like macro invocation: GLIB_CHECK_VERSION( ... ) [syntaxError] #if GLIB_CHECK_VERSION(2, 3, 4) ^ ``` So define them in a best-effort fashion: * Cairo is actually using the real value (not that it's likely to matter) * GLib, GTK and ATK make them result to `1` as there's no better alternative than an arbitrary boolean value, and those checks are usually guarding newer or optional code paths, so it conceptually makes more sense to have a truthy value.
1 parent 6f53cda commit 8c762ad

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

cfg/cairo.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<define name="CAIRO_MIME_TYPE_PNG" value="&quot;image/png&quot;"/>
2222
<define name="CAIRO_MIME_TYPE_URI" value="&quot;text/x-uri&quot;"/>
2323
<define name="CAIRO_MIME_TYPE_UNIQUE_ID" value="&quot;application/x-cairo.uuid&quot;"/>
24+
<define name="CAIRO_VERSION_ENCODE(major, minor, micro)" value="(((major) * 10000) + ((minor) * 100) + ((micro) * 1))"/>
2425
<!-- ########## cairo Allocation / Deallocation ########## -->
2526
<!-- ########## cairo Functions ########## -->
2627
<!-- cairo_t * cairo_create (cairo_surface_t *target); -->

cfg/gtk.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23079,4 +23079,8 @@
2307923079
<define name="GTK_PRIORITY_HIGH" value="G_PRIORITY_HIGH"/>
2308023080
<define name="GTK_PRIORITY_RESIZE" value="(G_PRIORITY_HIGH_IDLE+10)"/>
2308123081
<define name="GTK_PRIORITY_REDRAW" value="(G_PRIORITY_HIGH_IDLE+20)"/>
23082+
<!-- version check for GLib, ATK and GTK -->
23083+
<define name="GLIB_CHECK_VERSION(major, minor, micro)" value="1"/>
23084+
<define name="ATK_CHECK_VERSION(major, minor, micro)" value="1"/>
23085+
<define name="GTK_CHECK_VERSION(major, minor, micro)" value="1"/>
2308223086
</def>

test/cfg/cairo.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
#include <cairo.h>
1111

12+
#if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 2, 3)
13+
#endif
14+
1215
void validCode(cairo_surface_t *target)
1316
{
1417
cairo_t * cairo1 = cairo_create(target);

test/cfg/gtk.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@
1111
#include <glib.h>
1212
#include <glib/gtypes.h>
1313
#include <glib/gi18n.h>
14+
#include <gtk/gtk.h>
1415

1516

17+
#if GLIB_CHECK_VERSION(2, 3, 4)
18+
#endif
19+
#if GTK_CHECK_VERSION(4, 5, 6)
20+
#endif
21+
#if ATK_CHECK_VERSION(2, 3, 6)
22+
#endif
23+
1624
void validCode(int argInt, GHashTableIter * hash_table_iter, GHashTable * hash_table)
1725
{
1826
g_assert_cmpint(4 + 1, >=, 5);

0 commit comments

Comments
 (0)