aboutsummaryrefslogtreecommitdiff
path: root/extmod/modure.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 /extmod/modure.c
parentcbf7674025814797f5c537d6d1c195efe58ccaaf (diff)
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 'extmod/modure.c')
-rw-r--r--extmod/modure.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/extmod/modure.c b/extmod/modure.c
index ef946ea98..5843569a5 100644
--- a/extmod/modure.c
+++ b/extmod/modure.c
@@ -53,12 +53,12 @@ typedef struct _mp_obj_match_t {
STATIC void match_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind;
- mp_obj_match_t *self = self_in;
+ mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<match num=%d>", self->num_matches);
}
STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
- mp_obj_match_t *self = self_in;
+ mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in);
mp_int_t no = mp_obj_get_int(no_in);
if (no < 0 || no >= self->num_matches) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, no_in));
@@ -83,18 +83,18 @@ STATIC const mp_obj_type_t match_type = {
{ &mp_type_type },
.name = MP_QSTR_match,
.print = match_print,
- .locals_dict = (mp_obj_t)&match_locals_dict,
+ .locals_dict = (void*)&match_locals_dict,
};
STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
(void)kind;
- mp_obj_re_t *self = self_in;
+ mp_obj_re_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<re %p>", self);
}
STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
(void)n_args;
- mp_obj_re_t *self = args[0];
+ mp_obj_re_t *self = MP_OBJ_TO_PTR(args[0]);
Subject subj;
mp_uint_t len;
subj.begin = mp_obj_str_get_data(args[1], &len);
@@ -112,7 +112,7 @@ STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
match->base.type = &match_type;
match->num_matches = caps_num / 2; // caps_num counts start and end pointers
match->str = args[1];
- return match;
+ return MP_OBJ_FROM_PTR(match);
}
STATIC mp_obj_t re_match(mp_uint_t n_args, const mp_obj_t *args) {
@@ -126,7 +126,7 @@ STATIC mp_obj_t re_search(mp_uint_t n_args, const mp_obj_t *args) {
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_search_obj, 2, 4, re_search);
STATIC mp_obj_t re_split(mp_uint_t n_args, const mp_obj_t *args) {
- mp_obj_re_t *self = args[0];
+ mp_obj_re_t *self = MP_OBJ_TO_PTR(args[0]);
Subject subj;
mp_uint_t len;
subj.begin = mp_obj_str_get_data(args[1], &len);
@@ -179,7 +179,7 @@ STATIC const mp_obj_type_t re_type = {
{ &mp_type_type },
.name = MP_QSTR_ure,
.print = re_print,
- .locals_dict = (mp_obj_t)&re_locals_dict,
+ .locals_dict = (void*)&re_locals_dict,
};
STATIC mp_obj_t mod_re_compile(mp_uint_t n_args, const mp_obj_t *args) {
@@ -202,16 +202,16 @@ error:
if (flags & FLAG_DEBUG) {
re1_5_dumpcode(&o->re);
}
- return o;
+ return MP_OBJ_FROM_PTR(o);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_re_compile_obj, 1, 2, mod_re_compile);
STATIC mp_obj_t mod_re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
(void)n_args;
- mp_obj_re_t *self = mod_re_compile(1, args);
+ mp_obj_t self = mod_re_compile(1, args);
const mp_obj_t args2[] = {self, args[1]};
- mp_obj_match_t *match = re_exec(is_anchored, 2, args2);
+ mp_obj_t match = re_exec(is_anchored, 2, args2);
return match;
}