diff --git a/src/arena.c b/src/arena.c index 64a731649d..323c5bdc7d 100644 --- a/src/arena.c +++ b/src/arena.c @@ -12,8 +12,13 @@ */ #define PM_ARENA_BLOCK_SIZE(data_size) (offsetof(pm_arena_block_t, data) + (data_size)) -/** Initial block data size: 8 KB. */ +/** + * Initial block data size: 8 KB. An embedder on a small heap can define a + * smaller one; a parse of a short program then takes blocks of that size. + */ +#ifndef PM_ARENA_INITIAL_SIZE #define PM_ARENA_INITIAL_SIZE 8192 +#endif /** Double the block size every this many blocks. */ #define PM_ARENA_GROWTH_INTERVAL 8 diff --git a/src/errors_format.c b/src/errors_format.c index 32956a613a..afb6ee1214 100644 --- a/src/errors_format.c +++ b/src/errors_format.c @@ -8,6 +8,10 @@ #include "prism/internal/parser.h" #include +// Include sys/types.h before inttypes.h to work around an issue with certain +// versions of GCC and newlib which causes omission of the 64-bit PRI macros +// (see 61ebe5123; the removal of defines.h dropped it). +#include #include #include #include diff --git a/src/integer.c b/src/integer.c index 104052412d..deb317695a 100644 --- a/src/integer.c +++ b/src/integer.c @@ -4,6 +4,10 @@ #include "prism/internal/buffer.h" #include +// Include sys/types.h before inttypes.h to work around an issue with certain +// versions of GCC and newlib which causes omission of PRIu64 and the other +// 64-bit macros (see 61ebe5123; the removal of defines.h dropped it). +#include #include #include #include diff --git a/src/prism.c b/src/prism.c index 5bdab809a2..01b91fee91 100644 --- a/src/prism.c +++ b/src/prism.c @@ -23254,6 +23254,16 @@ pm_parser_init_shebang(pm_parser_t *parser, const pm_options_t *options, const c parser->frozen_string_literal = next_options.frozen_string_literal; } +/** + * The smallest capacity the constant pool starts with, whatever the source + * size suggests. An embedder that interns a fixed set of names into the pool + * at every parse (a symbol table) can raise it to that set's size, so the + * pool does not grow to hold them and leave each outgrown array in the arena. + */ +#ifndef PM_CONSTANT_POOL_MIN_CAPACITY +#define PM_CONSTANT_POOL_MIN_CAPACITY 4 +#endif + /** * Initialize a parser with the given start and end pointers. */ @@ -23331,7 +23341,8 @@ pm_parser_init(pm_arena_t *arena, pm_parser_t *parser, const uint8_t *source, si * frequency. Resizes are cheap with arena allocation, so we lean toward * under-estimating. */ uint32_t constant_size = ((uint32_t) size) / 120; - pm_constant_pool_init(&parser->metadata_arena, &parser->constant_pool, constant_size < 4 ? 4 : constant_size); + if (constant_size < PM_CONSTANT_POOL_MIN_CAPACITY) constant_size = PM_CONSTANT_POOL_MIN_CAPACITY; + pm_constant_pool_init(&parser->metadata_arena, &parser->constant_pool, constant_size); /* Initialize the line offset list. Similar to the constant pool, we are * going to estimate the number of newlines that we will need based on the