summaryrefslogtreecommitdiffstatshomepage
path: root/unix/modffi.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-11-27 17:01:44 +0000
committerDamien George <damien.p.george@gmail.com>2015-11-29 14:25:35 +0000
commit999cedb90ff0827cdb9dfe0e4faa6ebc1739d271 (patch)
tree897eb07b82f1893cfd413b9ef7f625cd996f859d /unix/modffi.c
parentcbf7674025814797f5c537d6d1c195efe58ccaaf (diff)
downloadmicropython-999cedb90ff0827cdb9dfe0e4faa6ebc1739d271.tar.gz
micropython-999cedb90ff0827cdb9dfe0e4faa6ebc1739d271.zip
py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.
This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
Diffstat (limited to 'unix/modffi.c')
-rw-r--r--unix/modffi.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/unix/modffi.c b/unix/modffi.c
index 48834fb739..c998a809e4 100644
--- a/unix/modffi.c
+++ b/unix/modffi.c
@@ -170,12 +170,12 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
STATIC void ffimod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind;
- mp_obj_ffimod_t *self = self_in;
+ mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<ffimod %p>", self->handle);
}
STATIC mp_obj_t ffimod_close(mp_obj_t self_in) {
- mp_obj_ffimod_t *self = self_in;
+ mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in);
dlclose(self->handle);
return mp_const_none;
}
@@ -205,12 +205,12 @@ STATIC mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in)
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Error in ffi_prep_cif"));
}
- return o;
+ return MP_OBJ_FROM_PTR(o);
}
STATIC mp_obj_t ffimod_func(mp_uint_t n_args, const mp_obj_t *args) {
(void)n_args; // always 4
- mp_obj_ffimod_t *self = args[0];
+ mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(args[0]);
const char *symname = mp_obj_str_get_str(args[2]);
void *sym = dlsym(self->handle, symname);
@@ -222,7 +222,7 @@ STATIC mp_obj_t ffimod_func(mp_uint_t n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ffimod_func_obj, 4, 4, ffimod_func);
STATIC mp_obj_t mod_ffi_func(mp_obj_t rettype, mp_obj_t addr_in, mp_obj_t argtypes) {
- void *addr = (void*)mp_obj_int_get_truncated(addr_in);
+ void *addr = (void*)MP_OBJ_TO_PTR(mp_obj_int_get_truncated(addr_in));
return make_func(rettype, addr, argtypes);
}
MP_DEFINE_CONST_FUN_OBJ_3(mod_ffi_func_obj, mod_ffi_func);
@@ -267,12 +267,12 @@ STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "ffi_prep_closure_loc"));
}
- return o;
+ return MP_OBJ_FROM_PTR(o);
}
MP_DEFINE_CONST_FUN_OBJ_3(mod_ffi_callback_obj, mod_ffi_callback);
STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symname_in) {
- mp_obj_ffimod_t *self = self_in;
+ mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in);
const char *rettype = mp_obj_str_get_str(vartype_in);
const char *symname = mp_obj_str_get_str(symname_in);
@@ -285,12 +285,12 @@ STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symna
o->var = sym;
o->type = *rettype;
- return o;
+ return MP_OBJ_FROM_PTR(o);
}
MP_DEFINE_CONST_FUN_OBJ_3(ffimod_var_obj, ffimod_var);
STATIC mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) {
- mp_obj_ffimod_t *self = self_in;
+ mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in);
const char *symname = mp_obj_str_get_str(symname_in);
void *sym = dlsym(self->handle, symname);
@@ -315,9 +315,9 @@ STATIC mp_obj_t ffimod_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno)));
}
mp_obj_ffimod_t *o = m_new_obj(mp_obj_ffimod_t);
- o->base.type = type_in;
+ o->base.type = MP_OBJ_TO_PTR(type_in);
o->handle = mod;
- return o;
+ return MP_OBJ_FROM_PTR(o);
}
STATIC const mp_rom_map_elem_t ffimod_locals_dict_table[] = {
@@ -334,19 +334,19 @@ STATIC const mp_obj_type_t ffimod_type = {
.name = MP_QSTR_ffimod,
.print = ffimod_print,
.make_new = ffimod_make_new,
- .locals_dict = (mp_obj_t)&ffimod_locals_dict,
+ .locals_dict = (mp_obj_dict_t*)&ffimod_locals_dict,
};
// FFI function
STATIC void ffifunc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind;
- mp_obj_ffifunc_t *self = self_in;
+ mp_obj_ffifunc_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<ffifunc %p>", self->func);
}
STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
- mp_obj_ffifunc_t *self = self_in;
+ mp_obj_ffifunc_t *self = MP_OBJ_TO_PTR(self_in);
assert(n_kw == 0);
assert(n_args == self->cif.nargs);