Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-127545: Replace _Py_ALIGN_AS(V) by _Py_ALIGNED_DEF(N, T)#135209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
encukou merged 6 commits intopython:mainfromencukou:gc_crash
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Replace _Py_ALIGN_AS(V) by _Py_ALIGNED_DEF(N, T)
This is a common façade for the various `_Alignas` alternatives,which behave in interesting ways.The standard `alignas` errors if it would decrease the alignment;to prevent that it can be used again with the defined variable'stype.The standard `alignas` can't be used on a `struct` definition,the workaround is to use it on one of the `struct`'s members.MSVC `declspec(aligned)` only takes integer literals.MSVC `declspec(aligned)` had a bug when applied to a combinedstruct+member definition.The workaround is to separate the struct definition.Do that for `PyASCIIObject.state`.
  • Loading branch information
@encukou
encukou committedJun 6, 2025
commite0156b0516ac4d125e480b81990eaf6549f193dc
13 changes: 0 additions & 13 deletionsInclude/Python.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -59,14 +59,6 @@
# include <intrin.h> // __readgsqword()
#endif

// Suppress known warnings in Python header files.
#if defined(_MSC_VER)
// Warning that alignas behaviour has changed. Doesn't affect us, because we
// never relied on the old behaviour.
#pragma warning(push)
#pragma warning(disable: 5274)
#endif

// Include Python header files
#include "pyport.h"
#include "pymacro.h"
Expand DownExpand Up@@ -146,9 +138,4 @@
#include "cpython/pyfpe.h"
#include "cpython/tracemalloc.h"

// Restore warning filter
#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif /* !Py_PYTHON_H */
120 changes: 59 additions & 61 deletionsInclude/cpython/unicodeobject.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,63 @@ static inline Py_UCS4 Py_UNICODE_LOW_SURROGATE(Py_UCS4 ch) {

/* --- Unicode Type ------------------------------------------------------- */

struct _PyUnicodeObject_state {
/* If interned is non-zero, the two references from the
dictionary to this object are *not* counted in ob_refcnt.
The possible values here are:
0: Not Interned
1: Interned
2: Interned and Immortal
3: Interned, Immortal, and Static
This categorization allows the runtime to determine the right
cleanup mechanism at runtime shutdown. */
#ifdef Py_GIL_DISABLED
// Needs to be accessed atomically, so can't be a bit field.
unsigned char interned;
#else
unsigned int interned:2;
#endif
/* Character size:

- PyUnicode_1BYTE_KIND (1):

* character type = Py_UCS1 (8 bits, unsigned)
* all characters are in the range U+0000-U+00FF (latin1)
* if ascii is set, all characters are in the range U+0000-U+007F
(ASCII), otherwise at least one character is in the range
U+0080-U+00FF

- PyUnicode_2BYTE_KIND (2):

* character type = Py_UCS2 (16 bits, unsigned)
* all characters are in the range U+0000-U+FFFF (BMP)
* at least one character is in the range U+0100-U+FFFF

- PyUnicode_4BYTE_KIND (4):

* character type = Py_UCS4 (32 bits, unsigned)
* all characters are in the range U+0000-U+10FFFF
* at least one character is in the range U+10000-U+10FFFF
*/
unsigned int kind:3;
/* Compact is with respect to the allocation scheme. Compact unicode
objects only require one memory block while non-compact objects use
one block for the PyUnicodeObject struct and another for its data
buffer. */
unsigned int compact:1;
/* The string only contains characters in the range U+0000-U+007F (ASCII)
and the kind is PyUnicode_1BYTE_KIND. If ascii is set and compact is
set, use the PyASCIIObject structure. */
unsigned int ascii:1;
/* The object is statically allocated. */
unsigned int statically_allocated:1;
#ifndef Py_GIL_DISABLED
/* Historical: padding to ensure that PyUnicode_DATA() is always aligned to
4 bytes (see issue gh-63736 on m68k) */
unsigned int :24;
#endif
};

/* ASCII-only strings created through PyUnicode_New use the PyASCIIObject
structure. state.ascii and state.compact are set, and the data
immediately follow the structure. utf8_length can be found
Expand DownExpand Up@@ -99,67 +156,8 @@ typedef struct {
PyObject_HEAD
Py_ssize_t length; /* Number of code points in the string */
Py_hash_t hash; /* Hash value; -1 if not set */
#ifdef Py_GIL_DISABLED
/* Ensure 4 byte alignment for PyUnicode_DATA(), see gh-63736 on m68k.
In the non-free-threaded build, we'll use explicit padding instead */
_Py_ALIGN_AS(4)
#endif
struct {
/* If interned is non-zero, the two references from the
dictionary to this object are *not* counted in ob_refcnt.
The possible values here are:
0: Not Interned
1: Interned
2: Interned and Immortal
3: Interned, Immortal, and Static
This categorization allows the runtime to determine the right
cleanup mechanism at runtime shutdown. */
#ifdef Py_GIL_DISABLED
// Needs to be accessed atomically, so can't be a bit field.
unsigned char interned;
#else
unsigned int interned:2;
#endif
/* Character size:

- PyUnicode_1BYTE_KIND (1):

* character type = Py_UCS1 (8 bits, unsigned)
* all characters are in the range U+0000-U+00FF (latin1)
* if ascii is set, all characters are in the range U+0000-U+007F
(ASCII), otherwise at least one character is in the range
U+0080-U+00FF

- PyUnicode_2BYTE_KIND (2):

* character type = Py_UCS2 (16 bits, unsigned)
* all characters are in the range U+0000-U+FFFF (BMP)
* at least one character is in the range U+0100-U+FFFF

- PyUnicode_4BYTE_KIND (4):

* character type = Py_UCS4 (32 bits, unsigned)
* all characters are in the range U+0000-U+10FFFF
* at least one character is in the range U+10000-U+10FFFF
*/
unsigned int kind:3;
/* Compact is with respect to the allocation scheme. Compact unicode
objects only require one memory block while non-compact objects use
one block for the PyUnicodeObject struct and another for its data
buffer. */
unsigned int compact:1;
/* The string only contains characters in the range U+0000-U+007F (ASCII)
and the kind is PyUnicode_1BYTE_KIND. If ascii is set and compact is
set, use the PyASCIIObject structure. */
unsigned int ascii:1;
/* The object is statically allocated. */
unsigned int statically_allocated:1;
#ifndef Py_GIL_DISABLED
/* Padding to ensure that PyUnicode_DATA() is always aligned to
4 bytes (see issue gh-63736 on m68k) */
unsigned int :24;
#endif
} state;
/* Ensure 4 byte alignment for PyUnicode_DATA(), see gh-63736 on m68k. */
_Py_ALIGNED_DEF(4, struct _PyUnicodeObject_state) state;
} PyASCIIObject;

