From 739c384c6aa81aa309605a76d619ab5bba213ff0 Mon Sep 17 00:00:00 2001 From: Costy Petrisor Date: Sat, 28 Jul 2018 10:23:59 +0000 Subject: [PATCH 1/7] bpo-34113: Fix SIGSEGV on negative STACKADJ when LLTRACE is on --- Python/ceval.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index 8f0e0e00c2b9d50..872712e94390e7f 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -762,16 +762,20 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) assert(STACK_LEVEL() <= co->co_stacksize); } #define POP() ((void)(lltrace && prtrace(TOP(), "pop")), \ BASIC_POP()) -#define STACKADJ(n) { (void)(BASIC_STACKADJ(n), \ - lltrace && prtrace(TOP(), "stackadj")); \ - assert(STACK_LEVEL() <= co->co_stacksize); } +#define STACKADJ_GROW(n) { (void)(BASIC_STACKADJ(n), \ + lltrace && prtrace(TOP(), "stackadj")); \ + assert(STACK_LEVEL() <= co->co_stacksize); } +#define STACKADJ_SHRINK(n) { (void)(lltrace && prtrace(TOP(), "stackadj")); \ + (void)(BASIC_STACKADJ(n)); \ + assert(STACK_LEVEL() <= co->co_stacksize); } #define EXT_POP(STACK_POINTER) ((void)(lltrace && \ prtrace((STACK_POINTER)[-1], "ext_pop")), \ *--(STACK_POINTER)) #else #define PUSH(v) BASIC_PUSH(v) #define POP() BASIC_POP() -#define STACKADJ(n) BASIC_STACKADJ(n) +#define STACKADJ_GROW(n) BASIC_STACKADJ(n) +#define STACKADJ_SHRINK(n) BASIC_STACKADJ(n) #define EXT_POP(STACK_POINTER) (*--(STACK_POINTER)) #endif @@ -1133,7 +1137,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *second = SECOND(); Py_INCREF(top); Py_INCREF(second); - STACKADJ(2); + STACKADJ_GROW(2); SET_TOP(top); SET_SECOND(second); FAST_DISPATCH(); @@ -1173,7 +1177,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) SET_TOP(Py_False); DISPATCH(); } - STACKADJ(-1); + STACKADJ_SHRINK(-1); goto error; } @@ -1569,7 +1573,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *container = SECOND(); PyObject *v = THIRD(); int err; - STACKADJ(-3); + STACKADJ_SHRINK(-3); /* container[sub] = v */ err = PyObject_SetItem(container, sub, v); Py_DECREF(v); @@ -1584,7 +1588,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *sub = TOP(); PyObject *container = SECOND(); int err; - STACKADJ(-2); + STACKADJ_SHRINK(-2); /* del container[sub] */ err = PyObject_DelItem(container, sub); Py_DECREF(container); @@ -2067,7 +2071,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) } } else if (unpack_iterable(seq, oparg, -1, stack_pointer + oparg)) { - STACKADJ(oparg); + STACKADJ_GROW(oparg); } else { /* unpack_iterable() raised an exception */ Py_DECREF(seq); @@ -2097,7 +2101,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *owner = TOP(); PyObject *v = SECOND(); int err; - STACKADJ(-2); + STACKADJ_SHRINK(-2); err = PyObject_SetAttr(owner, name, v); Py_DECREF(v); Py_DECREF(owner); @@ -2420,7 +2424,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) err = PySet_Add(set, item); Py_DECREF(item); } - STACKADJ(-oparg); + STACKADJ_SHRINK(-oparg); if (err != 0) { Py_DECREF(set); goto error; @@ -2641,7 +2645,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *value = SECOND(); PyObject *map; int err; - STACKADJ(-2); + STACKADJ_SHRINK(-2); map = PEEK(oparg); /* dict */ assert(PyDict_CheckExact(map)); err = PyDict_SetItem(map, key, value); /* map[key] = value */ @@ -2784,7 +2788,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *cond = TOP(); int err; if (cond == Py_True) { - STACKADJ(-1); + STACKADJ_SHRINK(-1); Py_DECREF(cond); FAST_DISPATCH(); } @@ -2794,7 +2798,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) } err = PyObject_IsTrue(cond); if (err > 0) { - STACKADJ(-1); + STACKADJ_SHRINK(-1); Py_DECREF(cond); } else if (err == 0) @@ -2808,7 +2812,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *cond = TOP(); int err; if (cond == Py_False) { - STACKADJ(-1); + STACKADJ_SHRINK(-1); Py_DECREF(cond); FAST_DISPATCH(); } @@ -2821,7 +2825,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) JUMPTO(oparg); } else if (err == 0) { - STACKADJ(-1); + STACKADJ_SHRINK(-1); Py_DECREF(cond); } else @@ -2907,7 +2911,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyErr_Clear(); } /* iterator ended normally */ - STACKADJ(-1); + STACKADJ_SHRINK(-1); Py_DECREF(iter); JUMPBY(oparg); PREDICT(POP_BLOCK); @@ -3015,7 +3019,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) val = tb = Py_None; exc = TOP(); if (exc == NULL) { - STACKADJ(-1); + STACKADJ_SHRINK(-1); exit_func = TOP(); SET_TOP(exc); exc = Py_None; From 6f8d632884c8761b606e6fa0ec58c18c8ce958b2 Mon Sep 17 00:00:00 2001 From: Costy Petrisor Date: Sat, 28 Jul 2018 10:36:47 +0000 Subject: [PATCH 2/7] updated NEWS.d using blurb --- .../Core and Builtins/2018-07-28-10-34-00.bpo-34113.eZ5FWV.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2018-07-28-10-34-00.bpo-34113.eZ5FWV.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-07-28-10-34-00.bpo-34113.eZ5FWV.rst b/Misc/NEWS.d/next/Core and Builtins/2018-07-28-10-34-00.bpo-34113.eZ5FWV.rst new file mode 100644 index 000000000000000..f4c80f9b8a97f1f --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2018-07-28-10-34-00.bpo-34113.eZ5FWV.rst @@ -0,0 +1,2 @@ +Fixed crash on debug builds when opcode stack was adjusted with negative +numbers. Patch by Constantin Petrisor. From 345cbd97d464bdd0a4c9648f444a85405fd227f2 Mon Sep 17 00:00:00 2001 From: Costy Petrisor Date: Sat, 28 Jul 2018 11:25:11 +0000 Subject: [PATCH 3/7] followed review comments by Victor Stinner --- Python/ceval.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index 872712e94390e7f..93559eb49008ada 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -762,12 +762,18 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) assert(STACK_LEVEL() <= co->co_stacksize); } #define POP() ((void)(lltrace && prtrace(TOP(), "pop")), \ BASIC_POP()) -#define STACKADJ_GROW(n) { (void)(BASIC_STACKADJ(n), \ +#define STACKADJ_GROW(n) do { \ + assert(n >= 0); \ + (void)(BASIC_STACKADJ(n), \ lltrace && prtrace(TOP(), "stackadj")); \ - assert(STACK_LEVEL() <= co->co_stacksize); } -#define STACKADJ_SHRINK(n) { (void)(lltrace && prtrace(TOP(), "stackadj")); \ - (void)(BASIC_STACKADJ(n)); \ - assert(STACK_LEVEL() <= co->co_stacksize); } + assert(STACK_LEVEL() <= co->co_stacksize); \ + } while (0) +#define STACKADJ_SHRINK(n) do { \ + assert(n >= 0); \ + (void)(lltrace && prtrace(TOP(), "stackadj")); \ + (void)(BASIC_STACKADJ(-n)); \ + assert(STACK_LEVEL() <= co->co_stacksize); \ + } while (0) #define EXT_POP(STACK_POINTER) ((void)(lltrace && \ prtrace((STACK_POINTER)[-1], "ext_pop")), \ *--(STACK_POINTER)) @@ -775,7 +781,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) #define PUSH(v) BASIC_PUSH(v) #define POP() BASIC_POP() #define STACKADJ_GROW(n) BASIC_STACKADJ(n) -#define STACKADJ_SHRINK(n) BASIC_STACKADJ(n) +#define STACKADJ_SHRINK(n) BASIC_STACKADJ(-n) #define EXT_POP(STACK_POINTER) (*--(STACK_POINTER)) #endif @@ -1177,7 +1183,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) SET_TOP(Py_False); DISPATCH(); } - STACKADJ_SHRINK(-1); + STACKADJ_SHRINK(1); goto error; } @@ -1573,7 +1579,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *container = SECOND(); PyObject *v = THIRD(); int err; - STACKADJ_SHRINK(-3); + STACKADJ_SHRINK(3); /* container[sub] = v */ err = PyObject_SetItem(container, sub, v); Py_DECREF(v); @@ -1588,7 +1594,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *sub = TOP(); PyObject *container = SECOND(); int err; - STACKADJ_SHRINK(-2); + STACKADJ_SHRINK(2); /* del container[sub] */ err = PyObject_DelItem(container, sub); Py_DECREF(container); @@ -2101,7 +2107,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *owner = TOP(); PyObject *v = SECOND(); int err; - STACKADJ_SHRINK(-2); + STACKADJ_SHRINK(2); err = PyObject_SetAttr(owner, name, v); Py_DECREF(v); Py_DECREF(owner); @@ -2424,7 +2430,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) err = PySet_Add(set, item); Py_DECREF(item); } - STACKADJ_SHRINK(-oparg); + STACKADJ_SHRINK(oparg); if (err != 0) { Py_DECREF(set); goto error; @@ -2645,7 +2651,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *value = SECOND(); PyObject *map; int err; - STACKADJ_SHRINK(-2); + STACKADJ_SHRINK(2); map = PEEK(oparg); /* dict */ assert(PyDict_CheckExact(map)); err = PyDict_SetItem(map, key, value); /* map[key] = value */ @@ -2788,7 +2794,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *cond = TOP(); int err; if (cond == Py_True) { - STACKADJ_SHRINK(-1); + STACKADJ_SHRINK(1); Py_DECREF(cond); FAST_DISPATCH(); } @@ -2798,7 +2804,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) } err = PyObject_IsTrue(cond); if (err > 0) { - STACKADJ_SHRINK(-1); + STACKADJ_SHRINK(1); Py_DECREF(cond); } else if (err == 0) @@ -2812,7 +2818,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *cond = TOP(); int err; if (cond == Py_False) { - STACKADJ_SHRINK(-1); + STACKADJ_SHRINK(1); Py_DECREF(cond); FAST_DISPATCH(); } @@ -2825,7 +2831,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) JUMPTO(oparg); } else if (err == 0) { - STACKADJ_SHRINK(-1); + STACKADJ_SHRINK(1); Py_DECREF(cond); } else @@ -2911,7 +2917,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyErr_Clear(); } /* iterator ended normally */ - STACKADJ_SHRINK(-1); + STACKADJ_SHRINK(1); Py_DECREF(iter); JUMPBY(oparg); PREDICT(POP_BLOCK); @@ -3019,7 +3025,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) val = tb = Py_None; exc = TOP(); if (exc == NULL) { - STACKADJ_SHRINK(-1); + STACKADJ_SHRINK(1); exit_func = TOP(); SET_TOP(exc); exc = Py_None; From 4ee09fb1b1737084e9baced8f35a3f87d4954671 Mon Sep 17 00:00:00 2001 From: Costy Petrisor Date: Sat, 28 Jul 2018 14:06:43 +0000 Subject: [PATCH 4/7] added a test which fails without the fix in this PR --- Lib/test/test_lltrace.py | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Lib/test/test_lltrace.py diff --git a/Lib/test/test_lltrace.py b/Lib/test/test_lltrace.py new file mode 100644 index 000000000000000..d19023bf2f6fd88 --- /dev/null +++ b/Lib/test/test_lltrace.py @@ -0,0 +1,43 @@ + +import os +import tempfile +import textwrap +import unittest + +from test import support +from test.support.script_helper import ( + assert_python_ok, assert_python_failure, interpreter_requires_environment, +) + + +class TestLLTrace(unittest.TestCase): + + def test_lltrace_does_not_crash_on_subscript_operator(self): + # If this test fails, it will reproduce a crash reported as + # bpo-34113. The crash happened at the command line console of + # debug Python builds with __ltrace__ enabled (only possible in console), + # when the interal Python stack was negatively adjusted + with tempfile.NamedTemporaryFile(mode='w+', delete=False) as tmp_script: + self.addCleanup(os.remove, tmp_script.name) + tmp_script.write(textwrap.dedent("""\ + import code + + console = code.InteractiveConsole() + console.push('__ltrace__ = 1') + console.push('a = [1, 2, 3]') + console.push('a[0] = 1') + print('unreachable if bug exists') + """)) + tmp_script.flush() + + status, stdout, stderr = assert_python_ok(tmp_script.name) + self.assertEqual(status, 0) + + +def test_main(): + support.run_unittest( + TestLLTrace, + ) + +if __name__ == "__main__": + test_main() From 0cfc6bd3d2ab177639039dfe4ae7202cd3c90705 Mon Sep 17 00:00:00 2001 From: Costy Petrisor Date: Tue, 31 Jul 2018 17:03:28 +0000 Subject: [PATCH 5/7] addressed review comments by Victor Stinner --- Lib/test/test_lltrace.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_lltrace.py b/Lib/test/test_lltrace.py index d19023bf2f6fd88..50281b0c045e73f 100644 --- a/Lib/test/test_lltrace.py +++ b/Lib/test/test_lltrace.py @@ -1,13 +1,9 @@ - import os import tempfile import textwrap import unittest -from test import support -from test.support.script_helper import ( - assert_python_ok, assert_python_failure, interpreter_requires_environment, -) +from test.support.script_helper import assert_python_ok class TestLLTrace(unittest.TestCase): @@ -30,14 +26,7 @@ def test_lltrace_does_not_crash_on_subscript_operator(self): """)) tmp_script.flush() - status, stdout, stderr = assert_python_ok(tmp_script.name) - self.assertEqual(status, 0) - - -def test_main(): - support.run_unittest( - TestLLTrace, - ) + assert_python_ok(tmp_script.name) if __name__ == "__main__": - test_main() + unittest.main() From 5eca161954a4a0899bda425474cf768273ce52d4 Mon Sep 17 00:00:00 2001 From: Costy Petrisor Date: Tue, 31 Jul 2018 17:23:14 +0000 Subject: [PATCH 6/7] renamed macros STACKADJ_GROW to STACK_GROW and STACKADJ_SHRINK to STACK_SHRINK --- Python/ceval.c | 56 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index 93559eb49008ada..46da295aac06954 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -762,26 +762,26 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) assert(STACK_LEVEL() <= co->co_stacksize); } #define POP() ((void)(lltrace && prtrace(TOP(), "pop")), \ BASIC_POP()) -#define STACKADJ_GROW(n) do { \ - assert(n >= 0); \ - (void)(BASIC_STACKADJ(n), \ - lltrace && prtrace(TOP(), "stackadj")); \ - assert(STACK_LEVEL() <= co->co_stacksize); \ - } while (0) -#define STACKADJ_SHRINK(n) do { \ - assert(n >= 0); \ - (void)(lltrace && prtrace(TOP(), "stackadj")); \ - (void)(BASIC_STACKADJ(-n)); \ - assert(STACK_LEVEL() <= co->co_stacksize); \ - } while (0) +#define STACK_GROW(n) do { \ + assert(n >= 0); \ + (void)(BASIC_STACKADJ(n), \ + lltrace && prtrace(TOP(), "stackadj")); \ + assert(STACK_LEVEL() <= co->co_stacksize); \ + } while (0) +#define STACK_SHRINK(n) do { \ + assert(n >= 0); \ + (void)(lltrace && prtrace(TOP(), "stackadj")); \ + (void)(BASIC_STACKADJ(-n)); \ + assert(STACK_LEVEL() <= co->co_stacksize); \ + } while (0) #define EXT_POP(STACK_POINTER) ((void)(lltrace && \ prtrace((STACK_POINTER)[-1], "ext_pop")), \ *--(STACK_POINTER)) #else #define PUSH(v) BASIC_PUSH(v) #define POP() BASIC_POP() -#define STACKADJ_GROW(n) BASIC_STACKADJ(n) -#define STACKADJ_SHRINK(n) BASIC_STACKADJ(-n) +#define STACK_GROW(n) BASIC_STACKADJ(n) +#define STACK_SHRINK(n) BASIC_STACKADJ(-n) #define EXT_POP(STACK_POINTER) (*--(STACK_POINTER)) #endif @@ -1143,7 +1143,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *second = SECOND(); Py_INCREF(top); Py_INCREF(second); - STACKADJ_GROW(2); + STACK_GROW(2); SET_TOP(top); SET_SECOND(second); FAST_DISPATCH(); @@ -1183,7 +1183,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) SET_TOP(Py_False); DISPATCH(); } - STACKADJ_SHRINK(1); + STACK_SHRINK(1); goto error; } @@ -1579,7 +1579,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *container = SECOND(); PyObject *v = THIRD(); int err; - STACKADJ_SHRINK(3); + STACK_SHRINK(3); /* container[sub] = v */ err = PyObject_SetItem(container, sub, v); Py_DECREF(v); @@ -1594,7 +1594,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *sub = TOP(); PyObject *container = SECOND(); int err; - STACKADJ_SHRINK(2); + STACK_SHRINK(2); /* del container[sub] */ err = PyObject_DelItem(container, sub); Py_DECREF(container); @@ -2077,7 +2077,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) } } else if (unpack_iterable(seq, oparg, -1, stack_pointer + oparg)) { - STACKADJ_GROW(oparg); + STACK_GROW(oparg); } else { /* unpack_iterable() raised an exception */ Py_DECREF(seq); @@ -2107,7 +2107,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *owner = TOP(); PyObject *v = SECOND(); int err; - STACKADJ_SHRINK(2); + STACK_SHRINK(2); err = PyObject_SetAttr(owner, name, v); Py_DECREF(v); Py_DECREF(owner); @@ -2430,7 +2430,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) err = PySet_Add(set, item); Py_DECREF(item); } - STACKADJ_SHRINK(oparg); + STACK_SHRINK(oparg); if (err != 0) { Py_DECREF(set); goto error; @@ -2651,7 +2651,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *value = SECOND(); PyObject *map; int err; - STACKADJ_SHRINK(2); + STACK_SHRINK(2); map = PEEK(oparg); /* dict */ assert(PyDict_CheckExact(map)); err = PyDict_SetItem(map, key, value); /* map[key] = value */ @@ -2794,7 +2794,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *cond = TOP(); int err; if (cond == Py_True) { - STACKADJ_SHRINK(1); + STACK_SHRINK(1); Py_DECREF(cond); FAST_DISPATCH(); } @@ -2804,7 +2804,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) } err = PyObject_IsTrue(cond); if (err > 0) { - STACKADJ_SHRINK(1); + STACK_SHRINK(1); Py_DECREF(cond); } else if (err == 0) @@ -2818,7 +2818,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyObject *cond = TOP(); int err; if (cond == Py_False) { - STACKADJ_SHRINK(1); + STACK_SHRINK(1); Py_DECREF(cond); FAST_DISPATCH(); } @@ -2831,7 +2831,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) JUMPTO(oparg); } else if (err == 0) { - STACKADJ_SHRINK(1); + STACK_SHRINK(1); Py_DECREF(cond); } else @@ -2917,7 +2917,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) PyErr_Clear(); } /* iterator ended normally */ - STACKADJ_SHRINK(1); + STACK_SHRINK(1); Py_DECREF(iter); JUMPBY(oparg); PREDICT(POP_BLOCK); @@ -3025,7 +3025,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) val = tb = Py_None; exc = TOP(); if (exc == NULL) { - STACKADJ_SHRINK(1); + STACK_SHRINK(1); exit_func = TOP(); SET_TOP(exc); exc = Py_None; From 627d639ce994d6f21795b645566b2c5823f95b98 Mon Sep 17 00:00:00 2001 From: Costy Petrisor Date: Tue, 31 Jul 2018 17:31:28 +0000 Subject: [PATCH 7/7] used support.TESTFN instead of tempfile.NamedTemporaryFile --- Lib/test/test_lltrace.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_lltrace.py b/Lib/test/test_lltrace.py index 50281b0c045e73f..49fae81eefab9fc 100644 --- a/Lib/test/test_lltrace.py +++ b/Lib/test/test_lltrace.py @@ -1,8 +1,8 @@ import os -import tempfile import textwrap import unittest +from test import support from test.support.script_helper import assert_python_ok @@ -13,9 +13,9 @@ def test_lltrace_does_not_crash_on_subscript_operator(self): # bpo-34113. The crash happened at the command line console of # debug Python builds with __ltrace__ enabled (only possible in console), # when the interal Python stack was negatively adjusted - with tempfile.NamedTemporaryFile(mode='w+', delete=False) as tmp_script: - self.addCleanup(os.remove, tmp_script.name) - tmp_script.write(textwrap.dedent("""\ + with open(support.TESTFN, 'w') as fd: + self.addCleanup(os.unlink, support.TESTFN) + fd.write(textwrap.dedent("""\ import code console = code.InteractiveConsole() @@ -24,9 +24,8 @@ def test_lltrace_does_not_crash_on_subscript_operator(self): console.push('a[0] = 1') print('unreachable if bug exists') """)) - tmp_script.flush() - assert_python_ok(tmp_script.name) + assert_python_ok(support.TESTFN) if __name__ == "__main__": unittest.main()