Skip to content

Commit d6c558c

Browse files
committed
py/parse: Use m_renew_maybe to ensure that memory is shrunk in-place.
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.
1 parent add930c commit d6c558c

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

py/parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ STATIC void *parser_alloc(parser_t *parser, size_t num_bytes) {
166166
sizeof(mp_parse_chunk_t) + chunk->alloc + num_bytes, false);
167167
if (new_data == NULL) {
168168
// could not grow existing memory; shrink it to fit previous
169-
(void)m_renew(byte, chunk, sizeof(mp_parse_chunk_t) + chunk->alloc,
170-
sizeof(mp_parse_chunk_t) + chunk->union_.used);
169+
(void)m_renew_maybe(byte, chunk, sizeof(mp_parse_chunk_t) + chunk->alloc,
170+
sizeof(mp_parse_chunk_t) + chunk->union_.used, false);
171171
chunk->alloc = chunk->union_.used;
172172
chunk->union_.next = parser->tree.chunk;
173173
parser->tree.chunk = chunk;

0 commit comments

Comments
 (0)