def convert_from_object(self, cdata, w_ob): if self.value_fits_ulong: value = misc.as_unsigned_long(self.space, w_ob, strict=True) if self.value_fits_long: if value > self.vrangemax: self._overflow(w_ob) misc.write_raw_unsigned_data(cdata, value, self.size) else: self._convert_from_object_longlong(cdata, w_ob)
def cast(self, w_ob): # cast to a pointer, to a funcptr, or to an array. # Note that casting to an array is an extension to the C language, # which seems to be necessary in order to sanely get a # <cdata 'int[3]'> at some address. if self.size < 0: return W_CType.cast(self, w_ob) space = self.space if (isinstance(w_ob, cdataobj.W_CData) and isinstance(w_ob.ctype, W_CTypePtrOrArray)): value = w_ob.unsafe_escaping_ptr() else: value = misc.as_unsigned_long(space, w_ob, strict=False) value = rffi.cast(rffi.CCHARP, value) return cdataobj.W_CData(space, value, self)
def cast(self, w_ob): # cast to a pointer, to a funcptr, or to an array. # Note that casting to an array is an extension to the C language, # which seems to be necessary in order to sanely get a # <cdata 'int[3]'> at some address. if self.size < 0: return W_CType.cast(self, w_ob) space = self.space if (isinstance(w_ob, cdataobj.W_CData) and isinstance(w_ob.ctype, W_CTypePtrOrArray)): value = w_ob._cdata else: value = misc.as_unsigned_long(space, w_ob, strict=False) value = rffi.cast(rffi.CCHARP, value) return cdataobj.W_CData(space, value, self)