linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Cc: osandov@osandov.com
Subject: [PATCH 3/4] btrfs-progs: libbtrfsutil: Convert to designated initialization for QgroupInherit_type
Date: Mon, 18 Nov 2019 14:30:51 +0800	[thread overview]
Message-ID: <20191118063052.56970-4-wqu@suse.com> (raw)
In-Reply-To: <20191118063052.56970-1-wqu@suse.com>

[BUG]
When compiling btrfs-progs with libbtrfsutil on a python3.8 system, we
got the following warning:

  qgroup.c:110:2: warning: initialization of ‘long int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion]
    110 |  NULL,     /* tp_print */
        |  ^~~~
  qgroup.c:110:2: note: (near initialization for ‘QgroupInherit_type.tp_vectorcall_offset’)

[CAUSE]
C definition of PyTypeObject changed in python 3.8.
Now at the old tp_print, we have tp_vectorcall_offset.

So we got above warning.

[FIX]
C has designated initialization, which can assign values to each named
member, without hard coding to match the offset.
And all the other uninitialized values will be set to 0, so we can save
a lot of unneeded "= 0" or "= NULL" lines.

Just use that awesome feature to avoid any future breakage.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 libbtrfsutil/python/qgroup.c | 43 +++++++-----------------------------
 1 file changed, 8 insertions(+), 35 deletions(-)

diff --git a/libbtrfsutil/python/qgroup.c b/libbtrfsutil/python/qgroup.c
index 44ac5ebc19d2..163fbbf077e6 100644
--- a/libbtrfsutil/python/qgroup.c
+++ b/libbtrfsutil/python/qgroup.c
@@ -103,39 +103,12 @@ static PyMethodDef QgroupInherit_methods[] = {
 
 PyTypeObject QgroupInherit_type = {
 	PyVarObject_HEAD_INIT(NULL, 0)
-	"btrfsutil.QgroupInherit",		/* tp_name */
-	sizeof(QgroupInherit),			/* tp_basicsize */
-	0,					/* tp_itemsize */
-	(destructor)QgroupInherit_dealloc,	/* tp_dealloc */
-	NULL,					/* tp_print */
-	NULL,					/* tp_getattr */
-	NULL,					/* tp_setattr */
-	NULL,					/* tp_as_async */
-	NULL,					/* tp_repr */
-	NULL,					/* tp_as_number */
-	NULL,					/* tp_as_sequence */
-	NULL,					/* tp_as_mapping */
-	NULL,					/* tp_hash  */
-	NULL,					/* tp_call */
-	NULL,					/* tp_str */
-	(getattrofunc)QgroupInherit_getattro,	/* tp_getattro */
-	NULL,					/* tp_setattro */
-	NULL,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT,			/* tp_flags */
-	QgroupInherit_DOC,			/* tp_doc */
-	NULL,					/* tp_traverse */
-	NULL,					/* tp_clear */
-	NULL,					/* tp_richcompare */
-	0,					/* tp_weaklistoffset */
-	NULL,					/* tp_iter */
-	NULL,					/* tp_iternext */
-	QgroupInherit_methods,			/* tp_methods */
-	NULL,					/* tp_members */
-	NULL,					/* tp_getset */
-	NULL,					/* tp_base */
-	NULL,					/* tp_dict */
-	NULL,					/* tp_descr_get */
-	NULL,					/* tp_descr_set */
-	0,					/* tp_dictoffset */
-	(initproc)QgroupInherit_init,		/* tp_init */
+	.tp_name		= "btrfsutil.QgroupInherit",
+	.tp_basicsize		= sizeof(QgroupInherit),
+	.tp_dealloc		= (destructor)QgroupInherit_dealloc,
+	.tp_getattro		= (getattrofunc)QgroupInherit_getattro,
+	.tp_flags		= Py_TPFLAGS_DEFAULT,
+	.tp_doc			= QgroupInherit_DOC,
+	.tp_methods		= QgroupInherit_methods,
+	.tp_init		= (initproc)QgroupInherit_init,
 };
-- 
2.24.0


  parent reply	other threads:[~2019-11-18  6:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-18  6:30 [PATCH 0/4] btrfs-progs: Compiling warning fixes for devel branch Qu Wenruo
2019-11-18  6:30 ` [PATCH 1/4] btrfs-progs: check/lowmem: Fix a false alert on uninitialized value Qu Wenruo
2019-11-18  6:30 ` [PATCH 2/4] btrfs-progs: libbtrfsutil: Convert to designated initialization for BtrfsUtilError_type Qu Wenruo
2019-11-18  6:30 ` Qu Wenruo [this message]
2019-11-18  6:30 ` [PATCH 4/4] btrfs-progs: libbtrfsutil: Convert to designated initialization for SubvolumeIterator_type Qu Wenruo
2019-11-18  8:23 ` [PATCH 0/4] btrfs-progs: Compiling warning fixes for devel branch Nikolay Borisov
2019-11-18 18:10 ` David Sterba
2019-11-18 18:27 ` Omar Sandoval
2019-11-18 23:47   ` Qu WenRuo
2019-11-19 20:38     ` Omar Sandoval

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191118063052.56970-4-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=osandov@osandov.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).