From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marek =?utf-8?Q?Marczykowski-G=C3=B3recki?= Subject: Python 3 bindings Date: Fri, 17 Feb 2017 13:36:01 +0100 Message-ID: <20170217123601.GF12171@mail-itl> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0700342868274011847==" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: xen-devel List-Id: xen-devel@lists.xenproject.org --===============0700342868274011847== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="CGDBiGfvSTbxKZlW" Content-Disposition: inline --CGDBiGfvSTbxKZlW Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, I'm adjusting python bindings to work on python3 too. This will require few #if in the code (to compile for both python2 and python3), but it isn't that bad. But there are some major changes in python3, which require some decision about the bindings API: 1. Python3 has no longer separate 'int' and 'long' type - old 'long' type was renamed to 'int' (but on C-API level, it uses PyLong_*). I see two options: - switch to PyLong_* everywhere, including python2 bindings - this makes the code much cleaner, but it is an API change in python2 - switch to PyLong_* only for python3 - this will introduce some #ifdefs, but python2 API will be unchanged 2. Python3 has no longer separate 'str' and 'unicode' type, new 'str' is the same as 'unicode' (PyUnicode_* at C-API level). For things not really unicode-aware, 'bytes' type should be used. On the other hand, in python2 'bytes' type was the same as 'str'. This affects various places, where in most cases 'bytes' type is appropriate (for example cpuid). But I'm not sure about xenstore paths - those should also be 'bytes', or maybe 'unicode' (which is implicitly using 'utf-8' encoding)? I think the only reason to use 'unicode' is convenience for API users - in python3 if you write 'some string' it will be unicode type, to create bytes data you need to write b'some string'. As for python2, it should definitely be still 'str'/'bytes' type. There is one more little detail - build process. Here I'm going to follow popular standard - use $(PYTHON) variable - if that points to python3, build for python3. Actually this means no change in the current makefile. If someone want to build for both python2 and python3, will need to call the build twice - at packaging level. --=20 Best Regards, Marek Marczykowski-G=C3=B3recki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? --CGDBiGfvSTbxKZlW Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJYpu4yAAoJENuP0xzK19cs9yUH/RA/ftaWj2lnh56VzZvps7Lv tbr30iSp81+ZF1aS9zM7J6Qf33bHNXWU+RiLjN16oXWBzOiGEC9Y/o6XteUpihcb C/InHpisjTzAfJMmkj0GJZeV3UUuclSZbrHZQvSvCHqMXmmjze+f/MT1S6drDTm2 kZNvhkj7ty9bZ/pkI0bVTDj2Y5KVxURAqrUgA1OFVxZh9xpV5KC5N2r0DfNf1oyp 476A7DRigAup7l/JqDZ3mBw0RsPx/Oc9QosMpGLvajqsi70k6jWcqKq7BmXaKDVt oa/I2rPk6uUDFBw2t4BBJmUwszn48bPi0NuizcO9YC7NhRP1Ay4rqGBvJOmo4t4= =H/Be -----END PGP SIGNATURE----- --CGDBiGfvSTbxKZlW-- --===============0700342868274011847== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --===============0700342868274011847==--