Skip to content

Commit b5568d7

Browse files
Remove anonymous union from PyObject V2
1 parent eaff9c3 commit b5568d7

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

Include/object.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ check by comparing the reference count field to the immortality reference count.
131131
#define PyObject_HEAD_INIT(type) \
132132
{ \
133133
_PyObject_EXTRA_INIT \
134-
{ _Py_IMMORTAL_REFCNT }, \
134+
_Py_IMMORTAL_REFCNT, \
135135
(type) \
136136
},
137137
#else
138138
#define PyObject_HEAD_INIT(type) \
139139
{ \
140140
_PyObject_EXTRA_INIT \
141-
{ 1 }, \
141+
1, \
142142
(type) \
143143
},
144144
#endif /* Py_BUILD_CORE */
@@ -165,12 +165,7 @@ check by comparing the reference count field to the immortality reference count.
165165
*/
166166
struct _object {
167167
_PyObject_HEAD_EXTRA
168-
union {
169-
Py_ssize_t ob_refcnt;
170-
#if SIZEOF_VOID_P > 4
171-
PY_UINT32_T ob_refcnt_split[2];
172-
#endif
173-
};
168+
Py_ssize_t ob_refcnt;
174169
PyTypeObject *ob_type;
175170
};
176171

@@ -624,12 +619,11 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
624619
// directly PyObject.ob_refcnt.
625620
#if SIZEOF_VOID_P > 4
626621
// Portable saturated add, branching on the carry flag and set low bits
627-
PY_UINT32_T cur_refcnt = op->ob_refcnt_split[PY_BIG_ENDIAN];
628-
PY_UINT32_T new_refcnt = cur_refcnt + 1;
629-
if (new_refcnt == 0) {
622+
Py_ssize_t new_refcnt = op->ob_refcnt + 1;
623+
if ((PY_UINT32_T)new_refcnt == 0) {
630624
return;
631625
}
632-
op->ob_refcnt_split[PY_BIG_ENDIAN] = new_refcnt;
626+
op->ob_refcnt = new_refcnt;
633627
#else
634628
// Explicitly check immortality against the immortal value
635629
if (_Py_IsImmortal(op)) {

Objects/object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ PyTypeObject _PyNone_Type = {
18761876

18771877
PyObject _Py_NoneStruct = {
18781878
_PyObject_EXTRA_INIT
1879-
{ _Py_IMMORTAL_REFCNT },
1879+
_Py_IMMORTAL_REFCNT,
18801880
&_PyNone_Type
18811881
};
18821882

@@ -1979,7 +1979,7 @@ PyTypeObject _PyNotImplemented_Type = {
19791979

19801980
PyObject _Py_NotImplementedStruct = {
19811981
_PyObject_EXTRA_INIT
1982-
{ _Py_IMMORTAL_REFCNT },
1982+
_Py_IMMORTAL_REFCNT,
19831983
&_PyNotImplemented_Type
19841984
};
19851985

Objects/setobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2544,6 +2544,6 @@ static PyTypeObject _PySetDummy_Type = {
25442544

25452545
static PyObject _dummy_struct = {
25462546
_PyObject_EXTRA_INIT
2547-
{ _Py_IMMORTAL_REFCNT },
2547+
_Py_IMMORTAL_REFCNT,
25482548
&_PySetDummy_Type
25492549
};

Objects/sliceobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ PyTypeObject PyEllipsis_Type = {
9999

100100
PyObject _Py_EllipsisObject = {
101101
_PyObject_EXTRA_INIT
102-
{ _Py_IMMORTAL_REFCNT },
102+
_Py_IMMORTAL_REFCNT,
103103
&PyEllipsis_Type
104104
};
105105

0 commit comments

Comments
 (0)