From be6d8be91e133e98117025062df0e63aaf87efd2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 5 Dec 2014 23:13:52 +0000 Subject: py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack. mp_obj_int_get_truncated is used as a "fast path" int accessor that doesn't check for overflow and returns the int truncated to the machine word size, ie mp_int_t. Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word sized values. Addresses issues #779 and #998. --- py/binary.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'py/binary.c') diff --git a/py/binary.c b/py/binary.c index 46a4eb694..e4dac31e9 100644 --- a/py/binary.c +++ b/py/binary.c @@ -252,7 +252,12 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte ** val = (mp_uint_t)val_in; break; default: - val = mp_obj_get_int(val_in); + // we handle large ints here by calling the truncated accessor + if (MP_OBJ_IS_TYPE(val_in, &mp_type_int)) { + val = mp_obj_int_get_truncated(val_in); + } else { + val = mp_obj_get_int(val_in); + } } mp_binary_set_int(MIN(size, sizeof(val)), struct_type == '>', p, val); -- cgit v1.2.3