unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] index: explicitly follow GObject conventions
@ 2018-10-07  1:37 Daniel Kahn Gillmor
  2018-10-21 13:34 ` David Bremner
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Kahn Gillmor @ 2018-10-07  1:37 UTC (permalink / raw)
  To: Notmuch Mail

Use explicit labels for GTypeInfo member initializers, rather than
relying on comments and ordering.  This is both easier to read, and
harder to screw up.  This also makes it clear that we're mis-casting
GObject class initializers for gcc.

Without this patch, g++ 8.2.0-7 produces this warning:

CXX  -g -O2 lib/index.o
lib/index.cc: In function ‘GMimeFilter* notmuch_filter_discard_non_term_new(GMimeContentType*)’:
lib/index.cc:252:23: warning: cast between incompatible function types from ‘void (*)(NotmuchFilterDiscardNonTermClass*)’ {aka ‘void (*)(_NotmuchFilterDiscardNonTermClass*)’} to ‘GClassInitFunc’ {aka ‘void (*)(void*, void*)’} [-Wcast-function-type]
      (GClassInitFunc) notmuch_filter_discard_non_term_class_init,
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The definition of GClassInitFunc in
/usr/include/glib-2.0/gobject/gtype.h suggests that this function will
always be called with the class_data member of the GTypeInfo.  We set
that value to NULL in both GObject definitions in notmuch. So we mark
it as explicitly unused.

There is no functional change here, just code cleanup.
---
 gmime-filter-reply.c | 25 +++++++++++++------------
 lib/index.cc         | 23 ++++++++++++-----------
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/gmime-filter-reply.c b/gmime-filter-reply.c
index f673c0a2..480d9381 100644
--- a/gmime-filter-reply.c
+++ b/gmime-filter-reply.c
@@ -19,6 +19,7 @@
 #include <stdbool.h>
 
 #include "gmime-filter-reply.h"
+#include "notmuch-client.h"
 
 /**
  * SECTION: gmime-filter-reply
@@ -29,7 +30,7 @@
  **/
 
 
-static void g_mime_filter_reply_class_init (GMimeFilterReplyClass *klass);
+static void g_mime_filter_reply_class_init (GMimeFilterReplyClass *klass, void *class_data);
 static void g_mime_filter_reply_init (GMimeFilterReply *filter, GMimeFilterReplyClass *klass);
 static void g_mime_filter_reply_finalize (GObject *object);
 
@@ -50,16 +51,16 @@ g_mime_filter_reply_get_type (void)
 
 	if (!type) {
 		static const GTypeInfo info = {
-			sizeof (GMimeFilterReplyClass),
-			NULL, /* base_class_init */
-			NULL, /* base_class_finalize */
-			(GClassInitFunc) g_mime_filter_reply_class_init,
-			NULL, /* class_finalize */
-			NULL, /* class_data */
-			sizeof (GMimeFilterReply),
-			0,    /* n_preallocs */
-			(GInstanceInitFunc) g_mime_filter_reply_init,
-			NULL	/* value_table */
+			.class_size = sizeof (GMimeFilterReplyClass),
+			.base_init = NULL,
+			.base_finalize = NULL,
+			.class_init = (GClassInitFunc) g_mime_filter_reply_class_init,
+			.class_finalize = NULL,
+			.class_data = NULL,
+			.instance_size = sizeof (GMimeFilterReply),
+			.n_preallocs = 0,
+			.instance_init = (GInstanceInitFunc) g_mime_filter_reply_init,
+			.value_table = NULL,
 		};
 
 		type = g_type_register_static (GMIME_TYPE_FILTER, "GMimeFilterReply", &info, (GTypeFlags) 0);
@@ -70,7 +71,7 @@ g_mime_filter_reply_get_type (void)
 
 
 static void
-g_mime_filter_reply_class_init (GMimeFilterReplyClass *klass)
+g_mime_filter_reply_class_init (GMimeFilterReplyClass *klass, unused (void *class_data))
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	GMimeFilterClass *filter_class = GMIME_FILTER_CLASS (klass);
diff --git a/lib/index.cc b/lib/index.cc
index 3f694387..efd9da4c 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -142,7 +142,8 @@ static void filter_reset (GMimeFilter *filter);
 static GMimeFilterClass *parent_class = NULL;
 
 static void
-notmuch_filter_discard_non_term_class_init (NotmuchFilterDiscardNonTermClass *klass)
+notmuch_filter_discard_non_term_class_init (NotmuchFilterDiscardNonTermClass *klass,
+					    unused (void *class_data))
 {
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
     GMimeFilterClass *filter_class = GMIME_FILTER_CLASS (klass);
@@ -246,16 +247,16 @@ notmuch_filter_discard_non_term_new (GMimeContentType *content_type)
 
     if (!type) {
 	static const GTypeInfo info = {
-	    sizeof (NotmuchFilterDiscardNonTermClass),
-	    NULL, /* base_class_init */
-	    NULL, /* base_class_finalize */
-	    (GClassInitFunc) notmuch_filter_discard_non_term_class_init,
-	    NULL, /* class_finalize */
-	    NULL, /* class_data */
-	    sizeof (NotmuchFilterDiscardNonTerm),
-	    0,    /* n_preallocs */
-	    NULL, /* instance_init */
-	    NULL  /* value_table */
+	    .class_size = sizeof (NotmuchFilterDiscardNonTermClass),
+	    .base_init = NULL,
+	    .base_finalize = NULL,
+	    .class_init = (GClassInitFunc) notmuch_filter_discard_non_term_class_init,
+	    .class_finalize = NULL,
+	    .class_data = NULL,
+	    .instance_size = sizeof (NotmuchFilterDiscardNonTerm),
+	    .n_preallocs = 0,
+	    .instance_init = NULL,
+	    .value_table = NULL,
 	};
 
 	type = g_type_register_static (GMIME_TYPE_FILTER, "NotmuchFilterDiscardNonTerm", &info, (GTypeFlags) 0);
-- 
2.19.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] index: explicitly follow GObject conventions
  2018-10-07  1:37 [PATCH] index: explicitly follow GObject conventions Daniel Kahn Gillmor
@ 2018-10-21 13:34 ` David Bremner
  0 siblings, 0 replies; 2+ messages in thread
From: David Bremner @ 2018-10-21 13:34 UTC (permalink / raw)
  To: Daniel Kahn Gillmor, Notmuch Mail

Daniel Kahn Gillmor <dkg@fifthhorseman.net> writes:

> Use explicit labels for GTypeInfo member initializers, rather than
> relying on comments and ordering.  This is both easier to read, and
> harder to screw up.  This also makes it clear that we're mis-casting
> GObject class initializers for gcc.
>
> Without this patch, g++ 8.2.0-7 produces this warning:

pushed

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-21 13:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-07  1:37 [PATCH] index: explicitly follow GObject conventions Daniel Kahn Gillmor
2018-10-21 13:34 ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).