From patchwork Mon Nov 18 06:30:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 11248955 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 424EB14DB for ; Mon, 18 Nov 2019 06:31:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2BE0020730 for ; Mon, 18 Nov 2019 06:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726597AbfKRGbD (ORCPT ); Mon, 18 Nov 2019 01:31:03 -0500 Received: from mx2.suse.de ([195.135.220.15]:38350 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726595AbfKRGbD (ORCPT ); Mon, 18 Nov 2019 01:31:03 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 793B2B246; Mon, 18 Nov 2019 06:31:01 +0000 (UTC) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: osandov@osandov.com Subject: [PATCH 2/4] btrfs-progs: libbtrfsutil: Convert to designated initialization for BtrfsUtilError_type Date: Mon, 18 Nov 2019 14:30:50 +0800 Message-Id: <20191118063052.56970-3-wqu@suse.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191118063052.56970-1-wqu@suse.com> References: <20191118063052.56970-1-wqu@suse.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org [BUG] When compiling btrfs-progs with libbtrfsutil on a python3.8 system, we got the following warning: error.c:169:2: warning: initialization of ‘long int’ from ‘void *’ makes integer from pointer without a cast [-Wint-conversion] 169 | NULL, /* tp_print */ | ^~~~ error.c:169:2: note: (near initialization for ‘BtrfsUtilError_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. Also, uninitialized values will be 0, so we can also save a lot of unneeded "= 0" or "= NULL" lines. Just use that awesome feature to avoid any future breakage. Signed-off-by: Qu Wenruo --- libbtrfsutil/python/error.c | 49 +++++++++---------------------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/libbtrfsutil/python/error.c b/libbtrfsutil/python/error.c index 0876c9b42c81..b2076e6bf4d6 100644 --- a/libbtrfsutil/python/error.c +++ b/libbtrfsutil/python/error.c @@ -162,41 +162,16 @@ static PyMemberDef BtrfsUtilError_members[] = { PyTypeObject BtrfsUtilError_type = { PyVarObject_HEAD_INIT(NULL, 0) - "btrfsutil.BtrfsUtilError", /* tp_name */ - sizeof(BtrfsUtilError), /* tp_basicsize */ - 0, /* tp_itemsize */ - (destructor)BtrfsUtilError_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 */ - (reprfunc)BtrfsUtilError_str, /* tp_str */ - NULL, /* tp_getattro */ - NULL, /* tp_setattro */ - NULL, /* tp_as_buffer */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ - BtrfsUtilError_DOC, /* tp_doc */ - (traverseproc)BtrfsUtilError_traverse, /* tp_traverse */ - (inquiry)BtrfsUtilError_clear, /* tp_clear */ - NULL, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - NULL, /* tp_iter */ - NULL, /* tp_iternext */ - NULL, /* tp_methods */ - BtrfsUtilError_members, /* tp_members */ - NULL, /* tp_getset */ - NULL, /* tp_base */ - NULL, /* tp_dict */ - NULL, /* tp_descr_get */ - NULL, /* tp_descr_set */ - offsetof(BtrfsUtilError, os_error.dict), /* tp_dictoffset */ - NULL, /* tp_init */ - NULL, /* tp_alloc */ - BtrfsUtilError_new, /* tp_new */ + .tp_name = "btrfsutil.BtrfsUtilError", + .tp_basicsize = sizeof(BtrfsUtilError), + .tp_dealloc = (destructor)BtrfsUtilError_dealloc, + .tp_str = (reprfunc)BtrfsUtilError_str, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | + Py_TPFLAGS_HAVE_GC, + .tp_doc = BtrfsUtilError_DOC, + .tp_traverse = (traverseproc)BtrfsUtilError_traverse, + .tp_clear = (inquiry)BtrfsUtilError_clear, + .tp_members = BtrfsUtilError_members, + .tp_dictoffset = offsetof(BtrfsUtilError, os_error.dict), + .tp_new = BtrfsUtilError_new, };