summaryrefslogtreecommitdiff
path: root/unix/modffi.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-12-05 23:13:52 +0000
committerDamien George <damien.p.george@gmail.com>2014-12-05 23:13:52 +0000
commitbe6d8be91e133e98117025062df0e63aaf87efd2 (patch)
tree692495154f547612c148312b4abc0afc3f4a50d6 /unix/modffi.c
parent451a0870753be89f5a284fd39727705a3ad2109b (diff)
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.
Diffstat (limited to 'unix/modffi.c')
-rw-r--r--unix/modffi.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/unix/modffi.c b/unix/modffi.c
index 331219a14..6f8778929 100644
--- a/unix/modffi.c
+++ b/unix/modffi.c
@@ -211,7 +211,7 @@ STATIC void call_py_func(ffi_cif *cif, void *ret, void** args, mp_obj_t func) {
}
mp_obj_t res = mp_call_function_n_kw(func, cif->nargs, 0, pyargs);
- *(ffi_arg*)ret = mp_obj_int_get(res);
+ *(ffi_arg*)ret = mp_obj_int_get_truncated(res);
}
STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t paramtypes_in) {
@@ -313,7 +313,7 @@ mp_obj_t ffifunc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const
if (a == mp_const_none) {
values[i] = 0;
} else if (MP_OBJ_IS_INT(a)) {
- values[i] = mp_obj_int_get(a);
+ values[i] = mp_obj_int_get_truncated(a);
} else if (MP_OBJ_IS_STR(a)) {
const char *s = mp_obj_str_get_str(a);
values[i] = (ffi_arg)s;
@@ -422,7 +422,7 @@ mp_obj_t mod_ffi_open(mp_uint_t n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_ffi_open_obj, 1, 2, mod_ffi_open);
mp_obj_t mod_ffi_as_bytearray(mp_obj_t ptr, mp_obj_t size) {
- return mp_obj_new_bytearray_by_ref(mp_obj_int_get(size), (void*)mp_obj_int_get(ptr));
+ return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)mp_obj_int_get_truncated(ptr));
}
MP_DEFINE_CONST_FUN_OBJ_2(mod_ffi_as_bytearray_obj, mod_ffi_as_bytearray);