Skip to content

Commit

Permalink
test: silence an infinite-loop error in g_error()
Browse files Browse the repository at this point in the history
Due to some improvements to GCC's static analyzer, the intentional
loop in `g_error()` throws an error in the CI.

Add `V_GNUC_BEGIN_IGNORE_INFINITE_LOOP` (and matching `END`) macro to
silence false positives from `g_error()`.
  • Loading branch information
andyholmes committed Mar 22, 2024
1 parent 14ce9c7 commit 420d061
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
35 changes: 35 additions & 0 deletions src/libvalent/core/valent-debug.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,40 @@ void valent_trace_mark (const char *strfunc,
# define VALENT_JSON(_node, _ctx) G_STMT_START { } G_STMT_END
#endif

/**
* V_GNUC_BEGIN_IGNORE_INFINITE_LOOP: (skip)
*
* Tells gcc (if it is a new enough version) to temporarily stop emitting
* warnings when functions employ an infinite loop. This is useful for functions
* that do so intentionally, such as [[email protected]].
*
* Since: 1.0
*/

/**
* V_GNUC_END_IGNORE_INFINITE_LOOP: (skip)
*
* Undoes the effect of [[email protected]_GNUC_BEGIN_IGNORE_INFINITE_LOOP], telling gcc
* to begin outputting warnings again (assuming those warnings had been enabled
* to begin with).
*
* Since: 1.0
*/

#if G_GNUC_CHECK_VERSION(14, 0)
#define V_GNUC_BEGIN_IGNORE_INFINITE_LOOP \
G_STMT_START { \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wanalyzer-infinite-loop\"") \
} G_STMT_END
#define V_GNUC_END_IGNORE_INFINITE_LOOP \
G_STMT_START { \
_Pragma("GCC diagnostic pop") \
} G_STMT_END
#else
#define V_GNUC_BEGIN_IGNORE_INFINITE_LOOP G_STMT_START { } G_STMT_END
#define V_GNUC_END_IGNORE_INFINITE_LOOP G_STMT_START { } G_STMT_END
#endif

G_END_DECLS

11 changes: 8 additions & 3 deletions src/libvalent/core/valent-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "config.h"

#include "valent-debug.h"
#include "valent-macros.h"
#include "valent-object.h"

Expand Down Expand Up @@ -182,9 +183,13 @@ static void
valent_object_constructed (GObject *object)
{
if G_UNLIKELY (G_OBJECT_GET_CLASS (object)->dispose != valent_object_dispose)
g_error ("%s overrides GObject.Object.dispose() instead of "
"Valent.Object.destroy(), which is not thread safe",
G_OBJECT_TYPE_NAME (object));
{
V_GNUC_BEGIN_IGNORE_INFINITE_LOOP;
g_error ("%s overrides GObject.Object.dispose() instead of "
"Valent.Object.destroy(), which is not thread safe",
G_OBJECT_TYPE_NAME (object));
V_GNUC_END_IGNORE_INFINITE_LOOP;
}

G_OBJECT_CLASS (valent_object_parent_class)->constructed (object);
}
Expand Down

0 comments on commit 420d061

Please sign in to comment.