Implement C long
as 64-bit on POSIX
#1918
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The size of
c_long
inctypes
was hardcoded to 32-bit, which is correct on Windows, but not correct on 64-bit GCC-compatible systems, like Linux and macOS, wherelong
is 64-bit. This is not limited toctypes
but extends to alll
andL
typecode usage (StdLib checks that size ofc_long
matches size ofstruct('l')
). For instance, here is an excerpt fromtest_fcntl
in StdLib, assuming the test runs on Linux:If
l
is 4 bytes, it will create the struct that is 8 bytes too short. The test passes because IronPython (like CPython) always reserves at least 1 KiB of the buffer for thefcntl
call and (unlike CPython) zeroes the buffer first, so that the syscall incidentally sees the proper numbers of zeros. But in a general case, if the parameters oflockdata
(struct flock
) are misalligned, the lock will not work correctly. For instancestruct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 8, 0, 0)
(lock 8 bytes from position 0) will be understood by the OS asstruct.pack('hhqqhh', fcntl.F_WRLCK, 0, 8 << 32, 0, 0, 0)
(lock 0 bytes form position 34359738368).The required change for
l
/L
to become 64-bit on some systems was surprisingly sprawling, so I tried to limit the PR to just that. But I do have similar concerns aboutn
/N
, which in CPython maps tossize_t
/size_t
, andu
which maps towchar_t
, but that is outside the scope of this PR.Side note: the changes to
_ctypes_test.c
are substantial but actually pretty simple: I reverted the file to the original version as it is in the 3.4 branch of CPython (with only small removals of CPython specific code). Apparently, at some point it got tweaked in IronPython to make the tests passing, perhaps just to work around the long-size mismatch. This is no longer necessary. However, the test code has been expanded in 3.6, afaik in a backward compatible way, so perhaps it would be worthwhile to use that version to simplify the maintenance of our 3.4 and 3.6, or just upgrade it on the 3.6 side only.