Fix shape allocation limits
We can only allocate enough shapes to fit in the shape buffer. MAX_SHAPE_ID was based on the theoretical maximum number of shapes we could have, not on the amount of memory we can actually consume. This commit changes the MAX_SHAPE_ID to be based on the amount of memory we're allowed to consume. Co-Authored-By: Jemma Issroff <jemmaissroff@gmail.com>
This commit is contained in:
parent
e340eb2106
commit
1a9e2d20e2
Notes:
git
2023-03-22 15:46:36 +00:00
1
shape.c
1
shape.c
@ -145,6 +145,7 @@ get_next_shape_internal(rb_shape_t * shape, ID id, enum shape_type shape_type, b
|
||||
|
||||
new_shape->type = (uint8_t)shape_type;
|
||||
new_shape->capacity = shape->capacity;
|
||||
new_shape->edges = NULL;
|
||||
|
||||
switch (shape_type) {
|
||||
case SHAPE_IVAR:
|
||||
|
4
shape.h
4
shape.h
@ -28,12 +28,12 @@ typedef uint16_t shape_id_t;
|
||||
|
||||
# define SHAPE_FLAG_SHIFT ((SIZEOF_VALUE * 8) - SHAPE_ID_NUM_BITS)
|
||||
|
||||
# define SHAPE_BITMAP_SIZE 16384
|
||||
# define SHAPE_BUFFER_SIZE 0x80000
|
||||
|
||||
# define SHAPE_MAX_VARIATIONS 8
|
||||
# define SHAPE_MAX_NUM_IVS 80
|
||||
|
||||
# define MAX_SHAPE_ID (SHAPE_MASK - 1)
|
||||
# define MAX_SHAPE_ID SHAPE_BUFFER_SIZE
|
||||
# define INVALID_SHAPE_ID SHAPE_MASK
|
||||
# define ROOT_SHAPE_ID 0x0
|
||||
|
||||
|
4
vm.c
4
vm.c
@ -4022,13 +4022,13 @@ Init_vm_objects(void)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MMAP
|
||||
vm->shape_list = (rb_shape_t *)mmap(NULL, rb_size_mul_or_raise(SHAPE_BITMAP_SIZE * 32, sizeof(rb_shape_t), rb_eRuntimeError),
|
||||
vm->shape_list = (rb_shape_t *)mmap(NULL, rb_size_mul_or_raise(SHAPE_BUFFER_SIZE, sizeof(rb_shape_t), rb_eRuntimeError),
|
||||
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
if (vm->shape_list == MAP_FAILED) {
|
||||
vm->shape_list = 0;
|
||||
}
|
||||
#else
|
||||
vm->shape_list = xcalloc(SHAPE_BITMAP_SIZE * 32, sizeof(rb_shape_t));
|
||||
vm->shape_list = xcalloc(SHAPE_BUFFER_SIZE, sizeof(rb_shape_t));
|
||||
#endif
|
||||
|
||||
if (!vm->shape_list) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user