def sizeof(tp): """Similar to llmemory.sizeof() but tries hard to return a integer instead of a symbolic value. """ if isinstance(tp, lltype.Typedef): tp = tp.OF if isinstance(tp, lltype.FixedSizeArray): return sizeof(tp.OF) * tp.length if isinstance(tp, lltype.Struct): # the hint is present in structures probed by rffi_platform. size = tp._hints.get('size') if size is None: size = llmemory.sizeof(tp) # a symbolic result in this case return size if isinstance(tp, lltype.Ptr) or tp is llmemory.Address: return globals()['r_void*'].BITS/8 if tp is lltype.Char or tp is lltype.Bool: return 1 if tp is lltype.UniChar: return r_wchar_t.BITS/8 if tp is lltype.Float: return 8 if tp is lltype.SingleFloat: return 4 if tp is lltype.LongFloat: # :-/ return sizeof_c_type("long double") assert isinstance(tp, lltype.Number) if tp is lltype.Signed: return LONG_BIT/8 return tp._type.BITS/8
# ____________________________________________________________ TYPES = [] for _name in 'short int long'.split(): for name in (_name, 'unsigned ' + _name): TYPES.append(name) TYPES += ['signed char', 'unsigned char', 'long long', 'unsigned long long', 'size_t', 'time_t', 'wchar_t', 'uintptr_t', 'intptr_t', 'void*'] # generic pointer type # This is a bit of a hack since we can't use rffi_platform here. try: sizeof_c_type('__int128_t', ignore_errors=True) TYPES += ['__int128_t'] except CompilationError: pass _TYPES_ARE_UNSIGNED = set(['size_t', 'uintptr_t']) # plus "unsigned *" if os.name != 'nt': TYPES.append('mode_t') TYPES.append('pid_t') TYPES.append('ssize_t') else: MODE_T = lltype.Signed PID_T = lltype.Signed SSIZE_T = lltype.Signed def populate_inttypes():
# ____________________________________________________________ TYPES = [] for _name in 'short int long'.split(): for name in (_name, 'unsigned ' + _name): TYPES.append(name) TYPES += ['signed char', 'unsigned char', 'long long', 'unsigned long long', 'size_t', 'time_t', 'wchar_t', 'uintptr_t', 'intptr_t', 'void*'] # generic pointer type # This is a bit of a hack since we can't use rffi_platform here. try: sizeof_c_type('__int128_t', ignore_errors=True) TYPES += ['__int128_t'] except CompilationError: pass if os.name != 'nt': TYPES.append('mode_t') TYPES.append('pid_t') TYPES.append('ssize_t') # the types below are rare enough and not available on Windows TYPES.extend(['ptrdiff_t', 'int_least8_t', 'uint_least8_t', 'int_least16_t', 'uint_least16_t', 'int_least32_t', 'uint_least32_t', 'int_least64_t', 'uint_least64_t', 'int_fast8_t', 'uint_fast8_t',
'n': { 'size': 2, 'pack': pack_int, 'unpack': unpack_int, 'bigendian': True, 'many_args': True, }, 'v': { 'size': 2, 'pack': pack_int, 'unpack': unpack_int, 'bigendian': False, 'many_args': True, }, 'i': { 'size': sizeof_c_type('unsigned int'), 'pack': pack_int, 'unpack': unpack_int, 'signed': True, 'many_args': True, }, 'I': { 'size': 4, 'pack': pack_int, 'unpack': unpack_int, 'many_args': True, }, 'l': { 'size': 4, 'pack': pack_int, 'unpack': unpack_int,