Skip to content

Commit afcc22e

Browse files
Merge remote-tracking branch 'upstream/3.13' into backport-156106-3.13
2 parents 21e3c5f + acdb9a7 commit afcc22e

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

Lib/test/test_frame.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ def test_f_trace_lines_and_opcodes(self):
244244
"can't delete numeric/char attribute"):
245245
del f.f_trace_lines
246246

247+
def test_f_trace_opcodes_del(self):
248+
f, _, _ = self.make_frames()
249+
f.f_trace_opcodes = True
250+
with self.assertRaisesRegex(AttributeError, 'cannot delete attribute'):
251+
del f.f_trace_opcodes
252+
# a failed deletion does not change the value
253+
self.assertIs(f.f_trace_opcodes, True)
254+
247255
def test_f_lineno_del_segfault(self):
248256
f, _, _ = self.make_frames()
249257
with self.assertRaises(AttributeError):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash when deleting the :attr:`~frame.f_trace_opcodes` attribute of
2+
a frame object. It now raises :exc:`AttributeError`.

Objects/frameobject.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,11 @@ frame_gettrace_opcodes(PyFrameObject *f, void *closure)
979979
static int
980980
frame_settrace_opcodes(PyFrameObject *f, PyObject* value, void *Py_UNUSED(ignored))
981981
{
982+
if (value == NULL) {
983+
PyErr_SetString(PyExc_AttributeError,
984+
"cannot delete attribute f_trace_opcodes");
985+
return -1;
986+
}
982987
if (!PyBool_Check(value)) {
983988
PyErr_SetString(PyExc_TypeError,
984989
"attribute value type must be bool");

0 commit comments

Comments
 (0)