/* Non-ASCII strings allocated through PyUnicode_New use the
Expand Down
4 changes: 2 additions & 2 deletionsInclude/internal/pycore_interp_structs.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -159,13 +159,13 @@ struct atexit_state {
typedef struct {
// Tagged pointer to next object in the list.
// 0 means the object is not tracked
uintptr_t _gc_next;
_Py_ALIGNED_DEF(1 << _PyObject_ALIGNMENT_SHIFT,uintptr_t) _gc_next;

// Tagged pointer to previous object in the list.
// Lowest two bits are used for flags documented later.
// Those bits are made available by the struct's minimum alignment.
uintptr_t _gc_prev;
} PyGC_Head Py_ALIGNED(1 << _PyObject_ALIGNMENT_SHIFT);
} PyGC_Head;

#define _PyGC_Head_UNUSED PyGC_Head

Expand Down
7 changes: 4 additions & 3 deletionsInclude/object.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -141,13 +141,14 @@
#else
Py_ssize_t ob_refcnt;
#endif
_Py_ALIGNED_DEF(1 << _PyObject_ALIGNMENT_SHIFT, char) _aligner;

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

syntax error: '<<' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

syntax error: '<<' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

syntax error: '<<' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

syntax error: '<<' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

'__declspec(constant)' is not a recognized extended attribute [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

'__declspec(constant)' is not a recognized extended attribute [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

'__declspec(constant)' is not a recognized extended attribute [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

'__declspec(constant)' is not a recognized extended attribute [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

syntax error: ')' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

syntax error: ')' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

syntax error: '<<' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

syntax error: '<<' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

syntax error: '<<' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

syntax error: '<<' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

'__declspec(constant)' is not a recognized extended attribute [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

'__declspec(constant)' is not a recognized extended attribute [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

'__declspec(constant)' is not a recognized extended attribute [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

'__declspec(constant)' is not a recognized extended attribute [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 144 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]
};
#ifdef _MSC_VER
__pragma(warning(pop))
#endif

PyTypeObject *ob_type;
} Py_ALIGNED(1 << _PyObject_ALIGNMENT_SHIFT);
};
#else
// Objects that are not owned by any thread use a thread id (tid) of zero.
// This includes both immortal objects and objects whose reference count
Expand All@@ -158,14 +159,14 @@
// ob_tid stores the thread id (or zero). It is also used by the GC and the
// trashcan mechanism as a linked list pointer and by the GC to store the
// computed "gc_refs" refcount.
uintptr_t ob_tid;
_Py_ALIGNED_DEF(1 << _PyObject_ALIGNMENT_SHIFT,uintptr_t) ob_tid;

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

syntax error: '<<' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

syntax error: '<<' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

syntax error: '<<' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

syntax error: '<<' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'__declspec(constant)' is not a recognized extended attribute [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'__declspec(constant)' is not a recognized extended attribute [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'__declspec(constant)' is not a recognized extended attribute [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'__declspec(constant)' is not a recognized extended attribute [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

syntax error: ')' [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

syntax error: '<<' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

syntax error: '<<' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

syntax error: '<<' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

syntax error: '<<' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'__declspec(constant)' is not a recognized extended attribute [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'__declspec(constant)' is not a recognized extended attribute [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'__declspec(constant)' is not a recognized extended attribute [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'__declspec(constant)' is not a recognized extended attribute [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

syntax error: ')' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 162 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

syntax error: ')' [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]
uint16_t ob_flags;
PyMutex ob_mutex; // per-object lock
uint8_t ob_gc_bits; // gc-related state
uint32_t ob_ref_local; // local reference count
Py_ssize_t ob_ref_shared; // shared (atomic) reference count
PyTypeObject *ob_type;
} Py_ALIGNED(1 << _PyObject_ALIGNMENT_SHIFT);
};
#endif

/* Cast argument to PyObject* type. */
Expand DownExpand Up@@ -258,7 +259,7 @@
#ifdef _Py_THREAD_SANITIZER
return _Py_atomic_load_uintptr_relaxed(&ob->ob_tid) == _Py_ThreadId();
#else
return ob->ob_tid == _Py_ThreadId();

