aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Lamy <ronan.lamy@gmail.com>2020-05-27 17:57:16 +0100
committerRonan Lamy <ronan.lamy@gmail.com>2020-05-27 17:57:16 +0100
commite34131d29b83fc6158f279b594a8b6a19bb0f6c7 (patch)
tree6533cb3767f118f18d6854ec2c6380ff6963aa75 /lib_pypy
parentUpdate _ctypes_test to 2.7.18 (diff)
downloadpypy-e34131d29b83fc6158f279b594a8b6a19bb0f6c7.tar.gz
pypy-e34131d29b83fc6158f279b594a8b6a19bb0f6c7.tar.bz2
pypy-e34131d29b83fc6158f279b594a8b6a19bb0f6c7.zip
Ensure correct PEP3118 codes for primitive ctypes types (cf. bpo-10746)
Diffstat (limited to 'lib_pypy')
-rw-r--r--lib_pypy/_ctypes/primitive.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
index 84e7f4364c..3a2146d10e 100644
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -146,6 +146,14 @@ FROM_PARAM_BY_TYPE = {
'P': from_param_void_p,
}
+CTYPES_TO_PEP3118_TABLE = {
+ 'i': {2: 'h', 4: 'i', 8: 'q'},
+ 'I': {2: 'H', 4: 'I', 8: 'Q'},
+ 'l': {4: 'l', 8: 'q'},
+ 'L': {4: 'L', 8: 'Q'},
+ '?': {1: '?', 2: 'h', 4: 'l', 8: 'q'},
+}
+
class SimpleType(_CDataMeta):
def __new__(self, name, bases, dct):
try:
@@ -168,7 +176,11 @@ class SimpleType(_CDataMeta):
result._ffishape_ = tp
result._fficompositesize_ = None
result._ffiarray = ffiarray
- result._format = byteorder[sys.byteorder] + tp
+ if tp in CTYPES_TO_PEP3118_TABLE:
+ pep_code = CTYPES_TO_PEP3118_TABLE[tp][_rawffi.sizeof(tp)]
+ else:
+ pep_code = tp
+ result._format = byteorder[sys.byteorder] + pep_code
if tp == 'z':
# c_char_p
def _getvalue(self):
@@ -328,7 +340,7 @@ class SimpleType(_CDataMeta):
result.__ctype_be__ = result
swapped.__ctype_be__ = result
swapped.__ctype_le__ = swapped
- swapped._format = '<' + tp
+ swapped._format = '<' + pep_code
else:
name += '_be'
swapped = self.__new__(self, name, bases, dct)
@@ -336,7 +348,7 @@ class SimpleType(_CDataMeta):
result.__ctype_le__ = result
swapped.__ctype_le__ = result
swapped.__ctype_be__ = swapped
- swapped._format = '>' + tp
+ swapped._format = '>' + pep_code
from _ctypes import sizeof
def _getval(self):
return swap_bytes(self._buffer[0], sizeof(self), name, 'get')