gh-130080: move _Py_EnsureArrayLargeEnough to a separate header so it can be used outside of the compiler (#130930)

This commit is contained in:
Irit Katriel 2025-03-13 16:02:58 +00:00 committed by GitHub
parent 9a63138e09
commit 4242c2b8d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 108 additions and 52 deletions

View file

@ -1,5 +1,6 @@
#include "Python.h"
#include "opcode.h"
#include "pycore_c_array.h" // _Py_CArray_EnsureCapacity
#include "pycore_flowgraph.h"
#include "pycore_compile.h"
#include "pycore_intrinsics.h"
@ -141,13 +142,16 @@ static int
basicblock_next_instr(basicblock *b)
{
assert(b != NULL);
RETURN_IF_ERROR(
_PyCompile_EnsureArrayLargeEnough(
b->b_iused + 1,
(void**)&b->b_instr,
&b->b_ialloc,
DEFAULT_BLOCK_SIZE,
sizeof(cfg_instr)));
_Py_c_array_t array = {
.array = (void*)b->b_instr,
.allocated_entries = b->b_ialloc,
.item_size = sizeof(cfg_instr),
.initial_num_entries = DEFAULT_BLOCK_SIZE,
};
RETURN_IF_ERROR(_Py_CArray_EnsureCapacity(&array, b->b_iused + 1));
b->b_instr = array.array;
b->b_ialloc = array.allocated_entries;
return b->b_iused++;
}