Re: log_warning_error_tests()



On 16/06/2013 12:42, John Emmas wrote:

If I change it to this, the test passes:-

#ifdef _MSC_VER
        g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
                         "*assertion*failed*");
#else
        g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
                         "*g_print*assertion*failed*");
#endif
        g_print (NULL);

The problem seems to be that the macro 'g_return_if_fail' expands to a second macro which uses the identifier __PRETTY_FUNCTION__.  However, __PRETTY_FUNCTION__ is a gcc extension which is defined in glib/gmacros.h - but it's only defined for GNUC.  When building with MSVC the relevant function name (g_print, in this case) won't get included in any assertion text.  Does that make sense?


I think I arrived at the right conclusion but for the wrong reason.  The damage in fact gets caused in 'glib/gmessages.h' by the declaration of 'g_return_if_fail' (again, abbreviated slightly for clarity):-

#ifdef __GNUC__

        #define g_return_if_fail(expr)        G_STMT_START{            \
             if G_LIKELY(expr) { } else                           \
             {                                \
                 g_return_if_fail_warning (G_LOG_DOMAIN,            \
                                 __PRETTY_FUNCTION__,                \
                                 #expr);                \
                 return;                            \
             };                }G_STMT_END

#else /* !__GNUC__ */

        #define g_return_if_fail(expr)        G_STMT_START{        \
             if (expr) { } else                        \
             {                            \
               g_log (G_LOG_DOMAIN,                    \
                  G_LOG_LEVEL_CRITICAL,                \
                  "file %s: line %d: assertion '%s' failed",    \
                  __FILE__,                    \
                  __LINE__,                    \
                  #expr);                        \
               return;                        \
             };                }G_STMT_END

#endif

So as you can see, for any non-GNUC build, the name of the function that failed will not form part of the assertion text.  So my suggested fix (in 'test_glib.c') should probably get changed to this:-

#ifdef __GNUC__
        g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
                         "*g_print*assertion*failed*");
#else
        g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
                         "*assertion*failed*");
#endif

Do I need to submit a bug report and patch or can it be fixed quite easily (given that the code only just got changed) ?

John


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]