Author: Armin Rigo <ar...@tunes.org> Branch: ffi-backend Changeset: r55782:aae0f822a3aa Date: 2012-06-23 16:12 +0200 http://bitbucket.org/pypy/pypy/changeset/aae0f822a3aa/
Log: Overflow. diff --git a/pypy/module/_ffi_backend/ctypeobj.py b/pypy/module/_ffi_backend/ctypeobj.py --- a/pypy/module/_ffi_backend/ctypeobj.py +++ b/pypy/module/_ffi_backend/ctypeobj.py @@ -263,6 +263,12 @@ w_cdata.write_raw_integer_data(value) return w_cdata + def _overflow(self, w_ob): + space = self.space + s = space.str_w(space.str(w_ob)) + raise operationerrfmt(space.w_OverflowError, + "integer %s does not fit '%s'", s, self.name) + class W_CTypePrimitiveChar(W_CTypePrimitive): @@ -319,8 +325,12 @@ def convert_from_object(self, cdata, w_ob): value = misc.as_long_long(self.space, w_ob) # xxx enums + if self.value_fits_long: + vmin = (-1) << (self.size * 8 - 1) + vmax = ~vmin + if not (vmin <= value <= vmax): + self._overflow(w_ob) misc.write_raw_integer_data(cdata, value, self.size) - # xxx overflow class W_CTypePrimitiveUnsigned(W_CTypePrimitive): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit