py/viper: Truncate viper integer args so they can be up to 32-bit.

This commit is contained in:
Damien George 2016-01-07 16:48:20 +00:00
parent daa1a455c6
commit dd0a0f79d7

View File

@ -48,14 +48,13 @@ mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type) {
switch (type & 3) { switch (type & 3) {
case MP_NATIVE_TYPE_OBJ: return (mp_uint_t)obj; case MP_NATIVE_TYPE_OBJ: return (mp_uint_t)obj;
case MP_NATIVE_TYPE_BOOL: case MP_NATIVE_TYPE_BOOL:
case MP_NATIVE_TYPE_INT: return mp_obj_get_int(obj); case MP_NATIVE_TYPE_INT: return mp_obj_get_int_truncated(obj);
case MP_NATIVE_TYPE_UINT: { case MP_NATIVE_TYPE_UINT: {
mp_buffer_info_t bufinfo; mp_buffer_info_t bufinfo;
if (mp_get_buffer(obj, &bufinfo, MP_BUFFER_RW)) { if (mp_get_buffer(obj, &bufinfo, MP_BUFFER_RW)) {
return (mp_uint_t)bufinfo.buf; return (mp_uint_t)bufinfo.buf;
} else { } else {
// TODO should be mp_obj_get_uint_truncated or something return mp_obj_get_int_truncated(obj);
return mp_obj_get_int(obj);
} }
} }
default: assert(0); return 0; default: assert(0); return 0;