aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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')