summaryrefslogtreecommitdiffstatshomepage
path: root/unix/moduselect.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/moduselect.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/moduselect.c')
-rw-r--r--unix/moduselect.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/unix/moduselect.c b/unix/moduselect.c
index 41255ff904..0d06cc5309 100644
--- a/unix/moduselect.c
+++ b/unix/moduselect.c
@@ -46,7 +46,7 @@ typedef struct _mp_obj_poll_t {
/// \method register(obj[, eventmask])
STATIC mp_obj_t poll_register(uint n_args, const mp_obj_t *args) {
- mp_obj_poll_t *self = args[0];
+ mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]);
mp_uint_t flags;
if (n_args == 3) {
flags = mp_obj_get_int(args[2]);
@@ -79,7 +79,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_register_obj, 2, 3, poll_register);
/// \method unregister(obj)
STATIC mp_obj_t poll_unregister(mp_obj_t self_in, mp_obj_t obj_in) {
- mp_obj_poll_t *self = self_in;
+ mp_obj_poll_t *self = MP_OBJ_TO_PTR(self_in);
struct pollfd *entries = self->entries;
int fd = mp_obj_get_int(obj_in);
for (int i = self->len - 1; i >= 0; i--) {
@@ -97,7 +97,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(poll_unregister_obj, poll_unregister);
/// \method modify(obj, eventmask)
STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmask_in) {
- mp_obj_poll_t *self = self_in;
+ mp_obj_poll_t *self = MP_OBJ_TO_PTR(self_in);
struct pollfd *entries = self->entries;
int fd = mp_obj_get_int(obj_in);
for (int i = self->len - 1; i >= 0; i--) {
@@ -116,7 +116,7 @@ MP_DEFINE_CONST_FUN_OBJ_3(poll_modify_obj, poll_modify);
/// \method poll([timeout])
/// Timeout is in milliseconds.
STATIC mp_obj_t poll_poll(uint n_args, const mp_obj_t *args) {
- mp_obj_poll_t *self = args[0];
+ mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]);
// work out timeout (its given already in ms)
int timeout = -1;
@@ -135,19 +135,19 @@ STATIC mp_obj_t poll_poll(uint n_args, const mp_obj_t *args) {
return mp_const_empty_tuple;
}
- mp_obj_list_t *ret_list = mp_obj_new_list(n_ready, NULL);
+ mp_obj_list_t *ret_list = MP_OBJ_TO_PTR(mp_obj_new_list(n_ready, NULL));
int ret_i = 0;
struct pollfd *entries = self->entries;
for (int i = 0; i < self->len; i++, entries++) {
if (entries->revents != 0) {
- mp_obj_tuple_t *t = mp_obj_new_tuple(2, NULL);
+ mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(2, NULL));
t->items[0] = MP_OBJ_NEW_SMALL_INT(entries->fd);
t->items[1] = MP_OBJ_NEW_SMALL_INT(entries->revents);
- ret_list->items[ret_i++] = t;
+ ret_list->items[ret_i++] = MP_OBJ_FROM_PTR(t);
}
}
- return ret_list;
+ return MP_OBJ_FROM_PTR(ret_list);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_poll_obj, 1, 2, poll_poll);
@@ -162,7 +162,7 @@ STATIC MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table);
STATIC const mp_obj_type_t mp_type_poll = {
{ &mp_type_type },
.name = MP_QSTR_poll,
- .locals_dict = (mp_obj_t)&poll_locals_dict,
+ .locals_dict = (void*)&poll_locals_dict,
};
STATIC mp_obj_t select_poll(mp_uint_t n_args, const mp_obj_t *args) {
@@ -175,7 +175,7 @@ STATIC mp_obj_t select_poll(mp_uint_t n_args, const mp_obj_t *args) {
poll->entries = m_new(struct pollfd, alloc);
poll->alloc = alloc;
poll->len = 0;
- return poll;
+ return MP_OBJ_FROM_PTR(poll);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_poll_obj, 0, 1, select_poll);