Python-checkins
Threads by month
- ----- 2024 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
August 2023
- 1 participants
- 769 discussions
31 Aug '23
https://github.com/python/cpython/commit/b4784b0c5f1cab48b45df5481edc203e25…
commit: b4784b0c5f1cab48b45df5481edc203e25688d0c
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: AlexWaygood <Alex.Waygood(a)Gmail.com>
date: 2023-08-31T22:27:27Z
summary:
[3.11] `ast` docs: Fix incorrect link on `keyword` (GH-108728) (#108738)
`ast` docs: Fix incorrect link on `keyword` (GH-108728)
In two places, Sphinx was erroneously adding links to the `keyword` module instead of the `ast.keyword` class
(cherry picked from commit c1e2f3b2f70b8a72ea7e1bf792addf62a94ae65d)
Co-authored-by: Alex Povel <git(a)alexpovel.de>
files:
M Doc/library/ast.rst
diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst
index d136f016b9b17..6392f7318d7a6 100644
--- a/Doc/library/ast.rst
+++ b/Doc/library/ast.rst
@@ -585,7 +585,7 @@ Expressions
:class:`Name` or :class:`Attribute` object. Of the arguments:
* ``args`` holds a list of the arguments passed by position.
- * ``keywords`` holds a list of :class:`keyword` objects representing
+ * ``keywords`` holds a list of :class:`.keyword` objects representing
arguments passed by keyword.
When creating a ``Call`` node, ``args`` and ``keywords`` are required, but
@@ -1925,7 +1925,7 @@ Function and class definitions
* ``name`` is a raw string for the class name
* ``bases`` is a list of nodes for explicitly specified base classes.
- * ``keywords`` is a list of :class:`keyword` nodes, principally for 'metaclass'.
+ * ``keywords`` is a list of :class:`.keyword` nodes, principally for 'metaclass'.
Other keywords will be passed to the metaclass, as per `PEP-3115
<https://peps.python.org/pep-3115/>`_.
* ``body`` is a list of nodes representing the code within the class
1
0
https://github.com/python/cpython/commit/c1e2f3b2f70b8a72ea7e1bf792addf62a9…
commit: c1e2f3b2f70b8a72ea7e1bf792addf62a94ae65d
branch: main
author: Alex Povel <git(a)alexpovel.de>
committer: AlexWaygood <Alex.Waygood(a)Gmail.com>
date: 2023-08-31T23:17:32+01:00
summary:
`ast` docs: Fix incorrect link on `keyword` (#108728)
In two places, Sphinx was erroneously adding links to the `keyword` module instead of the `ast.keyword` class
files:
M Doc/library/ast.rst
diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst
index 2237a07eb9d8a..8f5148feb809a 100644
--- a/Doc/library/ast.rst
+++ b/Doc/library/ast.rst
@@ -585,7 +585,7 @@ Expressions
:class:`Name` or :class:`Attribute` object. Of the arguments:
* ``args`` holds a list of the arguments passed by position.
- * ``keywords`` holds a list of :class:`keyword` objects representing
+ * ``keywords`` holds a list of :class:`.keyword` objects representing
arguments passed by keyword.
When creating a ``Call`` node, ``args`` and ``keywords`` are required, but
@@ -2024,7 +2024,7 @@ Function and class definitions
* ``name`` is a raw string for the class name
* ``bases`` is a list of nodes for explicitly specified base classes.
- * ``keywords`` is a list of :class:`keyword` nodes, principally for 'metaclass'.
+ * ``keywords`` is a list of :class:`.keyword` nodes, principally for 'metaclass'.
Other keywords will be passed to the metaclass, as per `PEP-3115
<https://peps.python.org/pep-3115/>`_.
* ``body`` is a list of nodes representing the code within the class
1
0
[3.12] gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704) (#108733)
by Yhg1s 31 Aug '23
by Yhg1s 31 Aug '23
31 Aug '23
https://github.com/python/cpython/commit/8c3793a539ce950e552da390b7b24485dd…
commit: 8c3793a539ce950e552da390b7b24485dd655237
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: Yhg1s <thomas(a)python.org>
date: 2023-09-01T00:04:55+02:00
summary:
[3.12] gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704) (#108733)
gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704)
When overriding the `__new__` method of an enum, the underlying data type should be created directly; i.e. .
member = object.__new__(cls)
member = int.__new__(cls, value)
member = str.__new__(cls, value)
Calling `super().__new__()` finds the lookup version of `Enum.__new__`, and will now raise an exception when detected.
(cherry picked from commit d48760b2f1e28dd3c1a35721939f400a8ab619b8)
Co-authored-by: Ethan Furman <ethan(a)stoneleaf.us>
files:
A Misc/NEWS.d/next/Library/2023-08-30-20-10-28.gh-issue-108682.c2gzLQ.rst
M Doc/howto/enum.rst
M Lib/enum.py
M Lib/test/test_enum.py
diff --git a/Doc/howto/enum.rst b/Doc/howto/enum.rst
index 4312b4c8140f5..28749754a54db 100644
--- a/Doc/howto/enum.rst
+++ b/Doc/howto/enum.rst
@@ -426,10 +426,17 @@ enumeration, with the exception of special methods (:meth:`__str__`,
:meth:`__add__`, etc.), descriptors (methods are also descriptors), and
variable names listed in :attr:`_ignore_`.
-Note: if your enumeration defines :meth:`__new__` and/or :meth:`__init__` then
+Note: if your enumeration defines :meth:`__new__` and/or :meth:`__init__`,
any value(s) given to the enum member will be passed into those methods.
See `Planet`_ for an example.
+.. note::
+
+ The :meth:`__new__` method, if defined, is used during creation of the Enum
+ members; it is then replaced by Enum's :meth:`__new__` which is used after
+ class creation for lookup of existing members. See :ref:`new-vs-init` for
+ more details.
+
Restricted Enum subclassing
---------------------------
@@ -895,6 +902,8 @@ Some rules:
:meth:`__str__` method has been reset to their data types'
:meth:`__str__` method.
+.. _new-vs-init:
+
When to use :meth:`__new__` vs. :meth:`__init__`
------------------------------------------------
@@ -927,6 +936,11 @@ want one of them to be the value::
>>> print(Coordinate(3))
Coordinate.VY
+.. warning::
+
+ *Do not* call ``super().__new__()``, as the lookup-only ``__new__`` is the one
+ that is found; instead, use the data type directly.
+
Finer Points
^^^^^^^^^^^^
@@ -1353,6 +1367,13 @@ to handle any extra arguments::
members; it is then replaced by Enum's :meth:`__new__` which is used after
class creation for lookup of existing members.
+.. warning::
+
+ *Do not* call ``super().__new__()``, as the lookup-only ``__new__`` is the one
+ that is found; instead, use the data type directly -- e.g.::
+
+ obj = int.__new__(cls, value)
+
OrderedEnum
^^^^^^^^^^^
diff --git a/Lib/enum.py b/Lib/enum.py
index 9114c5ccaaa95..9c0af9e56d8ee 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -865,6 +865,8 @@ def _create_(cls, class_name, names, *, module=None, qualname=None, type=None, s
value = first_enum._generate_next_value_(name, start, count, last_values[:])
last_values.append(value)
names.append((name, value))
+ if names is None:
+ names = ()
# Here, names is either an iterable of (name, value) or a mapping.
for item in names:
@@ -1121,6 +1123,11 @@ def __new__(cls, value):
for member in cls._member_map_.values():
if member._value_ == value:
return member
+ # still not found -- verify that members exist, in-case somebody got here mistakenly
+ # (such as via super when trying to override __new__)
+ if not cls._member_map_:
+ raise TypeError("%r has no members defined" % cls)
+ #
# still not found -- try _missing_ hook
try:
exc = None
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index dbdc639d62ec1..dc60caccaa435 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -236,11 +236,82 @@ class _EnumTests:
values = None
def setUp(self):
- class BaseEnum(self.enum_type):
+ if self.__class__.__name__[-5:] == 'Class':
+ class BaseEnum(self.enum_type):
+ @enum.property
+ def first(self):
+ return '%s is first!' % self.name
+ class MainEnum(BaseEnum):
+ first = auto()
+ second = auto()
+ third = auto()
+ if issubclass(self.enum_type, Flag):
+ dupe = 3
+ else:
+ dupe = third
+ self.MainEnum = MainEnum
+ #
+ class NewStrEnum(self.enum_type):
+ def __str__(self):
+ return self.name.upper()
+ first = auto()
+ self.NewStrEnum = NewStrEnum
+ #
+ class NewFormatEnum(self.enum_type):
+ def __format__(self, spec):
+ return self.name.upper()
+ first = auto()
+ self.NewFormatEnum = NewFormatEnum
+ #
+ class NewStrFormatEnum(self.enum_type):
+ def __str__(self):
+ return self.name.title()
+ def __format__(self, spec):
+ return ''.join(reversed(self.name))
+ first = auto()
+ self.NewStrFormatEnum = NewStrFormatEnum
+ #
+ class NewBaseEnum(self.enum_type):
+ def __str__(self):
+ return self.name.title()
+ def __format__(self, spec):
+ return ''.join(reversed(self.name))
+ class NewSubEnum(NewBaseEnum):
+ first = auto()
+ self.NewSubEnum = NewSubEnum
+ #
+ class LazyGNV(self.enum_type):
+ def _generate_next_value_(name, start, last, values):
+ pass
+ self.LazyGNV = LazyGNV
+ #
+ class BusyGNV(self.enum_type):
+ @staticmethod
+ def _generate_next_value_(name, start, last, values):
+ pass
+ self.BusyGNV = BusyGNV
+ #
+ self.is_flag = False
+ self.names = ['first', 'second', 'third']
+ if issubclass(MainEnum, StrEnum):
+ self.values = self.names
+ elif MainEnum._member_type_ is str:
+ self.values = ['1', '2', '3']
+ elif issubclass(self.enum_type, Flag):
+ self.values = [1, 2, 4]
+ self.is_flag = True
+ self.dupe2 = MainEnum(5)
+ else:
+ self.values = self.values or [1, 2, 3]
+ #
+ if not getattr(self, 'source_values', False):
+ self.source_values = self.values
+ elif self.__class__.__name__[-8:] == 'Function':
@enum.property
def first(self):
return '%s is first!' % self.name
- class MainEnum(BaseEnum):
+ BaseEnum = self.enum_type('BaseEnum', {'first':first})
+ #
first = auto()
second = auto()
third = auto()
@@ -248,63 +319,60 @@ class MainEnum(BaseEnum):
dupe = 3
else:
dupe = third
- self.MainEnum = MainEnum
- #
- class NewStrEnum(self.enum_type):
+ self.MainEnum = MainEnum = BaseEnum('MainEnum', dict(first=first, second=second, third=third, dupe=dupe))
+ #
def __str__(self):
return self.name.upper()
first = auto()
- self.NewStrEnum = NewStrEnum
- #
- class NewFormatEnum(self.enum_type):
+ self.NewStrEnum = self.enum_type('NewStrEnum', (('first',first),('__str__',__str__)))
+ #
def __format__(self, spec):
return self.name.upper()
first = auto()
- self.NewFormatEnum = NewFormatEnum
- #
- class NewStrFormatEnum(self.enum_type):
+ self.NewFormatEnum = self.enum_type('NewFormatEnum', [('first',first),('__format__',__format__)])
+ #
def __str__(self):
return self.name.title()
def __format__(self, spec):
return ''.join(reversed(self.name))
first = auto()
- self.NewStrFormatEnum = NewStrFormatEnum
- #
- class NewBaseEnum(self.enum_type):
+ self.NewStrFormatEnum = self.enum_type('NewStrFormatEnum', dict(first=first, __format__=__format__, __str__=__str__))
+ #
def __str__(self):
return self.name.title()
def __format__(self, spec):
return ''.join(reversed(self.name))
- class NewSubEnum(NewBaseEnum):
- first = auto()
- self.NewSubEnum = NewSubEnum
- #
- class LazyGNV(self.enum_type):
+ NewBaseEnum = self.enum_type('NewBaseEnum', dict(__format__=__format__, __str__=__str__))
+ class NewSubEnum(NewBaseEnum):
+ first = auto()
+ self.NewSubEnum = NewBaseEnum('NewSubEnum', 'first')
+ #
def _generate_next_value_(name, start, last, values):
pass
- self.LazyGNV = LazyGNV
- #
- class BusyGNV(self.enum_type):
+ self.LazyGNV = self.enum_type('LazyGNV', {'_generate_next_value_':_generate_next_value_})
+ #
@staticmethod
def _generate_next_value_(name, start, last, values):
pass
- self.BusyGNV = BusyGNV
- #
- self.is_flag = False
- self.names = ['first', 'second', 'third']
- if issubclass(MainEnum, StrEnum):
- self.values = self.names
- elif MainEnum._member_type_ is str:
- self.values = ['1', '2', '3']
- elif issubclass(self.enum_type, Flag):
- self.values = [1, 2, 4]
- self.is_flag = True
- self.dupe2 = MainEnum(5)
+ self.BusyGNV = self.enum_type('BusyGNV', {'_generate_next_value_':_generate_next_value_})
+ #
+ self.is_flag = False
+ self.names = ['first', 'second', 'third']
+ if issubclass(MainEnum, StrEnum):
+ self.values = self.names
+ elif MainEnum._member_type_ is str:
+ self.values = ['1', '2', '3']
+ elif issubclass(self.enum_type, Flag):
+ self.values = [1, 2, 4]
+ self.is_flag = True
+ self.dupe2 = MainEnum(5)
+ else:
+ self.values = self.values or [1, 2, 3]
+ #
+ if not getattr(self, 'source_values', False):
+ self.source_values = self.values
else:
- self.values = self.values or [1, 2, 3]
- #
- if not getattr(self, 'source_values', False):
- self.source_values = self.values
+ raise ValueError('unknown enum style: %r' % self.__class__.__name__)
def assertFormatIsValue(self, spec, member):
self.assertEqual(spec.format(member), spec.format(member.value))
@@ -332,6 +400,17 @@ def spam(cls):
with self.assertRaises(AttributeError):
del Season.SPRING.name
+ def test_bad_new_super(self):
+ with self.assertRaisesRegex(
+ TypeError,
+ 'has no members defined',
+ ):
+ class BadSuper(self.enum_type):
+ def __new__(cls, value):
+ obj = super().__new__(cls, value)
+ return obj
+ failed = 1
+
def test_basics(self):
TE = self.MainEnum
if self.is_flag:
@@ -387,7 +466,7 @@ def test_contains_tf(self):
MainEnum = self.MainEnum
self.assertIn(MainEnum.first, MainEnum)
self.assertTrue(self.values[0] in MainEnum)
- if type(self) is not TestStrEnum:
+ if type(self) not in (TestStrEnumClass, TestStrEnumFunction):
self.assertFalse('first' in MainEnum)
val = MainEnum.dupe
self.assertIn(val, MainEnum)
@@ -909,15 +988,23 @@ class OpenXYZ(self.enum_type):
self.assertTrue(~OpenXYZ(0), (X|Y|Z))
-class TestPlainEnum(_EnumTests, _PlainOutputTests, unittest.TestCase):
+class TestPlainEnumClass(_EnumTests, _PlainOutputTests, unittest.TestCase):
+ enum_type = Enum
+
+
+class TestPlainEnumFunction(_EnumTests, _PlainOutputTests, unittest.TestCase):
enum_type = Enum
-class TestPlainFlag(_EnumTests, _PlainOutputTests, _FlagTests, unittest.TestCase):
+class TestPlainFlagClass(_EnumTests, _PlainOutputTests, _FlagTests, unittest.TestCase):
enum_type = Flag
-class TestIntEnum(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+class TestPlainFlagFunction(_EnumTests, _PlainOutputTests, _FlagTests, unittest.TestCase):
+ enum_type = Flag
+
+
+class TestIntEnumClass(_EnumTests, _MinimalOutputTests, unittest.TestCase):
enum_type = IntEnum
#
def test_shadowed_attr(self):
@@ -929,7 +1016,17 @@ class Number(IntEnum):
self.assertIs(Number.numerator.divisor, Number.divisor)
-class TestStrEnum(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+class TestIntEnumFunction(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ enum_type = IntEnum
+ #
+ def test_shadowed_attr(self):
+ Number = IntEnum('Number', ('divisor', 'numerator'))
+ #
+ self.assertEqual(Number.divisor.numerator, 1)
+ self.assertIs(Number.numerator.divisor, Number.divisor)
+
+
+class TestStrEnumClass(_EnumTests, _MinimalOutputTests, unittest.TestCase):
enum_type = StrEnum
#
def test_shadowed_attr(self):
@@ -942,64 +1039,141 @@ class Book(StrEnum):
self.assertIs(Book.title.author, Book.author)
-class TestIntFlag(_EnumTests, _MinimalOutputTests, _FlagTests, unittest.TestCase):
+class TestStrEnumFunction(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ enum_type = StrEnum
+ #
+ def test_shadowed_attr(self):
+ Book = StrEnum('Book', ('author', 'title'))
+ #
+ self.assertEqual(Book.author.title(), 'Author')
+ self.assertEqual(Book.title.title(), 'Title')
+ self.assertIs(Book.title.author, Book.author)
+
+
+class TestIntFlagClass(_EnumTests, _MinimalOutputTests, _FlagTests, unittest.TestCase):
+ enum_type = IntFlag
+
+
+class TestIntFlagFunction(_EnumTests, _MinimalOutputTests, _FlagTests, unittest.TestCase):
enum_type = IntFlag
-class TestMixedInt(_EnumTests, _MixedOutputTests, unittest.TestCase):
+class TestMixedIntClass(_EnumTests, _MixedOutputTests, unittest.TestCase):
class enum_type(int, Enum): pass
-class TestMixedStr(_EnumTests, _MixedOutputTests, unittest.TestCase):
+class TestMixedIntFunction(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ enum_type = Enum('enum_type', type=int)
+
+
+class TestMixedStrClass(_EnumTests, _MixedOutputTests, unittest.TestCase):
class enum_type(str, Enum): pass
-class TestMixedIntFlag(_EnumTests, _MixedOutputTests, _FlagTests, unittest.TestCase):
+class TestMixedStrFunction(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ enum_type = Enum('enum_type', type=str)
+
+
+class TestMixedIntFlagClass(_EnumTests, _MixedOutputTests, _FlagTests, unittest.TestCase):
class enum_type(int, Flag): pass
-class TestMixedDate(_EnumTests, _MixedOutputTests, unittest.TestCase):
+class TestMixedIntFlagFunction(_EnumTests, _MixedOutputTests, _FlagTests, unittest.TestCase):
+ enum_type = Flag('enum_type', type=int)
+
+class TestMixedDateClass(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ #
values = [date(2021, 12, 25), date(2020, 3, 15), date(2019, 11, 27)]
source_values = [(2021, 12, 25), (2020, 3, 15), (2019, 11, 27)]
-
+ #
class enum_type(date, Enum):
+ @staticmethod
def _generate_next_value_(name, start, count, last_values):
values = [(2021, 12, 25), (2020, 3, 15), (2019, 11, 27)]
return values[count]
-class TestMinimalDate(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+class TestMixedDateFunction(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ #
+ values = [date(2021, 12, 25), date(2020, 3, 15), date(2019, 11, 27)]
+ source_values = [(2021, 12, 25), (2020, 3, 15), (2019, 11, 27)]
+ #
+ # staticmethod decorator will be added by EnumType if not present
+ def _generate_next_value_(name, start, count, last_values):
+ values = [(2021, 12, 25), (2020, 3, 15), (2019, 11, 27)]
+ return values[count]
+ #
+ enum_type = Enum('enum_type', {'_generate_next_value_':_generate_next_value_}, type=date)
+
+class TestMinimalDateClass(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ #
values = [date(2023, 12, 1), date(2016, 2, 29), date(2009, 1, 1)]
source_values = [(2023, 12, 1), (2016, 2, 29), (2009, 1, 1)]
-
+ #
class enum_type(date, ReprEnum):
+ # staticmethod decorator will be added by EnumType if absent
def _generate_next_value_(name, start, count, last_values):
values = [(2023, 12, 1), (2016, 2, 29), (2009, 1, 1)]
return values[count]
-class TestMixedFloat(_EnumTests, _MixedOutputTests, unittest.TestCase):
+class TestMinimalDateFunction(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ #
+ values = [date(2023, 12, 1), date(2016, 2, 29), date(2009, 1, 1)]
+ source_values = [(2023, 12, 1), (2016, 2, 29), (2009, 1, 1)]
+ #
+ @staticmethod
+ def _generate_next_value_(name, start, count, last_values):
+ values = [(2023, 12, 1), (2016, 2, 29), (2009, 1, 1)]
+ return values[count]
+ #
+ enum_type = ReprEnum('enum_type', {'_generate_next_value_':_generate_next_value_}, type=date)
- values = [1.1, 2.2, 3.3]
+class TestMixedFloatClass(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ #
+ values = [1.1, 2.2, 3.3]
+ #
class enum_type(float, Enum):
def _generate_next_value_(name, start, count, last_values):
values = [1.1, 2.2, 3.3]
return values[count]
-class TestMinimalFloat(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+class TestMixedFloatFunction(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ #
+ values = [1.1, 2.2, 3.3]
+ #
+ def _generate_next_value_(name, start, count, last_values):
+ values = [1.1, 2.2, 3.3]
+ return values[count]
+ #
+ enum_type = Enum('enum_type', {'_generate_next_value_':_generate_next_value_}, type=float)
- values = [4.4, 5.5, 6.6]
+class TestMinimalFloatClass(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ #
+ values = [4.4, 5.5, 6.6]
+ #
class enum_type(float, ReprEnum):
def _generate_next_value_(name, start, count, last_values):
values = [4.4, 5.5, 6.6]
return values[count]
+class TestMinimalFloatFunction(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ #
+ values = [4.4, 5.5, 6.6]
+ #
+ def _generate_next_value_(name, start, count, last_values):
+ values = [4.4, 5.5, 6.6]
+ return values[count]
+ #
+ enum_type = ReprEnum('enum_type', {'_generate_next_value_':_generate_next_value_}, type=float)
+
+
class TestSpecial(unittest.TestCase):
"""
various operations that are not attributable to every possible enum
diff --git a/Misc/NEWS.d/next/Library/2023-08-30-20-10-28.gh-issue-108682.c2gzLQ.rst b/Misc/NEWS.d/next/Library/2023-08-30-20-10-28.gh-issue-108682.c2gzLQ.rst
new file mode 100644
index 0000000000000..148d432914274
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-08-30-20-10-28.gh-issue-108682.c2gzLQ.rst
@@ -0,0 +1,2 @@
+Enum: raise :exc:`TypeError` if ``super().__new__()`` is called from a
+custom ``__new__``.
1
0
[3.12] gh-97850: Note in py312 whatsnew that `importlib.util.set_loader` and `importlib.util.module_for_loader` have been removed (GH-108719) (#108723)
by Yhg1s 31 Aug '23
by Yhg1s 31 Aug '23
31 Aug '23
https://github.com/python/cpython/commit/a92c60c99bab716d1d08bccb92dcc0fe6e…
commit: a92c60c99bab716d1d08bccb92dcc0fe6ee93abe
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington(a)users.noreply.github.com>
committer: Yhg1s <thomas(a)python.org>
date: 2023-09-01T00:03:02+02:00
summary:
[3.12] gh-97850: Note in py312 whatsnew that `importlib.util.set_loader` and `importlib.util.module_for_loader` have been removed (GH-108719) (#108723)
gh-97850: Note in py312 whatsnew that `importlib.util.set_loader` and `importlib.util.module_for_loader` have been removed (GH-108719)
Note in py312 whatsnew that `importlib.util.set_loader` and `importlib.util.module_for_loader` have been removed
(cherry picked from commit 013a99a47b3299f48cf7f95aa451a116441b029c)
Co-authored-by: Alex Waygood <Alex.Waygood(a)Gmail.com>
files:
M Doc/whatsnew/3.12.rst
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst
index d0326e05f78ea..f76f9c465b912 100644
--- a/Doc/whatsnew/3.12.rst
+++ b/Doc/whatsnew/3.12.rst
@@ -1312,8 +1312,9 @@ Removed
* References to, and support for :meth:`!module_repr()` has been removed.
(Contributed by Barry Warsaw in :gh:`97850`.)
- * ``importlib.util.set_package`` has been removed. (Contributed by Brett
- Cannon in :gh:`65961`.)
+ * ``importlib.util.set_package``, ``importlib.util.set_loader`` and
+ ``importlib.util.module_for_loader`` have all been removed. (Contributed by
+ Brett Cannon and Nikita Sobolev in :gh:`65961` and :gh:`97850`.)
* Support for ``find_loader()`` and ``find_module()`` APIs have been
removed. (Contributed by Barry Warsaw in :gh:`98040`.)
1
0
31 Aug '23
https://github.com/python/cpython/commit/ad73674283978a8bf8f1983bfd69150e60…
commit: ad73674283978a8bf8f1983bfd69150e60e6225f
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2023-08-31T23:42:34+02:00
summary:
gh-107603: Argument Clinic: Only include pycore_gc.h if needed (#108726)
Argument Clinic now only includes pycore_gc.h if PyGC_Head is needed,
and only includes pycore_runtime.h if _Py_ID() is needed.
* Add 'condition' optional argument to Clinic.add_include().
* deprecate_keyword_use() includes pycore_runtime.h when using
the _PyID() function.
* Fix rendering of includes: comments start at the column 35.
* Mark PC/clinic/_wmimodule.cpp.h and
"Objects/stringlib/clinic/*.h.h" header files as generated in
.gitattributes.
Effects:
* 42 header files generated by AC no longer include the internal C
API, instead of 4 header files before. For example,
Modules/clinic/_abc.c.h no longer includes the internal C API.
* Fix _testclinic_depr.c.h: it now always includes pycore_runtime.h
to get _Py_ID().
files:
M .gitattributes
M Lib/test/test_clinic.py
M Modules/_blake2/clinic/blake2b_impl.c.h
M Modules/_blake2/clinic/blake2s_impl.c.h
M Modules/_ctypes/clinic/callproc.c.h
M Modules/_io/clinic/_iomodule.c.h
M Modules/_io/clinic/bufferedio.c.h
M Modules/_io/clinic/bytesio.c.h
M Modules/_io/clinic/fileio.c.h
M Modules/_io/clinic/iobase.c.h
M Modules/_io/clinic/stringio.c.h
M Modules/_io/clinic/textio.c.h
M Modules/_io/clinic/winconsoleio.c.h
M Modules/_multiprocessing/clinic/multiprocessing.c.h
M Modules/_multiprocessing/clinic/posixshmem.c.h
M Modules/_multiprocessing/clinic/semaphore.c.h
M Modules/_sqlite/clinic/_sqlite3.connect.c.h
M Modules/_sqlite/clinic/blob.c.h
M Modules/_sqlite/clinic/connection.c.h
M Modules/_sqlite/clinic/cursor.c.h
M Modules/_sqlite/clinic/module.c.h
M Modules/_sqlite/clinic/row.c.h
M Modules/_sre/clinic/sre.c.h
M Modules/_ssl/clinic/cert.c.h
M Modules/_testcapi/clinic/exceptions.c.h
M Modules/_testcapi/clinic/float.c.h
M Modules/_testcapi/clinic/long.c.h
M Modules/_testcapi/clinic/vectorcall.c.h
M Modules/_testcapi/clinic/watchers.c.h
M Modules/cjkcodecs/clinic/multibytecodec.c.h
M Modules/clinic/_abc.c.h
M Modules/clinic/_asynciomodule.c.h
M Modules/clinic/_bisectmodule.c.h
M Modules/clinic/_bz2module.c.h
M Modules/clinic/_codecsmodule.c.h
M Modules/clinic/_collectionsmodule.c.h
M Modules/clinic/_contextvarsmodule.c.h
M Modules/clinic/_csv.c.h
M Modules/clinic/_curses_panel.c.h
M Modules/clinic/_cursesmodule.c.h
M Modules/clinic/_datetimemodule.c.h
M Modules/clinic/_dbmmodule.c.h
M Modules/clinic/_elementtree.c.h
M Modules/clinic/_functoolsmodule.c.h
M Modules/clinic/_gdbmmodule.c.h
M Modules/clinic/_hashopenssl.c.h
M Modules/clinic/_heapqmodule.c.h
M Modules/clinic/_localemodule.c.h
M Modules/clinic/_lsprof.c.h
M Modules/clinic/_lzmamodule.c.h
M Modules/clinic/_opcode.c.h
M Modules/clinic/_operator.c.h
M Modules/clinic/_pickle.c.h
M Modules/clinic/_posixsubprocess.c.h
M Modules/clinic/_queuemodule.c.h
M Modules/clinic/_randommodule.c.h
M Modules/clinic/_ssl.c.h
M Modules/clinic/_statisticsmodule.c.h
M Modules/clinic/_struct.c.h
M Modules/clinic/_testclinic.c.h
M Modules/clinic/_testclinic_depr.c.h
M Modules/clinic/_testinternalcapi.c.h
M Modules/clinic/_testmultiphase.c.h
M Modules/clinic/_tkinter.c.h
M Modules/clinic/_tracemalloc.c.h
M Modules/clinic/_typingmodule.c.h
M Modules/clinic/_weakref.c.h
M Modules/clinic/_winapi.c.h
M Modules/clinic/_zoneinfo.c.h
M Modules/clinic/arraymodule.c.h
M Modules/clinic/binascii.c.h
M Modules/clinic/cmathmodule.c.h
M Modules/clinic/fcntlmodule.c.h
M Modules/clinic/gcmodule.c.h
M Modules/clinic/grpmodule.c.h
M Modules/clinic/itertoolsmodule.c.h
M Modules/clinic/mathmodule.c.h
M Modules/clinic/md5module.c.h
M Modules/clinic/overlapped.c.h
M Modules/clinic/posixmodule.c.h
M Modules/clinic/pwdmodule.c.h
M Modules/clinic/pyexpat.c.h
M Modules/clinic/readline.c.h
M Modules/clinic/resource.c.h
M Modules/clinic/selectmodule.c.h
M Modules/clinic/sha1module.c.h
M Modules/clinic/sha2module.c.h
M Modules/clinic/sha3module.c.h
M Modules/clinic/signalmodule.c.h
M Modules/clinic/socketmodule.c.h
M Modules/clinic/symtablemodule.c.h
M Modules/clinic/syslogmodule.c.h
M Modules/clinic/termios.c.h
M Modules/clinic/unicodedata.c.h
M Modules/clinic/zlibmodule.c.h
M Objects/clinic/bytearrayobject.c.h
M Objects/clinic/bytesobject.c.h
M Objects/clinic/classobject.c.h
M Objects/clinic/codeobject.c.h
M Objects/clinic/complexobject.c.h
M Objects/clinic/descrobject.c.h
M Objects/clinic/dictobject.c.h
M Objects/clinic/enumobject.c.h
M Objects/clinic/floatobject.c.h
M Objects/clinic/funcobject.c.h
M Objects/clinic/listobject.c.h
M Objects/clinic/longobject.c.h
M Objects/clinic/memoryobject.c.h
M Objects/clinic/moduleobject.c.h
M Objects/clinic/odictobject.c.h
M Objects/clinic/structseq.c.h
M Objects/clinic/tupleobject.c.h
M Objects/clinic/typeobject.c.h
M Objects/clinic/typevarobject.c.h
M Objects/clinic/unicodeobject.c.h
M Objects/stringlib/clinic/transmogrify.h.h
M PC/clinic/_testconsole.c.h
M PC/clinic/_wmimodule.cpp.h
M PC/clinic/msvcrtmodule.c.h
M PC/clinic/winreg.c.h
M PC/clinic/winsound.c.h
M Python/clinic/Python-tokenize.c.h
M Python/clinic/_warnings.c.h
M Python/clinic/bltinmodule.c.h
M Python/clinic/context.c.h
M Python/clinic/import.c.h
M Python/clinic/instrumentation.c.h
M Python/clinic/marshal.c.h
M Python/clinic/sysmodule.c.h
M Python/clinic/traceback.c.h
M Tools/clinic/clinic.py
diff --git a/.gitattributes b/.gitattributes
index 317a613217a9b..e05ff900bf1c0 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -66,6 +66,8 @@ PCbuild/readme.txt dos
[attr]generated linguist-generated=true diff=generated
**/clinic/*.c.h generated
+**/clinic/*.cpp.h generated
+**/clinic/*.h.h generated
*_db.h generated
Doc/data/stable_abi.dat generated
Doc/library/token-list.inc generated
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py
index b29f2ea55516f..4a5f472e6f710 100644
--- a/Lib/test/test_clinic.py
+++ b/Lib/test/test_clinic.py
@@ -2673,12 +2673,6 @@ def test_file_dest(self):
preserve
[clinic start generated code]*/
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- # include "pycore_gc.h" // PyGC_Head
- # include "pycore_runtime.h" // _Py_ID()
- #endif
-
-
PyDoc_VAR(func__doc__);
PyDoc_STRVAR(func__doc__,
@@ -2691,7 +2685,7 @@ def test_file_dest(self):
static PyObject *
func(PyObject *module, PyObject *a)
- /*[clinic end generated code: output=56c09670e89a0d9a input=a9049054013a1b77]*/
+ /*[clinic end generated code: output=3dde2d13002165b9 input=a9049054013a1b77]*/
""")
with os_helper.temp_dir() as tmp_dir:
in_fn = os.path.join(tmp_dir, "test.c")
diff --git a/Modules/_blake2/clinic/blake2b_impl.c.h b/Modules/_blake2/clinic/blake2b_impl.c.h
index 384e7142bcfda..869cbea78dd26 100644
--- a/Modules/_blake2/clinic/blake2b_impl.c.h
+++ b/Modules/_blake2/clinic/blake2b_impl.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
+#include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
PyDoc_STRVAR(py_blake2b_new__doc__,
"blake2b(data=b\'\', /, *, digest_size=_blake2.blake2b.MAX_DIGEST_SIZE,\n"
@@ -277,4 +276,4 @@ _blake2_blake2b_hexdigest(BLAKE2bObject *self, PyObject *Py_UNUSED(ignored))
{
return _blake2_blake2b_hexdigest_impl(self);
}
-/*[clinic end generated code: output=48128782266b7b8e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2ad807e0c83d8c25 input=a9049054013a1b77]*/
diff --git a/Modules/_blake2/clinic/blake2s_impl.c.h b/Modules/_blake2/clinic/blake2s_impl.c.h
index d7a475277e054..affc203486b17 100644
--- a/Modules/_blake2/clinic/blake2s_impl.c.h
+++ b/Modules/_blake2/clinic/blake2s_impl.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
+#include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
PyDoc_STRVAR(py_blake2s_new__doc__,
"blake2s(data=b\'\', /, *, digest_size=_blake2.blake2s.MAX_DIGEST_SIZE,\n"
@@ -277,4 +276,4 @@ _blake2_blake2s_hexdigest(BLAKE2sObject *self, PyObject *Py_UNUSED(ignored))
{
return _blake2_blake2s_hexdigest_impl(self);
}
-/*[clinic end generated code: output=2188af9910a45497 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=90ca2b52b8c40785 input=a9049054013a1b77]*/
diff --git a/Modules/_ctypes/clinic/callproc.c.h b/Modules/_ctypes/clinic/callproc.c.h
index 6f036bb66b25a..a787693ae67cd 100644
--- a/Modules/_ctypes/clinic/callproc.c.h
+++ b/Modules/_ctypes/clinic/callproc.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(create_pointer_type__doc__,
"POINTER($module, type, /)\n"
"--\n"
@@ -35,4 +29,4 @@ PyDoc_STRVAR(create_pointer_inst__doc__,
#define CREATE_POINTER_INST_METHODDEF \
{"pointer", (PyCFunction)create_pointer_inst, METH_O, create_pointer_inst__doc__},
-/*[clinic end generated code: output=ae26452a759ba56d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=51b311ea369e5adf input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/_iomodule.c.h b/Modules/_io/clinic/_iomodule.c.h
index 77c203681fca4..49a3573ab9747 100644
--- a/Modules/_io/clinic/_iomodule.c.h
+++ b/Modules/_io/clinic/_iomodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_io_open__doc__,
"open($module, /, file, mode=\'r\', buffering=-1, encoding=None,\n"
" errors=None, newline=None, closefd=True, opener=None)\n"
@@ -404,4 +403,4 @@ _io_open_code(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
exit:
return return_value;
}
-/*[clinic end generated code: output=a4ceb802f3a7243f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=aaf96c8d9bd20abc input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h
index 32c4a4e177cbb..b2c52cf2a95a4 100644
--- a/Modules/_io/clinic/bufferedio.c.h
+++ b/Modules/_io/clinic/bufferedio.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_io__BufferedIOBase_readinto__doc__,
"readinto($self, buffer, /)\n"
@@ -1099,4 +1098,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=768c3a3a3deabcb4 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=9e09091995ae02b0 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h
index b5cdd0802b874..d736477920082 100644
--- a/Modules/_io/clinic/bytesio.c.h
+++ b/Modules/_io/clinic/bytesio.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
+#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(_io_BytesIO_readable__doc__,
"readable($self, /)\n"
@@ -539,4 +538,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=6b1219bda0619e2a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8ab65edc03edbfe0 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h
index 7b63e36b5038d..29f8cf6aa9a85 100644
--- a/Modules/_io/clinic/fileio.c.h
+++ b/Modules/_io/clinic/fileio.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
+#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(_io_FileIO_close__doc__,
"close($self, /)\n"
@@ -537,4 +536,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
#define _IO_FILEIO_TRUNCATE_METHODDEF
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
-/*[clinic end generated code: output=3a3c6ed7e5e78063 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=238dd48819076434 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/iobase.c.h b/Modules/_io/clinic/iobase.c.h
index fb96ea132f3dc..9ac80b687925a 100644
--- a/Modules/_io/clinic/iobase.c.h
+++ b/Modules/_io/clinic/iobase.c.h
@@ -2,12 +2,7 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
+#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(_io__IOBase_seek__doc__,
"seek($self, offset, whence=os.SEEK_SET, /)\n"
@@ -442,4 +437,4 @@ _io__RawIOBase_readall(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__RawIOBase_readall_impl(self);
}
-/*[clinic end generated code: output=d96f5bfd72e6eafb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=95e1633805d10294 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h
index dbe1833a90ed8..ccdae18d2af24 100644
--- a/Modules/_io/clinic/stringio.c.h
+++ b/Modules/_io/clinic/stringio.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
+#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(_io_StringIO_getvalue__doc__,
"getvalue($self, /)\n"
@@ -368,4 +367,4 @@ _io_StringIO_seekable(stringio *self, PyObject *Py_UNUSED(ignored))
{
return _io_StringIO_seekable_impl(self);
}
-/*[clinic end generated code: output=09d4056cc8c4aae4 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=57e86cd679344ee7 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h
index ce6efbe20b6bb..bc14327388fb2 100644
--- a/Modules/_io/clinic/textio.c.h
+++ b/Modules/_io/clinic/textio.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
+#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(_io__TextIOBase_detach__doc__,
"detach($self, /)\n"
@@ -980,4 +979,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_close_impl(self);
}
-/*[clinic end generated code: output=390af0e65a0d02c0 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=175e1723a462a722 input=a9049054013a1b77]*/
diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h
index 53f971e37c125..0683eecdfebb3 100644
--- a/Modules/_io/clinic/winconsoleio.c.h
+++ b/Modules/_io/clinic/winconsoleio.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
+#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
#if defined(HAVE_WINDOWS_CONSOLE_IO)
@@ -466,4 +465,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
-/*[clinic end generated code: output=0cdb16d95f1c7dac input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7be51d48ddb7c8c8 input=a9049054013a1b77]*/
diff --git a/Modules/_multiprocessing/clinic/multiprocessing.c.h b/Modules/_multiprocessing/clinic/multiprocessing.c.h
index e8eed0c0c4283..0ae0039a66606 100644
--- a/Modules/_multiprocessing/clinic/multiprocessing.c.h
+++ b/Modules/_multiprocessing/clinic/multiprocessing.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
#if defined(MS_WINDOWS)
PyDoc_STRVAR(_multiprocessing_closesocket__doc__,
@@ -172,4 +166,4 @@ _multiprocessing_sem_unlink(PyObject *module, PyObject *arg)
#ifndef _MULTIPROCESSING_SEND_METHODDEF
#define _MULTIPROCESSING_SEND_METHODDEF
#endif /* !defined(_MULTIPROCESSING_SEND_METHODDEF) */
-/*[clinic end generated code: output=eb078dff6b6595ff input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8b91c020d4353cc5 input=a9049054013a1b77]*/
diff --git a/Modules/_multiprocessing/clinic/posixshmem.c.h b/Modules/_multiprocessing/clinic/posixshmem.c.h
index 265f46889d531..09dfa11da23b8 100644
--- a/Modules/_multiprocessing/clinic/posixshmem.c.h
+++ b/Modules/_multiprocessing/clinic/posixshmem.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
#if defined(HAVE_SHM_OPEN)
PyDoc_STRVAR(_posixshmem_shm_open__doc__,
@@ -166,4 +165,4 @@ _posixshmem_shm_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs
#ifndef _POSIXSHMEM_SHM_UNLINK_METHODDEF
#define _POSIXSHMEM_SHM_UNLINK_METHODDEF
#endif /* !defined(_POSIXSHMEM_SHM_UNLINK_METHODDEF) */
-/*[clinic end generated code: output=c022e2f7371fdece input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2f356903a281d857 input=a9049054013a1b77]*/
diff --git a/Modules/_multiprocessing/clinic/semaphore.c.h b/Modules/_multiprocessing/clinic/semaphore.c.h
index c5bffc843570d..a4357376ee129 100644
--- a/Modules/_multiprocessing/clinic/semaphore.c.h
+++ b/Modules/_multiprocessing/clinic/semaphore.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
#if defined(HAVE_MP_SEMAPHORE) && defined(MS_WINDOWS)
PyDoc_STRVAR(_multiprocessing_SemLock_acquire__doc__,
@@ -542,4 +541,4 @@ _multiprocessing_SemLock___exit__(SemLockObject *self, PyObject *const *args, Py
#ifndef _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
#define _MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF
#endif /* !defined(_MULTIPROCESSING_SEMLOCK___EXIT___METHODDEF) */
-/*[clinic end generated code: output=0fcadfdd8d6944be input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e8ea65f8cba8e173 input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/_sqlite3.connect.c.h b/Modules/_sqlite/clinic/_sqlite3.connect.c.h
index 998c8de1e09f1..eceb5a7bf2367 100644
--- a/Modules/_sqlite/clinic/_sqlite3.connect.c.h
+++ b/Modules/_sqlite/clinic/_sqlite3.connect.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(pysqlite_connect__doc__,
"connect($module, /, database, timeout=5.0, detect_types=0,\n"
" isolation_level=\'\', check_same_thread=True,\n"
@@ -28,4 +27,4 @@ PyDoc_STRVAR(pysqlite_connect__doc__,
#define PYSQLITE_CONNECT_METHODDEF \
{"connect", _PyCFunction_CAST(pysqlite_connect), METH_FASTCALL|METH_KEYWORDS, pysqlite_connect__doc__},
-/*[clinic end generated code: output=8d49736db880f09a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=03bd99542e3aec9d input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/blob.c.h b/Modules/_sqlite/clinic/blob.c.h
index 7dda4d77c72ab..e7c60264722f7 100644
--- a/Modules/_sqlite/clinic/blob.c.h
+++ b/Modules/_sqlite/clinic/blob.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(blob_close__doc__,
"close($self, /)\n"
"--\n"
@@ -219,4 +213,4 @@ blob_exit(pysqlite_Blob *self, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=1783b816ccc3bb75 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8bfd79ab12ac5385 input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h
index f9510f47dd9ef..fcc657799dfaf 100644
--- a/Modules/_sqlite/clinic/connection.c.h
+++ b/Modules/_sqlite/clinic/connection.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
static int
pysqlite_connection_init_impl(pysqlite_Connection *self, PyObject *database,
double timeout, int detect_types,
@@ -1822,4 +1821,4 @@ getconfig(pysqlite_Connection *self, PyObject *arg)
#ifndef DESERIALIZE_METHODDEF
#define DESERIALIZE_METHODDEF
#endif /* !defined(DESERIALIZE_METHODDEF) */
-/*[clinic end generated code: output=f06b254bc5c2bcaf input=a9049054013a1b77]*/
+/*[clinic end generated code: output=166bf41ad5ca1655 input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/cursor.c.h b/Modules/_sqlite/clinic/cursor.c.h
index 1a21a1c41dafd..3cb637bde4ff6 100644
--- a/Modules/_sqlite/clinic/cursor.c.h
+++ b/Modules/_sqlite/clinic/cursor.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
static int
pysqlite_cursor_init_impl(pysqlite_Cursor *self,
pysqlite_Connection *connection);
@@ -313,4 +312,4 @@ pysqlite_cursor_close(pysqlite_Cursor *self, PyObject *Py_UNUSED(ignored))
{
return pysqlite_cursor_close_impl(self);
}
-/*[clinic end generated code: output=b56b3ddb3b6df8c6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0c52a9cf54d00543 input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/module.c.h b/Modules/_sqlite/clinic/module.c.h
index 82e628ababd4a..49ba7a341ed58 100644
--- a/Modules/_sqlite/clinic/module.c.h
+++ b/Modules/_sqlite/clinic/module.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(pysqlite_complete_statement__doc__,
"complete_statement($module, /, statement)\n"
"--\n"
@@ -208,4 +207,4 @@ pysqlite_adapt(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=c1d450089867b4bf input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a14893a7c2eead5e input=a9049054013a1b77]*/
diff --git a/Modules/_sqlite/clinic/row.c.h b/Modules/_sqlite/clinic/row.c.h
index 89a48fd52da22..cdf850d01e01a 100644
--- a/Modules/_sqlite/clinic/row.c.h
+++ b/Modules/_sqlite/clinic/row.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
static PyObject *
pysqlite_row_new_impl(PyTypeObject *type, pysqlite_Cursor *cursor,
PyObject *data);
@@ -60,4 +54,4 @@ pysqlite_row_keys(pysqlite_Row *self, PyObject *Py_UNUSED(ignored))
{
return pysqlite_row_keys_impl(self);
}
-/*[clinic end generated code: output=157b31ac3f6af1ba input=a9049054013a1b77]*/
+/*[clinic end generated code: output=972487d535d2e7d5 input=a9049054013a1b77]*/
diff --git a/Modules/_sre/clinic/sre.c.h b/Modules/_sre/clinic/sre.c.h
index 1846f175b4585..1b5e1a710af9d 100644
--- a/Modules/_sre/clinic/sre.c.h
+++ b/Modules/_sre/clinic/sre.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_sre_getcodesize__doc__,
"getcodesize($module, /)\n"
@@ -1461,4 +1460,4 @@ _sre_SRE_Scanner_search(ScannerObject *self, PyTypeObject *cls, PyObject *const
}
return _sre_SRE_Scanner_search_impl(self, cls);
}
-/*[clinic end generated code: output=b8cf77f05e44d08c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=46d83927cbafa93a input=a9049054013a1b77]*/
diff --git a/Modules/_ssl/clinic/cert.c.h b/Modules/_ssl/clinic/cert.c.h
index e2842263bec04..db43c88e41113 100644
--- a/Modules/_ssl/clinic/cert.c.h
+++ b/Modules/_ssl/clinic/cert.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_ssl_Certificate_public_bytes__doc__,
"public_bytes($self, /, format=Encoding.PEM)\n"
"--\n"
@@ -86,4 +85,4 @@ _ssl_Certificate_get_info(PySSLCertificate *self, PyObject *Py_UNUSED(ignored))
{
return _ssl_Certificate_get_info_impl(self);
}
-/*[clinic end generated code: output=72e2bb139c64546c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8e438b54fbebd53e input=a9049054013a1b77]*/
diff --git a/Modules/_testcapi/clinic/exceptions.c.h b/Modules/_testcapi/clinic/exceptions.c.h
index 61a9103b97f5b..01881534329c9 100644
--- a/Modules/_testcapi/clinic/exceptions.c.h
+++ b/Modules/_testcapi/clinic/exceptions.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_testcapi_err_set_raised__doc__,
"err_set_raised($module, exception, /)\n"
"--\n"
@@ -488,4 +487,4 @@ _testcapi_unstable_exc_prep_reraise_star(PyObject *module, PyObject *const *args
exit:
return return_value;
}
-/*[clinic end generated code: output=6c4b7ad1cb1e0153 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8f273949da28ffb5 input=a9049054013a1b77]*/
diff --git a/Modules/_testcapi/clinic/float.c.h b/Modules/_testcapi/clinic/float.c.h
index 84de17a8ee176..fb0931a0703e1 100644
--- a/Modules/_testcapi/clinic/float.c.h
+++ b/Modules/_testcapi/clinic/float.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_testcapi_float_pack__doc__,
"float_pack($module, size, d, le, /)\n"
"--\n"
@@ -85,4 +79,4 @@ _testcapi_float_unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs
exit:
return return_value;
}
-/*[clinic end generated code: output=de6879d0f4987d79 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=50146051f1341cce input=a9049054013a1b77]*/
diff --git a/Modules/_testcapi/clinic/long.c.h b/Modules/_testcapi/clinic/long.c.h
index 87bba4cfacfe5..b77cb51810cb6 100644
--- a/Modules/_testcapi/clinic/long.c.h
+++ b/Modules/_testcapi/clinic/long.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_testcapi_test_long_api__doc__,
"test_long_api($module, /)\n"
"--\n"
@@ -171,4 +165,4 @@ PyDoc_STRVAR(_testcapi_PyLong_AsInt__doc__,
#define _TESTCAPI_PYLONG_ASINT_METHODDEF \
{"PyLong_AsInt", (PyCFunction)_testcapi_PyLong_AsInt, METH_O, _testcapi_PyLong_AsInt__doc__},
-/*[clinic end generated code: output=1631a18f1193486a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=31267ab2dd90aa1d input=a9049054013a1b77]*/
diff --git a/Modules/_testcapi/clinic/vectorcall.c.h b/Modules/_testcapi/clinic/vectorcall.c.h
index 728c0d382565a..48688e9ade050 100644
--- a/Modules/_testcapi/clinic/vectorcall.c.h
+++ b/Modules/_testcapi/clinic/vectorcall.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_testcapi_pyobject_fastcalldict__doc__,
"pyobject_fastcalldict($module, func, func_args, kwargs, /)\n"
"--\n"
@@ -210,4 +204,4 @@ _testcapi_has_vectorcall_flag(PyObject *module, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=beaf6beac3d13c25 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0667266b825ec9ec input=a9049054013a1b77]*/
diff --git a/Modules/_testcapi/clinic/watchers.c.h b/Modules/_testcapi/clinic/watchers.c.h
index ce9c770a37cc5..fd2ef60833404 100644
--- a/Modules/_testcapi/clinic/watchers.c.h
+++ b/Modules/_testcapi/clinic/watchers.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_testcapi_watch_dict__doc__,
"watch_dict($module, watcher_id, dict, /)\n"
"--\n"
@@ -195,4 +189,4 @@ _testcapi_set_func_kwdefaults_via_capi(PyObject *module, PyObject *const *args,
exit:
return return_value;
}
-/*[clinic end generated code: output=b7564a84c5815b46 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5ad5771d6b29dfb9 input=a9049054013a1b77]*/
diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h b/Modules/cjkcodecs/clinic/multibytecodec.c.h
index 1b41c231eac5d..0b73a7059eb58 100644
--- a/Modules/cjkcodecs/clinic/multibytecodec.c.h
+++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_multibytecodec_MultibyteCodec_encode__doc__,
"encode($self, /, input, errors=None)\n"
"--\n"
@@ -690,4 +689,4 @@ PyDoc_STRVAR(_multibytecodec___create_codec__doc__,
#define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF \
{"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, _multibytecodec___create_codec__doc__},
-/*[clinic end generated code: output=5f0e8dacddb0ac76 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1ee928e7a85e9d34 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_abc.c.h b/Modules/clinic/_abc.c.h
index 2adec818c9131..8d3832e1b83d2 100644
--- a/Modules/clinic/_abc.c.h
+++ b/Modules/clinic/_abc.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_abc__reset_registry__doc__,
"_reset_registry($module, self, /)\n"
"--\n"
@@ -165,4 +159,4 @@ _abc_get_cache_token(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return _abc_get_cache_token_impl(module);
}
-/*[clinic end generated code: output=c2e69611a495c98d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=babb3ce445fa9b21 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_asynciomodule.c.h b/Modules/clinic/_asynciomodule.c.h
index 6a780a80cd0bc..74dd06461e6e2 100644
--- a/Modules/clinic/_asynciomodule.c.h
+++ b/Modules/clinic/_asynciomodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_asyncio_Future___init____doc__,
"Future(*, loop=None)\n"
"--\n"
@@ -1487,4 +1486,4 @@ _asyncio_current_task(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
exit:
return return_value;
}
-/*[clinic end generated code: output=6b0e283177b07639 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1b7658bfab7024f3 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_bisectmodule.c.h b/Modules/clinic/_bisectmodule.c.h
index 62ce0fc817236..5553b05acbf52 100644
--- a/Modules/clinic/_bisectmodule.c.h
+++ b/Modules/clinic/_bisectmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_bisect_bisect_right__doc__,
"bisect_right($module, /, a, x, lo=0, hi=None, *, key=None)\n"
@@ -434,4 +433,4 @@ _bisect_insort_left(PyObject *module, PyObject *const *args, Py_ssize_t nargs, P
exit:
return return_value;
}
-/*[clinic end generated code: output=839fdddeacdc2ecb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=43ece163c3e972df input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h
index 7c4d57b5fec7e..29f5d3a68e06a 100644
--- a/Modules/clinic/_bz2module.c.h
+++ b/Modules/clinic/_bz2module.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_bz2_BZ2Compressor_compress__doc__,
"compress($self, data, /)\n"
@@ -242,4 +241,4 @@ _bz2_BZ2Decompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=40706688f92642b4 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3dfc8436fa8eaefb input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_codecsmodule.c.h b/Modules/clinic/_codecsmodule.c.h
index fc6dcaa765128..bf9bd4a61f5ce 100644
--- a/Modules/clinic/_codecsmodule.c.h
+++ b/Modules/clinic/_codecsmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_codecs_register__doc__,
"register($module, search_function, /)\n"
"--\n"
@@ -2818,4 +2817,4 @@ _codecs_lookup_error(PyObject *module, PyObject *arg)
#ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF
#define _CODECS_CODE_PAGE_ENCODE_METHODDEF
#endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */
-/*[clinic end generated code: output=6d9bc20c8dd36134 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3473564544f10403 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h
index b96502d3cf4b3..a375b87261ce2 100644
--- a/Modules/clinic/_collectionsmodule.c.h
+++ b/Modules/clinic/_collectionsmodule.c.h
@@ -2,12 +2,7 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_collections__count_elements__doc__,
"_count_elements($module, mapping, iterable, /)\n"
@@ -76,4 +71,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=d83188040656ad7c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b01ddb9fdecc4a2d input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_contextvarsmodule.c.h b/Modules/clinic/_contextvarsmodule.c.h
index 461d4845635ef..b1885e41c355d 100644
--- a/Modules/clinic/_contextvarsmodule.c.h
+++ b/Modules/clinic/_contextvarsmodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_contextvars_copy_context__doc__,
"copy_context($module, /)\n"
"--\n"
@@ -24,4 +18,4 @@ _contextvars_copy_context(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return _contextvars_copy_context_impl(module);
}
-/*[clinic end generated code: output=1736c27450823e70 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=26e07024451baf52 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_csv.c.h b/Modules/clinic/_csv.c.h
index 8900946350a52..86ed0efd79028 100644
--- a/Modules/clinic/_csv.c.h
+++ b/Modules/clinic/_csv.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_csv_list_dialects__doc__,
"list_dialects($module, /)\n"
"--\n"
@@ -206,4 +205,4 @@ _csv_field_size_limit(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
exit:
return return_value;
}
-/*[clinic end generated code: output=94374e41eb2806ee input=a9049054013a1b77]*/
+/*[clinic end generated code: output=4704d708f5745e91 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_curses_panel.c.h b/Modules/clinic/_curses_panel.c.h
index 900058e6d59af..a8c32c6aa3fc1 100644
--- a/Modules/clinic/_curses_panel.c.h
+++ b/Modules/clinic/_curses_panel.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_curses_panel_panel_bottom__doc__,
"bottom($self, /)\n"
"--\n"
@@ -422,4 +416,4 @@ _curses_panel_update_panels(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return _curses_panel_update_panels_impl(module);
}
-/*[clinic end generated code: output=cb76cb1d5040f387 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=dd302cb9afc42f40 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_cursesmodule.c.h b/Modules/clinic/_cursesmodule.c.h
index 836087581a73b..ecc3c059d03c9 100644
--- a/Modules/clinic/_cursesmodule.c.h
+++ b/Modules/clinic/_cursesmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_curses_window_addch__doc__,
"addch([y, x,] ch, [attr=_curses.A_NORMAL])\n"
"Paint the character.\n"
@@ -4313,4 +4312,4 @@ _curses_has_extended_color_support(PyObject *module, PyObject *Py_UNUSED(ignored
#ifndef _CURSES_USE_DEFAULT_COLORS_METHODDEF
#define _CURSES_USE_DEFAULT_COLORS_METHODDEF
#endif /* !defined(_CURSES_USE_DEFAULT_COLORS_METHODDEF) */
-/*[clinic end generated code: output=cff0e570de65d9b8 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=839faafb638935ea input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_datetimemodule.c.h b/Modules/clinic/_datetimemodule.c.h
index c058c13fcc068..177a37e486e24 100644
--- a/Modules/clinic/_datetimemodule.c.h
+++ b/Modules/clinic/_datetimemodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(datetime_date_fromtimestamp__doc__,
"fromtimestamp($type, timestamp, /)\n"
"--\n"
@@ -146,4 +145,4 @@ datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t narg
exit:
return return_value;
}
-/*[clinic end generated code: output=720c99f24a9aa41c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e422c25b1c28f38b input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h
index fbf4ccf27c1f7..a76b8b30eded3 100644
--- a/Modules/clinic/_dbmmodule.c.h
+++ b/Modules/clinic/_dbmmodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_dbm_dbm_close__doc__,
"close($self, /)\n"
"--\n"
@@ -222,4 +216,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=f1bf74536f201669 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=972d221f9da819d3 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h
index 78e456b6a4346..3477257f9d2cf 100644
--- a/Modules/clinic/_elementtree.c.h
+++ b/Modules/clinic/_elementtree.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_elementtree_Element_append__doc__,
"append($self, subelement, /)\n"
@@ -1219,4 +1218,4 @@ _elementtree_XMLParser__setevents(XMLParserObject *self, PyObject *const *args,
exit:
return return_value;
}
-/*[clinic end generated code: output=0a34620406b95eb0 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=20d1869da79a43d7 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_functoolsmodule.c.h b/Modules/clinic/_functoolsmodule.c.h
index 9c79e6430413b..25a3e5b0da60a 100644
--- a/Modules/clinic/_functoolsmodule.c.h
+++ b/Modules/clinic/_functoolsmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_functools_cmp_to_key__doc__,
"cmp_to_key($module, /, mycmp)\n"
"--\n"
@@ -101,4 +100,4 @@ _functools__lru_cache_wrapper_cache_clear(PyObject *self, PyObject *Py_UNUSED(ig
{
return _functools__lru_cache_wrapper_cache_clear_impl(self);
}
-/*[clinic end generated code: output=7e7f3bcf9ed61f23 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=de9cf85e85167f43 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h
index 73e2d7934213e..e9138bbf0430c 100644
--- a/Modules/clinic/_gdbmmodule.c.h
+++ b/Modules/clinic/_gdbmmodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_gdbm_gdbm_get__doc__,
"get($self, key, default=None, /)\n"
"--\n"
@@ -344,4 +338,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=cf48d9f76fdd62b9 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=84f30c7fff0eadac input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h
index 0ea192eac2d3f..e41f608bde501 100644
--- a/Modules/clinic/_hashopenssl.c.h
+++ b/Modules/clinic/_hashopenssl.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(EVP_copy__doc__,
"copy($self, /)\n"
@@ -1852,4 +1851,4 @@ _hashlib_compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t narg
#ifndef _HASHLIB_SCRYPT_METHODDEF
#define _HASHLIB_SCRYPT_METHODDEF
#endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */
-/*[clinic end generated code: output=cfad8d5e904a4917 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=75413752099f2dec input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_heapqmodule.c.h b/Modules/clinic/_heapqmodule.c.h
index 3ee3f51702fa3..8d73b5b48d6a0 100644
--- a/Modules/clinic/_heapqmodule.c.h
+++ b/Modules/clinic/_heapqmodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_heapq_heappush__doc__,
"heappush($module, heap, item, /)\n"
"--\n"
@@ -271,4 +265,4 @@ _heapq__heapify_max(PyObject *module, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=29e99a48c57f82bb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=9a22715a8bf0c91d input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_localemodule.c.h b/Modules/clinic/_localemodule.c.h
index 18cf5025012e7..efbb9f709958c 100644
--- a/Modules/clinic/_localemodule.c.h
+++ b/Modules/clinic/_localemodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_locale_setlocale__doc__,
"setlocale($module, category, locale=<unrepresentable>, /)\n"
"--\n"
@@ -599,4 +593,4 @@ _locale_getencoding(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF
#define _LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF
#endif /* !defined(_LOCALE_BIND_TEXTDOMAIN_CODESET_METHODDEF) */
-/*[clinic end generated code: output=119644f17919234d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3abe7fade999eff6 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_lsprof.c.h b/Modules/clinic/_lsprof.c.h
index 5fcc7ae02e3b0..dfc003eb54774 100644
--- a/Modules/clinic/_lsprof.c.h
+++ b/Modules/clinic/_lsprof.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_lsprof_Profiler_getstats__doc__,
"getstats($self, /)\n"
"--\n"
@@ -51,4 +45,4 @@ _lsprof_Profiler_getstats(ProfilerObject *self, PyTypeObject *cls, PyObject *con
}
return _lsprof_Profiler_getstats_impl(self, cls);
}
-/*[clinic end generated code: output=7425d3481349629a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0615a53cce828f06 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_lzmamodule.c.h b/Modules/clinic/_lzmamodule.c.h
index ceb7539915762..528b48384f0bc 100644
--- a/Modules/clinic/_lzmamodule.c.h
+++ b/Modules/clinic/_lzmamodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_lzma_LZMACompressor_compress__doc__,
"compress($self, data, /)\n"
@@ -339,4 +338,4 @@ _lzma__decode_filter_properties(PyObject *module, PyObject *const *args, Py_ssiz
return return_value;
}
-/*[clinic end generated code: output=f1a001f5f489c372 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=eadc9ee7a11a06f5 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_opcode.c.h b/Modules/clinic/_opcode.c.h
index f8e6a0a54f940..4b9a70d2ba985 100644
--- a/Modules/clinic/_opcode.c.h
+++ b/Modules/clinic/_opcode.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_opcode_stack_effect__doc__,
"stack_effect($module, opcode, oparg=None, /, *, jump=None)\n"
"--\n"
@@ -668,4 +667,4 @@ _opcode_get_intrinsic2_descs(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return _opcode_get_intrinsic2_descs_impl(module);
}
-/*[clinic end generated code: output=ce89aee80dd825d2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d608239a4c7a05a1 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_operator.c.h b/Modules/clinic/_operator.c.h
index 18b0b920b0d11..06bde243b4e85 100644
--- a/Modules/clinic/_operator.c.h
+++ b/Modules/clinic/_operator.c.h
@@ -2,12 +2,7 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_operator_truth__doc__,
"truth($module, a, /)\n"
@@ -1493,4 +1488,4 @@ _operator__compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t na
exit:
return return_value;
}
-/*[clinic end generated code: output=72bc63a775937245 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=9658aca50a9ad991 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_pickle.c.h b/Modules/clinic/_pickle.c.h
index 539acc34a05cc..5df40d6282775 100644
--- a/Modules/clinic/_pickle.c.h
+++ b/Modules/clinic/_pickle.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_pickle_Pickler_clear_memo__doc__,
"clear_memo($self, /)\n"
"--\n"
@@ -1034,4 +1033,4 @@ _pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
exit:
return return_value;
}
-/*[clinic end generated code: output=a0e04b85e7bae626 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=57c209a12264146d input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_posixsubprocess.c.h b/Modules/clinic/_posixsubprocess.c.h
index 3b19a47e71649..83048a385d319 100644
--- a/Modules/clinic/_posixsubprocess.c.h
+++ b/Modules/clinic/_posixsubprocess.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(subprocess_fork_exec__doc__,
"fork_exec($module, args, executable_list, close_fds, pass_fds, cwd,\n"
" env, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite,\n"
@@ -159,4 +153,4 @@ subprocess_fork_exec(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=be0e9b5d8c0217fa input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a83b11467169b97b input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_queuemodule.c.h b/Modules/clinic/_queuemodule.c.h
index 94fb59a5b17a4..8d4df14ae3b00 100644
--- a/Modules/clinic/_queuemodule.c.h
+++ b/Modules/clinic/_queuemodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(simplequeue_new__doc__,
"SimpleQueue()\n"
"--\n"
@@ -331,4 +330,4 @@ _queue_SimpleQueue_qsize(simplequeueobject *self, PyObject *Py_UNUSED(ignored))
exit:
return return_value;
}
-/*[clinic end generated code: output=9a72a8d1b5767f6a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5c326e4c1f2a1ad7 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_randommodule.c.h b/Modules/clinic/_randommodule.c.h
index 45f06b60ed444..008b531d832c5 100644
--- a/Modules/clinic/_randommodule.c.h
+++ b/Modules/clinic/_randommodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_random_Random_random__doc__,
"random($self, /)\n"
"--\n"
@@ -115,4 +109,4 @@ _random_Random_getrandbits(RandomObject *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=3feabc783b317d0d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5e7e05d756a7e1c7 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h
index 6ab8e3ee43633..5f8ae29180a4f 100644
--- a/Modules/clinic/_ssl.c.h
+++ b/Modules/clinic/_ssl.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_ssl__SSLSocket_do_handshake__doc__,
"do_handshake($self, /)\n"
@@ -1543,4 +1542,4 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje
#ifndef _SSL_ENUM_CRLS_METHODDEF
#define _SSL_ENUM_CRLS_METHODDEF
#endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */
-/*[clinic end generated code: output=6e2eb86330f3f9b8 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a47d575abe0aceb6 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_statisticsmodule.c.h b/Modules/clinic/_statisticsmodule.c.h
index 4dedadd2939ad..03543e41af7f5 100644
--- a/Modules/clinic/_statisticsmodule.c.h
+++ b/Modules/clinic/_statisticsmodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_statistics__normal_dist_inv_cdf__doc__,
"_normal_dist_inv_cdf($module, p, mu, sigma, /)\n"
"--\n"
@@ -71,4 +65,4 @@ _statistics__normal_dist_inv_cdf(PyObject *module, PyObject *const *args, Py_ssi
exit:
return return_value;
}
-/*[clinic end generated code: output=6899dc752cc6b457 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b807a8243e7801e6 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_struct.c.h b/Modules/clinic/_struct.c.h
index a823364447818..8c468e6e7205e 100644
--- a/Modules/clinic/_struct.c.h
+++ b/Modules/clinic/_struct.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(Struct__doc__,
"Struct(format)\n"
@@ -452,4 +451,4 @@ iter_unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
return return_value;
}
-/*[clinic end generated code: output=9b48aeaa86898ec5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5c1bc384ff87df1f input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h
index 94c4b5a1221ee..ba3aeca49e26e 100644
--- a/Modules/clinic/_testclinic.c.h
+++ b/Modules/clinic/_testclinic.c.h
@@ -3,12 +3,11 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
-#include "pycore_long.h" // _PyLong_UnsignedShort_Converter()
+#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_long.h" // _PyLong_UnsignedShort_Converter()
+#include "pycore_runtime.h" // _Py_ID()
PyDoc_STRVAR(test_empty_function__doc__,
"test_empty_function($module, /)\n"
@@ -3071,4 +3070,4 @@ clone_with_conv_f2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py
exit:
return return_value;
}
-/*[clinic end generated code: output=a652e6b1787d3346 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=c2a69a08ffdfc466 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_testclinic_depr.c.h b/Modules/clinic/_testclinic_depr.c.h
index 7b9d8971efb46..36ff55bc00293 100644
--- a/Modules/clinic/_testclinic_depr.c.h
+++ b/Modules/clinic/_testclinic_depr.c.h
@@ -3,12 +3,11 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
-#include "pycore_long.h" // _PyLong_UnsignedShort_Converter()
+#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_long.h" // _PyLong_UnsignedShort_Converter()
+#include "pycore_runtime.h" // _Py_ID()
PyDoc_STRVAR(depr_star_new__doc__,
"DeprStarNew(a=None)\n"
@@ -2393,4 +2392,4 @@ depr_multi(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
exit:
return return_value;
}
-/*[clinic end generated code: output=464aeba97e482f5c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=689b1e2d0872e413 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_testinternalcapi.c.h b/Modules/clinic/_testinternalcapi.c.h
index 72a5f16609965..2876138702350 100644
--- a/Modules/clinic/_testinternalcapi.c.h
+++ b/Modules/clinic/_testinternalcapi.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_testinternalcapi_compiler_cleandoc__doc__,
"compiler_cleandoc($module, /, doc)\n"
"--\n"
@@ -265,4 +264,4 @@ _testinternalcapi_assemble_code_object(PyObject *module, PyObject *const *args,
exit:
return return_value;
}
-/*[clinic end generated code: output=1ce6e2257e95a853 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=cba1c94ff4015b82 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_testmultiphase.c.h b/Modules/clinic/_testmultiphase.c.h
index f7b99b1c52f0a..a96d20bf33ea0 100644
--- a/Modules/clinic/_testmultiphase.c.h
+++ b/Modules/clinic/_testmultiphase.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_testmultiphase_StateAccessType_get_defining_module__doc__,
"get_defining_module($self, /)\n"
"--\n"
@@ -162,4 +161,4 @@ _testmultiphase_StateAccessType_get_count(StateAccessTypeObject *self, PyTypeObj
}
return _testmultiphase_StateAccessType_get_count_impl(self, cls);
}
-/*[clinic end generated code: output=6f8db3983c5312a0 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=db1fdd15244ee59c input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_tkinter.c.h b/Modules/clinic/_tkinter.c.h
index e588ea6989c67..fcfc406238808 100644
--- a/Modules/clinic/_tkinter.c.h
+++ b/Modules/clinic/_tkinter.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_tkinter_tkapp_eval__doc__,
"eval($self, script, /)\n"
"--\n"
@@ -865,4 +859,4 @@ _tkinter_getbusywaitinterval(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF
#define _TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF
#endif /* !defined(_TKINTER_TKAPP_DELETEFILEHANDLER_METHODDEF) */
-/*[clinic end generated code: output=2cdb2fd0ce66ebe5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=bcd9cdc8f6bdcfae input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_tracemalloc.c.h b/Modules/clinic/_tracemalloc.c.h
index aa4fe84939aaa..c07ad797d6295 100644
--- a/Modules/clinic/_tracemalloc.c.h
+++ b/Modules/clinic/_tracemalloc.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_tracemalloc_is_tracing__doc__,
"is_tracing($module, /)\n"
"--\n"
@@ -218,4 +212,4 @@ _tracemalloc_reset_peak(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return _tracemalloc_reset_peak_impl(module);
}
-/*[clinic end generated code: output=98a42e95af7eaf09 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ad7d1fae89f2bdaa input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_typingmodule.c.h b/Modules/clinic/_typingmodule.c.h
index f980aa0d0844d..ea415e67153ed 100644
--- a/Modules/clinic/_typingmodule.c.h
+++ b/Modules/clinic/_typingmodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_typing__idfunc__doc__,
"_idfunc($module, x, /)\n"
"--\n"
@@ -15,4 +9,4 @@ PyDoc_STRVAR(_typing__idfunc__doc__,
#define _TYPING__IDFUNC_METHODDEF \
{"_idfunc", (PyCFunction)_typing__idfunc, METH_O, _typing__idfunc__doc__},
-/*[clinic end generated code: output=97457fda45072c7d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e7ea2a3cb7ab301a input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_weakref.c.h b/Modules/clinic/_weakref.c.h
index 48feb042cac03..541cba75e6813 100644
--- a/Modules/clinic/_weakref.c.h
+++ b/Modules/clinic/_weakref.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_weakref_getweakrefcount__doc__,
"getweakrefcount($module, object, /)\n"
"--\n"
@@ -116,4 +110,4 @@ _weakref_proxy(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=28265e89d583273d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f4be6b8177fbceb8 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_winapi.c.h b/Modules/clinic/_winapi.c.h
index c648e68be448c..7fef127bef860 100644
--- a/Modules/clinic/_winapi.c.h
+++ b/Modules/clinic/_winapi.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_long.h" // _PyLong_Size_t_Converter()
+#include "pycore_long.h" // _PyLong_Size_t_Converter()
PyDoc_STRVAR(_winapi_Overlapped_GetOverlappedResult__doc__,
"GetOverlappedResult($self, wait, /)\n"
@@ -1479,4 +1478,4 @@ _winapi_CopyFile2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyO
return return_value;
}
-/*[clinic end generated code: output=c7e08927e163ef13 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6df38b5eb93f2e5a input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_zoneinfo.c.h b/Modules/clinic/_zoneinfo.c.h
index ae62865e0f67d..6691d39deb7c2 100644
--- a/Modules/clinic/_zoneinfo.c.h
+++ b/Modules/clinic/_zoneinfo.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(zoneinfo_ZoneInfo_from_file__doc__,
"from_file($type, file_obj, /, key=None)\n"
"--\n"
@@ -372,4 +371,4 @@ zoneinfo_ZoneInfo__unpickle(PyTypeObject *type, PyTypeObject *cls, PyObject *con
exit:
return return_value;
}
-/*[clinic end generated code: output=54051388dfc408af input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a5384f79d49a593b input=a9049054013a1b77]*/
diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h
index 8bdfcc62bef08..2a874b8c83060 100644
--- a/Modules/clinic/arraymodule.c.h
+++ b/Modules/clinic/arraymodule.c.h
@@ -2,12 +2,7 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(array_array___copy____doc__,
"__copy__($self, /)\n"
@@ -675,4 +670,4 @@ PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \
{"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
-/*[clinic end generated code: output=ab24c7a40a41c2e1 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8595b1906b5a6552 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h
index 8af49b4d87afc..d80decf145bfd 100644
--- a/Modules/clinic/binascii.c.h
+++ b/Modules/clinic/binascii.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(binascii_a2b_uu__doc__,
"a2b_uu($module, data, /)\n"
"--\n"
@@ -795,4 +794,4 @@ binascii_b2a_qp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
return return_value;
}
-/*[clinic end generated code: output=bf950ef45a10928d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=acc9419209dfd568 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/cmathmodule.c.h b/Modules/clinic/cmathmodule.c.h
index 941448e76e80d..a665ac3c1c499 100644
--- a/Modules/clinic/cmathmodule.c.h
+++ b/Modules/clinic/cmathmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(cmath_acos__doc__,
"acos($module, z, /)\n"
"--\n"
@@ -982,4 +981,4 @@ cmath_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
exit:
return return_value;
}
-/*[clinic end generated code: output=87f609786ef270cd input=a9049054013a1b77]*/
+/*[clinic end generated code: output=96a5c4ae198dd5bf input=a9049054013a1b77]*/
diff --git a/Modules/clinic/fcntlmodule.c.h b/Modules/clinic/fcntlmodule.c.h
index c15f345ee6ffe..83e882bbbaf18 100644
--- a/Modules/clinic/fcntlmodule.c.h
+++ b/Modules/clinic/fcntlmodule.c.h
@@ -2,12 +2,7 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-#include "pycore_fileutils.h" // _PyLong_FileDescriptor_Converter()
+#include "pycore_fileutils.h" // _PyLong_FileDescriptor_Converter()
PyDoc_STRVAR(fcntl_fcntl__doc__,
"fcntl($module, fd, cmd, arg=0, /)\n"
@@ -250,4 +245,4 @@ fcntl_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=5f096e8731fa38be input=a9049054013a1b77]*/
+/*[clinic end generated code: output=4d4fac195494faec input=a9049054013a1b77]*/
diff --git a/Modules/clinic/gcmodule.c.h b/Modules/clinic/gcmodule.c.h
index 290a8aaa2728e..40448404877e3 100644
--- a/Modules/clinic/gcmodule.c.h
+++ b/Modules/clinic/gcmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
+#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(gc_enable__doc__,
"enable($module, /)\n"
@@ -425,4 +424,4 @@ gc_get_freeze_count(PyObject *module, PyObject *Py_UNUSED(ignored))
exit:
return return_value;
}
-/*[clinic end generated code: output=fe89ce0b90a1067d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=63093e7724b94a37 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/grpmodule.c.h b/Modules/clinic/grpmodule.c.h
index 38de3ce68ceb7..e6c9cccfce4a7 100644
--- a/Modules/clinic/grpmodule.c.h
+++ b/Modules/clinic/grpmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(grp_getgrgid__doc__,
"getgrgid($module, /, id)\n"
"--\n"
@@ -146,4 +145,4 @@ grp_getgrall(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return grp_getgrall_impl(module);
}
-/*[clinic end generated code: output=e685227ed5d9be9f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d4bdad9b26fb8558 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/itertoolsmodule.c.h b/Modules/clinic/itertoolsmodule.c.h
index 6555bd495b200..74cd3ddc3c9a8 100644
--- a/Modules/clinic/itertoolsmodule.c.h
+++ b/Modules/clinic/itertoolsmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(batched_new__doc__,
"batched(iterable, n)\n"
@@ -914,4 +913,4 @@ itertools_count(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=20999801c7349d2c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=95bb863274717bd9 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/mathmodule.c.h b/Modules/clinic/mathmodule.c.h
index c16c1b083985f..bfce397be77c8 100644
--- a/Modules/clinic/mathmodule.c.h
+++ b/Modules/clinic/mathmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(math_ceil__doc__,
"ceil($module, x, /)\n"
"--\n"
@@ -950,4 +949,4 @@ math_ulp(PyObject *module, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=91a0357265a2a553 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=da62cea7eb3dc8bc input=a9049054013a1b77]*/
diff --git a/Modules/clinic/md5module.c.h b/Modules/clinic/md5module.c.h
index b4602104f1804..6087a0f9c25c1 100644
--- a/Modules/clinic/md5module.c.h
+++ b/Modules/clinic/md5module.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(MD5Type_copy__doc__,
"copy($self, /)\n"
"--\n"
@@ -148,4 +147,4 @@ _md5_md5(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kw
exit:
return return_value;
}
-/*[clinic end generated code: output=b4924c9905cc9f34 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=943d42b9d17d9a5b input=a9049054013a1b77]*/
diff --git a/Modules/clinic/overlapped.c.h b/Modules/clinic/overlapped.c.h
index 100df2062d8ef..9a71e25aa557a 100644
--- a/Modules/clinic/overlapped.c.h
+++ b/Modules/clinic/overlapped.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
+#include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
PyDoc_STRVAR(_overlapped_CreateIoCompletionPort__doc__,
"CreateIoCompletionPort($module, handle, port, key, concurrency, /)\n"
@@ -1263,4 +1262,4 @@ _overlapped_Overlapped_WSARecvFromInto(OverlappedObject *self, PyObject *const *
return return_value;
}
-/*[clinic end generated code: output=994ad727b827ff87 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=31bcc780209593a2 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
index e80bbff6b5156..854fd6cf5ec35 100644
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -3,13 +3,12 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
-#include "pycore_fileutils.h" // _PyLong_FileDescriptor_Converter()
-#include "pycore_long.h" // _PyLong_UnsignedInt_Converter()
+#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_fileutils.h" // _PyLong_FileDescriptor_Converter()
+#include "pycore_long.h" // _PyLong_UnsignedInt_Converter()
PyDoc_STRVAR(os_stat__doc__,
"stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
@@ -11993,4 +11992,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
-/*[clinic end generated code: output=1b34619e5f65adc2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=30c63cb556431cea input=a9049054013a1b77]*/
diff --git a/Modules/clinic/pwdmodule.c.h b/Modules/clinic/pwdmodule.c.h
index 748c873b1c8a4..0e8aa5e6a9f47 100644
--- a/Modules/clinic/pwdmodule.c.h
+++ b/Modules/clinic/pwdmodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(pwd_getpwuid__doc__,
"getpwuid($module, uidobj, /)\n"
"--\n"
@@ -77,4 +71,4 @@ pwd_getpwall(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef PWD_GETPWALL_METHODDEF
#define PWD_GETPWALL_METHODDEF
#endif /* !defined(PWD_GETPWALL_METHODDEF) */
-/*[clinic end generated code: output=1edf1e26cd2762db input=a9049054013a1b77]*/
+/*[clinic end generated code: output=211c7a2516899b91 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/pyexpat.c.h b/Modules/clinic/pyexpat.c.h
index 97247781eaa07..21b09110d0085 100644
--- a/Modules/clinic/pyexpat.c.h
+++ b/Modules/clinic/pyexpat.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(pyexpat_xmlparser_Parse__doc__,
"Parse($self, data, isfinal=False, /)\n"
"--\n"
@@ -498,4 +497,4 @@ pyexpat_ErrorString(PyObject *module, PyObject *arg)
#ifndef PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
#define PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF
#endif /* !defined(PYEXPAT_XMLPARSER_USEFOREIGNDTD_METHODDEF) */
-/*[clinic end generated code: output=6b30852bfc778208 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ac398d94833e802d input=a9049054013a1b77]*/
diff --git a/Modules/clinic/readline.c.h b/Modules/clinic/readline.c.h
index 0bd6e36851e45..e5a784a5f79e5 100644
--- a/Modules/clinic/readline.c.h
+++ b/Modules/clinic/readline.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(readline_parse_and_bind__doc__,
"parse_and_bind($module, string, /)\n"
"--\n"
@@ -688,4 +682,4 @@ readline_redisplay(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef READLINE_CLEAR_HISTORY_METHODDEF
#define READLINE_CLEAR_HISTORY_METHODDEF
#endif /* !defined(READLINE_CLEAR_HISTORY_METHODDEF) */
-/*[clinic end generated code: output=2c9c5709b3e00c8b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=790ed2ba01babb60 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/resource.c.h b/Modules/clinic/resource.c.h
index d769a7f612357..0ac272af25d15 100644
--- a/Modules/clinic/resource.c.h
+++ b/Modules/clinic/resource.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
#if defined(HAVE_GETRUSAGE)
PyDoc_STRVAR(resource_getrusage__doc__,
@@ -178,4 +172,4 @@ resource_getpagesize(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef RESOURCE_PRLIMIT_METHODDEF
#define RESOURCE_PRLIMIT_METHODDEF
#endif /* !defined(RESOURCE_PRLIMIT_METHODDEF) */
-/*[clinic end generated code: output=916ecf0eb1927c37 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2376b9a3f03777aa input=a9049054013a1b77]*/
diff --git a/Modules/clinic/selectmodule.c.h b/Modules/clinic/selectmodule.c.h
index 69c0f06789e71..282196b8f8897 100644
--- a/Modules/clinic/selectmodule.c.h
+++ b/Modules/clinic/selectmodule.c.h
@@ -3,12 +3,11 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_fileutils.h" // _PyLong_FileDescriptor_Converter()
-#include "pycore_long.h" // _PyLong_UnsignedShort_Converter()
+#include "pycore_fileutils.h" // _PyLong_FileDescriptor_Converter()
+#include "pycore_long.h" // _PyLong_UnsignedShort_Converter()
PyDoc_STRVAR(select_select__doc__,
"select($module, rlist, wlist, xlist, timeout=None, /)\n"
@@ -1311,4 +1310,4 @@ select_kqueue_control(kqueue_queue_Object *self, PyObject *const *args, Py_ssize
#ifndef SELECT_KQUEUE_CONTROL_METHODDEF
#define SELECT_KQUEUE_CONTROL_METHODDEF
#endif /* !defined(SELECT_KQUEUE_CONTROL_METHODDEF) */
-/*[clinic end generated code: output=a215af2157f038c7 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=35cd4aa7b6802838 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/sha1module.c.h b/Modules/clinic/sha1module.c.h
index ad15ddaadfc86..fa4ec8bb51e78 100644
--- a/Modules/clinic/sha1module.c.h
+++ b/Modules/clinic/sha1module.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(SHA1Type_copy__doc__,
"copy($self, /)\n"
"--\n"
@@ -148,4 +147,4 @@ _sha1_sha1(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
exit:
return return_value;
}
-/*[clinic end generated code: output=4d1293ca3472acdb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7efbe42154a7a7f8 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/sha2module.c.h b/Modules/clinic/sha2module.c.h
index 8f855ca345e47..9fb8bf7de876f 100644
--- a/Modules/clinic/sha2module.c.h
+++ b/Modules/clinic/sha2module.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(SHA256Type_copy__doc__,
"copy($self, /)\n"
"--\n"
@@ -437,4 +436,4 @@ _sha2_sha384(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
exit:
return return_value;
}
-/*[clinic end generated code: output=f81dacb48f3fee72 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1242ccc50bcefe98 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/sha3module.c.h b/Modules/clinic/sha3module.c.h
index 80fe3ed32c80d..fd65462d62c19 100644
--- a/Modules/clinic/sha3module.c.h
+++ b/Modules/clinic/sha3module.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
+#include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
PyDoc_STRVAR(py_sha3_new__doc__,
"sha3_224(data=b\'\', /, *, usedforsecurity=True)\n"
@@ -194,4 +193,4 @@ _sha3_shake_128_hexdigest(SHA3object *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=5188d9ae4af48c6d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=0888aed37ef39984 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/signalmodule.c.h b/Modules/clinic/signalmodule.c.h
index f0ae699a3f1e1..5e8957a4be780 100644
--- a/Modules/clinic/signalmodule.c.h
+++ b/Modules/clinic/signalmodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(signal_default_int_handler__doc__,
"default_int_handler($module, signalnum, frame, /)\n"
"--\n"
@@ -705,4 +699,4 @@ signal_pidfd_send_signal(PyObject *module, PyObject *const *args, Py_ssize_t nar
#ifndef SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
#define SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF
#endif /* !defined(SIGNAL_PIDFD_SEND_SIGNAL_METHODDEF) */
-/*[clinic end generated code: output=9903be3eba6cbc1c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ef4c2ad1a2443063 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h
index 5e2f581c3e060..c62050160f111 100644
--- a/Modules/clinic/socketmodule.c.h
+++ b/Modules/clinic/socketmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
static int
sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
PyObject *fdobj);
@@ -91,4 +90,4 @@ sock_initobj(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=c44e3ac23999ac60 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=1b68ae94d6cbeeb1 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/symtablemodule.c.h b/Modules/clinic/symtablemodule.c.h
index 04fdb9f2d9b77..2cd08f8178200 100644
--- a/Modules/clinic/symtablemodule.c.h
+++ b/Modules/clinic/symtablemodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_symtable_symtable__doc__,
"symtable($module, source, filename, startstr, /)\n"
"--\n"
@@ -54,4 +48,4 @@ _symtable_symtable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=07716ddbd6c7efe1 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3f7ccf535d750238 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/syslogmodule.c.h b/Modules/clinic/syslogmodule.c.h
index 3e0792b88060c..f0c6f2a871d04 100644
--- a/Modules/clinic/syslogmodule.c.h
+++ b/Modules/clinic/syslogmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(syslog_openlog__doc__,
"openlog($module, /, ident=<unrepresentable>, logoption=0,\n"
" facility=LOG_USER)\n"
@@ -251,4 +250,4 @@ syslog_LOG_UPTO(PyObject *module, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=b8124c0977ed6177 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=68942dad7fb3872e input=a9049054013a1b77]*/
diff --git a/Modules/clinic/termios.c.h b/Modules/clinic/termios.c.h
index 44d4107c378e5..78828e57d7307 100644
--- a/Modules/clinic/termios.c.h
+++ b/Modules/clinic/termios.c.h
@@ -2,12 +2,7 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-#include "pycore_fileutils.h" // _PyLong_FileDescriptor_Converter()
+#include "pycore_fileutils.h" // _PyLong_FileDescriptor_Converter()
PyDoc_STRVAR(termios_tcgetattr__doc__,
"tcgetattr($module, fd, /)\n"
@@ -293,4 +288,4 @@ termios_tcsetwinsize(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=434df4394b596e92 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=daecc8ebc8fe29f5 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/unicodedata.c.h b/Modules/clinic/unicodedata.c.h
index ec30f9017e370..74362c6a6857b 100644
--- a/Modules/clinic/unicodedata.c.h
+++ b/Modules/clinic/unicodedata.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(unicodedata_UCD_decimal__doc__,
"decimal($self, chr, default=<unrepresentable>, /)\n"
"--\n"
@@ -523,4 +517,4 @@ unicodedata_UCD_lookup(PyObject *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=43e551ecaa985a40 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=ca10ded25747d182 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h
index 1debe2ae98959..895215307974f 100644
--- a/Modules/clinic/zlibmodule.c.h
+++ b/Modules/clinic/zlibmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(zlib_compress__doc__,
"compress($module, data, /, level=Z_DEFAULT_COMPRESSION, wbits=MAX_WBITS)\n"
@@ -1130,4 +1129,4 @@ zlib_crc32(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
#ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
#define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
#endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */
-/*[clinic end generated code: output=d574a79aa47c9969 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6d90c72ba2dd04c5 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h
index f091fc7afbd69..7039db0972199 100644
--- a/Objects/clinic/bytearrayobject.c.h
+++ b/Objects/clinic/bytearrayobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
static int
bytearray___init___impl(PyByteArrayObject *self, PyObject *arg,
@@ -1285,4 +1284,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
{
return bytearray_sizeof_impl(self);
}
-/*[clinic end generated code: output=d388e9027b333f00 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=94b9b5f492b5fed6 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h
index 66db76dbbb4fa..e2f9ba6c1e55b 100644
--- a/Objects/clinic/bytesobject.c.h
+++ b/Objects/clinic/bytesobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(bytes___bytes____doc__,
"__bytes__($self, /)\n"
@@ -1061,4 +1060,4 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=9da56b6c04914e18 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8a9f5c28cbfe7592 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/classobject.c.h b/Objects/clinic/classobject.c.h
index a7bac63052bc4..48cfd6c7b78ca 100644
--- a/Objects/clinic/classobject.c.h
+++ b/Objects/clinic/classobject.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(method___reduce____doc__,
"__reduce__($self, /)\n"
"--\n"
@@ -86,4 +80,4 @@ instancemethod_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=2a5e7fa5947a86cb input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a0d17bad3b0734d9 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/codeobject.c.h b/Objects/clinic/codeobject.c.h
index 65801bd35156a..b20b066f49490 100644
--- a/Objects/clinic/codeobject.c.h
+++ b/Objects/clinic/codeobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(code_new__doc__,
"code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n"
" flags, codestring, constants, names, varnames, filename, name,\n"
@@ -464,4 +463,4 @@ code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t n
exit:
return return_value;
}
-/*[clinic end generated code: output=0446968a1fbd13b2 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b9ccfbfabe1a5f46 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/complexobject.c.h b/Objects/clinic/complexobject.c.h
index bb2b3815415f8..788f30d54450f 100644
--- a/Objects/clinic/complexobject.c.h
+++ b/Objects/clinic/complexobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(complex_conjugate__doc__,
"conjugate($self, /)\n"
"--\n"
@@ -157,4 +156,4 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=d438b7ed87f8459e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=002c74f8a33b6697 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/descrobject.c.h b/Objects/clinic/descrobject.c.h
index 75706437df83f..4f18fd77a2c7a 100644
--- a/Objects/clinic/descrobject.c.h
+++ b/Objects/clinic/descrobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
static PyObject *
mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping);
@@ -167,4 +166,4 @@ property_init(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=8dc1ddfcf764ac8e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a97dc44d12f9f9b6 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/dictobject.c.h b/Objects/clinic/dictobject.c.h
index bc2452330e4e2..eda86c31fcc57 100644
--- a/Objects/clinic/dictobject.c.h
+++ b/Objects/clinic/dictobject.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(dict_fromkeys__doc__,
"fromkeys($type, iterable, value=None, /)\n"
"--\n"
@@ -197,4 +191,4 @@ dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
{
return dict___reversed___impl(self);
}
-/*[clinic end generated code: output=c0064abbea6091c5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=582766ac0154c8bf input=a9049054013a1b77]*/
diff --git a/Objects/clinic/enumobject.c.h b/Objects/clinic/enumobject.c.h
index adf78efd0d66f..97f20c63cd4ad 100644
--- a/Objects/clinic/enumobject.c.h
+++ b/Objects/clinic/enumobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(enum_new__doc__,
"enumerate(iterable, start=0)\n"
"--\n"
@@ -107,4 +106,4 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=aba0ddbeab1601e3 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=661b29708f501d19 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/floatobject.c.h b/Objects/clinic/floatobject.c.h
index 3d9cd3a683ff5..c40eff85cf355 100644
--- a/Objects/clinic/floatobject.c.h
+++ b/Objects/clinic/floatobject.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(float_is_integer__doc__,
"is_integer($self, /)\n"
"--\n"
@@ -322,4 +316,4 @@ float___format__(PyObject *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=355c3f5102034a41 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=eb093cc601cc5426 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/funcobject.c.h b/Objects/clinic/funcobject.c.h
index c3a3a8edc3927..1be4567428690 100644
--- a/Objects/clinic/funcobject.c.h
+++ b/Objects/clinic/funcobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(func_new__doc__,
"function(code, globals, name=None, argdefs=None, closure=None)\n"
"--\n"
@@ -104,4 +103,4 @@ func_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=777cead7b1f6fad3 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b2d676ff51c992d0 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h
index a41ed3e4b040d..b6f0c5c0c42dd 100644
--- a/Objects/clinic/listobject.c.h
+++ b/Objects/clinic/listobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(list_insert__doc__,
"insert($self, index, object, /)\n"
@@ -384,4 +383,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
{
return list___reversed___impl(self);
}
-/*[clinic end generated code: output=537a17b562c57505 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=e2d9f4092498a5ca input=a9049054013a1b77]*/
diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h
index 3ecef1f0fd54d..9288648fe3b7c 100644
--- a/Objects/clinic/longobject.c.h
+++ b/Objects/clinic/longobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
static PyObject *
long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase);
@@ -476,4 +475,4 @@ int_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return int_is_integer_impl(self);
}
-/*[clinic end generated code: output=ea9c87ea532dadbe input=a9049054013a1b77]*/
+/*[clinic end generated code: output=009a537ab558763c input=a9049054013a1b77]*/
diff --git a/Objects/clinic/memoryobject.c.h b/Objects/clinic/memoryobject.c.h
index a6561e2e54df8..74c749e0b6ccc 100644
--- a/Objects/clinic/memoryobject.c.h
+++ b/Objects/clinic/memoryobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(memoryview__doc__,
"memoryview(object)\n"
"--\n"
@@ -413,4 +412,4 @@ memoryview_hex(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs
exit:
return return_value;
}
-/*[clinic end generated code: output=28a632db32b44b63 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7ebdadda3b0fcd35 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/moduleobject.c.h b/Objects/clinic/moduleobject.c.h
index 29df388853193..ce21e4728dcb9 100644
--- a/Objects/clinic/moduleobject.c.h
+++ b/Objects/clinic/moduleobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(module___init____doc__,
"module(name, doc=None)\n"
"--\n"
@@ -74,4 +73,4 @@ module___init__(PyObject *self, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=a5a750cc8190576e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=9d3d7854d17a033c input=a9049054013a1b77]*/
diff --git a/Objects/clinic/odictobject.c.h b/Objects/clinic/odictobject.c.h
index 115a134e3f7f5..643f504535d25 100644
--- a/Objects/clinic/odictobject.c.h
+++ b/Objects/clinic/odictobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(OrderedDict_fromkeys__doc__,
"fromkeys($type, /, iterable, value=None)\n"
"--\n"
@@ -332,4 +331,4 @@ OrderedDict_move_to_end(PyODictObject *self, PyObject *const *args, Py_ssize_t n
exit:
return return_value;
}
-/*[clinic end generated code: output=76d85a9162d62ca8 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6d7ae9fb552c6108 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/structseq.c.h b/Objects/clinic/structseq.c.h
index 40ba18a544f4b..2571888454cb7 100644
--- a/Objects/clinic/structseq.c.h
+++ b/Objects/clinic/structseq.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
static PyObject *
structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict);
@@ -62,4 +61,4 @@ structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=802d5663c7d01024 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2f88fe2a6f5c13a8 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/tupleobject.c.h b/Objects/clinic/tupleobject.c.h
index 3de95759a13f2..f21712746a5ad 100644
--- a/Objects/clinic/tupleobject.c.h
+++ b/Objects/clinic/tupleobject.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(tuple_index__doc__,
"index($self, value, start=0, stop=sys.maxsize, /)\n"
"--\n"
@@ -118,4 +112,4 @@ tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
{
return tuple___getnewargs___impl(self);
}
-/*[clinic end generated code: output=48a9e0834b300ac3 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7c5d9d12e0cf6a83 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/typeobject.c.h b/Objects/clinic/typeobject.c.h
index 1857eab17a793..eb0b22a943ae8 100644
--- a/Objects/clinic/typeobject.c.h
+++ b/Objects/clinic/typeobject.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(type___instancecheck____doc__,
"__instancecheck__($self, instance, /)\n"
"--\n"
@@ -266,4 +260,4 @@ object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return object___dir___impl(self);
}
-/*[clinic end generated code: output=baf5ec2093815a3f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=943f639f264362d9 input=a9049054013a1b77]*/
diff --git a/Objects/clinic/typevarobject.c.h b/Objects/clinic/typevarobject.c.h
index 5d12be5361cd2..4762cd63545b6 100644
--- a/Objects/clinic/typevarobject.c.h
+++ b/Objects/clinic/typevarobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(typevar_new__doc__,
"typevar(name, *constraints, *, bound=None, covariant=False,\n"
" contravariant=False, infer_variance=False)\n"
@@ -591,4 +590,4 @@ typealias_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=d614edf64f28e346 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=db0b327ebbb1488f input=a9049054013a1b77]*/
diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h
index 56b64087d6654..cfee9b8aa1fa8 100644
--- a/Objects/clinic/unicodeobject.c.h
+++ b/Objects/clinic/unicodeobject.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(EncodingMap_size__doc__,
"size($self, /)\n"
@@ -1505,4 +1504,4 @@ unicode_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=a64776a3ea1c970c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8d08dfbb814c4393 input=a9049054013a1b77]*/
diff --git a/Objects/stringlib/clinic/transmogrify.h.h b/Objects/stringlib/clinic/transmogrify.h.h
index d1adda4e979c1..e81c5916e6f19 100644
--- a/Objects/stringlib/clinic/transmogrify.h.h
+++ b/Objects/stringlib/clinic/transmogrify.h.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(stringlib_expandtabs__doc__,
"expandtabs($self, /, tabsize=8)\n"
@@ -279,4 +278,4 @@ stringlib_zfill(PyObject *self, PyObject *arg)
exit:
return return_value;
}
-/*[clinic end generated code: output=a0338b2d41671b17 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=39cd1ee983137188 input=a9049054013a1b77]*/
diff --git a/PC/clinic/_testconsole.c.h b/PC/clinic/_testconsole.c.h
index b2f3b4ce8b08a..99cd302ff3469 100644
--- a/PC/clinic/_testconsole.c.h
+++ b/PC/clinic/_testconsole.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
#if defined(MS_WINDOWS)
PyDoc_STRVAR(_testconsole_write_input__doc__,
@@ -140,4 +139,4 @@ _testconsole_read_output(PyObject *module, PyObject *const *args, Py_ssize_t nar
#ifndef _TESTCONSOLE_READ_OUTPUT_METHODDEF
#define _TESTCONSOLE_READ_OUTPUT_METHODDEF
#endif /* !defined(_TESTCONSOLE_READ_OUTPUT_METHODDEF) */
-/*[clinic end generated code: output=208c72e2c873555b input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f59fe72cd4e73704 input=a9049054013a1b77]*/
diff --git a/PC/clinic/_wmimodule.cpp.h b/PC/clinic/_wmimodule.cpp.h
index bfcad41750b31..3ece5e6823b46 100644
--- a/PC/clinic/_wmimodule.cpp.h
+++ b/PC/clinic/_wmimodule.cpp.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_wmi_exec_query__doc__,
"exec_query($module, /, query)\n"
"--\n"
@@ -69,4 +68,4 @@ _wmi_exec_query(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
exit:
return return_value;
}
-/*[clinic end generated code: output=923d09bee1d15c5f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=53821e597fc2aca4 input=a9049054013a1b77]*/
diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h
index af6710af9657e..e2959a0fda1c5 100644
--- a/PC/clinic/msvcrtmodule.c.h
+++ b/PC/clinic/msvcrtmodule.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(msvcrt_heapmin__doc__,
"heapmin($module, /)\n"
"--\n"
@@ -701,4 +695,4 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg)
#ifndef MSVCRT_GETERRORMODE_METHODDEF
#define MSVCRT_GETERRORMODE_METHODDEF
#endif /* !defined(MSVCRT_GETERRORMODE_METHODDEF) */
-/*[clinic end generated code: output=f70de1b6d0e700cd input=a9049054013a1b77]*/
+/*[clinic end generated code: output=97e00f191821d4c0 input=a9049054013a1b77]*/
diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h
index 6e23929c185ca..7507c1151a984 100644
--- a/PC/clinic/winreg.c.h
+++ b/PC/clinic/winreg.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
+#include "pycore_long.h" // _PyLong_UnsignedLong_Converter()
#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES))
@@ -1762,4 +1761,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg)
#ifndef WINREG_QUERYREFLECTIONKEY_METHODDEF
#define WINREG_QUERYREFLECTIONKEY_METHODDEF
#endif /* !defined(WINREG_QUERYREFLECTIONKEY_METHODDEF) */
-/*[clinic end generated code: output=2431b1b06b148722 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d7ae41899af53d7c input=a9049054013a1b77]*/
diff --git a/PC/clinic/winsound.c.h b/PC/clinic/winsound.c.h
index d35261253557d..b8c8e7d04a699 100644
--- a/PC/clinic/winsound.c.h
+++ b/PC/clinic/winsound.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(winsound_PlaySound__doc__,
"PlaySound($module, /, sound, flags)\n"
"--\n"
@@ -206,4 +205,4 @@ winsound_MessageBeep(PyObject *module, PyObject *const *args, Py_ssize_t nargs,
exit:
return return_value;
}
-/*[clinic end generated code: output=e63a6516d7a55cb8 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=21584101f656198f input=a9049054013a1b77]*/
diff --git a/Python/clinic/Python-tokenize.c.h b/Python/clinic/Python-tokenize.c.h
index 28f5075826e36..a8453e25807b0 100644
--- a/Python/clinic/Python-tokenize.c.h
+++ b/Python/clinic/Python-tokenize.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
static PyObject *
tokenizeriter_new_impl(PyTypeObject *type, PyObject *readline,
int extra_tokens, const char *encoding);
@@ -80,4 +79,4 @@ tokenizeriter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=48be65a2808bdfa6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=406b5a433a59069c input=a9049054013a1b77]*/
diff --git a/Python/clinic/_warnings.c.h b/Python/clinic/_warnings.c.h
index 1a01416e7363c..cf3c73b1cf0e6 100644
--- a/Python/clinic/_warnings.c.h
+++ b/Python/clinic/_warnings.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
-#include "pycore_abstract.h" // _PyNumber_Index()
+#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(warnings_warn__doc__,
"warn($module, /, message, category=None, stacklevel=1, source=None, *,\n"
@@ -244,4 +243,4 @@ warnings_filters_mutated(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return warnings_filters_mutated_impl(module);
}
-/*[clinic end generated code: output=c8a6dc1403fba1d5 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8c396a721ef75739 input=a9049054013a1b77]*/
diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h
index b0d6929aa50dc..b4dcc6bf1d297 100644
--- a/Python/clinic/bltinmodule.c.h
+++ b/Python/clinic/bltinmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(builtin___import____doc__,
"__import__($module, /, name, globals=None, locals=None, fromlist=(),\n"
" level=0)\n"
@@ -1212,4 +1211,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=bb2da8ccae4190e9 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=607c62f2341ebfc0 input=a9049054013a1b77]*/
diff --git a/Python/clinic/context.c.h b/Python/clinic/context.c.h
index 27c375717bff9..292d3f7f4ff49 100644
--- a/Python/clinic/context.c.h
+++ b/Python/clinic/context.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(_contextvars_Context_get__doc__,
"get($self, key, default=None, /)\n"
"--\n"
@@ -183,4 +177,4 @@ PyDoc_STRVAR(_contextvars_ContextVar_reset__doc__,
#define _CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF \
{"reset", (PyCFunction)_contextvars_ContextVar_reset, METH_O, _contextvars_ContextVar_reset__doc__},
-/*[clinic end generated code: output=0c94d4b919500438 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2436b16a92452869 input=a9049054013a1b77]*/
diff --git a/Python/clinic/import.c.h b/Python/clinic/import.c.h
index fd54033b7e7ac..890c3026fc999 100644
--- a/Python/clinic/import.c.h
+++ b/Python/clinic/import.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(_imp_lock_held__doc__,
"lock_held($module, /)\n"
"--\n"
@@ -627,4 +626,4 @@ _imp_source_hash(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb
#ifndef _IMP_EXEC_DYNAMIC_METHODDEF
#define _IMP_EXEC_DYNAMIC_METHODDEF
#endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
-/*[clinic end generated code: output=d97b56ef622cb28a input=a9049054013a1b77]*/
+/*[clinic end generated code: output=058f6aa1c9f4ebe4 input=a9049054013a1b77]*/
diff --git a/Python/clinic/instrumentation.c.h b/Python/clinic/instrumentation.c.h
index c97fb977ad345..1b1b6d048b0dd 100644
--- a/Python/clinic/instrumentation.c.h
+++ b/Python/clinic/instrumentation.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(monitoring_use_tool_id__doc__,
"use_tool_id($module, tool_id, name, /)\n"
"--\n"
@@ -308,4 +302,4 @@ monitoring__all_events(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return monitoring__all_events_impl(module);
}
-/*[clinic end generated code: output=8baabc8341df3f0e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=46f449b18195f976 input=a9049054013a1b77]*/
diff --git a/Python/clinic/marshal.c.h b/Python/clinic/marshal.c.h
index 102e637ec1833..16e48f77c87fd 100644
--- a/Python/clinic/marshal.c.h
+++ b/Python/clinic/marshal.c.h
@@ -2,12 +2,6 @@
preserve
[clinic start generated code]*/
-#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
-#endif
-
-
PyDoc_STRVAR(marshal_dump__doc__,
"dump($module, value, file, version=version, /)\n"
"--\n"
@@ -161,4 +155,4 @@ marshal_loads(PyObject *module, PyObject *arg)
return return_value;
}
-/*[clinic end generated code: output=0f4ecfd941293f67 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=23091e077319f596 input=a9049054013a1b77]*/
diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h
index 1f751e48d3e0f..a4b39873735fd 100644
--- a/Python/clinic/sysmodule.c.h
+++ b/Python/clinic/sysmodule.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(sys_addaudithook__doc__,
"addaudithook($module, /, hook)\n"
"--\n"
@@ -1412,4 +1411,4 @@ sys__getframemodulename(PyObject *module, PyObject *const *args, Py_ssize_t narg
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
#define SYS_GETANDROIDAPILEVEL_METHODDEF
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
-/*[clinic end generated code: output=6de02cd7d925d1de input=a9049054013a1b77]*/
+/*[clinic end generated code: output=6619682ea70e7375 input=a9049054013a1b77]*/
diff --git a/Python/clinic/traceback.c.h b/Python/clinic/traceback.c.h
index 1a0eaf9e91b3c..c5687e3074878 100644
--- a/Python/clinic/traceback.c.h
+++ b/Python/clinic/traceback.c.h
@@ -3,11 +3,10 @@ preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
-# include "pycore_gc.h" // PyGC_Head
-# include "pycore_runtime.h" // _Py_ID()
+# include "pycore_gc.h" // PyGC_Head
+# include "pycore_runtime.h" // _Py_ID()
#endif
-
PyDoc_STRVAR(tb_new__doc__,
"TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)\n"
"--\n"
@@ -78,4 +77,4 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=6303f910c04227a4 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=57e27eb68d04d842 input=a9049054013a1b77]*/
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index ec5bf302416ba..b744ca7e5c814 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -77,6 +77,11 @@
"noptargs",
"return_value",
}
+
+# '#include "header.h" // reason': column of '//' comment
+INCLUDE_COMMENT_COLUMN = 35
+
+# match '#define Py_LIMITED_API'
LIMITED_CAPI_REGEX = re.compile(r'#define +Py_LIMITED_API')
@@ -675,7 +680,9 @@ def normalize_snippet(
def declare_parser(
f: Function,
*,
- hasformat: bool = False
+ hasformat: bool = False,
+ clinic: Clinic,
+ limited_capi: bool,
) -> str:
"""
Generates the code template for a static local PyArg_Parser variable,
@@ -694,7 +701,11 @@ def declare_parser(
p for p in f.parameters.values()
if not p.is_positional_only() and not p.is_vararg()
])
- if num_keywords == 0:
+ if limited_capi:
+ declarations = """
+ #define KWTUPLE NULL
+ """
+ elif num_keywords == 0:
declarations = """
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
@@ -723,6 +734,10 @@ def declare_parser(
#endif // !Py_BUILD_CORE
""" % num_keywords
+ condition = '#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)'
+ clinic.add_include('pycore_gc.h', 'PyGC_Head', condition=condition)
+ clinic.add_include('pycore_runtime.h', '_Py_ID()', condition=condition)
+
declarations += """
static const char * const _keywords[] = {{{keywords_c} NULL}};
static _PyArg_Parser _parser = {{
@@ -976,6 +991,7 @@ def deprecate_keyword_use(
argname_fmt: str | None,
*,
limited_capi: bool,
+ clinic: Clinic,
) -> str:
assert len(params) > 0
last_param = next(reversed(params.values()))
@@ -990,9 +1006,11 @@ def deprecate_keyword_use(
elif func.kind.new_or_init or limited_capi:
conditions.append(f"nargs < {i+1} && PyDict_Contains(kwargs, &_Py_ID({p.name}))")
containscheck = "PyDict_Contains"
+ clinic.add_include('pycore_runtime.h', '_Py_ID()')
else:
conditions.append(f"nargs < {i+1} && PySequence_Contains(kwnames, &_Py_ID({p.name}))")
containscheck = "PySequence_Contains"
+ clinic.add_include('pycore_runtime.h', '_Py_ID()')
else:
conditions = [f"nargs < {i+1}"]
condition = ") || (".join(conditions)
@@ -1081,8 +1099,10 @@ def output_templates(
# Copy includes from parameters to Clinic
for converter in converters:
- if converter.include:
- clinic.add_include(*converter.include)
+ include = converter.include
+ if include:
+ clinic.add_include(include.filename, include.reason,
+ condition=include.condition)
has_option_groups = parameters and (parameters[0].group or parameters[-1].group)
default_return_converter = f.return_converter.type == 'PyObject *'
@@ -1415,14 +1435,16 @@ def parser_body(
declarations += "\nPy_ssize_t nargs = PyTuple_Size(args);"
if deprecated_keywords:
code = self.deprecate_keyword_use(f, deprecated_keywords, None,
- limited_capi=limited_capi)
+ limited_capi=limited_capi,
+ clinic=clinic)
parser_code.append(code)
elif not new_or_init:
flags = "METH_FASTCALL|METH_KEYWORDS"
parser_prototype = self.PARSER_PROTOTYPE_FASTCALL_KEYWORDS
argname_fmt = 'args[%d]'
- declarations = declare_parser(f)
+ declarations = declare_parser(f, clinic=clinic,
+ limited_capi=clinic.limited_capi)
declarations += "\nPyObject *argsbuf[%s];" % len(converters)
if has_optional_kw:
declarations += "\nPy_ssize_t noptargs = %s + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - %d;" % (nargs, min_pos + min_kw_only)
@@ -1437,7 +1459,8 @@ def parser_body(
flags = "METH_VARARGS|METH_KEYWORDS"
parser_prototype = self.PARSER_PROTOTYPE_KEYWORD
argname_fmt = 'fastargs[%d]'
- declarations = declare_parser(f)
+ declarations = declare_parser(f, clinic=clinic,
+ limited_capi=clinic.limited_capi)
declarations += "\nPyObject *argsbuf[%s];" % len(converters)
declarations += "\nPyObject * const *fastargs;"
declarations += "\nPy_ssize_t nargs = PyTuple_GET_SIZE(args);"
@@ -1457,7 +1480,8 @@ def parser_body(
if not limited_capi:
if deprecated_keywords:
code = self.deprecate_keyword_use(f, deprecated_keywords, argname_fmt,
- limited_capi=limited_capi)
+ limited_capi=limited_capi,
+ clinic=clinic)
parser_code.append(code)
add_label: str | None = None
@@ -1522,7 +1546,9 @@ def parser_body(
if add_label:
parser_code.append("%s:" % add_label)
else:
- declarations = declare_parser(f, hasformat=True)
+ declarations = declare_parser(f, clinic=clinic,
+ hasformat=True,
+ limited_capi=clinic.limited_capi)
if not new_or_init:
parser_code = [normalize_snippet("""
if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser{parse_arguments_comma}
@@ -1541,7 +1567,8 @@ def parser_body(
declarations += "\nPy_ssize_t nargs = PyTuple_GET_SIZE(args);"
if deprecated_keywords:
code = self.deprecate_keyword_use(f, deprecated_keywords, None,
- limited_capi=limited_capi)
+ limited_capi=limited_capi,
+ clinic=clinic)
parser_code.append(code)
if deprecated_positionals:
@@ -2169,6 +2196,26 @@ def is_stop_line(line: str) -> bool:
return Block(input_output(), dsl_name, output=output)
+(a)dc.dataclass(slots=True, frozen=True)
+class Include:
+ """
+ An include like: #include "pycore_long.h" // _Py_ID()
+ """
+ # Example: "pycore_long.h".
+ filename: str
+
+ # Example: "_Py_ID()".
+ reason: str
+
+ # None means unconditional include.
+ # Example: "#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)".
+ condition: str | None
+
+ def sort_key(self) -> tuple[str, str]:
+ # order: '#if' comes before 'NO_CONDITION'
+ return (self.condition or 'NO_CONDITION', self.filename)
+
+
@dc.dataclass(slots=True)
class BlockPrinter:
language: Language
@@ -2180,7 +2227,7 @@ def print_block(
*,
core_includes: bool = False,
limited_capi: bool,
- header_includes: dict[str, str],
+ header_includes: dict[str, Include],
) -> None:
input = block.input
output = block.output
@@ -2209,21 +2256,32 @@ def print_block(
write("\n")
output = ''
- if core_includes:
- if not limited_capi:
- output += textwrap.dedent("""
- #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
- # include "pycore_gc.h" // PyGC_Head
- # include "pycore_runtime.h" // _Py_ID()
- #endif
-
- """)
-
+ if core_includes and header_includes:
# Emit optional "#include" directives for C headers
- for include, reason in sorted(header_includes.items()):
- line = f'#include "{include}"'.ljust(35) + f'// {reason}\n'
+ output += '\n'
+
+ current_condition: str | None = None
+ includes = sorted(header_includes.values(), key=Include.sort_key)
+ for include in includes:
+ if include.condition != current_condition:
+ if current_condition:
+ output += '#endif\n'
+ current_condition = include.condition
+ if include.condition:
+ output += f'{include.condition}\n'
+
+ if current_condition:
+ line = f'# include "{include.filename}"'
+ else:
+ line = f'#include "{include.filename}"'
+ if include.reason:
+ comment = f'// {include.reason}\n'
+ line = line.ljust(INCLUDE_COMMENT_COLUMN - 1) + comment
output += line
+ if current_condition:
+ output += '#endif\n'
+
input = ''.join(block.input)
output += ''.join(block.output)
if output:
@@ -2434,9 +2492,8 @@ def __init__(
self.modules: ModuleDict = {}
self.classes: ClassDict = {}
self.functions: list[Function] = []
- # dict: include name => reason
- # Example: 'pycore_long.h' => '_PyLong_UnsignedShort_Converter()'
- self.includes: dict[str, str] = {}
+ # dict: include name => Include instance
+ self.includes: dict[str, Include] = {}
self.line_prefix = self.line_suffix = ''
@@ -2495,11 +2552,23 @@ def __init__(
global clinic
clinic = self
- def add_include(self, name: str, reason: str) -> None:
- if name in self.includes:
- # Mention a single reason is enough, no need to list all of them
- return
- self.includes[name] = reason
+ def add_include(self, name: str, reason: str,
+ *, condition: str | None = None) -> None:
+ try:
+ existing = self.includes[name]
+ except KeyError:
+ pass
+ else:
+ if existing.condition and not condition:
+ # If the previous include has a condition and the new one is
+ # unconditional, override the include.
+ pass
+ else:
+ # Already included, do nothing. Only mention a single reason,
+ # no need to list all of them.
+ return
+
+ self.includes[name] = Include(name, reason, condition)
def add_destination(
self,
@@ -3129,10 +3198,7 @@ class CConverter(metaclass=CConverterAutoRegister):
# Only set by self_converter.
signature_name: str | None = None
- # Optional (name, reason) include which generate a line like:
- # "#include "name" // reason"
- include: tuple[str, str] | None = None
-
+ include: Include | None = None
broken_limited_capi: bool = False
# keep in sync with self_converter.__init__!
@@ -3439,10 +3505,11 @@ def parser_name(self) -> str:
else:
return self.name
- def add_include(self, name: str, reason: str) -> None:
+ def add_include(self, name: str, reason: str,
+ *, condition: str | None = None) -> None:
if self.include is not None:
raise ValueError("a converter only supports a single include")
- self.include = (name, reason)
+ self.include = Include(name, reason, condition)
type_checks = {
'&PyLong_Type': ('PyLong_Check', 'int'),
1
0
https://github.com/python/cpython/commit/2bd960b57944107fbfbd8ff005b4223e1e…
commit: 2bd960b57944107fbfbd8ff005b4223e1ea6555f
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2023-08-31T21:41:18Z
summary:
gh-108337: Add pyatomic.h header (#108701)
This adds a new header that provides atomic operations on common data
types. The intention is that this will be exposed through Python.h,
although that is not the case yet. The only immediate use is in
the test file.
Co-authored-by: Sam Gross <colesbury(a)gmail.com>
files:
A Include/cpython/pyatomic.h
A Include/cpython/pyatomic_gcc.h
A Include/cpython/pyatomic_msc.h
A Include/cpython/pyatomic_std.h
A Lib/test/test_capi/test_pyatomic.py
A Misc/NEWS.d/next/C API/2023-08-22-13-00-54.gh-issue-108337.wceHZm.rst
A Modules/_testcapi/pyatomic.c
M Doc/whatsnew/3.13.rst
M Include/internal/pycore_atomic.h
M Makefile.pre.in
M Modules/Setup.stdlib.in
M Modules/_testcapi/parts.h
M Modules/_testcapimodule.c
M PCbuild/_testcapi.vcxproj
M PCbuild/_testcapi.vcxproj.filters
M PCbuild/pythoncore.vcxproj
M PCbuild/pythoncore.vcxproj.filters
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index fd2f2c3fff828..d35d20ebb2529 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -833,6 +833,9 @@ Build Changes
:ref:`debug build <debug-build>`.
(Contributed by Victor Stinner in :gh:`108634`.)
+* Building CPython now requires a compiler with support for the C11 atomic
+ library, GCC built-in atomic functions, or MSVC interlocked intrinsics.
+
C API Changes
=============
diff --git a/Include/cpython/pyatomic.h b/Include/cpython/pyatomic.h
new file mode 100644
index 0000000000000..73712db847087
--- /dev/null
+++ b/Include/cpython/pyatomic.h
@@ -0,0 +1,506 @@
+// This header provides cross-platform low-level atomic operations
+// similar to C11 atomics.
+//
+// Operations are sequentially consistent unless they have a suffix indicating
+// otherwise. If in doubt, prefer the sequentially consistent operations.
+//
+// The "_relaxed" suffix for load and store operations indicates the "relaxed"
+// memory order. They don't provide synchronization, but (roughly speaking)
+// guarantee somewhat sane behavior for races instead of undefined behavior.
+// In practice, they correspond to "normal" hardware load and store
+// instructions, so they are almost as inexpensive as plain loads and stores
+// in C.
+//
+// Note that atomic read-modify-write operations like _Py_atomic_add_* return
+// the previous value of the atomic variable, not the new value.
+//
+// See https://en.cppreference.com/w/c/atomic for more information on C11
+// atomics.
+// See https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2055r0.pdf
+// "A Relaxed Guide to memory_order_relaxed" for discussion of and common usage
+// or relaxed atomics.
+//
+// Functions with pseudo Python code:
+//
+// def _Py_atomic_load(obj):
+// return obj # sequential consistency
+//
+// def _Py_atomic_load_relaxed(obj):
+// return obj # relaxed consistency
+//
+// def _Py_atomic_store(obj, value):
+// obj = value # sequential consistency
+//
+// def _Py_atomic_store_relaxed(obj, value):
+// obj = value # relaxed consistency
+//
+// def _Py_atomic_exchange(obj, value):
+// # sequential consistency
+// old_obj = obj
+// obj = value
+// return old_obj
+//
+// def _Py_atomic_compare_exchange(obj, expected, desired):
+// # sequential consistency
+// if obj == expected:
+// obj = desired
+// return True
+// else:
+// expected = obj
+// return False
+//
+// def _Py_atomic_add(obj, value):
+// # sequential consistency
+// old_obj = obj
+// obj += value
+// return old_obj
+//
+// def _Py_atomic_and(obj, value):
+// # sequential consistency
+// old_obj = obj
+// obj &= value
+// return old_obj
+//
+// def _Py_atomic_or(obj, value):
+// # sequential consistency
+// old_obj = obj
+// obj |= value
+// return old_obj
+//
+// Other functions:
+//
+// def _Py_atomic_load_ptr_acquire(obj):
+// return obj # acquire
+//
+// def _Py_atomic_store_ptr_release(obj):
+// return obj # release
+//
+// def _Py_atomic_fence_seq_cst():
+// # sequential consistency
+// ...
+//
+// def _Py_atomic_fence_release():
+// # release
+// ...
+
+#ifndef Py_ATOMIC_H
+#define Py_ATOMIC_H
+
+
+// --- _Py_atomic_add --------------------------------------------------------
+// Atomically adds `value` to `obj` and returns the previous value
+
+static inline int
+_Py_atomic_add_int(int *obj, int value);
+
+static inline int8_t
+_Py_atomic_add_int8(int8_t *obj, int8_t value);
+
+static inline int16_t
+_Py_atomic_add_int16(int16_t *obj, int16_t value);
+
+static inline int32_t
+_Py_atomic_add_int32(int32_t *obj, int32_t value);
+
+static inline int64_t
+_Py_atomic_add_int64(int64_t *obj, int64_t value);
+
+static inline intptr_t
+_Py_atomic_add_intptr(intptr_t *obj, intptr_t value);
+
+static inline unsigned int
+_Py_atomic_add_uint(unsigned int *obj, unsigned int value);
+
+static inline uint8_t
+_Py_atomic_add_uint8(uint8_t *obj, uint8_t value);
+
+static inline uint16_t
+_Py_atomic_add_uint16(uint16_t *obj, uint16_t value);
+
+static inline uint32_t
+_Py_atomic_add_uint32(uint32_t *obj, uint32_t value);
+
+static inline uint64_t
+_Py_atomic_add_uint64(uint64_t *obj, uint64_t value);
+
+static inline uintptr_t
+_Py_atomic_add_uintptr(uintptr_t *obj, uintptr_t value);
+
+static inline Py_ssize_t
+_Py_atomic_add_ssize(Py_ssize_t *obj, Py_ssize_t value);
+
+
+// --- _Py_atomic_compare_exchange -------------------------------------------
+// Performs an atomic compare-and-exchange.
+//
+// - If `*obj` and `*expected` are equal, store `desired` into `*obj`
+// and return 1 (success).
+// - Otherwise, store the `*obj` current value into `*expected`
+// and return 0 (failure).
+//
+// These correspond to the C11 atomic_compare_exchange_strong() function.
+
+static inline int
+_Py_atomic_compare_exchange_int(int *obj, int *expected, int desired);
+
+static inline int
+_Py_atomic_compare_exchange_int8(int8_t *obj, int8_t *expected, int8_t desired);
+
+static inline int
+_Py_atomic_compare_exchange_int16(int16_t *obj, int16_t *expected, int16_t desired);
+
+static inline int
+_Py_atomic_compare_exchange_int32(int32_t *obj, int32_t *expected, int32_t desired);
+
+static inline int
+_Py_atomic_compare_exchange_int64(int64_t *obj, int64_t *expected, int64_t desired);
+
+static inline int
+_Py_atomic_compare_exchange_intptr(intptr_t *obj, intptr_t *expected, intptr_t desired);
+
+static inline int
+_Py_atomic_compare_exchange_uint(unsigned int *obj, unsigned int *expected, unsigned int desired);
+
+static inline int
+_Py_atomic_compare_exchange_uint8(uint8_t *obj, uint8_t *expected, uint8_t desired);
+
+static inline int
+_Py_atomic_compare_exchange_uint16(uint16_t *obj, uint16_t *expected, uint16_t desired);
+
+static inline int
+_Py_atomic_compare_exchange_uint32(uint32_t *obj, uint32_t *expected, uint32_t desired);
+
+static inline int
+_Py_atomic_compare_exchange_uint64(uint64_t *obj, uint64_t *expected, uint64_t desired);
+
+static inline int
+_Py_atomic_compare_exchange_uintptr(uintptr_t *obj, uintptr_t *expected, uintptr_t desired);
+
+static inline int
+_Py_atomic_compare_exchange_ssize(Py_ssize_t *obj, Py_ssize_t *expected, Py_ssize_t desired);
+
+// NOTE: `obj` and `expected` are logically `void**` types, but we use `void*`
+// so that we can pass types like `PyObject**` without a cast.
+static inline int
+_Py_atomic_compare_exchange_ptr(void *obj, void *expected, void *value);
+
+
+// --- _Py_atomic_exchange ---------------------------------------------------
+// Atomically replaces `*obj` with `value` and returns the previous value of `*obj`.
+
+static inline int
+_Py_atomic_exchange_int(int *obj, int value);
+
+static inline int8_t
+_Py_atomic_exchange_int8(int8_t *obj, int8_t value);
+
+static inline int16_t
+_Py_atomic_exchange_int16(int16_t *obj, int16_t value);
+
+static inline int32_t
+_Py_atomic_exchange_int32(int32_t *obj, int32_t value);
+
+static inline int64_t
+_Py_atomic_exchange_int64(int64_t *obj, int64_t value);
+
+static inline intptr_t
+_Py_atomic_exchange_intptr(intptr_t *obj, intptr_t value);
+
+static inline unsigned int
+_Py_atomic_exchange_uint(unsigned int *obj, unsigned int value);
+
+static inline uint8_t
+_Py_atomic_exchange_uint8(uint8_t *obj, uint8_t value);
+
+static inline uint16_t
+_Py_atomic_exchange_uint16(uint16_t *obj, uint16_t value);
+
+static inline uint32_t
+_Py_atomic_exchange_uint32(uint32_t *obj, uint32_t value);
+
+static inline uint64_t
+_Py_atomic_exchange_uint64(uint64_t *obj, uint64_t value);
+
+static inline uintptr_t
+_Py_atomic_exchange_uintptr(uintptr_t *obj, uintptr_t value);
+
+static inline Py_ssize_t
+_Py_atomic_exchange_ssize(Py_ssize_t *obj, Py_ssize_t value);
+
+static inline void *
+_Py_atomic_exchange_ptr(void *obj, void *value);
+
+
+// --- _Py_atomic_and --------------------------------------------------------
+// Performs `*obj &= value` atomically and returns the previous value of `*obj`.
+
+static inline uint8_t
+_Py_atomic_and_uint8(uint8_t *obj, uint8_t value);
+
+static inline uint16_t
+_Py_atomic_and_uint16(uint16_t *obj, uint16_t value);
+
+static inline uint32_t
+_Py_atomic_and_uint32(uint32_t *obj, uint32_t value);
+
+static inline uint64_t
+_Py_atomic_and_uint64(uint64_t *obj, uint64_t value);
+
+static inline uintptr_t
+_Py_atomic_and_uintptr(uintptr_t *obj, uintptr_t value);
+
+
+// --- _Py_atomic_or ---------------------------------------------------------
+// Performs `*obj |= value` atomically and returns the previous value of `*obj`.
+
+static inline uint8_t
+_Py_atomic_or_uint8(uint8_t *obj, uint8_t value);
+
+static inline uint16_t
+_Py_atomic_or_uint16(uint16_t *obj, uint16_t value);
+
+static inline uint32_t
+_Py_atomic_or_uint32(uint32_t *obj, uint32_t value);
+
+static inline uint64_t
+_Py_atomic_or_uint64(uint64_t *obj, uint64_t value);
+
+static inline uintptr_t
+_Py_atomic_or_uintptr(uintptr_t *obj, uintptr_t value);
+
+
+// --- _Py_atomic_load -------------------------------------------------------
+// Atomically loads `*obj` (sequential consistency)
+
+static inline int
+_Py_atomic_load_int(const int *obj);
+
+static inline int8_t
+_Py_atomic_load_int8(const int8_t *obj);
+
+static inline int16_t
+_Py_atomic_load_int16(const int16_t *obj);
+
+static inline int32_t
+_Py_atomic_load_int32(const int32_t *obj);
+
+static inline int64_t
+_Py_atomic_load_int64(const int64_t *obj);
+
+static inline intptr_t
+_Py_atomic_load_intptr(const intptr_t *obj);
+
+static inline uint8_t
+_Py_atomic_load_uint8(const uint8_t *obj);
+
+static inline uint16_t
+_Py_atomic_load_uint16(const uint16_t *obj);
+
+static inline uint32_t
+_Py_atomic_load_uint32(const uint32_t *obj);
+
+static inline uint64_t
+_Py_atomic_load_uint64(const uint64_t *obj);
+
+static inline uintptr_t
+_Py_atomic_load_uintptr(const uintptr_t *obj);
+
+static inline unsigned int
+_Py_atomic_load_uint(const unsigned int *obj);
+
+static inline Py_ssize_t
+_Py_atomic_load_ssize(const Py_ssize_t *obj);
+
+static inline void *
+_Py_atomic_load_ptr(const void *obj);
+
+
+// --- _Py_atomic_load_relaxed -----------------------------------------------
+// Loads `*obj` (relaxed consistency, i.e., no ordering)
+
+static inline int
+_Py_atomic_load_int_relaxed(const int *obj);
+
+static inline int8_t
+_Py_atomic_load_int8_relaxed(const int8_t *obj);
+
+static inline int16_t
+_Py_atomic_load_int16_relaxed(const int16_t *obj);
+
+static inline int32_t
+_Py_atomic_load_int32_relaxed(const int32_t *obj);
+
+static inline int64_t
+_Py_atomic_load_int64_relaxed(const int64_t *obj);
+
+static inline intptr_t
+_Py_atomic_load_intptr_relaxed(const intptr_t *obj);
+
+static inline uint8_t
+_Py_atomic_load_uint8_relaxed(const uint8_t *obj);
+
+static inline uint16_t
+_Py_atomic_load_uint16_relaxed(const uint16_t *obj);
+
+static inline uint32_t
+_Py_atomic_load_uint32_relaxed(const uint32_t *obj);
+
+static inline uint64_t
+_Py_atomic_load_uint64_relaxed(const uint64_t *obj);
+
+static inline uintptr_t
+_Py_atomic_load_uintptr_relaxed(const uintptr_t *obj);
+
+static inline unsigned int
+_Py_atomic_load_uint_relaxed(const unsigned int *obj);
+
+static inline Py_ssize_t
+_Py_atomic_load_ssize_relaxed(const Py_ssize_t *obj);
+
+static inline void *
+_Py_atomic_load_ptr_relaxed(const void *obj);
+
+
+// --- _Py_atomic_store ------------------------------------------------------
+// Atomically performs `*obj = value` (sequential consistency)
+
+static inline void
+_Py_atomic_store_int(int *obj, int value);
+
+static inline void
+_Py_atomic_store_int8(int8_t *obj, int8_t value);
+
+static inline void
+_Py_atomic_store_int16(int16_t *obj, int16_t value);
+
+static inline void
+_Py_atomic_store_int32(int32_t *obj, int32_t value);
+
+static inline void
+_Py_atomic_store_int64(int64_t *obj, int64_t value);
+
+static inline void
+_Py_atomic_store_intptr(intptr_t *obj, intptr_t value);
+
+static inline void
+_Py_atomic_store_uint8(uint8_t *obj, uint8_t value);
+
+static inline void
+_Py_atomic_store_uint16(uint16_t *obj, uint16_t value);
+
+static inline void
+_Py_atomic_store_uint32(uint32_t *obj, uint32_t value);
+
+static inline void
+_Py_atomic_store_uint64(uint64_t *obj, uint64_t value);
+
+static inline void
+_Py_atomic_store_uintptr(uintptr_t *obj, uintptr_t value);
+
+static inline void
+_Py_atomic_store_uint(unsigned int *obj, unsigned int value);
+
+static inline void
+_Py_atomic_store_ptr(void *obj, void *value);
+
+static inline void
+_Py_atomic_store_ssize(Py_ssize_t* obj, Py_ssize_t value);
+
+
+// --- _Py_atomic_store_relaxed ----------------------------------------------
+// Stores `*obj = value` (relaxed consistency, i.e., no ordering)
+
+static inline void
+_Py_atomic_store_int_relaxed(int *obj, int value);
+
+static inline void
+_Py_atomic_store_int8_relaxed(int8_t *obj, int8_t value);
+
+static inline void
+_Py_atomic_store_int16_relaxed(int16_t *obj, int16_t value);
+
+static inline void
+_Py_atomic_store_int32_relaxed(int32_t *obj, int32_t value);
+
+static inline void
+_Py_atomic_store_int64_relaxed(int64_t *obj, int64_t value);
+
+static inline void
+_Py_atomic_store_intptr_relaxed(intptr_t *obj, intptr_t value);
+
+static inline void
+_Py_atomic_store_uint8_relaxed(uint8_t* obj, uint8_t value);
+
+static inline void
+_Py_atomic_store_uint16_relaxed(uint16_t *obj, uint16_t value);
+
+static inline void
+_Py_atomic_store_uint32_relaxed(uint32_t *obj, uint32_t value);
+
+static inline void
+_Py_atomic_store_uint64_relaxed(uint64_t *obj, uint64_t value);
+
+static inline void
+_Py_atomic_store_uintptr_relaxed(uintptr_t *obj, uintptr_t value);
+
+static inline void
+_Py_atomic_store_uint_relaxed(unsigned int *obj, unsigned int value);
+
+static inline void
+_Py_atomic_store_ptr_relaxed(void *obj, void *value);
+
+static inline void
+_Py_atomic_store_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t value);
+
+
+// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------
+
+// Loads `*obj` (acquire operation)
+static inline void *
+_Py_atomic_load_ptr_acquire(const void *obj);
+
+// Stores `*obj = value` (release operation)
+static inline void
+_Py_atomic_store_ptr_release(void *obj, void *value);
+
+
+// --- _Py_atomic_fence ------------------------------------------------------
+
+// Sequential consistency fence. C11 fences have complex semantics. When
+// possible, use the atomic operations on variables defined above, which
+// generally do not require explicit use of a fence.
+// See https://en.cppreference.com/w/cpp/atomic/atomic_thread_fence
+static inline void _Py_atomic_fence_seq_cst(void);
+
+// Release fence
+static inline void _Py_atomic_fence_release(void);
+
+
+#ifndef _Py_USE_GCC_BUILTIN_ATOMICS
+# if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8))
+# define _Py_USE_GCC_BUILTIN_ATOMICS 1
+# elif defined(__clang__)
+# if __has_builtin(__atomic_load)
+# define _Py_USE_GCC_BUILTIN_ATOMICS 1
+# endif
+# endif
+#endif
+
+#if _Py_USE_GCC_BUILTIN_ATOMICS
+# define Py_ATOMIC_GCC_H
+# include "cpython/pyatomic_gcc.h"
+# undef Py_ATOMIC_GCC_H
+#elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
+# define Py_ATOMIC_STD_H
+# include "cpython/pyatomic_std.h"
+# undef Py_ATOMIC_STD_H
+#elif defined(_MSC_VER)
+# define Py_ATOMIC_MSC_H
+# include "cpython/pyatomic_msc.h"
+# undef Py_ATOMIC_MSC_H
+#else
+# error "no available pyatomic implementation for this platform/compiler"
+#endif
+
+#endif /* Py_ATOMIC_H */
+
diff --git a/Include/cpython/pyatomic_gcc.h b/Include/cpython/pyatomic_gcc.h
new file mode 100644
index 0000000000000..f1a38c7b52871
--- /dev/null
+++ b/Include/cpython/pyatomic_gcc.h
@@ -0,0 +1,499 @@
+// This is the implementation of Python atomic operations using GCC's built-in
+// functions that match the C+11 memory model. This implementation is preferred
+// for GCC compatible compilers, such as Clang. These functions are available
+// in GCC 4.8+ without needing to compile with --std=c11 or --std=gnu11.
+
+#ifndef Py_ATOMIC_GCC_H
+# error "this header file must not be included directly"
+#endif
+
+
+// --- _Py_atomic_add --------------------------------------------------------
+
+static inline int
+_Py_atomic_add_int(int *obj, int value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline int8_t
+_Py_atomic_add_int8(int8_t *obj, int8_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline int16_t
+_Py_atomic_add_int16(int16_t *obj, int16_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline int32_t
+_Py_atomic_add_int32(int32_t *obj, int32_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline int64_t
+_Py_atomic_add_int64(int64_t *obj, int64_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline intptr_t
+_Py_atomic_add_intptr(intptr_t *obj, intptr_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline unsigned int
+_Py_atomic_add_uint(unsigned int *obj, unsigned int value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint8_t
+_Py_atomic_add_uint8(uint8_t *obj, uint8_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint16_t
+_Py_atomic_add_uint16(uint16_t *obj, uint16_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint32_t
+_Py_atomic_add_uint32(uint32_t *obj, uint32_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint64_t
+_Py_atomic_add_uint64(uint64_t *obj, uint64_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uintptr_t
+_Py_atomic_add_uintptr(uintptr_t *obj, uintptr_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline Py_ssize_t
+_Py_atomic_add_ssize(Py_ssize_t *obj, Py_ssize_t value)
+{ return __atomic_fetch_add(obj, value, __ATOMIC_SEQ_CST); }
+
+
+// --- _Py_atomic_compare_exchange -------------------------------------------
+
+static inline int
+_Py_atomic_compare_exchange_int(int *obj, int *expected, int desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_int8(int8_t *obj, int8_t *expected, int8_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_int16(int16_t *obj, int16_t *expected, int16_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_int32(int32_t *obj, int32_t *expected, int32_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_int64(int64_t *obj, int64_t *expected, int64_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_intptr(intptr_t *obj, intptr_t *expected, intptr_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_uint(unsigned int *obj, unsigned int *expected, unsigned int desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_uint8(uint8_t *obj, uint8_t *expected, uint8_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_uint16(uint16_t *obj, uint16_t *expected, uint16_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_uint32(uint32_t *obj, uint32_t *expected, uint32_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_uint64(uint64_t *obj, uint64_t *expected, uint64_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_uintptr(uintptr_t *obj, uintptr_t *expected, uintptr_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_ssize(Py_ssize_t *obj, Py_ssize_t *expected, Py_ssize_t desired)
+{ return __atomic_compare_exchange_n(obj, expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+static inline int
+_Py_atomic_compare_exchange_ptr(void *obj, void *expected, void *desired)
+{ return __atomic_compare_exchange_n((void **)obj, (void **)expected, desired, 0,
+ __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); }
+
+
+// --- _Py_atomic_exchange ---------------------------------------------------
+
+static inline int
+_Py_atomic_exchange_int(int *obj, int value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline int8_t
+_Py_atomic_exchange_int8(int8_t *obj, int8_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline int16_t
+_Py_atomic_exchange_int16(int16_t *obj, int16_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline int32_t
+_Py_atomic_exchange_int32(int32_t *obj, int32_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline int64_t
+_Py_atomic_exchange_int64(int64_t *obj, int64_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline intptr_t
+_Py_atomic_exchange_intptr(intptr_t *obj, intptr_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline unsigned int
+_Py_atomic_exchange_uint(unsigned int *obj, unsigned int value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint8_t
+_Py_atomic_exchange_uint8(uint8_t *obj, uint8_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint16_t
+_Py_atomic_exchange_uint16(uint16_t *obj, uint16_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint32_t
+_Py_atomic_exchange_uint32(uint32_t *obj, uint32_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint64_t
+_Py_atomic_exchange_uint64(uint64_t *obj, uint64_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uintptr_t
+_Py_atomic_exchange_uintptr(uintptr_t *obj, uintptr_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline Py_ssize_t
+_Py_atomic_exchange_ssize(Py_ssize_t *obj, Py_ssize_t value)
+{ return __atomic_exchange_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void *
+_Py_atomic_exchange_ptr(void *obj, void *value)
+{ return __atomic_exchange_n((void **)obj, value, __ATOMIC_SEQ_CST); }
+
+
+// --- _Py_atomic_and --------------------------------------------------------
+
+static inline uint8_t
+_Py_atomic_and_uint8(uint8_t *obj, uint8_t value)
+{ return __atomic_fetch_and(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint16_t
+_Py_atomic_and_uint16(uint16_t *obj, uint16_t value)
+{ return __atomic_fetch_and(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint32_t
+_Py_atomic_and_uint32(uint32_t *obj, uint32_t value)
+{ return __atomic_fetch_and(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint64_t
+_Py_atomic_and_uint64(uint64_t *obj, uint64_t value)
+{ return __atomic_fetch_and(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uintptr_t
+_Py_atomic_and_uintptr(uintptr_t *obj, uintptr_t value)
+{ return __atomic_fetch_and(obj, value, __ATOMIC_SEQ_CST); }
+
+
+// --- _Py_atomic_or ---------------------------------------------------------
+
+static inline uint8_t
+_Py_atomic_or_uint8(uint8_t *obj, uint8_t value)
+{ return __atomic_fetch_or(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint16_t
+_Py_atomic_or_uint16(uint16_t *obj, uint16_t value)
+{ return __atomic_fetch_or(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint32_t
+_Py_atomic_or_uint32(uint32_t *obj, uint32_t value)
+{ return __atomic_fetch_or(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uint64_t
+_Py_atomic_or_uint64(uint64_t *obj, uint64_t value)
+{ return __atomic_fetch_or(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline uintptr_t
+_Py_atomic_or_uintptr(uintptr_t *obj, uintptr_t value)
+{ return __atomic_fetch_or(obj, value, __ATOMIC_SEQ_CST); }
+
+
+// --- _Py_atomic_load -------------------------------------------------------
+
+static inline int
+_Py_atomic_load_int(const int *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline int8_t
+_Py_atomic_load_int8(const int8_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline int16_t
+_Py_atomic_load_int16(const int16_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline int32_t
+_Py_atomic_load_int32(const int32_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline int64_t
+_Py_atomic_load_int64(const int64_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline intptr_t
+_Py_atomic_load_intptr(const intptr_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline uint8_t
+_Py_atomic_load_uint8(const uint8_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline uint16_t
+_Py_atomic_load_uint16(const uint16_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline uint32_t
+_Py_atomic_load_uint32(const uint32_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline uint64_t
+_Py_atomic_load_uint64(const uint64_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline uintptr_t
+_Py_atomic_load_uintptr(const uintptr_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline unsigned int
+_Py_atomic_load_uint(const unsigned int *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline Py_ssize_t
+_Py_atomic_load_ssize(const Py_ssize_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_SEQ_CST); }
+
+static inline void *
+_Py_atomic_load_ptr(const void *obj)
+{ return (void *)__atomic_load_n((void **)obj, __ATOMIC_SEQ_CST); }
+
+
+// --- _Py_atomic_load_relaxed -----------------------------------------------
+
+static inline int
+_Py_atomic_load_int_relaxed(const int *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline int8_t
+_Py_atomic_load_int8_relaxed(const int8_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline int16_t
+_Py_atomic_load_int16_relaxed(const int16_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline int32_t
+_Py_atomic_load_int32_relaxed(const int32_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline int64_t
+_Py_atomic_load_int64_relaxed(const int64_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline intptr_t
+_Py_atomic_load_intptr_relaxed(const intptr_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline uint8_t
+_Py_atomic_load_uint8_relaxed(const uint8_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline uint16_t
+_Py_atomic_load_uint16_relaxed(const uint16_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline uint32_t
+_Py_atomic_load_uint32_relaxed(const uint32_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline uint64_t
+_Py_atomic_load_uint64_relaxed(const uint64_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline uintptr_t
+_Py_atomic_load_uintptr_relaxed(const uintptr_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline unsigned int
+_Py_atomic_load_uint_relaxed(const unsigned int *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline Py_ssize_t
+_Py_atomic_load_ssize_relaxed(const Py_ssize_t *obj)
+{ return __atomic_load_n(obj, __ATOMIC_RELAXED); }
+
+static inline void *
+_Py_atomic_load_ptr_relaxed(const void *obj)
+{ return (void *)__atomic_load_n((const void **)obj, __ATOMIC_RELAXED); }
+
+
+// --- _Py_atomic_store ------------------------------------------------------
+
+static inline void
+_Py_atomic_store_int(int *obj, int value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_int8(int8_t *obj, int8_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_int16(int16_t *obj, int16_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_int32(int32_t *obj, int32_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_int64(int64_t *obj, int64_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_intptr(intptr_t *obj, intptr_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_uint8(uint8_t *obj, uint8_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_uint16(uint16_t *obj, uint16_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_uint32(uint32_t *obj, uint32_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_uint64(uint64_t *obj, uint64_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_uintptr(uintptr_t *obj, uintptr_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_uint(unsigned int *obj, unsigned int value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_ptr(void *obj, void *value)
+{ __atomic_store_n((void **)obj, value, __ATOMIC_SEQ_CST); }
+
+static inline void
+_Py_atomic_store_ssize(Py_ssize_t *obj, Py_ssize_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_SEQ_CST); }
+
+
+// --- _Py_atomic_store_relaxed ----------------------------------------------
+
+static inline void
+_Py_atomic_store_int_relaxed(int *obj, int value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_int8_relaxed(int8_t *obj, int8_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_int16_relaxed(int16_t *obj, int16_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_int32_relaxed(int32_t *obj, int32_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_int64_relaxed(int64_t *obj, int64_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_intptr_relaxed(intptr_t *obj, intptr_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_uint8_relaxed(uint8_t *obj, uint8_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_uint16_relaxed(uint16_t *obj, uint16_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_uint32_relaxed(uint32_t *obj, uint32_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_uint64_relaxed(uint64_t *obj, uint64_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_uintptr_relaxed(uintptr_t *obj, uintptr_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_uint_relaxed(unsigned int *obj, unsigned int value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_ptr_relaxed(void *obj, void *value)
+{ __atomic_store_n((void **)obj, value, __ATOMIC_RELAXED); }
+
+static inline void
+_Py_atomic_store_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t value)
+{ __atomic_store_n(obj, value, __ATOMIC_RELAXED); }
+
+
+// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------
+
+static inline void *
+_Py_atomic_load_ptr_acquire(const void *obj)
+{ return (void *)__atomic_load_n((void **)obj, __ATOMIC_ACQUIRE); }
+
+static inline void
+_Py_atomic_store_ptr_release(void *obj, void *value)
+{ __atomic_store_n((void **)obj, value, __ATOMIC_RELEASE); }
+
+
+// --- _Py_atomic_fence ------------------------------------------------------
+
+static inline void
+_Py_atomic_fence_seq_cst(void)
+{ __atomic_thread_fence(__ATOMIC_SEQ_CST); }
+
+ static inline void
+_Py_atomic_fence_release(void)
+{ __atomic_thread_fence(__ATOMIC_RELEASE); }
diff --git a/Include/cpython/pyatomic_msc.h b/Include/cpython/pyatomic_msc.h
new file mode 100644
index 0000000000000..c88bb03cc8f94
--- /dev/null
+++ b/Include/cpython/pyatomic_msc.h
@@ -0,0 +1,944 @@
+// This is the implementation of Python atomic operations for MSVC if the
+// compiler does not support C11 or C++11 atomics.
+//
+// MSVC intrinsics are defined on char, short, long, __int64, and pointer
+// types. Note that long and int are both 32-bits even on 64-bit Windows,
+// so operations on int are cast to long.
+//
+// The volatile keyword has additional memory ordering semantics on MSVC. On
+// x86 and x86-64, volatile accesses have acquire-release semantics. On ARM64,
+// volatile accesses behave like C11's memory_order_relaxed.
+
+#ifndef Py_ATOMIC_MSC_H
+# error "this header file must not be included directly"
+#endif
+
+#include <intrin.h>
+
+#define _Py_atomic_ASSERT_ARG_TYPE(TYPE) \
+ Py_BUILD_ASSERT(sizeof(*obj) == sizeof(TYPE))
+
+
+// --- _Py_atomic_add --------------------------------------------------------
+
+static inline int8_t
+_Py_atomic_add_int8(int8_t *obj, int8_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(char);
+ return (int8_t)_InterlockedExchangeAdd8((volatile char *)obj, (char)value);
+}
+
+static inline int16_t
+_Py_atomic_add_int16(int16_t *obj, int16_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(short);
+ return (int16_t)_InterlockedExchangeAdd16((volatile short *)obj, (short)value);
+}
+
+static inline int32_t
+_Py_atomic_add_int32(int32_t *obj, int32_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(long);
+ return (int32_t)_InterlockedExchangeAdd((volatile long *)obj, (long)value);
+}
+
+static inline int64_t
+_Py_atomic_add_int64(int64_t *obj, int64_t value)
+{
+#if defined(_M_X64) || defined(_M_ARM64)
+ _Py_atomic_ASSERT_ARG_TYPE(__int64);
+ return (int64_t)_InterlockedExchangeAdd64((volatile __int64 *)obj, (__int64)value);
+#else
+ int64_t old_value = _Py_atomic_load_int64_relaxed(obj);
+ for (;;) {
+ int64_t new_value = old_value + value;
+ if (_Py_atomic_compare_exchange_int64(obj, &old_value, new_value)) {
+ return old_value;
+ }
+ }
+#endif
+}
+
+
+static inline uint8_t
+_Py_atomic_add_uint8(uint8_t *obj, uint8_t value)
+{
+ return (uint8_t)_Py_atomic_add_int8((int8_t *)obj, (int8_t)value);
+}
+
+static inline uint16_t
+_Py_atomic_add_uint16(uint16_t *obj, uint16_t value)
+{
+ return (uint16_t)_Py_atomic_add_int16((int16_t *)obj, (int16_t)value);
+}
+
+static inline uint32_t
+_Py_atomic_add_uint32(uint32_t *obj, uint32_t value)
+{
+ return (uint32_t)_Py_atomic_add_int32((int32_t *)obj, (int32_t)value);
+}
+
+static inline int
+_Py_atomic_add_int(int *obj, int value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(int32_t);
+ return (int)_Py_atomic_add_int32((int32_t *)obj, (int32_t)value);
+}
+
+static inline unsigned int
+_Py_atomic_add_uint(unsigned int *obj, unsigned int value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(int32_t);
+ return (unsigned int)_Py_atomic_add_int32((int32_t *)obj, (int32_t)value);
+}
+
+static inline uint64_t
+_Py_atomic_add_uint64(uint64_t *obj, uint64_t value)
+{
+ return (uint64_t)_Py_atomic_add_int64((int64_t *)obj, (int64_t)value);
+}
+
+static inline intptr_t
+_Py_atomic_add_intptr(intptr_t *obj, intptr_t value)
+{
+#if SIZEOF_VOID_P == 8
+ _Py_atomic_ASSERT_ARG_TYPE(int64_t);
+ return (intptr_t)_Py_atomic_add_int64((int64_t *)obj, (int64_t)value);
+#else
+ _Py_atomic_ASSERT_ARG_TYPE(int32_t);
+ return (intptr_t)_Py_atomic_add_int32((int32_t *)obj, (int32_t)value);
+#endif
+}
+
+static inline uintptr_t
+_Py_atomic_add_uintptr(uintptr_t *obj, uintptr_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(intptr_t);
+ return (uintptr_t)_Py_atomic_add_intptr((intptr_t *)obj, (intptr_t)value);
+}
+
+static inline Py_ssize_t
+_Py_atomic_add_ssize(Py_ssize_t *obj, Py_ssize_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(intptr_t);
+ return (Py_ssize_t)_Py_atomic_add_intptr((intptr_t *)obj, (intptr_t)value);
+}
+
+
+// --- _Py_atomic_compare_exchange -------------------------------------------
+
+static inline int
+_Py_atomic_compare_exchange_int8(int8_t *obj, int8_t *expected, int8_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(char);
+ int8_t initial = (int8_t)_InterlockedCompareExchange8(
+ (volatile char *)obj,
+ (char)value,
+ (char)*expected);
+ if (initial == *expected) {
+ return 1;
+ }
+ *expected = initial;
+ return 0;
+}
+
+static inline int
+_Py_atomic_compare_exchange_int16(int16_t *obj, int16_t *expected, int16_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(short);
+ int16_t initial = (int16_t)_InterlockedCompareExchange16(
+ (volatile short *)obj,
+ (short)value,
+ (short)*expected);
+ if (initial == *expected) {
+ return 1;
+ }
+ *expected = initial;
+ return 0;
+}
+
+static inline int
+_Py_atomic_compare_exchange_int32(int32_t *obj, int32_t *expected, int32_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(long);
+ int32_t initial = (int32_t)_InterlockedCompareExchange(
+ (volatile long *)obj,
+ (long)value,
+ (long)*expected);
+ if (initial == *expected) {
+ return 1;
+ }
+ *expected = initial;
+ return 0;
+}
+
+static inline int
+_Py_atomic_compare_exchange_int64(int64_t *obj, int64_t *expected, int64_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(__int64);
+ int64_t initial = (int64_t)_InterlockedCompareExchange64(
+ (volatile __int64 *)obj,
+ (__int64)value,
+ (__int64)*expected);
+ if (initial == *expected) {
+ return 1;
+ }
+ *expected = initial;
+ return 0;
+}
+
+static inline int
+_Py_atomic_compare_exchange_ptr(void *obj, void *expected, void *value)
+{
+ void *initial = _InterlockedCompareExchangePointer(
+ (void**)obj,
+ value,
+ *(void**)expected);
+ if (initial == *(void**)expected) {
+ return 1;
+ }
+ *(void**)expected = initial;
+ return 0;
+}
+
+
+static inline int
+_Py_atomic_compare_exchange_uint8(uint8_t *obj, uint8_t *expected, uint8_t value)
+{
+ return _Py_atomic_compare_exchange_int8((int8_t *)obj,
+ (int8_t *)expected,
+ (int8_t)value);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uint16(uint16_t *obj, uint16_t *expected, uint16_t value)
+{
+ return _Py_atomic_compare_exchange_int16((int16_t *)obj,
+ (int16_t *)expected,
+ (int16_t)value);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uint32(uint32_t *obj, uint32_t *expected, uint32_t value)
+{
+ return _Py_atomic_compare_exchange_int32((int32_t *)obj,
+ (int32_t *)expected,
+ (int32_t)value);
+}
+
+static inline int
+_Py_atomic_compare_exchange_int(int *obj, int *expected, int value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(int32_t);
+ return _Py_atomic_compare_exchange_int32((int32_t *)obj,
+ (int32_t *)expected,
+ (int32_t)value);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uint(unsigned int *obj, unsigned int *expected, unsigned int value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(int32_t);
+ return _Py_atomic_compare_exchange_int32((int32_t *)obj,
+ (int32_t *)expected,
+ (int32_t)value);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uint64(uint64_t *obj, uint64_t *expected, uint64_t value)
+{
+ return _Py_atomic_compare_exchange_int64((int64_t *)obj,
+ (int64_t *)expected,
+ (int64_t)value);
+}
+
+static inline int
+_Py_atomic_compare_exchange_intptr(intptr_t *obj, intptr_t *expected, intptr_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(void*);
+ return _Py_atomic_compare_exchange_ptr((void**)obj,
+ (void**)expected,
+ (void*)value);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uintptr(uintptr_t *obj, uintptr_t *expected, uintptr_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(void*);
+ return _Py_atomic_compare_exchange_ptr((void**)obj,
+ (void**)expected,
+ (void*)value);
+}
+
+static inline int
+_Py_atomic_compare_exchange_ssize(Py_ssize_t *obj, Py_ssize_t *expected, Py_ssize_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(void*);
+ return _Py_atomic_compare_exchange_ptr((void**)obj,
+ (void**)expected,
+ (void*)value);
+}
+
+
+// --- _Py_atomic_exchange ---------------------------------------------------
+
+static inline int8_t
+_Py_atomic_exchange_int8(int8_t *obj, int8_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(char);
+ return (int8_t)_InterlockedExchange8((volatile char *)obj, (char)value);
+}
+
+static inline int16_t
+_Py_atomic_exchange_int16(int16_t *obj, int16_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(short);
+ return (int16_t)_InterlockedExchange16((volatile short *)obj, (short)value);
+}
+
+static inline int32_t
+_Py_atomic_exchange_int32(int32_t *obj, int32_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(long);
+ return (int32_t)_InterlockedExchange((volatile long *)obj, (long)value);
+}
+
+static inline int64_t
+_Py_atomic_exchange_int64(int64_t *obj, int64_t value)
+{
+#if defined(_M_X64) || defined(_M_ARM64)
+ _Py_atomic_ASSERT_ARG_TYPE(__int64);
+ return (int64_t)_InterlockedExchange64((volatile __int64 *)obj, (__int64)value);
+#else
+ int64_t old_value = _Py_atomic_load_int64_relaxed(obj);
+ for (;;) {
+ if (_Py_atomic_compare_exchange_int64(obj, &old_value, value)) {
+ return old_value;
+ }
+ }
+#endif
+}
+
+static inline void*
+_Py_atomic_exchange_ptr(void *obj, void *value)
+{
+ return (void*)_InterlockedExchangePointer((void * volatile *)obj, (void *)value);
+}
+
+
+static inline uint8_t
+_Py_atomic_exchange_uint8(uint8_t *obj, uint8_t value)
+{
+ return (uint8_t)_Py_atomic_exchange_int8((int8_t *)obj,
+ (int8_t)value);
+}
+
+static inline uint16_t
+_Py_atomic_exchange_uint16(uint16_t *obj, uint16_t value)
+{
+ return (uint16_t)_Py_atomic_exchange_int16((int16_t *)obj,
+ (int16_t)value);
+}
+
+static inline uint32_t
+_Py_atomic_exchange_uint32(uint32_t *obj, uint32_t value)
+{
+ return (uint32_t)_Py_atomic_exchange_int32((int32_t *)obj,
+ (int32_t)value);
+}
+
+static inline int
+_Py_atomic_exchange_int(int *obj, int value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(int32_t);
+ return (int)_Py_atomic_exchange_int32((int32_t *)obj,
+ (int32_t)value);
+}
+
+static inline unsigned int
+_Py_atomic_exchange_uint(unsigned int *obj, unsigned int value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(int32_t);
+ return (unsigned int)_Py_atomic_exchange_int32((int32_t *)obj,
+ (int32_t)value);
+}
+
+static inline uint64_t
+_Py_atomic_exchange_uint64(uint64_t *obj, uint64_t value)
+{
+ return (uint64_t)_Py_atomic_exchange_int64((int64_t *)obj,
+ (int64_t)value);
+}
+
+static inline intptr_t
+_Py_atomic_exchange_intptr(intptr_t *obj, intptr_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(void*);
+ return (intptr_t)_Py_atomic_exchange_ptr((void**)obj,
+ (void*)value);
+}
+
+static inline uintptr_t
+_Py_atomic_exchange_uintptr(uintptr_t *obj, uintptr_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(void*);
+ return (uintptr_t)_Py_atomic_exchange_ptr((void**)obj,
+ (void*)value);
+}
+
+static inline Py_ssize_t
+_Py_atomic_exchange_ssize(Py_ssize_t *obj, Py_ssize_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(void*);
+ return (Py_ssize_t)_Py_atomic_exchange_ptr((void**)obj,
+ (void*)value);
+}
+
+
+// --- _Py_atomic_and --------------------------------------------------------
+
+static inline uint8_t
+_Py_atomic_and_uint8(uint8_t *obj, uint8_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(char);
+ return (uint8_t)_InterlockedAnd8((volatile char *)obj, (char)value);
+}
+
+static inline uint16_t
+_Py_atomic_and_uint16(uint16_t *obj, uint16_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(short);
+ return (uint16_t)_InterlockedAnd16((volatile short *)obj, (short)value);
+}
+
+static inline uint32_t
+_Py_atomic_and_uint32(uint32_t *obj, uint32_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(long);
+ return (uint32_t)_InterlockedAnd((volatile long *)obj, (long)value);
+}
+
+static inline uint64_t
+_Py_atomic_and_uint64(uint64_t *obj, uint64_t value)
+{
+#if defined(_M_X64) || defined(_M_ARM64)
+ _Py_atomic_ASSERT_ARG_TYPE(__int64);
+ return (uint64_t)_InterlockedAnd64((volatile __int64 *)obj, (__int64)value);
+#else
+ uint64_t old_value = _Py_atomic_load_uint64_relaxed(obj);
+ for (;;) {
+ uint64_t new_value = old_value & value;
+ if (_Py_atomic_compare_exchange_uint64(obj, &old_value, new_value)) {
+ return old_value;
+ }
+ }
+#endif
+}
+
+static inline uintptr_t
+_Py_atomic_and_uintptr(uintptr_t *obj, uintptr_t value)
+{
+#if SIZEOF_VOID_P == 8
+ _Py_atomic_ASSERT_ARG_TYPE(uint64_t);
+ return (uintptr_t)_Py_atomic_and_uint64((uint64_t *)obj,
+ (uint64_t)value);
+#else
+ _Py_atomic_ASSERT_ARG_TYPE(uint32_t);
+ return (uintptr_t)_Py_atomic_and_uint32((uint32_t *)obj,
+ (uint32_t)value);
+#endif
+}
+
+
+// --- _Py_atomic_or ---------------------------------------------------------
+
+static inline uint8_t
+_Py_atomic_or_uint8(uint8_t *obj, uint8_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(char);
+ return (uint8_t)_InterlockedOr8((volatile char *)obj, (char)value);
+}
+
+static inline uint16_t
+_Py_atomic_or_uint16(uint16_t *obj, uint16_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(short);
+ return (uint16_t)_InterlockedOr16((volatile short *)obj, (short)value);
+}
+
+static inline uint32_t
+_Py_atomic_or_uint32(uint32_t *obj, uint32_t value)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(long);
+ return (uint32_t)_InterlockedOr((volatile long *)obj, (long)value);
+}
+
+static inline uint64_t
+_Py_atomic_or_uint64(uint64_t *obj, uint64_t value)
+{
+#if defined(_M_X64) || defined(_M_ARM64)
+ _Py_atomic_ASSERT_ARG_TYPE(__int64);
+ return (uint64_t)_InterlockedOr64((volatile __int64 *)obj, (__int64)value);
+#else
+ uint64_t old_value = _Py_atomic_load_uint64_relaxed(obj);
+ for (;;) {
+ uint64_t new_value = old_value | value;
+ if (_Py_atomic_compare_exchange_uint64(obj, &old_value, new_value)) {
+ return old_value;
+ }
+ }
+#endif
+}
+
+
+static inline uintptr_t
+_Py_atomic_or_uintptr(uintptr_t *obj, uintptr_t value)
+{
+#if SIZEOF_VOID_P == 8
+ _Py_atomic_ASSERT_ARG_TYPE(uint64_t);
+ return (uintptr_t)_Py_atomic_or_uint64((uint64_t *)obj,
+ (uint64_t)value);
+#else
+ _Py_atomic_ASSERT_ARG_TYPE(uint32_t);
+ return (uintptr_t)_Py_atomic_or_uint32((uint32_t *)obj,
+ (uint32_t)value);
+#endif
+}
+
+
+// --- _Py_atomic_load -------------------------------------------------------
+
+static inline uint8_t
+_Py_atomic_load_uint8(const uint8_t *obj)
+{
+#if defined(_M_X64) || defined(_M_IX86)
+ return *(volatile uint8_t *)obj;
+#elif defined(_M_ARM64)
+ return (uint8_t)__ldar8((unsigned __int8 volatile *)obj);
+#else
+# error "no implementation of _Py_atomic_load_uint8"
+#endif
+}
+
+static inline uint16_t
+_Py_atomic_load_uint16(const uint16_t *obj)
+{
+#if defined(_M_X64) || defined(_M_IX86)
+ return *(volatile uint16_t *)obj;
+#elif defined(_M_ARM64)
+ return (uint16_t)__ldar16((unsigned __int16 volatile *)obj);
+#else
+# error "no implementation of _Py_atomic_load_uint16"
+#endif
+}
+
+static inline uint32_t
+_Py_atomic_load_uint32(const uint32_t *obj)
+{
+#if defined(_M_X64) || defined(_M_IX86)
+ return *(volatile uint32_t *)obj;
+#elif defined(_M_ARM64)
+ return (uint32_t)__ldar32((unsigned __int32 volatile *)obj);
+#else
+# error "no implementation of _Py_atomic_load_uint32"
+#endif
+}
+
+static inline uint64_t
+_Py_atomic_load_uint64(const uint64_t *obj)
+{
+#if defined(_M_X64) || defined(_M_IX86)
+ return *(volatile uint64_t *)obj;
+#elif defined(_M_ARM64)
+ return (uint64_t)__ldar64((unsigned __int64 volatile *)obj);
+#else
+# error "no implementation of _Py_atomic_load_uint64"
+#endif
+}
+
+static inline int8_t
+_Py_atomic_load_int8(const int8_t *obj)
+{
+ return (int8_t)_Py_atomic_load_uint8((const uint8_t *)obj);
+}
+
+static inline int16_t
+_Py_atomic_load_int16(const int16_t *obj)
+{
+ return (int16_t)_Py_atomic_load_uint16((const uint16_t *)obj);
+}
+
+static inline int32_t
+_Py_atomic_load_int32(const int32_t *obj)
+{
+ return (int32_t)_Py_atomic_load_uint32((const uint32_t *)obj);
+}
+
+static inline int
+_Py_atomic_load_int(const int *obj)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(uint32_t);
+ return (int)_Py_atomic_load_uint32((uint32_t *)obj);
+}
+
+static inline unsigned int
+_Py_atomic_load_uint(const unsigned int *obj)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(uint32_t);
+ return (unsigned int)_Py_atomic_load_uint32((uint32_t *)obj);
+}
+
+static inline int64_t
+_Py_atomic_load_int64(const int64_t *obj)
+{
+ return (int64_t)_Py_atomic_load_uint64((const uint64_t *)obj);
+}
+
+static inline void*
+_Py_atomic_load_ptr(const void *obj)
+{
+#if SIZEOF_VOID_P == 8
+ return (void*)_Py_atomic_load_uint64((const uint64_t *)obj);
+#else
+ return (void*)_Py_atomic_load_uint32((const uint32_t *)obj);
+#endif
+}
+
+static inline intptr_t
+_Py_atomic_load_intptr(const intptr_t *obj)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(void*);
+ return (intptr_t)_Py_atomic_load_ptr((void*)obj);
+}
+
+static inline uintptr_t
+_Py_atomic_load_uintptr(const uintptr_t *obj)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(void*);
+ return (uintptr_t)_Py_atomic_load_ptr((void*)obj);
+}
+
+static inline Py_ssize_t
+_Py_atomic_load_ssize(const Py_ssize_t *obj)
+{
+ _Py_atomic_ASSERT_ARG_TYPE(void*);
+ return (Py_ssize_t)_Py_atomic_load_ptr((void*)obj);
+}
+
+
+// --- _Py_atomic_load_relaxed -----------------------------------------------
+
+static inline int
+_Py_atomic_load_int_relaxed(const int *obj)
+{
+ return *(volatile int *)obj;
+}
+
+static inline int8_t
+_Py_atomic_load_int8_relaxed(const int8_t *obj)
+{
+ return *(volatile int8_t *)obj;
+}
+
+static inline int16_t
+_Py_atomic_load_int16_relaxed(const int16_t *obj)
+{
+ return *(volatile int16_t *)obj;
+}
+
+static inline int32_t
+_Py_atomic_load_int32_relaxed(const int32_t *obj)
+{
+ return *(volatile int32_t *)obj;
+}
+
+static inline int64_t
+_Py_atomic_load_int64_relaxed(const int64_t *obj)
+{
+ return *(volatile int64_t *)obj;
+}
+
+static inline intptr_t
+_Py_atomic_load_intptr_relaxed(const intptr_t *obj)
+{
+ return *(volatile intptr_t *)obj;
+}
+
+static inline uint8_t
+_Py_atomic_load_uint8_relaxed(const uint8_t *obj)
+{
+ return *(volatile uint8_t *)obj;
+}
+
+static inline uint16_t
+_Py_atomic_load_uint16_relaxed(const uint16_t *obj)
+{
+ return *(volatile uint16_t *)obj;
+}
+
+static inline uint32_t
+_Py_atomic_load_uint32_relaxed(const uint32_t *obj)
+{
+ return *(volatile uint32_t *)obj;
+}
+
+static inline uint64_t
+_Py_atomic_load_uint64_relaxed(const uint64_t *obj)
+{
+ return *(volatile uint64_t *)obj;
+}
+
+static inline uintptr_t
+_Py_atomic_load_uintptr_relaxed(const uintptr_t *obj)
+{
+ return *(volatile uintptr_t *)obj;
+}
+
+static inline unsigned int
+_Py_atomic_load_uint_relaxed(const unsigned int *obj)
+{
+ return *(volatile unsigned int *)obj;
+}
+
+static inline Py_ssize_t
+_Py_atomic_load_ssize_relaxed(const Py_ssize_t *obj)
+{
+ return *(volatile Py_ssize_t *)obj;
+}
+
+static inline void*
+_Py_atomic_load_ptr_relaxed(const void *obj)
+{
+ return *(void * volatile *)obj;
+}
+
+
+// --- _Py_atomic_store ------------------------------------------------------
+
+static inline void
+_Py_atomic_store_int(int *obj, int value)
+{
+ (void)_Py_atomic_exchange_int(obj, value);
+}
+
+static inline void
+_Py_atomic_store_int8(int8_t *obj, int8_t value)
+{
+ (void)_Py_atomic_exchange_int8(obj, value);
+}
+
+static inline void
+_Py_atomic_store_int16(int16_t *obj, int16_t value)
+{
+ (void)_Py_atomic_exchange_int16(obj, value);
+}
+
+static inline void
+_Py_atomic_store_int32(int32_t *obj, int32_t value)
+{
+ (void)_Py_atomic_exchange_int32(obj, value);
+}
+
+static inline void
+_Py_atomic_store_int64(int64_t *obj, int64_t value)
+{
+ (void)_Py_atomic_exchange_int64(obj, value);
+}
+
+static inline void
+_Py_atomic_store_intptr(intptr_t *obj, intptr_t value)
+{
+ (void)_Py_atomic_exchange_intptr(obj, value);
+}
+
+static inline void
+_Py_atomic_store_uint8(uint8_t *obj, uint8_t value)
+{
+ (void)_Py_atomic_exchange_uint8(obj, value);
+}
+
+static inline void
+_Py_atomic_store_uint16(uint16_t *obj, uint16_t value)
+{
+ (void)_Py_atomic_exchange_uint16(obj, value);
+}
+
+static inline void
+_Py_atomic_store_uint32(uint32_t *obj, uint32_t value)
+{
+ (void)_Py_atomic_exchange_uint32(obj, value);
+}
+
+static inline void
+_Py_atomic_store_uint64(uint64_t *obj, uint64_t value)
+{
+ (void)_Py_atomic_exchange_uint64(obj, value);
+}
+
+static inline void
+_Py_atomic_store_uintptr(uintptr_t *obj, uintptr_t value)
+{
+ (void)_Py_atomic_exchange_uintptr(obj, value);
+}
+
+static inline void
+_Py_atomic_store_uint(unsigned int *obj, unsigned int value)
+{
+ (void)_Py_atomic_exchange_uint(obj, value);
+}
+
+static inline void
+_Py_atomic_store_ptr(void *obj, void *value)
+{
+ (void)_Py_atomic_exchange_ptr(obj, value);
+}
+
+static inline void
+_Py_atomic_store_ssize(Py_ssize_t *obj, Py_ssize_t value)
+{
+ (void)_Py_atomic_exchange_ssize(obj, value);
+}
+
+
+// --- _Py_atomic_store_relaxed ----------------------------------------------
+
+static inline void
+_Py_atomic_store_int_relaxed(int *obj, int value)
+{
+ *(volatile int *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_int8_relaxed(int8_t *obj, int8_t value)
+{
+ *(volatile int8_t *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_int16_relaxed(int16_t *obj, int16_t value)
+{
+ *(volatile int16_t *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_int32_relaxed(int32_t *obj, int32_t value)
+{
+ *(volatile int32_t *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_int64_relaxed(int64_t *obj, int64_t value)
+{
+ *(volatile int64_t *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_intptr_relaxed(intptr_t *obj, intptr_t value)
+{
+ *(volatile intptr_t *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_uint8_relaxed(uint8_t *obj, uint8_t value)
+{
+ *(volatile uint8_t *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_uint16_relaxed(uint16_t *obj, uint16_t value)
+{
+ *(volatile uint16_t *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_uint32_relaxed(uint32_t *obj, uint32_t value)
+{
+ *(volatile uint32_t *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_uint64_relaxed(uint64_t *obj, uint64_t value)
+{
+ *(volatile uint64_t *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_uintptr_relaxed(uintptr_t *obj, uintptr_t value)
+{
+ *(volatile uintptr_t *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_uint_relaxed(unsigned int *obj, unsigned int value)
+{
+ *(volatile unsigned int *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_ptr_relaxed(void *obj, void* value)
+{
+ *(void * volatile *)obj = value;
+}
+
+static inline void
+_Py_atomic_store_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t value)
+{
+ *(volatile Py_ssize_t *)obj = value;
+}
+
+// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------
+
+static inline void *
+_Py_atomic_load_ptr_acquire(const void *obj)
+{
+#if defined(_M_X64) || defined(_M_IX86)
+ return *(void * volatile *)obj;
+#elif defined(_M_ARM64)
+ return (void *)__ldar64((unsigned __int64 volatile *)obj);
+#else
+# error "no implementation of _Py_atomic_load_ptr_acquire"
+#endif
+}
+
+static inline void
+_Py_atomic_store_ptr_release(void *obj, void *value)
+{
+#if defined(_M_X64) || defined(_M_IX86)
+ *(void * volatile *)obj = value;
+#elif defined(_M_ARM64)
+ __stlr64(obj, (uintptr_t)value);
+#else
+# error "no implementation of _Py_atomic_store_ptr_release"
+#endif
+}
+
+
+// --- _Py_atomic_fence ------------------------------------------------------
+
+ static inline void
+_Py_atomic_fence_seq_cst(void)
+{
+#if defined(_M_ARM64)
+ __dmb(_ARM64_BARRIER_ISH);
+#elif defined(_M_X64)
+ __faststorefence();
+#elif defined(_M_IX86)
+ _mm_mfence();
+#else
+# error "no implementation of _Py_atomic_fence_seq_cst"
+#endif
+}
+
+ static inline void
+_Py_atomic_fence_release(void)
+{
+#if defined(_M_ARM64)
+ __dmb(_ARM64_BARRIER_ISH);
+#elif defined(_M_X64) || defined(_M_IX86)
+ _ReadWriteBarrier();
+#else
+# error "no implementation of _Py_atomic_fence_release"
+#endif
+}
+
+#undef _Py_atomic_ASSERT_ARG_TYPE
diff --git a/Include/cpython/pyatomic_std.h b/Include/cpython/pyatomic_std.h
new file mode 100644
index 0000000000000..bf74a90887c63
--- /dev/null
+++ b/Include/cpython/pyatomic_std.h
@@ -0,0 +1,872 @@
+// This is the implementation of Python atomic operations using C++11 or C11
+// atomics. Note that the pyatomic_gcc.h implementation is preferred for GCC
+// compatible compilers, even if they support C++11 atomics.
+
+#ifndef Py_ATOMIC_STD_H
+# error "this header file must not be included directly"
+#endif
+
+#ifdef __cplusplus
+extern "C++" {
+# include <atomic>
+}
+# define _Py_USING_STD using namespace std
+# define _Atomic(tp) atomic<tp>
+#else
+# define _Py_USING_STD
+# include <stdatomic.h>
+#endif
+
+
+// --- _Py_atomic_add --------------------------------------------------------
+
+static inline int
+_Py_atomic_add_int(int *obj, int value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(int)*)obj, value);
+}
+
+static inline int8_t
+_Py_atomic_add_int8(int8_t *obj, int8_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(int8_t)*)obj, value);
+}
+
+static inline int16_t
+_Py_atomic_add_int16(int16_t *obj, int16_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(int16_t)*)obj, value);
+}
+
+static inline int32_t
+_Py_atomic_add_int32(int32_t *obj, int32_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(int32_t)*)obj, value);
+}
+
+static inline int64_t
+_Py_atomic_add_int64(int64_t *obj, int64_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(int64_t)*)obj, value);
+}
+
+static inline intptr_t
+_Py_atomic_add_intptr(intptr_t *obj, intptr_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(intptr_t)*)obj, value);
+}
+
+static inline unsigned int
+_Py_atomic_add_uint(unsigned int *obj, unsigned int value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(unsigned int)*)obj, value);
+}
+
+static inline uint8_t
+_Py_atomic_add_uint8(uint8_t *obj, uint8_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(uint8_t)*)obj, value);
+}
+
+static inline uint16_t
+_Py_atomic_add_uint16(uint16_t *obj, uint16_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(uint16_t)*)obj, value);
+}
+
+static inline uint32_t
+_Py_atomic_add_uint32(uint32_t *obj, uint32_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(uint32_t)*)obj, value);
+}
+
+static inline uint64_t
+_Py_atomic_add_uint64(uint64_t *obj, uint64_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(uint64_t)*)obj, value);
+}
+
+static inline uintptr_t
+_Py_atomic_add_uintptr(uintptr_t *obj, uintptr_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(uintptr_t)*)obj, value);
+}
+
+static inline Py_ssize_t
+_Py_atomic_add_ssize(Py_ssize_t *obj, Py_ssize_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_add((_Atomic(Py_ssize_t)*)obj, value);
+}
+
+
+// --- _Py_atomic_compare_exchange -------------------------------------------
+
+static inline int
+_Py_atomic_compare_exchange_int(int *obj, int *expected, int desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(int)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_int8(int8_t *obj, int8_t *expected, int8_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(int8_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_int16(int16_t *obj, int16_t *expected, int16_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(int16_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_int32(int32_t *obj, int32_t *expected, int32_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(int32_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_int64(int64_t *obj, int64_t *expected, int64_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(int64_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_intptr(intptr_t *obj, intptr_t *expected, intptr_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(intptr_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uint(unsigned int *obj, unsigned int *expected, unsigned int desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(unsigned int)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uint8(uint8_t *obj, uint8_t *expected, uint8_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(uint8_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uint16(uint16_t *obj, uint16_t *expected, uint16_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(uint16_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uint32(uint32_t *obj, uint32_t *expected, uint32_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(uint32_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uint64(uint64_t *obj, uint64_t *expected, uint64_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(uint64_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_uintptr(uintptr_t *obj, uintptr_t *expected, uintptr_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(uintptr_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_ssize(Py_ssize_t *obj, Py_ssize_t *expected, Py_ssize_t desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(Py_ssize_t)*)obj,
+ expected, desired);
+}
+
+static inline int
+_Py_atomic_compare_exchange_ptr(void *obj, void *expected, void *desired)
+{
+ _Py_USING_STD;
+ return atomic_compare_exchange_strong((_Atomic(void *)*)obj,
+ (void **)expected, desired);
+}
+
+
+// --- _Py_atomic_exchange ---------------------------------------------------
+
+static inline int
+_Py_atomic_exchange_int(int *obj, int value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(int)*)obj, value);
+}
+
+static inline int8_t
+_Py_atomic_exchange_int8(int8_t *obj, int8_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(int8_t)*)obj, value);
+}
+
+static inline int16_t
+_Py_atomic_exchange_int16(int16_t *obj, int16_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(int16_t)*)obj, value);
+}
+
+static inline int32_t
+_Py_atomic_exchange_int32(int32_t *obj, int32_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(int32_t)*)obj, value);
+}
+
+static inline int64_t
+_Py_atomic_exchange_int64(int64_t *obj, int64_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(int64_t)*)obj, value);
+}
+
+static inline intptr_t
+_Py_atomic_exchange_intptr(intptr_t *obj, intptr_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(intptr_t)*)obj, value);
+}
+
+static inline unsigned int
+_Py_atomic_exchange_uint(unsigned int *obj, unsigned int value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(unsigned int)*)obj, value);
+}
+
+static inline uint8_t
+_Py_atomic_exchange_uint8(uint8_t *obj, uint8_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(uint8_t)*)obj, value);
+}
+
+static inline uint16_t
+_Py_atomic_exchange_uint16(uint16_t *obj, uint16_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(uint16_t)*)obj, value);
+}
+
+static inline uint32_t
+_Py_atomic_exchange_uint32(uint32_t *obj, uint32_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(uint32_t)*)obj, value);
+}
+
+static inline uint64_t
+_Py_atomic_exchange_uint64(uint64_t *obj, uint64_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(uint64_t)*)obj, value);
+}
+
+static inline uintptr_t
+_Py_atomic_exchange_uintptr(uintptr_t *obj, uintptr_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(uintptr_t)*)obj, value);
+}
+
+static inline Py_ssize_t
+_Py_atomic_exchange_ssize(Py_ssize_t *obj, Py_ssize_t value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(Py_ssize_t)*)obj, value);
+}
+
+static inline void*
+_Py_atomic_exchange_ptr(void *obj, void *value)
+{
+ _Py_USING_STD;
+ return atomic_exchange((_Atomic(void *)*)obj, value);
+}
+
+
+// --- _Py_atomic_and --------------------------------------------------------
+
+static inline uint8_t
+_Py_atomic_and_uint8(uint8_t *obj, uint8_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_and((_Atomic(uint8_t)*)obj, value);
+}
+
+static inline uint16_t
+_Py_atomic_and_uint16(uint16_t *obj, uint16_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_and((_Atomic(uint16_t)*)obj, value);
+}
+
+static inline uint32_t
+_Py_atomic_and_uint32(uint32_t *obj, uint32_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_and((_Atomic(uint32_t)*)obj, value);
+}
+
+static inline uint64_t
+_Py_atomic_and_uint64(uint64_t *obj, uint64_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_and((_Atomic(uint64_t)*)obj, value);
+}
+
+static inline uintptr_t
+_Py_atomic_and_uintptr(uintptr_t *obj, uintptr_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_and((_Atomic(uintptr_t)*)obj, value);
+}
+
+
+// --- _Py_atomic_or ---------------------------------------------------------
+
+static inline uint8_t
+_Py_atomic_or_uint8(uint8_t *obj, uint8_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_or((_Atomic(uint8_t)*)obj, value);
+}
+
+static inline uint16_t
+_Py_atomic_or_uint16(uint16_t *obj, uint16_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_or((_Atomic(uint16_t)*)obj, value);
+}
+
+static inline uint32_t
+_Py_atomic_or_uint32(uint32_t *obj, uint32_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_or((_Atomic(uint32_t)*)obj, value);
+}
+
+static inline uint64_t
+_Py_atomic_or_uint64(uint64_t *obj, uint64_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_or((_Atomic(uint64_t)*)obj, value);
+}
+
+static inline uintptr_t
+_Py_atomic_or_uintptr(uintptr_t *obj, uintptr_t value)
+{
+ _Py_USING_STD;
+ return atomic_fetch_or((_Atomic(uintptr_t)*)obj, value);
+}
+
+
+// --- _Py_atomic_load -------------------------------------------------------
+
+static inline int
+_Py_atomic_load_int(const int *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(int)*)obj);
+}
+
+static inline int8_t
+_Py_atomic_load_int8(const int8_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(int8_t)*)obj);
+}
+
+static inline int16_t
+_Py_atomic_load_int16(const int16_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(int16_t)*)obj);
+}
+
+static inline int32_t
+_Py_atomic_load_int32(const int32_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(int32_t)*)obj);
+}
+
+static inline int64_t
+_Py_atomic_load_int64(const int64_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(int64_t)*)obj);
+}
+
+static inline intptr_t
+_Py_atomic_load_intptr(const intptr_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(intptr_t)*)obj);
+}
+
+static inline uint8_t
+_Py_atomic_load_uint8(const uint8_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(uint8_t)*)obj);
+}
+
+static inline uint16_t
+_Py_atomic_load_uint16(const uint16_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(uint32_t)*)obj);
+}
+
+static inline uint32_t
+_Py_atomic_load_uint32(const uint32_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(uint32_t)*)obj);
+}
+
+static inline uint64_t
+_Py_atomic_load_uint64(const uint64_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(uint64_t)*)obj);
+}
+
+static inline uintptr_t
+_Py_atomic_load_uintptr(const uintptr_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(uintptr_t)*)obj);
+}
+
+static inline unsigned int
+_Py_atomic_load_uint(const unsigned int *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(unsigned int)*)obj);
+}
+
+static inline Py_ssize_t
+_Py_atomic_load_ssize(const Py_ssize_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(Py_ssize_t)*)obj);
+}
+
+static inline void*
+_Py_atomic_load_ptr(const void *obj)
+{
+ _Py_USING_STD;
+ return atomic_load((const _Atomic(void*)*)obj);
+}
+
+
+// --- _Py_atomic_load_relaxed -----------------------------------------------
+
+static inline int
+_Py_atomic_load_int_relaxed(const int *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(int)*)obj,
+ memory_order_relaxed);
+}
+
+static inline int8_t
+_Py_atomic_load_int8_relaxed(const int8_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(int8_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline int16_t
+_Py_atomic_load_int16_relaxed(const int16_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(int16_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline int32_t
+_Py_atomic_load_int32_relaxed(const int32_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(int32_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline int64_t
+_Py_atomic_load_int64_relaxed(const int64_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(int64_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline intptr_t
+_Py_atomic_load_intptr_relaxed(const intptr_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(intptr_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline uint8_t
+_Py_atomic_load_uint8_relaxed(const uint8_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(uint8_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline uint16_t
+_Py_atomic_load_uint16_relaxed(const uint16_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(uint16_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline uint32_t
+_Py_atomic_load_uint32_relaxed(const uint32_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(uint32_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline uint64_t
+_Py_atomic_load_uint64_relaxed(const uint64_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(uint64_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline uintptr_t
+_Py_atomic_load_uintptr_relaxed(const uintptr_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(uintptr_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline unsigned int
+_Py_atomic_load_uint_relaxed(const unsigned int *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(unsigned int)*)obj,
+ memory_order_relaxed);
+}
+
+static inline Py_ssize_t
+_Py_atomic_load_ssize_relaxed(const Py_ssize_t *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(Py_ssize_t)*)obj,
+ memory_order_relaxed);
+}
+
+static inline void*
+_Py_atomic_load_ptr_relaxed(const void *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(void*)*)obj,
+ memory_order_relaxed);
+}
+
+
+// --- _Py_atomic_store ------------------------------------------------------
+
+static inline void
+_Py_atomic_store_int(int *obj, int value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(int)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_int8(int8_t *obj, int8_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(int8_t)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_int16(int16_t *obj, int16_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(int16_t)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_int32(int32_t *obj, int32_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(int32_t)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_int64(int64_t *obj, int64_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(int64_t)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_intptr(intptr_t *obj, intptr_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(intptr_t)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_uint8(uint8_t *obj, uint8_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(uint8_t)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_uint16(uint16_t *obj, uint16_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(uint16_t)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_uint32(uint32_t *obj, uint32_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(uint32_t)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_uint64(uint64_t *obj, uint64_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(uint64_t)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_uintptr(uintptr_t *obj, uintptr_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(uintptr_t)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_uint(unsigned int *obj, unsigned int value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(unsigned int)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_ptr(void *obj, void *value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(void*)*)obj, value);
+}
+
+static inline void
+_Py_atomic_store_ssize(Py_ssize_t *obj, Py_ssize_t value)
+{
+ _Py_USING_STD;
+ atomic_store((_Atomic(Py_ssize_t)*)obj, value);
+}
+
+
+// --- _Py_atomic_store_relaxed ----------------------------------------------
+
+static inline void
+_Py_atomic_store_int_relaxed(int *obj, int value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(int)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_int8_relaxed(int8_t *obj, int8_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(int8_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_int16_relaxed(int16_t *obj, int16_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(int16_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_int32_relaxed(int32_t *obj, int32_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(int32_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_int64_relaxed(int64_t *obj, int64_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(int64_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_intptr_relaxed(intptr_t *obj, intptr_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(intptr_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_uint8_relaxed(uint8_t *obj, uint8_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(uint8_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_uint16_relaxed(uint16_t *obj, uint16_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(uint16_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_uint32_relaxed(uint32_t *obj, uint32_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(uint32_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_uint64_relaxed(uint64_t *obj, uint64_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(uint64_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_uintptr_relaxed(uintptr_t *obj, uintptr_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(uintptr_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_uint_relaxed(unsigned int *obj, unsigned int value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(unsigned int)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_ptr_relaxed(void *obj, void *value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(void*)*)obj, value,
+ memory_order_relaxed);
+}
+
+static inline void
+_Py_atomic_store_ssize_relaxed(Py_ssize_t *obj, Py_ssize_t value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(Py_ssize_t)*)obj, value,
+ memory_order_relaxed);
+}
+
+
+// --- _Py_atomic_load_ptr_acquire / _Py_atomic_store_ptr_release ------------
+
+static inline void *
+_Py_atomic_load_ptr_acquire(const void *obj)
+{
+ _Py_USING_STD;
+ return atomic_load_explicit((const _Atomic(void*)*)obj,
+ memory_order_acquire);
+}
+
+static inline void
+_Py_atomic_store_ptr_release(void *obj, void *value)
+{
+ _Py_USING_STD;
+ atomic_store_explicit((_Atomic(void*)*)obj, value,
+ memory_order_release);
+}
+
+
+// --- _Py_atomic_fence ------------------------------------------------------
+
+ static inline void
+_Py_atomic_fence_seq_cst(void)
+{
+ _Py_USING_STD;
+ atomic_thread_fence(memory_order_seq_cst);
+}
+
+ static inline void
+_Py_atomic_fence_release(void)
+{
+ _Py_USING_STD;
+ atomic_thread_fence(memory_order_release);
+}
diff --git a/Include/internal/pycore_atomic.h b/Include/internal/pycore_atomic.h
index 48d246ea08f3d..22ce971a64f3d 100644
--- a/Include/internal/pycore_atomic.h
+++ b/Include/internal/pycore_atomic.h
@@ -1,5 +1,5 @@
-#ifndef Py_ATOMIC_H
-#define Py_ATOMIC_H
+#ifndef Py_INTERNAL_ATOMIC_H
+#define Py_INTERNAL_ATOMIC_H
#ifdef __cplusplus
extern "C" {
#endif
@@ -554,4 +554,4 @@ typedef struct _Py_atomic_int {
#ifdef __cplusplus
}
#endif
-#endif /* Py_ATOMIC_H */
+#endif /* Py_INTERNAL_ATOMIC_H */
diff --git a/Lib/test/test_capi/test_pyatomic.py b/Lib/test/test_capi/test_pyatomic.py
new file mode 100644
index 0000000000000..846d6d50c2596
--- /dev/null
+++ b/Lib/test/test_capi/test_pyatomic.py
@@ -0,0 +1,15 @@
+import unittest
+from test.support import import_helper
+
+# Skip this test if the _testcapi module isn't available.
+_testcapi = import_helper.import_module('_testcapi')
+
+class PyAtomicTests(unittest.TestCase):
+ pass
+
+for name in sorted(dir(_testcapi)):
+ if name.startswith('test_atomic'):
+ setattr(PyAtomicTests, name, getattr(_testcapi, name))
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Makefile.pre.in b/Makefile.pre.in
index ad3e26c036408..0870cb3d899d4 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1713,6 +1713,9 @@ PYTHON_HEADERS= \
$(srcdir)/Include/cpython/optimizer.h \
$(srcdir)/Include/cpython/picklebufobject.h \
$(srcdir)/Include/cpython/pthread_stubs.h \
+ $(srcdir)/Include/cpython/pyatomic.h \
+ $(srcdir)/Include/cpython/pyatomic_gcc.h \
+ $(srcdir)/Include/cpython/pyatomic_std.h \
$(srcdir)/Include/cpython/pyctype.h \
$(srcdir)/Include/cpython/pydebug.h \
$(srcdir)/Include/cpython/pyerrors.h \
diff --git a/Misc/NEWS.d/next/C API/2023-08-22-13-00-54.gh-issue-108337.wceHZm.rst b/Misc/NEWS.d/next/C API/2023-08-22-13-00-54.gh-issue-108337.wceHZm.rst
new file mode 100644
index 0000000000000..476123a051bb3
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2023-08-22-13-00-54.gh-issue-108337.wceHZm.rst
@@ -0,0 +1 @@
+Add atomic operations on additional data types in pyatomic.h.
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index 7b9dc3c5c8e26..2bb39d2936894 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -159,7 +159,7 @@
@MODULE__XXTESTFUZZ_TRUE@_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c _xxtestfuzz/fuzzer.c
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c
-@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyos.c _testcapi/immortal.c _testcapi/heaptype_relative.c _testcapi/gc.c
+@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/vectorcall_limited.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/pyos.c _testcapi/immortal.c _testcapi/heaptype_relative.c _testcapi/gc.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
diff --git a/Modules/_testcapi/parts.h b/Modules/_testcapi/parts.h
index 9c6d615714180..c162dbc65db81 100644
--- a/Modules/_testcapi/parts.h
+++ b/Modules/_testcapi/parts.h
@@ -22,6 +22,7 @@ int _PyTestCapi_Init_Structmember(PyObject *module);
int _PyTestCapi_Init_Exceptions(PyObject *module);
int _PyTestCapi_Init_Code(PyObject *module);
int _PyTestCapi_Init_Buffer(PyObject *module);
+int _PyTestCapi_Init_PyAtomic(PyObject *module);
int _PyTestCapi_Init_PyOS(PyObject *module);
int _PyTestCapi_Init_Immortal(PyObject *module);
int _PyTestCapi_Init_GC(PyObject *mod);
diff --git a/Modules/_testcapi/pyatomic.c b/Modules/_testcapi/pyatomic.c
new file mode 100644
index 0000000000000..15602ce3f4ab3
--- /dev/null
+++ b/Modules/_testcapi/pyatomic.c
@@ -0,0 +1,180 @@
+/*
+ * C Extension module to smoke test pyatomic.h API.
+ *
+ * This only tests basic functionality, not any synchronizing ordering.
+ */
+
+/* Always enable assertions */
+#undef NDEBUG
+
+#include "Python.h"
+#include "cpython/pyatomic.h"
+#include "parts.h"
+
+// We define atomic bitwise operations on these types
+#define FOR_BITWISE_TYPES(V) \
+ V(uint8, uint8_t) \
+ V(uint16, uint16_t) \
+ V(uint32, uint32_t) \
+ V(uint64, uint64_t) \
+ V(uintptr, uintptr_t)
+
+// We define atomic addition on these types
+#define FOR_ARITHMETIC_TYPES(V) \
+ FOR_BITWISE_TYPES(V) \
+ V(int, int) \
+ V(uint, unsigned int) \
+ V(int8, int8_t) \
+ V(int16, int16_t) \
+ V(int32, int32_t) \
+ V(int64, int64_t) \
+ V(intptr, intptr_t) \
+ V(ssize, Py_ssize_t)
+
+// We define atomic load, store, exchange, and compare_exchange on these types
+#define FOR_ALL_TYPES(V) \
+ FOR_ARITHMETIC_TYPES(V) \
+ V(ptr, void*)
+
+#define IMPL_TEST_ADD(suffix, dtype) \
+static PyObject * \
+test_atomic_add_##suffix(PyObject *self, PyObject *obj) { \
+ dtype x = 0; \
+ assert(_Py_atomic_add_##suffix(&x, 1) == 0); \
+ assert(x == 1); \
+ assert(_Py_atomic_add_##suffix(&x, 2) == 1); \
+ assert(x == 3); \
+ assert(_Py_atomic_add_##suffix(&x, -2) == 3); \
+ assert(x == 1); \
+ assert(_Py_atomic_add_##suffix(&x, -1) == 1); \
+ assert(x == 0); \
+ assert(_Py_atomic_add_##suffix(&x, -1) == 0); \
+ assert(x == (dtype)-1); \
+ assert(_Py_atomic_add_##suffix(&x, -2) == (dtype)-1); \
+ assert(x == (dtype)-3); \
+ assert(_Py_atomic_add_##suffix(&x, 2) == (dtype)-3); \
+ assert(x == (dtype)-1); \
+ Py_RETURN_NONE; \
+}
+FOR_ARITHMETIC_TYPES(IMPL_TEST_ADD)
+
+#define IMPL_TEST_COMPARE_EXCHANGE(suffix, dtype) \
+static PyObject * \
+test_atomic_compare_exchange_##suffix(PyObject *self, PyObject *obj) { \
+ dtype x = (dtype)0; \
+ dtype y = (dtype)1; \
+ dtype z = (dtype)2; \
+ assert(_Py_atomic_compare_exchange_##suffix(&x, &y, z) == 0); \
+ assert(x == 0); \
+ assert(y == 0); \
+ assert(_Py_atomic_compare_exchange_##suffix(&x, &y, z) == 1); \
+ assert(x == z); \
+ assert(y == 0); \
+ assert(_Py_atomic_compare_exchange_##suffix(&x, &y, z) == 0); \
+ assert(x == z); \
+ assert(y == z); \
+ Py_RETURN_NONE; \
+}
+FOR_ALL_TYPES(IMPL_TEST_COMPARE_EXCHANGE)
+
+#define IMPL_TEST_EXCHANGE(suffix, dtype) \
+static PyObject * \
+test_atomic_exchange_##suffix(PyObject *self, PyObject *obj) { \
+ dtype x = (dtype)0; \
+ dtype y = (dtype)1; \
+ dtype z = (dtype)2; \
+ assert(_Py_atomic_exchange_##suffix(&x, y) == (dtype)0); \
+ assert(x == (dtype)1); \
+ assert(_Py_atomic_exchange_##suffix(&x, z) == (dtype)1); \
+ assert(x == (dtype)2); \
+ assert(_Py_atomic_exchange_##suffix(&x, y) == (dtype)2); \
+ assert(x == (dtype)1); \
+ Py_RETURN_NONE; \
+}
+FOR_ALL_TYPES(IMPL_TEST_EXCHANGE)
+
+#define IMPL_TEST_LOAD_STORE(suffix, dtype) \
+static PyObject * \
+test_atomic_load_store_##suffix(PyObject *self, PyObject *obj) { \
+ dtype x = (dtype)0; \
+ dtype y = (dtype)1; \
+ dtype z = (dtype)2; \
+ assert(_Py_atomic_load_##suffix(&x) == (dtype)0); \
+ assert(x == (dtype)0); \
+ _Py_atomic_store_##suffix(&x, y); \
+ assert(_Py_atomic_load_##suffix(&x) == (dtype)1); \
+ assert(x == (dtype)1); \
+ _Py_atomic_store_##suffix##_relaxed(&x, z); \
+ assert(_Py_atomic_load_##suffix##_relaxed(&x) == (dtype)2); \
+ assert(x == (dtype)2); \
+ Py_RETURN_NONE; \
+}
+FOR_ALL_TYPES(IMPL_TEST_LOAD_STORE)
+
+#define IMPL_TEST_AND_OR(suffix, dtype) \
+static PyObject * \
+test_atomic_and_or_##suffix(PyObject *self, PyObject *obj) { \
+ dtype x = (dtype)0; \
+ dtype y = (dtype)1; \
+ dtype z = (dtype)3; \
+ assert(_Py_atomic_or_##suffix(&x, z) == (dtype)0); \
+ assert(x == (dtype)3); \
+ assert(_Py_atomic_and_##suffix(&x, y) == (dtype)3); \
+ assert(x == (dtype)1); \
+ Py_RETURN_NONE; \
+}
+FOR_BITWISE_TYPES(IMPL_TEST_AND_OR)
+
+static PyObject *
+test_atomic_fences(PyObject *self, PyObject *obj) {
+ // Just make sure that the fences compile. We are not
+ // testing any synchronizing ordering.
+ _Py_atomic_fence_seq_cst();
+ _Py_atomic_fence_release();
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+test_atomic_release_acquire(PyObject *self, PyObject *obj) {
+ void *x = NULL;
+ void *y = &y;
+ assert(_Py_atomic_load_ptr_acquire(&x) == NULL);
+ _Py_atomic_store_ptr_release(&x, y);
+ assert(x == y);
+ assert(_Py_atomic_load_ptr_acquire(&x) == y);
+ Py_RETURN_NONE;
+}
+
+// NOTE: all tests should start with "test_atomic_" to be included
+// in test_pyatomic.py
+
+#define BIND_TEST_ADD(suffix, dtype) \
+ {"test_atomic_add_" #suffix, test_atomic_add_##suffix, METH_NOARGS},
+#define BIND_TEST_COMPARE_EXCHANGE(suffix, dtype) \
+ {"test_atomic_compare_exchange_" #suffix, test_atomic_compare_exchange_##suffix, METH_NOARGS},
+#define BIND_TEST_EXCHANGE(suffix, dtype) \
+ {"test_atomic_exchange_" #suffix, test_atomic_exchange_##suffix, METH_NOARGS},
+#define BIND_TEST_LOAD_STORE(suffix, dtype) \
+ {"test_atomic_load_store_" #suffix, test_atomic_load_store_##suffix, METH_NOARGS},
+#define BIND_TEST_AND_OR(suffix, dtype) \
+ {"test_atomic_and_or_" #suffix, test_atomic_and_or_##suffix, METH_NOARGS},
+
+static PyMethodDef test_methods[] = {
+ FOR_ARITHMETIC_TYPES(BIND_TEST_ADD)
+ FOR_ALL_TYPES(BIND_TEST_COMPARE_EXCHANGE)
+ FOR_ALL_TYPES(BIND_TEST_EXCHANGE)
+ FOR_ALL_TYPES(BIND_TEST_LOAD_STORE)
+ FOR_BITWISE_TYPES(BIND_TEST_AND_OR)
+ {"test_atomic_fences", test_atomic_fences, METH_NOARGS},
+ {"test_atomic_release_acquire", test_atomic_release_acquire, METH_NOARGS},
+ {NULL, NULL} /* sentinel */
+};
+
+int
+_PyTestCapi_Init_PyAtomic(PyObject *mod)
+{
+ if (PyModule_AddFunctions(mod, test_methods) < 0) {
+ return -1;
+ }
+ return 0;
+}
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index d5c8a9d7ae520..f8b36ff9ce835 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -4004,6 +4004,9 @@ PyInit__testcapi(void)
if (_PyTestCapi_Init_GC(m) < 0) {
return NULL;
}
+ if (_PyTestCapi_Init_PyAtomic(m) < 0) {
+ return NULL;
+ }
#ifndef LIMITED_API_AVAILABLE
PyModule_AddObjectRef(m, "LIMITED_API_AVAILABLE", Py_False);
diff --git a/PCbuild/_testcapi.vcxproj b/PCbuild/_testcapi.vcxproj
index 8c0fd0cf052b0..0a02929db438b 100644
--- a/PCbuild/_testcapi.vcxproj
+++ b/PCbuild/_testcapi.vcxproj
@@ -112,6 +112,7 @@
<ClCompile Include="..\Modules\_testcapi\exceptions.c" />
<ClCompile Include="..\Modules\_testcapi\code.c" />
<ClCompile Include="..\Modules\_testcapi\buffer.c" />
+ <ClCompile Include="..\Modules\_testcapi\pyatomic.c" />
<ClCompile Include="..\Modules\_testcapi\pyos.c" />
<ClCompile Include="..\Modules\_testcapi\immortal.c" />
<ClCompile Include="..\Modules\_testcapi\gc.c" />
diff --git a/PCbuild/_testcapi.vcxproj.filters b/PCbuild/_testcapi.vcxproj.filters
index 87d33ebe28e47..4ba6011d8af5b 100644
--- a/PCbuild/_testcapi.vcxproj.filters
+++ b/PCbuild/_testcapi.vcxproj.filters
@@ -66,6 +66,9 @@
<ClCompile Include="..\Modules\_testcapi\buffer.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\Modules\_testcapi\pyatomic.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="..\Modules\_testcapi\pyos.c">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index 0b0f5ad0fdb9c..4cd095b28e510 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -166,6 +166,8 @@
<ClInclude Include="..\Include\cpython\parser_interface.h" />
<ClInclude Include="..\Include\cpython\picklebufobject.h" />
<ClInclude Include="..\Include\cpython\pyarena.h" />
+ <ClInclude Include="..\Include\cpython\pyatomic.h" />
+ <ClInclude Include="..\Include\cpython\pyatomic_msc.h" />
<ClInclude Include="..\Include\cpython\pyctype.h" />
<ClInclude Include="..\Include\cpython\pydebug.h" />
<ClInclude Include="..\Include\cpython\pyerrors.h" />
diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
index c70b8017935d7..af1669209a904 100644
--- a/PCbuild/pythoncore.vcxproj.filters
+++ b/PCbuild/pythoncore.vcxproj.filters
@@ -423,6 +423,18 @@
<ClInclude Include="..\Include\cpython\pyarena.h">
<Filter>Include</Filter>
</ClInclude>
+ <ClInclude Include="..\Include\cpython\pyatomic.h">
+ <Filter>Include</Filter>
+ </ClInclude>
+ <ClInclude Include="..\Include\cpython\pyatomic_gcc.h">
+ <Filter>Include</Filter>
+ </ClInclude>
+ <ClInclude Include="..\Include\cpython\pyatomic_msc.h">
+ <Filter>Include</Filter>
+ </ClInclude>
+ <ClInclude Include="..\Include\cpython\pyatomic_std.h">
+ <Filter>Include</Filter>
+ </ClInclude>
<ClInclude Include="..\Include\cpython\pyctype.h">
<Filter>Include</Filter>
</ClInclude>
1
0
https://github.com/python/cpython/commit/c6d56135e151a19c79d002cb1f1dbcd1c7…
commit: c6d56135e151a19c79d002cb1f1dbcd1c766c51d
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2023-08-31T23:14:23+02:00
summary:
gh-108638: Fix tests when _stat extension is missing (#108689)
Fix test_inspect and test_pydoc when the _stat extension is missing.
Skip tests relying on _stat when _stat is missing.
files:
M Lib/test/test_inspect.py
M Lib/test/test_pydoc.py
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 9cb92c02d3e7d..78ef817906b2a 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -1186,7 +1186,7 @@ def test_getfullargspec_builtin_func_no_signature(self):
cls = _testcapi.DocStringNoSignatureTest
obj = _testcapi.DocStringNoSignatureTest()
- for builtin, template in [
+ tests = [
(_testcapi.docstring_no_signature_noargs, meth_noargs),
(_testcapi.docstring_no_signature_o, meth_o),
(cls.meth_noargs, meth_self_noargs),
@@ -1201,7 +1201,6 @@ def test_getfullargspec_builtin_func_no_signature(self):
(cls.meth_o_coexist, meth_self_o),
(time.time, meth_noargs),
- (stat.S_IMODE, meth_o),
(str.lower, meth_self_noargs),
(''.lower, meth_self_noargs),
(set.add, meth_self_o),
@@ -1212,7 +1211,16 @@ def test_getfullargspec_builtin_func_no_signature(self):
(datetime.datetime.utcnow, meth_type_noargs),
(dict.__dict__['__class_getitem__'], meth_type_o),
(dict.__class_getitem__, meth_type_o),
- ]:
+ ]
+ try:
+ import _stat
+ except ImportError:
+ # if the _stat extension is not available, stat.S_IMODE() is
+ # implemented in Python, not in C
+ pass
+ else:
+ tests.append((stat.S_IMODE, meth_o))
+ for builtin, template in tests:
with self.subTest(builtin):
self.assertEqual(inspect.getfullargspec(builtin),
inspect.getfullargspec(template))
@@ -2934,7 +2942,7 @@ def test_signature_on_builtins_no_signature(self):
cls = _testcapi.DocStringNoSignatureTest
obj = _testcapi.DocStringNoSignatureTest()
- for builtin, template in [
+ tests = [
(_testcapi.docstring_no_signature_noargs, meth_noargs),
(_testcapi.docstring_no_signature_o, meth_o),
(cls.meth_noargs, meth_self_noargs),
@@ -2949,7 +2957,6 @@ def test_signature_on_builtins_no_signature(self):
(cls.meth_o_coexist, meth_self_o),
(time.time, meth_noargs),
- (stat.S_IMODE, meth_o),
(str.lower, meth_self_noargs),
(''.lower, meth_noargs),
(set.add, meth_self_o),
@@ -2960,7 +2967,16 @@ def test_signature_on_builtins_no_signature(self):
(datetime.datetime.utcnow, meth_noargs),
(dict.__dict__['__class_getitem__'], meth_type_o),
(dict.__class_getitem__, meth_o),
- ]:
+ ]
+ try:
+ import _stat
+ except ImportError:
+ # if the _stat extension is not available, stat.S_IMODE() is
+ # implemented in Python, not in C
+ pass
+ else:
+ tests.append((stat.S_IMODE, meth_o))
+ for builtin, template in tests:
with self.subTest(builtin):
self.assertEqual(inspect.signature(builtin),
inspect.signature(template))
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index 9b5c11bf853fd..499eeb98ad613 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -1187,7 +1187,13 @@ def test_module_level_callable_noargs(self):
"time()")
def test_module_level_callable_o(self):
- self.assertEqual(self._get_summary_line(stat.S_IMODE),
+ try:
+ import _stat
+ except ImportError:
+ # stat.S_IMODE() and _stat.S_IMODE() have a different signature
+ self.skipTest('_stat extension is missing')
+
+ self.assertEqual(self._get_summary_line(_stat.S_IMODE),
"S_IMODE(object, /)")
def test_unbound_builtin_method_noargs(self):
1
0
gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704)
by ethanfurman 31 Aug '23
by ethanfurman 31 Aug '23
31 Aug '23
https://github.com/python/cpython/commit/d48760b2f1e28dd3c1a35721939f400a8a…
commit: d48760b2f1e28dd3c1a35721939f400a8ab619b8
branch: main
author: Ethan Furman <ethan(a)stoneleaf.us>
committer: ethanfurman <ethan(a)stoneleaf.us>
date: 2023-08-31T12:45:12-07:00
summary:
gh-108682: [Enum] raise TypeError if super().__new__ called in custom __new__ (GH-108704)
When overriding the `__new__` method of an enum, the underlying data type should be created directly; i.e. .
member = object.__new__(cls)
member = int.__new__(cls, value)
member = str.__new__(cls, value)
Calling `super().__new__()` finds the lookup version of `Enum.__new__`, and will now raise an exception when detected.
files:
A Misc/NEWS.d/next/Library/2023-08-30-20-10-28.gh-issue-108682.c2gzLQ.rst
M Doc/howto/enum.rst
M Lib/enum.py
M Lib/test/test_enum.py
diff --git a/Doc/howto/enum.rst b/Doc/howto/enum.rst
index 4312b4c8140f5..28749754a54db 100644
--- a/Doc/howto/enum.rst
+++ b/Doc/howto/enum.rst
@@ -426,10 +426,17 @@ enumeration, with the exception of special methods (:meth:`__str__`,
:meth:`__add__`, etc.), descriptors (methods are also descriptors), and
variable names listed in :attr:`_ignore_`.
-Note: if your enumeration defines :meth:`__new__` and/or :meth:`__init__` then
+Note: if your enumeration defines :meth:`__new__` and/or :meth:`__init__`,
any value(s) given to the enum member will be passed into those methods.
See `Planet`_ for an example.
+.. note::
+
+ The :meth:`__new__` method, if defined, is used during creation of the Enum
+ members; it is then replaced by Enum's :meth:`__new__` which is used after
+ class creation for lookup of existing members. See :ref:`new-vs-init` for
+ more details.
+
Restricted Enum subclassing
---------------------------
@@ -895,6 +902,8 @@ Some rules:
:meth:`__str__` method has been reset to their data types'
:meth:`__str__` method.
+.. _new-vs-init:
+
When to use :meth:`__new__` vs. :meth:`__init__`
------------------------------------------------
@@ -927,6 +936,11 @@ want one of them to be the value::
>>> print(Coordinate(3))
Coordinate.VY
+.. warning::
+
+ *Do not* call ``super().__new__()``, as the lookup-only ``__new__`` is the one
+ that is found; instead, use the data type directly.
+
Finer Points
^^^^^^^^^^^^
@@ -1353,6 +1367,13 @@ to handle any extra arguments::
members; it is then replaced by Enum's :meth:`__new__` which is used after
class creation for lookup of existing members.
+.. warning::
+
+ *Do not* call ``super().__new__()``, as the lookup-only ``__new__`` is the one
+ that is found; instead, use the data type directly -- e.g.::
+
+ obj = int.__new__(cls, value)
+
OrderedEnum
^^^^^^^^^^^
diff --git a/Lib/enum.py b/Lib/enum.py
index 0c985b2c77856..4b99e7bda2cca 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -856,6 +856,8 @@ def _create_(cls, class_name, names, *, module=None, qualname=None, type=None, s
value = first_enum._generate_next_value_(name, start, count, last_values[:])
last_values.append(value)
names.append((name, value))
+ if names is None:
+ names = ()
# Here, names is either an iterable of (name, value) or a mapping.
for item in names:
@@ -1112,6 +1114,11 @@ def __new__(cls, value):
for member in cls._member_map_.values():
if member._value_ == value:
return member
+ # still not found -- verify that members exist, in-case somebody got here mistakenly
+ # (such as via super when trying to override __new__)
+ if not cls._member_map_:
+ raise TypeError("%r has no members defined" % cls)
+ #
# still not found -- try _missing_ hook
try:
exc = None
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 36a1ee4764084..11a5b425efff9 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -276,11 +276,82 @@ class _EnumTests:
values = None
def setUp(self):
- class BaseEnum(self.enum_type):
+ if self.__class__.__name__[-5:] == 'Class':
+ class BaseEnum(self.enum_type):
+ @enum.property
+ def first(self):
+ return '%s is first!' % self.name
+ class MainEnum(BaseEnum):
+ first = auto()
+ second = auto()
+ third = auto()
+ if issubclass(self.enum_type, Flag):
+ dupe = 3
+ else:
+ dupe = third
+ self.MainEnum = MainEnum
+ #
+ class NewStrEnum(self.enum_type):
+ def __str__(self):
+ return self.name.upper()
+ first = auto()
+ self.NewStrEnum = NewStrEnum
+ #
+ class NewFormatEnum(self.enum_type):
+ def __format__(self, spec):
+ return self.name.upper()
+ first = auto()
+ self.NewFormatEnum = NewFormatEnum
+ #
+ class NewStrFormatEnum(self.enum_type):
+ def __str__(self):
+ return self.name.title()
+ def __format__(self, spec):
+ return ''.join(reversed(self.name))
+ first = auto()
+ self.NewStrFormatEnum = NewStrFormatEnum
+ #
+ class NewBaseEnum(self.enum_type):
+ def __str__(self):
+ return self.name.title()
+ def __format__(self, spec):
+ return ''.join(reversed(self.name))
+ class NewSubEnum(NewBaseEnum):
+ first = auto()
+ self.NewSubEnum = NewSubEnum
+ #
+ class LazyGNV(self.enum_type):
+ def _generate_next_value_(name, start, last, values):
+ pass
+ self.LazyGNV = LazyGNV
+ #
+ class BusyGNV(self.enum_type):
+ @staticmethod
+ def _generate_next_value_(name, start, last, values):
+ pass
+ self.BusyGNV = BusyGNV
+ #
+ self.is_flag = False
+ self.names = ['first', 'second', 'third']
+ if issubclass(MainEnum, StrEnum):
+ self.values = self.names
+ elif MainEnum._member_type_ is str:
+ self.values = ['1', '2', '3']
+ elif issubclass(self.enum_type, Flag):
+ self.values = [1, 2, 4]
+ self.is_flag = True
+ self.dupe2 = MainEnum(5)
+ else:
+ self.values = self.values or [1, 2, 3]
+ #
+ if not getattr(self, 'source_values', False):
+ self.source_values = self.values
+ elif self.__class__.__name__[-8:] == 'Function':
@enum.property
def first(self):
return '%s is first!' % self.name
- class MainEnum(BaseEnum):
+ BaseEnum = self.enum_type('BaseEnum', {'first':first})
+ #
first = auto()
second = auto()
third = auto()
@@ -288,63 +359,60 @@ class MainEnum(BaseEnum):
dupe = 3
else:
dupe = third
- self.MainEnum = MainEnum
- #
- class NewStrEnum(self.enum_type):
+ self.MainEnum = MainEnum = BaseEnum('MainEnum', dict(first=first, second=second, third=third, dupe=dupe))
+ #
def __str__(self):
return self.name.upper()
first = auto()
- self.NewStrEnum = NewStrEnum
- #
- class NewFormatEnum(self.enum_type):
+ self.NewStrEnum = self.enum_type('NewStrEnum', (('first',first),('__str__',__str__)))
+ #
def __format__(self, spec):
return self.name.upper()
first = auto()
- self.NewFormatEnum = NewFormatEnum
- #
- class NewStrFormatEnum(self.enum_type):
+ self.NewFormatEnum = self.enum_type('NewFormatEnum', [('first',first),('__format__',__format__)])
+ #
def __str__(self):
return self.name.title()
def __format__(self, spec):
return ''.join(reversed(self.name))
first = auto()
- self.NewStrFormatEnum = NewStrFormatEnum
- #
- class NewBaseEnum(self.enum_type):
+ self.NewStrFormatEnum = self.enum_type('NewStrFormatEnum', dict(first=first, __format__=__format__, __str__=__str__))
+ #
def __str__(self):
return self.name.title()
def __format__(self, spec):
return ''.join(reversed(self.name))
- class NewSubEnum(NewBaseEnum):
- first = auto()
- self.NewSubEnum = NewSubEnum
- #
- class LazyGNV(self.enum_type):
+ NewBaseEnum = self.enum_type('NewBaseEnum', dict(__format__=__format__, __str__=__str__))
+ class NewSubEnum(NewBaseEnum):
+ first = auto()
+ self.NewSubEnum = NewBaseEnum('NewSubEnum', 'first')
+ #
def _generate_next_value_(name, start, last, values):
pass
- self.LazyGNV = LazyGNV
- #
- class BusyGNV(self.enum_type):
+ self.LazyGNV = self.enum_type('LazyGNV', {'_generate_next_value_':_generate_next_value_})
+ #
@staticmethod
def _generate_next_value_(name, start, last, values):
pass
- self.BusyGNV = BusyGNV
- #
- self.is_flag = False
- self.names = ['first', 'second', 'third']
- if issubclass(MainEnum, StrEnum):
- self.values = self.names
- elif MainEnum._member_type_ is str:
- self.values = ['1', '2', '3']
- elif issubclass(self.enum_type, Flag):
- self.values = [1, 2, 4]
- self.is_flag = True
- self.dupe2 = MainEnum(5)
+ self.BusyGNV = self.enum_type('BusyGNV', {'_generate_next_value_':_generate_next_value_})
+ #
+ self.is_flag = False
+ self.names = ['first', 'second', 'third']
+ if issubclass(MainEnum, StrEnum):
+ self.values = self.names
+ elif MainEnum._member_type_ is str:
+ self.values = ['1', '2', '3']
+ elif issubclass(self.enum_type, Flag):
+ self.values = [1, 2, 4]
+ self.is_flag = True
+ self.dupe2 = MainEnum(5)
+ else:
+ self.values = self.values or [1, 2, 3]
+ #
+ if not getattr(self, 'source_values', False):
+ self.source_values = self.values
else:
- self.values = self.values or [1, 2, 3]
- #
- if not getattr(self, 'source_values', False):
- self.source_values = self.values
+ raise ValueError('unknown enum style: %r' % self.__class__.__name__)
def assertFormatIsValue(self, spec, member):
self.assertEqual(spec.format(member), spec.format(member.value))
@@ -372,6 +440,17 @@ def spam(cls):
with self.assertRaises(AttributeError):
del Season.SPRING.name
+ def test_bad_new_super(self):
+ with self.assertRaisesRegex(
+ TypeError,
+ 'has no members defined',
+ ):
+ class BadSuper(self.enum_type):
+ def __new__(cls, value):
+ obj = super().__new__(cls, value)
+ return obj
+ failed = 1
+
def test_basics(self):
TE = self.MainEnum
if self.is_flag:
@@ -427,7 +506,7 @@ def test_contains_tf(self):
MainEnum = self.MainEnum
self.assertIn(MainEnum.first, MainEnum)
self.assertTrue(self.values[0] in MainEnum)
- if type(self) is not TestStrEnum:
+ if type(self) not in (TestStrEnumClass, TestStrEnumFunction):
self.assertFalse('first' in MainEnum)
val = MainEnum.dupe
self.assertIn(val, MainEnum)
@@ -949,15 +1028,23 @@ class OpenXYZ(self.enum_type):
self.assertTrue(~OpenXYZ(0), (X|Y|Z))
-class TestPlainEnum(_EnumTests, _PlainOutputTests, unittest.TestCase):
+class TestPlainEnumClass(_EnumTests, _PlainOutputTests, unittest.TestCase):
+ enum_type = Enum
+
+
+class TestPlainEnumFunction(_EnumTests, _PlainOutputTests, unittest.TestCase):
enum_type = Enum
-class TestPlainFlag(_EnumTests, _PlainOutputTests, _FlagTests, unittest.TestCase):
+class TestPlainFlagClass(_EnumTests, _PlainOutputTests, _FlagTests, unittest.TestCase):
enum_type = Flag
-class TestIntEnum(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+class TestPlainFlagFunction(_EnumTests, _PlainOutputTests, _FlagTests, unittest.TestCase):
+ enum_type = Flag
+
+
+class TestIntEnumClass(_EnumTests, _MinimalOutputTests, unittest.TestCase):
enum_type = IntEnum
#
def test_shadowed_attr(self):
@@ -969,7 +1056,17 @@ class Number(IntEnum):
self.assertIs(Number.numerator.divisor, Number.divisor)
-class TestStrEnum(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+class TestIntEnumFunction(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ enum_type = IntEnum
+ #
+ def test_shadowed_attr(self):
+ Number = IntEnum('Number', ('divisor', 'numerator'))
+ #
+ self.assertEqual(Number.divisor.numerator, 1)
+ self.assertIs(Number.numerator.divisor, Number.divisor)
+
+
+class TestStrEnumClass(_EnumTests, _MinimalOutputTests, unittest.TestCase):
enum_type = StrEnum
#
def test_shadowed_attr(self):
@@ -982,64 +1079,141 @@ class Book(StrEnum):
self.assertIs(Book.title.author, Book.author)
-class TestIntFlag(_EnumTests, _MinimalOutputTests, _FlagTests, unittest.TestCase):
+class TestStrEnumFunction(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ enum_type = StrEnum
+ #
+ def test_shadowed_attr(self):
+ Book = StrEnum('Book', ('author', 'title'))
+ #
+ self.assertEqual(Book.author.title(), 'Author')
+ self.assertEqual(Book.title.title(), 'Title')
+ self.assertIs(Book.title.author, Book.author)
+
+
+class TestIntFlagClass(_EnumTests, _MinimalOutputTests, _FlagTests, unittest.TestCase):
+ enum_type = IntFlag
+
+
+class TestIntFlagFunction(_EnumTests, _MinimalOutputTests, _FlagTests, unittest.TestCase):
enum_type = IntFlag
-class TestMixedInt(_EnumTests, _MixedOutputTests, unittest.TestCase):
+class TestMixedIntClass(_EnumTests, _MixedOutputTests, unittest.TestCase):
class enum_type(int, Enum): pass
-class TestMixedStr(_EnumTests, _MixedOutputTests, unittest.TestCase):
+class TestMixedIntFunction(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ enum_type = Enum('enum_type', type=int)
+
+
+class TestMixedStrClass(_EnumTests, _MixedOutputTests, unittest.TestCase):
class enum_type(str, Enum): pass
-class TestMixedIntFlag(_EnumTests, _MixedOutputTests, _FlagTests, unittest.TestCase):
+class TestMixedStrFunction(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ enum_type = Enum('enum_type', type=str)
+
+
+class TestMixedIntFlagClass(_EnumTests, _MixedOutputTests, _FlagTests, unittest.TestCase):
class enum_type(int, Flag): pass
-class TestMixedDate(_EnumTests, _MixedOutputTests, unittest.TestCase):
+class TestMixedIntFlagFunction(_EnumTests, _MixedOutputTests, _FlagTests, unittest.TestCase):
+ enum_type = Flag('enum_type', type=int)
+
+class TestMixedDateClass(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ #
values = [date(2021, 12, 25), date(2020, 3, 15), date(2019, 11, 27)]
source_values = [(2021, 12, 25), (2020, 3, 15), (2019, 11, 27)]
-
+ #
class enum_type(date, Enum):
+ @staticmethod
def _generate_next_value_(name, start, count, last_values):
values = [(2021, 12, 25), (2020, 3, 15), (2019, 11, 27)]
return values[count]
-class TestMinimalDate(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+class TestMixedDateFunction(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ #
+ values = [date(2021, 12, 25), date(2020, 3, 15), date(2019, 11, 27)]
+ source_values = [(2021, 12, 25), (2020, 3, 15), (2019, 11, 27)]
+ #
+ # staticmethod decorator will be added by EnumType if not present
+ def _generate_next_value_(name, start, count, last_values):
+ values = [(2021, 12, 25), (2020, 3, 15), (2019, 11, 27)]
+ return values[count]
+ #
+ enum_type = Enum('enum_type', {'_generate_next_value_':_generate_next_value_}, type=date)
+
+class TestMinimalDateClass(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ #
values = [date(2023, 12, 1), date(2016, 2, 29), date(2009, 1, 1)]
source_values = [(2023, 12, 1), (2016, 2, 29), (2009, 1, 1)]
-
+ #
class enum_type(date, ReprEnum):
+ # staticmethod decorator will be added by EnumType if absent
def _generate_next_value_(name, start, count, last_values):
values = [(2023, 12, 1), (2016, 2, 29), (2009, 1, 1)]
return values[count]
-class TestMixedFloat(_EnumTests, _MixedOutputTests, unittest.TestCase):
+class TestMinimalDateFunction(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ #
+ values = [date(2023, 12, 1), date(2016, 2, 29), date(2009, 1, 1)]
+ source_values = [(2023, 12, 1), (2016, 2, 29), (2009, 1, 1)]
+ #
+ @staticmethod
+ def _generate_next_value_(name, start, count, last_values):
+ values = [(2023, 12, 1), (2016, 2, 29), (2009, 1, 1)]
+ return values[count]
+ #
+ enum_type = ReprEnum('enum_type', {'_generate_next_value_':_generate_next_value_}, type=date)
- values = [1.1, 2.2, 3.3]
+class TestMixedFloatClass(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ #
+ values = [1.1, 2.2, 3.3]
+ #
class enum_type(float, Enum):
def _generate_next_value_(name, start, count, last_values):
values = [1.1, 2.2, 3.3]
return values[count]
-class TestMinimalFloat(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+class TestMixedFloatFunction(_EnumTests, _MixedOutputTests, unittest.TestCase):
+ #
+ values = [1.1, 2.2, 3.3]
+ #
+ def _generate_next_value_(name, start, count, last_values):
+ values = [1.1, 2.2, 3.3]
+ return values[count]
+ #
+ enum_type = Enum('enum_type', {'_generate_next_value_':_generate_next_value_}, type=float)
- values = [4.4, 5.5, 6.6]
+class TestMinimalFloatClass(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ #
+ values = [4.4, 5.5, 6.6]
+ #
class enum_type(float, ReprEnum):
def _generate_next_value_(name, start, count, last_values):
values = [4.4, 5.5, 6.6]
return values[count]
+class TestMinimalFloatFunction(_EnumTests, _MinimalOutputTests, unittest.TestCase):
+ #
+ values = [4.4, 5.5, 6.6]
+ #
+ def _generate_next_value_(name, start, count, last_values):
+ values = [4.4, 5.5, 6.6]
+ return values[count]
+ #
+ enum_type = ReprEnum('enum_type', {'_generate_next_value_':_generate_next_value_}, type=float)
+
+
class TestSpecial(unittest.TestCase):
"""
various operations that are not attributable to every possible enum
diff --git a/Misc/NEWS.d/next/Library/2023-08-30-20-10-28.gh-issue-108682.c2gzLQ.rst b/Misc/NEWS.d/next/Library/2023-08-30-20-10-28.gh-issue-108682.c2gzLQ.rst
new file mode 100644
index 0000000000000..148d432914274
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-08-30-20-10-28.gh-issue-108682.c2gzLQ.rst
@@ -0,0 +1,2 @@
+Enum: raise :exc:`TypeError` if ``super().__new__()`` is called from a
+custom ``__new__``.
1
0
https://github.com/python/cpython/commit/13a00078b81776b23b0b6add69b8483822…
commit: 13a00078b81776b23b0b6add69b848382240d1f2
branch: main
author: Victor Stinner <vstinner(a)python.org>
committer: vstinner <vstinner(a)python.org>
date: 2023-08-31T18:33:34+02:00
summary:
gh-108634: Py_TRACE_REFS uses a hash table (#108663)
Python built with "configure --with-trace-refs" (tracing references)
is now ABI compatible with Python release build and debug build.
Moreover, it now also supports the Limited API.
Change Py_TRACE_REFS build:
* Remove _PyObject_EXTRA_INIT macro.
* The PyObject structure no longer has two extra members (_ob_prev
and _ob_next).
* Use a hash table (_Py_hashtable_t) to trace references (all
objects): PyInterpreterState.object_state.refchain.
* Py_TRACE_REFS build is now ABI compatible with release build and
debug build.
* Limited C API extensions can now be built with Py_TRACE_REFS:
xxlimited, xxlimited_35, _testclinic_limited.
* No longer rename PyModule_Create2() and PyModule_FromDefAndSpec2()
functions to PyModule_Create2TraceRefs() and
PyModule_FromDefAndSpec2TraceRefs().
* _Py_PrintReferenceAddresses() is now called before
finalize_interp_delete() which deletes the refchain hash table.
* test_tracemalloc find_trace() now also filters by size to ignore
the memory allocated by _PyRefchain_Trace().
Test changes for Py_TRACE_REFS:
* Add test.support.Py_TRACE_REFS constant.
* Add test_sys.test_getobjects() to test sys.getobjects() function.
* test_exceptions skips test_recursion_normalizing_with_no_memory()
and test_memory_error_in_PyErr_PrintEx() if Python is built with
Py_TRACE_REFS.
* test_repl skips test_no_memory().
* test_capi skisp test_set_nomemory().
files:
A Misc/NEWS.d/next/Build/2023-08-30-02-52-52.gh-issue-108634.3dpBvf.rst
A Misc/NEWS.d/next/C API/2023-08-30-02-54-06.gh-issue-108634.oV3Xzk.rst
M Doc/c-api/typeobj.rst
M Doc/using/configure.rst
M Doc/whatsnew/3.13.rst
M Include/internal/pycore_object.h
M Include/internal/pycore_object_state.h
M Include/internal/pycore_runtime_init.h
M Include/modsupport.h
M Include/object.h
M Include/pyport.h
M Lib/test/support/__init__.py
M Lib/test/test_capi/test_mem.py
M Lib/test/test_exceptions.py
M Lib/test/test_import/__init__.py
M Lib/test/test_repl.py
M Lib/test/test_sys.py
M Lib/test/test_tracemalloc.py
M Misc/SpecialBuilds.txt
M Modules/_testcapi/parts.h
M Objects/object.c
M Objects/setobject.c
M Objects/sliceobject.c
M Objects/structseq.c
M Objects/typeobject.c
M Python/bltinmodule.c
M Python/hashtable.c
M Python/pylifecycle.c
M Python/pystate.c
M configure
M configure.ac
diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst
index f417c68fd1efd..1fa3f2a6f5373 100644
--- a/Doc/c-api/typeobj.rst
+++ b/Doc/c-api/typeobj.rst
@@ -528,28 +528,6 @@ type objects) *must* have the :c:member:`~PyVarObject.ob_size` field.
This field is inherited by subtypes.
-.. c:member:: PyObject* PyObject._ob_next
- PyObject* PyObject._ob_prev
-
- These fields are only present when the macro ``Py_TRACE_REFS`` is defined
- (see the :option:`configure --with-trace-refs option <--with-trace-refs>`).
-
- Their initialization to ``NULL`` is taken care of by the
- ``PyObject_HEAD_INIT`` macro. For :ref:`statically allocated objects
- <static-types>`, these fields always remain ``NULL``. For :ref:`dynamically
- allocated objects <heap-types>`, these two fields are used to link the
- object into a doubly linked list of *all* live objects on the heap.
-
- This could be used for various debugging purposes; currently the only uses
- are the :func:`sys.getobjects` function and to print the objects that are
- still alive at the end of a run when the environment variable
- :envvar:`PYTHONDUMPREFS` is set.
-
- **Inheritance:**
-
- These fields are not inherited by subtypes.
-
-
PyVarObject Slots
-----------------
diff --git a/Doc/using/configure.rst b/Doc/using/configure.rst
index a16a4afffb1af..fe35372603fdd 100644
--- a/Doc/using/configure.rst
+++ b/Doc/using/configure.rst
@@ -425,8 +425,7 @@ See also the :ref:`Python Development Mode <devmode>` and the
.. versionchanged:: 3.8
Release builds and debug builds are now ABI compatible: defining the
``Py_DEBUG`` macro no longer implies the ``Py_TRACE_REFS`` macro (see the
- :option:`--with-trace-refs` option), which introduces the only ABI
- incompatibility.
+ :option:`--with-trace-refs` option).
Debug options
@@ -447,8 +446,14 @@ Debug options
* Add :func:`sys.getobjects` function.
* Add :envvar:`PYTHONDUMPREFS` environment variable.
- This build is not ABI compatible with release build (default build) or debug
- build (``Py_DEBUG`` and ``Py_REF_DEBUG`` macros).
+ The :envvar:`PYTHONDUMPREFS` environment variable can be used to dump
+ objects and reference counts still alive at Python exit.
+
+ :ref:`Statically allocated objects <static-types>` are not traced.
+
+ .. versionchanged:: 3.13
+ This build is now ABI compatible with release build and :ref:`debug build
+ <debug-build>`.
.. versionadded:: 3.8
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index 298d5fb567732..fd2f2c3fff828 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -828,6 +828,11 @@ Build Changes
* SQLite 3.15.2 or newer is required to build the :mod:`sqlite3` extension module.
(Contributed by Erlend Aasland in :gh:`105875`.)
+* Python built with :file:`configure` :option:`--with-trace-refs` (tracing
+ references) is now ABI compatible with Python release build and
+ :ref:`debug build <debug-build>`.
+ (Contributed by Victor Stinner in :gh:`108634`.)
+
C API Changes
=============
@@ -900,6 +905,10 @@ New Features
(with an underscore prefix).
(Contributed by Victor Stinner in :gh:`108014`.)
+* Python built with :file:`configure` :option:`--with-trace-refs` (tracing
+ references) now supports the :ref:`Limited API <limited-c-api>`.
+ (Contributed by Victor Stinner in :gh:`108634`.)
+
Porting to Python 3.13
----------------------
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index 7c142b384d17f..d842816e67355 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -55,7 +55,6 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
backwards compatible solution */
#define _PyObject_HEAD_INIT(type) \
{ \
- _PyObject_EXTRA_INIT \
.ob_refcnt = _Py_IMMORTAL_REFCNT, \
.ob_type = (type) \
},
@@ -184,6 +183,8 @@ _PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
extern void _PyType_InitCache(PyInterpreterState *interp);
extern void _PyObject_InitState(PyInterpreterState *interp);
+extern void _PyObject_FiniState(PyInterpreterState *interp);
+extern bool _PyRefchain_IsTraced(PyInterpreterState *interp, PyObject *obj);
/* Inline functions trading binary compatibility for speed:
_PyObject_Init() is the fast version of PyObject_Init(), and
@@ -302,7 +303,7 @@ extern void _PyDebug_PrintTotalRefs(void);
#endif
#ifdef Py_TRACE_REFS
-extern void _Py_AddToAllObjects(PyObject *op, int force);
+extern void _Py_AddToAllObjects(PyObject *op);
extern void _Py_PrintReferences(PyInterpreterState *, FILE *);
extern void _Py_PrintReferenceAddresses(PyInterpreterState *, FILE *);
#endif
diff --git a/Include/internal/pycore_object_state.h b/Include/internal/pycore_object_state.h
index 65feb5af969f8..9eac27b1a9a4e 100644
--- a/Include/internal/pycore_object_state.h
+++ b/Include/internal/pycore_object_state.h
@@ -8,6 +8,8 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
+#include "pycore_hashtable.h" // _Py_hashtable_t
+
struct _py_object_runtime_state {
#ifdef Py_REF_DEBUG
Py_ssize_t interpreter_leaks;
@@ -20,11 +22,10 @@ struct _py_object_state {
Py_ssize_t reftotal;
#endif
#ifdef Py_TRACE_REFS
- /* Head of circular doubly-linked list of all objects. These are linked
- * together via the _ob_prev and _ob_next members of a PyObject, which
- * exist only in a Py_TRACE_REFS build.
- */
- PyObject refchain;
+ // Hash table storing all objects. The key is the object pointer
+ // (PyObject*) and the value is always the number 1 (as uintptr_t).
+ // See _PyRefchain_IsTraced() and _PyRefchain_Trace() functions.
+ _Py_hashtable_t *refchain;
#endif
int _not_used;
};
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index c775a8a7e7eef..2deba02a89f33 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -192,7 +192,7 @@ extern PyTypeObject _PyExc_MemoryError;
#ifdef Py_TRACE_REFS
# define _py_object_state_INIT(INTERP) \
{ \
- .refchain = {&INTERP.object_state.refchain, &INTERP.object_state.refchain}, \
+ .refchain = NULL, \
}
#else
# define _py_object_state_INIT(INTERP) \
diff --git a/Include/modsupport.h b/Include/modsupport.h
index 88577e027b527..7c15ab50c320e 100644
--- a/Include/modsupport.h
+++ b/Include/modsupport.h
@@ -111,14 +111,6 @@ PyAPI_FUNC(int) PyModule_ExecDef(PyObject *module, PyModuleDef *def);
#define PYTHON_ABI_VERSION 3
#define PYTHON_ABI_STRING "3"
-#ifdef Py_TRACE_REFS
- /* When we are tracing reference counts, rename module creation functions so
- modules compiled with incompatible settings will generate a
- link-time error. */
- #define PyModule_Create2 PyModule_Create2TraceRefs
- #define PyModule_FromDefAndSpec2 PyModule_FromDefAndSpec2TraceRefs
-#endif
-
PyAPI_FUNC(PyObject *) PyModule_Create2(PyModuleDef*, int apiver);
#ifdef Py_LIMITED_API
diff --git a/Include/object.h b/Include/object.h
index d82eb6138743b..de2a1ce0f3c4d 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -58,23 +58,6 @@ whose size is determined when the object is allocated.
# define Py_REF_DEBUG
#endif
-#if defined(Py_LIMITED_API) && defined(Py_TRACE_REFS)
-# error Py_LIMITED_API is incompatible with Py_TRACE_REFS
-#endif
-
-#ifdef Py_TRACE_REFS
-/* Define pointers to support a doubly-linked list of all live heap objects. */
-#define _PyObject_HEAD_EXTRA \
- PyObject *_ob_next; \
- PyObject *_ob_prev;
-
-#define _PyObject_EXTRA_INIT _Py_NULL, _Py_NULL,
-
-#else
-# define _PyObject_HEAD_EXTRA
-# define _PyObject_EXTRA_INIT
-#endif
-
/* PyObject_HEAD defines the initial segment of every PyObject. */
#define PyObject_HEAD PyObject ob_base;
@@ -130,14 +113,12 @@ check by comparing the reference count field to the immortality reference count.
#ifdef Py_BUILD_CORE
#define PyObject_HEAD_INIT(type) \
{ \
- _PyObject_EXTRA_INIT \
{ _Py_IMMORTAL_REFCNT }, \
(type) \
},
#else
#define PyObject_HEAD_INIT(type) \
{ \
- _PyObject_EXTRA_INIT \
{ 1 }, \
(type) \
},
@@ -164,8 +145,6 @@ check by comparing the reference count field to the immortality reference count.
* in addition, be cast to PyVarObject*.
*/
struct _object {
- _PyObject_HEAD_EXTRA
-
#if (defined(__GNUC__) || defined(__clang__)) \
&& !(defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)
// On C99 and older, anonymous union is a GCC and clang extension
diff --git a/Include/pyport.h b/Include/pyport.h
index 2dc241389243d..115b54fd96928 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -684,12 +684,6 @@ extern char * _getpty(int *, int, mode_t, int);
# endif
#endif
-/* Check that ALT_SOABI is consistent with Py_TRACE_REFS:
- ./configure --with-trace-refs should must be used to define Py_TRACE_REFS */
-#if defined(ALT_SOABI) && defined(Py_TRACE_REFS)
-# error "Py_TRACE_REFS ABI is not compatible with release and debug ABI"
-#endif
-
#if defined(__ANDROID__) || defined(__VXWORKS__)
// Use UTF-8 as the locale encoding, ignore the LC_CTYPE locale.
// See _Py_GetLocaleEncoding(), PyUnicode_DecodeLocale()
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index c3f8527bd6952..16a5056a33aa1 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -779,9 +779,6 @@ def python_is_optimized():
_header = 'nP'
_align = '0n'
-if hasattr(sys, "getobjects"):
- _header = '2P' + _header
- _align = '0P'
_vheader = _header + 'n'
def calcobjsize(fmt):
@@ -2469,3 +2466,5 @@ def adjust_int_max_str_digits(max_digits):
#Windows doesn't have os.uname() but it doesn't support s390x.
skip_on_s390x = unittest.skipIf(hasattr(os, 'uname') and os.uname().machine == 's390x',
'skipped on s390x')
+
+Py_TRACE_REFS = hasattr(sys, 'getobjects')
diff --git a/Lib/test/test_capi/test_mem.py b/Lib/test/test_capi/test_mem.py
index 527000875b724..72f23b1a34080 100644
--- a/Lib/test/test_capi/test_mem.py
+++ b/Lib/test/test_capi/test_mem.py
@@ -112,6 +112,9 @@ def test_pyobject_forbidden_bytes_is_freed(self):
def test_pyobject_freed_is_freed(self):
self.check_pyobject_is_freed('check_pyobject_freed_is_freed')
+ # Python built with Py_TRACE_REFS fail with a fatal error in
+ # _PyRefchain_Trace() on memory allocation error.
+ @unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
def test_set_nomemory(self):
code = """if 1:
import _testcapi
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 764122ed4ef78..c766f4d43311e 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1484,6 +1484,9 @@ def recurse_in_body_and_except():
@cpython_only
+ # Python built with Py_TRACE_REFS fail with a fatal error in
+ # _PyRefchain_Trace() on memory allocation error.
+ @unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
def test_recursion_normalizing_with_no_memory(self):
# Issue #30697. Test that in the abort that occurs when there is no
# memory left and the size of the Python frames stack is greater than
@@ -1652,6 +1655,9 @@ def test_unhandled(self):
self.assertTrue(report.endswith("\n"))
@cpython_only
+ # Python built with Py_TRACE_REFS fail with a fatal error in
+ # _PyRefchain_Trace() on memory allocation error.
+ @unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
def test_memory_error_in_PyErr_PrintEx(self):
code = """if 1:
import _testcapi
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index 740ce7d5ef263..33bce779f6cc0 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -28,7 +28,7 @@
from test.support import os_helper
from test.support import (
STDLIB_DIR, swap_attr, swap_item, cpython_only, is_emscripten,
- is_wasi, run_in_subinterp, run_in_subinterp_with_config)
+ is_wasi, run_in_subinterp, run_in_subinterp_with_config, Py_TRACE_REFS)
from test.support.import_helper import (
forget, make_legacy_pyc, unlink, unload, DirsOnSysPath, CleanImport)
from test.support.os_helper import (
@@ -2555,7 +2555,7 @@ def test_basic_multiple_interpreters_main_no_reset(self):
def test_basic_multiple_interpreters_deleted_no_reset(self):
# without resetting; already loaded in a deleted interpreter
- if hasattr(sys, 'getobjects'):
+ if Py_TRACE_REFS:
# It's a Py_TRACE_REFS build.
# This test breaks interpreter isolation a little,
# which causes problems on Py_TRACE_REF builds.
diff --git a/Lib/test/test_repl.py b/Lib/test/test_repl.py
index ddb4aa68048df..58392f2384a3d 100644
--- a/Lib/test/test_repl.py
+++ b/Lib/test/test_repl.py
@@ -5,6 +5,7 @@
import unittest
import subprocess
from textwrap import dedent
+from test import support
from test.support import cpython_only, has_subprocess_support, SuppressCrashReport
from test.support.script_helper import kill_python
@@ -59,6 +60,9 @@ def run_on_interactive_mode(source):
class TestInteractiveInterpreter(unittest.TestCase):
@cpython_only
+ # Python built with Py_TRACE_REFS fail with a fatal error in
+ # _PyRefchain_Trace() on memory allocation error.
+ @unittest.skipIf(support.Py_TRACE_REFS, 'cannot test Py_TRACE_REFS build')
def test_no_memory(self):
# Issue #30696: Fix the interactive interpreter looping endlessly when
# no memory. Check also that the fix does not break the interactive
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index f3608ce142fb9..d8b684c8a008f 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -1174,6 +1174,27 @@ def test_stdlib_dir(self):
self.assertEqual(os.path.normpath(sys._stdlib_dir),
os.path.normpath(expected))
+ @unittest.skipUnless(hasattr(sys, 'getobjects'), 'need sys.getobjects()')
+ def test_getobjects(self):
+ # sys.getobjects(0)
+ all_objects = sys.getobjects(0)
+ self.assertIsInstance(all_objects, list)
+ self.assertGreater(len(all_objects), 0)
+
+ # sys.getobjects(0, MyType)
+ class MyType:
+ pass
+ size = 100
+ my_objects = [MyType() for _ in range(size)]
+ get_objects = sys.getobjects(0, MyType)
+ self.assertEqual(len(get_objects), size)
+ for obj in get_objects:
+ self.assertIsInstance(obj, MyType)
+
+ # sys.getobjects(3, MyType)
+ get_objects = sys.getobjects(3, MyType)
+ self.assertEqual(len(get_objects), 3)
+
@test.support.cpython_only
class UnraisableHookTest(unittest.TestCase):
diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py
index 4af4ca3b97723..bea124521032d 100644
--- a/Lib/test/test_tracemalloc.py
+++ b/Lib/test/test_tracemalloc.py
@@ -173,9 +173,11 @@ def test_set_traceback_limit(self):
self.assertEqual(len(traceback), 1)
self.assertEqual(traceback, obj_traceback)
- def find_trace(self, traces, traceback):
+ def find_trace(self, traces, traceback, size):
+ # filter also by size to ignore the memory allocated by
+ # _PyRefchain_Trace() if Python is built with Py_TRACE_REFS.
for trace in traces:
- if trace[2] == traceback._frames:
+ if trace[2] == traceback._frames and trace[1] == size:
return trace
self.fail("trace not found")
@@ -186,11 +188,10 @@ def test_get_traces(self):
obj, obj_traceback = allocate_bytes(obj_size)
traces = tracemalloc._get_traces()
- trace = self.find_trace(traces, obj_traceback)
+ trace = self.find_trace(traces, obj_traceback, obj_size)
self.assertIsInstance(trace, tuple)
domain, size, traceback, length = trace
- self.assertEqual(size, obj_size)
self.assertEqual(traceback, obj_traceback._frames)
tracemalloc.stop()
@@ -208,17 +209,18 @@ def allocate_bytes4(size):
# Ensure that two identical tracebacks are not duplicated
tracemalloc.stop()
tracemalloc.start(4)
- obj_size = 123
- obj1, obj1_traceback = allocate_bytes4(obj_size)
- obj2, obj2_traceback = allocate_bytes4(obj_size)
+ obj1_size = 123
+ obj2_size = 125
+ obj1, obj1_traceback = allocate_bytes4(obj1_size)
+ obj2, obj2_traceback = allocate_bytes4(obj2_size)
traces = tracemalloc._get_traces()
obj1_traceback._frames = tuple(reversed(obj1_traceback._frames))
obj2_traceback._frames = tuple(reversed(obj2_traceback._frames))
- trace1 = self.find_trace(traces, obj1_traceback)
- trace2 = self.find_trace(traces, obj2_traceback)
+ trace1 = self.find_trace(traces, obj1_traceback, obj1_size)
+ trace2 = self.find_trace(traces, obj2_traceback, obj2_size)
domain1, size1, traceback1, length1 = trace1
domain2, size2, traceback2, length2 = trace2
self.assertIs(traceback2, traceback1)
diff --git a/Misc/NEWS.d/next/Build/2023-08-30-02-52-52.gh-issue-108634.3dpBvf.rst b/Misc/NEWS.d/next/Build/2023-08-30-02-52-52.gh-issue-108634.3dpBvf.rst
new file mode 100644
index 0000000000000..d1530787067d4
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2023-08-30-02-52-52.gh-issue-108634.3dpBvf.rst
@@ -0,0 +1,3 @@
+Python built with :file:`configure` :option:`--with-trace-refs` (tracing
+references) is now ABI compatible with Python release build and :ref:`debug
+build <debug-build>`. Patch by Victor Stinner.
diff --git a/Misc/NEWS.d/next/C API/2023-08-30-02-54-06.gh-issue-108634.oV3Xzk.rst b/Misc/NEWS.d/next/C API/2023-08-30-02-54-06.gh-issue-108634.oV3Xzk.rst
new file mode 100644
index 0000000000000..0427644ad3724
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2023-08-30-02-54-06.gh-issue-108634.oV3Xzk.rst
@@ -0,0 +1,3 @@
+Python built with :file:`configure` :option:`--with-trace-refs` (tracing
+references) now supports the :ref:`Limited API <limited-c-api>`. Patch by
+Victor Stinner.
diff --git a/Misc/SpecialBuilds.txt b/Misc/SpecialBuilds.txt
index 5609928284d44..78201bfbd6741 100644
--- a/Misc/SpecialBuilds.txt
+++ b/Misc/SpecialBuilds.txt
@@ -43,13 +43,9 @@ Py_TRACE_REFS
Build option: ``./configure --with-trace-refs``.
-Turn on heavy reference debugging. This is major surgery. Every PyObject grows
-two more pointers, to maintain a doubly-linked list of all live heap-allocated
-objects. Most built-in type objects are not in this list, as they're statically
-allocated.
-
-Note that because the fundamental PyObject layout changes, Python modules
-compiled with Py_TRACE_REFS are incompatible with modules compiled without it.
+Turn on heavy reference debugging. This is major surgery. All live
+heap-allocated objects are traced in a hash table. Most built-in type objects
+are not in this list, as they're statically allocated.
Special gimmicks:
diff --git a/Modules/_testcapi/parts.h b/Modules/_testcapi/parts.h
index 65ebf80bcd1e9..9c6d615714180 100644
--- a/Modules/_testcapi/parts.h
+++ b/Modules/_testcapi/parts.h
@@ -1,27 +1,9 @@
#ifndef Py_TESTCAPI_PARTS_H
#define Py_TESTCAPI_PARTS_H
-#include "pyconfig.h" // for Py_TRACE_REFS
-
-// Figure out if Limited API is available for this build. If it isn't we won't
-// build tests for it.
-// Currently, only Py_TRACE_REFS disables Limited API.
-#ifdef Py_TRACE_REFS
-#undef LIMITED_API_AVAILABLE
-#else
-#define LIMITED_API_AVAILABLE 1
-#endif
-
// Always enable assertions
#undef NDEBUG
-#if !defined(LIMITED_API_AVAILABLE) && defined(Py_LIMITED_API)
-// Limited API being unavailable means that with Py_LIMITED_API defined
-// we can't even include Python.h.
-// Do nothing; the .c file that defined Py_LIMITED_API should also do nothing.
-
-#else
-
#include "Python.h"
int _PyTestCapi_Init_Vectorcall(PyObject *module);
@@ -44,10 +26,7 @@ int _PyTestCapi_Init_PyOS(PyObject *module);
int _PyTestCapi_Init_Immortal(PyObject *module);
int _PyTestCapi_Init_GC(PyObject *mod);
-#ifdef LIMITED_API_AVAILABLE
int _PyTestCapi_Init_VectorcallLimited(PyObject *module);
int _PyTestCapi_Init_HeaptypeRelative(PyObject *module);
-#endif // LIMITED_API_AVAILABLE
-#endif
#endif // Py_TESTCAPI_PARTS_H
diff --git a/Objects/object.c b/Objects/object.c
index 0d88421bf0fdc..a4d7111a686bd 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -9,6 +9,7 @@
#include "pycore_dict.h" // _PyObject_MakeDictFromInstanceAttributes()
#include "pycore_floatobject.h" // _PyFloat_DebugMallocStats()
#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
+#include "pycore_hashtable.h" // _Py_hashtable_new()
#include "pycore_memoryobject.h" // _PyManagedBuffer_Type
#include "pycore_namespace.h" // _PyNamespace_Type
#include "pycore_object.h" // PyAPI_DATA() _Py_SwappedOp definition
@@ -162,44 +163,51 @@ _PyDebug_PrintTotalRefs(void) {
#ifdef Py_TRACE_REFS
-#define REFCHAIN(interp) &interp->object_state.refchain
+#define REFCHAIN(interp) interp->object_state.refchain
+#define REFCHAIN_VALUE ((void*)(uintptr_t)1)
-static inline void
-init_refchain(PyInterpreterState *interp)
-{
- PyObject *refchain = REFCHAIN(interp);
- refchain->_ob_prev = refchain;
- refchain->_ob_next = refchain;
-}
-
-/* Insert op at the front of the list of all objects. If force is true,
- * op is added even if _ob_prev and _ob_next are non-NULL already. If
- * force is false amd _ob_prev or _ob_next are non-NULL, do nothing.
- * force should be true if and only if op points to freshly allocated,
- * uninitialized memory, or you've unlinked op from the list and are
- * relinking it into the front.
- * Note that objects are normally added to the list via _Py_NewReference,
- * which is called by PyObject_Init. Not all objects are initialized that
- * way, though; exceptions include statically allocated type objects, and
- * statically allocated singletons (like Py_True and Py_None).
- */
-void
-_Py_AddToAllObjects(PyObject *op, int force)
+bool
+_PyRefchain_IsTraced(PyInterpreterState *interp, PyObject *obj)
{
-#ifdef Py_DEBUG
- if (!force) {
- /* If it's initialized memory, op must be in or out of
- * the list unambiguously.
- */
- _PyObject_ASSERT(op, (op->_ob_prev == NULL) == (op->_ob_next == NULL));
+ return (_Py_hashtable_get(REFCHAIN(interp), obj) == REFCHAIN_VALUE);
+}
+
+
+static void
+_PyRefchain_Trace(PyInterpreterState *interp, PyObject *obj)
+{
+ if (_Py_hashtable_set(REFCHAIN(interp), obj, REFCHAIN_VALUE) < 0) {
+ // Use a fatal error because _Py_NewReference() cannot report
+ // the error to the caller.
+ Py_FatalError("_Py_hashtable_set() memory allocation failed");
}
+}
+
+
+static void
+_PyRefchain_Remove(PyInterpreterState *interp, PyObject *obj)
+{
+ void *value = _Py_hashtable_steal(REFCHAIN(interp), obj);
+#ifndef NDEBUG
+ assert(value == REFCHAIN_VALUE);
+#else
+ (void)value;
#endif
- if (force || op->_ob_prev == NULL) {
- PyObject *refchain = REFCHAIN(_PyInterpreterState_GET());
- op->_ob_next = refchain->_ob_next;
- op->_ob_prev = refchain;
- refchain->_ob_next->_ob_prev = op;
- refchain->_ob_next = op;
+}
+
+
+/* Add an object to the refchain hash table.
+ *
+ * Note that objects are normally added to the list by PyObject_Init()
+ * indirectly. Not all objects are initialized that way, though; exceptions
+ * include statically allocated type objects, and statically allocated
+ * singletons (like Py_True and Py_None). */
+void
+_Py_AddToAllObjects(PyObject *op)
+{
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (!_PyRefchain_IsTraced(interp, op)) {
+ _PyRefchain_Trace(interp, op);
}
}
#endif /* Py_TRACE_REFS */
@@ -471,16 +479,6 @@ _PyObject_IsFreed(PyObject *op)
if (_PyMem_IsPtrFreed(op) || _PyMem_IsPtrFreed(Py_TYPE(op))) {
return 1;
}
- /* ignore op->ob_ref: its value can have be modified
- by Py_INCREF() and Py_DECREF(). */
-#ifdef Py_TRACE_REFS
- if (op->_ob_next != NULL && _PyMem_IsPtrFreed(op->_ob_next)) {
- return 1;
- }
- if (op->_ob_prev != NULL && _PyMem_IsPtrFreed(op->_ob_prev)) {
- return 1;
- }
-#endif
return 0;
}
@@ -1929,7 +1927,6 @@ PyTypeObject _PyNone_Type = {
};
PyObject _Py_NoneStruct = {
- _PyObject_EXTRA_INIT
{ _Py_IMMORTAL_REFCNT },
&_PyNone_Type
};
@@ -2032,7 +2029,6 @@ PyTypeObject _PyNotImplemented_Type = {
};
PyObject _Py_NotImplementedStruct = {
- _PyObject_EXTRA_INIT
{ _Py_IMMORTAL_REFCNT },
&_PyNotImplemented_Type
};
@@ -2042,12 +2038,30 @@ void
_PyObject_InitState(PyInterpreterState *interp)
{
#ifdef Py_TRACE_REFS
- if (!_Py_IsMainInterpreter(interp)) {
- init_refchain(interp);
+ _Py_hashtable_allocator_t alloc = {
+ // Don't use default PyMem_Malloc() and PyMem_Free() which
+ // require the caller to hold the GIL.
+ .malloc = PyMem_RawMalloc,
+ .free = PyMem_RawFree,
+ };
+ REFCHAIN(interp) = _Py_hashtable_new_full(
+ _Py_hashtable_hash_ptr, _Py_hashtable_compare_direct,
+ NULL, NULL, &alloc);
+ if (REFCHAIN(interp) == NULL) {
+ Py_FatalError("_PyObject_InitState() memory allocation failure");
}
#endif
}
+void
+_PyObject_FiniState(PyInterpreterState *interp)
+{
+#ifdef Py_TRACE_REFS
+ _Py_hashtable_destroy(REFCHAIN(interp));
+ REFCHAIN(interp) = NULL;
+#endif
+}
+
extern PyTypeObject _PyAnextAwaitable_Type;
extern PyTypeObject _PyLegacyEventHandler_Type;
@@ -2230,7 +2244,7 @@ new_reference(PyObject *op)
// Skip the immortal object check in Py_SET_REFCNT; always set refcnt to 1
op->ob_refcnt = 1;
#ifdef Py_TRACE_REFS
- _Py_AddToAllObjects(op, 1);
+ _Py_AddToAllObjects(op);
#endif
}
@@ -2258,53 +2272,62 @@ _Py_ForgetReference(PyObject *op)
_PyObject_ASSERT_FAILED_MSG(op, "negative refcnt");
}
- PyObject *refchain = REFCHAIN(_PyInterpreterState_GET());
- if (op == refchain ||
- op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op)
- {
- _PyObject_ASSERT_FAILED_MSG(op, "invalid object chain");
- }
+ PyInterpreterState *interp = _PyInterpreterState_GET();
#ifdef SLOW_UNREF_CHECK
- PyObject *p;
- for (p = refchain->_ob_next; p != refchain; p = p->_ob_next) {
- if (p == op) {
- break;
- }
- }
- if (p == refchain) {
+ if (!_PyRefchain_Get(interp, op)) {
/* Not found */
_PyObject_ASSERT_FAILED_MSG(op,
"object not found in the objects list");
}
#endif
- op->_ob_next->_ob_prev = op->_ob_prev;
- op->_ob_prev->_ob_next = op->_ob_next;
- op->_ob_next = op->_ob_prev = NULL;
+ _PyRefchain_Remove(interp, op);
}
+static int
+_Py_PrintReference(_Py_hashtable_t *ht,
+ const void *key, const void *value,
+ void *user_data)
+{
+ PyObject *op = (PyObject*)key;
+ FILE *fp = (FILE *)user_data;
+ fprintf(fp, "%p [%zd] ", (void *)op, Py_REFCNT(op));
+ if (PyObject_Print(op, fp, 0) != 0) {
+ PyErr_Clear();
+ }
+ putc('\n', fp);
+ return 0;
+}
+
+
/* Print all live objects. Because PyObject_Print is called, the
* interpreter must be in a healthy state.
*/
void
_Py_PrintReferences(PyInterpreterState *interp, FILE *fp)
{
- PyObject *op;
if (interp == NULL) {
interp = _PyInterpreterState_Main();
}
fprintf(fp, "Remaining objects:\n");
- PyObject *refchain = REFCHAIN(interp);
- for (op = refchain->_ob_next; op != refchain; op = op->_ob_next) {
- fprintf(fp, "%p [%zd] ", (void *)op, Py_REFCNT(op));
- if (PyObject_Print(op, fp, 0) != 0) {
- PyErr_Clear();
- }
- putc('\n', fp);
- }
+ _Py_hashtable_foreach(REFCHAIN(interp), _Py_PrintReference, fp);
}
+
+static int
+_Py_PrintReferenceAddress(_Py_hashtable_t *ht,
+ const void *key, const void *value,
+ void *user_data)
+{
+ PyObject *op = (PyObject*)key;
+ FILE *fp = (FILE *)user_data;
+ fprintf(fp, "%p [%zd] %s\n",
+ (void *)op, Py_REFCNT(op), Py_TYPE(op)->tp_name);
+ return 0;
+}
+
+
/* Print the addresses of all live objects. Unlike _Py_PrintReferences, this
* doesn't make any calls to the Python C API, so is always safe to call.
*/
@@ -2315,47 +2338,96 @@ _Py_PrintReferences(PyInterpreterState *interp, FILE *fp)
void
_Py_PrintReferenceAddresses(PyInterpreterState *interp, FILE *fp)
{
- PyObject *op;
- PyObject *refchain = REFCHAIN(interp);
fprintf(fp, "Remaining object addresses:\n");
- for (op = refchain->_ob_next; op != refchain; op = op->_ob_next)
- fprintf(fp, "%p [%zd] %s\n", (void *)op,
- Py_REFCNT(op), Py_TYPE(op)->tp_name);
+ _Py_hashtable_foreach(REFCHAIN(interp), _Py_PrintReferenceAddress, fp);
}
+
+typedef struct {
+ PyObject *self;
+ PyObject *args;
+ PyObject *list;
+ PyObject *type;
+ Py_ssize_t limit;
+} _Py_GetObjectsData;
+
+enum {
+ _PY_GETOBJECTS_IGNORE = 0,
+ _PY_GETOBJECTS_ERROR = 1,
+ _PY_GETOBJECTS_STOP = 2,
+};
+
+static int
+_Py_GetObject(_Py_hashtable_t *ht,
+ const void *key, const void *value,
+ void *user_data)
+{
+ PyObject *op = (PyObject *)key;
+ _Py_GetObjectsData *data = user_data;
+ if (data->limit > 0) {
+ if (PyList_GET_SIZE(data->list) >= data->limit) {
+ return _PY_GETOBJECTS_STOP;
+ }
+ }
+
+ if (op == data->self) {
+ return _PY_GETOBJECTS_IGNORE;
+ }
+ if (op == data->args) {
+ return _PY_GETOBJECTS_IGNORE;
+ }
+ if (op == data->list) {
+ return _PY_GETOBJECTS_IGNORE;
+ }
+ if (data->type != NULL) {
+ if (op == data->type) {
+ return _PY_GETOBJECTS_IGNORE;
+ }
+ if (!Py_IS_TYPE(op, (PyTypeObject *)data->type)) {
+ return _PY_GETOBJECTS_IGNORE;
+ }
+ }
+
+ if (PyList_Append(data->list, op) < 0) {
+ return _PY_GETOBJECTS_ERROR;
+ }
+ return 0;
+}
+
+
/* The implementation of sys.getobjects(). */
PyObject *
_Py_GetObjects(PyObject *self, PyObject *args)
{
- int i, n;
- PyObject *t = NULL;
- PyObject *res, *op;
- PyInterpreterState *interp = _PyInterpreterState_GET();
+ Py_ssize_t limit;
+ PyObject *type = NULL;
+ if (!PyArg_ParseTuple(args, "n|O", &limit, &type)) {
+ return NULL;
+ }
- if (!PyArg_ParseTuple(args, "i|O", &n, &t))
+ PyObject *list = PyList_New(0);
+ if (list == NULL) {
return NULL;
- PyObject *refchain = REFCHAIN(interp);
- op = refchain->_ob_next;
- res = PyList_New(0);
- if (res == NULL)
+ }
+
+ _Py_GetObjectsData data = {
+ .self = self,
+ .args = args,
+ .list = list,
+ .type = type,
+ .limit = limit,
+ };
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ int res = _Py_hashtable_foreach(REFCHAIN(interp), _Py_GetObject, &data);
+ if (res == _PY_GETOBJECTS_ERROR) {
+ Py_DECREF(list);
return NULL;
- for (i = 0; (n == 0 || i < n) && op != refchain; i++) {
- while (op == self || op == args || op == res || op == t ||
- (t != NULL && !Py_IS_TYPE(op, (PyTypeObject *) t))) {
- op = op->_ob_next;
- if (op == refchain)
- return res;
- }
- if (PyList_Append(res, op) < 0) {
- Py_DECREF(res);
- return NULL;
- }
- op = op->_ob_next;
}
- return res;
+ return list;
}
#undef REFCHAIN
+#undef REFCHAIN_VALUE
#endif /* Py_TRACE_REFS */
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 6051e57731c7a..ae3f0b8d5e55d 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -2548,7 +2548,6 @@ static PyTypeObject _PySetDummy_Type = {
};
static PyObject _dummy_struct = {
- _PyObject_EXTRA_INIT
{ _Py_IMMORTAL_REFCNT },
&_PySetDummy_Type
};
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 8cf654fb6f812..5ffc52ae674c8 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -98,7 +98,6 @@ PyTypeObject PyEllipsis_Type = {
};
PyObject _Py_EllipsisObject = {
- _PyObject_EXTRA_INIT
{ _Py_IMMORTAL_REFCNT },
&PyEllipsis_Type
};
diff --git a/Objects/structseq.c b/Objects/structseq.c
index 6c07e6366293f..0ca622edc2ba3 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -573,9 +573,10 @@ PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
Py_ssize_t n_members, n_unnamed_members;
#ifdef Py_TRACE_REFS
- /* if the type object was chained, unchain it first
+ /* if the type object was traced, remove it first
before overwriting its storage */
- if (type->ob_base.ob_base._ob_next) {
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (_PyRefchain_IsTraced(interp, (PyObject *)type)) {
_Py_ForgetReference((PyObject *)type);
}
#endif
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 7ce3de4d58d0d..67e059c3f74b7 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -7508,7 +7508,7 @@ type_ready(PyTypeObject *type, int rerunbuiltin)
* to get type objects into the doubly-linked list of all objects.
* Still, not all type objects go through PyType_Ready.
*/
- _Py_AddToAllObjects((PyObject *)type, 0);
+ _Py_AddToAllObjects((PyObject *)type);
#endif
/* Initialize tp_dict: _PyType_IsReady() tests if tp_dict != NULL */
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 30dd717b0fea2..971067e2d4fcc 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -3110,7 +3110,7 @@ _PyBuiltin_Init(PyInterpreterState *interp)
* result, programs leaking references to None and False (etc)
* couldn't be diagnosed by examining sys.getobjects(0).
*/
-#define ADD_TO_ALL(OBJECT) _Py_AddToAllObjects((PyObject *)(OBJECT), 0)
+#define ADD_TO_ALL(OBJECT) _Py_AddToAllObjects((PyObject *)(OBJECT))
#else
#define ADD_TO_ALL(OBJECT) (void)0
#endif
diff --git a/Python/hashtable.c b/Python/hashtable.c
index 4e22a1a5509eb..8f5e8168ba133 100644
--- a/Python/hashtable.c
+++ b/Python/hashtable.c
@@ -226,7 +226,6 @@ _Py_hashtable_set(_Py_hashtable_t *ht, const void *key, void *value)
assert(entry == NULL);
#endif
-
entry = ht->alloc.malloc(sizeof(_Py_hashtable_entry_t));
if (entry == NULL) {
/* memory allocation failed */
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 7d362af32cbc3..ee5d4981da51c 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1956,31 +1956,30 @@ Py_FinalizeEx(void)
// XXX Ensure finalizer errors are handled properly.
finalize_interp_clear(tstate);
- finalize_interp_delete(tstate->interp);
-
-#ifdef Py_REF_DEBUG
- if (show_ref_count) {
- _PyDebug_PrintTotalRefs();
- }
- _Py_FinalizeRefTotal(runtime);
-#endif
- _Py_FinalizeAllocatedBlocks(runtime);
#ifdef Py_TRACE_REFS
/* Display addresses (& refcnts) of all objects still alive.
* An address can be used to find the repr of the object, printed
- * above by _Py_PrintReferences.
- */
-
+ * above by _Py_PrintReferences. */
if (dump_refs) {
_Py_PrintReferenceAddresses(tstate->interp, stderr);
}
-
if (dump_refs_fp != NULL) {
_Py_PrintReferenceAddresses(tstate->interp, dump_refs_fp);
fclose(dump_refs_fp);
}
#endif /* Py_TRACE_REFS */
+
+ finalize_interp_delete(tstate->interp);
+
+#ifdef Py_REF_DEBUG
+ if (show_ref_count) {
+ _PyDebug_PrintTotalRefs();
+ }
+ _Py_FinalizeRefTotal(runtime);
+#endif
+ _Py_FinalizeAllocatedBlocks(runtime);
+
#ifdef WITH_PYMALLOC
if (malloc_stats) {
_PyObject_DebugMallocStats(stderr);
diff --git a/Python/pystate.c b/Python/pystate.c
index 01651d79f9acc..4a8808f700eaa 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -674,6 +674,7 @@ init_interpreter(PyInterpreterState *interp,
_obmalloc_pools_INIT(interp->obmalloc.pools);
memcpy(&interp->obmalloc.pools.used, temp, sizeof(temp));
}
+
_PyObject_InitState(interp);
_PyEval_InitState(interp, pending_lock);
@@ -1001,6 +1002,9 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
if (interp->id_mutex != NULL) {
PyThread_free_lock(interp->id_mutex);
}
+
+ _PyObject_FiniState(interp);
+
free_interpreter(interp);
}
diff --git a/configure b/configure
index 57e3307266c0b..7fe4aead29a73 100755
--- a/configure
+++ b/configure
@@ -23571,8 +23571,9 @@ SOABI='cpython-'`echo $VERSION | tr -d .`${ABIFLAGS}${PLATFORM_TRIPLET:+-$PLATFO
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $SOABI" >&5
printf "%s\n" "$SOABI" >&6; }
-# Release and debug (Py_DEBUG) ABI are compatible, but not Py_TRACE_REFS ABI
-if test "$Py_DEBUG" = 'true' -a "$with_trace_refs" != "yes"; then
+# Release build, debug build (Py_DEBUG), and trace refs build (Py_TRACE_REFS)
+# are ABI compatible
+if test "$Py_DEBUG" = 'true'; then
# Similar to SOABI but remove "d" flag from ABIFLAGS
ALT_SOABI='cpython-'`echo $VERSION | tr -d .``echo $ABIFLAGS | tr -d d`${PLATFORM_TRIPLET:+-$PLATFORM_TRIPLET}
@@ -29962,7 +29963,7 @@ printf %s "checking for stdlib extension module _testclinic_limited... " >&6; }
if test "$py_cv_module__testclinic_limited" != "n/a"
then :
- if test "$TEST_MODULES" = yes -a "$with_trace_refs" = "no"
+ if test "$TEST_MODULES" = yes
then :
if true
then :
@@ -30267,7 +30268,7 @@ printf %s "checking for stdlib extension module xxlimited... " >&6; }
if test "$py_cv_module_xxlimited" != "n/a"
then :
- if test "$with_trace_refs" = "no"
+ if true
then :
if test "$ac_cv_func_dlopen" = yes
then :
@@ -30305,7 +30306,7 @@ printf %s "checking for stdlib extension module xxlimited_35... " >&6; }
if test "$py_cv_module_xxlimited_35" != "n/a"
then :
- if test "$with_trace_refs" = "no"
+ if true
then :
if test "$ac_cv_func_dlopen" = yes
then :
diff --git a/configure.ac b/configure.ac
index 6fb6e11064703..5673b374353b4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5684,8 +5684,9 @@ AC_MSG_CHECKING([SOABI])
SOABI='cpython-'`echo $VERSION | tr -d .`${ABIFLAGS}${PLATFORM_TRIPLET:+-$PLATFORM_TRIPLET}
AC_MSG_RESULT([$SOABI])
-# Release and debug (Py_DEBUG) ABI are compatible, but not Py_TRACE_REFS ABI
-if test "$Py_DEBUG" = 'true' -a "$with_trace_refs" != "yes"; then
+# Release build, debug build (Py_DEBUG), and trace refs build (Py_TRACE_REFS)
+# are ABI compatible
+if test "$Py_DEBUG" = 'true'; then
# Similar to SOABI but remove "d" flag from ABIFLAGS
AC_SUBST([ALT_SOABI])
ALT_SOABI='cpython-'`echo $VERSION | tr -d .``echo $ABIFLAGS | tr -d d`${PLATFORM_TRIPLET:+-$PLATFORM_TRIPLET}
@@ -7229,7 +7230,7 @@ PY_STDLIB_MOD([_hashlib], [], [test "$ac_cv_working_openssl_hashlib" = yes],
dnl test modules
PY_STDLIB_MOD([_testcapi], [test "$TEST_MODULES" = yes])
PY_STDLIB_MOD([_testclinic], [test "$TEST_MODULES" = yes])
-PY_STDLIB_MOD([_testclinic_limited], [test "$TEST_MODULES" = yes -a "$with_trace_refs" = "no"])
+PY_STDLIB_MOD([_testclinic_limited], [test "$TEST_MODULES" = yes])
PY_STDLIB_MOD([_testinternalcapi], [test "$TEST_MODULES" = yes])
PY_STDLIB_MOD([_testbuffer], [test "$TEST_MODULES" = yes])
PY_STDLIB_MOD([_testimportmultiple], [test "$TEST_MODULES" = yes], [test "$ac_cv_func_dlopen" = yes])
@@ -7241,10 +7242,9 @@ PY_STDLIB_MOD([_ctypes_test],
[], [$LIBM])
dnl Limited API template modules.
-dnl The limited C API is not compatible with the Py_TRACE_REFS macro.
dnl Emscripten does not support shared libraries yet.
-PY_STDLIB_MOD([xxlimited], [test "$with_trace_refs" = "no"], [test "$ac_cv_func_dlopen" = yes])
-PY_STDLIB_MOD([xxlimited_35], [test "$with_trace_refs" = "no"], [test "$ac_cv_func_dlopen" = yes])
+PY_STDLIB_MOD([xxlimited], [], [test "$ac_cv_func_dlopen" = yes])
+PY_STDLIB_MOD([xxlimited_35], [], [test "$ac_cv_func_dlopen" = yes])
# substitute multiline block, must come after last PY_STDLIB_MOD()
AC_SUBST([MODULE_BLOCK])
1
0
gh-97850: Note in py312 whatsnew that `importlib.util.set_loader` and `importlib.util.module_for_loader` have been removed (#108719)
by AlexWaygood 31 Aug '23
by AlexWaygood 31 Aug '23
31 Aug '23
https://github.com/python/cpython/commit/013a99a47b3299f48cf7f95aa451a11644…
commit: 013a99a47b3299f48cf7f95aa451a116441b029c
branch: main
author: Alex Waygood <Alex.Waygood(a)Gmail.com>
committer: AlexWaygood <Alex.Waygood(a)Gmail.com>
date: 2023-08-31T15:35:23+01:00
summary:
gh-97850: Note in py312 whatsnew that `importlib.util.set_loader` and `importlib.util.module_for_loader` have been removed (#108719)
Note in py312 whatsnew that `importlib.util.set_loader` and `importlib.util.module_for_loader` have been removed
files:
M Doc/whatsnew/3.12.rst
diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst
index c5a5f7e6bd023..fb31a07930da2 100644
--- a/Doc/whatsnew/3.12.rst
+++ b/Doc/whatsnew/3.12.rst
@@ -1312,8 +1312,9 @@ Removed
* References to, and support for :meth:`!module_repr()` has been removed.
(Contributed by Barry Warsaw in :gh:`97850`.)
- * ``importlib.util.set_package`` has been removed. (Contributed by Brett
- Cannon in :gh:`65961`.)
+ * ``importlib.util.set_package``, ``importlib.util.set_loader`` and
+ ``importlib.util.module_for_loader`` have all been removed. (Contributed by
+ Brett Cannon and Nikita Sobolev in :gh:`65961` and :gh:`97850`.)
* Support for ``find_loader()`` and ``find_module()`` APIs have been
removed. (Contributed by Barry Warsaw in :gh:`98040`.)
1
0