Merge branch 'dhylands-lexer-crash'

This commit is contained in:
Damien George 2014-10-09 16:54:03 +01:00
commit f0f964807e
5 changed files with 14 additions and 4 deletions

View File

@ -731,7 +731,7 @@ STATIC void mp_lexer_next_token_into(mp_lexer_t *lex, mp_token_t *tok, bool firs
}
mp_lexer_t *mp_lexer_new(qstr src_name, void *stream_data, mp_lexer_stream_next_byte_t stream_next_byte, mp_lexer_stream_close_t stream_close) {
mp_lexer_t *lex = m_new_maybe(mp_lexer_t, 1);
mp_lexer_t *lex = m_new_obj_maybe(mp_lexer_t);
// check for memory allocation error
if (lex == NULL) {

View File

@ -52,7 +52,10 @@ STATIC void str_buf_free(mp_lexer_str_buf_t *sb) {
}
mp_lexer_t *mp_lexer_new_from_str_len(qstr src_name, const char *str, mp_uint_t len, mp_uint_t free_len) {
mp_lexer_str_buf_t *sb = m_new_obj(mp_lexer_str_buf_t);
mp_lexer_str_buf_t *sb = m_new_obj_maybe(mp_lexer_str_buf_t);
if (sb == NULL) {
return NULL;
}
sb->free_len = free_len;
sb->src_beg = str;
sb->src_cur = str;

View File

@ -69,7 +69,10 @@ STATIC void file_buf_close(mp_lexer_file_buf_t *fb) {
}
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
mp_lexer_file_buf_t *fb = m_new_obj(mp_lexer_file_buf_t);
mp_lexer_file_buf_t *fb = m_new_obj_maybe(mp_lexer_file_buf_t);
if (fb == NULL) {
return NULL;
}
fb->fd = open(filename, O_RDONLY);
if (fb->fd < 0) {
m_del_obj(mp_lexer_file_buf_t, fb);

View File

@ -54,6 +54,7 @@ typedef unsigned int uint;
#define m_new_maybe(type, num) ((type*)(m_malloc_maybe(sizeof(type) * (num))))
#define m_new0(type, num) ((type*)(m_malloc0(sizeof(type) * (num))))
#define m_new_obj(type) (m_new(type, 1))
#define m_new_obj_maybe(type) (m_new_maybe(type, 1))
#define m_new_obj_var(obj_type, var_type, var_num) ((obj_type*)m_malloc(sizeof(obj_type) + sizeof(var_type) * (var_num)))
#define m_new_obj_var_maybe(obj_type, var_type, var_num) ((obj_type*)m_malloc_maybe(sizeof(obj_type) + sizeof(var_type) * (var_num)))
#if MICROPY_ENABLE_FINALISER

View File

@ -64,7 +64,10 @@ STATIC void file_buf_close(mp_lexer_file_buf_t *fb) {
}
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
mp_lexer_file_buf_t *fb = m_new_obj(mp_lexer_file_buf_t);
mp_lexer_file_buf_t *fb = m_new_obj_maybe(mp_lexer_file_buf_t);
if (fb == NULL) {
return NULL;
}
FRESULT res = f_open(&fb->fp, filename, FA_READ);
if (res != FR_OK) {
m_del_obj(mp_lexer_file_buf_t, fb);