Skip to content

Commit 7bae15c

Browse files
authored
Use _Py_RVALUE() in macros (python#99844)
The following macros are modified to use _Py_RVALUE(), so they can no longer be used as l-value: * DK_LOG_SIZE() * _PyCode_CODE() * _PyList_ITEMS() * _PyTuple_ITEMS() * _Py_SLIST_HEAD() * _Py_SLIST_ITEM_NEXT() _PyCode_CODE() is private and other macros are part of the internal C API.
1 parent 6541798 commit 7bae15c

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

Include/cpython/code.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static inline Py_ssize_t PyCode_GetNumFree(PyCodeObject *op) {
153153
return op->co_nfreevars;
154154
}
155155

156-
#define _PyCode_CODE(CO) ((_Py_CODEUNIT *)(CO)->co_code_adaptive)
156+
#define _PyCode_CODE(CO) _Py_RVALUE((_Py_CODEUNIT *)(CO)->co_code_adaptive)
157157
#define _PyCode_NBYTES(CO) (Py_SIZE(CO) * (Py_ssize_t)sizeof(_Py_CODEUNIT))
158158

159159
/* Public interface */

Include/internal/pycore_dict.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ struct _dictvalues {
122122
PyObject *values[1];
123123
};
124124

125-
#define DK_LOG_SIZE(dk) ((dk)->dk_log2_size)
125+
#define DK_LOG_SIZE(dk) _Py_RVALUE((dk)->dk_log2_size)
126126
#if SIZEOF_VOID_P > 4
127127
#define DK_SIZE(dk) (((int64_t)1)<<DK_LOG_SIZE(dk))
128128
#else

Include/internal/pycore_hashtable.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ typedef struct {
1818
_Py_slist_item_t *head;
1919
} _Py_slist_t;
2020

21-
#define _Py_SLIST_ITEM_NEXT(ITEM) (((_Py_slist_item_t *)(ITEM))->next)
21+
#define _Py_SLIST_ITEM_NEXT(ITEM) _Py_RVALUE(((_Py_slist_item_t *)(ITEM))->next)
2222

23-
#define _Py_SLIST_HEAD(SLIST) (((_Py_slist_t *)(SLIST))->head)
23+
#define _Py_SLIST_HEAD(SLIST) _Py_RVALUE(((_Py_slist_t *)(SLIST))->head)
2424

2525

2626
/* _Py_hashtable: table entry */

Include/internal/pycore_list.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct _Py_list_state {
3535
#endif
3636
};
3737

38-
#define _PyList_ITEMS(op) (_PyList_CAST(op)->ob_item)
38+
#define _PyList_ITEMS(op) _Py_RVALUE(_PyList_CAST(op)->ob_item)
3939

4040
extern int
4141
_PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem);

Include/internal/pycore_tuple.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct _Py_tuple_state {
6262
#endif
6363
};
6464

65-
#define _PyTuple_ITEMS(op) (_PyTuple_CAST(op)->ob_item)
65+
#define _PyTuple_ITEMS(op) _Py_RVALUE(_PyTuple_CAST(op)->ob_item)
6666

6767
extern PyObject *_PyTuple_FromArray(PyObject *const *, Py_ssize_t);
6868
extern PyObject *_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t);

0 commit comments

Comments
 (0)