From patchwork Thu Feb 23 10:48:26 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: 9588153 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 47B8D604A2 for ; Thu, 23 Feb 2017 10:51:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3383428609 for ; Thu, 23 Feb 2017 10:51:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2821328695; Thu, 23 Feb 2017 10:51:28 +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 9521C28609 for ; Thu, 23 Feb 2017 10:51:27 +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 1cgqxG-0005sH-6I; Thu, 23 Feb 2017 10:48:58 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgqxE-0005rO-Ox for xen-devel@lists.xen.org; Thu, 23 Feb 2017 10:48:56 +0000 Received: from [193.109.254.147] by server-4.bemta-6.messagelabs.com id 4D/7D-25093-81EBEA85; Thu, 23 Feb 2017 10:48:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrKIsWRWlGSWpSXmKPExsXilM8ioyu+b12 EQftqFYslHxezODB6HN39mymAMYo1My8pvyKBNWPB9RdMBV9tKg7tesnUwPhGt4uRi0NIYBWj xKfNl5m6GDmBnGyJJ00vWUESLAKXmCUu31vHCJKQEPCU+LbtPRuE7Syx/t56FoiGQ4wS52b7g NhsAqES7dtnsILYIgLSEtc+X2YEGcQsMJdR4vO/bewgCWGBAInFv5vBmlkEVCWmHTnODGLzCv hLvFn2CmqZnMTNc51gcU6g+pd9bawQy/wlJk6dxQhRLyhxcuYToDkcQAvUJdbPEwIJ8wsoSWx bfxmshFlAXqJ562zmCYzCs5B0zELomIWkagEj8ypG9eLUorLUIl1LvaSizPSMktzEzBxdQwMz vdzU4uLE9NScxKRiveT83E2MwCBnAIIdjHc3BRxilORgUhLl9dmzLkKILyk/pTIjsTgjvqg0J 7X4EKMMB4eSBO9TkJxgUWp6akVaZg4w3mDSEhw8SiK8vSBp3uKCxNzizHSI1ClGXY45s3e/YR JiycvPS5US5/0KUiQAUpRRmgc3Ahb7lxhlpYR5GYGOEuIpSC3KzSxBlX/FKM7BqCTMG7AXaAp PZl4J3KZXQEcwAR1h6bwW5IiSRISUVAOjNs8rQzObjgV2p1/4n6lZPHnRb+8V8bHRqgdklTTq vj9/csH7+0Q9OVmupiKlO5+C/p85JvPx6sUPSQEnpqw5tdLm0sSe6YuvfpLIm/Xk1LV1SwX27 zaN6rrGkN4dozA52z1kysWXUual8Vc5Em9vCdJgZPZy5D7pm3l1TmrUwom77MNWagiXK7EUZy QaajEXFScCANaPGcL4AgAA X-Env-Sender: marmarek@invisiblethingslab.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1487846934!88654956!1 X-Originating-IP: [66.111.4.28] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 16482 invoked from network); 23 Feb 2017 10:48:55 -0000 Received: from out4-smtp.messagingengine.com (HELO out4-smtp.messagingengine.com) (66.111.4.28) by server-6.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 Feb 2017 10:48:55 -0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id B2BB5208A3; Thu, 23 Feb 2017 05:48:54 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute7.internal (MEProxy); Thu, 23 Feb 2017 05:48:54 -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=neU0pJEEwVEZmP2hrW7bddJRFeY=; b=bqqflBz9b7JqeyCYu9V8 dsD3/fAuUlFnk5DXzu0IBSPPwWtbI3hQYmPNK558glgwx0tkPC0Fs3sXiugdbghi HEWE5N3EqUCxDyakl3U6QXF9W6VHTKpzpW6D2yuzQIybTjRO33Svb1V1654QqKVQ w4nysk0hIWgftHjL6fu1NGk= X-ME-Sender: X-Sasl-enc: IWAk7oNzZK4NnL+NLM4J0KvaOIG3/K08q27vJrTpSrEe 1487846934 Received: from devel-3rdparty.localdomain (89-70-103-23.dynamic.chello.pl [89.70.103.23]) by mail.messagingengine.com (Postfix) with ESMTPA id BB8E72466B; Thu, 23 Feb 2017 05:48:53 -0500 (EST) From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= To: xen-devel@lists.xen.org Date: Thu, 23 Feb 2017 11:48:26 +0100 Message-Id: <1487846908-21462-7-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 6/8] python: use PyLong_* for constructing 'int' type in 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 'int' and 'long' types are the same, there are no longer separate PyInt_* functions. Provide convenient #defines to limit #if in code. Signed-off-by: Marek Marczykowski-Górecki --- tools/python/xen/lowlevel/xc/xc.c | 51 ++++++++++++++++++++++++--------------- tools/python/xen/lowlevel/xs/xs.c | 8 ++++++ 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index ce87afb..df31a1d 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -34,6 +34,17 @@ #define FLASK_CTX_LEN 1024 +/* Python 2 compatibility */ +#if PY_MAJOR_VERSION >= 3 +#define PyLongOrInt_FromLong PyLong_FromLong +#define PyLongOrInt_Check PyLong_Check +#define PyLongOrInt_AsLong PyLong_AsLong +#else +#define PyLongOrInt_FromLong PyInt_FromLong +#define PyLongOrInt_Check PyInt_Check +#define PyLongOrInt_AsLong PyInt_AsLong +#endif + static PyObject *xc_error_obj, *zero; typedef struct { @@ -127,9 +138,9 @@ static PyObject *pyxc_domain_create(XcObject *self, for ( i = 0; i < sizeof(xen_domain_handle_t); i++ ) { PyObject *p = PyList_GetItem(pyhandle, i); - if ( !PyInt_Check(p) ) + if ( !PyLongOrInt_Check(p) ) goto out_exception; - handle[i] = (uint8_t)PyInt_AsLong(p); + handle[i] = (uint8_t)PyLongOrInt_AsLong(p); } } @@ -142,7 +153,7 @@ static PyObject *pyxc_domain_create(XcObject *self, return pyxc_error_to_exception(self->xc_handle); - return PyInt_FromLong(dom); + return PyLongOrInt_FromLong(dom); out_exception: errno = EINVAL; @@ -242,7 +253,7 @@ static PyObject *pyxc_vcpu_setaffinity(XcObject *self, { for ( i = 0; i < PyList_Size(cpulist); i++ ) { - long cpu = PyInt_AsLong(PyList_GetItem(cpulist, i)); + long cpu = PyLongOrInt_AsLong(PyList_GetItem(cpulist, i)); if ( cpu < 0 || cpu >= nr_cpus ) { free(cpumap); @@ -284,9 +295,9 @@ static PyObject *pyxc_domain_sethandle(XcObject *self, PyObject *args) for ( i = 0; i < sizeof(xen_domain_handle_t); i++ ) { PyObject *p = PyList_GetItem(pyhandle, i); - if ( !PyInt_Check(p) ) + if ( !PyLongOrInt_Check(p) ) goto out_exception; - handle[i] = (uint8_t)PyInt_AsLong(p); + handle[i] = (uint8_t)PyLongOrInt_AsLong(p); } if (xc_domain_sethandle(self->xc_handle, dom, handle) < 0) @@ -361,7 +372,7 @@ static PyObject *pyxc_domain_getinfo(XcObject *self, return NULL; } for ( j = 0; j < sizeof(xen_domain_handle_t); j++ ) - PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j])); + PyList_SetItem(pyhandle, j, PyLongOrInt_FromLong(info[i].handle[j])); PyDict_SetItemString(info_dict, "handle", pyhandle); Py_DECREF(pyhandle); PyList_SetItem(list, i, info_dict); @@ -420,7 +431,7 @@ static PyObject *pyxc_vcpu_getinfo(XcObject *self, for ( i = 0; i < nr_cpus; i++ ) { if (*(cpumap + i / 8) & 1 ) { - PyObject *pyint = PyInt_FromLong(i); + PyObject *pyint = PyLongOrInt_FromLong(i); PyList_Append(cpulist, pyint); Py_DECREF(pyint); } @@ -836,7 +847,7 @@ static PyObject *pyxc_evtchn_alloc_unbound(XcObject *self, if ( (port = xc_evtchn_alloc_unbound(self->xc_handle, dom, remote_dom)) < 0 ) return pyxc_error_to_exception(self->xc_handle); - return PyInt_FromLong(port); + return PyLongOrInt_FromLong(port); } static PyObject *pyxc_evtchn_reset(XcObject *self, @@ -1063,7 +1074,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self) } else { - PyObject *pyint = PyInt_FromLong(cputopo[i].core); + PyObject *pyint = PyLongOrInt_FromLong(cputopo[i].core); PyList_Append(cpu_to_core_obj, pyint); Py_DECREF(pyint); } @@ -1074,7 +1085,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self) } else { - PyObject *pyint = PyInt_FromLong(cputopo[i].socket); + PyObject *pyint = PyLongOrInt_FromLong(cputopo[i].socket); PyList_Append(cpu_to_socket_obj, pyint); Py_DECREF(pyint); } @@ -1085,7 +1096,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self) } else { - PyObject *pyint = PyInt_FromLong(cputopo[i].node); + PyObject *pyint = PyLongOrInt_FromLong(cputopo[i].node); PyList_Append(cpu_to_node_obj, pyint); Py_DECREF(pyint); } @@ -1139,18 +1150,18 @@ static PyObject *pyxc_numainfo(XcObject *self) unsigned invalid_node; /* Total Memory */ - pyint = PyInt_FromLong(meminfo[i].memsize >> 20); /* MB */ + pyint = PyLongOrInt_FromLong(meminfo[i].memsize >> 20); /* MB */ PyList_Append(node_to_memsize_obj, pyint); Py_DECREF(pyint); /* Free Memory */ - pyint = PyInt_FromLong(meminfo[i].memfree >> 20); /* MB */ + pyint = PyLongOrInt_FromLong(meminfo[i].memfree >> 20); /* MB */ PyList_Append(node_to_memfree_obj, pyint); Py_DECREF(pyint); /* DMA memory. */ xc_availheap(self->xc_handle, 0, 32, i, &free_heap); - pyint = PyInt_FromLong(free_heap >> 20); /* MB */ + pyint = PyLongOrInt_FromLong(free_heap >> 20); /* MB */ PyList_Append(node_to_dma32_mem_obj, pyint); Py_DECREF(pyint); @@ -1166,7 +1177,7 @@ static PyObject *pyxc_numainfo(XcObject *self) } else { - pyint = PyInt_FromLong(dist); + pyint = PyLongOrInt_FromLong(dist); PyList_Append(node_to_node_dist_obj, pyint); Py_DECREF(pyint); } @@ -1700,7 +1711,7 @@ static PyObject *cpumap_to_cpulist(XcObject *self, xc_cpumap_t cpumap) { if ( *cpumap & (1 << (i % 8)) ) { - PyObject* pyint = PyInt_FromLong(i); + PyObject* pyint = PyLongOrInt_FromLong(i); PyList_Append(cpulist, pyint); Py_DECREF(pyint); @@ -1726,7 +1737,7 @@ static PyObject *pyxc_cpupool_create(XcObject *self, if ( xc_cpupool_create(self->xc_handle, &cpupool, sched) < 0 ) return pyxc_error_to_exception(self->xc_handle); - return PyInt_FromLong(cpupool); + return PyLongOrInt_FromLong(cpupool); } static PyObject *pyxc_cpupool_destroy(XcObject *self, @@ -1882,7 +1893,7 @@ static PyObject *pyflask_context_to_sid(PyObject *self, PyObject *args, return PyErr_SetFromErrno(xc_error_obj); } - return PyInt_FromLong(sid); + return PyLongOrInt_FromLong(sid); } static PyObject *pyflask_sid_to_context(PyObject *self, PyObject *args, @@ -2705,7 +2716,7 @@ PyMODINIT_FUNC initxc(void) Py_DECREF(m); return; } - zero = PyInt_FromLong(0); + zero = PyLongOrInt_FromLong(0); /* KAF: This ensures that we get debug output in a timely manner. */ setbuf(stdout, NULL); diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c index c2b4d87..b37daa9 100644 --- a/tools/python/xen/lowlevel/xs/xs.c +++ b/tools/python/xen/lowlevel/xs/xs.c @@ -43,6 +43,14 @@ #define PKG "xen.lowlevel.xs" #define CLS "xs" +#if PY_MAJOR_VERSION < 3 +/* Python 2 compatibility */ +#define PyLong_FromLong PyInt_FromLong +#undef PyLong_Check +#define PyLong_Check PyInt_Check +#define PyLong_AsLong PyInt_AsLong +#endif + static PyObject *xs_error; /** Python wrapper round an xs handle.