| 1 |
:orphan: |
| 2 |
|
| 3 |
.. _windows64: |
| 4 |
|
| 5 |
64 bit PyPy and Windows |
| 6 |
======================= |
| 7 |
|
| 8 |
Getting 64-bit windows to work with PyPy was a long-standing request that was |
| 9 |
finally cracked in the otherwise cursed year of 2020. The problem is that we |
| 10 |
assume that the integer type of RPython (``rffi.SIGNED``) is |
| 11 |
large enough to (occasionally) contain a pointer value cast to an |
| 12 |
integer. On most platforms the corresponding C type of ``long`` satisfies this |
| 13 |
condition. But on 64-bit windows, a ``long`` is 32-bits, while |
| 14 |
``sizeof(void*)`` is 64-bits. The simplest fix is to make sure that |
| 15 |
``rffi.SIGNED`` can hold a 64-bit integer, which results in a python2 with the |
| 16 |
following incompatibility between CPython and PyPy on Win64: |
| 17 |
|
| 18 |
CPython: ``sys.maxint == 2**31-1, sys.maxsize == 2**63-1`` |
| 19 |
|
| 20 |
PyPy: ``sys.maxint == sys.maxsize == 2**63-1`` |
| 21 |
|
| 22 |
...and, correspondingly, PyPy2 supports ints up to the larger value of |
| 23 |
sys.maxint before they are converted to ``long``. |
| 24 |
|
| 25 |
What we did |
| 26 |
----------- |
| 27 |
|
| 28 |
The first thing done was to do hack a *CPython2* |
| 29 |
until it fits this model: replace the field in PyIntObject with a ``long |
| 30 |
long`` field, and change the value of ``sys.maxint``. This is available in |
| 31 |
`nulano's branch of cpython`_ (again: this is **python2**). |
| 32 |
|
| 33 |
This hacked python was used in the next steps. We'll call it CPython64/64. |
| 34 |
|
| 35 |
First the tests in |
| 36 |
``rpython/translator/c/test/``, like ``test_standalone.py`` and |
| 37 |
``test_newgc.py`` were made to pass on top of CPython64/64. |
| 38 |
|
| 39 |
This runs small translations, and some details were |
| 40 |
wrong. The most obvious one is to make |
| 41 |
the integer type ``Signed`` |
| 42 |
equal to ``long`` on every other platform, but on Win64 it |
| 43 |
should be something like ``long long``. |
| 44 |
|
| 45 |
Then a more generally review of all the C files in |
| 46 |
``rpython/translator/c/src`` for the word ``long``, which means a |
| 47 |
32-bit integer even on Win64, replaced it with ``Signed``. |
| 48 |
|
| 49 |
Then, these two C types have corresponding RPython types: ``rffi.LONG`` |
| 50 |
and ``lltype.Signed`` respectively. The first should really correspond |
| 51 |
to the C ``long``, as verified by the ``test_rffi_sizeof`` test. The |
| 52 |
size of the latter is verified in ``rpython/rlib/rarithmetic``. |
| 53 |
|
| 54 |
Once these basic tests worked, we reviewed ``rpython/rlib/`` for |
| 55 |
uses of ``rffi.LONG`` versus ``lltype.Signed``. The goal was to |
| 56 |
fix some more ``LONG-versus-Signed`` issues, by fixing the tests --- as |
| 57 |
always run on top of CPython64/64. Note that there was some early work |
| 58 |
done in ``rarithmetic`` with the goal of running all the |
| 59 |
tests on Win64 on the regular CPython, but this early work was abandoned as a |
| 60 |
bad idea. Look only at CPython64/64. |
| 61 |
|
| 62 |
This was enough to get a translation of PyPy with ``-O2`` |
| 63 |
with a minimal set of modules, starting with ``--no-allworkingmodules``; |
| 64 |
using CPython64/64 to run this translation too. Careful checking of |
| 65 |
the warnings of the C compiler at the end revealed more places that needed |
| 66 |
work. By default, MSVC |
| 67 |
reports a lot of mismatches of integer sizes as warnings instead of |
| 68 |
errors. |
| 69 |
|
| 70 |
Then we reviewed ``pypy/module/*/`` for ``LONG-versus-Signed`` |
| 71 |
issues. This got us a working translated |
| 72 |
PyPy on Windows 64 that includes all ``--translationmodules``, i.e. |
| 73 |
everything needed to run translations. Once we had that, the hacked |
| 74 |
CPython64/64 becomes much less important, because we can run future |
| 75 |
translations on top of this translated PyPy. This made it to the nightly |
| 76 |
builds on the default branch, and needs to be used by anyone else who wants to |
| 77 |
working on Win64. The whole process |
| 78 |
ends up with a strange kind of dependency --- we need a translated PyPy in |
| 79 |
order to translate a PyPy ---, but that's ok here, as Windows executables are |
| 80 |
supposed to never be broken by newer versions of Windows. |
| 81 |
|
| 82 |
Happy hacking :-) |
| 83 |
|
| 84 |
.. _`nulano's branch of cpython`: https://github.com/nulano/cpython |
| 85 |
.. |