gh-130907: Treat all module-level annotations as conditional (#131550)

This commit is contained in:
Jelle Zijlstra 2025-04-28 06:10:28 -07:00 committed by GitHub
parent 5bf0f3666e
commit 922049b613
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 221 additions and 53 deletions

View file

@ -154,6 +154,15 @@ _PyInstructionSequence_InsertInstruction(instr_sequence *seq, int pos,
return SUCCESS;
}
int
_PyInstructionSequence_SetAnnotationsCode(instr_sequence *seq,
instr_sequence *annotations)
{
assert(seq->s_annotations_code == NULL);
seq->s_annotations_code = annotations;
return SUCCESS;
}
int
_PyInstructionSequence_AddNested(instr_sequence *seq, instr_sequence *nested)
{
@ -178,6 +187,12 @@ PyInstructionSequence_Fini(instr_sequence *seq) {
PyMem_Free(seq->s_instrs);
seq->s_instrs = NULL;
if (seq->s_annotations_code != NULL) {
PyInstructionSequence_Fini(seq->s_annotations_code);
Py_CLEAR(seq->s_annotations_code);
}
}
/*[clinic input]
@ -200,6 +215,7 @@ inst_seq_create(void)
seq->s_labelmap = NULL;
seq->s_labelmap_size = 0;
seq->s_nested = NULL;
seq->s_annotations_code = NULL;
PyObject_GC_Track(seq);
return seq;
@ -414,6 +430,7 @@ inst_seq_traverse(PyObject *op, visitproc visit, void *arg)
{
_PyInstructionSequence *seq = (_PyInstructionSequence *)op;
Py_VISIT(seq->s_nested);
Py_VISIT((PyObject *)seq->s_annotations_code);
return 0;
}
@ -422,6 +439,7 @@ inst_seq_clear(PyObject *op)
{
_PyInstructionSequence *seq = (_PyInstructionSequence *)op;
Py_CLEAR(seq->s_nested);
Py_CLEAR(seq->s_annotations_code);
return 0;
}