GNOME Bugzilla – Bug 701600
Port to Python3
Last modified: 2021-07-05 11:00:35 UTC
https://live.gnome.org/GnomeGoals/Python3Porting Package isn't listed there, but the external links for porting should be useful. Python3 is out for a while and it would be nice to port this package to support it.
Created attachment 246022 [details] [review] Port to Python 3
Created attachment 246023 [details] [review] Convert Tests to Python 3
Okay I will look, but the patches should be closely modeled against the equivalent patches I made for libxml2. Did you reuse the set of patches from libxml2 or is that completely new work from you ? thanks, Daniel
Created attachment 246026 [details] [review] Port Tests to Python 3
As I said, I've mostly looked at libxml2 work and applied it to libxslt files. I don't know Python or Python C bindings to do it on my own. Any modifications welcome. I am unable to do anything else because I don't know.
Ahh, okay :-) I was lacking time mostly ... and I will have to do libvirt too at some point, thanks for the help, I will try to allocate time for this, unlikely this week, maybe later in the month, thanks ! Daniel
Also interested in this and started writing my own patch before finding this item. Some points on the patch: 1. I am a bit confused about this bit of code: @@ -689,14 +698,23 @@ libxslt_xsltApplyStylesheetUser(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) j = 0; while (PyDict_Next(pyobj_params, &ppos, &name, &value)) { const char *tmp; - int size; - - tmp = PyString_AS_STRING(name); - size = PyString_GET_SIZE(name); - params[j * 2] = (char *) xmlCharStrndup(tmp, size); - if (PyString_Check(value)) { - tmp = PyString_AS_STRING(value); - size = PyString_GET_SIZE(value); + Py_ssize_t size; + +#if PY_VERSION_HEX >= 0x03030000 + tmp = PyUnicode_AsUTF8AndSize(name, &size); + params[j * 2] = (char *) xmlCharStrndup(tmp, (int) size); +#else + PyObject *b; + b = PyUnicode_AsUTF8String(name); + if (b != NULL) { + params[j * 2] = (char *) xmlCharStrndup(PyBytes_AS_STRING(b), + PyBytes_GET_SIZE(b)); + Py_DECREF(b); + } +#endif + if (PyBytes_Check(value)) { + tmp = PyBytes_AS_STRING(value); + size = PyBytes_GET_SIZE(value); params[(j * 2) + 1] = (char *) xmlCharStrndup(tmp, size); } else { PyUnicode_AsUTF8String is used on name for all python < 3.3. For Python 2.x, that will break existing functionality where the caller was passing a str (i.e. everybody, because that's what it previously took). It also changes the type of value to bytes for all versions, which breaks python 2.7 callers passing str, and python 3.x callers which are presumably expecting to pass unicode. I would have thought that this code would be unmodified for python 2.x and support unicode for 3.x. 2. I think this should use PY_IMPORT_INT @@ -417,13 +483,13 @@ libxml_xmlXPathObjectPtrWrap(xmlXPathObjectPtr obj) } break; case XPATH_BOOLEAN: - ret = PyInt_FromLong((long) obj->boolval); + ret = PyLong_FromLong((long) obj->boolval);
Again, as said in comment 5, I did mirror what libxml2 did at that time. I have no knowledge of Python. Feel free to take this patch and improve it as needed.
Wow thanks for the quick response, I was not expecting that after 18 months! To be clear, the patch is a much better start than the tiny amount I had. I may have time to submit a revision next week.
I don't want to hijack this thread but since various distributions have been shipping with patches for Python 3 compatibility there is now an additional one required to work with the recently released Python 3.6: http://pkgs.fedoraproject.org/cgit/rpms/libxml2.git/tree/libxml2-2.9.4-remove-pyverify_fd.patch https://bugzilla.redhat.com/show_bug.cgi?id=1406920
(In reply to Timo Gurr from comment #10) > I don't want to hijack this thread but since various distributions have been > shipping with patches for Python 3 compatibility there is now an additional > one required to work with the recently released Python 3.6: > > http://pkgs.fedoraproject.org/cgit/rpms/libxml2.git/tree/libxml2-2.9.4- > remove-pyverify_fd.patch > > https://bugzilla.redhat.com/show_bug.cgi?id=1406920 Replying to myself I just noticed the product of this bug is libxslt and not libxml2 which I searched for, my bad, sorry for the unnecessary noise!
GNOME is going to shut down bugzilla.gnome.org in favor of gitlab.gnome.org. As part of that, we are mass-closing older open tickets in bugzilla.gnome.org which have not seen updates for a longer time (resources are unfortunately quite limited so not every ticket can get handled). If you can still reproduce the situation described in this ticket in a recent and supported software version, then please follow https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines and create a new ticket at https://gitlab.gnome.org/GNOME/libxslt/-/issues/ Thank you for your understanding and your help.