casted[0] = rffi.cast(llt, val.int_val()) def ffi_size(self): return rffi.sizeof(llt) def ffi_type(self): return ctype return GenericCInt() from rpython.rlib.rarithmetic import build_int for x in [8, 16, 32, 64]: for s in [True, False]: nm = "C" + ("" if s else "U") + "Int" + str(x) int_tp = lltype.build_number(None, build_int(nm, s, x)) ctype = clibffi.cast_type_to_ffitype(int_tp) make_itype(unicode("pixie.stdlib." + nm), ctype, int_tp) class Token(py_object): """ Tokens are returned by ffi_set_value and are called when ffi is ready to clean up resources """ def finalize_token(self): pass class CInt(CType): def __init__(self): CType.__init__(self, u"pixie.stdlib.CInt")
casted = rffi.cast(lltp, ptr) casted[0] = rffi.cast(llt, val.int_val()) def ffi_size(self): return rffi.sizeof(llt) def ffi_type(self): return ctype return GenericCInt() from rpython.rlib.rarithmetic import build_int for x in [8, 16, 32, 64]: for s in [True, False]: nm = "C" + ("" if s else "U") + "Int" + str(x) int_tp = lltype.build_number(None, build_int(nm, s, x)) ctype = clibffi.cast_type_to_ffitype(int_tp) make_itype(unicode("pixie.stdlib." + nm), ctype, int_tp) class Token(py_object): """ Tokens are returned by ffi_set_value and are called when ffi is ready to clean up resources """ def finalize_token(self): pass
""" creates necessary c-level types """ names = populate_inttypes() result = [] for name in names: tp = platform.types[name.upper()] globals()['r_' + name] = platform.numbertype_to_rclass[tp] globals()[name.upper()] = tp tpp = lltype.Ptr(lltype.Array(tp, hints={'nolength': True})) globals()[name.upper()+'P'] = tpp result.append(tp) return result NUMBER_TYPES = setup() platform.numbertype_to_rclass[lltype.Signed] = int # avoid "r_long" for common cases r_int_real = rarithmetic.build_int("r_int_real", r_int.SIGN, r_int.BITS, True) INT_real = lltype.build_number("INT", r_int_real) platform.numbertype_to_rclass[INT_real] = r_int_real NUMBER_TYPES.append(INT_real) # ^^^ this creates at least the following names: # -------------------------------------------------------------------- # Type RPython integer class doing wrap-around # -------------------------------------------------------------------- # SIGNEDCHAR r_signedchar # UCHAR r_uchar # SHORT r_short # USHORT r_ushort # INT r_int # UINT r_uint # LONG r_long
def _make_type(self, name, signed, size): inttype = rarithmetic.build_int('r_' + name, signed, size*8) tp = lltype.build_number(name, inttype) self.numbertype_to_rclass[tp] = inttype self.types[name] = tp return tp
from rpython.rlib.rarithmetic import build_int, _get_bitsize native_size = _get_bitsize('P') #I assume this works.. Int = build_int('Int', True, native_size) Int32 = build_int('Int32', True, 32) UInt32 = build_int('UInt32', False, 32) Int64 = build_int('Int64', True, 64) UInt64 = build_int('UInt64', False, 64) def Char(c='\0'): assert isinstance(c, str) return c def StrToInt64(x): ''' A simple conversion from string to Int64. Supports base16 hex-string by appending "$" to the beginning of the string. ''' int_digits = '0123456789' hex_digits = '0123456789ABCDEF' i = 0; sign = 1; if (x[i] == '-'): sign = -1; i += 1; elif (x[i] == '+'): i += 1; value = Int64(0);