Skip to content

Commit 5d7e1c0

Browse files
committed
Fix some compiler warnings
1 parent 22f58e7 commit 5d7e1c0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Include/internal/pycore_object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
137137
_Py_AddRefTotal(_PyThreadState_GET(), n);
138138
#endif
139139
#if !defined(Py_GIL_DISABLED)
140+
#if SIZEOF_VOID_P > 4
141+
op->ob_refcnt += (PY_UINT32_T)n;
142+
#else
140143
op->ob_refcnt += n;
144+
#endif
141145
#else
142146
if (_Py_IsOwnedByCurrentThread(op)) {
143147
uint32_t local = op->ob_ref_local;

Include/refcount.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ static inline Py_ALWAYS_INLINE int _Py_IsStaticImmortal(PyObject *op)
142142
PyAPI_FUNC(void) _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt);
143143

144144
static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
145+
assert(refcnt >= 0);
145146
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030d0000
146147
// Stable ABI implements Py_SET_REFCNT() as a function call
147148
// on limited C API version 3.13 and newer.
@@ -154,9 +155,12 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
154155
if (_Py_IsImmortal(ob)) {
155156
return;
156157
}
157-
158158
#ifndef Py_GIL_DISABLED
159+
#if SIZEOF_VOID_P > 4
160+
ob->ob_refcnt = (PY_UINT32_T)refcnt;
161+
#else
159162
ob->ob_refcnt = refcnt;
163+
#endif
160164
#else
161165
if (_Py_IsOwnedByCurrentThread(ob)) {
162166
if ((size_t)refcnt > (size_t)UINT32_MAX) {

0 commit comments

Comments
 (0)