Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b7e660

Browse files
committed
_Py_Borrow casts its argument to PyObject*
1 parent 4fa27a1 commit 1b7e660

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

pythoncapi_compat.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ extern "C" {
1919
#include "frameobject.h" // PyFrameObject, PyFrame_GetBack()
2020

2121

22+
// Cast argument to PyObject* type.
23+
#ifndef _PyObject_CAST
24+
# define _PyObject_CAST(op) ((PyObject*)(op))
25+
#endif
26+
27+
2228
// bpo-42262 added Py_NewRef() and Py_XNewRef() to Python 3.10.0a3
2329
#if PY_VERSION_HEX < 0x030a00A3
2430
static inline PyObject* Py_NewRef(PyObject *obj)
@@ -36,17 +42,19 @@ static inline PyObject* Py_XNewRef(PyObject *obj)
3642

3743

3844
// bpo-42522
39-
static inline PyObject* _Py_Borrow(PyObject *obj)
45+
static inline PyObject* __Py_Borrow(PyObject *obj)
4046
{
4147
Py_DECREF(obj);
4248
return obj;
4349
}
50+
#define _Py_Borrow(obj) __Py_Borrow(_PyObject_CAST(obj))
4451

45-
static inline PyObject* _Py_XBorrow(PyObject *obj)
52+
static inline PyObject* __Py_XBorrow(PyObject *obj)
4653
{
4754
Py_XDECREF(obj);
4855
return obj;
4956
}
57+
#define _Py_XBorrow(obj) __Py_XBorrow(_PyObject_CAST(obj))
5058

5159

5260
// bpo-39573: Py_TYPE(), Py_REFCNT() and Py_SIZE() can no longer be used

0 commit comments

Comments
 (0)