diff --git a/unix/modffi.c b/unix/modffi.c
index 253672390cd66afaf41d540ead5f23c4899aaa0b..b6c2bf4e3a2ab76c0f0f24fd02f11525c30f6d07 100644
--- a/unix/modffi.c
+++ b/unix/modffi.c
@@ -30,6 +30,7 @@
 #include <errno.h>
 #include <dlfcn.h>
 #include <ffi.h>
+#include <stdint.h>
 
 #include "py/nlr.h"
 #include "py/runtime.h"
@@ -140,7 +141,7 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
 {
     switch (type) {
         case 's': {
-            const char *s = (const char *)val;
+            const char *s = (const char *)(intptr_t)val;
             if (!s) {
                 return mp_const_none;
             }
@@ -159,7 +160,7 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
         }
         #endif
         case 'O':
-            return (mp_obj_t)val;
+            return (mp_obj_t)(intptr_t)val;
         default:
             return mp_obj_new_int(val);
     }
@@ -355,7 +356,7 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw,
     for (uint i = 0; i < n_args; i++, argtype++) {
         mp_obj_t a = args[i];
         if (*argtype == 'O') {
-            values[i] = (ffi_arg)a;
+            values[i] = (ffi_arg)(intptr_t)a;
         #if MICROPY_PY_BUILTINS_FLOAT
         } else if (*argtype == 'f') {
             float *p = (float*)&values[i];
@@ -370,7 +371,7 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw,
             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;
+            values[i] = (ffi_arg)(intptr_t)s;
         } else if (((mp_obj_base_t*)a)->type->buffer_p.get_buffer != NULL) {
             mp_obj_base_t *o = (mp_obj_base_t*)a;
             mp_buffer_info_t bufinfo;
@@ -378,10 +379,10 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw,
             if (ret != 0) {
                 goto error;
             }
-            values[i] = (ffi_arg)bufinfo.buf;
+            values[i] = (ffi_arg)(intptr_t)bufinfo.buf;
         } else if (MP_OBJ_IS_TYPE(a, &fficallback_type)) {
             mp_obj_fficallback_t *p = a;
-            values[i] = (ffi_arg)p->func;
+            values[i] = (ffi_arg)(intptr_t)p->func;
         } else {
             goto error;
         }