Skip to content

Commit 90c1852

Browse files
committed
Update PyCode_GetName/FileName usage in torch patch
1 parent 0c84173 commit 90c1852

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

graalpython/lib-graalpython/patches/torch/torch-1.13.1.patch

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,27 @@ index 8c9ed1d7..5183a325 100644
310310
}
311311
}
312312
diff --git a/torch/csrc/jit/python/python_tracer.cpp b/torch/csrc/jit/python/python_tracer.cpp
313-
index 78676e2e..ecc76ea9 100644
313+
index 78676e2e..e6a3caf0 100644
314314
--- a/torch/csrc/jit/python/python_tracer.cpp
315315
+++ b/torch/csrc/jit/python/python_tracer.cpp
316-
@@ -33,8 +33,8 @@ std::vector<StackEntry> _pythonCallstack() {
316+
@@ -33,11 +33,15 @@ std::vector<StackEntry> _pythonCallstack() {
317317
while (nullptr != frame) {
318318
auto code = THPCodeObjectPtr(PyFrame_GetCode(frame));
319319
size_t line = PyCode_Addr2Line(code.get(), PyFrame_GetLasti(frame));
320320
- std::string filename = THPUtils_unpackString(code->co_filename);
321321
- std::string funcname = THPUtils_unpackString(code->co_name);
322-
+ std::string filename = THPUtils_unpackString(PyCode_GetFileName(code));
323-
+ std::string funcname = THPUtils_unpackString(PyCode_GetName(code));
322+
+ PyObject* filenameObj = PyCode_GetFileName(code);
323+
+ std::string filename = THPUtils_unpackString(filenameObj);
324+
+ PyObject* funcnameObj = PyCode_GetName(code);
325+
+ std::string funcname = THPUtils_unpackString(funcnameObj);
324326
auto source = std::make_shared<Source>(funcname, filename, line);
325327
entries.emplace_back(
326328
StackEntry{funcname, SourceRange(source, 0, funcname.size())});
329+
+ Py_DECREF(funcnameObj);
330+
+ Py_DECREF(filenameObj);
331+
auto new_frame = PyFrame_GetBack(frame);
332+
Py_DECREF(frame);
333+
frame = new_frame;
327334
diff --git a/torch/csrc/utils/python_compat.h b/torch/csrc/utils/python_compat.h
328335
index 44911527..d3ad9c54 100644
329336
--- a/torch/csrc/utils/python_compat.h

0 commit comments

Comments
 (0)