From d4b785a6a70d049b5ea9a5d3d44f9a7d2fab72e4 Mon Sep 17 00:00:00 2001 From: William Wen Date: Fri, 26 Sep 2025 14:58:20 -0700 Subject: [PATCH] [dynamo, 3.14] fix stack ref copy error (#163796) Pull Request resolved: https://github.com/pytorch/pytorch/pull/163796 Approved by: https://github.com/anijain2305 ghstack dependencies: #161838, #161555, #161839, #163009, #163109, #163110, #163191, #163292 --- torch/csrc/dynamo/eval_frame.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/torch/csrc/dynamo/eval_frame.c b/torch/csrc/dynamo/eval_frame.c index c8036a54e0ce..3e77c8ccbdce 100644 --- a/torch/csrc/dynamo/eval_frame.c +++ b/torch/csrc/dynamo/eval_frame.c @@ -229,11 +229,7 @@ const char* get_frame_name(THP_EVAL_API_FRAME_OBJECT* frame) { #if IS_PYTHON_3_14_PLUS static void dup_obj(_PyStackRef* dst, _PyStackRef src) { - if (PyStackRef_IsNull(src)) { - *dst = (_PyStackRef){0}; - } else { - *dst = PyStackRef_DUP(src); - } + *dst = PyStackRef_DUP(src); } #else static void dup_obj(PyObject** dst, PyObject* src) { @@ -502,13 +498,19 @@ PyObject* dynamo_eval_custom_code( THP_EVAL_API_FRAME_OBJECT* frame, PyCodeObject* code, const char* trace_annotation, - int throw_flag) { return NULL; } + int throw_flag) { + return NULL; +} THPPyInterpreterFrame* THPPyInterpreterFrame_New( - THP_EVAL_API_FRAME_OBJECT* frame) { return NULL; } + THP_EVAL_API_FRAME_OBJECT* frame) { + return NULL; +} PyObject* dynamo_eval_frame_default( PyThreadState* tstate, THP_EVAL_API_FRAME_OBJECT* frame, - int throw_flag) { return NULL; } + int throw_flag) { + return NULL; +} static struct PyGetSetDef THPPyInterpreterFrame_properties[] = {{NULL}}; @@ -565,9 +567,7 @@ static PyObject* decrement_working_threads( Py_RETURN_NONE; } -static PyObject* set_eval_frame( - PyObject* new_callback, - PyObject* module) { +static PyObject* set_eval_frame(PyObject* new_callback, PyObject* module) { // Change the eval frame callback and return the old one // - None: disables TorchDynamo // - False: run-only mode (reuse existing compiles) @@ -587,8 +587,8 @@ static PyObject* set_eval_frame( Py_INCREF(new_callback); - // Set thread local callback. This will drive behavior of our shim, if/when it - // is installed. + // Set thread local callback. This will drive behavior of our shim, if/when + // it is installed. eval_frame_callback_set(new_callback); // Transfer owned reference from eval_frame_callback_get() to caller