From f01d2b85581e9e695897dfc86b7c8d8e3b04a232 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Mon, 18 Nov 2019 14:30:52 +0800 Subject: [PATCH] libbtrfsutil: Convert to designated initialization for SubvolumeIterator_type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [BUG] When compiling btrfs-progs with libbtrfsutil on a python3.8 system, we got the following warning: subvolume.c:636:2: warning: initialization of ‘long int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion] 636 | NULL, /* tp_print */ | ^~~~ subvolume.c:636:2: note: (near initialization for ‘SubvolumeIterator_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. Reviewed-by: Nikolay Borisov Reviewed-by: Omar Sandoval Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- libbtrfsutil/python/subvolume.c | 44 +++++++-------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) diff --git a/libbtrfsutil/python/subvolume.c b/libbtrfsutil/python/subvolume.c index 0f893b91..a837d2e3 100644 --- a/libbtrfsutil/python/subvolume.c +++ b/libbtrfsutil/python/subvolume.c @@ -629,39 +629,13 @@ static PyMethodDef SubvolumeIterator_methods[] = { PyTypeObject SubvolumeIterator_type = { PyVarObject_HEAD_INIT(NULL, 0) - "btrfsutil.SubvolumeIterator", /* tp_name */ - sizeof(SubvolumeIterator), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)SubvolumeIterator_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 */ - NULL, /* tp_getattro */ - NULL, /* tp_setattro */ - NULL, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - SubvolumeIterator_DOC, /* tp_doc */ - NULL, /* tp_traverse */ - NULL, /* tp_clear */ - NULL, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - PyObject_SelfIter, /* tp_iter */ - (iternextfunc)SubvolumeIterator_next, /* tp_iternext */ - SubvolumeIterator_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)SubvolumeIterator_init, /* tp_init */ + .tp_name = "btrfsutil.SubvolumeIterator", + .tp_basicsize = sizeof(SubvolumeIterator), + .tp_dealloc = (destructor)SubvolumeIterator_dealloc, + .tp_flags = Py_TPFLAGS_DEFAULT, + .tp_doc = SubvolumeIterator_DOC, + .tp_iter = PyObject_SelfIter, + .tp_iternext = (iternextfunc)SubvolumeIterator_next, + .tp_methods = SubvolumeIterator_methods, + .tp_init = (initproc)SubvolumeIterator_init, };