mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
Use union to discriminate pointer types from enum/int types.
This commit is contained in:
parent
83687c98dc
commit
b940671186
2 changed files with 9 additions and 8 deletions
|
|
@ -19,18 +19,22 @@ typedef enum {false, true} bool;
|
|||
|
||||
typedef struct {
|
||||
int size;
|
||||
void *elements[1];
|
||||
union {
|
||||
void *elements[1];
|
||||
unsigned int enum_type[1];
|
||||
} elt;
|
||||
} asdl_seq;
|
||||
|
||||
asdl_seq *asdl_seq_new(int size, PyArena *arena);
|
||||
|
||||
#define asdl_seq_GET(S, I) (S)->elements[(I)]
|
||||
#define asdl_seq_GET(S, I) (S)->elt.elements[(I)]
|
||||
#define asdl_seq_GET_ENUM(S, I) (S)->elt.enum_type[(I)]
|
||||
#define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)
|
||||
#ifdef Py_DEBUG
|
||||
#define asdl_seq_SET(S, I, V) { \
|
||||
int _asdl_i = (I); \
|
||||
assert((S) && _asdl_i < (S)->size); \
|
||||
(S)->elements[_asdl_i] = (V); \
|
||||
(S)->elt.elements[_asdl_i] = (V); \
|
||||
}
|
||||
#else
|
||||
#define asdl_seq_SET(S, I, V) (S)->elements[I] = (V)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue