summaryrefslogtreecommitdiff
path: root/extmod/modure.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-08-17 23:50:19 +1000
committerDamien George <damien.p.george@gmail.com>2019-08-19 16:43:00 +1000
commit7d851a27f146188752e89bb026021fb8d3985395 (patch)
tree3af741a441e5c3158afc309f379583f41e52733c /extmod/modure.c
parent3a679eaf00b909980ad38344ec0c7395adcd0564 (diff)
extmod/modure: Make regex dump-code debugging feature optional.
Enabled via MICROPY_PY_URE_DEBUG, disabled by default (but enabled on unix coverage build). This is a rarely used feature that costs a lot of code (500-800 bytes flash). Debugging of regular expressions can be done offline with other tools.
Diffstat (limited to 'extmod/modure.c')
-rw-r--r--extmod/modure.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/extmod/modure.c b/extmod/modure.c
index 0d5330cb5..8a6020705 100644
--- a/extmod/modure.c
+++ b/extmod/modure.c
@@ -382,6 +382,7 @@ STATIC const mp_obj_type_t re_type = {
};
STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
+ (void)n_args;
const char *re_str = mp_obj_str_get_str(args[0]);
int size = re1_5_sizecode(re_str);
if (size == -1) {
@@ -389,18 +390,22 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) {
}
mp_obj_re_t *o = m_new_obj_var(mp_obj_re_t, char, size);
o->base.type = &re_type;
+ #if MICROPY_PY_URE_DEBUG
int flags = 0;
if (n_args > 1) {
flags = mp_obj_get_int(args[1]);
}
+ #endif
int error = re1_5_compilecode(&o->re, re_str);
if (error != 0) {
error:
mp_raise_ValueError("Error in regex");
}
+ #if MICROPY_PY_URE_DEBUG
if (flags & FLAG_DEBUG) {
re1_5_dumpcode(&o->re);
}
+ #endif
return MP_OBJ_FROM_PTR(o);
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_re_compile_obj, 1, 2, mod_re_compile);
@@ -440,7 +445,9 @@ STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = {
#if MICROPY_PY_URE_SUB
{ MP_ROM_QSTR(MP_QSTR_sub), MP_ROM_PTR(&mod_re_sub_obj) },
#endif
+ #if MICROPY_PY_URE_DEBUG
{ MP_ROM_QSTR(MP_QSTR_DEBUG), MP_ROM_INT(FLAG_DEBUG) },
+ #endif
};
STATIC MP_DEFINE_CONST_DICT(mp_module_re_globals, mp_module_re_globals_table);
@@ -455,7 +462,9 @@ const mp_obj_module_t mp_module_ure = {
#define re1_5_fatal(x) assert(!x)
#include "re1.5/compilecode.c"
+#if MICROPY_PY_URE_DEBUG
#include "re1.5/dumpcode.c"
+#endif
#include "re1.5/recursiveloop.c"
#include "re1.5/charclass.c"