Skip to content

Commit

Permalink
py/parse: Use m_renew_maybe to ensure that memory is shrunk in-place.
Browse files Browse the repository at this point in the history
The chunks of memory that the parser allocates contain parse nodes and
are pointed to from many places, so these chunks cannot be relocated
by the memory manager.  This patch makes it so that when a chunk is
shrunk to fit, it is not relocated.
  • Loading branch information
dpgeorge committed Feb 23, 2016
1 parent add930c commit d6c558c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions py/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ STATIC void *parser_alloc(parser_t *parser, size_t num_bytes) {
sizeof(mp_parse_chunk_t) + chunk->alloc + num_bytes, false);
if (new_data == NULL) {
// could not grow existing memory; shrink it to fit previous
(void)m_renew(byte, chunk, sizeof(mp_parse_chunk_t) + chunk->alloc,
sizeof(mp_parse_chunk_t) + chunk->union_.used);
(void)m_renew_maybe(byte, chunk, sizeof(mp_parse_chunk_t) + chunk->alloc,
sizeof(mp_parse_chunk_t) + chunk->union_.used, false);
chunk->alloc = chunk->union_.used;
chunk->union_.next = parser->tree.chunk;
parser->tree.chunk = chunk;
Expand Down

0 comments on commit d6c558c

Please sign in to comment.