@@ -1697,155 +1697,6 @@ def test_multiple_labels(self):
16971697 }
16981698 """
16991699
1700- class TestGeneratedTailCallErorHandlers (unittest .TestCase ):
1701- def setUp (self ) -> None :
1702- super ().setUp ()
1703- self .maxDiff = None
1704-
1705- self .temp_dir = tempfile .gettempdir ()
1706- self .temp_input_filename = os .path .join (self .temp_dir , "input.txt" )
1707- self .temp_output_filename = os .path .join (self .temp_dir , "output.txt" )
1708- self .temp_metadata_filename = os .path .join (self .temp_dir , "metadata.txt" )
1709- self .temp_pymetadata_filename = os .path .join (self .temp_dir , "pymetadata.txt" )
1710- self .temp_executor_filename = os .path .join (self .temp_dir , "executor.txt" )
1711-
1712- def tearDown (self ) -> None :
1713- for filename in [
1714- self .temp_input_filename ,
1715- self .temp_output_filename ,
1716- self .temp_metadata_filename ,
1717- self .temp_pymetadata_filename ,
1718- self .temp_executor_filename ,
1719- ]:
1720- try :
1721- os .remove (filename )
1722- except :
1723- pass
1724- super ().tearDown ()
1725-
1726- def run_cases_test (self , input : str , expected : str ):
1727- with open (self .temp_input_filename , "w+" ) as temp_input :
1728- temp_input .write (textwrap .dedent (input ))
1729- temp_input .flush ()
1730-
1731- with handle_stderr ():
1732- tier1_tail_call_generator .generate_label_handlers_from_files (
1733- self .temp_input_filename , self .temp_output_filename
1734- )
1735-
1736- with open (self .temp_output_filename ) as temp_output :
1737- lines = temp_output .readlines ()
1738- while lines and lines [0 ].startswith (("// " , "#" , " #" , "\n " )):
1739- lines .pop (0 )
1740- while lines and lines [- 1 ].startswith (("#" , "\n " )):
1741- lines .pop (- 1 )
1742- actual = "" .join (lines )
1743-
1744- self .assertEqual (actual .strip (), textwrap .dedent (expected ).strip ())
1745-
1746- def test_correctly_finds_pyeval_framedefault (self ):
1747- input = """
1748- PyObject* _Py_HOT_FUNCTION
1749- _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
1750- {
1751-
1752- /* END_BASE_INTERPRETER */
1753- }
1754- """
1755- output = """
1756- """
1757- self .run_cases_test (input , output )
1758-
1759- def test_simple_label (self ):
1760- input = """
1761- PyObject* _Py_HOT_FUNCTION
1762- _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
1763- {
1764-
1765- TAIL_CALL_TARGET(error):
1766- DO_THING();
1767- /* END_BASE_INTERPRETER */
1768- }
1769- """
1770- output = """
1771- Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_error(TAIL_CALL_PARAMS);
1772-
1773- Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_error(TAIL_CALL_PARAMS)
1774- {
1775- DO_THING();
1776- /* END_BASE_INTERPRETER */
1777- }
1778- """
1779- self .run_cases_test (input , output )
1780-
1781- def test_fallthrough_label (self ):
1782- input = """
1783- PyObject* _Py_HOT_FUNCTION
1784- _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
1785- {
1786-
1787- TAIL_CALL_TARGET(error):
1788- DO_THING();
1789- TAIL_CALL_TARGET(fallthrough):
1790- DO_THING2();
1791- /* END_BASE_INTERPRETER */
1792- }
1793- """
1794- output = """
1795- Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_error(TAIL_CALL_PARAMS);
1796- Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_fallthrough(TAIL_CALL_PARAMS);
1797-
1798- Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_error(TAIL_CALL_PARAMS)
1799- {
1800- DO_THING();
1801- TAIL_CALL(fallthrough);
1802- }
1803-
1804- Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_fallthrough(TAIL_CALL_PARAMS)
1805- {
1806- DO_THING2();
1807- /* END_BASE_INTERPRETER */
1808- }
1809- """
1810- self .run_cases_test (input , output )
1811-
1812- def test_transform_gotos (self ):
1813- input = """
1814- PyObject* _Py_HOT_FUNCTION
1815- _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
1816- {
1817-
1818- TAIL_CALL_TARGET(error):
1819- if (thing) {
1820- goto fallthrough;
1821- }
1822- DO_THING();
1823- TAIL_CALL_TARGET(fallthrough):
1824- DO_THING2();
1825- /* END_BASE_INTERPRETER */
1826- }
1827- """
1828- output = """
1829- Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_error(TAIL_CALL_PARAMS);
1830- Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_fallthrough(TAIL_CALL_PARAMS);
1831-
1832- Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_error(TAIL_CALL_PARAMS)
1833- {
1834- if (thing) {
1835- TAIL_CALL(fallthrough);
1836- }
1837- DO_THING();
1838- TAIL_CALL(fallthrough);
1839- }
1840-
1841- Py_PRESERVE_NONE_CC static PyObject *_TAIL_CALL_fallthrough(TAIL_CALL_PARAMS)
1842- {
1843- DO_THING2();
1844- /* END_BASE_INTERPRETER */
1845- }
1846- """
1847- self .run_cases_test (input , output )
1848-
18491700
18501701class TestGeneratedAbstractCases (unittest .TestCase ):
18511702 def setUp (self ) -> None :
0 commit comments