aboutsummaryrefslogtreecommitdiff
path: root/py/lexer.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-09-19 11:17:02 +1000
committerDamien George <damien.p.george@gmail.com>2016-09-19 12:28:55 +1000
commit5da0d29d3cefa6a3cac52e0db96e9ede820d6a51 (patch)
treecf39b02347b40016088c907cd2e1b3aaada8b653 /py/lexer.c
parentadaf0d865cd6c81fb352751566460506392ed55f (diff)
py/vstr: Remove vstr.had_error flag and inline basic vstr functions.
The vstr.had_error flag was a relic from the very early days which assumed that the malloc functions (eg m_new, m_renew) returned NULL if they failed to allocate. But that's no longer the case: these functions will raise an exception if they fail. Since it was impossible for had_error to be set, this patch introduces no change in behaviour. An alternative option would be to change the malloc calls to the _maybe variants, which return NULL instead of raising, but then a lot of code will need to explicitly check if the vstr had an error and raise if it did. The code-size savings for this patch are, in bytes: bare-arm:188, minimal:456, unix(NDEBUG,x86-64):368, stmhal:228, esp8266:360.
Diffstat (limited to 'py/lexer.c')
-rw-r--r--py/lexer.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/py/lexer.c b/py/lexer.c
index 820f91be7..b2c9c5ff7 100644
--- a/py/lexer.c
+++ b/py/lexer.c
@@ -723,7 +723,8 @@ mp_lexer_t *mp_lexer_new(qstr src_name, void *stream_data, mp_lexer_stream_next_
vstr_init(&lex->vstr, 32);
// check for memory allocation error
- if (lex->indent_level == NULL || vstr_had_error(&lex->vstr)) {
+ // note: vstr_init above may fail on malloc, but so may mp_lexer_next_token_into below
+ if (lex->indent_level == NULL) {
mp_lexer_free(lex);
return NULL;
}