From 5388542fc09d51d4ee1fc1c45f839c32e2dd11aa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 24 Jun 2021 11:10:35 +0200 Subject: [PATCH] checkpatch: discourage use of API that uses numeric source IDs The numeric source IDs exist from a time before 2000, when there was only one "GMainContext" singleton instance. Nowadays, the source ID is only relative to one GMainContext, and you'd have to track that association yourself. Als, g_source_remove() requires an additional hash lookup, when you could simply track the GSource instance from the start. This API should not be used anymore. Operate on GSouce instances direclty and use API like nm_clear_g_source_inst() nm_g_idle_add_source() nm_g_idle_souce_new() nm_g_source_attach() g_source_attach g_source_destroy g_source_unref etc. Note that if you don't care about to ever remove a source again, like scheduling an idle action that should not be cancelled, then g_idle_add(callback, user_data); is fine. It is only problematic to do something with those numeric IDs. checkpatch.pl would also flag those uses, but these are just warnings and in the few cases where such a warning is emitted wrongly, it's find to ignore them. --- contrib/scripts/checkpatch.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/scripts/checkpatch.pl b/contrib/scripts/checkpatch.pl index c64f69db9b..c535fd0a93 100755 --- a/contrib/scripts/checkpatch.pl +++ b/contrib/scripts/checkpatch.pl @@ -191,6 +191,7 @@ complain ("This gtk-doc annotation looks wrong") if $line =~ /\*.*\( *(transfer- complain ("Prefer nm_assert() or g_return*() to g_assert*()") if $line =~ /g_assert/ and (not $filename =~ /\/tests\//) and (not $filename =~ /\/nm-test-/); complain ("Use gs_free_error with GError variables") if $line =~ /\bgs_free\b +GError *\*/; complain ("Don't use strcmp/g_strcmp0 unless you need to sort. Consider nm_streq()/nm_streq0(),NM_IN_STRSET() for testing equality") if $line =~ /\b(strcmp|g_strcmp0)\b/; +complain ("Don't use API that uses the numeric source id. Instead, use GSource and API like nm_g_idle_add_source(), nm_clear_g_source_inst(), etc.") if $line =~ /\b(g_idle_add|g_idle_add_full|g_timeout_add|g_timeout_add_seconds|g_source_remove|nm_clear_g_source)\b/; #complain ("Use spaces instead of tabs") if $line =~ /\t/; # Further on we process stuff without comments.