Check warning on line 262 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'_Py_IsOwnedByCurrentThread' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 262 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'_Py_IsOwnedByCurrentThread' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 262 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'_Py_IsOwnedByCurrentThread' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 262 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'_Py_IsOwnedByCurrentThread' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 262 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'_Py_IsOwnedByCurrentThread' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 262 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'_Py_IsOwnedByCurrentThread' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 262 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'_Py_IsOwnedByCurrentThread' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 262 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'_Py_IsOwnedByCurrentThread' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]
#endif
}
#endif
Expand All@@ -272,7 +273,7 @@
#else
static inline PyTypeObject* _Py_TYPE(PyObject *ob)
{
return ob->ob_type;

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'_Py_TYPE' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'_Py_TYPE' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'_Py_TYPE' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (x64)

'_Py_TYPE' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'_Py_TYPE' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'_Py_TYPE' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'_Py_TYPE' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows (free-threading) / Build and test (arm64)

'_Py_TYPE' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

'_Py_TYPE' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

'_Py_TYPE' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

'_Py_TYPE' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (arm64)

'_Py_TYPE' must return a value [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

'_Py_TYPE' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

'_Py_TYPE' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

'_Py_TYPE' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 276 in Include/object.h

View workflow job for this annotation

GitHub Actions/ Windows / Build and test (x64)

'_Py_TYPE' must return a value [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]
}
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
# define Py_TYPE(ob) _Py_TYPE(_PyObject_CAST(ob))
Expand Down
83 changes: 53 additions & 30 deletionsInclude/pymacro.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -24,44 +24,67 @@
#endif


// _Py_ALIGN_AS: this compiler's spelling of `alignas` keyword,
// We currently use alignas for free-threaded builds only; additional compat
// checking would be great before we add it to the default build.
// Standards/compiler support:
// _Py_ALIGNED_DEF(N, T): Define a variable/member with increased alignment
//
// `N`: the desired minimum alignment, an integer literal
// `T`: the type of the defined variable
// (or a type with at least the defined variable's alignment)
//
// May not be used on a struct definition.
//
// Standards/compiler support for `alignas` alternatives:
// - `alignas` is a keyword in C23 and C++11.
// - `_Alignas` is a keyword in C11
// - GCC & clang has __attribute__((aligned))
// (use that for older standards in pedantic mode)
// - MSVC has __declspec(align)
// - `_Alignas` is common C compiler extension
// Older compilers may nameit differently; to allow compilation on such
// unsupported platforms, we don't redefine_Py_ALIGN_AS if it's already
// Older compilers may name`alignas` differently; to allow compilation on such
// unsupported platforms, we don't redefine_Py_ALIGNED_DEF if it's already
// defined. Note that defining it wrong (including defining it to nothing) will
// cause ABI incompatibilities.
#ifdef Py_GIL_DISABLED
# ifndef _Py_ALIGN_AS
# ifdef __cplusplus
# if __cplusplus >= 201103L
# define _Py_ALIGN_AS(V) alignas(V)
# elif defined(__GNUC__) || defined(__clang__)
# define _Py_ALIGN_AS(V) __attribute__((aligned(V)))
# elif defined(_MSC_VER)
# define _Py_ALIGN_AS(V) __declspec(align(V))
# else
# define _Py_ALIGN_AS(V) alignas(V)
# endif
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
# define _Py_ALIGN_AS(V) alignas(V)
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
# define _Py_ALIGN_AS(V) _Alignas(V)
# elif (defined(__GNUC__) || defined(__clang__))
# define _Py_ALIGN_AS(V) __attribute__((aligned(V)))
# elif defined(_MSC_VER)
# define _Py_ALIGN_AS(V) __declspec(align(V))
# else
# define _Py_ALIGN_AS(V) _Alignas(V)
# endif
# endif
//
// Behavior of `alignas` alternatives:
// - `alignas` & `_Alignas`:
// - Can be used multiple times; the greatest alignment applies.
// - It is an *error* if the combined effect of all `alignas` modifiers would
// decrease the alignment.
// - Takes types or numbers.
// - May not be used on a struct definition, unless also defining a variable.
// - Can't be used on a whole struct, only on members.
// - `__declspec(align)`:
// - Has no effect if it would decrease alignment.
// - Only takes an integer literal.
// - May be used on struct or variable definitions.
// - ` __attribute__((aligned))`:
// - Has no effect if it would decrease alignment.
// - Takes types or numbers
// - May be used on struct or variable definitions.
// However, when defining both the struct and the variable at once,
// `declspec(aligned)` causes compiler warning 5274 and possible ABI
// incompatibility.
#ifndef _Py_ALIGNED_DEF
# ifdef __cplusplus
# if __cplusplus >= 201103L
# define _Py_ALIGNED_DEF(N, T) alignas(N) alignas(T) T
# elif defined(__GNUC__) || defined(__clang__)
# define _Py_ALIGNED_DEF(N, T) __attribute__((aligned(N))) T
# elif defined(_MSC_VER)
# define _Py_ALIGNED_DEF(N, T) __declspec(align(N)) T
# else
# define _Py_ALIGNED_DEF(N, T) alignas(N) alignas(T) T
# endif
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
# define _Py_ALIGNED_DEF(N, T) alignas(N) alignas(T) T
# elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
# define _Py_ALIGNED_DEF(N, T) _Alignas(N) _Alignas(T) T
# elif (defined(__GNUC__) || defined(__clang__))
# define _Py_ALIGNED_DEF(N, T) __attribute__((aligned(N))) T
# elif defined(_MSC_VER)
# define _Py_ALIGNED_DEF(N, T) __declspec(align(N)) T
# else
# define _Py_ALIGNED_DEF(N, T) _Alignas(N) _Alignas(T) T
# endif
#endif

/* Minimum value between x and y */
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp