From patchwork Thu Feb 23 10:48:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 9588155 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 61F2C604A2 for ; Thu, 23 Feb 2017 10:51:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DD3328609 for ; Thu, 23 Feb 2017 10:51:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42AEE28695; Thu, 23 Feb 2017 10:51:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DA60328609 for ; Thu, 23 Feb 2017 10:51:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgqxH-0005tA-D9; Thu, 23 Feb 2017 10:48:59 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgqxF-0005pu-L4 for xen-devel@lists.xen.org; Thu, 23 Feb 2017 10:48:57 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id FC/DE-04971-91EBEA85; Thu, 23 Feb 2017 10:48:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCIsWRWlGSWpSXmKPExsXilM8ioyuxb12 EwZqlhhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8a2Dx9ZC94rVKx6fp+5gXGKVBcjJ4eQwCpG iQWbgyDsbInZ696wg9gsApeYJT69zwOxJQQ8JU6f/MUGYTtLHG7dx9TFyAVUf4hRYvGhPUwgC TaBUIn27TNYQWwRAWmJa58vM4IUMQvMZZT4/G8b2FRhAReJvqOLgRIcQBtUJf5NAhvKK+AvMX 3iESaIBXISN891MoPYnAIBEi/72lghjvOXmDh1FiNEvaDEyZlPWEDGMAuoS6yfJwQS5hdQkti 2/jJYCbOAvETz1tnMExiFZyHpmIXQMQtJ1QJG5lWMGsWpRWWpRbqGFnpJRZnpGSW5iZk5uoYG Znq5qcXFiempOYlJxXrJ+bmbGIEhzgAEOxhvbgw4xCjJwaQkyuuzZ12EEF9SfkplRmJxRnxRa U5q8SFGGQ4OJQnepyA5waLU9NSKtMwcYLTBpCU4eJREeHtB0rzFBYm5xZnpEKlTjLocc2bvfs MkxJKXn5cqJc77FaRIAKQoozQPbgQs8i8xykoJ8zICHSXEU5BalJtZgir/ilGcg1FJmFdwL9A Unsy8ErhNr4COYAI6wtJ5LcgRJYkIKakGxjkpq0JjCgqDOoozorc+/j9R7VGRYqx82/HrrQXz I8JUY2adt/reFLVMd/OfxxujX1+6vltQunvJikyrk9wtLAuX/L+7v/1h9xKjPYm7fs+69czw/ xrL+NqsPasZfQ9NTLJekPRQvrN0V4r+ofJ6m7wGfwuHY3ZZXYfv2d1pmbSxN0dc7WqskhJLcU aioRZzUXEiALVHiNn3AgAA X-Env-Sender: marmarek@invisiblethingslab.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1487846936!35632724!1 X-Originating-IP: [66.111.4.28] X-SpamReason: No, hits=0.0 required=7.0 tests=UPPERCASE_25_50 X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9062 invoked from network); 23 Feb 2017 10:48:56 -0000 Received: from out4-smtp.messagingengine.com (HELO out4-smtp.messagingengine.com) (66.111.4.28) by server-15.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 Feb 2017 10:48:56 -0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id C5783209FE; Thu, 23 Feb 2017 05:48:55 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Thu, 23 Feb 2017 05:48:55 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=jrEHnJ3mt9l1UaZMXS94ePCAc8s=; b=pgoyvqH/pYKnJnd6Vbyx fvMf32b8B7hhZPVy3ktf5RsZwuj0SAmj69OPZp+5PzAnHNtTPCbyTL888IG3e2MM DZjgEh9oxPFDw/q7IcPqsYbF7oMGLB4307qTYjChUWQ8MtvDbQgGDyLHPY/3m8p8 sr1L7KgtrEyPVbH1P6QQ1J0= X-ME-Sender: X-Sasl-enc: Gr8o68Z+29UpkSv9gAi6gLchWCIE60F2+Q7FCQEY+HCK 1487846935 Received: from devel-3rdparty.localdomain (89-70-103-23.dynamic.chello.pl [89.70.103.23]) by mail.messagingengine.com (Postfix) with ESMTPA id D0A8D24357; Thu, 23 Feb 2017 05:48:54 -0500 (EST) From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xen.org Date: Thu, 23 Feb 2017 11:48:27 +0100 Message-Id: <1487846908-21462-8-git-send-email-marmarek@invisiblethingslab.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487846908-21462-1-git-send-email-marmarek@invisiblethingslab.com> References: <1487846908-21462-1-git-send-email-marmarek@invisiblethingslab.com> MIME-Version: 1.0 Organization: Invisible Things Lab Cc: Wei Liu , Ian Jackson , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Subject: [Xen-devel] [PATCH 7/8] python: adjust module initalization for Python3 X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In Python3, PyTypeObject looks slightly different, and also module initialization is different. Instead of Py_InitModule, PyModule_Create should be called on already defined PyModuleDef structure. And then initialization function should return that module. Additionally initialization function should be named PyInit_, instead of init. Signed-off-by: Marek Marczykowski-Górecki --- tools/python/xen/lowlevel/xc/xc.c | 35 ++++++++++++++++++++++++++++++++--- tools/python/xen/lowlevel/xs/xs.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 6 deletions(-) diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index df31a1d..d09c45f 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -2685,7 +2685,11 @@ static void PyXc_dealloc(XcObject *self) } static PyTypeObject PyXcType = { +#if PY_MAJOR_VERSION >= 3 + .ob_base = { PyObject_HEAD_INIT(NULL) }, +#else PyObject_HEAD_INIT(NULL) +#endif .tp_name = PKG "." CLS, .tp_basicsize = sizeof(XcObject), .tp_itemsize = 0, @@ -2699,22 +2703,44 @@ static PyTypeObject PyXcType = { static PyMethodDef xc_methods[] = { { NULL } }; + +#if PY_MAJOR_VERSION >= 3 +static PyModuleDef xc_module = { + PyModuleDef_HEAD_INIT, + PKG, /* name */ + NULL, /* docstring */ + -1, /* size of per-interpreter state, -1 means the module use global + variables */ + xc_methods +}; +#endif + +#if PY_MAJOR_VERSION >= 3 +#define INITERROR return NULL +PyMODINIT_FUNC PyInit_xc(void) +#else +#define INITERROR return PyMODINIT_FUNC initxc(void) +#endif { PyObject *m; if (PyType_Ready(&PyXcType) < 0) - return; + INITERROR; +#if PY_MAJOR_VERSION >= 3 + m = PyModule_Create(&xc_module); +#else m = Py_InitModule(PKG, xc_methods); +#endif if (m == NULL) - return; + INITERROR; xc_error_obj = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL); if (xc_error_obj == NULL) { Py_DECREF(m); - return; + INITERROR; } zero = PyLongOrInt_FromLong(0); @@ -2732,6 +2758,9 @@ PyMODINIT_FUNC initxc(void) PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT", XEN_SCHEDULER_CREDIT); PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT2", XEN_SCHEDULER_CREDIT2); +#if PY_MAJOR_VERSION >= 3 + return m; +#endif } diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c index b37daa9..aba5a20 100644 --- a/tools/python/xen/lowlevel/xs/xs.c +++ b/tools/python/xen/lowlevel/xs/xs.c @@ -946,7 +946,11 @@ static void xshandle_dealloc(XsHandle *self) } static PyTypeObject xshandle_type = { +#if PY_MAJOR_VERSION >= 3 + .ob_base = { PyObject_HEAD_INIT(NULL) }, +#else PyObject_HEAD_INIT(NULL) +#endif .tp_name = PKG "." CLS, .tp_basicsize = sizeof(XsHandle), .tp_itemsize = 0, @@ -960,22 +964,43 @@ static PyTypeObject xshandle_type = { static PyMethodDef xs_methods[] = { { NULL } }; +#if PY_MAJOR_VERSION >= 3 +static PyModuleDef xs_module = { + PyModuleDef_HEAD_INIT, + PKG, /* name */ + NULL, /* docstring */ + -1, /* size of per-interpreter state, -1 means the module use global + variables */ + xs_methods +}; +#endif + +#if PY_MAJOR_VERSION >= 3 +#define INITERROR return NULL +PyMODINIT_FUNC PyInit_xs(void) +#else +#define INITERROR return PyMODINIT_FUNC initxs(void) +#endif { PyObject* m; if (PyType_Ready(&xshandle_type) < 0) - return; + INITERROR; +#if PY_MAJOR_VERSION >= 3 + m = PyModule_Create(&xs_module); +#else m = Py_InitModule(PKG, xs_methods); +#endif if (m == NULL) - return; + INITERROR; xs_error = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL); if (xs_error == NULL) { Py_DECREF(m); - return; + INITERROR; } Py_INCREF(&xshandle_type); @@ -983,6 +1008,9 @@ PyMODINIT_FUNC initxs(void) Py_INCREF(xs_error); PyModule_AddObject(m, "Error", xs_error); +#if PY_MAJOR_VERSION >= 3 + return m; +#endif }