summaryrefslogtreecommitdiffstatshomepage
path: root/unix
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-14 17:16:35 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-02-14 20:38:35 +0200
commit8bc3516389cd148ebeaa58ceaf3d3f7fb13440d8 (patch)
tree11b747322a7d8c03d476914d57fd86725f886a12 /unix
parent70d7a83c74812a517ef0489877becb075d164630 (diff)
downloadmicropython-8bc3516389cd148ebeaa58ceaf3d3f7fb13440d8.tar.gz
micropython-8bc3516389cd148ebeaa58ceaf3d3f7fb13440d8.zip
ffi: Implement ffivar.get()/set() methods.
Done by introducing another factored out helper API in binary.c. This API can be reused also by array and struct modules.
Diffstat (limited to 'unix')
-rw-r--r--unix/ffi.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/unix/ffi.c b/unix/ffi.c
index b83fc120a9..a82e4e3386 100644
--- a/unix/ffi.c
+++ b/unix/ffi.c
@@ -10,6 +10,7 @@
#include "qstr.h"
#include "obj.h"
#include "runtime.h"
+#include "binary.h"
typedef struct _mp_obj_opaque_t {
mp_obj_base_t base;
@@ -295,10 +296,30 @@ static void ffivar_print(void (*print)(void *env, const char *fmt, ...), void *e
print(env, "<ffivar @%p: 0x%x>", self->var, *(int*)self->var);
}
+static mp_obj_t ffivar_get(mp_obj_t self_in) {
+ mp_obj_ffivar_t *self = self_in;
+ return mp_binary_get_val(self->type, self->var, 0);
+}
+MP_DEFINE_CONST_FUN_OBJ_1(ffivar_get_obj, ffivar_get);
+
+static mp_obj_t ffivar_set(mp_obj_t self_in, mp_obj_t val_in) {
+ mp_obj_ffivar_t *self = self_in;
+ mp_binary_set_val(self->type, self->var, 0, val_in);
+ return mp_const_none;
+}
+MP_DEFINE_CONST_FUN_OBJ_2(ffivar_set_obj, ffivar_set);
+
+static const mp_method_t ffivar_type_methods[] = {
+ { "get", &ffivar_get_obj },
+ { "set", &ffivar_set_obj },
+ { NULL, NULL },
+};
+
static const mp_obj_type_t ffivar_type = {
{ &mp_const_type },
"ffivar",
.print = ffivar_print,
+ .methods = ffivar_type_methods,
};
// Generic opaque storage object