From 6a231008e43d5d5b8adb6ecd0a6ceff29f1ba9b1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Feb 2025 08:12:37 +0100 Subject: [PATCH] gobject/performance: fix "type-check" test to not optimize out test code Despite assigning the function to a variable, gcc can still detect that the function never changes and most of the test code is optimized out. Initialize it somewhere, where the compiler cannot prove that this function pointer is always set to the same value. We could also make the pointer volatile, but this approach seems preferable to me. --- gobject/tests/performance/performance.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gobject/tests/performance/performance.c b/gobject/tests/performance/performance.c index ce2ed70fd..934d7a274 100644 --- a/gobject/tests/performance/performance.c +++ b/gobject/tests/performance/performance.c @@ -712,6 +712,11 @@ test_finalization_print_result (PerformanceTest *test, #define NUM_KILO_CHECKS_PER_ROUND 50 +/* Work around g_type_check_instance_is_a being marked "pure", + * and thus only called once for the loop. */ +static gboolean (*my_type_check_instance_is_a) (GTypeInstance *type_instance, + GType iface_type); + struct TypeCheckTest { GObject *object; unsigned int n_checks; @@ -722,6 +727,8 @@ test_type_check_setup (PerformanceTest *test) { struct TypeCheckTest *data; + my_type_check_instance_is_a = &g_type_check_instance_is_a; + data = g_new0 (struct TypeCheckTest, 1); data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL); @@ -738,12 +745,6 @@ test_type_check_init (PerformanceTest *test, data->n_checks = (unsigned int) (factor * NUM_KILO_CHECKS_PER_ROUND); } - -/* Work around g_type_check_instance_is_a being marked "pure", - and thus only called once for the loop. */ -gboolean (*my_type_check_instance_is_a) (GTypeInstance *type_instance, - GType iface_type) = &g_type_check_instance_is_a; - static void test_type_check_run (PerformanceTest *test, gpointer _data)