diff --git a/Include/cpython/object.h b/Include/cpython/object.h index f4755a7b2fb852..b5779065093b03 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -325,9 +325,9 @@ PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *); */ #define Py_SETREF(dst, src) \ do { \ - PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \ - PyObject *_tmp_dst = (*_tmp_dst_ptr); \ - *_tmp_dst_ptr = _PyObject_CAST(src); \ + _PY_TYPEOF(dst)* _tmp_dst_ptr = &(dst); \ + _PY_TYPEOF(dst) _tmp_dst = *_tmp_dst_ptr; \ + *_tmp_dst_ptr = (src); \ Py_DECREF(_tmp_dst); \ } while (0) @@ -336,9 +336,9 @@ PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *); */ #define Py_XSETREF(dst, src) \ do { \ - PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \ - PyObject *_tmp_dst = (*_tmp_dst_ptr); \ - *_tmp_dst_ptr = _PyObject_CAST(src); \ + _PY_TYPEOF(dst)* _tmp_dst_ptr = &(dst); \ + _PY_TYPEOF(dst) _tmp_dst = *_tmp_dst_ptr; \ + *_tmp_dst_ptr = (src); \ Py_XDECREF(_tmp_dst); \ } while (0) diff --git a/Include/object.h b/Include/object.h index a2ed0bd2349f2a..4eb4eaa8701fbb 100644 --- a/Include/object.h +++ b/Include/object.h @@ -604,9 +604,9 @@ static inline void Py_DECREF(PyObject *op) */ #define Py_CLEAR(op) \ do { \ - PyObject **_py_tmp_ptr = _Py_CAST(PyObject**, &(op)); \ + _PY_TYPEOF(op)* _py_tmp_ptr = &(op); \ if (*_py_tmp_ptr != NULL) { \ - PyObject* _py_tmp = (*_py_tmp_ptr); \ + _PY_TYPEOF(op) _py_tmp = *_py_tmp_ptr; \ *_py_tmp_ptr = NULL; \ Py_DECREF(_py_tmp); \ } \ diff --git a/Include/pyport.h b/Include/pyport.h index b3ff2f4882e90f..f743e40cb6c620 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -717,4 +717,7 @@ extern char * _getpty(int *, int, mode_t, int); # endif #endif +// Get the type of an expression +#define _PY_TYPEOF(EXPR) __typeof__(EXPR) + #endif /* Py_PYPORT_H */