mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-87092: fix a few cases of incorrect error handling in compiler (#103456)
gh-87092: fix a few cases of incorrect error handling
This commit is contained in:
parent
cb157a1a35
commit
6751a4af95
1 changed files with 23 additions and 9 deletions
|
@ -6688,7 +6688,10 @@ insert_prefix_instructions(struct compiler_unit *u, basicblock *entryblock,
|
||||||
.i_loc = NO_LOCATION,
|
.i_loc = NO_LOCATION,
|
||||||
.i_target = NULL,
|
.i_target = NULL,
|
||||||
};
|
};
|
||||||
RETURN_IF_ERROR(_PyBasicblock_InsertInstruction(entryblock, ncellsused, &make_cell));
|
if (_PyBasicblock_InsertInstruction(entryblock, ncellsused, &make_cell) < 0) {
|
||||||
|
PyMem_RawFree(sorted);
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
ncellsused += 1;
|
ncellsused += 1;
|
||||||
}
|
}
|
||||||
PyMem_RawFree(sorted);
|
PyMem_RawFree(sorted);
|
||||||
|
@ -6860,7 +6863,7 @@ optimize_and_assemble_code_unit(struct compiler_unit *u, PyObject *const_cache,
|
||||||
maxdepth, g.g_entryblock, nlocalsplus,
|
maxdepth, g.g_entryblock, nlocalsplus,
|
||||||
code_flags, filename);
|
code_flags, filename);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
Py_XDECREF(consts);
|
Py_XDECREF(consts);
|
||||||
instr_sequence_fini(&optimized_instrs);
|
instr_sequence_fini(&optimized_instrs);
|
||||||
_PyCfgBuilder_Fini(&g);
|
_PyCfgBuilder_Fini(&g);
|
||||||
|
@ -6958,7 +6961,9 @@ instructions_to_instr_sequence(PyObject *instructions, instr_sequence *seq)
|
||||||
|
|
||||||
for (int i = 0; i < num_insts; i++) {
|
for (int i = 0; i < num_insts; i++) {
|
||||||
if (is_target[i]) {
|
if (is_target[i]) {
|
||||||
RETURN_IF_ERROR(instr_sequence_use_label(seq, i));
|
if (instr_sequence_use_label(seq, i) < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PyObject *item = PyList_GET_ITEM(instructions, i);
|
PyObject *item = PyList_GET_ITEM(instructions, i);
|
||||||
if (!PyTuple_Check(item) || PyTuple_GET_SIZE(item) != 6) {
|
if (!PyTuple_Check(item) || PyTuple_GET_SIZE(item) != 6) {
|
||||||
|
@ -6996,10 +7001,14 @@ instructions_to_instr_sequence(PyObject *instructions, instr_sequence *seq)
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
RETURN_IF_ERROR(instr_sequence_addop(seq, opcode, oparg, loc));
|
if (instr_sequence_addop(seq, opcode, oparg, loc) < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (seq->s_used && !IS_TERMINATOR_OPCODE(seq->s_instrs[seq->s_used-1].i_opcode)) {
|
if (seq->s_used && !IS_TERMINATOR_OPCODE(seq->s_instrs[seq->s_used-1].i_opcode)) {
|
||||||
RETURN_IF_ERROR(instr_sequence_addop(seq, RETURN_VALUE, 0, NO_LOCATION));
|
if (instr_sequence_addop(seq, RETURN_VALUE, 0, NO_LOCATION) < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PyMem_Free(is_target);
|
PyMem_Free(is_target);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
@ -7014,12 +7023,17 @@ instructions_to_cfg(PyObject *instructions, cfg_builder *g)
|
||||||
instr_sequence seq;
|
instr_sequence seq;
|
||||||
memset(&seq, 0, sizeof(instr_sequence));
|
memset(&seq, 0, sizeof(instr_sequence));
|
||||||
|
|
||||||
RETURN_IF_ERROR(
|
if (instructions_to_instr_sequence(instructions, &seq) < 0) {
|
||||||
instructions_to_instr_sequence(instructions, &seq));
|
goto error;
|
||||||
|
}
|
||||||
RETURN_IF_ERROR(instr_sequence_to_cfg(&seq, g));
|
if (instr_sequence_to_cfg(&seq, g) < 0) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
instr_sequence_fini(&seq);
|
instr_sequence_fini(&seq);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
error:
|
||||||
|
instr_sequence_fini(&seq);
|
||||||
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue