[Pyrex] Migration to Py 2.5: Py_ssize_t and exceptions

Stefan Behnel behnel_ml at gkec.informatik.tu-darmstadt.de
Tue Apr 25 13:04:21 CEST 2006


Hi,

as many of you will know by now, Python 2.5 introduces the "Py_ssize_t" type
to replace "int" for indices.

http://www.python.org/dev/peps/pep-0353/

This means that Pyrex will have to support it if it wants to continue working
on 64-bit machines. I wrote a preliminary patch that adds support for that
type as well as conversion from/to int's and Python numbers.

Note that it defines "PY_SSIZE_T_CLEAN", which changes the behaviour of
certain Python API functions (including function argument unpacking) under
Python 2.5 on 64-bit machines. However, since old source code is broken in
this environment anyway, this should not introduce more crashes than the code
itself does.

I updated the lxml source to work (more or less) with Python 2.5a1 and it
compiles with both Python 2.4 and 2.5 without problems. So, it's currently a
"works for me".

Note that I couldn't actually test sufficiently large input (>2GB) to see if
it really works as expected. However, the generated C code looks good and the
compiler does not complain.

The second problem regards exception handling. In Py2.5, exceptions are
newstyle classes, i.e. of type "type" and not type "class". Pyrex generates an
exception for these. The fix is also in the attached patch:

Index: Pyrex/Compiler/Nodes.py
===================================================================
--- Pyrex/Compiler/Nodes.py     (Revision 131)
+++ Pyrex/Compiler/Nodes.py     (Arbeitskopie)
@@ -3650,7 +3658,7 @@
     }
     if (PyString_Check(type))
         ;
-    else if (PyClass_Check(type))
+    else if (PyType_Check(type) || PyClass_Check(type))
         ; /*PyErr_NormalizeException(&type, &value, &tb);*/
     else if (PyInstance_Check(type)) {
         /* Raising an instance.  The value should be a dummy. */


I hope these two changes do not break anything for earlier Python versions so
that they can be integrated into a not-too-far-away Pyrex version.

Regards,
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Py2.5.patch
Type: text/x-patch
Size: 14579 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20060425/175c3643/Py2.5.bin


More information about the Pyrex mailing list