summaryrefslogtreecommitdiffstats
path: root/Python/instruction_sequence.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2025-03-13 16:02:58 (GMT)
committerGitHub <noreply@github.com>2025-03-13 16:02:58 (GMT)
commit4242c2b8d073c740164b82725270fd691bda03c8 (patch)
tree081bdbdcfc08af11bfc5727c6b60d49b8d7ad008 /Python/instruction_sequence.c
parent9a63138e0953fc8efc2d52154f17c383259854e1 (diff)
downloadcpython-4242c2b8d073c740164b82725270fd691bda03c8.zip
cpython-4242c2b8d073c740164b82725270fd691bda03c8.tar.gz
cpython-4242c2b8d073c740164b82725270fd691bda03c8.tar.bz2
gh-130080: move _Py_EnsureArrayLargeEnough to a separate header so it can be used outside of the compiler (#130930)
Diffstat (limited to 'Python/instruction_sequence.c')
-rw-r--r--Python/instruction_sequence.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/Python/instruction_sequence.c b/Python/instruction_sequence.c
index ed40c06..4ca85ee 100644
--- a/Python/instruction_sequence.c
+++ b/Python/instruction_sequence.c
@@ -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 */