Files
typthon/Include/internal/pycore_asdl.h
copilot-swe-agent[bot] 42e2356c88 Fix incorrect replacements in Py_ to Ty_ renaming
Fixed several macros and constants that should not have been renamed:
- _Py_CAST, _Py_NULL, _Py_RVALUE (internal utility macros)
- Py_UNUSED (unused parameter macro)
- Py_EQ, Py_NE, Py_LT, Py_LE, Py_GT, Py_GE (comparison constants)
- Py_RETURN_* macros (NONE, TRUE, FALSE, NOTIMPLEMENTED, RICHCOMPARE)
- Py_READONLY, Py_ULL, Py_CONTEXT_SWITCHED
- TyGC_Head in generated clinic files

Build is still in progress with some remaining issues to resolve.

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
2025-12-29 17:44:05 +00:00

113 lines
3.0 KiB
C

#ifndef Ty_INTERNAL_ASDL_H
#define Ty_INTERNAL_ASDL_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Ty_BUILD_CORE
# error "this header requires Ty_BUILD_CORE define"
#endif
#include "pycore_pyarena.h" // _TyArena_Malloc()
typedef TyObject * identifier;
typedef TyObject * string;
typedef TyObject * object;
typedef TyObject * constant;
/* It would be nice if the code generated by asdl_c.py was completely
independent of Python, but it is a goal the requires too much work
at this stage. So, for example, I'll represent identifiers as
interned Python strings.
*/
#define _ASDL_SEQ_HEAD \
Ty_ssize_t size; \
void **elements;
typedef struct {
_ASDL_SEQ_HEAD
} asdl_seq;
typedef struct {
_ASDL_SEQ_HEAD
void *typed_elements[1];
} asdl_generic_seq;
typedef struct {
_ASDL_SEQ_HEAD
TyObject *typed_elements[1];
} asdl_identifier_seq;
typedef struct {
_ASDL_SEQ_HEAD
int typed_elements[1];
} asdl_int_seq;
asdl_generic_seq *_Ty_asdl_generic_seq_new(Ty_ssize_t size, PyArena *arena);
asdl_identifier_seq *_Ty_asdl_identifier_seq_new(Ty_ssize_t size, PyArena *arena);
asdl_int_seq *_Ty_asdl_int_seq_new(Ty_ssize_t size, PyArena *arena);
#define GENERATE_ASDL_SEQ_CONSTRUCTOR(NAME, TYPE) \
asdl_ ## NAME ## _seq *_Ty_asdl_ ## NAME ## _seq_new(Ty_ssize_t size, PyArena *arena) \
{ \
asdl_ ## NAME ## _seq *seq = NULL; \
size_t n; \
/* check size is sane */ \
if (size < 0 || \
(size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) { \
TyErr_NoMemory(); \
return NULL; \
} \
n = (size ? (sizeof(TYPE *) * (size - 1)) : 0); \
/* check if size can be added safely */ \
if (n > SIZE_MAX - sizeof(asdl_ ## NAME ## _seq)) { \
TyErr_NoMemory(); \
return NULL; \
} \
n += sizeof(asdl_ ## NAME ## _seq); \
seq = (asdl_ ## NAME ## _seq *)_TyArena_Malloc(arena, n); \
if (!seq) { \
TyErr_NoMemory(); \
return NULL; \
} \
memset(seq, 0, n); \
seq->size = size; \
seq->elements = (void**)seq->typed_elements; \
return seq; \
}
#define asdl_seq_GET_UNTYPED(S, I) _Py_RVALUE((S)->elements[(I)])
#define asdl_seq_GET(S, I) _Py_RVALUE((S)->typed_elements[(I)])
#define asdl_seq_LEN(S) _Py_RVALUE(((S) == NULL ? 0 : (S)->size))
#ifdef Ty_DEBUG
# define asdl_seq_SET(S, I, V) \
do { \
Ty_ssize_t _asdl_i = (I); \
assert((S) != NULL); \
assert(0 <= _asdl_i && _asdl_i < (S)->size); \
(S)->typed_elements[_asdl_i] = (V); \
} while (0)
#else
# define asdl_seq_SET(S, I, V) _Py_RVALUE((S)->typed_elements[(I)] = (V))
#endif
#ifdef Ty_DEBUG
# define asdl_seq_SET_UNTYPED(S, I, V) \
do { \
Ty_ssize_t _asdl_i = (I); \
assert((S) != NULL); \
assert(0 <= _asdl_i && _asdl_i < (S)->size); \
(S)->elements[_asdl_i] = (V); \
} while (0)
#else
# define asdl_seq_SET_UNTYPED(S, I, V) _Py_RVALUE((S)->elements[(I)] = (V))
#endif
#ifdef __cplusplus
}
#endif
#endif /* !Ty_INTERNAL_ASDL_H */