Skip to content

Commit 6239435

Browse files
committed
Document that safe functions are not 100% reliable
1 parent 3764548 commit 6239435

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Include/internal/pycore_code.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@ PyAPI_FUNC(int) _PyLineTable_NextAddressRange(PyCodeAddressRange *range);
276276
extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
277277

278278
// Similar to PyCode_Addr2Line(), but return -1 if the code object is invalid
279-
// and can be called without an attached tstate.
280-
// Used by dump_frame() in Python/traceback.c.
279+
// and can be called without an attached tstate. Used by dump_frame() in
280+
// Python/traceback.c. The function uses heuristics to detect freed memory,
281+
// it's not 100% reliable.
281282
extern int _PyCode_SafeAddr2Line(PyCodeObject *co, int addr);
282283

283284

Include/internal/pycore_interpframe.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ static inline PyCodeObject *_PyFrame_GetCode(_PyInterpreterFrame *f) {
2525
}
2626

2727
// Similar to _PyFrame_GetCode(), but return NULL if the frame is invalid or
28-
// freed. Used by dump_frame() in Python/traceback.c.
28+
// freed. Used by dump_frame() in Python/traceback.c. The function uses
29+
// heuristics to detect freed memory, it's not 100% reliable.
2930
static inline PyCodeObject*
3031
_PyFrame_SafeGetCode(_PyInterpreterFrame *f)
3132
{
@@ -66,9 +67,9 @@ _PyFrame_GetBytecode(_PyInterpreterFrame *f)
6667
#endif
6768
}
6869

69-
// Similar to PyUnstable_InterpreterFrame_GetLasti(), but return NULL
70-
// if the frame is invalid or freed.
71-
// Used by dump_frame() in Python/traceback.c.
70+
// Similar to PyUnstable_InterpreterFrame_GetLasti(), but return NULL if the
71+
// frame is invalid or freed. Used by dump_frame() in Python/traceback.c. The
72+
// function uses heuristics to detect freed memory, it's not 100% reliable.
7273
static inline int
7374
_PyFrame_SafeGetLasti(struct _PyInterpreterFrame *f)
7475
{

0 commit comments

Comments
 (0)