mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-130080: move _Py_EnsureArrayLargeEnough to a separate header so it can be used outside of the compiler (#130930)
This commit is contained in:
parent
9a63138e09
commit
4242c2b8d0
5 changed files with 108 additions and 52 deletions
|
@ -7,7 +7,8 @@
|
|||
|
||||
#include "Python.h"
|
||||
|
||||
#include "pycore_compile.h" // _PyCompile_EnsureArrayLargeEnough
|
||||
#include "pycore_c_array.h" // _Py_CArray_EnsureCapacity
|
||||
#include "pycore_compile.h" // _PyInstruction
|
||||
#include "pycore_opcode_utils.h"
|
||||
#include "pycore_opcode_metadata.h" // OPCODE_HAS_ARG, etc
|
||||
|
||||
|
@ -36,12 +37,18 @@ static int
|
|||
instr_sequence_next_inst(instr_sequence *seq) {
|
||||
assert(seq->s_instrs != NULL || seq->s_used == 0);
|
||||
|
||||
RETURN_IF_ERROR(
|
||||
_PyCompile_EnsureArrayLargeEnough(seq->s_used + 1,
|
||||
(void**)&seq->s_instrs,
|
||||
&seq->s_allocated,
|
||||
INITIAL_INSTR_SEQUENCE_SIZE,
|
||||
sizeof(instruction)));
|
||||
|
||||
_Py_c_array_t array = {
|
||||
.array = (void*)seq->s_instrs,
|
||||
.allocated_entries = seq->s_allocated,
|
||||
.item_size = sizeof(instruction),
|
||||
.initial_num_entries = INITIAL_INSTR_SEQUENCE_SIZE,
|
||||
};
|
||||
|
||||
RETURN_IF_ERROR(_Py_CArray_EnsureCapacity(&array, seq->s_used + 1));
|
||||
seq->s_instrs = array.array;
|
||||
seq->s_allocated = array.allocated_entries;
|
||||
|
||||
assert(seq->s_allocated >= 0);
|
||||
assert(seq->s_used < seq->s_allocated);
|
||||
return seq->s_used++;
|
||||
|
@ -58,12 +65,16 @@ int
|
|||
_PyInstructionSequence_UseLabel(instr_sequence *seq, int lbl)
|
||||
{
|
||||
int old_size = seq->s_labelmap_size;
|
||||
RETURN_IF_ERROR(
|
||||
_PyCompile_EnsureArrayLargeEnough(lbl,
|
||||
(void**)&seq->s_labelmap,
|
||||
&seq->s_labelmap_size,
|
||||
INITIAL_INSTR_SEQUENCE_LABELS_MAP_SIZE,
|
||||
sizeof(int)));
|
||||
_Py_c_array_t array = {
|
||||
.array = (void*)seq->s_labelmap,
|
||||
.allocated_entries = seq->s_labelmap_size,
|
||||
.item_size = sizeof(int),
|
||||
.initial_num_entries = INITIAL_INSTR_SEQUENCE_LABELS_MAP_SIZE,
|
||||
};
|
||||
|
||||
RETURN_IF_ERROR(_Py_CArray_EnsureCapacity(&array, lbl));
|
||||
seq->s_labelmap = array.array;
|
||||
seq->s_labelmap_size = array.allocated_entries;
|
||||
|
||||
for(int i = old_size; i < seq->s_labelmap_size; i++) {
|
||||
seq->s_labelmap[i] = -111; /* something weird, for debugging */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue