mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	[3.14] gh-91048: Reorder result tuple of parse_code_object (GH-134898) (#134956)
* gh-91048:  Reorder result tuple of parse_code_object (GH-134898)
Reorder result tuple of parse_code_object
The standard followed by APIs like pstat.Stats is to take a file, line,
function triplet. The parse_code_object function (and callers exposing
this in Python like RemoteUnwinder.get_stack_trace) return function,
file, line triplets which requires the caller to reorder these when
using it in classes like pstat.Stats.
(cherry picked from commit 8e8786f898)
Co-authored-by: László Kiss Kollár <kiss.kollar.laszlo@gmail.com>
* Reorder asyncio
---------
Co-authored-by: László Kiss Kollár <kiss.kollar.laszlo@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
			
			
This commit is contained in:
		
							parent
							
								
									77c4b5d413
								
							
						
					
					
						commit
						f303532857
					
				
					 2 changed files with 42 additions and 42 deletions
				
			
		|  | @ -114,17 +114,17 @@ def foo(): | ||||||
|                 p.wait(timeout=SHORT_TIMEOUT) |                 p.wait(timeout=SHORT_TIMEOUT) | ||||||
| 
 | 
 | ||||||
|             thread_expected_stack_trace = [ |             thread_expected_stack_trace = [ | ||||||
|                 ("foo", script_name, 15), |                 (script_name, 15, "foo"), | ||||||
|                 ("baz", script_name, 12), |                 (script_name, 12, "baz"), | ||||||
|                 ("bar", script_name, 9), |                 (script_name, 9, "bar"), | ||||||
|                 ('Thread.run', threading.__file__, ANY) |                 (threading.__file__, ANY, 'Thread.run') | ||||||
|             ] |             ] | ||||||
|             # Is possible that there are more threads, so we check that the |             # Is possible that there are more threads, so we check that the | ||||||
|             # expected stack traces are in the result (looking at you Windows!) |             # expected stack traces are in the result (looking at you Windows!) | ||||||
|             self.assertIn((ANY, thread_expected_stack_trace), stack_trace) |             self.assertIn((ANY, thread_expected_stack_trace), stack_trace) | ||||||
| 
 | 
 | ||||||
|             # Check that the main thread stack trace is in the result |             # Check that the main thread stack trace is in the result | ||||||
|             frame = ("<module>", script_name, 19) |             frame = (script_name, 19, "<module>") | ||||||
|             for _, stack in stack_trace: |             for _, stack in stack_trace: | ||||||
|                 if frame in stack: |                 if frame in stack: | ||||||
|                     break |                     break | ||||||
|  | @ -222,47 +222,47 @@ def new_eager_loop(): | ||||||
|                 root_task = "Task-1" |                 root_task = "Task-1" | ||||||
|                 expected_stack_trace = [ |                 expected_stack_trace = [ | ||||||
|                     [ |                     [ | ||||||
|                         ("c5", script_name, 10), |                         (script_name, 10, "c5"), | ||||||
|                         ("c4", script_name, 14), |                         (script_name, 14, "c4"), | ||||||
|                         ("c3", script_name, 17), |                         (script_name, 17, "c3"), | ||||||
|                         ("c2", script_name, 20), |                         (script_name, 20, "c2"), | ||||||
|                     ], |                     ], | ||||||
|                     "c2_root", |                     "c2_root", | ||||||
|                     [ |                     [ | ||||||
|                         [ |                         [ | ||||||
|                             [ |                             [ | ||||||
|                                 ( |                                 ( | ||||||
|                                     "TaskGroup._aexit", |  | ||||||
|                                     taskgroups.__file__, |                                     taskgroups.__file__, | ||||||
|                                     ANY, |                                     ANY, | ||||||
|  |                                     "TaskGroup._aexit" | ||||||
|                                 ), |                                 ), | ||||||
|                                 ( |                                 ( | ||||||
|                                     "TaskGroup.__aexit__", |  | ||||||
|                                     taskgroups.__file__, |                                     taskgroups.__file__, | ||||||
|                                     ANY, |                                     ANY, | ||||||
|  |                                     "TaskGroup.__aexit__" | ||||||
|                                 ), |                                 ), | ||||||
|                                 ("main", script_name, 26), |                                 (script_name, 26, "main"), | ||||||
|                             ], |                             ], | ||||||
|                             "Task-1", |                             "Task-1", | ||||||
|                             [], |                             [], | ||||||
|                         ], |                         ], | ||||||
|                         [ |                         [ | ||||||
|                             [("c1", script_name, 23)], |                             [(script_name, 23, "c1")], | ||||||
|                             "sub_main_1", |                             "sub_main_1", | ||||||
|                             [ |                             [ | ||||||
|                                 [ |                                 [ | ||||||
|                                     [ |                                     [ | ||||||
|                                         ( |                                         ( | ||||||
|                                             "TaskGroup._aexit", |  | ||||||
|                                             taskgroups.__file__, |                                             taskgroups.__file__, | ||||||
|                                             ANY, |                                             ANY, | ||||||
|  |                                             "TaskGroup._aexit" | ||||||
|                                         ), |                                         ), | ||||||
|                                         ( |                                         ( | ||||||
|                                             "TaskGroup.__aexit__", |  | ||||||
|                                             taskgroups.__file__, |                                             taskgroups.__file__, | ||||||
|                                             ANY, |                                             ANY, | ||||||
|  |                                             "TaskGroup.__aexit__" | ||||||
|                                         ), |                                         ), | ||||||
|                                         ("main", script_name, 26), |                                         (script_name, 26, "main"), | ||||||
|                                     ], |                                     ], | ||||||
|                                     "Task-1", |                                     "Task-1", | ||||||
|                                     [], |                                     [], | ||||||
|  | @ -270,22 +270,22 @@ def new_eager_loop(): | ||||||
|                             ], |                             ], | ||||||
|                         ], |                         ], | ||||||
|                         [ |                         [ | ||||||
|                             [("c1", script_name, 23)], |                             [(script_name, 23, "c1")], | ||||||
|                             "sub_main_2", |                             "sub_main_2", | ||||||
|                             [ |                             [ | ||||||
|                                 [ |                                 [ | ||||||
|                                     [ |                                     [ | ||||||
|                                         ( |                                         ( | ||||||
|                                             "TaskGroup._aexit", |  | ||||||
|                                             taskgroups.__file__, |                                             taskgroups.__file__, | ||||||
|                                             ANY, |                                             ANY, | ||||||
|  |                                             "TaskGroup._aexit" | ||||||
|                                         ), |                                         ), | ||||||
|                                         ( |                                         ( | ||||||
|                                             "TaskGroup.__aexit__", |  | ||||||
|                                             taskgroups.__file__, |                                             taskgroups.__file__, | ||||||
|                                             ANY, |                                             ANY, | ||||||
|  |                                             "TaskGroup.__aexit__" | ||||||
|                                         ), |                                         ), | ||||||
|                                         ("main", script_name, 26), |                                         (script_name, 26, "main"), | ||||||
|                                     ], |                                     ], | ||||||
|                                     "Task-1", |                                     "Task-1", | ||||||
|                                     [], |                                     [], | ||||||
|  | @ -363,9 +363,9 @@ async def main(): | ||||||
| 
 | 
 | ||||||
|             expected_stack_trace = [ |             expected_stack_trace = [ | ||||||
|                 [ |                 [ | ||||||
|                     ("gen_nested_call", script_name, 10), |                     (script_name, 10, "gen_nested_call"), | ||||||
|                     ("gen", script_name, 16), |                     (script_name, 16, "gen"), | ||||||
|                     ("main", script_name, 19), |                     (script_name, 19, "main"), | ||||||
|                 ], |                 ], | ||||||
|                 "Task-1", |                 "Task-1", | ||||||
|                 [], |                 [], | ||||||
|  | @ -439,9 +439,9 @@ async def main(): | ||||||
|             stack_trace[2].sort(key=lambda x: x[1]) |             stack_trace[2].sort(key=lambda x: x[1]) | ||||||
| 
 | 
 | ||||||
|             expected_stack_trace = [ |             expected_stack_trace = [ | ||||||
|                 [("deep", script_name, 11), ("c1", script_name, 15)], |                 [(script_name, 11, "deep"), (script_name, 15, "c1")], | ||||||
|                 "Task-2", |                 "Task-2", | ||||||
|                 [[[("main", script_name, 21)], "Task-1", []]], |                 [[[(script_name, 21, "main")], "Task-1", []]], | ||||||
|             ] |             ] | ||||||
|             self.assertEqual(stack_trace, expected_stack_trace) |             self.assertEqual(stack_trace, expected_stack_trace) | ||||||
| 
 | 
 | ||||||
|  | @ -515,16 +515,16 @@ async def main(): | ||||||
|             stack_trace[2].sort(key=lambda x: x[1]) |             stack_trace[2].sort(key=lambda x: x[1]) | ||||||
|             expected_stack_trace = [ |             expected_stack_trace = [ | ||||||
|                 [ |                 [ | ||||||
|                     ("deep", script_name, 11), |                     (script_name, 11, "deep"), | ||||||
|                     ("c1", script_name, 15), |                     (script_name, 15, "c1"), | ||||||
|                     ("staggered_race.<locals>.run_one_coro", staggered.__file__, ANY), |                     (staggered.__file__, ANY, "staggered_race.<locals>.run_one_coro"), | ||||||
|                 ], |                 ], | ||||||
|                 "Task-2", |                 "Task-2", | ||||||
|                 [ |                 [ | ||||||
|                     [ |                     [ | ||||||
|                         [ |                         [ | ||||||
|                             ("staggered_race", staggered.__file__, ANY), |                             (staggered.__file__, ANY, "staggered_race"), | ||||||
|                             ("main", script_name, 21), |                             (script_name, 21, "main"), | ||||||
|                         ], |                         ], | ||||||
|                         "Task-1", |                         "Task-1", | ||||||
|                         [], |                         [], | ||||||
|  | @ -662,16 +662,16 @@ async def main(): | ||||||
|                 self.assertIn((ANY, "Task-1", []), entries) |                 self.assertIn((ANY, "Task-1", []), entries) | ||||||
|                 main_stack = [ |                 main_stack = [ | ||||||
|                     ( |                     ( | ||||||
|                         "TaskGroup._aexit", |  | ||||||
|                         taskgroups.__file__, |                         taskgroups.__file__, | ||||||
|                         ANY, |                         ANY, | ||||||
|  |                         "TaskGroup._aexit", | ||||||
|                     ), |                     ), | ||||||
|                     ( |                     ( | ||||||
|                         "TaskGroup.__aexit__", |  | ||||||
|                         taskgroups.__file__, |                         taskgroups.__file__, | ||||||
|                         ANY, |                         ANY, | ||||||
|  |                         "TaskGroup.__aexit__", | ||||||
|                     ), |                     ), | ||||||
|                     ("main", script_name, 60), |                     (script_name, 60, "main"), | ||||||
|                 ] |                 ] | ||||||
|                 self.assertIn( |                 self.assertIn( | ||||||
|                     (ANY, "server task", [[main_stack, ANY]]), |                     (ANY, "server task", [[main_stack, ANY]]), | ||||||
|  | @ -686,16 +686,16 @@ async def main(): | ||||||
|                     [ |                     [ | ||||||
|                         [ |                         [ | ||||||
|                             ( |                             ( | ||||||
|                                 "TaskGroup._aexit", |  | ||||||
|                                 taskgroups.__file__, |                                 taskgroups.__file__, | ||||||
|                                 ANY, |                                 ANY, | ||||||
|  |                                 "TaskGroup._aexit", | ||||||
|                             ), |                             ), | ||||||
|                             ( |                             ( | ||||||
|                                 "TaskGroup.__aexit__", |  | ||||||
|                                 taskgroups.__file__, |                                 taskgroups.__file__, | ||||||
|                                 ANY, |                                 ANY, | ||||||
|  |                                 "TaskGroup.__aexit__", | ||||||
|                             ), |                             ), | ||||||
|                             ("echo_client_spam", script_name, 41), |                             (script_name, 41, "echo_client_spam"), | ||||||
|                         ], |                         ], | ||||||
|                         ANY, |                         ANY, | ||||||
|                     ] |                     ] | ||||||
|  | @ -741,14 +741,14 @@ def test_self_trace(self): | ||||||
|             stack[:2], |             stack[:2], | ||||||
|             [ |             [ | ||||||
|                 ( |                 ( | ||||||
|                     "get_stack_trace", |  | ||||||
|                     __file__, |                     __file__, | ||||||
|                     get_stack_trace.__code__.co_firstlineno + 2, |                     get_stack_trace.__code__.co_firstlineno + 2, | ||||||
|  |                     "get_stack_trace", | ||||||
|                 ), |                 ), | ||||||
|                 ( |                 ( | ||||||
|                     "TestGetStackTrace.test_self_trace", |  | ||||||
|                     __file__, |                     __file__, | ||||||
|                     self.test_self_trace.__code__.co_firstlineno + 6, |                     self.test_self_trace.__code__.co_firstlineno + 6, | ||||||
|  |                     "TestGetStackTrace.test_self_trace", | ||||||
|                 ), |                 ), | ||||||
|             ] |             ] | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  | @ -1562,9 +1562,9 @@ parse_code_object(RemoteUnwinderObject *unwinder, | ||||||
| 
 | 
 | ||||||
|     Py_INCREF(meta->func_name); |     Py_INCREF(meta->func_name); | ||||||
|     Py_INCREF(meta->file_name); |     Py_INCREF(meta->file_name); | ||||||
|     PyTuple_SET_ITEM(tuple, 0, meta->func_name); |     PyTuple_SET_ITEM(tuple, 0, meta->file_name); | ||||||
|     PyTuple_SET_ITEM(tuple, 1, meta->file_name); |     PyTuple_SET_ITEM(tuple, 1, lineno); | ||||||
|     PyTuple_SET_ITEM(tuple, 2, lineno); |     PyTuple_SET_ITEM(tuple, 2, meta->func_name); | ||||||
| 
 | 
 | ||||||
|     *result = tuple; |     *result = tuple; | ||||||
|     return 0; |     return 0; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)