@@ -41,22 +41,6 @@ static inline PyObject* Py_XNewRef(PyObject *obj)
4141#endif
4242
4343
44- // bpo-42522
45- static inline PyObject * __Py_Borrow (PyObject * obj )
46- {
47- Py_DECREF (obj );
48- return obj ;
49- }
50- #define _Py_Borrow (obj ) __Py_Borrow(_PyObject_CAST(obj))
51-
52- static inline PyObject * __Py_XBorrow (PyObject * obj )
53- {
54- Py_XDECREF (obj );
55- return obj ;
56- }
57- #define _Py_XBorrow (obj ) __Py_XBorrow(_PyObject_CAST(obj))
58-
59-
6044// bpo-39573: Py_TYPE(), Py_REFCNT() and Py_SIZE() can no longer be used
6145// as l-value in Python 3.10.
6246#if PY_VERSION_HEX < 0x030900A4
@@ -96,6 +80,14 @@ PyFrame_GetCode(PyFrameObject *frame)
9680}
9781#endif
9882
83+ static inline PyCodeObject *
84+ _PyFrame_GetCodeBorrow (PyFrameObject * frame )
85+ {
86+ PyCodeObject * code = PyFrame_GetCode (frame );
87+ Py_DECREF (code );
88+ return code ; // borrowed reference
89+ }
90+
9991
10092#if PY_VERSION_HEX < 0x030900B1
10193static inline PyFrameObject *
@@ -108,6 +100,14 @@ PyFrame_GetBack(PyFrameObject *frame)
108100}
109101#endif
110102
103+ static inline PyFrameObject *
104+ _PyFrame_GetBackBorrow (PyFrameObject * frame )
105+ {
106+ PyFrameObject * back = PyFrame_GetBack (frame );
107+ Py_XDECREF (back );
108+ return back ; // borrowed reference
109+ }
110+
111111
112112#if PY_VERSION_HEX < 0x030900A5
113113static inline PyInterpreterState *
@@ -130,6 +130,14 @@ PyThreadState_GetFrame(PyThreadState *tstate)
130130}
131131#endif
132132
133+ static inline PyFrameObject *
134+ _PyThreadState_GetFrameBorrow (PyThreadState * tstate )
135+ {
136+ PyFrameObject * frame = PyThreadState_GetFrame (tstate );
137+ Py_XDECREF (frame );
138+ return frame ; // borrowed reference
139+ }
140+
133141
134142#if PY_VERSION_HEX < 0x030900A5
135143static inline PyInterpreterState *
0 commit comments