Skip to content

Commit 0b92dea

Browse files
mpagemeta-codesync[bot]
authored andcommitted
Add patch '21-jit-frame-safe-get-code' to third-party/python/3.14
Summary: This diff adds a patch to the `third-party/python/3.14` Meta-internal fork. Make _PyFrame_SafeGetCode work with CinderX JIT frames Reviewed By: yoney Differential Revision: D102666061 fbshipit-source-id: fdc741c66641b9207eef06145e7d2934e58d4b7d
1 parent ec8450a commit 0b92dea

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

Include/internal/pycore_interpframe.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ _PyFrame_EnsureFrameFullyInitialized(_PyInterpreterFrame *frame)
3939
return 0;
4040
}
4141

42+
static inline bool _PyFrame_IsExternalFrame(_PyInterpreterFrame *frame)
43+
{
44+
if (PyStackRef_IsNull(frame->f_executable)) {
45+
return false;
46+
}
47+
return PyUnstable_JITExecutable_Check(PyStackRef_AsPyObjectBorrow(frame->f_executable));
48+
}
49+
4250
#endif
4351

4452
static inline PyCodeObject *_PyFrame_GetCode(_PyInterpreterFrame *f) {
@@ -59,12 +67,6 @@ static inline PyCodeObject *_PyFrame_GetCode(_PyInterpreterFrame *f) {
5967
static inline PyCodeObject*
6068
_PyFrame_SafeGetCode(_PyInterpreterFrame *f)
6169
{
62-
// globals and builtins may be NULL on a legit frame, but it's unlikely.
63-
// It's more likely that it's a sign of an invalid frame.
64-
if (f->f_globals == NULL || f->f_builtins == NULL) {
65-
return NULL;
66-
}
67-
6870
if (PyStackRef_IsNull(f->f_executable)) {
6971
return NULL;
7072
}
@@ -78,13 +80,20 @@ _PyFrame_SafeGetCode(_PyInterpreterFrame *f)
7880
return NULL;
7981
}
8082
#ifdef META_PYTHON
81-
if (PyUnstable_JITExecutable_Check(executable)) {
83+
if (_PyFrame_IsExternalFrame(f)) {
8284
executable = (PyObject *)((PyUnstable_PyJitExecutable *)executable)->je_code;
8385
if (_PyObject_IsFreed(executable)) {
8486
return NULL;
8587
}
86-
}
88+
} else
8789
#endif
90+
{
91+
// globals and builtins may be NULL on a legit frame, but it's unlikely.
92+
// It's more likely that it's a sign of an invalid frame.
93+
if (f->f_globals == NULL || f->f_builtins == NULL) {
94+
return NULL;
95+
}
96+
}
8897
if (!PyCode_Check(executable)) {
8998
return NULL;
9099
}

0 commit comments

Comments
 (0)